mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
OK, SEADING is now working completely
with a target zone, and with routing and seading task active in parallel.
This commit is contained in:
parent
23ea389b8f
commit
d91ba031aa
@ -1,6 +1,7 @@
|
||||
--- The main include file for the MOOSE system.
|
||||
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Utils" )
|
||||
Include.File( "Base" )
|
||||
Include.File( "Object" )
|
||||
Include.File( "Identifiable" )
|
||||
@ -47,8 +48,9 @@ Include.File( "Detection" )
|
||||
Include.File( "FAC" )
|
||||
Include.File( "StateMachine" )
|
||||
Include.File( "Task2" )
|
||||
Include.File( "TaskClientSead" )
|
||||
Include.File( "TaskClientMenu" )
|
||||
Include.File( "TaskSead" )
|
||||
Include.File( "TaskMenu" )
|
||||
Include.File( "TaskRoute" )
|
||||
|
||||
-- The order of the declarations is important here. Don't touch it.
|
||||
|
||||
|
||||
@ -67,11 +67,13 @@ function STATEMACHINE:_submap( subs, sub, name )
|
||||
self:E( { sub = sub, name = name } )
|
||||
subs[sub.onstateparent] = subs[sub.onstateparent] or {}
|
||||
subs[sub.onstateparent][sub.oneventparent] = subs[sub.onstateparent][sub.oneventparent] or {}
|
||||
subs[sub.onstateparent][sub.oneventparent].fsm = sub.fsm
|
||||
subs[sub.onstateparent][sub.oneventparent].event = sub.event
|
||||
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].name = name
|
||||
subs[sub.onstateparent][sub.oneventparent].fsmparent = self
|
||||
local Index = #subs[sub.onstateparent][sub.oneventparent] + 1
|
||||
subs[sub.onstateparent][sub.oneventparent][Index] = {}
|
||||
subs[sub.onstateparent][sub.oneventparent][Index].fsm = sub.fsm
|
||||
subs[sub.onstateparent][sub.oneventparent][Index].event = sub.event
|
||||
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
|
||||
|
||||
|
||||
@ -98,23 +100,28 @@ function STATEMACHINE:_create_transition(name)
|
||||
|
||||
self.current = to
|
||||
|
||||
local fsm, event = self:_gosub( to, name )
|
||||
if fsm and fsm[event] then
|
||||
self:E( "calling sub: " .. event )
|
||||
fsm.fsmparent = self
|
||||
fsm.returnevents = self:_returnevents( to, name )
|
||||
fsm[event]( fsm )
|
||||
else
|
||||
local execute = true
|
||||
|
||||
local subtable = self:_gosub( to, name )
|
||||
for _, sub in pairs( subtable ) do
|
||||
self:E( "calling sub: " .. sub.event )
|
||||
sub.fsm.fsmparent = self
|
||||
sub.fsm.returnevents = sub.returnevents
|
||||
sub.fsm[sub.event]( sub.fsm )
|
||||
execute = false
|
||||
end
|
||||
|
||||
local fsmparent, event = self:_isendstate( to )
|
||||
if fsmparent and event then
|
||||
self:_call_handler(self["onstatechange"], params)
|
||||
fsmparent[event]( fsmparent )
|
||||
else
|
||||
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
|
||||
local fsmparent, event = self:_isendstate( to )
|
||||
if fsmparent and event then
|
||||
self:_call_handler(self["onstatechange"], params)
|
||||
fsmparent[event]( fsmparent )
|
||||
execute = false
|
||||
end
|
||||
|
||||
if execute then
|
||||
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
|
||||
|
||||
return true
|
||||
@ -125,19 +132,11 @@ function STATEMACHINE:_create_transition(name)
|
||||
end
|
||||
|
||||
function STATEMACHINE:_gosub( parentstate, parentevent )
|
||||
local fsmtable = {}
|
||||
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
|
||||
return nil
|
||||
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
|
||||
return {}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ TASK2 = {
|
||||
--- Instantiates a new TASK Base. Should never be used. Interface Class.
|
||||
-- @param #TASK2 self
|
||||
-- @return #TASK2 self
|
||||
function TASK2:New( Client, Mission )
|
||||
function TASK2:New( Mission, Client )
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F()
|
||||
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
--- @module Task_Client_Menu
|
||||
|
||||
--- TASK2_CLIENT_MENU class
|
||||
-- @type TASK2_CLIENT_MENU
|
||||
--- TASK2_MENU_CLIENT class
|
||||
-- @type TASK2_MENU_CLIENT
|
||||
-- @field Client#CLIENT Client
|
||||
-- @field Set#SET_UNIT TargetSet
|
||||
-- @field Menu#MENU_CLIENT_COMMAND MenuSEAD
|
||||
-- @extends Task2#TASK2
|
||||
TASK2_CLIENT_MENU = {
|
||||
ClassName = "TASK2_CLIENT_MENU",
|
||||
TASK2_MENU_CLIENT = {
|
||||
ClassName = "TASK2_MENU_CLIENT",
|
||||
TargetSet = nil,
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new MENU handling machine.
|
||||
-- @param #TASK2_CLIENT_MENU self
|
||||
-- @param Client#CLIENT Client
|
||||
-- @param #TASK2_MENU_CLIENT self
|
||||
-- @param Mission#MISSION Mission
|
||||
-- @param Client#CLIENT Client
|
||||
-- @param #string MenuText The text of the menu item.
|
||||
-- @return #TASK2_CLIENT_MENU self
|
||||
function TASK2_CLIENT_MENU:New( Client, Mission, MenuText )
|
||||
-- @return #TASK2_MENU_CLIENT self
|
||||
function TASK2_MENU_CLIENT:New( Mission, Client, MenuText )
|
||||
|
||||
-- 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
|
||||
|
||||
@ -46,12 +46,12 @@ end
|
||||
--- Task Events
|
||||
|
||||
--- StateMachine callback function for a TASK2
|
||||
-- @param #TASK2_CLIENT_MENU self
|
||||
-- @param #TASK2_MENU_CLIENT self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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.Client:Message( "Press F10 for task menu", 15 )
|
||||
@ -60,8 +60,8 @@ function TASK2_CLIENT_MENU:OnMenu( Fsm, Event, From, To )
|
||||
end
|
||||
|
||||
--- Menu function.
|
||||
-- @param #TASK2_CLIENT_MENU self
|
||||
function TASK2_CLIENT_MENU:MenuAssign()
|
||||
-- @param #TASK2_MENU_CLIENT self
|
||||
function TASK2_MENU_CLIENT:MenuAssign()
|
||||
self:E( )
|
||||
|
||||
self.Client:Message( "Menu Assign", 15 )
|
||||
@ -70,12 +70,12 @@ function TASK2_CLIENT_MENU:MenuAssign()
|
||||
end
|
||||
|
||||
--- StateMachine callback function for a TASK2
|
||||
-- @param #TASK2_CLIENT_MENU self
|
||||
-- @param #TASK2_MENU_CLIENT self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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.Client:Message( "Assign Task", 15 )
|
||||
@ -23,19 +23,19 @@ function TASK2_ROUTE_CLIENT:New( Mission, Client, TargetZone )
|
||||
|
||||
self.TargetZone = TargetZone
|
||||
self.DisplayInterval = 30
|
||||
self.DisplayCount = 1
|
||||
self.DisplayCount = 30
|
||||
self.DisplayMessage = true
|
||||
self.DisplayTime = 10 -- 10 seconds is the default
|
||||
self.DisplayCategory = "Route" -- Route is the default display category
|
||||
|
||||
self.Fsm = STATEMACHINE_TASK:New( self, {
|
||||
initial = 'Unarrived',
|
||||
initial = 'UnArrived',
|
||||
events = {
|
||||
{ name = 'Route', from = 'UnArrived', to = 'Arrived' },
|
||||
{ name = 'Fail', from = 'UnArrived', to = 'Failed' },
|
||||
},
|
||||
callbacks = {
|
||||
onleaveUnarrived = self.OnBeforeRoute,
|
||||
onleaveUnArrived = self.OnLeaveUnArrived,
|
||||
onFail = self.OnFail,
|
||||
},
|
||||
endstates = {
|
||||
@ -54,7 +54,7 @@ end
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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 } )
|
||||
|
||||
local IsInZone = self.Client:IsInZone( self.TargetZone )
|
||||
@ -1,28 +1,28 @@
|
||||
--- @module Task_SEAD
|
||||
|
||||
--- TASK2_SEAD class
|
||||
-- @type TASK2_SEAD
|
||||
--- TASK2_SEAD_CLIENT class
|
||||
-- @type TASK2_SEAD_CLIENT
|
||||
-- @field Client#CLIENT Client
|
||||
-- @field Set#SET_UNIT TargetSet
|
||||
-- @field Menu#MENU_CLIENT_COMMAND MenuSEAD
|
||||
-- @extends Task2#TASK2
|
||||
TASK2_SEAD = {
|
||||
ClassName = "TASK2_SEAD",
|
||||
TASK2_SEAD_CLIENT = {
|
||||
ClassName = "TASK2_SEAD_CLIENT",
|
||||
Fsm = {},
|
||||
TargetSet = nil,
|
||||
}
|
||||
|
||||
|
||||
--- Creates a new SEAD task.
|
||||
-- @param #TASK2_SEAD self
|
||||
-- @param Client#CLIENT Client
|
||||
-- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param Mission#MISSION Mission
|
||||
-- @param Client#CLIENT Client
|
||||
-- @param Set#SET_UNIT TargetSet
|
||||
-- @return #TASK2_SEAD self
|
||||
function TASK2_SEAD:New( Client, Mission, TargetSet )
|
||||
-- @return #TASK2_SEAD_CLIENT self
|
||||
function TASK2_SEAD_CLIENT:New( Mission, Client, TargetSet )
|
||||
|
||||
-- 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
|
||||
|
||||
@ -58,12 +58,12 @@ end
|
||||
--- Task Events
|
||||
|
||||
--- StateMachine callback function for a TASK2
|
||||
-- @param #TASK2_SEAD self
|
||||
-- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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.Client:Message( "Waiting", 15 )
|
||||
@ -71,13 +71,13 @@ function TASK2_SEAD:OnAwait( Fsm, Event, From, To )
|
||||
end
|
||||
|
||||
--- StateMachine callback function for a TASK2
|
||||
-- @param #TASK2_SEAD self
|
||||
-- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @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 )
|
||||
if self.TargetSet:Count() > 0 then
|
||||
@ -88,25 +88,25 @@ function TASK2_SEAD:OnHitTarget( Fsm, Event, From, To, Event )
|
||||
end
|
||||
|
||||
--- StateMachine callback function for a TASK2
|
||||
-- @param #TASK2_SEAD self
|
||||
-- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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 )
|
||||
|
||||
end
|
||||
|
||||
--- StateMachine callback function for a TASK2
|
||||
-- @param #TASK2_SEAD self
|
||||
-- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @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:NextEvent( Fsm.Restart )
|
||||
@ -114,12 +114,12 @@ function TASK2_SEAD:OnKilled( Fsm, Event, From, To )
|
||||
end
|
||||
|
||||
--- StateMachine callback function for a TASK2
|
||||
-- @param #TASK2_SEAD self
|
||||
-- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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:NextEvent( Fsm.Menu )
|
||||
@ -127,12 +127,12 @@ function TASK2_SEAD:OnRestart( Fsm, Event, From, To )
|
||||
end
|
||||
|
||||
--- StateMachine callback function for a TASK2
|
||||
-- @param #TASK2_SEAD self
|
||||
-- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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 )
|
||||
|
||||
@ -140,18 +140,18 @@ end
|
||||
|
||||
--- DCS Events
|
||||
|
||||
--- @param #TASK2_SEAD self
|
||||
--- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function TASK2_SEAD:EventHit( Event )
|
||||
function TASK2_SEAD_CLIENT:EventHit( Event )
|
||||
|
||||
if Event.IniUnit then
|
||||
self:NextEvent( self.Fsm.HitTarget, Event )
|
||||
end
|
||||
end
|
||||
|
||||
--- @param #TASK2_SEAD self
|
||||
--- @param #TASK2_SEAD_CLIENT self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function TASK2_SEAD:EventKilled( Event )
|
||||
function TASK2_SEAD_CLIENT:EventKilled( Event )
|
||||
|
||||
if Event.IniUnit then
|
||||
if Event.IniUnitName == self.Client.ClientName then
|
||||
@ -7,9 +7,11 @@ Mission:AddScoring( Scoring )
|
||||
local Client = CLIENT:FindByName( "Test SEAD" )
|
||||
local TargetSet = SET_UNIT:New():FilterPrefixes( "US Hawk SR" ):FilterStart()
|
||||
|
||||
local Task_Menu = TASK2_CLIENT_MENU:New( Client, Mission, "SEAD" )
|
||||
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 TargetZone = ZONE:New( "Target Zone" )
|
||||
|
||||
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( "Success", "Destroyed all radars!!!", 100 )
|
||||
@ -19,15 +21,14 @@ local Task_Sead = STATEMACHINE:New( {
|
||||
events = {
|
||||
{ name = 'Start', from = 'None', to = 'Unassigned' },
|
||||
{ name = 'Next', from = 'Unassigned', to = 'Assigned' },
|
||||
{ name = 'Next', from = 'Assigned', to = 'Arrived' },
|
||||
{ name = 'Next', from = 'Arrived', to = 'Success' },
|
||||
{ name = 'Next', from = 'Assigned', to = 'Success' },
|
||||
{ name = 'Fail', from = 'Assigned', to = 'Failed' },
|
||||
{ name = 'Fail', from = 'Arrived', to = 'Failed' }
|
||||
},
|
||||
subs = {
|
||||
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' } },
|
||||
Sead = { onstateparent = 'Arrived', oneventparent = 'Next', fsm = Task_Client_Sead.Fsm, event = 'Await', returnevents = { 'Next' } }
|
||||
Route = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = Task_Route.Fsm, event = 'Route' },
|
||||
Sead = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = Task_Client_Sead.Fsm, event = 'Await', returnevents = { 'Next' } }
|
||||
}
|
||||
} )
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user