mission complete working with removing of command
This commit is contained in:
Binary file not shown.
+3
-4
@@ -144,12 +144,11 @@ local stageConfig = {
|
|||||||
Spearhead.internal.GlobalCapManager.start(databaseManager, capConfig, stageConfig)
|
Spearhead.internal.GlobalCapManager.start(databaseManager, capConfig, stageConfig)
|
||||||
Spearhead.internal.GlobalStageManager.start(databaseManager)
|
Spearhead.internal.GlobalStageManager.start(databaseManager)
|
||||||
|
|
||||||
--[[
|
|
||||||
TODO: REMOVE DEBUG
|
|
||||||
]]
|
|
||||||
Spearhead.Events.PublishStageNumberChanged(1)
|
Spearhead.Events.PublishStageNumberChanged(1)
|
||||||
|
|
||||||
Spearhead.LoadingDone()
|
Spearhead.LoadingDone()
|
||||||
--Check lines of code in directory per file:
|
--Check lines of code in directory per file:
|
||||||
-- Get-ChildItem . -Include *.lua -Recurse | foreach {""+(Get-Content $_).Count + " => " + $_.name }
|
-- Get-ChildItem . -Include *.lua -Recurse | foreach {""+(Get-Content $_).Count + " => " + $_.name }
|
||||||
-- find . -name '*.lua' | xargs wc -l
|
-- find . -name '*.lua' | xargs wc -l
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1608,7 +1608,7 @@ do
|
|||||||
event.id == world.event.S_EVENT_EJECTION or
|
event.id == world.event.S_EVENT_EJECTION or
|
||||||
event.id == world.event.S_EVENT_UNIT_LOST then
|
event.id == world.event.S_EVENT_UNIT_LOST then
|
||||||
local object = event.initiator
|
local object = event.initiator
|
||||||
if object and OnUnitLostListeners[object:getName()] then
|
if object and object.getName and OnUnitLostListeners[object:getName()] then
|
||||||
for _, callable in pairs(OnUnitLostListeners[object:getName()]) do
|
for _, callable in pairs(OnUnitLostListeners[object:getName()]) do
|
||||||
local succ, err = pcall(function()
|
local succ, err = pcall(function()
|
||||||
callable:OnUnitLost(object)
|
callable:OnUnitLost(object)
|
||||||
|
|||||||
@@ -84,6 +84,14 @@ do -- DB
|
|||||||
o.tables.descriptions[name] = layer_object.text
|
o.tables.descriptions[name] = layer_object.text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local inZone = Spearhead.DcsUtil.isPositionInZones(layer_object.mapX, layer_object.mapY, o.tables.random_mission_zones)
|
||||||
|
if Spearhead.Util.tableLength(inZone) >= 1 then
|
||||||
|
local name = inZone[1]
|
||||||
|
if name ~= nil then
|
||||||
|
o.tables.descriptions[name] = layer_object.text
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -584,6 +592,19 @@ do -- DB
|
|||||||
Logger:info("Airbases: " .. Spearhead.Util.tableLength(o.tables.airbasesPerStage))
|
Logger:info("Airbases: " .. Spearhead.Util.tableLength(o.tables.airbasesPerStage))
|
||||||
Logger:info("RedAirbase Groups: " .. Spearhead.Util.tableLength(o.tables.redAirbaseGroupsPerAirbase["21"]))
|
Logger:info("RedAirbase Groups: " .. Spearhead.Util.tableLength(o.tables.redAirbaseGroupsPerAirbase["21"]))
|
||||||
|
|
||||||
|
|
||||||
|
for _, missionZone in pairs(o.tables.mission_zones) do
|
||||||
|
if o.tables.descriptions[missionZone] == nil then
|
||||||
|
Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZone .. " does not have a briefing")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, randomMission in pairs(o.tables.random_mission_zones) do
|
||||||
|
if o.tables.descriptions[randomMission] == nil then
|
||||||
|
Spearhead.AddMissionEditorWarning("Mission with zonename: " .. randomMission .. " does not have a briefing")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
singleton = o
|
singleton = o
|
||||||
return o
|
return o
|
||||||
|
|||||||
+63
-10
@@ -102,6 +102,8 @@ do -- INIT Mission Class
|
|||||||
o.logger = logger
|
o.logger = logger
|
||||||
o.code = database:GetNewMissionCode()
|
o.code = database:GetNewMissionCode()
|
||||||
|
|
||||||
|
o.groupNamesPerUnit = {}
|
||||||
|
|
||||||
o.groupUnitAliveDict = {}
|
o.groupUnitAliveDict = {}
|
||||||
o.targetAliveStates = {}
|
o.targetAliveStates = {}
|
||||||
o.hasSpecificTargets = false
|
o.hasSpecificTargets = false
|
||||||
@@ -115,10 +117,13 @@ do -- INIT Mission Class
|
|||||||
--[[
|
--[[
|
||||||
OnUnit lost event
|
OnUnit lost event
|
||||||
]]--
|
]]--
|
||||||
local category = object:getCategory()
|
self.logger:debug("Getting on unit lost event")
|
||||||
|
|
||||||
|
local category = Object.getCategory(object)
|
||||||
if category == Object.Category.UNIT then
|
if category == Object.Category.UNIT then
|
||||||
local unitName = object:getName()
|
local unitName = object:getName()
|
||||||
local groupName = object:getGroup():getName()
|
self.logger:debug("UnitName:" .. unitName)
|
||||||
|
local groupName = self.groupNamesPerUnit[unitName]
|
||||||
self.groupUnitAliveDict[groupName][unitName] = false
|
self.groupUnitAliveDict[groupName][unitName] = false
|
||||||
|
|
||||||
if self.targetAliveStates[groupName][unitName] then
|
if self.targetAliveStates[groupName][unitName] then
|
||||||
@@ -128,11 +133,13 @@ do -- INIT Mission Class
|
|||||||
local name = object:getName()
|
local name = object:getName()
|
||||||
self.groupUnitAliveDict[name][name] = false
|
self.groupUnitAliveDict[name][name] = false
|
||||||
|
|
||||||
|
self.logger:debug("Name " .. name)
|
||||||
|
|
||||||
if self.targetAliveStates[name][name] then
|
if self.targetAliveStates[name][name] then
|
||||||
self.targetAliveStates[name][name] = false
|
self.targetAliveStates[name][name] = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
CheckStateAsync(false)
|
timer.scheduleFunction(CheckStateAsync, self, timer.getTime() + 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
o.MissionCompleteListeners = {}
|
o.MissionCompleteListeners = {}
|
||||||
@@ -190,8 +197,8 @@ do -- INIT Mission Class
|
|||||||
TODO: Check own state based on mission type
|
TODO: Check own state based on mission type
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
local specificTargetsAlive = false
|
|
||||||
if self.hasSpecificTargets == true then
|
if self.hasSpecificTargets == true then
|
||||||
|
local specificTargetsAlive = false
|
||||||
for groupName, unitNameDict in pairs(self.targetAliveStates) do
|
for groupName, unitNameDict in pairs(self.targetAliveStates) do
|
||||||
for unitName, isAlive in pairs(unitNameDict) do
|
for unitName, isAlive in pairs(unitNameDict) do
|
||||||
if isAlive == true then
|
if isAlive == true then
|
||||||
@@ -199,8 +206,10 @@ do -- INIT Mission Class
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if specificTargetsAlive == false then
|
||||||
|
self.missionState = Mission.MissionState.COMPLETED
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
|
||||||
local function CountAliveGroups()
|
local function CountAliveGroups()
|
||||||
local aliveGroups = 0
|
local aliveGroups = 0
|
||||||
|
|
||||||
@@ -235,8 +244,10 @@ do -- INIT Mission Class
|
|||||||
]]
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if self.missionState == Mission.MissionState.COMPLETED then
|
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!" )
|
||||||
|
|
||||||
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)
|
||||||
@@ -260,8 +271,42 @@ do -- INIT Mission Class
|
|||||||
StartCheckingAndUpdateSelfContinuous(self)
|
StartCheckingAndUpdateSelfContinuous(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local ToStateString = function(self)
|
||||||
|
if self.hasSpecificTargets then
|
||||||
|
local dead = 0
|
||||||
|
local total = 0
|
||||||
|
for _, group in pairs(self.targetAliveStates) do
|
||||||
|
for _, isAlive in pairs(group) do
|
||||||
|
total = total + 1
|
||||||
|
if isAlive == false then
|
||||||
|
dead = dead + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local completionPercentage = math.floor((dead / total) * 100)
|
||||||
|
return "Targets Destroyed: " .. completionPercentage .. "%"
|
||||||
|
else
|
||||||
|
local dead = 0
|
||||||
|
local total = 0
|
||||||
|
for _, group in pairs(self.targetAliveStates) do
|
||||||
|
for _, isAlive in pairs(group) do
|
||||||
|
total = total + 1
|
||||||
|
if isAlive == false then
|
||||||
|
dead = dead + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local completionPercentage = math.floor((dead / total) * 100)
|
||||||
|
return "Targets Destroyed: " .. completionPercentage .. "%"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
o.ShowBriefing = function(self, groupId)
|
o.ShowBriefing = function(self, groupId)
|
||||||
local text = "Mission [" .. self.code .. "] ".. self.name .. "\n \n" .. self.missionbriefing .. " \n \nState TODO"
|
local stateString = ToStateString(self)
|
||||||
|
|
||||||
|
if self.missionbriefing == nil then self.missionbriefing = "No briefing available" end
|
||||||
|
local text = "Mission [" .. self.code .. "] ".. self.name .. "\n \n" .. self.missionbriefing .. " \n \n" .. stateString
|
||||||
trigger.action.outTextForGroup(groupId, text, 30);
|
trigger.action.outTextForGroup(groupId, text, 30);
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -278,14 +323,11 @@ do -- INIT Mission Class
|
|||||||
self.targetAliveStates[group_name] = {}
|
self.targetAliveStates[group_name] = {}
|
||||||
|
|
||||||
if Spearhead.DcsUtil.IsGroupStatic(group_name) then
|
if Spearhead.DcsUtil.IsGroupStatic(group_name) then
|
||||||
self.startingUnits = self.startingUnits + 1
|
|
||||||
Spearhead.Events.addOnUnitLostEventListener(group_name, self)
|
Spearhead.Events.addOnUnitLostEventListener(group_name, self)
|
||||||
|
|
||||||
self.groupUnitAliveDict[group_name][group_name] = true
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
local group = Group.getByName(group_name)
|
local group = Group.getByName(group_name)
|
||||||
local isGroupTarget = Spearhead.Util.startswith(group_name, "TGT_")
|
local isGroupTarget = Spearhead.Util.startswith(group_name, "TGT_")
|
||||||
@@ -293,12 +335,23 @@ do -- INIT Mission Class
|
|||||||
self.startingUnits = self.startingUnits + group:getInitialSize()
|
self.startingUnits = self.startingUnits + group:getInitialSize()
|
||||||
for _, unit in pairs(group:getUnits()) do
|
for _, unit in pairs(group:getUnits()) do
|
||||||
local unitName = unit:getName()
|
local unitName = unit:getName()
|
||||||
|
|
||||||
|
self.groupNamesPerUnit[unitName] = group_name
|
||||||
|
|
||||||
Spearhead.Events.addOnUnitLostEventListener(unitName, self)
|
Spearhead.Events.addOnUnitLostEventListener(unitName, self)
|
||||||
self.groupUnitAliveDict[group_name][unitName] = true
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if 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
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+31
-11
@@ -281,7 +281,6 @@ do --init STAGE DIRECTOR
|
|||||||
for _, mission in pairs(self.db.missionsByCode) do
|
for _, mission in pairs(self.db.missionsByCode) do
|
||||||
totalmissions = totalmissions + 1
|
totalmissions = totalmissions + 1
|
||||||
if mission.missionState == Spearhead.internal.Mission.MissionState.ACTIVE then
|
if mission.missionState == Spearhead.internal.Mission.MissionState.ACTIVE then
|
||||||
self.logger:debug("blaat")
|
|
||||||
|
|
||||||
text = text .. "\n [" .. mission.code .. "] " .. mission.name ..
|
text = text .. "\n [" .. mission.code .. "] " .. mission.name ..
|
||||||
" (" .. mission.missionTypeDisplayName .. ") \n"
|
" (" .. mission.missionTypeDisplayName .. ") \n"
|
||||||
@@ -318,6 +317,7 @@ do --init STAGE DIRECTOR
|
|||||||
if previousActive <= self.stageNumber then
|
if previousActive <= self.stageNumber then
|
||||||
if number > self.stageNumber then
|
if number > self.stageNumber then
|
||||||
self:ActivateBlueStage()
|
self:ActivateBlueStage()
|
||||||
|
self:RemoveAllMissionCommands()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -335,12 +335,30 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
o.RemoveMissionCommands = function (self, mission)
|
||||||
|
|
||||||
|
self.logger:debug("Removing commands for: " .. mission.name)
|
||||||
|
|
||||||
|
local folderName = mission.name .. "(" .. mission.missionTypeDisplayName .. ")"
|
||||||
|
for i = 0, 2 do
|
||||||
|
local players = coalition.getPlayers(i)
|
||||||
|
for _, playerUnit in pairs(players) do
|
||||||
|
local groupId = playerUnit:getGroup():getID()
|
||||||
|
missionCommands.removeItemForGroup(groupId, { "Missions", folderName })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
o.RemoveAllMissionCommands = function (self)
|
||||||
|
for _, mission in pairs(self.db.missionsByCode) do
|
||||||
|
self:RemoveMissionCommands(mission)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
o.AddCommandsForMissionToGroup = function (self, groupId, mission)
|
o.AddCommandsForMissionToGroup = function (self, groupId, mission)
|
||||||
local folderName = mission.name .. "(" .. mission.missionTypeDisplayName .. ")"
|
local folderName = mission.name .. "(" .. mission.missionTypeDisplayName .. ")"
|
||||||
missionCommands.addSubMenuForGroup(groupId, folderName, { "Missions"} )
|
missionCommands.addSubMenuForGroup(groupId, folderName, { "Missions"} )
|
||||||
missionCommands.addCommandForGroup(groupId, "Show Briefing", { "Missions", folderName }, ShowBriefingClicked, { self = self, groupId = groupId, missionCode = mission.code })
|
missionCommands.addCommandForGroup(groupId, "Show Briefing", { "Missions", folderName }, ShowBriefingClicked, { self = self, groupId = groupId, missionCode = mission.code })
|
||||||
self.logger:debug("blaat added command")
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
o.AddCommmandsForMissionToAllPlayers = function(self, mission)
|
o.AddCommmandsForMissionToAllPlayers = function(self, mission)
|
||||||
@@ -364,18 +382,20 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local removeMissionCommandsDelayed = function(input)
|
||||||
|
local self = input.self
|
||||||
|
local mission = input.mission
|
||||||
|
self:RemoveMissionCommands(mission)
|
||||||
|
end
|
||||||
|
|
||||||
o.OnMissionComplete = function(self, mission)
|
o.OnMissionComplete = function(self, mission)
|
||||||
local folderName = mission.name .. "(" .. mission.missionTypeDisplayName .. ")"
|
timer.scheduleFunction(removeMissionCommandsDelayed, { self = self, mission = mission}, timer.getTime() + 20)
|
||||||
for i = 0, 2 do
|
|
||||||
local players = coalition.getPlayers(i)
|
|
||||||
for _, playerUnit in pairs(players) do
|
|
||||||
local groupId = playerUnit:getGroup():getID()
|
|
||||||
missionCommands.removeItemForGroup(groupId, { "Missions", folderName })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
timer.scheduleFunction(activateMissionsIfApplicableAsync, self, timer.getTime() + 10)
|
timer.scheduleFunction(activateMissionsIfApplicableAsync, self, timer.getTime() + 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for _, mission in pairs(o.db.missionsByCode) do
|
||||||
|
mission:AddMissionCompleteListener(o)
|
||||||
|
end
|
||||||
|
|
||||||
Spearhead.Events.AddOnStatusRequestReceivedListener(o)
|
Spearhead.Events.AddOnStatusRequestReceivedListener(o)
|
||||||
Spearhead.Events.AddStageNumberChangedListener(o)
|
Spearhead.Events.AddStageNumberChangedListener(o)
|
||||||
|
|||||||
Reference in New Issue
Block a user