Fixed Stage switching and mission status for BAI
This commit is contained in:
@@ -22,7 +22,7 @@ function StageConfig:new()
|
||||
local maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage
|
||||
o.getMaxMissionsPerStage = function(self) return maxMissionsPerStage end
|
||||
|
||||
o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.INFO
|
||||
o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.DEBUG
|
||||
return o;
|
||||
end
|
||||
|
||||
|
||||
@@ -113,6 +113,10 @@ do -- INIT Mission Class
|
||||
return nil
|
||||
end
|
||||
|
||||
o.GetState = function(self)
|
||||
return self.missionState
|
||||
end
|
||||
|
||||
o.OnUnitLost = function(self, object)
|
||||
--[[
|
||||
OnUnit lost event
|
||||
@@ -139,7 +143,7 @@ do -- INIT Mission Class
|
||||
self.targetAliveStates[name][name] = false
|
||||
end
|
||||
end
|
||||
timer.scheduleFunction(CheckStateAsync, self, timer.getTime() + 3)
|
||||
timer.scheduleFunction(CheckStateAsync, self, timer.getTime() + 1)
|
||||
end
|
||||
|
||||
o.MissionCompleteListeners = {}
|
||||
@@ -208,6 +212,9 @@ do -- INIT Mission Class
|
||||
end
|
||||
else
|
||||
local function CountAliveGroups()
|
||||
|
||||
self.logger:debug(self.groupUnitAliveDict)
|
||||
|
||||
local aliveGroups = 0
|
||||
|
||||
for _, group in pairs(self.groupUnitAliveDict) do
|
||||
@@ -287,7 +294,7 @@ do -- INIT Mission Class
|
||||
else
|
||||
local dead = 0
|
||||
local total = 0
|
||||
for _, group in pairs(self.targetAliveStates) do
|
||||
for _, group in pairs(self.groupUnitAliveDict) do
|
||||
for _, isAlive in pairs(group) do
|
||||
total = total + 1
|
||||
if isAlive == false then
|
||||
@@ -318,6 +325,7 @@ do -- INIT Mission Class
|
||||
local Init = function(self)
|
||||
for key, group_name in pairs(self.groupNames) do
|
||||
|
||||
|
||||
self.groupUnitAliveDict[group_name] = {}
|
||||
self.targetAliveStates[group_name] = {}
|
||||
|
||||
@@ -326,6 +334,7 @@ do -- INIT Mission Class
|
||||
|
||||
if Spearhead.Util.startswith(group_name, "TGT_") == true then
|
||||
self.targetAliveStates[group_name][group_name] = true
|
||||
self.hasSpecificTargets = true
|
||||
end
|
||||
else
|
||||
local group = Group.getByName(group_name)
|
||||
@@ -338,27 +347,31 @@ do -- INIT Mission Class
|
||||
self.groupNamesPerUnit[unitName] = group_name
|
||||
|
||||
Spearhead.Events.addOnUnitLostEventListener(unitName, self)
|
||||
self.groupUnitAliveDict[group_name][unitName] = true
|
||||
|
||||
|
||||
if isGroupTarget == true or Spearhead.Util.startswith(unitName, "TGT_") == true then
|
||||
self.targetAliveStates[group_name][unitName] = true
|
||||
self.hasSpecificTargets = true
|
||||
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 attributes = desc.attributes
|
||||
if attributes["SAM"] == true or attributes["SAM TR"] or attributes["AAA"] then
|
||||
self.targetAliveStates[group_name][unitName] = true
|
||||
self.hasSpecificTargets = true
|
||||
end
|
||||
else
|
||||
self.groupUnitAliveDict[group_name][unitName] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
Spearhead.DcsUtil.DestroyGroup(group_name)
|
||||
end
|
||||
|
||||
if Spearhead.Util.tableLength(self.targetAliveStates) > 0 then
|
||||
self.hasSpecificTargets = true
|
||||
end
|
||||
end
|
||||
|
||||
Init(o)
|
||||
|
||||
@@ -142,7 +142,7 @@ do --init STAGE DIRECTOR
|
||||
o.IsComplete = function(self)
|
||||
for i, mission in pairs(self.db.missions) do
|
||||
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
|
||||
end
|
||||
end
|
||||
@@ -229,11 +229,13 @@ do --init STAGE DIRECTOR
|
||||
|
||||
local availableMissions = {}
|
||||
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
|
||||
end
|
||||
|
||||
if mission.missionState == Spearhead.internal.Mission.MissionState.NEW then
|
||||
if state == Spearhead.internal.Mission.MissionState.NEW then
|
||||
table.insert(availableMissions, mission)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user