# Module `MISSION`

A MISSION is the main owner of a Mission orchestration within MOOSE .

The Mission framework orchestrates CLIENTs, TASKs, STAGEs etc. A CLIENT needs to be registered within the MISSION through the function AddClient. A TASK needs to be registered within the MISSION through the function AddTask.

## Global(s)

MISSION |
MISSIONSCHEDULER |
TaskComplete |
_TransportExecuteStage |

## Type `MISSION`

MISSION.AddClient(CLIENT, self, Client) | Register a new CLIENT to participate within the mission.
MISSION.AddGoalFunction(function, self, GoalFunction) | Add a goal function to a MISSION.
MISSION:AddTask(Task, TaskNumber) |
MISSION.ClassName |
MISSION:Completed() | Set a Mission to completed.
MISSION.FAILED |
MISSION:Failed() | Set a Mission to failed.
MISSION.FindClient(CLIENT, self, ClientName) | Find a CLIENT object within the MISSION by its ClientName.
MISSION:GetTask(TaskNumber) |
MISSION:GetTasks() | Get all the TASKs from the Mission.
MISSION.GoalFunction |
MISSION:IsCompleted() | Returns if a Mission has completed.
MISSION:IsFailed() | Returns if a Mission has failed.
MISSION:IsOngoing() | Returns if a Mission is ongoing.
MISSION:IsPending() | Returns if a Mission is pending.
MISSION:Meta() |
MISSION.MissionCoalition |
MISSION.MissionProgressTrigger |
MISSION.MissionReportFlash |
MISSION.MissionReportShow |
MISSION.MissionReportTrigger |
MISSION.MissionStatus |
MISSION.MissionTimeInterval |
MISSION.Name |
MISSION.New(string, string, string, string, self, MissionName, MissionPriority, MissionBriefing, MissionCoalition) | This is the main MISSION declaration method.
MISSION:Ongoing() | Set a Mission to ongoing.
MISSION:Pending() | Set a Mission to pending.
MISSION.REPEAT |
MISSION:ReportToAll() | Report the status of all MISSIONs to all active Clients.
MISSION:ReportTrigger() | Handles the reporting.
MISSION.SUCCESS |
MISSION.ShowBriefing(CLIENT, self, Client) | Show the briefing of the MISSION to the CLIENT.
MISSION:StatusToClients() | Send the status of the MISSION to all Clients.
MISSION._ActiveTasks |
MISSION._Clients |
MISSION._GoalTasks |
MISSION._Tasks |

## Type `MISSIONSCHEDULER`

MISSIONSCHEDULER.AddMission(Mission) | This is the main MISSION declaration method.
MISSIONSCHEDULER.FindMission(MissionName) | Find a MISSION within the MISSIONSCHEDULER.
MISSIONSCHEDULER.MissionCount |
MISSIONSCHEDULER.Missions |
MISSIONSCHEDULER.RemoveMission(MissionName) | Remove a MISSION from the MISSIONSCHEDULER.
MISSIONSCHEDULER.ReportMenu() | Enables a MENU option in the communications menu under F10 to control the status of the active missions.
MISSIONSCHEDULER.ReportMissionsFlash(TimeInterval) |
MISSIONSCHEDULER.ReportMissionsHide(Prm) |
MISSIONSCHEDULER.ReportMissionsShow() |
MISSIONSCHEDULER.Scheduler() | This is the main MISSIONSCHEDULER Scheduler function.
MISSIONSCHEDULER.SchedulerId |
MISSIONSCHEDULER:Scoring(Scoring) | Adds a mission scoring to the game.
MISSIONSCHEDULER.Start() | Start the MISSIONSCHEDULER.
MISSIONSCHEDULER.Stop() | Stop the MISSIONSCHEDULER.
MISSIONSCHEDULER:Time(TimeSeconds, TimeIntervalShow, TimeShow) |
MISSIONSCHEDULER.TimeIntervalCount |
MISSIONSCHEDULER.TimeIntervalShow |
MISSIONSCHEDULER.TimeSeconds |
MISSIONSCHEDULER.TimeShow |

## Global(s)

#MISSION MISSION

#MISSIONSCHEDULER MISSIONSCHEDULER

#boolean TaskComplete

  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.

_TransportExecuteStage

  _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

  --

## Type `MISSION`

### Field(s)

MISSION.AddClient(CLIENT, self, Client)

  Register a new CLIENT to participate within the mission.

  ### Parameters

  - `CLIENT` : Client is the CLIENT object. The object must have been instantiated with CLIENT.

  - `self` :

  - `Client` :

  ### Return value

  CLIENT

  ### Usage:

      Add a number of Client objects to the Mission.
      	Mission:AddClient( CLIENT:New( '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:New( '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:New( '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:New( '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() )

MISSION.AddGoalFunction(function, self, GoalFunction)

  Add a goal function to a MISSION.

  Goal functions are called when a TASK within a mission has been completed.

  ### Parameters

  - `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.

  - `self` :

  - `GoalFunction` :

  ### 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 )

MISSION:AddTask(Task, TaskNumber)

  ### Parameters

  - `Task` :

  - `TaskNumber` :

#string MISSION.ClassName

MISSION:Completed()

  Set a Mission to completed.

#number MISSION.FAILED

MISSION:Failed()

  Set a Mission to failed.

MISSION.FindClient(CLIENT, self, ClientName)

  Find a CLIENT object within the MISSION by its ClientName.

  ### Parameters

  - `CLIENT` : ClientName is a string defining the Client Group as defined within the ME.

  - `self` :

  - `ClientName` :

  ### Return value

  CLIENT

  ### Usage:

      -- Seach for Client "Bomber" within the Mission.
      local BomberClient = Mission:FindClient( "Bomber" )

MISSION:GetTask(TaskNumber)

  ### Parameter

  - `TaskNumber` :

MISSION:GetTasks()

  Get all the TASKs from the Mission.

  This function is useful in GoalFunctions.

  ### Return value

  {TASK,...} Structure of TASKS with the TASK number as the key.

  ### Usage:

      -- Get Tasks from the Mission.
      Tasks = Mission:GetTasks()
      env.info( "Task 2 Completion = " .. Tasks[2]:GetGoalPercentage() .. "%" )

MISSION.GoalFunction

MISSION:IsCompleted()

  Returns if a Mission has completed.

  ### Return value

  bool

MISSION:IsFailed()

  Returns if a Mission has failed.

  treturn bool

MISSION:IsOngoing()

  Returns if a Mission is ongoing.

  treturn bool

MISSION:IsPending()

  Returns if a Mission is pending.

  treturn bool

MISSION:Meta()

#string MISSION.MissionCoalition

#number MISSION.MissionProgressTrigger

#boolean MISSION.MissionReportFlash

#boolean MISSION.MissionReportShow

#number MISSION.MissionReportTrigger

#string MISSION.MissionStatus

#number MISSION.MissionTimeInterval

#string MISSION.Name

MISSION.New(string, string, string, string, self, MissionName, MissionPriority, MissionBriefing, MissionCoalition)

  This is the main MISSION declaration method.

  Each Mission is like the master or a Mission orchestration between, Clients, Tasks, Stages etc.

  ### Parameters

  - `string` : MissionName is the name of the mission. This name will be used to reference the status of each mission by the players.

  - `string` : MissionPriority is a string indicating the "priority" of the Mission. f.e. "Primary", "Secondary" or "First", "Second". It is free format and up to the Mission designer to choose. There are no rules behind this field.

  - `string` : MissionBriefing is a string indicating the mission briefing to be shown when a player joins a CLIENT.

  - `string` : MissionCoalition is a string indicating the coalition or party to which this mission belongs to. It is free format and can be chosen freely by the mission designer. Note that this field is not to be confused with the coalition concept of the ME. Examples of a Mission Coalition could be "NATO", "CCCP", "Intruders", "Terrorists"...

  - `self` :

  - `MissionName` :

  - `MissionPriority` :

  - `MissionBriefing` :

  - `MissionCoalition` :

  ### Return value

  MISSION

  ### Usage:

      -- Declare a few missions.
      local Mission = MISSIONSCHEDULER.AddMission( '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' )
      local Mission = MISSIONSCHEDULER.AddMission( 'Patriots', 'Primary', 'Our intelligence reports that 3 Patriot SAM defense batteries are located near Ruisi, Kvarhiti and Gori.', 'Russia'  )
      local Mission = MISSIONSCHEDULER.AddMission( 'Package Delivery', 'Operational', 'In order to be in full control of the situation, we need you to deliver a very important package at a secret location. Fly undetected through the NATO defenses and deliver the secret package. The secret agent is located at waypoint 4.', 'Russia'  )
      local Mission = MISSIONSCHEDULER.AddMission( 'Rescue General', 'Tactical', 'Our intelligence has received a remote signal behind Gori. We believe it is a very important Russian General that was captured by Georgia. Go out there and rescue him! Ensure you stay out of the battle zone, keep south. Waypoint 4 is the location of our Russian General.', 'Russia'  )
      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' )
      local Mission = MISSIONSCHEDULER.AddMission( 'SA-6 SAMs', 'Primary', 'Our intelligence reports that 3 SA-6 SAM defense batteries are located near Didmukha, Khetagurov and Berula. Eliminate the Russian SAMs.', 'NATO'  )
      local Mission = MISSIONSCHEDULER.AddMission( 'NATO Sling Load', 'Operational', 'Fly to the cargo pickup zone at Dzegvi or Kaspi, and sling the cargo to Soganlug airbase.', 'NATO' )
      local Mission = MISSIONSCHEDULER.AddMission( 'Rescue secret agent', 'Tactical', 'In order to be in full control of the situation, we need you to rescue a secret agent from the woods behind enemy lines. Avoid the Russian defenses and rescue the agent. Keep south until Khasuri, and keep your eyes open for any SAM presence. The agent is located at waypoint 4 on your kneeboard.', 'NATO'  )

MISSION:Ongoing()

  Set a Mission to ongoing.

MISSION:Pending()

  Set a Mission to pending.

#number MISSION.REPEAT

MISSION:ReportToAll()

  Report the status of all MISSIONs to all active Clients.

MISSION:ReportTrigger()

  Handles the reporting.

  After certain time intervals, a MISSION report MESSAGE will be shown to All Players.

#number MISSION.SUCCESS

MISSION.ShowBriefing(CLIENT, self, Client)

  Show the briefing of the MISSION to the CLIENT.

  ### Parameters

  - `CLIENT` : Client to show briefing to.

  - `self` :

  - `Client` :

  ### Return value

  CLIENT

MISSION:StatusToClients()

  Send the status of the MISSION to all Clients.

MISSION._ActiveTasks

MISSION._Clients

MISSION._GoalTasks

MISSION._Tasks

## Type `MISSIONSCHEDULER`

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.

### Field(s)

MISSIONSCHEDULER.AddMission(Mission)

  This is the main MISSION declaration method.

  Each Mission is like the master or a Mission orchestration between, Clients, Tasks, Stages etc.

  ### Parameter

  - `Mission` : is the MISSION object instantiated by MISSION.

  ### Return value

  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 )

MISSIONSCHEDULER.FindMission(MissionName)

  Find a MISSION within the MISSIONSCHEDULER.

  ### Parameter

  - `MissionName` : is the name of the MISSION given at declaration using AddMission.

  ### Return value

  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' )

#number MISSIONSCHEDULER.MissionCount

MISSIONSCHEDULER.Missions

MISSIONSCHEDULER.RemoveMission(MissionName)

  Remove a MISSION from the MISSIONSCHEDULER.

  ### Parameter

  - `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' )

MISSIONSCHEDULER.ReportMenu()

  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.

MISSIONSCHEDULER.ReportMissionsFlash(TimeInterval)

  Internal function used by the MISSIONSCHEDULER menu.

  ### Parameter

  - `TimeInterval` :

MISSIONSCHEDULER.ReportMissionsHide(Prm)

  Internal function used by the MISSIONSCHEDULER menu.

  ### Parameter

  - `Prm` :

MISSIONSCHEDULER.ReportMissionsShow()

  Internal function used by the MISSIONSCHEDULER menu.

MISSIONSCHEDULER.Scheduler()

  This is the main MISSIONSCHEDULER Scheduler function.

  It is considered internal and is automatically created when the Mission.lua file is included.

MISSIONSCHEDULER.SchedulerId

MISSIONSCHEDULER:Scoring(Scoring)

  Adds a mission scoring to the game.

  ### Parameter

  - `Scoring` :

MISSIONSCHEDULER.Start()

  Start the MISSIONSCHEDULER.

MISSIONSCHEDULER.Stop()

  Stop the MISSIONSCHEDULER.

MISSIONSCHEDULER:Time(TimeSeconds, TimeIntervalShow, TimeShow)

  ### Parameters

  - `TimeSeconds` :

  - `TimeIntervalShow` :

  - `TimeShow` :

#number MISSIONSCHEDULER.TimeIntervalCount

#number MISSIONSCHEDULER.TimeIntervalShow

#number MISSIONSCHEDULER.TimeSeconds

#number MISSIONSCHEDULER.TimeShow