Fixed Stage switching and mission status for BAI

This commit is contained in:
2024-10-13 02:03:07 +02:00
parent e2279c0ecb
commit 2447092d05
3 changed files with 27 additions and 12 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ function StageConfig:new()
local maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage local maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage
o.getMaxMissionsPerStage = function(self) return maxMissionsPerStage end o.getMaxMissionsPerStage = function(self) return maxMissionsPerStage end
o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.INFO o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.DEBUG
return o; return o;
end end
+21 -8
View File
@@ -113,6 +113,10 @@ do -- INIT Mission Class
return nil return nil
end end
o.GetState = function(self)
return self.missionState
end
o.OnUnitLost = function(self, object) o.OnUnitLost = function(self, object)
--[[ --[[
OnUnit lost event OnUnit lost event
@@ -139,7 +143,7 @@ do -- INIT Mission Class
self.targetAliveStates[name][name] = false self.targetAliveStates[name][name] = false
end end
end end
timer.scheduleFunction(CheckStateAsync, self, timer.getTime() + 3) timer.scheduleFunction(CheckStateAsync, self, timer.getTime() + 1)
end end
o.MissionCompleteListeners = {} o.MissionCompleteListeners = {}
@@ -208,6 +212,9 @@ do -- INIT Mission Class
end end
else else
local function CountAliveGroups() local function CountAliveGroups()
self.logger:debug(self.groupUnitAliveDict)
local aliveGroups = 0 local aliveGroups = 0
for _, group in pairs(self.groupUnitAliveDict) do for _, group in pairs(self.groupUnitAliveDict) do
@@ -287,7 +294,7 @@ do -- INIT Mission Class
else else
local dead = 0 local dead = 0
local total = 0 local total = 0
for _, group in pairs(self.targetAliveStates) do for _, group in pairs(self.groupUnitAliveDict) do
for _, isAlive in pairs(group) do for _, isAlive in pairs(group) do
total = total + 1 total = total + 1
if isAlive == false then if isAlive == false then
@@ -318,6 +325,7 @@ do -- INIT Mission Class
local Init = function(self) local Init = function(self)
for key, group_name in pairs(self.groupNames) do for key, group_name in pairs(self.groupNames) do
self.groupUnitAliveDict[group_name] = {} self.groupUnitAliveDict[group_name] = {}
self.targetAliveStates[group_name] = {} self.targetAliveStates[group_name] = {}
@@ -326,6 +334,7 @@ do -- INIT Mission Class
if Spearhead.Util.startswith(group_name, "TGT_") == true then if Spearhead.Util.startswith(group_name, "TGT_") == true then
self.targetAliveStates[group_name][group_name] = true self.targetAliveStates[group_name][group_name] = true
self.hasSpecificTargets = true
end end
else else
local group = Group.getByName(group_name) local group = Group.getByName(group_name)
@@ -338,27 +347,31 @@ do -- INIT Mission Class
self.groupNamesPerUnit[unitName] = group_name self.groupNamesPerUnit[unitName] = group_name
Spearhead.Events.addOnUnitLostEventListener(unitName, self) Spearhead.Events.addOnUnitLostEventListener(unitName, self)
self.groupUnitAliveDict[group_name][unitName] = true
if isGroupTarget == true or Spearhead.Util.startswith(unitName, "TGT_") == true then if isGroupTarget == true or Spearhead.Util.startswith(unitName, "TGT_") == true then
self.targetAliveStates[group_name][unitName] = true self.targetAliveStates[group_name][unitName] = true
self.hasSpecificTargets = true
end end
if self.missionType == MissionType.DEAD or self.missionType == MissionType.SAM then if self.missionType == MissionType.BAI then
if Spearhead.DcsUtil.IsGroupStatic(group_name) ~= true then
self.groupUnitAliveDict[group_name][unitName] = true
end
elseif self.missionType == MissionType.DEAD or self.missionType == MissionType.SAM then
local desc = unit:getDesc() local desc = unit:getDesc()
local attributes = desc.attributes local attributes = desc.attributes
if attributes["SAM"] == true or attributes["SAM TR"] or attributes["AAA"] then if attributes["SAM"] == true or attributes["SAM TR"] or attributes["AAA"] then
self.targetAliveStates[group_name][unitName] = true self.targetAliveStates[group_name][unitName] = true
self.hasSpecificTargets = true
end end
else
self.groupUnitAliveDict[group_name][unitName] = true
end end
end end
end end
Spearhead.DcsUtil.DestroyGroup(group_name) Spearhead.DcsUtil.DestroyGroup(group_name)
end end
if Spearhead.Util.tableLength(self.targetAliveStates) > 0 then
self.hasSpecificTargets = true
end
end end
Init(o) Init(o)
+5 -3
View File
@@ -142,7 +142,7 @@ do --init STAGE DIRECTOR
o.IsComplete = function(self) o.IsComplete = function(self)
for i, mission in pairs(self.db.missions) do for i, mission in pairs(self.db.missions) do
local state = mission:GetState() local state = mission:GetState()
if state == Spearhead.Mission.MissionState.ACTIVE or state == Spearhead.Mission.MissionState.NEW then if state == Spearhead.internal.Mission.MissionState.ACTIVE or state == Spearhead.internal.Mission.MissionState.NEW then
return false return false
end end
end end
@@ -229,11 +229,13 @@ do --init STAGE DIRECTOR
local availableMissions = {} local availableMissions = {}
for _, mission in pairs(self.db.missionsByCode) do for _, mission in pairs(self.db.missionsByCode) do
if mission.missionState == Spearhead.internal.Mission.MissionState.ACTIVE then local state = mission:GetState()
if state == Spearhead.internal.Mission.MissionState.ACTIVE then
activeCount = activeCount + 1 activeCount = activeCount + 1
end end
if mission.missionState == Spearhead.internal.Mission.MissionState.NEW then if state == Spearhead.internal.Mission.MissionState.NEW then
table.insert(availableMissions, mission) table.insert(availableMissions, mission)
end end
end end