OK, SEADING is now working completely

with a target zone, and with routing and seading task active in
parallel.
This commit is contained in:
FlightControl 2016-07-03 09:31:02 +02:00
parent 23ea389b8f
commit d91ba031aa
9 changed files with 88 additions and 86 deletions

View File

@ -1,6 +1,7 @@
--- The main include file for the MOOSE system. --- The main include file for the MOOSE system.
Include.File( "Routines" ) Include.File( "Routines" )
Include.File( "Utils" )
Include.File( "Base" ) Include.File( "Base" )
Include.File( "Object" ) Include.File( "Object" )
Include.File( "Identifiable" ) Include.File( "Identifiable" )
@ -47,8 +48,9 @@ Include.File( "Detection" )
Include.File( "FAC" ) Include.File( "FAC" )
Include.File( "StateMachine" ) Include.File( "StateMachine" )
Include.File( "Task2" ) Include.File( "Task2" )
Include.File( "TaskClientSead" ) Include.File( "TaskSead" )
Include.File( "TaskClientMenu" ) Include.File( "TaskMenu" )
Include.File( "TaskRoute" )
-- The order of the declarations is important here. Don't touch it. -- The order of the declarations is important here. Don't touch it.

View File

@ -67,11 +67,13 @@ function STATEMACHINE:_submap( subs, sub, name )
self:E( { sub = sub, name = name } ) self:E( { sub = sub, name = name } )
subs[sub.onstateparent] = subs[sub.onstateparent] or {} subs[sub.onstateparent] = subs[sub.onstateparent] or {}
subs[sub.onstateparent][sub.oneventparent] = subs[sub.onstateparent][sub.oneventparent] or {} subs[sub.onstateparent][sub.oneventparent] = subs[sub.onstateparent][sub.oneventparent] or {}
subs[sub.onstateparent][sub.oneventparent].fsm = sub.fsm local Index = #subs[sub.onstateparent][sub.oneventparent] + 1
subs[sub.onstateparent][sub.oneventparent].event = sub.event subs[sub.onstateparent][sub.oneventparent][Index] = {}
subs[sub.onstateparent][sub.oneventparent].returnevents = sub.returnevents -- these events need to be given to find the correct continue event ... if none given, the processing will stop. subs[sub.onstateparent][sub.oneventparent][Index].fsm = sub.fsm
subs[sub.onstateparent][sub.oneventparent].name = name subs[sub.onstateparent][sub.oneventparent][Index].event = sub.event
subs[sub.onstateparent][sub.oneventparent].fsmparent = self subs[sub.onstateparent][sub.oneventparent][Index].returnevents = sub.returnevents -- these events need to be given to find the correct continue event ... if none given, the processing will stop.
subs[sub.onstateparent][sub.oneventparent][Index].name = name
subs[sub.onstateparent][sub.oneventparent][Index].fsmparent = self
end end
@ -98,23 +100,28 @@ function STATEMACHINE:_create_transition(name)
self.current = to self.current = to
local fsm, event = self:_gosub( to, name ) local execute = true
if fsm and fsm[event] then
self:E( "calling sub: " .. event ) local subtable = self:_gosub( to, name )
fsm.fsmparent = self for _, sub in pairs( subtable ) do
fsm.returnevents = self:_returnevents( to, name ) self:E( "calling sub: " .. sub.event )
fsm[event]( fsm ) sub.fsm.fsmparent = self
else sub.fsm.returnevents = sub.returnevents
sub.fsm[sub.event]( sub.fsm )
execute = false
end
local fsmparent, event = self:_isendstate( to ) local fsmparent, event = self:_isendstate( to )
if fsmparent and event then if fsmparent and event then
self:_call_handler(self["onstatechange"], params) self:_call_handler(self["onstatechange"], params)
fsmparent[event]( fsmparent ) fsmparent[event]( fsmparent )
else execute = false
self:_call_handler(self["onenter" .. to] or self["on" .. to], params) end
self:_call_handler(self["onafter" .. name] or self["on" .. name], params)
self:_call_handler(self["onstatechange"], params) if execute then
end self:_call_handler(self["onenter" .. to] or self["on" .. to], params)
self:_call_handler(self["onafter" .. name] or self["on" .. name], params)
self:_call_handler(self["onstatechange"], params)
end end
return true return true
@ -125,19 +132,11 @@ function STATEMACHINE:_create_transition(name)
end end
function STATEMACHINE:_gosub( parentstate, parentevent ) function STATEMACHINE:_gosub( parentstate, parentevent )
local fsmtable = {}
if self.subs[parentstate] and self.subs[parentstate][parentevent] then if self.subs[parentstate] and self.subs[parentstate][parentevent] then
return self.subs[parentstate][parentevent].fsm, self.subs[parentstate][parentevent].event return self.subs[parentstate][parentevent]
else else
return nil return {}
end
end
function STATEMACHINE:_returnevents( parentstate, parentevent )
if self.subs[parentstate] and self.subs[parentstate][parentevent] then
self:E(self.subs[parentstate][parentevent].returnevents)
return self.subs[parentstate][parentevent].returnevents
else
return nil
end end
end end

View File

@ -17,7 +17,7 @@ TASK2 = {
--- Instantiates a new TASK Base. Should never be used. Interface Class. --- Instantiates a new TASK Base. Should never be used. Interface Class.
-- @param #TASK2 self -- @param #TASK2 self
-- @return #TASK2 self -- @return #TASK2 self
function TASK2:New( Client, Mission ) function TASK2:New( Mission, Client )
local self = BASE:Inherit( self, BASE:New() ) local self = BASE:Inherit( self, BASE:New() )
self:F() self:F()

View File

@ -1,27 +1,27 @@
--- @module Task_Client_Menu --- @module Task_Client_Menu
--- TASK2_CLIENT_MENU class --- TASK2_MENU_CLIENT class
-- @type TASK2_CLIENT_MENU -- @type TASK2_MENU_CLIENT
-- @field Client#CLIENT Client -- @field Client#CLIENT Client
-- @field Set#SET_UNIT TargetSet -- @field Set#SET_UNIT TargetSet
-- @field Menu#MENU_CLIENT_COMMAND MenuSEAD -- @field Menu#MENU_CLIENT_COMMAND MenuSEAD
-- @extends Task2#TASK2 -- @extends Task2#TASK2
TASK2_CLIENT_MENU = { TASK2_MENU_CLIENT = {
ClassName = "TASK2_CLIENT_MENU", ClassName = "TASK2_MENU_CLIENT",
TargetSet = nil, TargetSet = nil,
} }
--- Creates a new MENU handling machine. --- Creates a new MENU handling machine.
-- @param #TASK2_CLIENT_MENU self -- @param #TASK2_MENU_CLIENT self
-- @param Client#CLIENT Client
-- @param Mission#MISSION Mission -- @param Mission#MISSION Mission
-- @param Client#CLIENT Client
-- @param #string MenuText The text of the menu item. -- @param #string MenuText The text of the menu item.
-- @return #TASK2_CLIENT_MENU self -- @return #TASK2_MENU_CLIENT self
function TASK2_CLIENT_MENU:New( Client, Mission, MenuText ) function TASK2_MENU_CLIENT:New( Mission, Client, MenuText )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, TASK2:New( Client, Mission ) ) -- #TASK2_CLIENT_MENU local self = BASE:Inherit( self, TASK2:New( Mission, Client ) ) -- #TASK2_MENU_CLIENT
self.MenuText = MenuText self.MenuText = MenuText
@ -46,12 +46,12 @@ end
--- Task Events --- Task Events
--- StateMachine callback function for a TASK2 --- StateMachine callback function for a TASK2
-- @param #TASK2_CLIENT_MENU self -- @param #TASK2_MENU_CLIENT self
-- @param StateMachine#STATEMACHINE_TASK Fsm -- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
function TASK2_CLIENT_MENU:OnMenu( Fsm, Event, From, To ) function TASK2_MENU_CLIENT:OnMenu( Fsm, Event, From, To )
self:E( { Event, From, To, self.Client.ClientName} ) self:E( { Event, From, To, self.Client.ClientName} )
self.Client:Message( "Press F10 for task menu", 15 ) self.Client:Message( "Press F10 for task menu", 15 )
@ -60,8 +60,8 @@ function TASK2_CLIENT_MENU:OnMenu( Fsm, Event, From, To )
end end
--- Menu function. --- Menu function.
-- @param #TASK2_CLIENT_MENU self -- @param #TASK2_MENU_CLIENT self
function TASK2_CLIENT_MENU:MenuAssign() function TASK2_MENU_CLIENT:MenuAssign()
self:E( ) self:E( )
self.Client:Message( "Menu Assign", 15 ) self.Client:Message( "Menu Assign", 15 )
@ -70,12 +70,12 @@ function TASK2_CLIENT_MENU:MenuAssign()
end end
--- StateMachine callback function for a TASK2 --- StateMachine callback function for a TASK2
-- @param #TASK2_CLIENT_MENU self -- @param #TASK2_MENU_CLIENT self
-- @param StateMachine#STATEMACHINE_TASK Fsm -- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
function TASK2_CLIENT_MENU:OnAssign( Fsm, Event, From, To ) function TASK2_MENU_CLIENT:OnAssign( Fsm, Event, From, To )
self:E( { Event, From, To, self.Client.ClientName} ) self:E( { Event, From, To, self.Client.ClientName} )
self.Client:Message( "Assign Task", 15 ) self.Client:Message( "Assign Task", 15 )

View File

@ -23,19 +23,19 @@ function TASK2_ROUTE_CLIENT:New( Mission, Client, TargetZone )
self.TargetZone = TargetZone self.TargetZone = TargetZone
self.DisplayInterval = 30 self.DisplayInterval = 30
self.DisplayCount = 1 self.DisplayCount = 30
self.DisplayMessage = true self.DisplayMessage = true
self.DisplayTime = 10 -- 10 seconds is the default self.DisplayTime = 10 -- 10 seconds is the default
self.DisplayCategory = "Route" -- Route is the default display category self.DisplayCategory = "Route" -- Route is the default display category
self.Fsm = STATEMACHINE_TASK:New( self, { self.Fsm = STATEMACHINE_TASK:New( self, {
initial = 'Unarrived', initial = 'UnArrived',
events = { events = {
{ name = 'Route', from = 'UnArrived', to = 'Arrived' }, { name = 'Route', from = 'UnArrived', to = 'Arrived' },
{ name = 'Fail', from = 'UnArrived', to = 'Failed' }, { name = 'Fail', from = 'UnArrived', to = 'Failed' },
}, },
callbacks = { callbacks = {
onleaveUnarrived = self.OnBeforeRoute, onleaveUnArrived = self.OnLeaveUnArrived,
onFail = self.OnFail, onFail = self.OnFail,
}, },
endstates = { endstates = {
@ -54,7 +54,7 @@ end
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
function TASK2_ROUTE_CLIENT:OnBeforeRoute( Fsm, Event, From, To ) function TASK2_ROUTE_CLIENT:OnLeaveUnArrived( Fsm, Event, From, To )
self:E( { Event, From, To, self.Client.ClientName } ) self:E( { Event, From, To, self.Client.ClientName } )
local IsInZone = self.Client:IsInZone( self.TargetZone ) local IsInZone = self.Client:IsInZone( self.TargetZone )

View File

@ -1,28 +1,28 @@
--- @module Task_SEAD --- @module Task_SEAD
--- TASK2_SEAD class --- TASK2_SEAD_CLIENT class
-- @type TASK2_SEAD -- @type TASK2_SEAD_CLIENT
-- @field Client#CLIENT Client -- @field Client#CLIENT Client
-- @field Set#SET_UNIT TargetSet -- @field Set#SET_UNIT TargetSet
-- @field Menu#MENU_CLIENT_COMMAND MenuSEAD -- @field Menu#MENU_CLIENT_COMMAND MenuSEAD
-- @extends Task2#TASK2 -- @extends Task2#TASK2
TASK2_SEAD = { TASK2_SEAD_CLIENT = {
ClassName = "TASK2_SEAD", ClassName = "TASK2_SEAD_CLIENT",
Fsm = {}, Fsm = {},
TargetSet = nil, TargetSet = nil,
} }
--- Creates a new SEAD task. --- Creates a new SEAD task.
-- @param #TASK2_SEAD self -- @param #TASK2_SEAD_CLIENT self
-- @param Client#CLIENT Client
-- @param Mission#MISSION Mission -- @param Mission#MISSION Mission
-- @param Client#CLIENT Client
-- @param Set#SET_UNIT TargetSet -- @param Set#SET_UNIT TargetSet
-- @return #TASK2_SEAD self -- @return #TASK2_SEAD_CLIENT self
function TASK2_SEAD:New( Client, Mission, TargetSet ) function TASK2_SEAD_CLIENT:New( Mission, Client, TargetSet )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, TASK2:New( Client, Mission ) ) -- #TASK2_SEAD local self = BASE:Inherit( self, TASK2:New( Mission, Client ) ) -- #TASK2_SEAD_CLIENT
self.TargetSet = TargetSet self.TargetSet = TargetSet
@ -58,12 +58,12 @@ end
--- Task Events --- Task Events
--- StateMachine callback function for a TASK2 --- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self -- @param #TASK2_SEAD_CLIENT self
-- @param StateMachine#STATEMACHINE_TASK Fsm -- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
function TASK2_SEAD:OnAwait( Fsm, Event, From, To ) function TASK2_SEAD_CLIENT:OnAwait( Fsm, Event, From, To )
self:E( { Event, From, To, self.Client.ClientName} ) self:E( { Event, From, To, self.Client.ClientName} )
self.Client:Message( "Waiting", 15 ) self.Client:Message( "Waiting", 15 )
@ -71,13 +71,13 @@ function TASK2_SEAD:OnAwait( Fsm, Event, From, To )
end end
--- StateMachine callback function for a TASK2 --- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self -- @param #TASK2_SEAD_CLIENT self
-- @param StateMachine#STATEMACHINE_TASK Fsm -- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function TASK2_SEAD:OnHitTarget( Fsm, Event, From, To, Event ) function TASK2_SEAD_CLIENT:OnHitTarget( Fsm, Event, From, To, Event )
self.Client:Message( "Hit Target", 15 ) self.Client:Message( "Hit Target", 15 )
if self.TargetSet:Count() > 0 then if self.TargetSet:Count() > 0 then
@ -88,25 +88,25 @@ function TASK2_SEAD:OnHitTarget( Fsm, Event, From, To, Event )
end end
--- StateMachine callback function for a TASK2 --- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self -- @param #TASK2_SEAD_CLIENT self
-- @param StateMachine#STATEMACHINE_TASK Fsm -- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
function TASK2_SEAD:OnMoreTargets( Fsm, Event, From, To ) function TASK2_SEAD_CLIENT:OnMoreTargets( Fsm, Event, From, To )
self.Client:Message( "More Targets", 15 ) self.Client:Message( "More Targets", 15 )
end end
--- StateMachine callback function for a TASK2 --- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self -- @param #TASK2_SEAD_CLIENT self
-- @param StateMachine#STATEMACHINE_TASK Fsm -- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
-- @param Event#EVENTDATA DCSEvent -- @param Event#EVENTDATA DCSEvent
function TASK2_SEAD:OnKilled( Fsm, Event, From, To ) function TASK2_SEAD_CLIENT:OnKilled( Fsm, Event, From, To )
self.Client:Message( "Player got killed", 15 ) self.Client:Message( "Player got killed", 15 )
self:NextEvent( Fsm.Restart ) self:NextEvent( Fsm.Restart )
@ -114,12 +114,12 @@ function TASK2_SEAD:OnKilled( Fsm, Event, From, To )
end end
--- StateMachine callback function for a TASK2 --- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self -- @param #TASK2_SEAD_CLIENT self
-- @param StateMachine#STATEMACHINE_TASK Fsm -- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
function TASK2_SEAD:OnRestart( Fsm, Event, From, To ) function TASK2_SEAD_CLIENT:OnRestart( Fsm, Event, From, To )
self.Client:Message( "Restart SEAD Task", 15 ) self.Client:Message( "Restart SEAD Task", 15 )
self:NextEvent( Fsm.Menu ) self:NextEvent( Fsm.Menu )
@ -127,12 +127,12 @@ function TASK2_SEAD:OnRestart( Fsm, Event, From, To )
end end
--- StateMachine callback function for a TASK2 --- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self -- @param #TASK2_SEAD_CLIENT self
-- @param StateMachine#STATEMACHINE_TASK Fsm -- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event -- @param #string Event
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
function TASK2_SEAD:OnDestroyed( Fsm, Event, From, To ) function TASK2_SEAD_CLIENT:OnDestroyed( Fsm, Event, From, To )
self.Client:Message( "Destroyed", 15 ) self.Client:Message( "Destroyed", 15 )
@ -140,18 +140,18 @@ end
--- DCS Events --- DCS Events
--- @param #TASK2_SEAD self --- @param #TASK2_SEAD_CLIENT self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function TASK2_SEAD:EventHit( Event ) function TASK2_SEAD_CLIENT:EventHit( Event )
if Event.IniUnit then if Event.IniUnit then
self:NextEvent( self.Fsm.HitTarget, Event ) self:NextEvent( self.Fsm.HitTarget, Event )
end end
end end
--- @param #TASK2_SEAD self --- @param #TASK2_SEAD_CLIENT self
-- @param Event#EVENTDATA Event -- @param Event#EVENTDATA Event
function TASK2_SEAD:EventKilled( Event ) function TASK2_SEAD_CLIENT:EventKilled( Event )
if Event.IniUnit then if Event.IniUnit then
if Event.IniUnitName == self.Client.ClientName then if Event.IniUnitName == self.Client.ClientName then

View File

@ -7,9 +7,11 @@ Mission:AddScoring( Scoring )
local Client = CLIENT:FindByName( "Test SEAD" ) local Client = CLIENT:FindByName( "Test SEAD" )
local TargetSet = SET_UNIT:New():FilterPrefixes( "US Hawk SR" ):FilterStart() local TargetSet = SET_UNIT:New():FilterPrefixes( "US Hawk SR" ):FilterStart()
local Task_Menu = TASK2_CLIENT_MENU:New( Client, Mission, "SEAD" ) local TargetZone = ZONE:New( "Target Zone" )
local Task_Route = TASK2_ROUTE:New( Client, Mission ) -- The target location is dynamically defined in state machine
local Task_Client_Sead = TASK2_SEAD:New( Client, Mission, TargetSet ) local Task_Menu = TASK2_MENU_CLIENT:New( Mission, Client, "SEAD" )
local Task_Route = TASK2_ROUTE_CLIENT:New( Mission, Client, TargetZone ) -- The target location is dynamically defined in state machine
local Task_Client_Sead = TASK2_SEAD_CLIENT:New( Mission, Client, TargetSet )
Task_Client_Sead:AddScore( "Destroy", "Destroyed RADAR", 25 ) Task_Client_Sead:AddScore( "Destroy", "Destroyed RADAR", 25 )
Task_Client_Sead:AddScore( "Success", "Destroyed all radars!!!", 100 ) Task_Client_Sead:AddScore( "Success", "Destroyed all radars!!!", 100 )
@ -19,15 +21,14 @@ local Task_Sead = STATEMACHINE:New( {
events = { events = {
{ name = 'Start', from = 'None', to = 'Unassigned' }, { name = 'Start', from = 'None', to = 'Unassigned' },
{ name = 'Next', from = 'Unassigned', to = 'Assigned' }, { name = 'Next', from = 'Unassigned', to = 'Assigned' },
{ name = 'Next', from = 'Assigned', to = 'Arrived' }, { name = 'Next', from = 'Assigned', to = 'Success' },
{ name = 'Next', from = 'Arrived', to = 'Success' },
{ name = 'Fail', from = 'Assigned', to = 'Failed' }, { name = 'Fail', from = 'Assigned', to = 'Failed' },
{ name = 'Fail', from = 'Arrived', to = 'Failed' } { name = 'Fail', from = 'Arrived', to = 'Failed' }
}, },
subs = { subs = {
Menu = { onstateparent = 'Unassigned', oneventparent = 'Start', fsm = Task_Menu.Fsm, event = 'Menu', returnevents = { 'Next' } }, Menu = { onstateparent = 'Unassigned', oneventparent = 'Start', fsm = Task_Menu.Fsm, event = 'Menu', returnevents = { 'Next' } },
Route = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = Task_Route.Fsm, event = 'Route', returnevents = { 'Next' } }, Route = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = Task_Route.Fsm, event = 'Route' },
Sead = { onstateparent = 'Arrived', oneventparent = 'Next', fsm = Task_Client_Sead.Fsm, event = 'Await', returnevents = { 'Next' } } Sead = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = Task_Client_Sead.Fsm, event = 'Await', returnevents = { 'Next' } }
} }
} ) } )