Refactored Persistance managed by SpawnManager for groups, and added … (#53)
* Refactored Persistance managed by SpawnManager for groups, and added Persistence for buildables * get last file based on the iteration number * Working persistence of everything as a MVP version
This commit is contained in:
@@ -20,8 +20,9 @@ GlobalStageManager = {}
|
||||
---@param database Database
|
||||
---@param stageConfig StageConfig
|
||||
---@param logLevel LogLevel
|
||||
---@param spawnManager SpawnManager
|
||||
---@return nil
|
||||
function GlobalStageManager:NewAndStart(database, stageConfig, logLevel)
|
||||
function GlobalStageManager:NewAndStart(database, stageConfig, logLevel, spawnManager)
|
||||
local logger = Spearhead.LoggerTemplate.new("StageManager", logLevel)
|
||||
logger:info("Using Stage Log Level: " .. logLevel)
|
||||
local o = {}
|
||||
@@ -134,13 +135,13 @@ function GlobalStageManager:NewAndStart(database, stageConfig, logLevel)
|
||||
}
|
||||
|
||||
if isSideStage == true then
|
||||
local stage = Spearhead.classes.stageClasses.Stages.ExtraStage.New(database, stageConfig, stagelogger, initData)
|
||||
local stage = Spearhead.classes.stageClasses.Stages.ExtraStage.New(database, stageConfig, stagelogger, initData, spawnManager)
|
||||
stage:AddStageCompleteListener(OnStageCompleteListener)
|
||||
|
||||
if SideStageByIndex[tostring(orderNumber)] == nil then SideStageByIndex[tostring(orderNumber)] = {} end
|
||||
table.insert(SideStageByIndex[tostring(orderNumber)], stage)
|
||||
else
|
||||
local stage = Spearhead.classes.stageClasses.Stages.PrimaryStage.New(database, stageConfig, stagelogger, initData)
|
||||
local stage = Spearhead.classes.stageClasses.Stages.PrimaryStage.New(database, stageConfig, stagelogger, initData, spawnManager)
|
||||
stage:AddStageCompleteListener(OnStageCompleteListener)
|
||||
|
||||
if StagesByIndex[tostring(orderNumber)] == nil then StagesByIndex[tostring(orderNumber)] = {} end
|
||||
@@ -185,7 +186,7 @@ function GlobalStageManager:NewAndStart(database, stageConfig, logLevel)
|
||||
stageZoneName = stageName,
|
||||
waitingSeconds = waitingSeconds --[[@as integer]]
|
||||
}
|
||||
local waitingStage = Spearhead.classes.stageClasses.Stages.WaitingStage.New(database, stageConfig, stagelogger, initData)
|
||||
local waitingStage = Spearhead.classes.stageClasses.Stages.WaitingStage.New(database, stageConfig, stagelogger, initData, spawnManager)
|
||||
|
||||
if WaitingStagesByIndex[tostring(stageIndex)] == nil then
|
||||
WaitingStagesByIndex[tostring(stageIndex)] = {}
|
||||
|
||||
@@ -2,22 +2,38 @@
|
||||
|
||||
|
||||
---@class SpearheadGroup : OnUnitLostListener
|
||||
---@field groupName string
|
||||
---@field private _groupName string
|
||||
---@field private _isStatic boolean
|
||||
---@field private _isSpawned boolean
|
||||
---@field private _spawnManager SpawnManager
|
||||
---@field private _isPersistent boolean
|
||||
local SpearheadGroup = {}
|
||||
SpearheadGroup.__index = SpearheadGroup
|
||||
|
||||
function SpearheadGroup.New(groupName)
|
||||
---comment
|
||||
---@param groupName string
|
||||
---@param spawnManager SpawnManager
|
||||
---@param isPersistent boolean?
|
||||
---@return SpearheadGroup
|
||||
function SpearheadGroup.New(groupName, spawnManager, isPersistent)
|
||||
local self = setmetatable({}, SpearheadGroup)
|
||||
|
||||
self._isStatic = Spearhead.DcsUtil.IsGroupStatic(groupName) == true
|
||||
self.groupName = groupName
|
||||
if isPersistent == nil then isPersistent = false end
|
||||
|
||||
self._spawnManager = spawnManager
|
||||
self._isStatic = spawnManager:IsGroupStatic(groupName) == true
|
||||
self._groupName = groupName
|
||||
self._isSpawned = false
|
||||
self._isPersistent = isPersistent
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
function SpearheadGroup:GetName()
|
||||
return self._groupName
|
||||
end
|
||||
|
||||
function SpearheadGroup:IsSpawned()
|
||||
return self._isSpawned
|
||||
end
|
||||
@@ -25,27 +41,8 @@ end
|
||||
function SpearheadGroup:SpawnCorpsesOnly()
|
||||
|
||||
if self._isSpawned == true then return end
|
||||
|
||||
local group, isStatic = Spearhead.DcsUtil.SpawnGroupTemplate(self.groupName)
|
||||
if isStatic == true then
|
||||
self._isStatic = true
|
||||
local deathState = Spearhead.classes.persistence.Persistence.UnitDeadState(self.groupName)
|
||||
if deathState and deathState.isDead == true then
|
||||
Spearhead.DcsUtil.DestroyGroup(self.groupName)
|
||||
Spearhead.DcsUtil.SpawnCorpse(deathState.country_id, self.groupName, deathState.type, deathState.pos, deathState.heading)
|
||||
end
|
||||
else
|
||||
if group then
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
local deathState = Spearhead.classes.persistence.Persistence.UnitDeadState(unit:getName())
|
||||
Spearhead.DcsUtil.DestroyUnit(unit:getName())
|
||||
if deathState and deathState.isDead == true then
|
||||
Spearhead.DcsUtil.SpawnCorpse(deathState.country_id, unit:getName(), deathState.type, deathState.pos, deathState.heading)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
self._spawnManager:SpawnCorpsesOnly(self._groupName)
|
||||
self._isSpawned = true
|
||||
|
||||
end
|
||||
@@ -55,52 +52,19 @@ function SpearheadGroup:Spawn(lateStart)
|
||||
|
||||
if self._isSpawned == true then return end
|
||||
|
||||
local spawned, isStatic = Spearhead.DcsUtil.SpawnGroupTemplate(self.groupName, nil, nil, lateStart)
|
||||
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
|
||||
Spearhead.DcsUtil.DestroyUnit(self.groupName, unit:getName())
|
||||
Spearhead.DcsUtil.SpawnCorpse(deathState.country_id, unit:getName(), deathState.type, deathState.pos, deathState.heading)
|
||||
else
|
||||
Spearhead.Events.addOnUnitLostEventListener(unit:getName(), self)
|
||||
end
|
||||
|
||||
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
|
||||
---@type SpawnOverrides
|
||||
local overrides = {
|
||||
uncontrolled = lateStart or false,
|
||||
}
|
||||
|
||||
local spawnedObject, isStatic = self._spawnManager:SpawnGroup(self._groupName, overrides, self._isPersistent)
|
||||
self._isStatic = isStatic
|
||||
self._isSpawned = true
|
||||
end
|
||||
|
||||
function SpearheadGroup:Activate()
|
||||
|
||||
if self._isStatic == true then return end
|
||||
|
||||
local group = Group.getByName(self.groupName)
|
||||
if group then
|
||||
group:activate()
|
||||
|
||||
local controller = group:getController()
|
||||
if controller then
|
||||
controller:setCommand({
|
||||
id = 'Start',
|
||||
params = {}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SpearheadGroup:Destroy()
|
||||
self._isSpawned = false
|
||||
Spearhead.DcsUtil.DestroyGroup(self.groupName)
|
||||
self._spawnManager:DestroyGroup(self._groupName)
|
||||
end
|
||||
|
||||
---@return boolean
|
||||
@@ -112,13 +76,13 @@ end
|
||||
---@return integer
|
||||
function SpearheadGroup:GetCoalition()
|
||||
if self._isStatic == true then
|
||||
local object = StaticObject.getByName(self.groupName)
|
||||
local object = StaticObject.getByName(self._groupName)
|
||||
if object == nil then
|
||||
return 0
|
||||
end
|
||||
return object:getCoalition()
|
||||
else
|
||||
local group = Group.getByName(self.groupName)
|
||||
local group = Group.getByName(self._groupName)
|
||||
if group == nil then
|
||||
return 0
|
||||
end
|
||||
@@ -126,28 +90,18 @@ function SpearheadGroup:GetCoalition()
|
||||
end
|
||||
end
|
||||
|
||||
function SpearheadGroup:OnUnitLost(object)
|
||||
local name = object:getName()
|
||||
local pos = object:getPoint()
|
||||
local type = object:getDesc().typeName
|
||||
local position = object:getPosition()
|
||||
local heading = math.atan2(position.x.z, position.x.x)
|
||||
local country_id = object:getCountry()
|
||||
Spearhead.classes.persistence.Persistence.UnitKilled(name, pos, heading, type, country_id)
|
||||
end
|
||||
|
||||
---comment
|
||||
---@return table result list of objects
|
||||
function SpearheadGroup:GetObjects()
|
||||
|
||||
local result = {}
|
||||
if self._isStatic == true then
|
||||
local staticObject = StaticObject.getByName(self.groupName)
|
||||
local staticObject = StaticObject.getByName(self._groupName)
|
||||
if staticObject then
|
||||
table.insert(result, staticObject)
|
||||
end
|
||||
else
|
||||
local group = Group.getByName(self.groupName)
|
||||
local group = Group.getByName(self._groupName)
|
||||
if not group then return {} end
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
table.insert(result, unit)
|
||||
@@ -165,7 +119,7 @@ function SpearheadGroup:GetAsUnits()
|
||||
end
|
||||
|
||||
local result = {}
|
||||
local group = Group.getByName(self.groupName)
|
||||
local group = Group.getByName(self._groupName)
|
||||
if not group then return {} end
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
table.insert(result, unit)
|
||||
@@ -178,12 +132,12 @@ function SpearheadGroup:GetAllUnitPositions()
|
||||
|
||||
local result = {}
|
||||
if self._isStatic == true then
|
||||
local staticObject = StaticObject.getByName(self.groupName)
|
||||
local staticObject = StaticObject.getByName(self._groupName)
|
||||
if staticObject then
|
||||
table.insert(result, staticObject:getPoint())
|
||||
end
|
||||
else
|
||||
local group = Group.getByName(self.groupName)
|
||||
local group = Group.getByName(self._groupName)
|
||||
if not group then return {} end
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
table.insert(result, unit:getPoint())
|
||||
@@ -196,9 +150,15 @@ function SpearheadGroup:SetInvisible()
|
||||
|
||||
if self._isStatic == true then
|
||||
local country = Spearhead.DcsUtil.GetNeutralCountry()
|
||||
Spearhead.DcsUtil.SpawnGroupTemplate(self.groupName, nil, nil, nil, country)
|
||||
|
||||
---@type SpawnOverrides
|
||||
local overrides = {
|
||||
countryID = country
|
||||
}
|
||||
|
||||
self._spawnManager:SpawnGroup(self._groupName, overrides, self._isPersistent)
|
||||
else
|
||||
local group = Group.getByName(self.groupName)
|
||||
local group = Group.getByName(self._groupName)
|
||||
if group then
|
||||
local setInvisible = {
|
||||
id = 'SetInvisible',
|
||||
@@ -215,7 +175,7 @@ end
|
||||
|
||||
function SpearheadGroup:SetVisible()
|
||||
|
||||
local group = Group.getByName(self.groupName)
|
||||
local group = Group.getByName(self._groupName)
|
||||
if group then
|
||||
local setInvisible = {
|
||||
id = 'SetInvisible',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
---@class BlueSam : OnCrateDroppedListener, MissionCompleteListener
|
||||
---@class BlueSam : BuildableZone
|
||||
---@field Activate fun(self: BlueSam)
|
||||
---@field private _database Database
|
||||
---@field private _logger Logger
|
||||
@@ -11,13 +11,16 @@
|
||||
---@field private _unitsPerCrate number?
|
||||
---@field private _buildableMission BuildableMission?
|
||||
local BlueSam = {}
|
||||
BlueSam.__index = BlueSam
|
||||
|
||||
---@param database Database
|
||||
---@param logger Logger
|
||||
---@param zoneName string
|
||||
---@param spawnManager SpawnManager
|
||||
---@return BlueSam?
|
||||
function BlueSam.New(database, logger, zoneName)
|
||||
BlueSam.__index = BlueSam
|
||||
function BlueSam.New(database, logger, zoneName, spawnManager)
|
||||
|
||||
setmetatable(BlueSam, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone)
|
||||
local self = setmetatable({}, BlueSam)
|
||||
|
||||
self._database = database
|
||||
@@ -44,15 +47,19 @@ function BlueSam.New(database, logger, zoneName)
|
||||
local redUnitsPos = {}
|
||||
|
||||
|
||||
local buildable = false
|
||||
if self._buildableCrateKilos and self._buildableCrateKilos > 0 then
|
||||
buildable = true
|
||||
end
|
||||
|
||||
for _, groupName in pairs(blueSamData.groups) do
|
||||
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true)
|
||||
if SpearheadGroup then
|
||||
|
||||
if SpearheadGroup:GetCoalition() == 2 then
|
||||
if SpearheadGroup:GetCoalition() == 2 or SpearheadGroup:GetCoalition() == 0 then
|
||||
table.insert(self._blueGroups, SpearheadGroup)
|
||||
end
|
||||
|
||||
|
||||
for _, unit in pairs(SpearheadGroup:GetObjects()) do
|
||||
if SpearheadGroup:GetCoalition() == 1 then
|
||||
table.insert(blueUnitsPos, unit:getPoint())
|
||||
@@ -76,21 +83,11 @@ function BlueSam.New(database, logger, zoneName)
|
||||
end
|
||||
end
|
||||
|
||||
if self._buildableCrateKilos ~= nil and self._buildableCrateKilos ~= 0 then
|
||||
self._logger:debug("Buildable mission creating for zone: " .. zoneName .. " with crates: " .. self._buildableCrateKilos)
|
||||
|
||||
local noLandingZone = self:GetNoLandingZone()
|
||||
local zone = Spearhead.DcsUtil.getZoneByName(zoneName)
|
||||
if zone then
|
||||
self._buildableMission = Spearhead.classes.stageClasses.missions.BuildableMission.new(database, logger, zone, noLandingZone, self._buildableCrateKilos, "SAM_CRATE")
|
||||
self._buildableMission:AddOnCrateDroppedOfListener(self)
|
||||
self._buildableMission:AddMissionCompleteListener(self)
|
||||
end
|
||||
|
||||
local zone = Spearhead.DcsUtil.getZoneByName(zoneName)
|
||||
if zone then
|
||||
Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone.New(self, zone, self._buildableCrateKilos or 0, "SAM_CRATE", self._blueGroups, logger, database)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -132,21 +129,14 @@ function BlueSam:Activate()
|
||||
if self._buildableMission == nil then
|
||||
self:SpawnGroups()
|
||||
else
|
||||
self._buildableMission:SpawnActive()
|
||||
self:StartBuildable()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function BlueSam:SpawnGroups()
|
||||
for unitName, needsCleanup in pairs(self._cleanupUnits) do
|
||||
if needsCleanup == true then
|
||||
Spearhead.DcsUtil.DestroyUnit(unitName)
|
||||
else
|
||||
local deathState = Spearhead.classes.persistence.Persistence.UnitDeadState(unitName)
|
||||
if deathState and deathState.isDead == true then
|
||||
Spearhead.DcsUtil.SpawnCorpse(deathState.country_id, unitName, deathState.type, deathState.pos, deathState.heading)
|
||||
end
|
||||
end
|
||||
Spearhead.DcsUtil.DestroyUnit(unitName)
|
||||
end
|
||||
|
||||
for _, group in pairs(self._blueGroups) do
|
||||
@@ -154,25 +144,12 @@ function BlueSam:SpawnGroups()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---@param buildableMission BuildableMission
|
||||
---@param kilos number
|
||||
function BlueSam:OnCrateDroppedOff(buildableMission, kilos)
|
||||
|
||||
self._logger:debug("Crate dropped off in zone: " .. self._zoneName)
|
||||
self._receivedKilos = self._receivedKilos + kilos
|
||||
|
||||
end
|
||||
|
||||
---@param buildableMission Mission
|
||||
function BlueSam:OnMissionComplete(buildableMission)
|
||||
self._logger:debug("Buildable mission complete for zone: " .. self._zoneName)
|
||||
|
||||
function BlueSam:OnBuildingComplete()
|
||||
self:SpawnGroups()
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
if Spearhead == nil then Spearhead = {} end
|
||||
if Spearhead.classes == nil then Spearhead.classes = {} end
|
||||
if Spearhead.classes.stageClasses == nil then Spearhead.classes.stageClasses = {} end
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
|
||||
|
||||
---@class FarpZone : OnCrateDroppedListener, MissionCompleteListener
|
||||
---@class FarpZone: BuildableZone
|
||||
---@field private _startingFarp boolean
|
||||
---@field private _groups Array<SpearheadGroup>
|
||||
---@field private _padNames Array<string>
|
||||
---@field private _database Database
|
||||
---@field private _logger Logger
|
||||
---@field private _zoneName string
|
||||
---@field private _requiredBuildingKilos number
|
||||
---@field private _receivedBuildingKilos number
|
||||
---@field private _groupsPerKilo number
|
||||
---@field private _buildableMission BuildableMission?
|
||||
---@field private _supplyHubs Array<SupplyHub>
|
||||
local FarpZone = {}
|
||||
FarpZone.__index = FarpZone
|
||||
@@ -19,10 +15,10 @@ FarpZone.__index = FarpZone
|
||||
---@param database Database
|
||||
---@param logger Logger
|
||||
---@param zoneName string
|
||||
---@param spawnManager SpawnManager
|
||||
---@return FarpZone
|
||||
function FarpZone.New(database, logger, zoneName)
|
||||
|
||||
FarpZone.__index = FarpZone
|
||||
function FarpZone.New(database, logger, zoneName, spawnManager)
|
||||
setmetatable(FarpZone, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone)
|
||||
local self = setmetatable({}, FarpZone)
|
||||
|
||||
self._database = database
|
||||
@@ -54,34 +50,18 @@ function FarpZone.New(database, logger, zoneName)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for _, groupName in pairs(farpData.groups) do
|
||||
local group = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
local group = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true)
|
||||
table.insert(self._groups, group)
|
||||
group:Destroy()
|
||||
end
|
||||
|
||||
self._requiredBuildingKilos = farpData.buildingKilos
|
||||
self._receivedBuildingKilos = 0
|
||||
|
||||
if self._requiredBuildingKilos ~= nil and self._requiredBuildingKilos > 0 then
|
||||
self._logger:debug("FARP zone " .. zoneName .. " requires " .. self._requiredBuildingKilos .. " crates to be dropped off")
|
||||
local noLandingZone = self:GetNoLandingZone()
|
||||
local zone = Spearhead.DcsUtil.getZoneByName(zoneName)
|
||||
if zone then
|
||||
self._buildableMission = Spearhead.classes.stageClasses.missions.BuildableMission.new(database, logger, zone, noLandingZone, self._requiredBuildingKilos, "FARP_CRATE")
|
||||
if self._buildableMission then
|
||||
self._buildableMission:AddOnCrateDroppedOfListener(self)
|
||||
self._buildableMission:AddMissionCompleteListener(self)
|
||||
end
|
||||
|
||||
local totalGroups = Spearhead.Util.tableLength(self._groups)
|
||||
self._groupsPerKilo = totalGroups / self._requiredBuildingKilos
|
||||
end
|
||||
local zone = Spearhead.DcsUtil.getZoneByName(zoneName)
|
||||
if zone then
|
||||
Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone.New(self, zone, farpData.buildingKilos or 0, "FARP_CRATE", self._groups, logger, database)
|
||||
end
|
||||
end
|
||||
if self._buildableMission == nil then
|
||||
self._logger:debug("No buildable mission for zone: " .. zoneName)
|
||||
end
|
||||
self:Deactivate()
|
||||
|
||||
return self
|
||||
@@ -101,7 +81,7 @@ function FarpZone:Activate()
|
||||
self:SetPadsBlue()
|
||||
self:ActivateSupplyHubs()
|
||||
else
|
||||
self._buildableMission:SpawnActive()
|
||||
self:StartBuildable()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -109,101 +89,13 @@ function FarpZone:Deactivate()
|
||||
self:NeutralisePads()
|
||||
end
|
||||
|
||||
---@class UnpackCrateParam
|
||||
---@field self FarpZone
|
||||
---@field kilos number
|
||||
---@field groupsPerKilo number
|
||||
---@field kilosPerSecond number
|
||||
---@field unpackedItems number
|
||||
---@field unpackedKilos number
|
||||
|
||||
---@param params UnpackCrateParam
|
||||
---@param time number
|
||||
local startUnpackingCrate = function(params, time)
|
||||
local unpacked = params.unpackedKilos + (params.kilosPerSecond * 2)
|
||||
local alreadySpawned = params.unpackedItems / params.groupsPerKilo
|
||||
local diff = unpacked - alreadySpawned
|
||||
|
||||
local amount = math.floor(diff * params.groupsPerKilo)
|
||||
local spawned = params.self:SpawnAmount(amount)
|
||||
|
||||
params.unpackedItems = params.unpackedItems + amount
|
||||
params.unpackedKilos = unpacked
|
||||
if params.unpackedKilos >= params.kilos or spawned == false then
|
||||
params.self:FinaliseCrate(params.kilos)
|
||||
return
|
||||
end
|
||||
|
||||
return time + 2
|
||||
end
|
||||
|
||||
---comment
|
||||
---@param amount number
|
||||
---@return boolean
|
||||
function FarpZone:SpawnAmount(amount)
|
||||
|
||||
local function spawnOne()
|
||||
for _, group in pairs(self._groups) do
|
||||
if group:IsSpawned() == false then
|
||||
group:Spawn()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
for i = 1, amount do
|
||||
local spawned = spawnOne()
|
||||
if spawned ~= true then
|
||||
self._logger:debug("No more groups to spawn in zone: " .. self._zoneName)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
---@param buildableMission BuildableMission
|
||||
function FarpZone:OnCrateDroppedOff(buildableMission, kilos)
|
||||
|
||||
self._logger:debug("Crate dropped off in zone: " .. self._zoneName)
|
||||
|
||||
local timeToUnpack = (kilos / 500) * 15
|
||||
|
||||
---@type UnpackCrateParam
|
||||
local params = {
|
||||
self = self,
|
||||
groupsPerKilo = self._groupsPerKilo,
|
||||
unpackedItems = 0,
|
||||
kilosPerSecond = kilos/timeToUnpack,
|
||||
unpackedKilos = 0,
|
||||
kilos = kilos
|
||||
}
|
||||
|
||||
timer.scheduleFunction(startUnpackingCrate, params, timer.getTime() + 2)
|
||||
|
||||
end
|
||||
|
||||
---@param kilos number
|
||||
function FarpZone:FinaliseCrate(kilos)
|
||||
self._receivedBuildingKilos = self._receivedBuildingKilos + kilos
|
||||
if self._receivedBuildingKilos >= self._requiredBuildingKilos then
|
||||
self:BuildUp()
|
||||
self:SetPadsBlue()
|
||||
self:ActivateSupplyHubs()
|
||||
end
|
||||
end
|
||||
|
||||
---@param buildableMission Mission
|
||||
function FarpZone:OnMissionComplete(buildableMission)
|
||||
self._logger:debug("Buildable mission complete for zone: " .. self._zoneName)
|
||||
|
||||
-- self:BuildUp()
|
||||
-- self:SetPadsBlue()
|
||||
-- self:ActivateSupplyHubs()
|
||||
|
||||
function FarpZone:OnBuildingComplete()
|
||||
self:BuildUp()
|
||||
self:SetPadsBlue()
|
||||
self:ActivateSupplyHubs()
|
||||
end
|
||||
|
||||
---@private
|
||||
function FarpZone:BuildUp()
|
||||
for _, group in pairs(self._groups) do
|
||||
group:Spawn()
|
||||
@@ -239,40 +131,6 @@ function FarpZone:SetPadsBlue()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---@private
|
||||
---@return SpearheadTriggerZone?
|
||||
function FarpZone:GetNoLandingZone()
|
||||
|
||||
---@type Array<Vec2>
|
||||
local points = {}
|
||||
|
||||
for _, group in pairs(self._groups) do
|
||||
for _, unitPos in pairs(group:GetAllUnitPositions()) do
|
||||
table.insert(points, { x = unitPos.x, y = unitPos.z })
|
||||
end
|
||||
end
|
||||
|
||||
local vecs = Spearhead.Util.getConvexHull(points)
|
||||
|
||||
local zone = Spearhead.DcsUtil.getZoneByName(self._zoneName)
|
||||
if zone == nil then
|
||||
self._logger:error("Zone not found: " .. self._zoneName)
|
||||
return nil
|
||||
end
|
||||
|
||||
---@type SpearheadTriggerZone
|
||||
local spearheadZone = {
|
||||
name = self._zoneName .. "_noland",
|
||||
location = zone.location,
|
||||
verts = vecs,
|
||||
radius = 0,
|
||||
zone_type = "Polygon"
|
||||
}
|
||||
|
||||
return spearheadZone
|
||||
end
|
||||
|
||||
if Spearhead == nil then Spearhead = {} end
|
||||
if Spearhead.classes == nil then Spearhead.classes = {} end
|
||||
if Spearhead.classes.stageClasses == nil then Spearhead.classes.stageClasses = {} end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
---@class StageBase : OnCrateDroppedListener, MissionCompleteListener
|
||||
---@class StageBase : BuildableZone
|
||||
---@field private _database Database
|
||||
---@field private _logger Logger
|
||||
---@field private _red_groups Array<SpearheadGroup>
|
||||
@@ -12,14 +12,16 @@
|
||||
---@field private _receivedBuildingKilos number
|
||||
---@field private _buildableMission BuildableMission?
|
||||
local StageBase = {}
|
||||
StageBase.__index = StageBase
|
||||
|
||||
---comment
|
||||
---@param databaseManager Database
|
||||
---@param logger table
|
||||
---@param airbaseName string
|
||||
---@param spawnManager SpawnManager
|
||||
---@return StageBase?
|
||||
function StageBase.New(databaseManager, logger, airbaseName)
|
||||
StageBase.__index = StageBase
|
||||
function StageBase.New(databaseManager, logger, airbaseName, spawnManager)
|
||||
setmetatable(StageBase, Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone)
|
||||
local self = setmetatable({}, StageBase)
|
||||
|
||||
self._database = databaseManager
|
||||
@@ -47,7 +49,7 @@ function StageBase.New(databaseManager, logger, airbaseName)
|
||||
local blueUnitsPos = {}
|
||||
|
||||
for _, groupName in pairs(airbaseData.RedGroups) do
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true)
|
||||
table.insert(self._red_groups, shGroup)
|
||||
|
||||
for _, unit in pairs(shGroup:GetObjects()) do
|
||||
@@ -58,7 +60,7 @@ function StageBase.New(databaseManager, logger, airbaseName)
|
||||
end
|
||||
|
||||
for _, groupName in pairs(airbaseData.BlueGroups) do
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName, spawnManager, true)
|
||||
table.insert(self._blue_groups, shGroup)
|
||||
|
||||
for _, unit in pairs(shGroup:GetObjects()) do
|
||||
@@ -92,22 +94,9 @@ function StageBase.New(databaseManager, logger, airbaseName)
|
||||
end
|
||||
end
|
||||
|
||||
if airbaseData.buildingKilos ~= nil and airbaseData.buildingKilos > 0 then
|
||||
self._logger:debug("Airbase " .. airbaseName .. " requires " .. tostring(airbaseData.buildingKilos) .. " kilos to be dropped off")
|
||||
self._requiredBuildingKilos = airbaseData.buildingKilos
|
||||
self._receivedBuildingKilos = 0
|
||||
self._groupsPerKilo = Spearhead.Util.tableLength(self._blue_groups) / self._requiredBuildingKilos
|
||||
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbaseName)
|
||||
if zone then
|
||||
self._buildableMission = Spearhead.classes.stageClasses.missions.BuildableMission.new(databaseManager, logger, zone, self:GetNoLandingZone(), self._requiredBuildingKilos, "AIRBASE_CRATE")
|
||||
end
|
||||
|
||||
|
||||
if self._buildableMission then
|
||||
self._buildableMission:AddOnCrateDroppedOfListener(self)
|
||||
else
|
||||
self._logger:error("Failed to create buildable mission for airbase: " .. airbaseName)
|
||||
end
|
||||
local zone = Spearhead.DcsUtil.getAirbaseZoneByName(airbaseName)
|
||||
if zone then
|
||||
Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone.New(self, zone, airbaseData.buildingKilos or 0, "AIRBASE_CRATE", self._blue_groups, logger, databaseManager)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -172,11 +161,12 @@ function StageBase:ActivateBlueStage()
|
||||
|
||||
self:CleanRedUnits()
|
||||
|
||||
if self._buildableMission and self._buildableMission:getState() ~= "COMPLETED" then
|
||||
self._buildableMission:SpawnActive()
|
||||
return
|
||||
if self._buildableMission then
|
||||
self:StartBuildable()
|
||||
else
|
||||
self:FinaliseBlueStage()
|
||||
end
|
||||
self:FinaliseBlueStage()
|
||||
|
||||
end
|
||||
|
||||
function StageBase:FinaliseBlueStage()
|
||||
@@ -192,119 +182,9 @@ function StageBase:FinaliseBlueStage()
|
||||
end
|
||||
end
|
||||
|
||||
do ---Building parts
|
||||
---@class UnpackAirbaseCrateParam
|
||||
---@field self StageBase
|
||||
---@field kilos number
|
||||
---@field groupsPerKilo number
|
||||
---@field kilosPerSecond number
|
||||
---@field unpackedItems number
|
||||
---@field unpackedKilos number
|
||||
|
||||
---@param params UnpackAirbaseCrateParam
|
||||
---@param time number
|
||||
local startUnpackingCrate = function(params, time)
|
||||
local unpacked = params.unpackedKilos + (params.kilosPerSecond * 2)
|
||||
local alreadySpawned = params.unpackedItems / params.groupsPerKilo
|
||||
local diff = unpacked - alreadySpawned
|
||||
|
||||
local amount = math.floor(diff * params.groupsPerKilo)
|
||||
local spawned = params.self:SpawnAmount(amount)
|
||||
|
||||
params.unpackedItems = params.unpackedItems + amount
|
||||
params.unpackedKilos = unpacked
|
||||
if params.unpackedKilos >= params.kilos or spawned == false then
|
||||
params.self:FinaliseCrate(params.kilos)
|
||||
return
|
||||
end
|
||||
|
||||
return time + 2
|
||||
end
|
||||
|
||||
---comment
|
||||
---@param amount number
|
||||
---@return boolean
|
||||
function StageBase:SpawnAmount(amount)
|
||||
local function spawnOne()
|
||||
for _, group in pairs(self._blue_groups) do
|
||||
if group:IsSpawned() == false then
|
||||
group:Spawn()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
for i = 1, amount do
|
||||
local spawned = spawnOne()
|
||||
if spawned ~= true then
|
||||
self._logger:debug("No more groups to spawn at base: " .. self._airbase:getName())
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
---@param buildableMission BuildableMission
|
||||
function StageBase:OnCrateDroppedOff(buildableMission, kilos)
|
||||
self._logger:debug("Crate dropped off at base: " .. self._airbase:getName())
|
||||
|
||||
local timeToUnpack = (kilos / 500) * 30
|
||||
|
||||
---@type UnpackAirbaseCrateParam
|
||||
local params = {
|
||||
self = self,
|
||||
groupsPerKilo = self._groupsPerKilo,
|
||||
unpackedItems = 0,
|
||||
kilosPerSecond = kilos / timeToUnpack,
|
||||
unpackedKilos = 0,
|
||||
kilos = kilos
|
||||
}
|
||||
|
||||
timer.scheduleFunction(startUnpackingCrate, params, timer.getTime() + 2)
|
||||
end
|
||||
|
||||
---@private
|
||||
---@return SpearheadTriggerZone?
|
||||
function StageBase:GetNoLandingZone()
|
||||
---@type Array<Vec2>
|
||||
local points = {}
|
||||
|
||||
for _, group in pairs(self._blue_groups) do
|
||||
for _, unitPos in pairs(group:GetAllUnitPositions()) do
|
||||
table.insert(points, { x = unitPos.x, y = unitPos.z })
|
||||
end
|
||||
end
|
||||
|
||||
local vecs = Spearhead.Util.getConvexHull(points)
|
||||
|
||||
local pos = self._airbase:getPoint()
|
||||
local location = {
|
||||
x = pos.x,
|
||||
y = pos.z
|
||||
}
|
||||
|
||||
---@type SpearheadTriggerZone
|
||||
local spearheadZone = {
|
||||
name = self._airbase:getName() .. "_noland",
|
||||
location = location,
|
||||
verts = vecs,
|
||||
radius = 0,
|
||||
zone_type = "Polygon"
|
||||
}
|
||||
|
||||
return spearheadZone
|
||||
end
|
||||
|
||||
|
||||
---@param kilos number
|
||||
function StageBase:FinaliseCrate(kilos)
|
||||
self._receivedBuildingKilos = self._receivedBuildingKilos + kilos
|
||||
if self._receivedBuildingKilos >= self._requiredBuildingKilos then
|
||||
self:FinaliseBlueStage()
|
||||
end
|
||||
end
|
||||
function StageBase:OnBuildingComplete()
|
||||
self:FinaliseBlueStage()
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
|
||||
---@class BuildableZone : OnCrateDroppedListener
|
||||
---@field protected _targetZone SpearheadTriggerZone
|
||||
---@field protected _requiredKilos number
|
||||
---@field protected _buildableMission BuildableMission?
|
||||
---@field protected _buildableGroups Array<SpearheadGroup>
|
||||
---@field private _groupsPerKilo number
|
||||
---@field private _receivedBuildingKilos number
|
||||
---@field private _buildableLogger Logger
|
||||
---@field protected OnBuildingComplete fun(self:BuildableZone)
|
||||
local BuildableZone = {}
|
||||
BuildableZone.__index = BuildableZone
|
||||
|
||||
---@param targetZone SpearheadTriggerZone
|
||||
---@param kilosRequired number
|
||||
---@param buildableGroups Array<SpearheadGroup>
|
||||
---@param database Database
|
||||
---@param crateType SupplyType
|
||||
---@param logger Logger
|
||||
function BuildableZone:New(targetZone, kilosRequired, crateType, buildableGroups, logger, database)
|
||||
self._targetZone = targetZone
|
||||
self._requiredKilos = kilosRequired or 0
|
||||
self._buildableGroups = buildableGroups or {}
|
||||
self._buildableLogger = logger
|
||||
local totalGroups = Spearhead.Util.tableLength(self._buildableGroups)
|
||||
self._groupsPerKilo = totalGroups / self._requiredKilos
|
||||
|
||||
self._receivedBuildingKilos = 0
|
||||
local persistedKilos = Spearhead.classes.persistence.Persistence.GetZoneDeliveredKilos(targetZone.name)
|
||||
if persistedKilos and persistedKilos > 0 then
|
||||
self._receivedBuildingKilos = persistedKilos
|
||||
|
||||
---@param params UnpackCrateParam
|
||||
---@param time number
|
||||
local startUnpackingCrate = function(params, time)
|
||||
local unpacked = params.unpackedKilos + (params.kilosPerSecond * 2)
|
||||
local alreadySpawned = params.unpackedItems / params.groupsPerKilo
|
||||
local diff = unpacked - alreadySpawned
|
||||
|
||||
local amount = math.floor(diff * params.groupsPerKilo)
|
||||
local spawned = params.self:SpawnAmount(amount)
|
||||
|
||||
params.unpackedItems = params.unpackedItems + amount
|
||||
params.unpackedKilos = unpacked
|
||||
if params.unpackedKilos >= params.kilos or spawned == false then
|
||||
return
|
||||
end
|
||||
|
||||
return time + 0.5
|
||||
end
|
||||
|
||||
---@type UnpackCrateParam
|
||||
local params = {
|
||||
self = self,
|
||||
groupsPerKilo = self._groupsPerKilo,
|
||||
unpackedItems = 0,
|
||||
kilosPerSecond = persistedKilos/30,
|
||||
unpackedKilos = 0,
|
||||
kilos = persistedKilos
|
||||
}
|
||||
|
||||
timer.scheduleFunction(startUnpackingCrate, params, timer.getTime() + 5)
|
||||
kilosRequired = kilosRequired - persistedKilos
|
||||
end
|
||||
|
||||
local noLandingZone = self:GetNoLandingZone()
|
||||
if kilosRequired and kilosRequired > 0 then
|
||||
self._buildableMission = Spearhead.classes.stageClasses.missions.BuildableMission.new(database, logger, targetZone, noLandingZone, kilosRequired, crateType)
|
||||
self._buildableMission:AddOnCrateDroppedOfListener(self)
|
||||
else
|
||||
self._buildableMission = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
if self._buildableMission == nil then
|
||||
self._buildableLogger:debug("No buildable mission for zone: " .. targetZone.name)
|
||||
end
|
||||
end
|
||||
|
||||
---@protected
|
||||
function BuildableZone:StartBuildable()
|
||||
self._buildableMission:SpawnActive()
|
||||
end
|
||||
|
||||
---@protected
|
||||
function BuildableZone:OnBuildingComplete() end
|
||||
|
||||
---@class UnpackCrateParam
|
||||
---@field self BuildableZone
|
||||
---@field kilos number
|
||||
---@field groupsPerKilo number
|
||||
---@field kilosPerSecond number
|
||||
---@field unpackedItems number
|
||||
---@field unpackedKilos number
|
||||
|
||||
---@param mission BuildableMission?
|
||||
---@param kilos number
|
||||
function BuildableZone:OnCrateDroppedOff(mission, kilos)
|
||||
self._buildableLogger:debug("Crate dropped off in zone: " .. self._targetZone.name)
|
||||
|
||||
local timeToUnpack = (kilos / 500) * 15
|
||||
|
||||
---@type UnpackCrateParam
|
||||
local params = {
|
||||
self = self,
|
||||
groupsPerKilo = self._groupsPerKilo,
|
||||
unpackedItems = 0,
|
||||
kilosPerSecond = kilos/timeToUnpack,
|
||||
unpackedKilos = 0,
|
||||
kilos = kilos
|
||||
}
|
||||
|
||||
---@param params UnpackCrateParam
|
||||
---@param time number
|
||||
local startUnpackingCrate = function(params, time)
|
||||
local unpacked = params.unpackedKilos + (params.kilosPerSecond * 2)
|
||||
local alreadySpawned = params.unpackedItems / params.groupsPerKilo
|
||||
local diff = unpacked - alreadySpawned
|
||||
|
||||
local amount = math.floor(diff * params.groupsPerKilo)
|
||||
local spawned = params.self:SpawnAmount(amount)
|
||||
|
||||
params.unpackedItems = params.unpackedItems + amount
|
||||
params.unpackedKilos = unpacked
|
||||
if params.unpackedKilos >= params.kilos or spawned == false then
|
||||
params.self:FinaliseCrate(params.kilos)
|
||||
return
|
||||
end
|
||||
|
||||
return time + 2
|
||||
end
|
||||
|
||||
timer.scheduleFunction(startUnpackingCrate, params, timer.getTime() + 2)
|
||||
end
|
||||
|
||||
---@param kilos number
|
||||
function BuildableZone:FinaliseCrate(kilos)
|
||||
self._receivedBuildingKilos = self._receivedBuildingKilos + kilos
|
||||
Spearhead.classes.persistence.Persistence.SetZoneDeliveredKilos(self._targetZone.name, self._receivedBuildingKilos)
|
||||
if self._receivedBuildingKilos >= self._requiredKilos then
|
||||
self:OnBuildingComplete()
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
---@return SpearheadTriggerZone?
|
||||
function BuildableZone:GetNoLandingZone()
|
||||
|
||||
---@type Array<Vec2>
|
||||
local points = {}
|
||||
|
||||
for _, group in pairs(self._buildableGroups) do
|
||||
for _, unitPos in pairs(group:GetAllUnitPositions()) do
|
||||
table.insert(points, { x = unitPos.x, y = unitPos.z })
|
||||
end
|
||||
end
|
||||
|
||||
local vecs = Spearhead.Util.getConvexHull(points)
|
||||
|
||||
---@type SpearheadTriggerZone
|
||||
local spearheadZone = {
|
||||
name = self._targetZone.name .. "_noland",
|
||||
location = self._targetZone.location,
|
||||
verts = vecs,
|
||||
radius = 0,
|
||||
zone_type = "Polygon"
|
||||
}
|
||||
|
||||
return spearheadZone
|
||||
end
|
||||
|
||||
|
||||
---comment
|
||||
---@param amount number
|
||||
---@return boolean
|
||||
function BuildableZone:SpawnAmount(amount)
|
||||
local function spawnOne()
|
||||
for _, group in pairs(self._buildableGroups) do
|
||||
if group:IsSpawned() == false then
|
||||
group:Spawn()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
for i = 1, amount do
|
||||
local spawned = spawnOne()
|
||||
if spawned ~= true then
|
||||
self._buildableLogger:debug("No more groups to spawn in zone: " .. self._targetZone.name)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
if not Spearhead then Spearhead = {} end
|
||||
Spearhead.classes = Spearhead.classes or {}
|
||||
Spearhead.classes.stageClasses = Spearhead.classes.stageClasses or {}
|
||||
Spearhead.classes.stageClasses.SpecialZones = Spearhead.classes.stageClasses.SpecialZones or {}
|
||||
Spearhead.classes.stageClasses.SpecialZones.abstract = Spearhead.classes.stageClasses.SpecialZones.abstract or {}
|
||||
Spearhead.classes.stageClasses.SpecialZones.abstract.BuildableZone = BuildableZone
|
||||
@@ -63,8 +63,9 @@ Stage.StageColors = {
|
||||
---@param logger Logger
|
||||
---@param initData StageInitData
|
||||
---@param missionPriority MissionPriority
|
||||
---@param spawnManager SpawnManager
|
||||
---@return Stage
|
||||
function Stage:superNew(database, stageConfig, logger, initData, missionPriority)
|
||||
function Stage:superNew(database, stageConfig, logger, initData, missionPriority, spawnManager)
|
||||
|
||||
logger:debug("[BaseStage] Initiating stage with name: " .. initData.stageZoneName)
|
||||
|
||||
@@ -109,7 +110,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
||||
|
||||
local farpNames = database:getFarpNamesInStage(self.zoneName)
|
||||
for _, farpName in pairs(farpNames) do
|
||||
local farp = Spearhead.classes.stageClasses.SpecialZones.FarpZone.New(database, logger, farpName)
|
||||
local farp = Spearhead.classes.stageClasses.SpecialZones.FarpZone.New(database, logger, farpName, spawnManager)
|
||||
table.insert(self._db.farps, farp)
|
||||
end
|
||||
|
||||
@@ -141,7 +142,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
||||
self._logger:debug("Found " .. Spearhead.Util.tableLength(missionZones) .. " mission zones for stage: " .. self.zoneName)
|
||||
for _, missionZone in pairs(missionZones) do
|
||||
|
||||
local mission = Spearhead.classes.stageClasses.missions.ZoneMission.new(missionZone, self._missionPriority, database, logger, self)
|
||||
local mission = Spearhead.classes.stageClasses.missions.ZoneMission.new(missionZone, self._missionPriority, database, logger, self, spawnManager)
|
||||
if mission then
|
||||
self._db.missionsByCode[mission.code] = mission
|
||||
|
||||
@@ -164,7 +165,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
||||
---@type table<string, Array<Mission>>
|
||||
local randomMissionByName = {}
|
||||
for _, missionZoneName in pairs(randomMissionNames) do
|
||||
local mission = Spearhead.classes.stageClasses.missions.ZoneMission.new(missionZoneName, self._missionPriority, database, logger, self)
|
||||
local mission = Spearhead.classes.stageClasses.missions.ZoneMission.new(missionZoneName, self._missionPriority, database, logger, self, spawnManager)
|
||||
if mission then
|
||||
if randomMissionByName[mission.name] == nil then
|
||||
randomMissionByName[mission.name] = {}
|
||||
@@ -217,22 +218,22 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
|
||||
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)
|
||||
local airbase = Spearhead.classes.stageClasses.SpecialZones.StageBase.New(database, logger, airbaseName, spawnManager)
|
||||
table.insert(self._db.airbases, airbase)
|
||||
end
|
||||
end
|
||||
|
||||
for _, samZoneName in pairs(database:getBlueSamsInStage(self.zoneName)) do
|
||||
local blueSam = Spearhead.classes.stageClasses.SpecialZones.BlueSam.New(database, logger, samZoneName)
|
||||
local blueSam = Spearhead.classes.stageClasses.SpecialZones.BlueSam.New(database, logger, samZoneName, spawnManager)
|
||||
table.insert(self._db.blueSams, blueSam)
|
||||
end
|
||||
|
||||
local miscGroups = database:getMiscGroupsAtStage(self.zoneName)
|
||||
for _, groupName in pairs(miscGroups) do
|
||||
local miscGroup = SpearheadGroup.New(groupName)
|
||||
local miscGroup = SpearheadGroup.New(groupName, spawnManager, true)
|
||||
|
||||
table.insert(self._db.miscGroups, miscGroup)
|
||||
Spearhead.DcsUtil.DestroyGroup(groupName)
|
||||
miscGroup:Destroy()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -9,14 +9,15 @@ ExtraStage.__index = ExtraStage
|
||||
---@param stageConfig StageConfig
|
||||
---@param logger any
|
||||
---@param initData StageInitData
|
||||
---@param spawnManager SpawnManager
|
||||
---@return ExtraStage
|
||||
function ExtraStage.New(database, stageConfig, logger, initData)
|
||||
function ExtraStage.New(database, stageConfig, logger, initData, spawnManager)
|
||||
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(ExtraStage, Stage)
|
||||
|
||||
local self = setmetatable({}, { __index = ExtraStage }) --[[@as ExtraStage]]
|
||||
self:superNew(database, stageConfig, logger, initData, "secondary")
|
||||
self:superNew(database, stageConfig, logger, initData, "secondary", spawnManager)
|
||||
|
||||
self.OnPostBlueActivated = function (selfStage)
|
||||
|
||||
|
||||
@@ -9,14 +9,15 @@ PrimaryStage.__index = PrimaryStage
|
||||
---@param stageConfig StageConfig
|
||||
---@param logger any
|
||||
---@param initData StageInitData
|
||||
---@param spawnManager SpawnManager
|
||||
---@return PrimaryStage
|
||||
function PrimaryStage.New(database, stageConfig, logger, initData)
|
||||
function PrimaryStage.New(database, stageConfig, logger, initData, spawnManager)
|
||||
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(PrimaryStage, Stage)
|
||||
|
||||
local self = setmetatable({}, { __index = PrimaryStage }) --[[@as PrimaryStage]]
|
||||
self:superNew(database, stageConfig, logger, initData, "primary")
|
||||
self:superNew(database, stageConfig, logger, initData, "primary", spawnManager)
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
@@ -15,14 +15,15 @@ local WaitingStageInitData = {}
|
||||
---@param stageConfig StageConfig
|
||||
---@param logger any
|
||||
---@param initData WaitingStageInitData
|
||||
---@param spawnManager SpawnManager
|
||||
---@return WaitingStage
|
||||
function WaitingStage.New(database, stageConfig, logger, initData)
|
||||
function WaitingStage.New(database, stageConfig, logger, initData, spawnManager)
|
||||
|
||||
local Stage = Spearhead.classes.stageClasses.Stages.BaseStage.Stage
|
||||
setmetatable(WaitingStage, Stage)
|
||||
|
||||
local self = setmetatable({}, { __index = WaitingStage }) --[[@as WaitingStage]]
|
||||
self:superNew(database, stageConfig, logger, initData, "none")
|
||||
self:superNew(database, stageConfig, logger, initData, "none", spawnManager)
|
||||
|
||||
self._waitTimeSeconds = 5
|
||||
if initData.waitingSeconds and initData.waitingSeconds > 5 then self._waitTimeSeconds = initData.waitingSeconds end
|
||||
|
||||
@@ -155,7 +155,7 @@ function BuildableMission:SpawnActive()
|
||||
self._logger:debug("Spawning buildable mission: " .. self.code)
|
||||
|
||||
if self._noLandingZone == nil then
|
||||
self._logger:error("No no landing zone found for mission: " .. self.code)
|
||||
self._logger:error("No nolanding zone found for mission: " .. self.code)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -65,8 +65,9 @@ MINIMAL_UNITS_ALIVE_RATIO = 0.21
|
||||
---@param database Database
|
||||
---@param logger Logger
|
||||
---@param parentStage Stage
|
||||
---@param spawnManager SpawnManager
|
||||
---@return ZoneMission?
|
||||
function ZoneMission.new(zoneName, priority, database, logger, parentStage)
|
||||
function ZoneMission.new(zoneName, priority, database, logger, parentStage, spawnManager)
|
||||
local Mission = Spearhead.classes.stageClasses.missions.baseMissions.Mission
|
||||
ZoneMission.__index = ZoneMission
|
||||
setmetatable(ZoneMission, Mission)
|
||||
@@ -128,7 +129,7 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage)
|
||||
if not missionData then return end
|
||||
|
||||
for _, groupName in pairs(missionData.BlueGroups) do
|
||||
local spearheadGroup = SpearheadGroup.New(groupName)
|
||||
local spearheadGroup = SpearheadGroup.New(groupName, spawnManager, true)
|
||||
if spearheadGroup then
|
||||
table.insert(self._missionGroups.blueGroups, spearheadGroup)
|
||||
end
|
||||
@@ -136,7 +137,7 @@ function ZoneMission.new(zoneName, priority, database, logger, parentStage)
|
||||
end
|
||||
|
||||
for _, groupName in pairs(missionData.RedGroups) do
|
||||
local spearheadGroup = SpearheadGroup.New(groupName)
|
||||
local spearheadGroup = SpearheadGroup.New(groupName, spawnManager, true)
|
||||
table.insert(self._missionGroups.redGroups, spearheadGroup)
|
||||
|
||||
local isGroupTarget = Spearhead.Util.startswith(string.lower(groupName), "tgt_")
|
||||
|
||||
Reference in New Issue
Block a user