mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
COMMANDCENTER class added, Event handlers added, HQs working with missions
- Handling menus - Reporting missions - ...
This commit is contained in:
148
Moose Development/Moose/Tasking/CommandCenter.lua
Normal file
148
Moose Development/Moose/Tasking/CommandCenter.lua
Normal file
@@ -0,0 +1,148 @@
|
||||
--- A COMMANDCENTER is the owner of multiple missions within MOOSE.
|
||||
-- A COMMANDCENTER governs multiple missions, the tasking and the reporting.
|
||||
-- @module CommandCenter
|
||||
|
||||
--- The COMMANDCENTER class
|
||||
-- @type COMMANDCENTER
|
||||
-- @field Wrapper.Group#GROUP HQ
|
||||
-- @list<Tasking.Mission#MISSION> Missions
|
||||
-- @extends Core.Base#BASE
|
||||
COMMANDCENTER = {
|
||||
ClassName = "COMMANDCENTER",
|
||||
Name = "",
|
||||
}
|
||||
|
||||
--- The REPORT class
|
||||
-- @type REPORT
|
||||
-- @extends Core.Base#BASE
|
||||
REPORT = {
|
||||
ClassName = "REPORT",
|
||||
}
|
||||
|
||||
--- Create a new REPORT.
|
||||
-- @param #REPORT self
|
||||
-- @param #string Title
|
||||
-- @return #REPORT
|
||||
function REPORT:New( Title )
|
||||
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
self.Report = {}
|
||||
self.Report[#self.Report+1] = Title
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a new line to a REPORT.
|
||||
-- @param #REPORT self
|
||||
-- @param #string Text
|
||||
-- @return #REPORT
|
||||
function REPORT:Add( Text )
|
||||
self.Report[#self.Report+1] = Text
|
||||
return self.Report[#self.Report+1]
|
||||
end
|
||||
|
||||
function REPORT:Text()
|
||||
return table.concat( self.Report, "\n" )
|
||||
end
|
||||
|
||||
|
||||
--- The constructor takes an IDENTIFIABLE as the HQ command center.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @param Wrapper.Positionable#POSITIONABLE HQ
|
||||
-- @param #string HQName
|
||||
-- @return #COMMANDCENTER
|
||||
function COMMANDCENTER:New( HQ, HQName )
|
||||
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
self.HQ = HQ
|
||||
self.HQName = HQName or HQ:GetName()
|
||||
self.HQCoalition = HQ:GetCoalition()
|
||||
|
||||
self.Missions = {}
|
||||
setmetatable( self.Missions, { __mode = "v" } )
|
||||
|
||||
self:EventOnBirth(
|
||||
--- @param Core.Event#EVENTDATA EventData
|
||||
function( HQ, EventData )
|
||||
self:E( { EventData } )
|
||||
local EventGroup = GROUP:Find( EventData.IniDCSGroup )
|
||||
if EventGroup and HQ:HasGroup( EventGroup ) then
|
||||
local MenuHQ = MENU_GROUP:New( EventGroup, "HQ" )
|
||||
local MenuReporting = MENU_GROUP:New( EventGroup, "Reporting", MenuHQ )
|
||||
local MenuMissions = MENU_GROUP_COMMAND:New( EventGroup, "Missions", MenuReporting, HQ.ReportMissions, HQ, EventGroup )
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the name of the HQ command center.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @return #string
|
||||
function COMMANDCENTER:GetName()
|
||||
|
||||
return self.HQName
|
||||
end
|
||||
|
||||
|
||||
--- Add a MISSION to be governed by the HQ command center.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @param Tasking.Mission#MISSION Mission
|
||||
-- @return Tasking.Mission#MISSION
|
||||
function COMMANDCENTER:AddMission( Mission )
|
||||
|
||||
self.Missions[Mission] = Mission
|
||||
|
||||
return Mission
|
||||
end
|
||||
|
||||
--- Removes a MISSION to be governed by the HQ command center.
|
||||
-- The given Mission is not nilified.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @param Tasking.Mission#MISSION Mission
|
||||
-- @return Tasking.Mission#MISSION
|
||||
function COMMANDCENTER:RemoveMission( Mission )
|
||||
|
||||
self.Missions[Mission] = nil
|
||||
|
||||
return Mission
|
||||
end
|
||||
|
||||
--- Checks of the COMMANDCENTER has a GROUP.
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @param Wrapper.Group#GROUP
|
||||
-- @return #boolean
|
||||
function COMMANDCENTER:HasGroup( MissionGroup )
|
||||
|
||||
local Has = false
|
||||
|
||||
for MissionID, Mission in pairs( self.Missions ) do
|
||||
local Mission = Mission -- Tasking.Mission#MISSION
|
||||
if Mission:HasGroup( MissionGroup ) then
|
||||
Has = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return Has
|
||||
end
|
||||
|
||||
|
||||
--- Report the status of all MISSIONs to a GROUP.
|
||||
function COMMANDCENTER:ReportMissions( ReportGroup )
|
||||
self:E( ReportGroup )
|
||||
|
||||
local Report = REPORT:New()
|
||||
|
||||
for MissionID, Mission in pairs( self.Missions ) do
|
||||
local Mission = Mission -- Tasking.Mission#MISSION
|
||||
Report:Add( " - " .. Mission:ReportStatus() )
|
||||
end
|
||||
|
||||
MESSAGE:New( Report:Text(), 30, "Status Report Missions from " .. self:GetName() .. "\n" ):ToGroup( ReportGroup )
|
||||
|
||||
end
|
||||
|
||||
@@ -485,6 +485,9 @@ do -- DETECTION_DISPATCHER
|
||||
|
||||
end
|
||||
|
||||
-- TODO set menus using the HQ coordinator
|
||||
--Mission:SetMenu()
|
||||
|
||||
if #AreaMsg > 0 then
|
||||
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
if not TaskGroup:GetState( TaskGroup, "Assigned" ) then
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
--- The MISSION class
|
||||
-- @type MISSION
|
||||
-- @extends Base#BASE
|
||||
-- @field #MISSION.Clients _Clients
|
||||
-- @field Menu#MENU_COALITION MissionMenu
|
||||
-- @field #string MissionBriefing
|
||||
-- @extends Core.StateMachine#STATEMACHINE
|
||||
MISSION = {
|
||||
ClassName = "MISSION",
|
||||
Name = "",
|
||||
@@ -35,7 +35,6 @@ MISSION = {
|
||||
|
||||
function MISSION:Meta()
|
||||
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -47,11 +46,14 @@ end
|
||||
-- @param #string MissionBriefing is a string indicating the mission briefing to be shown when a player joins a @{CLIENT}.
|
||||
-- @param DCSCoalitionObject#coalition 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"...
|
||||
-- @return #MISSION self
|
||||
function MISSION:New( MissionName, MissionPriority, MissionBriefing, MissionCoalition )
|
||||
function MISSION:New( HQ, MissionName, MissionPriority, MissionBriefing, MissionCoalition )
|
||||
|
||||
self = MISSION:Meta()
|
||||
local self = BASE:Inherit( self, STATEMACHINE:New() ) -- Core.StateMachine#STATEMACHINE
|
||||
|
||||
self:T( { MissionName, MissionPriority, MissionBriefing, MissionCoalition } )
|
||||
|
||||
self.HQ = HQ
|
||||
HQ:AddMission( self )
|
||||
self.Name = MissionName
|
||||
self.MissionPriority = MissionPriority
|
||||
self.MissionBriefing = MissionBriefing
|
||||
@@ -60,6 +62,13 @@ function MISSION:New( MissionName, MissionPriority, MissionBriefing, MissionCoal
|
||||
self.Tasks = {}
|
||||
setmetatable( self.Tasks, { __mode = "v" } )
|
||||
|
||||
-- Build the Fsm for the mission.
|
||||
|
||||
self:SetInitialState( "Idle" )
|
||||
self:AddAction( "Idle", "Start", "Ongoing" )
|
||||
self:AddAction( "Ongoing", "Stop", "Idle" )
|
||||
self:AddAction( "Ongoing", "Finish", "Finished" )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -85,6 +94,27 @@ function MISSION:GetScoring()
|
||||
return self.Scoring
|
||||
end
|
||||
|
||||
--- Get the groups for which TASKS are given in the mission
|
||||
-- @param #MISSION self
|
||||
-- @return Core.Set#SET_GROUP
|
||||
function MISSION:GetGroups()
|
||||
|
||||
local SetGroup = SET_GROUP:New()
|
||||
|
||||
for TaskID, Task in pairs( self:GetTasks() ) do
|
||||
local Task = Task -- Tasking.Task#TASK_BASE
|
||||
local GroupSet = Task:GetGroups()
|
||||
GroupSet:ForEachGroup(
|
||||
function( TaskGroup )
|
||||
SetGroup:Add( TaskGroup, TaskGroup )
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
return SetGroup
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Sets the Planned Task menu.
|
||||
-- @param #MISSION self
|
||||
@@ -279,25 +309,42 @@ function MISSION:StatusToClients()
|
||||
end
|
||||
end
|
||||
|
||||
--- Handles the reporting. After certain time intervals, a MISSION report MESSAGE will be shown to All Players.
|
||||
function MISSION:ReportTrigger()
|
||||
self:F()
|
||||
function MISSION:HasGroup( TaskGroup )
|
||||
local Has = false
|
||||
|
||||
for TaskID, Task in pairs( self:GetTasks() ) do
|
||||
local Task = Task -- Tasking.Task#TASK_BASE
|
||||
if Task:HasGroup( TaskGroup ) then
|
||||
Has = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return Has
|
||||
end
|
||||
|
||||
if self.MissionReportShow == true then
|
||||
self.MissionReportShow = false
|
||||
return true
|
||||
else
|
||||
if self.MissionReportFlash == true then
|
||||
if timer.getTime() >= self.MissionReportTrigger then
|
||||
self.MissionReportTrigger = timer.getTime() + self.MissionTimeInterval
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
--- Create a summary report of the mission (one line).
|
||||
-- @param #MISSION self
|
||||
-- @return #string
|
||||
function MISSION:ReportStatus()
|
||||
|
||||
-- List the name of the mission.
|
||||
local Name = self:GetName()
|
||||
|
||||
-- Determine the status of the mission.
|
||||
local Status = self:GetState()
|
||||
|
||||
-- Determine how many tasks are remaining.
|
||||
local TasksRemaining = 0
|
||||
for TaskID, Task in pairs( self:GetTasks() ) do
|
||||
local Task = Task -- Tasking.Task#TASK_BASE
|
||||
if Task:IsStateSuccess() or Task:IsStateFailed() then
|
||||
else
|
||||
TasksRemaining = TasksRemaining + 1
|
||||
end
|
||||
end
|
||||
|
||||
return "Mission " .. Name .. " - " .. Status .. " - " .. TasksRemaining .. " tasks remaining."
|
||||
end
|
||||
|
||||
--- Report the status of all MISSIONs to all active Clients.
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
-- @field Mission#MISSION Mission
|
||||
-- @field StateMachine#STATEMACHINE Fsm
|
||||
-- @field Set#SET_GROUP SetGroup The Set of Groups assigned to the Task
|
||||
-- @extends Core.Base#BASE
|
||||
-- @extends Core.StateMachine#STATEMACHINE_TASK
|
||||
TASK_BASE = {
|
||||
ClassName = "TASK_BASE",
|
||||
TaskScheduler = nil,
|
||||
@@ -106,6 +106,13 @@ function TASK_BASE:New( Mission, SetGroupAssign, TaskName, TaskType, TaskCategor
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the SET_GROUP assigned to the TASK.
|
||||
-- @param #TASK_BASE self
|
||||
-- @return Core.Set#SET_GROUP
|
||||
function TASK_BASE:GetGroups()
|
||||
return self.SetGroup
|
||||
end
|
||||
|
||||
--- Cleans all references of a TASK_BASE.
|
||||
-- @param #TASK_BASE self
|
||||
-- @return #nil
|
||||
@@ -151,6 +158,16 @@ function TASK_BASE:AssignToGroup( TaskGroup )
|
||||
return self
|
||||
end
|
||||
|
||||
---
|
||||
-- @param #TASK_BASE self
|
||||
-- @param Wrapper.Group#GROUP FindGroup
|
||||
-- @return #boolean
|
||||
function TASK_BASE:HasGroup( FindGroup )
|
||||
|
||||
return self:GetGroups():IsIncludeObject( FindGroup )
|
||||
|
||||
end
|
||||
|
||||
--- Assign the @{Task} to an alive @{Unit}.
|
||||
-- @param #TASK_BASE self
|
||||
-- @param Unit#UNIT TaskUnit
|
||||
|
||||
@@ -51,8 +51,8 @@ do -- TASK_SEAD
|
||||
Fsm:AddProcess( "Assigned", "Route", PROCESS_ROUTE_ZONE:New( self.TargetZone ), { Arrived = "Update" } )
|
||||
Fsm:AddAction ( "Rejected", "Eject", "Planned" )
|
||||
Fsm:AddAction ( "Arrived", "Update", "Updated" )
|
||||
Fsm:AddProcess( "*", "Account", PROCESS_ACCOUNT_DEADS:New( self.TargetSetUnit, "SEAD" ), { Accounted = "Success" } )
|
||||
Fsm:AddProcess( "*", "Smoke", PROCESS_SMOKE_TARGETS_ZONE:New( self.TargetSetUnit, self.TargetZone ) )
|
||||
Fsm:AddProcess( "Updated", "Account", PROCESS_ACCOUNT_DEADS:New( self.TargetSetUnit, "SEAD" ), { Accounted = "Success" } )
|
||||
Fsm:AddProcess( "Updated", "Smoke", PROCESS_SMOKE_TARGETS_ZONE:New( self.TargetSetUnit, self.TargetZone ) )
|
||||
Fsm:AddAction ( "Accounted", "Success", "Success" )
|
||||
Fsm:AddAction ( "Failed", "Fail", "Failed" )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user