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
+2 -1
View File
@@ -11,6 +11,7 @@
"Object", "Object",
"coalition", "coalition",
"timer", "timer",
"AI" "AI",
"net"
] ]
} }
Binary file not shown.
Binary file not shown.
+4 -6
View File
@@ -18,7 +18,6 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
o.logger = logger o.logger = logger
o.activeStage = 0 o.activeStage = 0
o.capConfig = capConfig o.capConfig = capConfig
o.spawned = false
if capConfig == nil then if capConfig == nil then
capConfig = {} 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 if targetStage ~= nil and capGroup.state == Spearhead.internal.CapGroup.GroupState.UNSPAWNED then
capGroup:SpawnOnTheRamp() capGroup:SpawnOnTheRamp()
self.spawned = true
end end
end end
end end
@@ -108,7 +106,7 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
end end
countPerStage[supposedTargetStage] = countPerStage[supposedTargetStage] + 1 countPerStage[supposedTargetStage] = countPerStage[supposedTargetStage] + 1
else else
backupGroup:SendRTB() backupGroup:SendRTBAndDespawn()
end end
elseif backupGroup.state == Spearhead.internal.CapGroup.GroupState.RTBINTEN and backupGroup:GetTargetZone(self.activeStage) ~= backupGroup.assignedStageNumber then elseif backupGroup.state == Spearhead.internal.CapGroup.GroupState.RTBINTEN and backupGroup:GetTargetZone(self.activeStage) ~= backupGroup.assignedStageNumber then
backupGroup:SendRTB() backupGroup:SendRTB()
@@ -149,9 +147,7 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
primaryGroup:SendRTB() primaryGroup:SendRTB()
end end
else else
if primaryGroup.state == Spearhead.internal.CapGroup.GroupState.INTRANSIT or primaryGroup.state == Spearhead.internal.CapGroup.GroupState.ONSTATION then primaryGroup:SendRTBAndDespawn()
primaryGroup:SendRTB()
end
end end
end end
@@ -167,6 +163,8 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
backupGroup:SendToStage(supposedTargetStage) backupGroup:SendToStage(supposedTargetStage)
countPerStage[supposedTargetStage] = countPerStage[supposedTargetStage] + 1 countPerStage[supposedTargetStage] = countPerStage[supposedTargetStage] + 1
end end
else
backupGroup:SendRTBAndDespawn()
end end
end end
end end
+25 -5
View File
@@ -161,8 +161,7 @@ CapGroup.GroupState = {
RTBINTEN = 4, RTBINTEN = 4,
RTB = 5, RTB = 5,
DEAD = 6, DEAD = 6,
REARMING = 7, REARMING = 7
DESPAWNED = 8
} }
local function SetReadyOnRampAsync(self, time) local function SetReadyOnRampAsync(self, time)
@@ -203,6 +202,7 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
o.unitCount = 0 o.unitCount = 0
o.onStationSince = 0 o.onStationSince = 0
o.currentCapTaskingDuration = 0 o.currentCapTaskingDuration = 0
o.markedForDespawn = false
--config --config
o.capConfig = {} o.capConfig = {}
@@ -237,6 +237,8 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
end end
o.SpawnOnTheRamp = function(self) o.SpawnOnTheRamp = function(self)
self.markedForDespawn = false
self.logger:debug("Spawning group " .. self.groupName)
self.aliveUnits = {} self.aliveUnits = {}
self.landedUnits = {} self.landedUnits = {}
self.onStationSince = 0 self.onStationSince = 0
@@ -258,7 +260,9 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
end end
o.Despawn = function(self) o.Despawn = function(self)
self.logger:debug("Despawning group " .. self.groupName)
Spearhead.DcsUtil.DestroyGroup(self.groupName) Spearhead.DcsUtil.DestroyGroup(self.groupName)
self:SetState(CapGroup.GroupState.UNSPAWNED)
end end
o.SendRTB = function(self) 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) timer.scheduleFunction(setTaskAsync, { task = rtbTask, groupName = self.groupName, logger = self.logger }, timer.getTime() + 3)
else else
self.logger:error("No RTB task could be created for group: " .. self.groupName .. " due to " .. errormessage) 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 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 ---Starts and send this group to perform CAP at a stage
---@param self any ---@param self any
---@param stageZoneNumber string ---@param stageZoneNumber string
@@ -394,10 +406,18 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
if landedCount + deadCount == self.unitCount then if landedCount + deadCount == self.unitCount then
if landed 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 else
local delay = self.capConfig.deathDelay - self.capConfig.rearmDelay + RESPAWN_AFTER_TOUCHDOWN_SECONDS if self.markedForDespawn == true then
timer.scheduleFunction(DelayedStartRearm, { self = self }, timer.getTime() + delay) 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 end
end end
+5 -6
View File
@@ -193,9 +193,6 @@ do -- INIT Mission Class
if self.missionState == Mission.MissionState.COMPLETED then if self.missionState == Mission.MissionState.COMPLETED then
return return
end end
--[[
TODO: Check own state based on mission type
]]--
if self.hasSpecificTargets == true then if self.hasSpecificTargets == true then
local specificTargetsAlive = false local specificTargetsAlive = false
@@ -225,9 +222,11 @@ do -- INIT Mission Class
local aliveRatio = (groupTotal - groupDeath) / groupTotal local aliveRatio = (groupTotal - groupDeath) / groupTotal
if aliveRatio >= MINIMAL_UNITS_ALIVE_RATIO then if aliveRatio >= MINIMAL_UNITS_ALIVE_RATIO then
aliveGroups = 1 aliveGroups = aliveGroups + 1
end end
end end
return aliveGroups
end end
if self.missionType == Mission.MissionType.STRIKE then --strike targets should normally have TGT targets if self.missionType == Mission.MissionType.STRIKE then --strike targets should normally have TGT targets
@@ -246,11 +245,11 @@ do -- INIT Mission Class
if self.missionState == Mission.MissionState.COMPLETED then if self.missionState == Mission.MissionState.COMPLETED then
self.logger:debug("Mission complete " .. self.name) self.logger:debug("Mission complete " .. self.name)
trigger.action.outText("Mission " .. self.name .. " (" .. self.code .. ") was completed succesfully!" ) trigger.action.outText("Mission " .. self.name .. " (" .. self.code .. ") was completed succesfully!", 20)
TriggerMissionComplete(self) TriggerMissionComplete(self)
--Schedule cleanup after 5 minutes of mission complete --Schedule cleanup after 5 minutes of mission complete
timer.scheduleFunction(CleanupDelayedAsync, self, timer.getTime() + 300) --timer.scheduleFunction(CleanupDelayedAsync, self, timer.getTime() + 300)
end end
end end
+37
View File
@@ -2,6 +2,9 @@
local Stage = {} local Stage = {}
do --init STAGE DIRECTOR do --init STAGE DIRECTOR
local stageDrawingId = 0
---comment ---comment
---@param stagezone_name string ---@param stagezone_name string
---@param database table ---@param database table
@@ -39,6 +42,9 @@ do --init STAGE DIRECTOR
o.activeStage = 0 o.activeStage = 0
o.preActivated = false o.preActivated = false
o.stageConfig = stageConfig or {} o.stageConfig = stageConfig or {}
o.stageDrawingId = stageDrawingId + 1
stageDrawingId = stageDrawingId + 1
do --Init Stage do --Init Stage
logger:info("Initiating new Stage with name: " .. stagezone_name) logger:info("Initiating new Stage with name: " .. stagezone_name)
@@ -138,7 +144,34 @@ do --init STAGE DIRECTOR
self:ActivateMissionsIfApplicable(self) self:ActivateMissionsIfApplicable(self)
end end
o.MarkStage = function(self, blue)
local fillColor = {1, 0, 0, 0.1}
local line ={ 1, 0,0, 1 }
if blue == true then
fillColor = {0, 0, 1, 0.1}
line ={ 0, 0,1, 1 }
end
local zone = Spearhead.DcsUtil.getZoneByName(self.zoneName)
if zone then
self.logger:debug("drawing stage")
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)
else
--trigger.action.circleToAll(-1, self.stageDrawingId, {x = zone.x, y = 0 , z = zone.z}, zone.radius, { 1, 0,0, 1 }, {1,0,0,1},4, true)
trigger.action.quadToAll( -1, self.stageDrawingId, zone.verts[2], zone.verts[1], zone.verts[4], zone.verts[3], {0,0,0,0}, {0,0,0,0}, 4, true)
end
trigger.action.setMarkupColorFill(self.stageDrawingId, fillColor)
trigger.action.setMarkupColor(self.stageDrawingId, line)
end
end
o.ActivateStage = function(self) o.ActivateStage = function(self)
pcall(function()
self:MarkStage()
end)
self:PreActivate() self:PreActivate()
local miscGroups = self.database:getMiscGroupsAtStage(self.zoneName) local miscGroups = self.database:getMiscGroupsAtStage(self.zoneName)
@@ -211,6 +244,10 @@ do --init STAGE DIRECTOR
end end
local ActivateBlueAsync = function(self) local ActivateBlueAsync = function(self)
pcall(function()
self:MarkStage(true)
end)
for key, airbaseId in pairs(self.db.airbaseIds) do for key, airbaseId in pairs(self.db.airbaseIds) do
local airbase = Spearhead.DcsUtil.getAirbaseById(airbaseId) local airbase = Spearhead.DcsUtil.getAirbaseById(airbaseId)