FSM restructuring

This commit is contained in:
FlightControl
2016-12-06 10:30:05 +01:00
parent 0a4630bde6
commit e46d7be91b
11 changed files with 210 additions and 210 deletions

View File

@@ -2,16 +2,16 @@
--
-- ===
--
-- # @{#PROCESS_ASSIGN} FSM class, extends @{Process#PROCESS}
-- # @{#FSMT_ASSIGN} FSM class, extends @{Process#PROCESS}
--
-- ## PROCESS_ASSIGN state machine:
-- ## FSMT_ASSIGN state machine:
--
-- This class is a state machine: it manages a process that is triggered by events causing state transitions to occur.
-- All derived classes from this class will start with the class name, followed by a \_. See the relevant derived class descriptions below.
-- Each derived class follows exactly the same process, using the same events and following the same state transitions,
-- but will have **different implementation behaviour** upon each event or state transition.
--
-- ### PROCESS_ASSIGN **Events**:
-- ### FSMT_ASSIGN **Events**:
--
-- These are the events defined in this class:
--
@@ -19,7 +19,7 @@
-- * **Assign**: Assign the task.
-- * **Reject**: Reject the task..
--
-- ### PROCESS_ASSIGN **Event methods**:
-- ### FSMT_ASSIGN **Event methods**:
--
-- Event methods are available (dynamically allocated by the state machine), that accomodate for state transitions occurring in the process.
-- There are two types of event methods, which you can use to influence the normal mechanisms in the state machine:
@@ -27,7 +27,7 @@
-- * **Immediate**: The event method has exactly the name of the event.
-- * **Delayed**: The event method starts with a __ + the name of the event. The first parameter of the event method is a number value, expressing the delay in seconds when the event will be executed.
--
-- ### PROCESS_ASSIGN **States**:
-- ### FSMT_ASSIGN **States**:
--
-- * **UnAssigned**: The player has not accepted the task.
-- * **Assigned (*)**: The player has accepted the task.
@@ -37,7 +37,7 @@
--
-- (*) End states of the process.
--
-- ### PROCESS_ASSIGN state transition methods:
-- ### FSMT_ASSIGN state transition methods:
--
-- State transition functions can be set **by the mission designer** customizing or improving the behaviour of the state.
-- There are 2 moments when state transition methods will be called by the state machine:
@@ -54,52 +54,52 @@
--
-- ===
--
-- # 1) @{#PROCESS_ASSIGN_ACCEPT} class, extends @{Fsm.Assign#PROCESS_ASSIGN}
-- # 1) @{#FSMT_ASSIGN_ACCEPT} class, extends @{Fsm.Assign#FSMT_ASSIGN}
--
-- The PROCESS_ASSIGN_ACCEPT class accepts by default a task for a player. No player intervention is allowed to reject the task.
-- The FSMT_ASSIGN_ACCEPT class accepts by default a task for a player. No player intervention is allowed to reject the task.
--
-- ## 1.1) PROCESS_ASSIGN_ACCEPT constructor:
-- ## 1.1) FSMT_ASSIGN_ACCEPT constructor:
--
-- * @{#PROCESS_ASSIGN_ACCEPT.New}(): Creates a new PROCESS_ASSIGN_ACCEPT object.
-- * @{#FSMT_ASSIGN_ACCEPT.New}(): Creates a new FSMT_ASSIGN_ACCEPT object.
--
-- ===
--
-- # 2) @{#PROCESS_ASSIGN_MENU_ACCEPT} class, extends @{Fsm.Assign#PROCESS_ASSIGN}
-- # 2) @{#FSMT_ASSIGN_MENU_ACCEPT} class, extends @{Fsm.Assign#FSMT_ASSIGN}
--
-- The PROCESS_ASSIGN_MENU_ACCEPT class accepts a task when the player accepts the task through an added menu option.
-- The FSMT_ASSIGN_MENU_ACCEPT class accepts a task when the player accepts the task through an added menu option.
-- This assignment type is useful to conditionally allow the player to choose whether or not he would accept the task.
-- The assignment type also allows to reject the task.
--
-- ## 2.1) PROCESS_ASSIGN_MENU_ACCEPT constructor:
-- ## 2.1) FSMT_ASSIGN_MENU_ACCEPT constructor:
-- -----------------------------------------
--
-- * @{#PROCESS_ASSIGN_MENU_ACCEPT.New}(): Creates a new PROCESS_ASSIGN_MENU_ACCEPT object.
-- * @{#FSMT_ASSIGN_MENU_ACCEPT.New}(): Creates a new FSMT_ASSIGN_MENU_ACCEPT object.
--
-- ===
--
-- @module Assign
do -- PROCESS_ASSIGN
do -- FSMT_ASSIGN
--- PROCESS_ASSIGN class
-- @type PROCESS_ASSIGN
--- FSMT_ASSIGN class
-- @type FSMT_ASSIGN
-- @field Tasking.Task#TASK_BASE Task
-- @field Wrapper.Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Core.StateMachine#FSM_TEMPLATE
PROCESS_ASSIGN = {
ClassName = "PROCESS_ASSIGN",
FSMT_ASSIGN = {
ClassName = "FSMT_ASSIGN",
}
--- Creates a new task assignment state machine. The process will accept the task by default, no player intervention accepted.
-- @param #PROCESS_ASSIGN self
-- @return #PROCESS_ASSIGN The task acceptance process.
function PROCESS_ASSIGN:New()
-- @param #FSMT_ASSIGN self
-- @return #FSMT_ASSIGN The task acceptance process.
function FSMT_ASSIGN:New()
-- Inherits from BASE
local self = BASE:Inherit( self, FSM_TEMPLATE:New( "PROCESS_ASSIGN" ) ) -- Core.StateMachine#FSM_TEMPLATE
local self = BASE:Inherit( self, FSM_TEMPLATE:New( "FSMT_ASSIGN" ) ) -- Core.StateMachine#FSM_TEMPLATE
self:AddTransition( "UnAssigned", "Start", "Waiting" )
self:AddTransition( "Waiting", "Assign", "Assigned" )
@@ -115,29 +115,29 @@ do -- PROCESS_ASSIGN
return self
end
end -- PROCESS_ASSIGN
end -- FSMT_ASSIGN
do -- PROCESS_ASSIGN_ACCEPT
do -- FSMT_ASSIGN_ACCEPT
--- PROCESS_ASSIGN_ACCEPT class
-- @type PROCESS_ASSIGN_ACCEPT
--- FSMT_ASSIGN_ACCEPT class
-- @type FSMT_ASSIGN_ACCEPT
-- @field Tasking.Task#TASK_BASE Task
-- @field Wrapper.Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Fsm.Process#PROCESS
PROCESS_ASSIGN_ACCEPT = {
ClassName = "PROCESS_ASSIGN_ACCEPT",
FSMT_ASSIGN_ACCEPT = {
ClassName = "FSMT_ASSIGN_ACCEPT",
}
--- Creates a new task assignment state machine. The process will accept the task by default, no player intervention accepted.
-- @param #PROCESS_ASSIGN_ACCEPT self
-- @param #FSMT_ASSIGN_ACCEPT self
-- @param #string TaskBriefing
function PROCESS_ASSIGN_ACCEPT:New( TaskBriefing )
function FSMT_ASSIGN_ACCEPT:New( TaskBriefing )
local self = BASE:Inherit( self, PROCESS_ASSIGN:New() ) -- #PROCESS_ASSIGN_ACCEPT
local self = BASE:Inherit( self, FSMT_ASSIGN:New() ) -- #FSMT_ASSIGN_ACCEPT
self:SetParameters( { TaskBriefing = TaskBriefing } )
@@ -145,12 +145,12 @@ do -- PROCESS_ASSIGN_ACCEPT
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_ACCEPT self
-- @param #FSMT_ASSIGN_ACCEPT self
-- @param Wrapper.Unit#UNIT ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_ACCEPT:onafterStart( ProcessUnit, Event, From, To )
function FSMT_ASSIGN_ACCEPT:onafterStart( ProcessUnit, Event, From, To )
self:E( { ProcessUnit, Event, From, To } )
local ProcessGroup = ProcessUnit:GetGroup()
@@ -160,12 +160,12 @@ do -- PROCESS_ASSIGN_ACCEPT
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_ACCEPT self
-- @param #FSMT_ASSIGN_ACCEPT self
-- @param Wrapper.Unit#UNIT ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_ACCEPT:onenterAssigned( ProcessUnit, Event, From, To )
function FSMT_ASSIGN_ACCEPT:onenterAssigned( ProcessUnit, Event, From, To )
env.info( "in here" )
self:E( { ProcessUnit, Event, From, To } )
@@ -176,30 +176,30 @@ do -- PROCESS_ASSIGN_ACCEPT
self.Task:Assign()
end
end -- PROCESS_ASSIGN_ACCEPT
end -- FSMT_ASSIGN_ACCEPT
do -- PROCESS_ASSIGN_MENU_ACCEPT
do -- FSMT_ASSIGN_MENU_ACCEPT
--- PROCESS_ASSIGN_MENU_ACCEPT class
-- @type PROCESS_ASSIGN_MENU_ACCEPT
--- FSMT_ASSIGN_MENU_ACCEPT class
-- @type FSMT_ASSIGN_MENU_ACCEPT
-- @field Tasking.Task#TASK_BASE Task
-- @field Wrapper.Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends #PROCESS_ASSIGN
PROCESS_ASSIGN_MENU_ACCEPT = {
ClassName = "PROCESS_ASSIGN_MENU_ACCEPT",
-- @extends #FSMT_ASSIGN
FSMT_ASSIGN_MENU_ACCEPT = {
ClassName = "FSMT_ASSIGN_MENU_ACCEPT",
}
--- Init.
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param #FSMT_ASSIGN_MENU_ACCEPT self
-- @param #string TaskName
-- @param #string TaskBriefing
-- @return #PROCESS_ASSIGN_MENU_ACCEPT self
function PROCESS_ASSIGN_MENU_ACCEPT:New( TaskName, TaskBriefing )
-- @return #FSMT_ASSIGN_MENU_ACCEPT self
function FSMT_ASSIGN_MENU_ACCEPT:New( TaskName, TaskBriefing )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS_ASSIGN:New() ) -- #PROCESS_ASSIGN_MENU_ACCEPT
local self = BASE:Inherit( self, FSMT_ASSIGN:New() ) -- #FSMT_ASSIGN_MENU_ACCEPT
self:SetParameters( { TaskName = TaskName, TaskBriefing = TaskBriefing } )
@@ -208,11 +208,11 @@ do -- PROCESS_ASSIGN_MENU_ACCEPT
--- Creates a new task assignment state machine. The process will request from the menu if it accepts the task, if not, the unit is removed from the simulator.
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param #FSMT_ASSIGN_MENU_ACCEPT self
-- @param #string TaskName
-- @param #string TaskBriefing
-- @return #PROCESS_ASSIGN_MENU_ACCEPT self
function PROCESS_ASSIGN_MENU_ACCEPT:Init( TaskName, TaskBriefing )
-- @return #FSMT_ASSIGN_MENU_ACCEPT self
function FSMT_ASSIGN_MENU_ACCEPT:Init( TaskName, TaskBriefing )
self.TaskBriefing = TaskBriefing
self.TaskName = TaskName
@@ -221,12 +221,12 @@ do -- PROCESS_ASSIGN_MENU_ACCEPT
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param #FSMT_ASSIGN_MENU_ACCEPT self
-- @param Wrapper.Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_MENU_ACCEPT:onafterStart( ProcessUnit, Event, From, To )
function FSMT_ASSIGN_MENU_ACCEPT:onafterStart( ProcessUnit, Event, From, To )
self:E( { ProcessUnit, Event, From, To } )
MESSAGE:New( self.TaskBriefing .. "\nAccess the radio menu to accept the task. You have 30 seconds or the assignment will be cancelled.", 30, "Task Assignment" ):ToGroup( ProcessUnit:GetGroup() )
@@ -239,40 +239,40 @@ do -- PROCESS_ASSIGN_MENU_ACCEPT
end
--- Menu function.
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
function PROCESS_ASSIGN_MENU_ACCEPT:MenuAssign()
-- @param #FSMT_ASSIGN_MENU_ACCEPT self
function FSMT_ASSIGN_MENU_ACCEPT:MenuAssign()
self:E( )
self:__Assign( 1 )
end
--- Menu function.
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
function PROCESS_ASSIGN_MENU_ACCEPT:MenuReject()
-- @param #FSMT_ASSIGN_MENU_ACCEPT self
function FSMT_ASSIGN_MENU_ACCEPT:MenuReject()
self:E( )
self:__Reject( 1 )
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param #FSMT_ASSIGN_MENU_ACCEPT self
-- @param Wrapper.Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_MENU_ACCEPT:onafterAssign( ProcessUnit, Event, From, To )
function FSMT_ASSIGN_MENU_ACCEPT:onafterAssign( ProcessUnit, Event, From, To )
self:E( { ProcessUnit.UnitNameEvent, From, To } )
self.Menu:Remove()
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param #FSMT_ASSIGN_MENU_ACCEPT self
-- @param Wrapper.Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_MENU_ACCEPT:onafterReject( ProcessUnit, Event, From, To )
function FSMT_ASSIGN_MENU_ACCEPT:onafterReject( ProcessUnit, Event, From, To )
self:E( { ProcessUnit.UnitName, Event, From, To } )
self.Menu:Remove()
@@ -281,4 +281,4 @@ do -- PROCESS_ASSIGN_MENU_ACCEPT
ProcessUnit:Destroy()
end
end -- PROCESS_ASSIGN_MENU_ACCEPT
end -- FSMT_ASSIGN_MENU_ACCEPT