mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Updated Mission, cleaned it up and removed stuff.
This commit is contained in:
@@ -12,22 +12,6 @@ MISSION = {
|
||||
ClassName = "MISSION",
|
||||
Name = "",
|
||||
MissionStatus = "PENDING",
|
||||
_Clients = {},
|
||||
TaskMenus = {},
|
||||
TaskCategoryMenus = {},
|
||||
TaskTypeMenus = {},
|
||||
_ActiveTasks = {},
|
||||
GoalFunction = nil,
|
||||
MissionReportTrigger = 0,
|
||||
MissionProgressTrigger = 0,
|
||||
MissionReportShow = false,
|
||||
MissionReportFlash = false,
|
||||
MissionTimeInterval = 0,
|
||||
MissionCoalition = "",
|
||||
SUCCESS = 1,
|
||||
FAILED = 2,
|
||||
REPEAT = 3,
|
||||
_GoalTasks = {}
|
||||
}
|
||||
|
||||
--- This is the main MISSION declaration method. Each Mission is like the master or a Mission orchestration between, Clients, Tasks, Stages etc.
|
||||
@@ -234,6 +218,10 @@ function MISSION:New( CommandCenter, MissionName, MissionPriority, MissionBriefi
|
||||
self.MissionCoalition = MissionCoalition
|
||||
|
||||
self.Tasks = {}
|
||||
|
||||
-- Private implementations
|
||||
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -524,76 +512,44 @@ function MISSION:GetNextTaskID( Task )
|
||||
return self.Tasks[TaskName].n
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- old stuff
|
||||
|
||||
--- Returns if a Mission has completed.
|
||||
-- @return bool
|
||||
--- Is the @{Mission} **Completed**.
|
||||
-- @param #MISSION self
|
||||
-- @return #boolean
|
||||
function MISSION:IsCompleted()
|
||||
self:F()
|
||||
return self.MissionStatus == "ACCOMPLISHED"
|
||||
return self:Is( "Completed" )
|
||||
end
|
||||
|
||||
--- Set a Mission to completed.
|
||||
function MISSION:Completed()
|
||||
self:F()
|
||||
self.MissionStatus = "ACCOMPLISHED"
|
||||
self:StatusToClients()
|
||||
--- Is the @{Mission} **Idle**.
|
||||
-- @param #MISSION self
|
||||
-- @return #boolean
|
||||
function MISSION:IsIdle()
|
||||
return self:Is( "Idle" )
|
||||
end
|
||||
|
||||
--- Returns if a Mission is ongoing.
|
||||
-- treturn bool
|
||||
--- Is the @{Mission} **Ongoing**.
|
||||
-- @param #MISSION self
|
||||
-- @return #boolean
|
||||
function MISSION:IsOngoing()
|
||||
self:F()
|
||||
return self.MissionStatus == "ONGOING"
|
||||
return self:Is( "Ongoing" )
|
||||
end
|
||||
|
||||
--- Set a Mission to ongoing.
|
||||
function MISSION:Ongoing()
|
||||
self:F()
|
||||
self.MissionStatus = "ONGOING"
|
||||
--self:StatusToClients()
|
||||
--- Is the @{Mission} **Failed**.
|
||||
-- @param #MISSION self
|
||||
-- @return #boolean
|
||||
function MISSION:IsFailed()
|
||||
return self:Is( "Failed" )
|
||||
end
|
||||
|
||||
--- Returns if a Mission is pending.
|
||||
-- treturn bool
|
||||
function MISSION:IsPending()
|
||||
self:F()
|
||||
return self.MissionStatus == "PENDING"
|
||||
end
|
||||
|
||||
--- Set a Mission to pending.
|
||||
function MISSION:Pending()
|
||||
self:F()
|
||||
self.MissionStatus = "PENDING"
|
||||
self:StatusToClients()
|
||||
end
|
||||
|
||||
--- Returns if a Mission has failed.
|
||||
-- treturn bool
|
||||
function MISSION:IsFailed()
|
||||
self:F()
|
||||
return self.MissionStatus == "FAILED"
|
||||
end
|
||||
|
||||
--- Set a Mission to failed.
|
||||
function MISSION:Failed()
|
||||
self:F()
|
||||
self.MissionStatus = "FAILED"
|
||||
self:StatusToClients()
|
||||
end
|
||||
|
||||
--- Send the status of the MISSION to all Clients.
|
||||
function MISSION:StatusToClients()
|
||||
self:F()
|
||||
if self.MissionReportFlash then
|
||||
for ClientID, Client in pairs( self._Clients ) do
|
||||
Client:Message( self.MissionCoalition .. ' "' .. self.Name .. '": ' .. self.MissionStatus .. '! ( ' .. self.MissionPriority .. ' mission ) ', 10, "Mission Command: Mission Status")
|
||||
end
|
||||
end
|
||||
--- Is the @{Mission} **Hold**.
|
||||
-- @param #MISSION self
|
||||
-- @return #boolean
|
||||
function MISSION:IsHold()
|
||||
return self:Is( "Hold" )
|
||||
end
|
||||
|
||||
--- Validates if the Mission has a Group
|
||||
-- @param #MISSION
|
||||
-- @return #boolean true if the Mission has a Group.
|
||||
function MISSION:HasGroup( TaskGroup )
|
||||
local Has = false
|
||||
|
||||
@@ -686,107 +642,6 @@ function MISSION:ReportDetails()
|
||||
return Report:Text()
|
||||
end
|
||||
|
||||
--- Report the status of all MISSIONs to all active Clients.
|
||||
function MISSION:ReportToAll()
|
||||
self:F()
|
||||
|
||||
local AlivePlayers = ''
|
||||
for ClientID, Client in pairs( self._Clients ) do
|
||||
if Client:GetDCSGroup() then
|
||||
if Client:GetClientGroupDCSUnit() then
|
||||
if Client:GetClientGroupDCSUnit():getLife() > 0.0 then
|
||||
if AlivePlayers == '' then
|
||||
AlivePlayers = ' Players: ' .. Client:GetClientGroupDCSUnit():getPlayerName()
|
||||
else
|
||||
AlivePlayers = AlivePlayers .. ' / ' .. Client:GetClientGroupDCSUnit():getPlayerName()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local Tasks = self:GetTasks()
|
||||
local TaskText = ""
|
||||
for TaskID, TaskData in pairs( Tasks ) do
|
||||
TaskText = TaskText .. " - Task " .. TaskID .. ": " .. TaskData.Name .. ": " .. TaskData:GetGoalProgress() .. "\n"
|
||||
end
|
||||
MESSAGE:New( self.MissionCoalition .. ' "' .. self.Name .. '": ' .. self.MissionStatus .. ' ( ' .. self.MissionPriority .. ' mission )' .. AlivePlayers .. "\n" .. TaskText:gsub("\n$",""), 10, "Mission Command: Mission Report" ):ToAll()
|
||||
end
|
||||
|
||||
|
||||
--- Add a goal function to a MISSION. Goal functions are called when a @{TASK} within a mission has been completed.
|
||||
-- @param function GoalFunction is the function defined by the mission designer to evaluate whether a certain goal has been reached after a @{TASK} finishes within the @{MISSION}. A GoalFunction must accept 2 parameters: Mission, Client, which contains the current MISSION object and the current CLIENT object respectively.
|
||||
-- @usage
|
||||
-- PatriotActivation = {
|
||||
-- { "US SAM Patriot Zerti", false },
|
||||
-- { "US SAM Patriot Zegduleti", false },
|
||||
-- { "US SAM Patriot Gvleti", false }
|
||||
-- }
|
||||
--
|
||||
-- function DeployPatriotTroopsGoal( Mission, Client )
|
||||
--
|
||||
--
|
||||
-- -- Check if the cargo is all deployed for mission success.
|
||||
-- for CargoID, CargoData in pairs( Mission._Cargos ) do
|
||||
-- if Group.getByName( CargoData.CargoGroupName ) then
|
||||
-- CargoGroup = Group.getByName( CargoData.CargoGroupName )
|
||||
-- if CargoGroup then
|
||||
-- -- Check if the cargo is ready to activate
|
||||
-- CurrentLandingZoneID = routines.IsUnitInZones( CargoGroup:getUnits()[1], Mission:GetTask( 2 ).LandingZones ) -- The second task is the Deploytask to measure mission success upon
|
||||
-- if CurrentLandingZoneID then
|
||||
-- if PatriotActivation[CurrentLandingZoneID][2] == false then
|
||||
-- -- Now check if this is a new Mission Task to be completed...
|
||||
-- trigger.action.setGroupAIOn( Group.getByName( PatriotActivation[CurrentLandingZoneID][1] ) )
|
||||
-- PatriotActivation[CurrentLandingZoneID][2] = true
|
||||
-- MessageToBlue( "Mission Command: Message to all airborne units! The " .. PatriotActivation[CurrentLandingZoneID][1] .. " is armed. Our air defenses are now stronger.", 60, "BLUE/PatriotDefense" )
|
||||
-- MessageToRed( "Mission Command: Our satellite systems are detecting additional NATO air defenses. To all airborne units: Take care!!!", 60, "RED/PatriotDefense" )
|
||||
-- Mission:GetTask( 2 ):AddGoalCompletion( "Patriots activated", PatriotActivation[CurrentLandingZoneID][1], 1 ) -- Register Patriot activation as part of mission goal.
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- local Mission = MISSIONSCHEDULER.AddMission( 'NATO Transport Troops', 'Operational', 'Transport 3 groups of air defense engineers from our barracks "Gold" and "Titan" to each patriot battery control center to activate our air defenses.', 'NATO' )
|
||||
-- Mission:AddGoalFunction( DeployPatriotTroopsGoal )
|
||||
function MISSION:AddGoalFunction( GoalFunction )
|
||||
self:F()
|
||||
self.GoalFunction = GoalFunction
|
||||
end
|
||||
|
||||
--- Register a new @{CLIENT} to participate within the mission.
|
||||
-- @param CLIENT Client is the @{CLIENT} object. The object must have been instantiated with @{CLIENT:New}.
|
||||
-- @return CLIENT
|
||||
-- @usage
|
||||
-- Add a number of Client objects to the Mission.
|
||||
-- Mission:AddClient( CLIENT:FindByName( 'US UH-1H*HOT-Deploy Troops 1', 'Transport 3 groups of air defense engineers from our barracks "Gold" and "Titan" to each patriot battery control center to activate our air defenses.' ):Transport() )
|
||||
-- Mission:AddClient( CLIENT:FindByName( 'US UH-1H*RAMP-Deploy Troops 3', 'Transport 3 groups of air defense engineers from our barracks "Gold" and "Titan" to each patriot battery control center to activate our air defenses.' ):Transport() )
|
||||
-- Mission:AddClient( CLIENT:FindByName( 'US UH-1H*HOT-Deploy Troops 2', 'Transport 3 groups of air defense engineers from our barracks "Gold" and "Titan" to each patriot battery control center to activate our air defenses.' ):Transport() )
|
||||
-- Mission:AddClient( CLIENT:FindByName( 'US UH-1H*RAMP-Deploy Troops 4', 'Transport 3 groups of air defense engineers from our barracks "Gold" and "Titan" to each patriot battery control center to activate our air defenses.' ):Transport() )
|
||||
function MISSION:AddClient( Client )
|
||||
self:F( { Client } )
|
||||
|
||||
local Valid = true
|
||||
|
||||
if Valid then
|
||||
self._Clients[Client.ClientName] = Client
|
||||
end
|
||||
|
||||
return Client
|
||||
end
|
||||
|
||||
--- Find a @{CLIENT} object within the @{MISSION} by its ClientName.
|
||||
-- @param CLIENT ClientName is a string defining the Client Group as defined within the ME.
|
||||
-- @return CLIENT
|
||||
-- @usage
|
||||
-- -- Seach for Client "Bomber" within the Mission.
|
||||
-- local BomberClient = Mission:FindClient( "Bomber" )
|
||||
function MISSION:FindClient( ClientName )
|
||||
self:F( { self._Clients[ClientName] } )
|
||||
return self._Clients[ClientName]
|
||||
end
|
||||
|
||||
|
||||
--- Get all the TASKs from the Mission. This function is useful in GoalFunctions.
|
||||
-- @return {TASK,...} Structure of TASKS with the @{TASK} number as the key.
|
||||
-- @usage
|
||||
@@ -800,330 +655,3 @@ function MISSION:GetTasks()
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
_TransportExecuteStage: Defines the different stages of Transport unload/load execution. This table is internal and is used to control the validity of Transport load/unload timing.
|
||||
|
||||
- _TransportExecuteStage.EXECUTING
|
||||
- _TransportExecuteStage.SUCCESS
|
||||
- _TransportExecuteStage.FAILED
|
||||
|
||||
--]]
|
||||
_TransportExecuteStage = {
|
||||
NONE = 0,
|
||||
EXECUTING = 1,
|
||||
SUCCESS = 2,
|
||||
FAILED = 3
|
||||
}
|
||||
|
||||
|
||||
--- The MISSIONSCHEDULER is an OBJECT and is the main scheduler of ALL active MISSIONs registered within this scheduler. It's workings are considered internal and is automatically created when the Mission.lua file is included.
|
||||
-- @type MISSIONSCHEDULER
|
||||
-- @field #MISSIONSCHEDULER.MISSIONS Missions
|
||||
MISSIONSCHEDULER = {
|
||||
Missions = {},
|
||||
MissionCount = 0,
|
||||
TimeIntervalCount = 0,
|
||||
TimeIntervalShow = 150,
|
||||
TimeSeconds = 14400,
|
||||
TimeShow = 5
|
||||
}
|
||||
|
||||
--- @type MISSIONSCHEDULER.MISSIONS
|
||||
-- @list <#MISSION> Mission
|
||||
|
||||
--- This is the main MISSIONSCHEDULER Scheduler function. It is considered internal and is automatically created when the Mission.lua file is included.
|
||||
function MISSIONSCHEDULER.Scheduler()
|
||||
|
||||
|
||||
-- loop through the missions in the TransportTasks
|
||||
for MissionName, MissionData in pairs( MISSIONSCHEDULER.Missions ) do
|
||||
|
||||
local Mission = MissionData -- #MISSION
|
||||
|
||||
if not Mission:IsCompleted() then
|
||||
|
||||
-- This flag will monitor if for this mission, there are clients alive. If this flag is still false at the end of the loop, the mission status will be set to Pending (if not Failed or Completed).
|
||||
local ClientsAlive = false
|
||||
|
||||
for ClientID, ClientData in pairs( Mission._Clients ) do
|
||||
|
||||
local Client = ClientData -- Wrapper.Client#CLIENT
|
||||
|
||||
if Client:IsAlive() then
|
||||
|
||||
-- There is at least one Client that is alive... So the Mission status is set to Ongoing.
|
||||
ClientsAlive = true
|
||||
|
||||
-- If this Client was not registered as Alive before:
|
||||
-- 1. We register the Client as Alive.
|
||||
-- 2. We initialize the Client Tasks and make a link to the original Mission Task.
|
||||
-- 3. We initialize the Cargos.
|
||||
-- 4. We flag the Mission as Ongoing.
|
||||
if not Client.ClientAlive then
|
||||
Client.ClientAlive = true
|
||||
Client.ClientBriefingShown = false
|
||||
for TaskNumber, Task in pairs( Mission._Tasks ) do
|
||||
-- Note that this a deepCopy. Each client must have their own Tasks with own Stages!!!
|
||||
Client._Tasks[TaskNumber] = routines.utils.deepCopy( Mission._Tasks[TaskNumber] )
|
||||
-- Each MissionTask must point to the original Mission.
|
||||
Client._Tasks[TaskNumber].MissionTask = Mission._Tasks[TaskNumber]
|
||||
Client._Tasks[TaskNumber].Cargos = Mission._Tasks[TaskNumber].Cargos
|
||||
Client._Tasks[TaskNumber].LandingZones = Mission._Tasks[TaskNumber].LandingZones
|
||||
end
|
||||
|
||||
Mission:Ongoing()
|
||||
end
|
||||
|
||||
|
||||
-- For each Client, check for each Task the state and evolve the mission.
|
||||
-- This flag will indicate if the Task of the Client is Complete.
|
||||
local TaskComplete = false
|
||||
|
||||
for TaskNumber, Task in pairs( Client._Tasks ) do
|
||||
|
||||
if not Task.Stage then
|
||||
Task:SetStage( 1 )
|
||||
end
|
||||
|
||||
|
||||
local TransportTime = timer.getTime()
|
||||
|
||||
if not Task:IsDone() then
|
||||
|
||||
if Task:Goal() then
|
||||
Task:ShowGoalProgress( Mission, Client )
|
||||
end
|
||||
|
||||
--env.info( 'Scheduler: Mission = ' .. Mission.Name .. ' / Client = ' .. Client.ClientName .. ' / Task = ' .. Task.Name .. ' / Stage = ' .. Task.ActiveStage .. ' - ' .. Task.Stage.Name .. ' - ' .. Task.Stage.StageType )
|
||||
|
||||
-- Action
|
||||
if Task:StageExecute() then
|
||||
Task.Stage:Execute( Mission, Client, Task )
|
||||
end
|
||||
|
||||
-- Wait until execution is finished
|
||||
if Task.ExecuteStage == _TransportExecuteStage.EXECUTING then
|
||||
Task.Stage:Executing( Mission, Client, Task )
|
||||
end
|
||||
|
||||
-- Validate completion or reverse to earlier stage
|
||||
if Task.Time + Task.Stage.WaitTime <= TransportTime then
|
||||
Task:SetStage( Task.Stage:Validate( Mission, Client, Task ) )
|
||||
end
|
||||
|
||||
if Task:IsDone() then
|
||||
--env.info( 'Scheduler: Mission '.. Mission.Name .. ' Task ' .. Task.Name .. ' Stage ' .. Task.Stage.Name .. ' done. TaskComplete = ' .. string.format ( "%s", TaskComplete and "true" or "false" ) )
|
||||
TaskComplete = true -- when a task is not yet completed, a mission cannot be completed
|
||||
|
||||
else
|
||||
-- break only if this task is not yet done, so that future task are not yet activated.
|
||||
TaskComplete = false -- when a task is not yet completed, a mission cannot be completed
|
||||
--env.info( 'Scheduler: Mission "'.. Mission.Name .. '" Task "' .. Task.Name .. '" Stage "' .. Task.Stage.Name .. '" break. TaskComplete = ' .. string.format ( "%s", TaskComplete and "true" or "false" ) )
|
||||
break
|
||||
end
|
||||
|
||||
if TaskComplete then
|
||||
|
||||
if Mission.GoalFunction ~= nil then
|
||||
Mission.GoalFunction( Mission, Client )
|
||||
end
|
||||
if MISSIONSCHEDULER.Scoring then
|
||||
MISSIONSCHEDULER.Scoring:_AddMissionTaskScore( Client:GetClientGroupDCSUnit(), Mission.Name, 25 )
|
||||
end
|
||||
|
||||
-- if not Mission:IsCompleted() then
|
||||
-- end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local MissionComplete = true
|
||||
for TaskNumber, Task in pairs( Mission._Tasks ) do
|
||||
if Task:Goal() then
|
||||
-- Task:ShowGoalProgress( Mission, Client )
|
||||
if Task:IsGoalReached() then
|
||||
else
|
||||
MissionComplete = false
|
||||
end
|
||||
else
|
||||
MissionComplete = false -- If there is no goal, the mission should never be ended. The goal status will be set somewhere else.
|
||||
end
|
||||
end
|
||||
|
||||
if MissionComplete then
|
||||
Mission:Completed()
|
||||
if MISSIONSCHEDULER.Scoring then
|
||||
MISSIONSCHEDULER.Scoring:_AddMissionScore( Mission.Name, 100 )
|
||||
end
|
||||
else
|
||||
if TaskComplete then
|
||||
-- Reset for new tasking of active client
|
||||
Client.ClientAlive = false -- Reset the client tasks.
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
if Client.ClientAlive then
|
||||
env.info( 'Scheduler: Client "' .. Client.ClientName .. '" is inactive.' )
|
||||
Client.ClientAlive = false
|
||||
|
||||
-- This is tricky. If we sanitize Client._Tasks before sanitizing Client._Tasks[TaskNumber].MissionTask, then the original MissionTask will be sanitized, and will be lost within the garbage collector.
|
||||
-- So first sanitize Client._Tasks[TaskNumber].MissionTask, after that, sanitize only the whole _Tasks structure...
|
||||
--Client._Tasks[TaskNumber].MissionTask = nil
|
||||
--Client._Tasks = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- If all Clients of this Mission are not activated, then the Mission status needs to be put back into Pending status.
|
||||
-- But only if the Mission was Ongoing. In case the Mission is Completed or Failed, the Mission status may not be changed. In these cases, this will be the last run of this Mission in the Scheduler.
|
||||
if ClientsAlive == false then
|
||||
if Mission:IsOngoing() then
|
||||
-- Mission status back to pending...
|
||||
Mission:Pending()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Mission:StatusToClients()
|
||||
|
||||
if Mission:ReportTrigger() then
|
||||
Mission:ReportToAll()
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Start the MISSIONSCHEDULER.
|
||||
function MISSIONSCHEDULER.Start()
|
||||
if MISSIONSCHEDULER ~= nil then
|
||||
--MISSIONSCHEDULER.SchedulerId = routines.scheduleFunction( MISSIONSCHEDULER.Scheduler, { }, 0, 2 )
|
||||
MISSIONSCHEDULER.SchedulerId = SCHEDULER:New( nil, MISSIONSCHEDULER.Scheduler, { }, 0, 2 )
|
||||
end
|
||||
end
|
||||
|
||||
--- Stop the MISSIONSCHEDULER.
|
||||
function MISSIONSCHEDULER.Stop()
|
||||
if MISSIONSCHEDULER.SchedulerId then
|
||||
routines.removeFunction(MISSIONSCHEDULER.SchedulerId)
|
||||
MISSIONSCHEDULER.SchedulerId = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- This is the main MISSION declaration method. Each Mission is like the master or a Mission orchestration between, Clients, Tasks, Stages etc.
|
||||
-- @param Mission is the MISSION object instantiated by @{MISSION:New}.
|
||||
-- @return MISSION
|
||||
-- @usage
|
||||
-- -- Declare a mission.
|
||||
-- Mission = MISSION:New( 'Russia Transport Troops SA-6',
|
||||
-- 'Operational',
|
||||
-- 'Transport troops from the control center to one of the SA-6 SAM sites to activate their operation.',
|
||||
-- 'Russia' )
|
||||
-- MISSIONSCHEDULER:AddMission( Mission )
|
||||
function MISSIONSCHEDULER.AddMission( Mission )
|
||||
MISSIONSCHEDULER.Missions[Mission.Name] = Mission
|
||||
MISSIONSCHEDULER.MissionCount = MISSIONSCHEDULER.MissionCount + 1
|
||||
-- Add an overall AI Client for the AI tasks... This AI Client will facilitate the Events in the background for each Task.
|
||||
--MissionAdd:AddClient( CLIENT:Register( 'AI' ) )
|
||||
|
||||
return Mission
|
||||
end
|
||||
|
||||
--- Remove a MISSION from the MISSIONSCHEDULER.
|
||||
-- @param MissionName is the name of the MISSION given at declaration using @{AddMission}.
|
||||
-- @usage
|
||||
-- -- Declare a mission.
|
||||
-- Mission = MISSION:New( 'Russia Transport Troops SA-6',
|
||||
-- 'Operational',
|
||||
-- 'Transport troops from the control center to one of the SA-6 SAM sites to activate their operation.',
|
||||
-- 'Russia' )
|
||||
-- MISSIONSCHEDULER:AddMission( Mission )
|
||||
--
|
||||
-- -- Now remove the Mission.
|
||||
-- MISSIONSCHEDULER:RemoveMission( 'Russia Transport Troops SA-6' )
|
||||
function MISSIONSCHEDULER.RemoveMission( MissionName )
|
||||
MISSIONSCHEDULER.Missions[MissionName] = nil
|
||||
MISSIONSCHEDULER.MissionCount = MISSIONSCHEDULER.MissionCount - 1
|
||||
end
|
||||
|
||||
--- Find a MISSION within the MISSIONSCHEDULER.
|
||||
-- @param MissionName is the name of the MISSION given at declaration using @{AddMission}.
|
||||
-- @return MISSION
|
||||
-- @usage
|
||||
-- -- Declare a mission.
|
||||
-- Mission = MISSION:New( 'Russia Transport Troops SA-6',
|
||||
-- 'Operational',
|
||||
-- 'Transport troops from the control center to one of the SA-6 SAM sites to activate their operation.',
|
||||
-- 'Russia' )
|
||||
-- MISSIONSCHEDULER:AddMission( Mission )
|
||||
--
|
||||
-- -- Now find the Mission.
|
||||
-- MissionFind = MISSIONSCHEDULER:FindMission( 'Russia Transport Troops SA-6' )
|
||||
function MISSIONSCHEDULER.FindMission( MissionName )
|
||||
return MISSIONSCHEDULER.Missions[MissionName]
|
||||
end
|
||||
|
||||
-- Internal function used by the MISSIONSCHEDULER menu.
|
||||
function MISSIONSCHEDULER.ReportMissionsShow( )
|
||||
for MissionName, Mission in pairs( MISSIONSCHEDULER.Missions ) do
|
||||
Mission.MissionReportShow = true
|
||||
Mission.MissionReportFlash = false
|
||||
end
|
||||
end
|
||||
|
||||
-- Internal function used by the MISSIONSCHEDULER menu.
|
||||
function MISSIONSCHEDULER.ReportMissionsFlash( TimeInterval )
|
||||
local Count = 0
|
||||
for MissionName, Mission in pairs( MISSIONSCHEDULER.Missions ) do
|
||||
Mission.MissionReportShow = false
|
||||
Mission.MissionReportFlash = true
|
||||
Mission.MissionReportTrigger = timer.getTime() + Count * TimeInterval
|
||||
Mission.MissionTimeInterval = MISSIONSCHEDULER.MissionCount * TimeInterval
|
||||
env.info( "TimeInterval = " .. Mission.MissionTimeInterval )
|
||||
Count = Count + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Internal function used by the MISSIONSCHEDULER menu.
|
||||
function MISSIONSCHEDULER.ReportMissionsHide( Prm )
|
||||
for MissionName, Mission in pairs( MISSIONSCHEDULER.Missions ) do
|
||||
Mission.MissionReportShow = false
|
||||
Mission.MissionReportFlash = false
|
||||
end
|
||||
end
|
||||
|
||||
--- Enables a MENU option in the communications menu under F10 to control the status of the active missions.
|
||||
-- This function should be called only once when starting the MISSIONSCHEDULER.
|
||||
function MISSIONSCHEDULER.ReportMenu()
|
||||
local ReportMenu = SUBMENU:New( 'Status' )
|
||||
local ReportMenuShow = COMMANDMENU:New( 'Show Report Missions', ReportMenu, MISSIONSCHEDULER.ReportMissionsShow, 0 )
|
||||
local ReportMenuFlash = COMMANDMENU:New('Flash Report Missions', ReportMenu, MISSIONSCHEDULER.ReportMissionsFlash, 120 )
|
||||
local ReportMenuHide = COMMANDMENU:New( 'Hide Report Missions', ReportMenu, MISSIONSCHEDULER.ReportMissionsHide, 0 )
|
||||
end
|
||||
|
||||
--- Show the remaining mission time.
|
||||
function MISSIONSCHEDULER:TimeShow()
|
||||
self.TimeIntervalCount = self.TimeIntervalCount + 1
|
||||
if self.TimeIntervalCount >= self.TimeTriggerShow then
|
||||
local TimeMsg = string.format("%00d", ( self.TimeSeconds / 60 ) - ( timer.getTime() / 60 )) .. ' minutes left until mission reload.'
|
||||
MESSAGE:New( TimeMsg, self.TimeShow, "Mission time" ):ToAll()
|
||||
self.TimeIntervalCount = 0
|
||||
end
|
||||
end
|
||||
|
||||
function MISSIONSCHEDULER:Time( TimeSeconds, TimeIntervalShow, TimeShow )
|
||||
|
||||
self.TimeIntervalCount = 0
|
||||
self.TimeSeconds = TimeSeconds
|
||||
self.TimeIntervalShow = TimeIntervalShow
|
||||
self.TimeShow = TimeShow
|
||||
end
|
||||
|
||||
--- Adds a mission scoring to the game.
|
||||
function MISSIONSCHEDULER:Scoring( Scoring )
|
||||
|
||||
self.Scoring = Scoring
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user