Inform state changes

This commit is contained in:
FlightControl 2016-07-10 14:44:55 +02:00
parent 8a4b40303a
commit 153ff7bd58
12 changed files with 54 additions and 13 deletions

View File

@ -278,7 +278,12 @@ function TASK_DISPATCHER:EvaluateTaskSEAD( Mission, DetectedArea )
DetectedArea.Tasks = DetectedArea.Tasks or {}
if RadarCount > 0 then
if not DetectedArea.Tasks.SEADTask then
local Task = TASK_SEAD:New( Mission, DetectedSet, DetectedZone )
-- Here we're doing something advanced... We're copying the DetectedSet, but making a new Set only with Radar units in it.
local TargetSetUnit = SET_UNIT:New()
TargetSetUnit:CopyFilter( DetectedSet )
TargetSetUnit:FilterHasRadar( Unit.RadarType.AS )
TargetSetUnit:FilterStart()
local Task = TASK_SEAD:New( Mission, TargetSetUnit, DetectedZone )
self.Mission:AddTask( Task )
MT[#MT+1] = "SEAD"
DetectedArea.Tasks.SEADTask = Task
@ -289,7 +294,11 @@ function TASK_DISPATCHER:EvaluateTaskSEAD( Mission, DetectedArea )
end
end
if MT ~= {} then
return table.concat( MT, "," )
else
return ""
end
end
--- Creates a CAS task when there are targets for it.
@ -321,7 +330,11 @@ function TASK_DISPATCHER:EvaluateTaskCAS( Mission, DetectedArea )
end
end
if MT ~= {} then
return table.concat( MT, "," )
else
return ""
end
end
--- Creates a string of the detected items in a @{Detection}.

View File

@ -59,7 +59,7 @@ function MESSAGE:New( MessageText, MessageDuration, MessageCategory )
self.MessageCategory = ""
end
self.MessageDuration = MessageDuration
self.MessageDuration = MessageDuration or 5
self.MessageTime = timer.getTime()
self.MessageText = MessageText

View File

@ -6,6 +6,7 @@
-- @field Unit#UNIT ProcessUnit
-- @field Task#TASK Task
-- @field StateMachine#STATEMACHINE_TASK Fsm
-- @field #string ProcessName
-- @extends Base#BASE
PROCESS = {
ClassName = "TASK",
@ -16,14 +17,17 @@ PROCESS = {
--- Instantiates a new TASK Base. Should never be used. Interface Class.
-- @param #PROCESS self
-- @param #string ProcessName
-- @param Task#TASK_BASE Task
-- @param Unit#UNIT ProcessUnit
-- @return #PROCESS self
function PROCESS:New( Task, ProcessUnit )
function PROCESS:New( ProcessName, Task, ProcessUnit )
local self = BASE:Inherit( self, BASE:New() )
self:F()
self.ProcessUnit = ProcessUnit
self.Task = Task
self.ProcessName = ProcessName
self.AllowEvents = true
@ -66,13 +70,15 @@ end
--- StateMachine callback function for a PROCESS
-- @param #PROCESS self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param StateMachine#STATEMACHINE_PROCESS Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS:OnStateChange( Fsm, Event, From, To )
self:E( { Event, From, To, self.ProcessUnit.UnitName } )
MESSAGE:New( "Process " .. self.ProcessName .. " : " .. Event .. " changed to state " .. To, 15 ):ToAll()
if self.Scores[To] then
local Scoring = self.Task:GetScoring()

View File

@ -19,7 +19,7 @@ PROCESS_ASSIGN = {
function PROCESS_ASSIGN:New( Task, ProcessUnit, TaskBriefing )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( Task, ProcessUnit ) ) -- #PROCESS_ASSIGN
local self = BASE:Inherit( self, PROCESS:New( "ASSIGN", Task, ProcessUnit ) ) -- #PROCESS_ASSIGN
self.TaskBriefing = TaskBriefing

View File

@ -21,7 +21,7 @@ PROCESS_CAS = {
function PROCESS_CAS:New( Task, ProcessUnit, TargetSetUnit )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( Task, ProcessUnit ) ) -- #PROCESS_CAS
local self = BASE:Inherit( self, PROCESS:New( "CAS", Task, ProcessUnit ) ) -- #PROCESS_CAS
self.TargetSetUnit = TargetSetUnit

View File

@ -19,7 +19,7 @@ PROCESS_ROUTE = {
function PROCESS_ROUTE:New( Task, ProcessUnit, TargetZone )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( Task, ProcessUnit ) ) -- #PROCESS_ROUTE
local self = BASE:Inherit( self, PROCESS:New( "ROUTE", Task, ProcessUnit ) ) -- #PROCESS_ROUTE
self.TargetZone = TargetZone
self.DisplayInterval = 30

View File

@ -21,7 +21,7 @@ PROCESS_SEAD = {
function PROCESS_SEAD:New( Task, ProcessUnit, TargetSetUnit )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( Task, ProcessUnit ) ) -- #PROCESS_SEAD
local self = BASE:Inherit( self, PROCESS:New( "SEAD", Task, ProcessUnit ) ) -- #PROCESS_SEAD
self.TargetSetUnit = TargetSetUnit
@ -75,6 +75,7 @@ end
-- @param Event#EVENTDATA Event
function PROCESS_SEAD:OnHitTarget( Fsm, Event, From, To, Event )
MESSAGE:New( "TargetCount = " .. self.TargetSetUnit:Count(), 15 ):ToAll()
if self.TargetSetUnit:Count() > 0 then
self:NextEvent( Fsm.MoreTargets )
else

View File

@ -1453,7 +1453,7 @@ function SET_UNIT:IsIncludeObject( MUnit )
if self.Filter.RadarTypes then
local MUnitRadar = false
for RadarTypeID, RadarType in pairs( self.Filter.RadarTypes ) do
self:T3( { "Radar:", RadarType } )
self:E( { "Radar:", RadarType } )
if MUnit:HasSensors( Unit.SensorType.RADAR, RadarType ) then
MUnitRadar = true
end

View File

@ -1,4 +1,9 @@
--- This module contains the STATEMACHINE class.
-- This development is based on a state machine implementation made by Conroy Kyle.
-- The state machine can be found here: https://github.com/kyleconroy/lua-state-machine
--
-- I've taken the development and enhanced it to make the state machine hierarchical...
-- It is a fantastic development, this module.
--
-- ===
--

View File

@ -332,6 +332,19 @@ function TASK_BASE:SetBriefing( TaskBriefing )
return self
end
--- StateMachine callback function for a TASK
-- @param #TASK_BASE self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Event#EVENTDATA Event
function TASK_BASE:OnStateChange( Fsm, Event, From, To )
MESSAGE:New( "Task " .. self.TaskName .. " : " .. Event .. " changed to state " .. To, 15 ):ToAll()
self:SetState( self, "State", To )
end
--- @param #TASK_BASE self

View File

@ -78,12 +78,15 @@ end
-- @param #string From
-- @param #string To
-- @param Event#EVENTDATA Event
function TASK_SEAD:OnNext( Fsm, Event, From, To, Event )
function TASK_SEAD:OnNext( Fsm, Event, From, To )
self:SetState( self, "State", To )
end
--- @param #TASK_SEAD self
function TASK_SEAD:_Schedule()
self:F2()