4class WeaponFSM extends HFSMBase<WeaponStateBase, WeaponEventBase, WeaponActionBase, WeaponGuardBase>
33 super.AddTransition(t);
41 if (
LogManager.
IsInventoryHFSMLogEnable())
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());
48 if (t.m_dstState != NULL)
53 GetOwnerState().OnSubMachineChanged(t.m_srcState, t.m_dstState);
56 m_State.OnStateChanged(t.m_srcState, t.m_dstState);
66 GetOwnerState().OnSubMachineChanged(t.m_srcState, NULL);
74 if (
LogManager.
IsInventoryHFSMLogEnable())
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());
79 auto tmp = t.m_srcState.GetParentState();
80 if (tmp == t.m_dstState.GetParentState())
84 if (t.m_dstState != NULL)
112 fsmDebugPrint(
"[hfsm] root::ProcessAbortEvent(" + e.Type().ToString() +
")");
171 int i = FindFirstUnguardedTransition(e);
183 i = FindFirstUnguardedTransition(e);
237 if (m_HasCompletions)
238 ProcessCompletionTransitions();
264 int i = FindFirstUnguardedTransition(e);
275 i = FindFirstUnguardedTransition(e);
285 if (row.m_dstState != NULL)
288 if (row.m_srcState.GetParentState() == row.m_dstState.GetParentState())
289 res = LocalTransition(i, e);
291 Error(
"cross-hierarchy transition or misconfigured transition detected!");
297 if (row.m_srcState.GetParentState() == GetOwnerState())
298 res = LocalTransition(i, e);
300 Error(
"cross-hierarchy transition or misconfigured transition detected!");
313 for (
int idx = 0; idx < state_count; ++idx)
331 int count = m_Transitions.Count();
332 for (
int i = 0; i < count; ++i)
344 int curr_state_id = -1;
345 if (!ctx.
Read(curr_state_id))
347 Error(
"[wpnfsm] LoadCurrentFSMState - cannot read current state");
361 Error(
"[wpnfsm] LoadCurrentFSMState - cannot find state for id=" + curr_state_id);
373 bool res =
m_State.LoadCurrentFSMState(ctx, version);
386 for (
int idx = 0; idx < state_count; ++idx)
390 Error(
"[wpnfsm] LoadCurrentUnstableFSMState - cannot load unique state " + idx +
"/" + state_count +
" with id=" +
m_UniqueStates.Get(idx).GetInternalStateID() +
" state=" +
m_UniqueStates.Get(idx));
406 if (!ctx.
Write(curr_state_id))
408 Error(
"[wpnfsm] SaveCurrentFSMState - cannot save curr_state_id=" + curr_state_id);
415 Error(
"[wpnfsm] SaveCurrentFSMState - cannot save currrent state=" +state);
427 if (!ctx.
Write(curr_state_id))
429 Error(
"[wpnfsm] SaveCurrentFSMState - cannot save curr_state_id=" + curr_state_id);
435 for (
int idx = 0; idx < state_count; ++idx)
442 Error(
"SaveCurrentUnstableFSMState - cannot save unique state=" +
m_UniqueStates.Get(idx) +
" idx=" + idx +
"/" + state_count +
" with id=" + state_id);
445 Error(
"[wpnfsm] SaveCurrentUnstableFSMState state=" +
m_UniqueStates.Get(idx) +
" with unassigned ID!");
464 bool repaired =
false;
475 state.
HasMagazine(), ( weapon.GetMagazine(0) != null ),
476 new WeaponEventAttachMagazine,
new WeaponEventDetachMagazine,
481 state.
IsJammed(), weapon.IsJammed(),
482 new WeaponEventTriggerToJam,
new WeaponEventUnjam,
485 if (weapon.IsJammed())
488 int nMuzzles = weapon.GetMuzzleCount();
494 "ChamberFiredRepair",
495 state.IsChamberFiredOut(0), weapon.IsChamberFiredOut(0),
496 new WeaponEventTrigger,
new WeaponEventMechanism,
501 state.IsChamberFull(0), weapon.IsChamberFullEx(0),
502 new WeaponEventLoad1Bullet,
new WeaponEventMechanism,
509 for (
int i = 0; i < nMuzzles; ++i)
512 "ChamberFiredRepair",
513 state.IsChamberFiredOut(i), weapon.IsChamberFiredOut(i),
519 state.IsChamberFull(i), weapon.IsChamberFull(i),
537 if (stateCondition != gunCondition)
545 Error(
string.Format(
"[wpnfsm] ValidateAndRepair Attempting to repair: %1 - %2 - %3 - state: %4 != weapon: %5",
546 weapon.GetDebugName(weapon),
name,
m_State, stateCondition, gunCondition));
556 state = repairedState;
557 weapon.SyncSelectionState(state.HasBullet(), state.HasMagazine());
558 repairedState.SyncAnimState();
568 int currentTime =
g_Game.GetTime();
582 weapon.RandomizeFSMState();
584 weapon.Synchronize();
606 Error(
string.Format(
"[wpnfsm] %1 ValidateAndRepair THRESHOLD BREACH - %2 - %3 - state: %4 != weapon: %5",
607 weapon.GetDebugName(weapon),
name,
m_State, stateCondition, gunCondition));
616 interState = FindTransitionState(state, e1);
618 interState = FindTransitionState(state, e2);
641 Print(
"[wpnfsm] Warning! OnStoreLoad - cannot load curent weapon state, id=" +
id);
665 WeaponStateBase abort_dst = FindAbortDestinationState(
new WeaponEventHumanCommandActionAborted(null));
668 if (closest_stable_state)
670 Print(
"[wpnfsm] Save occured in fsm transition! current state=" + GetCurrentState() +
" closes stable state=" + closest_stable_state +
" id=" + closest_stable_state.
GetCurrentStateID());
674 Print(
"[wpnfsm] Warning! Save occured in fsm transition! GetCurrentStateID - cannot find closest weapon stable state.");
722 int tc = m_Transitions.Count();
729 if (state.IsSingleState())
732 candidates.Insert(state);
736 int nMuzzles = muzzleStates.Count();
737 int nMuzzlesState = state.GetMuzzleStateCount();
738 if (nMuzzles != nMuzzlesState)
740 ErrorEx(
string.Format(
"Number of muzzles on the weapon (%1) does not correspond with what state has configured (%2).", nMuzzles, nMuzzlesState));
745 for (
int i = 0; i < nMuzzles; ++i)
747 if (muzzleStates[i] != state.GetMuzzleState(i))
755 candidates.Insert(state);
759 int cc = candidates.Count();
769 selected.SyncAnimState();
void wpnDebugSpamALot(string s)
void wpnDebugSpam(string s)
void wpnDebugPrint(string s)
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
void Start()
Plays all elements this effects consists of.
void fsmDebugSpam(string s)
void fsmDebugPrint(string s)
enum EObjectTemperatureState m_State
enum FSMTransition WeaponTransition
represents transition src -— event[guard]/action -—|> dst
bool LoadCurrentUnstableFSMState(ParamsWriteContext ctx, int version)
static const int MIN_SYNCHRONIZE_INTERVAL
override WeaponStateBase ProcessAbortEvent(WeaponEventBase e, out ProcessEventResult result)
void RandomizeFSMState(bool hasBullet, bool hasMagazine, bool isJammed)
Deprecated, use RandomizeFSMStateEx for better results.
void OnFailThresholdBreached(Weapon weapon, string name, bool stateCondition, bool gunCondition)
bool LoadAndSetCurrentFSMState(ParamsReadContext ctx, int version)
bool SaveCurrentUnstableFSMState(ParamsWriteContext ctx)
bool SaveCurrentFSMState(ParamsWriteContext ctx)
save current state of fsm
ProcessEventResult ProcessLocalTransition(FSMTransition< WeaponStateBase, WeaponEventBase, WeaponActionBase, WeaponGuardBase > t, WeaponEventBase e)
ProcessEventResult ProcessAbortTransition(FSMTransition< WeaponStateBase, WeaponEventBase, WeaponActionBase, WeaponGuardBase > t, WeaponEventBase e)
int m_LastSynchronizeTime
bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
load current state of fsm
void SetInternalID(WeaponStateBase state)
unique list of states in this machine (automation of save/load)
static const int RESET_SYNCHRONIZE_THRESHOLD
bool ValidateAndRepairHelper(Weapon_Base weapon, string name, bool stateCondition, bool gunCondition, WeaponEventBase e1, WeaponEventBase e2, out WeaponStableState state)
static const int MAX_SYNCHRONIZE_ATTEMPTS
override void AddTransition(FSMTransition< WeaponStateBase, WeaponEventBase, WeaponActionBase, WeaponGuardBase > t)
adds transition into transition table As a side effect registers the state(s) into m_UniqueStates
ref array< WeaponStateBase > m_UniqueStates
counter for InternalID: each state in a fsm is assigned an unique number
int m_SynchronizeAttempts
int GetCurrentStableStateID()
WeaponStableState FindStableStateForID(int id)
load from database - reverse lookup for state from saved id
WeaponStateBase FindStateForInternalID(int id)
retrieve base state that matches given internal id
bool Internal_ValidateAndRepair()
validate the state of the gun and repair if mismatch
WeaponStableState ValidateAndRepairStateFinder(bool condition, WeaponEventBase e1, WeaponEventBase e2, WeaponStableState state)
void OnStoreSave(ParamsWriteContext ctx)
save state of fsm
override ProcessEventResult ProcessEvent(WeaponEventBase e)
void ValidateAndRepair()
validate the state of the gun and repair if mismatch
bool OnStoreLoad(ParamsReadContext ctx, int version)
load state of fsm
void RandomizeFSMStateEx(array< MuzzleState > muzzleStates, bool hasMagazine, bool isJammed)
With the parameters given, selects a random suitable state for the FSM of the weapon @NOTE: It is bet...
base class for hierarchic finite state machine
static bool IsWeaponLogEnable()
static bool IsInventoryHFSMLogEnable()
proto bool Write(void value_out)
proto bool Read(void value_in)
signalize mechanism manipulation
weapon finite state machine
script counterpart to engine's class Weapon
override int GetCurrentStateID()
override bool IsRepairEnabled()
override bool HasMagazine()
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
WeaponStateBase GetParentState()
void SetInternalStateID(int i)
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
represent weapon state base
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
const int INDEX_NOT_FOUND
Serializer ParamsReadContext
Serializer ParamsWriteContext
void Error(string err)
Messagebox with error message.
proto void Print(void var)
Prints content of variable to console/log.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].