DayZ 1.24
Loading...
Searching...
No Matches
WeaponStateBase.c
Go to the documentation of this file.
1
11{
15 int m_InternalID = -1;
16
18
22 void SetParentState(WeaponStateBase parent) { m_parentState = parent; }
27
28 bool HasFSM() { return m_fsm != NULL; }
29 WeaponFSM GetFSM() { return m_fsm; }
30
33
35 {
36 if (HasFSM())
37 {
38 if (IsIdle())
39 {
40 if (LogManager.IsWeaponLogEnable()) wpnDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponStateBase::SaveCurrentFSMState - idle state, skipping other substates");
41 return m_fsm.SaveCurrentFSMState(ctx);
42 }
43 else
44 {
45 // if parent state is !idle (unstable) then save whole machine
46 if (LogManager.IsWeaponLogEnable()) wpnDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponStateBase::SaveCurrentFSMState - NOT idle state, saving full submachine state");
47 return m_fsm.SaveCurrentUnstableFSMState(ctx);
48 }
49 return false;
50 }
51 return true;
52 }
53
55 {
56 if (HasFSM())
57 {
58 if (IsIdle())
59 {
60 if (LogManager.IsWeaponLogEnable()) wpnDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponStateBase::LoadCurrentFSMState - idle state, skipping other substates");
61 if (m_fsm.LoadCurrentFSMState(ctx, version))
62 return true;
63 else
64 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponStateBase::LoadCurrentFSMState - Cannot load stable state for weapon=" + this);
65 }
66 else
67 {
68 // if parent state is !idle (unstable) then load whole machine
69 if (LogManager.IsWeaponLogEnable()) wpnDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponStateBase::LoadCurrentFSMState - NOT idle state, loading full submachine state");
70 if (m_fsm.LoadCurrentUnstableFSMState(ctx, version))
71 return true;
72 else
73 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponStateBase::LoadCurrentFSMState - Cannot load unstable state for weapon=" + this);
74 }
75 return false;
76 }
77 return true;
78 }
79
81 {
82 if (HasFSM())
83 return m_fsm.ProcessEvent(e);
84 return false;
85 }
90 {
91 if (HasFSM())
92 m_fsm.AddTransition(t);
93 else
94 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " adding transition to state without FSM. Configure FSM first.");
95 }
96
97
104 {
105 if (HasFSM() && !m_fsm.IsRunning())
106 {
107 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { " + this.Type().ToString() + " Has Sub-FSM! Starting submachine...");
108 m_fsm.Start(e);
109 }
110 else if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { " + this.Type().ToString());
111 }
112
118 void OnUpdate(float dt)
119 {
120 if (HasFSM() && m_fsm.IsRunning())
121 m_fsm.GetCurrentState().OnUpdate(dt);
122 }
123
129 {
130 if (HasFSM() && m_fsm.IsRunning())
131 {
132 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " OnAbort " + this.Type().ToString() + " Has Sub-FSM! Aborting submachine...");
133 m_fsm.Abort(e);
134 }
135 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } ABORTED " + this.Type().ToString());
136 }
137
143 {
144 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } " + this.Type().ToString());
145 }
146
151 bool IsWaitingForActionFinish() { return HasFSM() && m_fsm.IsRunning() && m_fsm.GetCurrentState().IsWaitingForActionFinish(); }
152
157 bool IsIdle() { return false; }
158
162 bool IsBoltOpen() { return false; }
163
170
177};
178
void wpnDebugSpam(string s)
Definition Debug.c:17
void wpnDebugPrint(string s)
Definition Debug.c:9
static bool IsWeaponLogEnable()
Definition Debug.c:799
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
signalize mechanism manipulation
Definition Events.c:35
weapon finite state machine
represent weapon state base
Definition BulletHide.c:2
bool SaveCurrentFSMState(ParamsWriteContext ctx)
bool ProcessEvent(WeaponEventBase e)
void OnStateChanged(WeaponStateBase src, WeaponStateBase dst)
called on current state when state machine has changed its state
void OnAbort(WeaponEventBase e)
WeaponFSM GetFSM()
bool IsIdle()
idle state does not expect any animation events
void OnExit(WeaponEventBase e)
void WeaponStateBase(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
internal state id used for load/restore
bool IsWaitingForActionFinish()
WeaponStateBase m_parentState
weapon that this state relates to
bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
ref WeaponFSM m_fsm
hierarchical parent state of this state (or null)
Weapon_Base m_weapon
void SetParentState(WeaponStateBase parent)
allows construction of hierarchical state machine
void OnUpdate(float dt)
WeaponStateBase GetParentState()
int m_InternalID
nested state machine (or null)
void OnSubMachineChanged(WeaponStateBase src, WeaponStateBase dst)
called when sub-machine has changed its state
void SetInternalStateID(int i)
void AddTransition(WeaponTransition t)
adds transition into m_fsm transition table
void OnEntry(WeaponEventBase e)
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90