33 protected bool m_HasCompletions =
false;
68 return path.Count() > 0;
84 m_Transitions.Insert(
t);
86 if (
t.m_event ==
NULL)
88 Print(
"Warning (performance): FSM " +
this +
" has completion transition for src=" +
t.m_srcState +
" ---NULL----|> dst=" +
t.m_dstState);
89 m_HasCompletions =
true;
107 if (m_HasCompletions)
108 ProcessCompletionTransitions();
151 fsmDebugPrint(
"[hfsm] (local abort) state=" +
t.m_srcState.ToString() +
"-------- ABORT event=" +
e.ToString() +
"[G=" +
t.m_guard.ToString() +
"]/A=" +
t.m_action.ToString() +
" --------|> dst=" +
t.m_dstState.ToString());
156 t.m_action.Action(
e);
158 auto tmp =
t.m_srcState.GetParentState();
159 if (
tmp ==
t.m_dstState.GetParentState())
163 if (
t.m_dstState !=
NULL)
171 fsmDebugPrint(
"[hfsm] abort & terminating fsm: state=" +
t.m_srcState.ToString() +
" event=" +
e.ToString());
196 fsmDebugPrint(
"[hfsm] SUB! " + GetOwnerState().
Type().
ToString() +
"::FindAbortDestinationState(" +
e.Type().ToString() +
")");
198 fsmDebugPrint(
"[hfsm] root::FindAbortDestinationState(" +
e.Type().ToString() +
")");
212 int i = FindFirstUnguardedTransition(
e);
240 fsmDebugPrint(
"[hfsm] root::ProcessAbortEvent(" +
e.Type().ToString() +
")");
265 if (GetOwnerState() ==
abort_dst.GetParentState())
296 int i = FindFirstUnguardedTransition(
e);
351 fsmDebugPrint(
"[hfsm] root::ProcessEvent(" +
e.Type().ToString() +
" =" +
e.DumpToString());
355 if (m_HasCompletions)
356 ProcessCompletionTransitions();
382 int i = FindFirstUnguardedTransition(
e);
395 if (
row.m_srcState.GetParentState() ==
row.m_dstState.GetParentState())
396 res = LocalTransition(
i,
e);
398 Error(
"cross-hierarchy transition or misconfigured transition detected!");
404 if (
row.m_srcState.GetParentState() == GetOwnerState())
405 res = LocalTransition(
i,
e);
407 Error(
"cross-hierarchy transition or misconfigured transition detected!");
417 int count = m_Transitions.Count();
421 if ((
t.m_srcState ==
curr_state) && (
t.m_event !=
NULL) && (
t.m_event.Type() ==
e.Type()))
437 int count = m_Transitions.Count();
441 if ((
t.m_srcState ==
curr_state) && (
t.m_event !=
NULL) && (
t.m_event.Type() ==
e.Type()))
451 int count = m_Transitions.Count();
455 if ((
t.m_srcState ==
curr_state) && (
t.m_event !=
NULL) && (
t.m_event.Type() ==
e.Type()))
471 int count = m_Transitions.Count();
498 fsmDebugPrint(
"[hfsm] (local) state=" +
t.m_srcState.ToString() +
"-------- event=" +
e.ToString() +
"[G=" +
t.m_guard.ToString() +
"]/A=" +
t.m_action.ToString() +
" --------|> dst=" +
t.m_dstState.ToString());
503 t.m_action.Action(
e);
507 if (
t.m_dstState !=
NULL)
512 GetOwnerState().OnSubMachineChanged(
t.m_srcState,
t.m_dstState);
515 m_State.OnStateChanged(
t.m_srcState,
t.m_dstState);
522 fsmDebugPrint(
"[hfsm] terminating fsm: state=" +
t.m_srcState.ToString() +
" event=" +
e.ToString());
525 GetOwnerState().OnSubMachineChanged(
t.m_srcState,
NULL);
552 if (
row.m_srcState.GetParentState() ==
row.m_dstState.GetParentState())
555 Error(
"cross-hierarchy transition or misconfigured transition detected!");
561 if (
row.m_srcState.GetParentState() == GetOwnerState())
564 Error(
"cross-hierarchy transition or misconfigured transition detected!");
void fsmDebugSpam(string s)
void fsmDebugPrint(string s)
Super root of all classes in Enforce script.
void AddTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t)
adds transition into transition table
ProcessEventResult ProcessAbortTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
bool GetHierarchyPath(FSMStateBase state, out array< FSMStateBase > path)
returns hierarchic state (path to root) of a state
ref FSMStateBase m_InitialState
state that owns this fsm (or null if root)
void Update(float dt)
if machine running, call OnUpdate() on current state
void HFSMBase(FSMStateBase ownerState=NULL)
FSMStateBase GetOwnerState()
ProcessEventResult ProcessCompletionTransitions()
FSMStateBase FindAbortDestinationState(FSMEventBase e)
i
void Terminate(FSMEventBase terminal_event=NULL)
terminates the state machine
FSMStateBase m_OwnerState
current fsm state
FSMStateBase FindGuardedTransitionState(FSMStateBase s, FSMEventBase e)
FSMStateBase FindTransitionState(FSMStateBase s, FSMEventBase e)
void Abort(FSMEventBase abort_event=NULL)
ProcessEventResult LocalTransition(int i, FSMEventBase e)
void Start(FSMEventBase initial_event=NULL, bool useExistingState=false)
starts the state machine by entering the initial_state (using intial_event as argument to initial sta...
void SetInitialState(FSMStateBase initial_state)
bool IsRunning()
returns true if machine is in running state
int FindFirstCompletionTransition()
FSMStateBase ProcessAbortEvent(FSMEventBase e, out ProcessEventResult result)
instructs the hierarchical state machine to process the event e
int FindFirstUnguardedTransition(FSMEventBase e)
FSMStateBase GetCurrentState()
ProcessEventResult ProcessEvent(FSMEventBase e)
instructs the hierarchical state machine to process the event e
ProcessEventResult ProcessLocalTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
instructs the state machine to process the event locally - no hierarchy is crossed
base class for hierarchic finite state machine
static bool IsWeaponLogEnable()
static bool IsInventoryHFSMLogEnable()
void Error(string err)
Messagebox with error message.
proto void Print(void var)
Prints content of variable to console/log.
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
proto void Insert(int index, string input)
Inserts a string into the n-th index, increasing the string length by the size of the input.