Added automatic stage continuation
This commit is contained in:
@@ -663,7 +663,7 @@ do -- INIT DCS_UTIL
|
|||||||
end
|
end
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param zone_name any
|
---@param airbaseId any
|
||||||
---@return table? zone { name,b zone_type, x, z, radius, verts }
|
---@return table? zone { name,b zone_type, x, z, radius, verts }
|
||||||
function DCS_UTIL.getAirbaseZoneById(airbaseId)
|
function DCS_UTIL.getAirbaseZoneById(airbaseId)
|
||||||
local string = tostring(airbaseId)
|
local string = tostring(airbaseId)
|
||||||
|
|||||||
@@ -1,22 +1,47 @@
|
|||||||
|
|
||||||
|
|
||||||
local StagesByName = {}
|
local StagesByName = {}
|
||||||
|
local StagesByIndex = {}
|
||||||
|
|
||||||
|
|
||||||
GlobalStageManager = {}
|
GlobalStageManager = {}
|
||||||
GlobalStageManager.start = function (database, stageConfig)
|
function GlobalStageManager:NewAndStart(database, stageConfig)
|
||||||
|
|
||||||
|
local o = {}
|
||||||
|
setmetatable(o, { __index = self })
|
||||||
|
|
||||||
|
o.onStageCompleted = function(stage)
|
||||||
|
|
||||||
|
local stageNumber = tostring(stage.stageNumber)
|
||||||
|
local anyActive = false
|
||||||
|
for _, stage in pairs(StagesByIndex[stageNumber] or {}) do
|
||||||
|
if stage.isActive then anyActive = true end
|
||||||
|
end
|
||||||
|
|
||||||
|
if anyActive == false and stageConfig:isAutoStages() == true then
|
||||||
|
Spearhead.Events.PublishStageNumberChanged(tonumber(stageNumber) + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local logger = Spearhead.LoggerTemplate:new("StageManager", stageConfig.logLevel)
|
||||||
|
|
||||||
for _, stageName in pairs(database:getStagezoneNames()) do
|
for _, stageName in pairs(database:getStagezoneNames()) do
|
||||||
|
|
||||||
local logger = Spearhead.LoggerTemplate:new(stageName, stageConfig.logLevel)
|
local stagelogger = Spearhead.LoggerTemplate:new(stageName, stageConfig.logLevel)
|
||||||
local stage = Spearhead.internal.Stage:new(stageName, database, logger, stageConfig)
|
local stage = Spearhead.internal.Stage:new(stageName, database, stagelogger, stageConfig)
|
||||||
|
|
||||||
StagesByName[stageName] = stage
|
|
||||||
|
|
||||||
local logger = Spearhead.LoggerTemplate:new("StageManager", stageConfig.logLevel)
|
|
||||||
logger:info("Initiated " .. Spearhead.Util.tableLength(StagesByName) .. " airbases for cap")
|
|
||||||
|
|
||||||
|
if stage then
|
||||||
|
stage:AddStageCompleteListener(o);
|
||||||
|
StagesByName[stageName] = stage
|
||||||
|
local indexString = tostring(stage.stageNumber)
|
||||||
|
if StagesByIndex[indexString] == nil then StagesByIndex[indexString] = {} end
|
||||||
|
table.insert(StagesByIndex[indexString], stage)
|
||||||
|
logger:info("Initiated " .. Spearhead.Util.tableLength(StagesByName) .. " airbases for cap")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
if not Spearhead.internal then Spearhead.internal = {} end
|
if not Spearhead.internal then Spearhead.internal = {} end
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
|
|
||||||
o.stageNumber = orderNumber
|
o.stageNumber = orderNumber
|
||||||
|
o.isActive = false
|
||||||
o.database = database
|
o.database = database
|
||||||
o.logger = logger
|
o.logger = logger
|
||||||
o.db = {}
|
o.db = {}
|
||||||
@@ -116,7 +117,7 @@ do --init STAGE DIRECTOR
|
|||||||
o.StageCompleteListeners = {}
|
o.StageCompleteListeners = {}
|
||||||
---comment
|
---comment
|
||||||
---@param self table
|
---@param self table
|
||||||
---@param StageCompleteListener table a Object with tage
|
---@param StageCompleteListener table an Object with function onStageCompleted(stage)
|
||||||
o.AddStageCompleteListener = function(self, StageCompleteListener)
|
o.AddStageCompleteListener = function(self, StageCompleteListener)
|
||||||
|
|
||||||
if type(StageCompleteListener) ~= "table" then
|
if type(StageCompleteListener) ~= "table" then
|
||||||
@@ -126,9 +127,15 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
|
|
||||||
local triggerStageCompleteListeners = function(self)
|
local triggerStageCompleteListeners = function(self)
|
||||||
--[[
|
self.isActive = false
|
||||||
TODO: Trigger Stage complete
|
for _, callable in pairs(self.MissionCompleteListeners) do
|
||||||
]]
|
local succ, err = pcall( function()
|
||||||
|
callable:OnMissionComplete(self)
|
||||||
|
end)
|
||||||
|
if err then
|
||||||
|
self.logger:warn("Error in misstion complete listener:" .. err)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -179,7 +186,7 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
|
|
||||||
local zone = Spearhead.DcsUtil.getZoneByName(self.zoneName)
|
local zone = Spearhead.DcsUtil.getZoneByName(self.zoneName)
|
||||||
if zone then
|
if zone and self.stageConfig:isDrawStagesEnabled() == true then
|
||||||
self.logger:debug("drawing stage")
|
self.logger:debug("drawing stage")
|
||||||
if zone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then
|
if zone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then
|
||||||
trigger.action.circleToAll(-1, self.stageDrawingId, {x = zone.x, y = 0 , z = zone.z}, zone.radius, {0,0,0,0}, {0,0,0,0},4, true)
|
trigger.action.circleToAll(-1, self.stageDrawingId, {x = zone.x, y = 0 , z = zone.z}, zone.radius, {0,0,0,0}, {0,0,0,0},4, true)
|
||||||
@@ -194,6 +201,8 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
|
|
||||||
o.ActivateStage = function(self)
|
o.ActivateStage = function(self)
|
||||||
|
self.isActive = true;
|
||||||
|
|
||||||
pcall(function()
|
pcall(function()
|
||||||
self:MarkStage()
|
self:MarkStage()
|
||||||
end)
|
end)
|
||||||
@@ -437,7 +446,7 @@ do --init STAGE DIRECTOR
|
|||||||
timer.scheduleFunction(removeMissionCommandsDelayed, { self = self, mission = mission}, timer.getTime() + 20)
|
timer.scheduleFunction(removeMissionCommandsDelayed, { self = self, mission = mission}, timer.getTime() + 20)
|
||||||
|
|
||||||
if(self:IsComplete()) then
|
if(self:IsComplete()) then
|
||||||
|
timer.scheduleFunction(triggerStageCompleteListeners, self, timer.getTime() + 15)
|
||||||
else
|
else
|
||||||
timer.scheduleFunction(activateMissionsIfApplicableAsync, self, timer.getTime() + 10)
|
timer.scheduleFunction(activateMissionsIfApplicableAsync, self, timer.getTime() + 10)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user