This commit is contained in:
FlightControl
2016-12-15 09:50:21 +01:00
parent 63e46ad029
commit 51d8e2b7d8
7 changed files with 263 additions and 24 deletions

View File

@@ -74,8 +74,9 @@ function COMMANDCENTER:New( CommandCenterPositionable, CommandCenterName )
local EventGroup = GROUP:Find( EventData.IniDCSGroup )
if EventGroup and self:HasGroup( EventGroup ) then
local MenuReporting = MENU_GROUP:New( EventGroup, "Reporting", self.CommandCenterMenu )
local MenuMissions = MENU_GROUP_COMMAND:New( EventGroup, "Missions", MenuReporting, self.ReportMissions, self, EventGroup )
self:ReportMissions( EventGroup )
local MenuMissionsSummary = MENU_GROUP_COMMAND:New( EventGroup, "Missions Summary Report", MenuReporting, self.ReportSummary, self, EventGroup )
local MenuMissionsDetails = MENU_GROUP_COMMAND:New( EventGroup, "Missions Details Report", MenuReporting, self.ReportDetails, self, EventGroup )
self:ReportSummary( EventGroup )
end
end
)
@@ -91,7 +92,9 @@ function COMMANDCENTER:New( CommandCenterPositionable, CommandCenterName )
function( self, EventData )
local PlayerUnit = EventData.IniUnit
for MissionID, Mission in pairs( self:GetMissions() ) do
local Mission = Mission -- Tasking.Mission#MISSION
Mission:AddUnit( PlayerUnit )
Mission:ReportDetails()
end
end
)
@@ -109,7 +112,20 @@ function COMMANDCENTER:New( CommandCenterPositionable, CommandCenterName )
end
end
)
-- Handle when a player leaves a slot and goes back to spectators ...
-- The PlayerUnit will be UnAssigned from the Task.
-- When there is no Unit left running the Task, the Task goes into Abort...
self:EventOnCrash(
--- @param #TASK_BASE self
-- @param Core.Event#EVENTDATA EventData
function( self, EventData )
local PlayerUnit = EventData.IniUnit
for MissionID, Mission in pairs( self:GetMissions() ) do
Mission:CrashUnit( PlayerUnit )
end
end
)
return self
end
@@ -208,16 +224,18 @@ function COMMANDCENTER:MessageToCoalition( Message )
self:GetPositionable():MessageToBlue( Message , 20, CCCoalition )
end
--- Report the status of all MISSIONs to a GROUP.
-- Each Mission is listed, with an indication how many Tasks are still to be completed.
-- @param #COMMANDCENTER self
function COMMANDCENTER:ReportMissions( ReportGroup )
function COMMANDCENTER:ReportSummary( 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() )
Report:Add( " - " .. Mission:ReportOverview() )
end
self:GetPositionable():MessageToGroup( Report:Text(), 30, ReportGroup )
@@ -225,18 +243,18 @@ function COMMANDCENTER:ReportMissions( ReportGroup )
end
--- Report the status of a Task to a Group.
-- Report the details of a Mission, listing the Mission, and all the Task details.
-- @param #COMMANDCENTER self
function COMMANDCENTER:ReportTaskStatus( ReportGroup, Task )
function COMMANDCENTER:ReportDetails( ReportGroup, Task )
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() )
Report:Add( " - " .. Mission:ReportDetails() )
end
self:GetPositionable():MessageToGroup( Report:Text(), 30, ReportGroup )
end

View File

@@ -46,7 +46,8 @@ function MISSION:New( CommandCenter, MissionName, MissionPriority, MissionBriefi
self:AddTransition( "Idle", "Start", "Ongoing" )
self:AddTransition( "Ongoing", "Stop", "Idle" )
self:AddTransition( "Ongoing", "Finish", "Finished" )
self:AddTransition( "Ongoing", "Complete", "Completed" )
self:AddTransition( "*", "Fail", "Failed" )
self:T( { MissionName, MissionPriority, MissionBriefing, MissionCoalition } )
@@ -60,12 +61,35 @@ function MISSION:New( CommandCenter, MissionName, MissionPriority, MissionBriefi
self.Tasks = {}
-- Build the Fsm for the mission.
return self
end
--- FSM function for a MISSION
-- @param #MISSION self
-- @param #string Event
-- @param #string From
-- @param #string To
function MISSION:onbeforeComplete( Event, From, To )
for TaskID, Task in pairs( self:GetTasks() ) do
local Task = Task -- Tasking.Task#TASK_BASE
if not Task:IsStateSuccess() and not Task:IsStateFailed() and not Task:IsStateAborted() and not Task:IsStateCancelled() then
return false -- Mission cannot be completed. Other Tasks are still active.
end
end
return true -- Allow Mission completion.
end
--- FSM function for a MISSION
-- @param #MISSION self
-- @param #string Event
-- @param #string From
-- @param #string To
function MISSION:onenterCompleted( Event, From, To )
self:GetCommandCenter():MessageToCoalition( "Mission " .. self:GetName() .. " has been completed! Good job guys!" )
end
--- Gets the mission name.
-- @param #MISSION self
-- @return #MISSION self
@@ -114,6 +138,28 @@ function MISSION:AbortUnit( PlayerUnit )
return PlayerUnitRemoved
end
--- Handles a crash of a PlayerUnit from the Mission.
-- For each Task within the Mission, the PlayerUnit is removed from Task where it is assigned.
-- If the Unit was not part of a Task in the Mission, false is returned.
-- If the Unit is part of a Task in the Mission, true is returned.
-- @param #MISSION self
-- @param Wrapper.Unit#UNIT PlayerUnit The CLIENT or UNIT of the Player crashing.
-- @return #boolean true if Unit is part of a Task in the Mission.
function MISSION:CrashUnit( PlayerUnit )
self:F( { PlayerUnit = PlayerUnit } )
local PlayerUnitRemoved = false
for TaskID, Task in pairs( self:GetTasks() ) do
if Task:CrashUnit( PlayerUnit ) then
PlayerUnitRemoved = true
end
end
return PlayerUnitRemoved
end
--- Add a scoring to the mission.
-- @param #MISSION self
-- @return #MISSION self
@@ -371,10 +417,12 @@ function MISSION:HasGroup( TaskGroup )
return Has
end
--- Create a summary report of the mission (one line).
--- Create a summary report of the Mission (one line).
-- @param #MISSION self
-- @return #string
function MISSION:ReportStatus()
function MISSION:ReportSummary()
local Report = REPORT:New()
-- List the name of the mission.
local Name = self:GetName()
@@ -392,7 +440,59 @@ function MISSION:ReportStatus()
end
end
return "Mission " .. Name .. " - " .. Status .. " - " .. TasksRemaining .. " tasks remaining."
Report:Add( "Mission " .. Name .. " - " .. Status .. " - " .. TasksRemaining .. " tasks remaining." )
return Report:Text()
end
--- Create a overview report of the Mission (multiple lines).
-- @param #MISSION self
-- @return #string
function MISSION:ReportOverview()
local Report = REPORT:New()
-- List the name of the mission.
local Name = self:GetName()
-- Determine the status of the mission.
local Status = self:GetState()
Report:Add( "Mission " .. Name .. " - State '" .. Status .. "'" )
-- Determine how many tasks are remaining.
local TasksRemaining = 0
for TaskID, Task in pairs( self:GetTasks() ) do
local Task = Task -- Tasking.Task#TASK_BASE
Report:Add( "- " .. Task:ReportSummary() )
end
return Report:Text()
end
--- Create a detailed report of the Mission, listing all the details of the Task.
-- @param #MISSION self
-- @return #string
function MISSION:ReportDetails()
local Report = REPORT:New()
-- List the name of the mission.
local Name = self:GetName()
-- Determine the status of the mission.
local Status = self:GetState()
Report:Add( "Mission " .. Name .. " - State '" .. Status .. "'" )
-- Determine how many tasks are remaining.
local TasksRemaining = 0
for TaskID, Task in pairs( self:GetTasks() ) do
local Task = Task -- Tasking.Task#TASK_BASE
Report:Add( Task:ReportDetails() )
end
return Report:Text()
end
--- Report the status of all MISSIONs to all active Clients.

View File

@@ -215,7 +215,7 @@ end
--- Get the Task FSM Process Template
-- @param #TASK_BASE self
-- @return Fsm.Fsm#FSM_PROCESS
function TASK_BASE:GetFsmTemplate()
function TASK_BASE:GetUnitProcess()
return self.FsmTemplate
end
@@ -223,7 +223,7 @@ end
--- Sets the Task FSM Process Template
-- @param #TASK_BASE self
-- @param Fsm.Fsm#FSM_PROCESS
function TASK_BASE:SetFsmTemplate( FsmTemplate )
function TASK_BASE:SetUnitProcess( FsmTemplate )
self.FsmTemplate = FsmTemplate
end
@@ -405,7 +405,7 @@ end
function TASK_BASE:AssignToUnit( TaskUnit )
self:F( TaskUnit:GetName() )
local FsmTemplate = self:GetFsmTemplate()
local FsmTemplate = self:GetUnitProcess()
-- Assign a new FsmUnit to TaskUnit.
local FsmUnit = self:SetStateMachine( TaskUnit, FsmTemplate:Copy( TaskUnit, self ) ) -- Fsm.Fsm#FSM_PROCESS
@@ -869,6 +869,7 @@ function TASK_BASE:onenterAssigned( Event, From, To )
self:E("Task Assigned")
self:MessageToGroups( "Task " .. self:GetName() .. " has been assigned!" )
self:GetMission():__Start()
end
@@ -883,6 +884,9 @@ function TASK_BASE:onenterSuccess( Event, From, To )
self:MessageToGroups( "Task " .. self:GetName() .. " is successful! Good job!" )
self:UnAssignFromGroups()
self:GetMission():__Complete()
end
@@ -934,3 +938,61 @@ function TASK_BASE:onstatechange( Event, From, To )
end
end
do -- Reporting
--- Create a summary report of the Task.
-- List the Task Name and Status
-- @param #TASK_BASE self
-- @return #string
function TASK_BASE:ReportSummary()
local Report = REPORT:New()
-- List the name of the Task.
local Name = self:GetName()
-- Determine the status of the Task.
local State = self:GetState()
Report:Add( "Task " .. Name .. " - State '" .. State )
return Report:Text()
end
--- Create a detailed report of the Task.
-- List the Task Status, and the Players assigned to the Task.
-- @param #TASK_BASE self
-- @return #string
function TASK_BASE:ReportDetails()
local Report = REPORT:New()
-- List the name of the Task.
local Name = self:GetName()
-- Determine the status of the Task.
local State = self:GetState()
-- Loop each Unit active in the Task, and find Player Names.
local PlayerNames = {}
for PlayerGroupID, PlayerGroup in pairs( self:GetGroups():GetSet() ) do
local Player = PlayerGroup -- Wrapper.Group#GROUP
for PlayerUnitID, PlayerUnit in pairs( PlayerGroup:GetUnits() ) do
local PlayerUnit = PlayerUnit -- Wrapper.Unit#UNIT
if PlayerUnit and PlayerUnit:IsAlive() then
local PlayerName = PlayerUnit:GetPlayerName()
PlayerNames[#PlayerNames+1] = PlayerName
end
end
PlayerNameText = table.concat( PlayerNames, ", " )
Report:Add( "Task " .. Name .. " - State '" .. State .. "' - Players " .. PlayerNameText )
end
return Report:Text()
end
end -- Reporting

View File

@@ -45,7 +45,7 @@ do -- TASK_A2G
self.TargetZone = TargetZone
self.FACUnit = FACUnit
local Fsm = self:GetFsmTemplate()
local Fsm = self:GetUnitProcess()
Fsm:AddProcess( "Planned", "Accept", FSM_ASSIGN_ACCEPT:New( "Attack the Area" ), { Assigned = "Route", Rejected = "Eject" } )
Fsm:AddProcess( "Assigned", "Route", FSM_ROUTE_ZONE:New( self.TargetZone ), { Arrived = "Update" } )

View File

@@ -45,7 +45,7 @@ do -- TASK_SEAD
self.TargetSetUnit = TargetSetUnit
self.TargetZone = TargetZone
local Fsm = self:GetFsmTemplate()
local Fsm = self:GetUnitProcess()
Fsm:AddProcess( "Planned", "Accept", FSM_ASSIGN_ACCEPT:New( self.TaskBriefing ), { Assigned = "Route", Rejected = "Eject" } )
Fsm:AddProcess( "Assigned", "Route", FSM_ROUTE_ZONE:New( self.TargetZone ), { Arrived = "Update" } )