More working stuff

This commit is contained in:
2024-09-26 00:02:05 +02:00
parent d747b2d79c
commit c945c688ae
7 changed files with 73 additions and 18 deletions
+4 -6
View File
@@ -18,7 +18,6 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
o.logger = logger
o.activeStage = 0
o.capConfig = capConfig
o.spawned = false
if capConfig == nil then
capConfig = {}
@@ -82,7 +81,6 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
if targetStage ~= nil and capGroup.state == Spearhead.internal.CapGroup.GroupState.UNSPAWNED then
capGroup:SpawnOnTheRamp()
self.spawned = true
end
end
end
@@ -108,7 +106,7 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
end
countPerStage[supposedTargetStage] = countPerStage[supposedTargetStage] + 1
else
backupGroup:SendRTB()
backupGroup:SendRTBAndDespawn()
end
elseif backupGroup.state == Spearhead.internal.CapGroup.GroupState.RTBINTEN and backupGroup:GetTargetZone(self.activeStage) ~= backupGroup.assignedStageNumber then
backupGroup:SendRTB()
@@ -149,9 +147,7 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
primaryGroup:SendRTB()
end
else
if primaryGroup.state == Spearhead.internal.CapGroup.GroupState.INTRANSIT or primaryGroup.state == Spearhead.internal.CapGroup.GroupState.ONSTATION then
primaryGroup:SendRTB()
end
primaryGroup:SendRTBAndDespawn()
end
end
@@ -167,6 +163,8 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
backupGroup:SendToStage(supposedTargetStage)
countPerStage[supposedTargetStage] = countPerStage[supposedTargetStage] + 1
end
else
backupGroup:SendRTBAndDespawn()
end
end
end
+25 -5
View File
@@ -161,8 +161,7 @@ CapGroup.GroupState = {
RTBINTEN = 4,
RTB = 5,
DEAD = 6,
REARMING = 7,
DESPAWNED = 8
REARMING = 7
}
local function SetReadyOnRampAsync(self, time)
@@ -203,6 +202,7 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
o.unitCount = 0
o.onStationSince = 0
o.currentCapTaskingDuration = 0
o.markedForDespawn = false
--config
o.capConfig = {}
@@ -237,6 +237,8 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
end
o.SpawnOnTheRamp = function(self)
self.markedForDespawn = false
self.logger:debug("Spawning group " .. self.groupName)
self.aliveUnits = {}
self.landedUnits = {}
self.onStationSince = 0
@@ -258,7 +260,9 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
end
o.Despawn = function(self)
self.logger:debug("Despawning group " .. self.groupName)
Spearhead.DcsUtil.DestroyGroup(self.groupName)
self:SetState(CapGroup.GroupState.UNSPAWNED)
end
o.SendRTB = function(self)
@@ -270,10 +274,18 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
timer.scheduleFunction(setTaskAsync, { task = rtbTask, groupName = self.groupName, logger = self.logger }, timer.getTime() + 3)
else
self.logger:error("No RTB task could be created for group: " .. self.groupName .. " due to " .. errormessage)
if self.markedForDespawn == true then
self:Despawn()
end
end
end
end
o.SendRTBAndDespawn = function(self)
self.markedForDespawn = true
o.SendRTB(self)
end
---Starts and send this group to perform CAP at a stage
---@param self any
---@param stageZoneNumber string
@@ -394,10 +406,18 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
if landedCount + deadCount == self.unitCount then
if landed then
timer.scheduleFunction(DelayedStartRearm, { self = self }, timer.getTime() + RESPAWN_AFTER_TOUCHDOWN_SECONDS)
if self.markedForDespawn == true then
self:Despawn()
else
timer.scheduleFunction(DelayedStartRearm, { self = self }, timer.getTime() + RESPAWN_AFTER_TOUCHDOWN_SECONDS)
end
else
local delay = self.capConfig.deathDelay - self.capConfig.rearmDelay + RESPAWN_AFTER_TOUCHDOWN_SECONDS
timer.scheduleFunction(DelayedStartRearm, { self = self }, timer.getTime() + delay)
if self.markedForDespawn == true then
self:Despawn()
else
local delay = self.capConfig.deathDelay - self.capConfig.rearmDelay + RESPAWN_AFTER_TOUCHDOWN_SECONDS
timer.scheduleFunction(DelayedStartRearm, { self = self }, timer.getTime() + delay)
end
end
end
end