Module Fsm
This module contains the FSM 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.
1) Workflow#FSM class, extends Core.Base#BASE
1.1) Add or remove objects from the FSM
Global(s)
| FSM | |
| FSM_CONTROLLABLE | |
| FSM_PROCESS | |
| FSM_SET | |
| FSM_TASK |
Type FSM
Type FSM_CONTROLLABLE
| FSM_CONTROLLABLE.ClassName | |
| FSM_CONTROLLABLE.Controllable | |
| FSM_CONTROLLABLE:GetControllable() |
Gets the CONTROLLABLE object that the FSM_CONTROLLABLE governs. |
| FSM_CONTROLLABLE:New(FSMT, Controllable) |
Creates a new FSM_CONTROLLABLE object. |
| FSM_CONTROLLABLE:SetControllable(FSMControllable) |
Sets the CONTROLLABLE object that the FSM_CONTROLLABLE governs. |
| FSM_CONTROLLABLE:_call_handler(handler, params) |
Type FSM_PROCESS
| FSM_PROCESS:AddScore(State, ScoreText, Score) |
Adds a score for the FSM_PROCESS to be achieved. |
| FSM_PROCESS:Assign(Task, ProcessUnit) |
Assign the process to a Unit and activate the process. |
| FSM_PROCESS.ClassName | |
| FSM_PROCESS:Copy(Controllable, Task) |
Creates a new FSMPROCESS object based on this FSMPROCESS. |
| FSM_PROCESS:GetCommandCenter() |
Gets the mission of the process. |
| FSM_PROCESS:GetMission() |
Gets the mission of the process. |
| FSM_PROCESS:GetTask() |
Gets the task of the process. |
| FSM_PROCESS:Init(FsmProcess) | |
| FSM_PROCESS:Message(Message) |
Send a message of the Task to the Group of the Unit. |
| FSM_PROCESS:New(Controllable, Task) |
Creates a new FSM_PROCESS object. |
| FSM_PROCESS:SetTask(Task) |
Sets the task of the process. |
| FSM_PROCESS.Task | |
| FSM_PROCESS:onenterAssigned(ProcessUnit) | |
| FSM_PROCESS:onenterFailed(ProcessUnit) | |
| FSM_PROCESS:onenterSuccess(ProcessUnit) | |
| FSM_PROCESS:onstatechange(ProcessUnit, Event, From, To, Dummy) |
StateMachine callback function for a FSM_PROCESS |
Type FSM_SET
| FSM_SET.ClassName | |
| FSM_SET:Get() |
Gets the SETBASE object that the FSMSET governs. |
| FSM_SET:New(FSMT, Set_SET_BASE, FSMSet) |
Creates a new FSM_SET object. |
| FSM_SET.Set | |
| FSM_SET:_call_handler(handler, params) |
Type FSM_TASK
| FSM_TASK.ClassName | |
| FSM_TASK:New(FSMT, Task, TaskUnit) |
Creates a new FSM_TASK object. |
| FSM_TASK.Task | |
| FSM_TASK:_call_handler(handler, params) |
Global(s)
Type Fsm
Type FSM
FSM class
Field(s)
- FSM:AddEndState(State)
-
Parameter
-
State:
-
- FSM:AddProcess(From, Event, Process, ReturnEvents)
-
Set the default Process template with key ProcessName providing the ProcessClass and the process object when it is assigned to a Controllable by the task.
Parameters
-
From: -
Event: -
Process: -
ReturnEvents:
Return value
-
- FSM:AddScore(State, ScoreText, Score)
-
Adds a score for the FSM to be achieved.
Parameters
-
#string State: is the state of the process when the score needs to be given. (See the relevant state descriptions of the process). -
#string ScoreText: is a text describing the score that is given according the status. -
#number Score: is a number providing the score of the status.
Return value
#FSM: self
-
- FSM:AddScoreProcess(From, Event, State, ScoreText, Score)
-
Adds a score for the FSM_PROCESS to be achieved.
Parameters
-
#string From: is the From State of the main process. -
#string Event: is the Event of the main process. -
#string State: is the state of the process when the score needs to be given. (See the relevant state descriptions of the process). -
#string ScoreText: is a text describing the score that is given according the status. -
#number Score: is a number providing the score of the status.
Return value
#FSM: self
-
- FSM:AddTransition(From, Event, To)
-
Parameters
-
From: -
Event: -
To:
-
- #string FSM.ClassName
- FSM:GetProcess(From, Event)
-
Parameters
-
From: -
Event:
-
- FSM:Is(State)
-
Parameter
-
State:
-
- FSM:LoadCallBacks(CallBackTable)
-
Parameter
-
CallBackTable:
-
- FSM:New(FsmT)
-
Creates a new FSM object.
Parameter
-
FsmT:
Return value
#FSM:
-
- FSM:SetStartState(State)
-
Parameter
-
State:
-
- FSM:_add_to_map(Map, Event)
-
Parameters
-
Map: -
Event:
-
- FSM:_call_handler(handler, params)
-
Parameters
-
handler: -
params:
-
- FSM:_create_transition(EventName)
-
Parameter
-
EventName:
-
- FSM:_delayed_transition(EventName)
-
Parameter
-
EventName:
-
- FSM:_eventmap(Events, EventStructure)
-
Parameters
-
Events: -
EventStructure:
-
- FSM:_gosub(ParentFrom, ParentEvent)
-
Parameters
-
ParentFrom: -
ParentEvent:
-
- FSM:_handler(EventName, ...)
-
Parameters
-
EventName: -
...:
-
- FSM:_isendstate(Current)
-
Parameter
-
Current:
-
- FSM:_submap(subs, sub, name)
-
Parameters
-
subs: -
sub: -
name:
-
- FSM:can(e)
-
Parameter
-
e:
-
- FSM:cannot(e)
-
Parameter
-
e:
-
- FSM:is(state)
-
Parameter
-
state:
-
Type FSM_CONTROLLABLE
FSM_CONTROLLABLE class
Field(s)
- #string FSM_CONTROLLABLE.ClassName
- FSM_CONTROLLABLE:GetControllable()
-
Gets the CONTROLLABLE object that the FSM_CONTROLLABLE governs.
Return value
- FSM_CONTROLLABLE:New(FSMT, Controllable)
-
Creates a new FSM_CONTROLLABLE object.
Parameters
-
#table FSMT: Finite State Machine Table -
Wrapper.Controllable#CONTROLLABLE Controllable: (optional) The CONTROLLABLE object that the FSM_CONTROLLABLE governs.
Return value
-
- FSM_CONTROLLABLE:SetControllable(FSMControllable)
-
Sets the CONTROLLABLE object that the FSM_CONTROLLABLE governs.
Parameter
-
Wrapper.Controllable#CONTROLLABLE FSMControllable:
Return value
-
- FSM_CONTROLLABLE:_call_handler(handler, params)
-
Parameters
-
handler: -
params:
-
Type FSM_PROCESS
FSM_PROCESS class
Field(s)
- FSM_PROCESS:AddScore(State, ScoreText, Score)
-
Adds a score for the FSM_PROCESS to be achieved.
Parameters
-
#string State: is the state of the process when the score needs to be given. (See the relevant state descriptions of the process). -
#string ScoreText: is a text describing the score that is given according the status. -
#number Score: is a number providing the score of the status.
Return value
#FSM_PROCESS: self
-
- FSM_PROCESS:Assign(Task, ProcessUnit)
-
Assign the process to a Unit and activate the process.
Parameters
-
Task.Tasking#TASK Task: -
Wrapper.Unit#UNIT ProcessUnit:
Return value
#FSM_PROCESS: self
-
- #string FSM_PROCESS.ClassName
- FSM_PROCESS:Copy(Controllable, Task)
-
Creates a new FSMPROCESS object based on this FSMPROCESS.
Parameters
-
Controllable: -
Task:
Return value
-
- FSM_PROCESS:GetCommandCenter()
-
Gets the mission of the process.
Return value
- FSM_PROCESS:GetMission()
-
Gets the mission of the process.
Return value
- FSM_PROCESS:GetTask()
-
Gets the task of the process.
Return value
- FSM_PROCESS:Init(FsmProcess)
-
Parameter
-
FsmProcess:
-
- FSM_PROCESS:Message(Message)
-
Send a message of the Task to the Group of the Unit.
Parameter
-
Message:
-
- FSM_PROCESS:New(Controllable, Task)
-
Creates a new FSM_PROCESS object.
Parameters
-
Controllable: -
Task:
Return value
-
- FSM_PROCESS:SetTask(Task)
-
Sets the task of the process.
Parameter
-
Tasking.Task#TASK Task:
Return value
-
- FSM_PROCESS:onenterAssigned(ProcessUnit)
-
Parameter
-
ProcessUnit:
-
- FSM_PROCESS:onenterFailed(ProcessUnit)
-
Parameter
-
ProcessUnit:
-
- FSM_PROCESS:onenterSuccess(ProcessUnit)
-
Parameter
-
ProcessUnit:
-
- FSM_PROCESS:onstatechange(ProcessUnit, Event, From, To, Dummy)
-
StateMachine callback function for a FSM_PROCESS
Parameters
-
Wrapper.Controllable#CONTROLLABLE ProcessUnit: -
#string Event: -
#string From: -
#string To: -
Dummy:
-
Type FSM_SET
FSM_SET class
Field(s)
- #string FSM_SET.ClassName
- FSM_SET:Get()
-
Gets the SETBASE object that the FSMSET governs.
Return value
- FSM_SET:New(FSMT, Set_SET_BASE, FSMSet)
-
Creates a new FSM_SET object.
Parameters
-
#table FSMT: Finite State Machine Table -
SetSETBASE: FSMSet (optional) The Set object that the FSM_SET governs. -
FSMSet:
Return value
-
- FSM_SET:_call_handler(handler, params)
-
Parameters
-
handler: -
params:
-
Type FSM_TASK
FSM_TASK class
Field(s)
- #string FSM_TASK.ClassName
- FSM_TASK:New(FSMT, Task, TaskUnit)
-
Creates a new FSM_TASK object.
Parameters
-
#table FSMT: -
Tasking.Task#TASK Task: -
Wrapper.Unit#UNIT TaskUnit:
Return value
-
- FSM_TASK:_call_handler(handler, params)
-
Parameters
-
handler: -
params:
-