Fixed bugs found in v0.0.2
This commit is contained in:
@@ -21,7 +21,7 @@ GlobalStageManager = {}
|
||||
---@param stageConfig StageConfig
|
||||
---@return nil
|
||||
function GlobalStageManager:NewAndStart(database, stageConfig)
|
||||
local logger = Spearhead.LoggerTemplate:new("StageManager", stageConfig.logLevel)
|
||||
local logger = Spearhead.LoggerTemplate.new("StageManager", stageConfig.logLevel)
|
||||
logger:info("Using Stage Log Level: " .. stageConfig.logLevel)
|
||||
local o = {}
|
||||
setmetatable(o, { __index = self })
|
||||
@@ -86,7 +86,9 @@ function GlobalStageManager:NewAndStart(database, stageConfig)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
for _, stageName in pairs(database:getStagezoneNames()) do
|
||||
logger:debug("Found stage zone with name: " .. stageName)
|
||||
|
||||
if Spearhead.Util.startswith(stageName, "missionstage", true) then
|
||||
local valid = true
|
||||
@@ -98,7 +100,6 @@ function GlobalStageManager:NewAndStart(database, stageConfig)
|
||||
|
||||
if Spearhead.Util.tableLength(split) < 3 then
|
||||
Spearhead.AddMissionEditorWarning("Stage zone with name " .. stageName .. " does not have a stage name")
|
||||
valid = false
|
||||
end
|
||||
|
||||
local orderNumber = nil
|
||||
@@ -108,7 +109,7 @@ function GlobalStageManager:NewAndStart(database, stageConfig)
|
||||
if Spearhead.Util.startswith(orderNumberString, "x") == true then
|
||||
isSideStage = true
|
||||
|
||||
local orderNumberString = string.gsub(orderNumberString, "x", "")
|
||||
orderNumberString = string.gsub(orderNumberString, "x", "")
|
||||
orderNumber = tonumber(orderNumberString)
|
||||
else
|
||||
orderNumber = tonumber(split[2])
|
||||
@@ -121,7 +122,7 @@ function GlobalStageManager:NewAndStart(database, stageConfig)
|
||||
end
|
||||
|
||||
local stageDisplayName = split[3]
|
||||
local stagelogger = Spearhead.LoggerTemplate:new(stageName, stageConfig.logLevel)
|
||||
local stagelogger = Spearhead.LoggerTemplate.new(stageName, stageConfig.logLevel)
|
||||
if valid == true and orderNumber then
|
||||
|
||||
---@type StageInitData
|
||||
@@ -174,7 +175,7 @@ function GlobalStageManager:NewAndStart(database, stageConfig)
|
||||
end
|
||||
|
||||
if valid == true then
|
||||
local stagelogger = Spearhead.LoggerTemplate:new(stageName, stageConfig.logLevel)
|
||||
local stagelogger = Spearhead.LoggerTemplate.new(stageName, stageConfig.logLevel)
|
||||
|
||||
---@type WaitingStageInitData
|
||||
local initData = {
|
||||
|
||||
@@ -17,6 +17,7 @@ function SpearheadGroup.New(groupName)
|
||||
self.isStatic = Spearhead.DcsUtil.IsGroupStatic(groupName) == true
|
||||
self.groupName = groupName
|
||||
self.isSpawned = false
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -44,9 +45,9 @@ function SpearheadGroup:Spawn()
|
||||
|
||||
if self.isSpawned == true then return end
|
||||
|
||||
local group = Spearhead.DcsUtil.SpawnGroupTemplate(self.groupName)
|
||||
if group then
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
local spawned, isStatic = Spearhead.DcsUtil.SpawnGroupTemplate(self.groupName)
|
||||
if spawned and isStatic == false then
|
||||
for _, unit in pairs(spawned:getUnits()) do
|
||||
local deathState = Spearhead.classes.persistence.Persistence.UnitDeadState(unit:getName())
|
||||
|
||||
if deathState and deathState.isDead == true then
|
||||
@@ -58,6 +59,12 @@ function SpearheadGroup:Spawn()
|
||||
|
||||
Spearhead.Events.addOnUnitLostEventListener(unit:getName(), self)
|
||||
end
|
||||
elseif spawned and isStatic == true then
|
||||
if spawned then
|
||||
Spearhead.Events.addOnUnitLostEventListener(spawned:getName(), self)
|
||||
end
|
||||
else
|
||||
Spearhead.LoggerTemplate.new("SPEARHEADGROUP", "ERROR"):error("Failed to spawn group: " .. self.groupName)
|
||||
end
|
||||
|
||||
self.isSpawned = true
|
||||
@@ -73,9 +80,15 @@ end
|
||||
function SpearheadGroup:GetCoalition()
|
||||
if self.isStatic == true then
|
||||
local object = StaticObject.getByName(self.groupName)
|
||||
if object == nil then
|
||||
return 0
|
||||
end
|
||||
return object:getCoalition()
|
||||
else
|
||||
local group = Group.getByName(self.groupName)
|
||||
if group == nil then
|
||||
return 0
|
||||
end
|
||||
return group:getCoalition()
|
||||
end
|
||||
end
|
||||
@@ -102,6 +115,7 @@ function SpearheadGroup:GetUnits()
|
||||
end
|
||||
else
|
||||
local group = Group.getByName(self.groupName)
|
||||
if not group then return {} end
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
table.insert(result, unit)
|
||||
end
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
---@field private _red_groups Array<SpearheadGroup>
|
||||
---@field private _blue_groups Array<SpearheadGroup>
|
||||
---@field private _cleanup_units table<string, boolean>
|
||||
---@field private _airbase table?
|
||||
---@field private _airbase Airbase?
|
||||
---@field private _initialSide number?
|
||||
local StageBase = {}
|
||||
|
||||
---comment
|
||||
---@param databaseManager table
|
||||
---@param databaseManager Database
|
||||
---@param logger table
|
||||
---@param airbaseId integer
|
||||
---@param airbaseName string
|
||||
---@return StageBase
|
||||
function StageBase.New(databaseManager, logger, airbaseId)
|
||||
function StageBase.New(databaseManager, logger, airbaseName)
|
||||
|
||||
StageBase.__index = StageBase
|
||||
local self = setmetatable({}, StageBase)
|
||||
@@ -27,35 +27,35 @@ function StageBase.New(databaseManager, logger, airbaseId)
|
||||
self._blue_groups = {}
|
||||
self._cleanup_units = {}
|
||||
|
||||
self._airbase = Spearhead.DcsUtil.getAirbaseById(airbaseId)
|
||||
self._initialSide = Spearhead.DcsUtil.getStartingCoalition(airbaseId)
|
||||
self._airbase = Airbase.getByName(airbaseName)
|
||||
self._initialSide = Spearhead.DcsUtil.getStartingCoalition(self._airbase)
|
||||
|
||||
do --init
|
||||
local redUnitsPos = {}
|
||||
local blueUnitsPos = {}
|
||||
|
||||
do -- fill tables
|
||||
local redGroups = databaseManager:getRedGroupsAtAirbase(airbaseId)
|
||||
local redGroups = databaseManager:getRedGroupsAtAirbase(airbaseName)
|
||||
if redGroups then
|
||||
for _, groupName in pairs(redGroups) do
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
table.insert(self._red_groups, shGroup)
|
||||
for _, groupName in pairs(redGroups) do
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
table.insert(self._red_groups, shGroup)
|
||||
|
||||
for _, unit in shGroup:GetUnits() do
|
||||
redUnitsPos[unit:getName()] = unit:getPoint()
|
||||
for _, unit in pairs(shGroup:GetUnits()) do
|
||||
redUnitsPos[unit:getName()] = unit:getPoint()
|
||||
end
|
||||
|
||||
shGroup:Destroy()
|
||||
end
|
||||
|
||||
shGroup:Destroy()
|
||||
end
|
||||
end
|
||||
|
||||
local blueGroups = databaseManager:getBlueGroupsAtAirbase(airbaseId)
|
||||
local blueGroups = databaseManager:getBlueGroupsAtAirbase(airbaseName)
|
||||
if blueGroups then
|
||||
for _, groupName in pairs(blueGroups) do
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
table.insert(self._blue_groups, shGroup)
|
||||
|
||||
for _, unit in shGroup:GetUnits() do
|
||||
for _, unit in pairs(shGroup:GetUnits()) do
|
||||
blueUnitsPos[unit:getName()] = unit:getPoint()
|
||||
end
|
||||
|
||||
|
||||
@@ -43,23 +43,16 @@
|
||||
--- @field protected OnPostBlueActivated fun(self:Stage)?
|
||||
local Stage = {}
|
||||
|
||||
Stage.__index = Stage
|
||||
|
||||
local stageDrawingId = 100
|
||||
|
||||
---comment
|
||||
---@param database Database
|
||||
---@param stageConfig StageConfig
|
||||
---@param logger any
|
||||
---@param initData StageInitData
|
||||
---@param missionPriority MissionPriority
|
||||
---@return Stage
|
||||
function Stage.New(database, stageConfig, logger, initData, missionPriority)
|
||||
function Stage:superNew(database, stageConfig, logger, initData, missionPriority)
|
||||
|
||||
logger:debug("[BaseStage] Initiating stage with name: " .. initData.stageZoneName)
|
||||
|
||||
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup
|
||||
|
||||
Stage.__index = Stage
|
||||
local o = {}
|
||||
local self = setmetatable(o, Stage)
|
||||
|
||||
self.zoneName = initData.stageZoneName
|
||||
self.stageNumber = initData.stageNumber
|
||||
self._isActive = false
|
||||
@@ -148,10 +141,10 @@ function Stage.New(database, stageConfig, logger, initData, missionPriority)
|
||||
mission:AddMissionCompleteListener(self)
|
||||
end
|
||||
|
||||
local airbaseIds = database:getAirbaseIdsInStage(self.zoneName)
|
||||
if airbaseIds ~= nil and type(airbaseIds) == "table" then
|
||||
for _, airbaseId in pairs(airbaseIds) do
|
||||
local airbase = Spearhead.classes.stageClasses.SpecialZones.StageBase.New(database, logger, airbaseId)
|
||||
local airbaseNames = database:getAirbaseNamesInStage(self.zoneName)
|
||||
if airbaseNames ~= nil and type(airbaseNames) == "table" then
|
||||
for _, airbaseName in pairs(airbaseNames) do
|
||||
local airbase = Spearhead.classes.stageClasses.SpecialZones.StageBase.New(database, logger, airbaseName)
|
||||
table.insert(self._db.airbases, airbase)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
---@class ExtraStage : Stage
|
||||
local ExtraStage = {}
|
||||
|
||||
ExtraStage.__index = ExtraStage
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(ExtraStage, Stage)
|
||||
|
||||
---comment
|
||||
---@param database Database
|
||||
---@param stageConfig StageConfig
|
||||
@@ -10,20 +14,15 @@ local ExtraStage = {}
|
||||
---@return ExtraStage
|
||||
function ExtraStage.New(database, stageConfig, logger, initData)
|
||||
|
||||
-- "Import"
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(ExtraStage, Stage)
|
||||
|
||||
ExtraStage.__index = ExtraStage
|
||||
local self = Stage.New(database, stageConfig, logger, initData, "secondary") --[[@as ExtraStage]]
|
||||
setmetatable(self, ExtraStage)
|
||||
local self = setmetatable({}, { __index = ExtraStage }) --[[@as ExtraStage]]
|
||||
self:superNew(database, stageConfig, logger, initData)
|
||||
|
||||
self.OnPostBlueActivated = function (selfStage)
|
||||
selfStage:MarkStage("GRAY")
|
||||
end
|
||||
|
||||
self.OnPostStageComplete = function (selfStage)
|
||||
self:ActivateBlueStage()
|
||||
selfStage:ActivateBlueStage()
|
||||
end
|
||||
|
||||
return self
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
---@class PrimaryStage : Stage
|
||||
local PrimaryStage = {}
|
||||
|
||||
PrimaryStage.__index = PrimaryStage
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(PrimaryStage, Stage)
|
||||
|
||||
---comment
|
||||
---@param database Database
|
||||
---@param stageConfig StageConfig
|
||||
@@ -10,14 +14,10 @@ local PrimaryStage = {}
|
||||
---@return PrimaryStage
|
||||
function PrimaryStage.New(database, stageConfig, logger, initData)
|
||||
|
||||
-- "Import"
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(PrimaryStage, Stage)
|
||||
PrimaryStage.__index = PrimaryStage
|
||||
setmetatable(PrimaryStage, {__index = Stage})
|
||||
local self = setmetatable({}, { __index = PrimaryStage }) --[[@as PrimaryStage]]
|
||||
self:superNew(database, stageConfig, logger, initData)
|
||||
return self
|
||||
|
||||
local o = Stage.New(database, stageConfig, logger, initData, "primary") --[[@as PrimaryStage]]
|
||||
return o
|
||||
end
|
||||
|
||||
if not Spearhead.classes then Spearhead.classes = {} end
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
---@field private _startTime number
|
||||
local WaitingStage = {}
|
||||
|
||||
WaitingStage.__index = WaitingStage
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(WaitingStage, Stage)
|
||||
|
||||
---@class WaitingStageInitData : StageInitData
|
||||
---@field waitingSeconds integer
|
||||
@@ -17,14 +20,8 @@ local WaitingStageInitData = {}
|
||||
---@return WaitingStage
|
||||
function WaitingStage.New(database, stageConfig, logger, initData)
|
||||
|
||||
-- "Import"
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(WaitingStage, Stage)
|
||||
WaitingStage.__index = WaitingStage
|
||||
setmetatable(WaitingStage, {__index = Stage})
|
||||
|
||||
local self = Stage.New(database, stageConfig, logger, initData, "primary") --[[@as WaitingStage]]
|
||||
setmetatable(self, WaitingStage)
|
||||
local self = setmetatable({}, { __index = WaitingStage }) --[[@as WaitingStage]]
|
||||
self:superNew(database, stageConfig, logger, initData)
|
||||
|
||||
self._waitTimeSeconds = 5
|
||||
if initData.waitingSeconds and initData.waitingSeconds > 5 then self._waitTimeSeconds = initData.waitingSeconds end
|
||||
|
||||
Reference in New Issue
Block a user