working status
This commit is contained in:
Binary file not shown.
@@ -144,6 +144,10 @@ local stageConfig = {
|
||||
Spearhead.internal.GlobalCapManager.start(databaseManager, capConfig, stageConfig)
|
||||
Spearhead.internal.GlobalStageManager.start(databaseManager)
|
||||
|
||||
--[[
|
||||
TODO: REMOVE DEBUG
|
||||
]]
|
||||
Spearhead.Events.PublishStageNumberChanged(1)
|
||||
|
||||
Spearhead.LoadingDone()
|
||||
--Check lines of code in directory per file:
|
||||
|
||||
+33
-4
@@ -47,7 +47,7 @@ do -- INIT UTIL
|
||||
return result
|
||||
end
|
||||
|
||||
for str in string.gmatch(input, "([^" .. seperator .. "]+)") do
|
||||
for str in string.gmatch(input, "[^" .. seperator .. "]+") do
|
||||
table.insert(result, str)
|
||||
end
|
||||
return result
|
||||
@@ -1493,9 +1493,8 @@ do
|
||||
|
||||
do --COMMANDS
|
||||
do -- status updates
|
||||
|
||||
local onStatusRequestReceivedListeners = {}
|
||||
|
||||
local onStatusRequestReceivedListeners = {}
|
||||
---comment
|
||||
---@param listener table object with OnStatusRequestReceived(self, groupId)
|
||||
SpearheadEvents.AddOnStatusRequestReceivedListener = function(listener)
|
||||
@@ -1547,7 +1546,6 @@ do
|
||||
for ii = 0, 9 do
|
||||
local number = tonumber(tostring(i) .. tostring(ii))
|
||||
missionCommands.addCommandForGroup(groupId, "Stage " .. tostring(number), { "debug", "Set Stage", menuName }, activateStage, number)
|
||||
SpearheadLogger:info("blaat " .. number)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1556,6 +1554,35 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
do -- PLAYER ENTER UNIT
|
||||
local playerEnterUnitListeners = {}
|
||||
---comment
|
||||
---@param listener table object with OnPlayerEnterUnit(self, unit)
|
||||
SpearheadEvents.AddOnPlayerEnterUnitListener = function(listener)
|
||||
if type(listener) ~= "table" then
|
||||
SpearheadLogger:warn("Unit lost Event listener not of type table/object")
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(playerEnterUnitListeners, listener)
|
||||
end
|
||||
|
||||
SpearheadEvents.TriggerPlayerEntersUnit = function(unit)
|
||||
if unit ~= nil then
|
||||
if playerEnterUnitListeners then
|
||||
for _, callable in pairs(playerEnterUnitListeners) do
|
||||
local succ, err = pcall(function()
|
||||
callable:OnPlayerEnterUnit(unit)
|
||||
end)
|
||||
if err then
|
||||
SpearheadLogger:error(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local e = {}
|
||||
function e:onEvent(event)
|
||||
if event.id == world.event.S_EVENT_LAND or event.id == world.event.S_EVENT_RUNWAY_TOUCH then
|
||||
@@ -1610,6 +1637,8 @@ function Spearhead.AddMissionEditorWarning(warningMessage)
|
||||
table.insert(Spearhead.MissionEditingWarnings, warningMessage or "skip")
|
||||
end
|
||||
|
||||
missionCommands.addSubMenu("Missions")
|
||||
|
||||
local loadDone = false
|
||||
Spearhead.LoadingDone = function()
|
||||
if loadDone == true then
|
||||
|
||||
+2
-5
@@ -230,7 +230,6 @@ do -- DB
|
||||
o.tables.capGroupsOnAirbase = {}
|
||||
local loadCapUnits = function()
|
||||
local all_groups = getAvailableCAPGroups()
|
||||
Logger:debug(all_groups)
|
||||
local airbases = world.getAirbases()
|
||||
for _, airbase in pairs(airbases) do
|
||||
local baseId = airbase:getID()
|
||||
@@ -298,7 +297,7 @@ do -- DB
|
||||
local baseId = tostring(airbase:getID())
|
||||
local point = airbase:getPoint()
|
||||
|
||||
if isAirbaseInZone[tostring(baseId) or "something" ] == true and airbase:getDesc().Category == Airbase.Category.AIRDROME then
|
||||
if isAirbaseInZone[tostring(baseId) or "something" ] == true and airbase:getDesc().category == Airbase.Category.AIRDROME then
|
||||
o.tables.redAirbaseGroupsPerAirbase[baseId] = {}
|
||||
o.tables.blueAirbaseGroupsPerAirbase[baseId] = {}
|
||||
local groups = Spearhead.DcsUtil.areGroupsInCustomZone(all_groups, { x = point.x, z = point.z, radius = 6600 })
|
||||
@@ -363,8 +362,6 @@ do -- DB
|
||||
loadAirbaseGroups()
|
||||
loadMiscGroupsInStages()
|
||||
|
||||
Logger:debug(o.tables.miscGroupsInStages)
|
||||
|
||||
local cleanup = function () --CLean up all groups that are now managed inside zones by spearhead
|
||||
|
||||
local count = 0
|
||||
@@ -586,7 +583,7 @@ do -- DB
|
||||
Logger:info("Farps: " .. Spearhead.Util.tableLength(o.tables.farp_zones))
|
||||
Logger:info("Airbases: " .. Spearhead.Util.tableLength(o.tables.airbasesPerStage))
|
||||
Logger:info("RedAirbase Groups: " .. Spearhead.Util.tableLength(o.tables.redAirbaseGroupsPerAirbase["21"]))
|
||||
Spearhead.Util.tableLength(o.tables.airbasesPerStage)
|
||||
|
||||
end
|
||||
singleton = o
|
||||
return o
|
||||
|
||||
@@ -94,6 +94,7 @@ do -- INIT Mission Class
|
||||
o.groupNames = database:getGroupsForMissionZone(missionZoneName)
|
||||
o.name = parsed.missionName
|
||||
o.missionType = parsed.type
|
||||
o.missionTypeDisplayName = Mission.MissionType.toString(o.missionType)
|
||||
o.startingGroups = Spearhead.Util.tableLength(o.groupNames)
|
||||
o.missionState = Mission.MissionState.NEW
|
||||
o.missionbriefing = database:GetDescriptionForMission(missionZoneName)
|
||||
@@ -259,9 +260,9 @@ do -- INIT Mission Class
|
||||
StartCheckingAndUpdateSelfContinuous(self)
|
||||
end
|
||||
|
||||
o.ShowBriefing = function(self, unitId)
|
||||
local text = "Mission #" .. self.code .. "\n" .. self.missionbriefing .. " \n \nState TODO"
|
||||
trigger.action.outTextForUnit(unitId, text, 30);
|
||||
o.ShowBriefing = function(self, groupId)
|
||||
local text = "Mission [" .. self.code .. "] ".. self.name .. "\n \n" .. self.missionbriefing .. " \n \nState TODO"
|
||||
trigger.action.outTextForGroup(groupId, text, 30);
|
||||
end
|
||||
|
||||
o.Cleanup = function(self)
|
||||
|
||||
+146
-29
@@ -7,7 +7,7 @@ do --init STAGE DIRECTOR
|
||||
---@param database table
|
||||
---@param logger table
|
||||
---@return table?
|
||||
function Stage:new(stagezone_name, database, logger)
|
||||
function Stage:new(stagezone_name, database, logger, stageConfig)
|
||||
local o = {}
|
||||
setmetatable(o, { __index = self })
|
||||
|
||||
@@ -29,6 +29,7 @@ do --init STAGE DIRECTOR
|
||||
o.database = database
|
||||
o.logger = logger
|
||||
o.db = {}
|
||||
o.db.missionsByCode = {}
|
||||
o.db.missions = {}
|
||||
o.db.sams = {}
|
||||
o.db.redAirbasegroups = {}
|
||||
@@ -37,14 +38,16 @@ do --init STAGE DIRECTOR
|
||||
o.db.farps = {}
|
||||
o.activeStage = 0
|
||||
o.preActivated = false
|
||||
o.stageConfig = stageConfig or {}
|
||||
|
||||
do --Init Stage
|
||||
logger:info("Initiating new Stage with name: " .. stagezone_name)
|
||||
|
||||
local missionZones = database:getMissionsForStage(stagezone_name)
|
||||
for _, missionZone in pairs(missionZones) do
|
||||
local mission = Spearhead.internal.Mission:new(missionZone, database)
|
||||
local mission = Spearhead.internal.Mission:new(missionZone, database, logger)
|
||||
if mission then
|
||||
o.db.missionsByCode[mission.code] = mission
|
||||
if mission.missionType == Spearhead.internal.Mission.MissionType.SAM then
|
||||
table.insert(o.db.sams, mission)
|
||||
else
|
||||
@@ -57,7 +60,7 @@ do --init STAGE DIRECTOR
|
||||
|
||||
local randomMissionByName = {}
|
||||
for _, missionZoneName in pairs(randomMissionNames) do
|
||||
local mission = Spearhead.internal.Mission:new(missionZoneName, database)
|
||||
local mission = Spearhead.internal.Mission:new(missionZoneName, database, logger)
|
||||
if mission then
|
||||
if randomMissionByName[mission.name] == nil then
|
||||
randomMissionByName[mission.name] = {}
|
||||
@@ -69,6 +72,7 @@ do --init STAGE DIRECTOR
|
||||
for _, missions in pairs(randomMissionByName) do
|
||||
local mission = Spearhead.Util.randomFromList(missions)
|
||||
if mission then
|
||||
o.db.missionsByCode[mission.code] = mission
|
||||
if mission.missionType == Spearhead.internal.Mission.MissionType.SAM then
|
||||
table.insert(o.db.sams, mission)
|
||||
else
|
||||
@@ -109,25 +113,33 @@ do --init STAGE DIRECTOR
|
||||
---Activates all SAMS, Airbase units etc all at once.
|
||||
---@param self table
|
||||
o.PreActivate = function(self)
|
||||
if self.preActivated == true then return end
|
||||
self.preActivated = true
|
||||
for key, mission in pairs(self.db.sams) do
|
||||
if mission and mission.Activate then
|
||||
mission:Activate()
|
||||
if self.preActivated == false then
|
||||
self.preActivated = true
|
||||
for key, mission in pairs(self.db.sams) do
|
||||
if mission and mission.Activate then
|
||||
mission:Activate()
|
||||
end
|
||||
end
|
||||
self.logger:debug("Pre-activating stage with airbase groups amount: " .. Spearhead.Util.tableLength(self.db.redAirbasegroups))
|
||||
|
||||
for _ , groupName in pairs(self.db.redAirbasegroups) do
|
||||
Spearhead.DcsUtil.SpawnGroupTemplate(groupName)
|
||||
end
|
||||
end
|
||||
|
||||
self.logger:debug("Pre-activating stage with airbase groups amount: " .. Spearhead.Util.tableLength(self.db.redAirbasegroups))
|
||||
|
||||
for _ , groupName in pairs(self.db.redAirbasegroups) do
|
||||
Spearhead.DcsUtil.SpawnGroupTemplate(groupName)
|
||||
if self.activeStage == self.stageNumber then
|
||||
for _, mission in pairs(self.db.sams) do
|
||||
self:AddCommmandsForMissionToAllPlayers(mission)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
o.ActiveStage = function(self)
|
||||
if self.preActivated == false then
|
||||
self:PreActivate()
|
||||
end
|
||||
local activateMissionsIfApplicableAsync = function(self)
|
||||
self:ActivateMissionsIfApplicable(self)
|
||||
end
|
||||
|
||||
o.ActivateStage = function(self)
|
||||
self:PreActivate()
|
||||
|
||||
local miscGroups = self.database:getMiscGroupsAtStage(self.zoneName)
|
||||
self.logger:debug("Activating Misc groups for zone: " .. Spearhead.Util.tableLength(miscGroups))
|
||||
@@ -138,18 +150,43 @@ do --init STAGE DIRECTOR
|
||||
for _, mission in pairs(self.db.missions) do
|
||||
if mission.missionType == Spearhead.internal.Mission.MissionType.DEAD then
|
||||
mission:Activate()
|
||||
self:AddCommmandsForMissionToAllPlayers(mission)
|
||||
end
|
||||
end
|
||||
timer.scheduleFunction(activateMissionsIfApplicableAsync, self, timer.getTime() + 5)
|
||||
end
|
||||
|
||||
o.ActivateMissionsIfApplicable = function (self)
|
||||
local activeCount = 0
|
||||
|
||||
local availableMissions = {}
|
||||
for _, mission in pairs(self.db.missionsByCode) do
|
||||
if mission.missionState == Spearhead.internal.Mission.MissionState.ACTIVE then
|
||||
activeCount = activeCount + 1
|
||||
end
|
||||
|
||||
if mission.missionState == Spearhead.internal.Mission.MissionState.NEW then
|
||||
table.insert(availableMissions, mission)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
TODO: Activate Stage
|
||||
]]--
|
||||
local max = self.stageConfig.maxMissionsInStage or 10
|
||||
|
||||
end
|
||||
|
||||
o.ActivateAllMissions = function(self)
|
||||
for _, mission in pairs(self.db.missions) do
|
||||
mission:Activate()
|
||||
local availableMissionsCount = Spearhead.Util.tableLength(availableMissions)
|
||||
if activeCount < max and availableMissionsCount > 0 then
|
||||
for i = activeCount+1, max do
|
||||
if availableMissionsCount == 0 then
|
||||
i = max+1 --exits this loop
|
||||
else
|
||||
local index = math.random(1, availableMissionsCount)
|
||||
local mission = table.remove(availableMissions, index)
|
||||
if mission then
|
||||
mission:Activate()
|
||||
self:AddCommmandsForMissionToAllPlayers(mission)
|
||||
end
|
||||
availableMissionsCount = availableMissionsCount - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -236,7 +273,30 @@ do --init STAGE DIRECTOR
|
||||
end
|
||||
|
||||
trigger.action.outTextForGroup(groupId, "Status Update incoming... ", 3)
|
||||
trigger.action.outTextForGroup(groupId, " " .. self.zoneName, 3)
|
||||
|
||||
local text = "Mission Status: \n"
|
||||
|
||||
local totalmissions = 0
|
||||
local completedMissions = 0
|
||||
for _, mission in pairs(self.db.missionsByCode) do
|
||||
totalmissions = totalmissions + 1
|
||||
if mission.missionState == Spearhead.internal.Mission.MissionState.ACTIVE then
|
||||
self.logger:debug("blaat")
|
||||
|
||||
text = text .. "\n [" .. mission.code .. "] " .. mission.name ..
|
||||
" (" .. mission.missionTypeDisplayName .. ") \n"
|
||||
end
|
||||
|
||||
if mission.missionState == Spearhead.internal.Mission.MissionState.COMPLETED then
|
||||
completedMissions = completedMissions + 1
|
||||
end
|
||||
end
|
||||
|
||||
local completionPercentage = math.floor((completedMissions / totalmissions) * 100)
|
||||
text = text .. " \n Missions Complete: " .. completionPercentage .. "%"
|
||||
|
||||
self.logger:debug(text)
|
||||
trigger.action.outTextForGroup(groupId, text, 20)
|
||||
end
|
||||
|
||||
o.OnStageNumberChanged = function (self, number)
|
||||
@@ -245,21 +305,78 @@ do --init STAGE DIRECTOR
|
||||
return
|
||||
end
|
||||
|
||||
local previousActive = self.activeStage
|
||||
self.activeStage = number
|
||||
|
||||
if Spearhead.capInfo.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then
|
||||
self:PreActivate()
|
||||
end
|
||||
|
||||
if number == self.stageNumber then
|
||||
self:ActiveStage()
|
||||
self:ActivateStage()
|
||||
end
|
||||
|
||||
if number > self.stageNumber then
|
||||
self:ActivateBlueStage()
|
||||
if previousActive <= self.stageNumber then
|
||||
if number > self.stageNumber then
|
||||
self:ActivateBlueStage()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- input = { self, groupId, missionCode }
|
||||
local ShowBriefingClicked = function (input)
|
||||
|
||||
local self = input.self
|
||||
local groupId = input.groupId
|
||||
local missionCode = input.missionCode
|
||||
|
||||
local mission = self.db.missionsByCode[missionCode]
|
||||
if mission then
|
||||
mission:ShowBriefing(groupId)
|
||||
end
|
||||
end
|
||||
|
||||
o.AddCommandsForMissionToGroup = function (self, groupId, mission)
|
||||
local folderName = mission.name .. "(" .. mission.missionTypeDisplayName .. ")"
|
||||
missionCommands.addSubMenuForGroup(groupId, folderName, { "Missions"} )
|
||||
missionCommands.addCommandForGroup(groupId, "Show Briefing", { "Missions", folderName }, ShowBriefingClicked, { self = self, groupId = groupId, missionCode = mission.code })
|
||||
self.logger:debug("blaat added command")
|
||||
|
||||
end
|
||||
|
||||
o.AddCommmandsForMissionToAllPlayers = function(self, mission)
|
||||
for i = 0, 2 do
|
||||
local players = coalition.getPlayers(i)
|
||||
for _, playerUnit in pairs(players) do
|
||||
local groupId = playerUnit:getGroup():getID()
|
||||
self:AddCommandsForMissionToGroup(groupId, mission)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
o.OnPlayerEntersUnit = function (self, unit)
|
||||
if self.activeStage == self.stageNumber then
|
||||
local groupId = unit:getGroup():getID()
|
||||
for _, mission in pairs(self.db.missionsByCode) do
|
||||
if mission.missionState == Spearhead.internal.Mission.MissionState.ACTIVE then
|
||||
self:AddCommandsForMissionToGroup(groupId, mission)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
o.OnMissionComplete = function(self, mission)
|
||||
local folderName = mission.name .. "(" .. mission.missionTypeDisplayName .. ")"
|
||||
for i = 0, 2 do
|
||||
local players = coalition.getPlayers(i)
|
||||
for _, playerUnit in pairs(players) do
|
||||
local groupId = playerUnit:getGroup():getID()
|
||||
missionCommands.removeItemForGroup(groupId, { "Missions", folderName })
|
||||
end
|
||||
end
|
||||
timer.scheduleFunction(activateMissionsIfApplicableAsync, self, timer.getTime() + 10)
|
||||
end
|
||||
|
||||
|
||||
Spearhead.Events.AddOnStatusRequestReceivedListener(o)
|
||||
Spearhead.Events.AddStageNumberChangedListener(o)
|
||||
return o
|
||||
|
||||
Reference in New Issue
Block a user