mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-11 11:48:38 +00:00
First prototype of task dispatching with menu
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
--
|
||||
-- 1) @{Fac#DETECTION_MANAGER} class, extends @{Base#BASE}
|
||||
-- ==============================================
|
||||
-- The @{Fac#DETECTION_MANAGER} class defines the core functions to report detected objects to clients.
|
||||
-- The @{Fac#DETECTION_MANAGER} class defines the core functions to report detected objects to groups.
|
||||
-- Reportings can be done in several manners, and it is up to the derived classes if DETECTION_MANAGER to model the reporting behaviour.
|
||||
--
|
||||
-- 1.1) DETECTION_MANAGER constructor:
|
||||
@@ -44,26 +44,26 @@
|
||||
|
||||
--- DETECTION_MANAGER class.
|
||||
-- @type DETECTION_MANAGER
|
||||
-- @field Set#SET_CLIENT ClientSet The clients to which the FAC will report to.
|
||||
-- @field Set#SET_GROUP SetGroup The groups to which the FAC will report to.
|
||||
-- @field Detection#DETECTION_BASE Detection The DETECTION_BASE object that is used to report the detected objects.
|
||||
-- @extends Base#BASE
|
||||
DETECTION_MANAGER = {
|
||||
ClassName = "DETECTION_MANAGER",
|
||||
ClientSet = nil,
|
||||
SetGroup = nil,
|
||||
Detection = nil,
|
||||
}
|
||||
|
||||
--- FAC constructor.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
-- @param Set#SET_CLIENT ClientSet
|
||||
-- @param Set#SET_GROUP SetGroup
|
||||
-- @param Detection#DETECTION_BASE Detection
|
||||
-- @return #DETECTION_MANAGER self
|
||||
function DETECTION_MANAGER:New( ClientSet, Detection )
|
||||
function DETECTION_MANAGER:New( SetGroup, Detection )
|
||||
|
||||
-- Inherits from BASE
|
||||
local self = BASE:Inherit( self, BASE:New() ) -- Fac#DETECTION_MANAGER
|
||||
local self = BASE:Inherit( self, BASE:New() ) -- Detection#DETECTION_MANAGER
|
||||
|
||||
self.ClientSet = ClientSet
|
||||
self.SetGroup = SetGroup
|
||||
self.Detection = Detection
|
||||
|
||||
self:SetReportInterval( 60 )
|
||||
@@ -102,7 +102,7 @@ function DETECTION_MANAGER:GetReportDisplayTime()
|
||||
return self._ReportDisplayTime
|
||||
end
|
||||
|
||||
--- Reports the detected items to the @{Set#SET_CLIENT}.
|
||||
--- Reports the detected items to the @{Set#SET_GROUP}.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
-- @param Set#SET_BASE DetectedSets The detected Sets created by the @{Detection#DETECTION_BASE} object.
|
||||
-- @return #DETECTION_MANAGER self
|
||||
@@ -129,17 +129,18 @@ function DETECTION_MANAGER:Schedule( DelayTime, ReportInterval )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Report the detected @{Unit#UNIT}s detected within the @{DetectION#DETECTION_BASE} object to the @{Set#SET_CLIENT}s.
|
||||
--- Report the detected @{Unit#UNIT}s detected within the @{Detection#DETECTION_BASE} object to the @{Set#SET_GROUP}s.
|
||||
-- @param #DETECTION_MANAGER self
|
||||
function DETECTION_MANAGER:_FacScheduler( SchedulerName )
|
||||
self:F2( { SchedulerName } )
|
||||
|
||||
self.ClientSet:ForEachClient(
|
||||
--- @param Client#CLIENT Client
|
||||
function( Client )
|
||||
if Client:IsAlive() then
|
||||
self.SetGroup:ForEachGroup(
|
||||
--- @param Group#GROUP Group
|
||||
function( Group )
|
||||
if Group:IsAlive() then
|
||||
local DetectedSets = self.Detection:GetDetectedSets()
|
||||
return self:ProcessDetected( Client, DetectedSets )
|
||||
local DetectedZones =self.Detection:GetDetectedZones()
|
||||
return self:ProcessDetected( Group, DetectedSets, DetectedZones )
|
||||
end
|
||||
end
|
||||
)
|
||||
@@ -151,7 +152,7 @@ end
|
||||
|
||||
--- FAC_REPORTING class.
|
||||
-- @type FAC_REPORTING
|
||||
-- @field Set#SET_CLIENT ClientSet The clients to which the FAC will report to.
|
||||
-- @field Set#SET_GROUP SetGroup The groups to which the FAC will report to.
|
||||
-- @field Detection#DETECTION_BASE Detection The DETECTION_BASE object that is used to report the detected objects.
|
||||
-- @extends #DETECTION_MANAGER
|
||||
FAC_REPORTING = {
|
||||
@@ -161,27 +162,28 @@ FAC_REPORTING = {
|
||||
|
||||
--- FAC_REPORTING constructor.
|
||||
-- @param #FAC_REPORTING self
|
||||
-- @param Set#SET_CLIENT ClientSet
|
||||
-- @param Set#SET_GROUP SetGroup
|
||||
-- @param Detection#DETECTION_BASE Detection
|
||||
-- @return #FAC_REPORTING self
|
||||
function FAC_REPORTING:New( ClientSet, Detection )
|
||||
function FAC_REPORTING:New( SetGroup, Detection )
|
||||
|
||||
-- Inherits from DETECTION_MANAGER
|
||||
local self = BASE:Inherit( self, DETECTION_MANAGER:New( ClientSet, Detection ) ) -- #FAC_REPORTING
|
||||
local self = BASE:Inherit( self, DETECTION_MANAGER:New( SetGroup, Detection ) ) -- #FAC_REPORTING
|
||||
|
||||
self:Schedule( 5, 60 )
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Reports the detected items to the @{Set#SET_CLIENT}.
|
||||
--- Reports the detected items to the @{Set#SET_GROUP}.
|
||||
-- @param #FAC_REPORTING self
|
||||
-- @param Client#CLIENT Client The @{Client} object to where the report needs to go.
|
||||
-- @param Group#GROUP Group The @{Group} object to where the report needs to go.
|
||||
-- @param Set#SET_BASE DetectedSets The detected Sets created by the @{Detection#DETECTION_BASE} object.
|
||||
-- @return #boolean Return true if you want the reporting to continue... false will cancel the reporting loop.
|
||||
function FAC_REPORTING:ProcessDetected( Client, DetectedSets )
|
||||
self:F2( Client )
|
||||
function FAC_REPORTING:ProcessDetected( Group, DetectedSets, DetectedZones )
|
||||
self:F2( Group )
|
||||
|
||||
self:E( Group )
|
||||
local DetectedMsg = {}
|
||||
for DetectedUnitSetID, DetectedUnitSet in pairs( DetectedSets ) do
|
||||
local UnitSet = DetectedUnitSet -- Set#SET_UNIT
|
||||
@@ -202,8 +204,8 @@ function FAC_REPORTING:ProcessDetected( Client, DetectedSets )
|
||||
local MessageText = table.concat( MT, ", " )
|
||||
DetectedMsg[#DetectedMsg+1] = " - Group #" .. DetectedUnitSetID .. ": " .. MessageText
|
||||
end
|
||||
local FACGroup = self.Detection:GetFACGroup()
|
||||
FACGroup:MessageToClient( "Reporting detected target groups:\n" .. table.concat( DetectedMsg, "\n" ), self:GetReportDisplayTime(), Client )
|
||||
local FACGroup = self.Detection:GetDetectionGroups()
|
||||
FACGroup:MessageToGroup( "Reporting detected target groups:\n" .. table.concat( DetectedMsg, "\n" ), self:GetReportDisplayTime(), Group )
|
||||
|
||||
return true
|
||||
end
|
||||
@@ -213,80 +215,83 @@ end
|
||||
|
||||
--- TASK_DISPATCHER class.
|
||||
-- @type TASK_DISPATCHER
|
||||
-- @field Set#SET_CLIENT ClientSet The clients to which the FAC will report to.
|
||||
-- @field Set#SET_GROUP SetGroup The groups to which the FAC will report to.
|
||||
-- @field Detection#DETECTION_BASE Detection The DETECTION_BASE object that is used to report the detected objects.
|
||||
-- @field Mission#MISSION Mission
|
||||
-- @field Group#GROUP CommandCenter
|
||||
-- @extends #DETECTION_MANAGER
|
||||
TASK_DISPATCHER = {
|
||||
ClassName = "TASK_DISPATCHER",
|
||||
Mission = nil,
|
||||
CommandCenter = nil,
|
||||
Detection = nil,
|
||||
}
|
||||
|
||||
|
||||
--- TASK_DISPATCHER constructor.
|
||||
-- @param #TASK_DISPATCHER self
|
||||
-- @param Set#SET_CLIENT ClientSet
|
||||
-- @param Set#SET_GROUP SetGroup
|
||||
-- @param Detection#DETECTION_BASE Detection
|
||||
-- @return #TASK_DISPATCHER self
|
||||
function TASK_DISPATCHER:New( ClientSet, Detection, TaskType, Priority )
|
||||
function TASK_DISPATCHER:New( Mission, CommandCenter, SetGroup, Detection )
|
||||
|
||||
-- Inherits from DETECTION_MANAGER
|
||||
local self = BASE:Inherit( self, DETECTION_MANAGER:New( ClientSet, Detection ) ) -- #TASK_DISPATCHER
|
||||
local self = BASE:Inherit( self, DETECTION_MANAGER:New( SetGroup, Detection ) ) -- #TASK_DISPATCHER
|
||||
|
||||
self:Schedule( 5, 60 )
|
||||
self.Detection = Detection
|
||||
self.CommandCenter = CommandCenter
|
||||
self.Mission = Mission
|
||||
|
||||
self:Schedule( 30 )
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Assigns tasks in relation to the detected items to the @{Set#SET_CLIENT}.
|
||||
-- @param #FAC_REPORTING self
|
||||
-- @param Client#CLIENT Client The @{Client} object to where the report needs to go.
|
||||
-- @param Set#SET_BASE DetectedSets The detected Sets created by the @{Detection#DETECTION_BASE} object.
|
||||
-- @param Mission#MISSIONSCHEDULER MissionScheduler
|
||||
-- @param #string TaskID The task to be executed.
|
||||
--- Assigns tasks in relation to the detected items to the @{Set#SET_GROUP}.
|
||||
-- @param #TASK_DISPATCHER self
|
||||
-- @param Group#GROUP Group The @{Group} object to where the report needs to go.
|
||||
-- @param #table DetectedSets The detected Sets created by the @{Detection#DETECTION_BASE} object.
|
||||
-- @param #table DetectedZones The detected Zones cretaed by the @{Detection#DETECTION_BASE} object.
|
||||
-- @return #boolean Return true if you want the task assigning to continue... false will cancel the loop.
|
||||
function TASK_DISPATCHER:ProcessDetected( Client, DetectedSets, MissionScheduler, Targets )
|
||||
self:F2( Client )
|
||||
function TASK_DISPATCHER:ProcessDetected( TaskGroup, DetectedSets, DetectedZones )
|
||||
self:F2( TaskGroup )
|
||||
|
||||
local DetectedMsg = {}
|
||||
|
||||
local FACGroup = self.Detection:GetFACGroup()
|
||||
local FACGroup = self.Detection:GetDetectionGroups()
|
||||
local FACGroupName = FACGroup:GetName()
|
||||
|
||||
for DetectedUnitSetID, DetectedUnitSet in pairs( DetectedSets ) do
|
||||
self:E( TaskGroup )
|
||||
|
||||
--- First we need to the detected targets.
|
||||
for DetectedID, DetectedUnitSet in pairs( DetectedSets ) do
|
||||
local UnitSet = DetectedUnitSet -- Set#SET_UNIT
|
||||
local MT = {} -- Message Text
|
||||
local UnitTypes = {}
|
||||
if not MissionScheduler.FindMission( FACGroupName ) then
|
||||
local Mission = MISSION:New()
|
||||
MissionScheduler.AddMission(Mission)
|
||||
end
|
||||
|
||||
for DetectedUnitID, DetectedUnitData in pairs( UnitSet:GetSet() ) do
|
||||
|
||||
local DetectedUnit = DetectedUnitData -- Unit#UNIT
|
||||
local UnitType = DetectedUnit:GetTypeName()
|
||||
self:E( DetectedUnit )
|
||||
local DetectedUnitName = DetectedUnit:GetName()
|
||||
local UnitType = DetectedUnit:GetTypeName()
|
||||
|
||||
if Task:GetTarget( DetectedUnitName ) then
|
||||
if not UnitTypes[UnitType] then
|
||||
UnitTypes[UnitType] = 1
|
||||
else
|
||||
UnitTypes[UnitType] = UnitTypes[UnitType] + 1
|
||||
end
|
||||
Task:AddTarget( DetectedUnit )
|
||||
-- Determine if the set has radar targets. If it does, construct a SEAD task.
|
||||
local RadarCount = UnitSet:HasRadar( Unit.RadarType.AS )
|
||||
if RadarCount > 0 then
|
||||
local DetectedZone = DetectedZones[DetectedID]
|
||||
local Task = TASK_SEAD:New( self.Mission, UnitSet, DetectedZone, UnitSet )
|
||||
self.Mission:AddTask( Task )
|
||||
MT[#MT+1] = "SEAD task added."
|
||||
end
|
||||
end
|
||||
|
||||
for UnitTypeID, UnitType in pairs( UnitTypes ) do
|
||||
MT[#MT+1] = Task:GetCommand() .. " " .. UnitType .. " of " .. UnitTypeID
|
||||
end
|
||||
|
||||
local MessageText = table.concat( MT, ", " )
|
||||
DetectedMsg[#DetectedMsg+1] = " - Group #" .. DetectedUnitSetID .. ": " .. MessageText
|
||||
DetectedMsg[#DetectedMsg+1] = " - Group #" .. DetectedID .. ": " .. MessageText
|
||||
end
|
||||
|
||||
Task:Assign( Client )
|
||||
local FACGroup = self.Detection:GetFACGroup()
|
||||
FACGroup:MessageToClient( "Reporting detected target groups:\n" .. table.concat( DetectedMsg, "\n" ), self:GetReportDisplayTime(), Client )
|
||||
self.CommandCenter:MessageToGroup( "Reporting tasks for target groups:\n" .. table.concat( DetectedMsg, "\n" ), self:GetReportDisplayTime(), TaskGroup )
|
||||
self.Mission:FillMissionMenu( TaskGroup )
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user