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",
"coalition",
"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.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
+5 -6
View File
@@ -193,9 +193,6 @@ do -- INIT Mission Class
if self.missionState == Mission.MissionState.COMPLETED then
return
end
--[[
TODO: Check own state based on mission type
]]--
if self.hasSpecificTargets == true then
local specificTargetsAlive = false
@@ -225,9 +222,11 @@ do -- INIT Mission Class
local aliveRatio = (groupTotal - groupDeath) / groupTotal
if aliveRatio >= MINIMAL_UNITS_ALIVE_RATIO then
aliveGroups = 1
aliveGroups = aliveGroups + 1
end
end
return aliveGroups
end
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
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)
--Schedule cleanup after 5 minutes of mission complete
timer.scheduleFunction(CleanupDelayedAsync, self, timer.getTime() + 300)
--timer.scheduleFunction(CleanupDelayedAsync, self, timer.getTime() + 300)
end
end
+37
View File
@@ -2,6 +2,9 @@
local Stage = {}
do --init STAGE DIRECTOR
local stageDrawingId = 0
---comment
---@param stagezone_name string
---@param database table
@@ -39,6 +42,9 @@ do --init STAGE DIRECTOR
o.activeStage = 0
o.preActivated = false
o.stageConfig = stageConfig or {}
o.stageDrawingId = stageDrawingId + 1
stageDrawingId = stageDrawingId + 1
do --Init Stage
logger:info("Initiating new Stage with name: " .. stagezone_name)
@@ -138,7 +144,34 @@ do --init STAGE DIRECTOR
self:ActivateMissionsIfApplicable(self)
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)
pcall(function()
self:MarkStage()
end)
self:PreActivate()
local miscGroups = self.database:getMiscGroupsAtStage(self.zoneName)
@@ -211,6 +244,10 @@ do --init STAGE DIRECTOR
end
local ActivateBlueAsync = function(self)
pcall(function()
self:MarkStage(true)
end)
for key, airbaseId in pairs(self.db.airbaseIds) do
local airbase = Spearhead.DcsUtil.getAirbaseById(airbaseId)