DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
WeaponStateBase.c
Go to the documentation of this file.
1
11{
15 int m_InternalID = -1;
16
17 void WeaponStateBase (Weapon_Base w = NULL, WeaponStateBase parent = NULL) { m_weapon = w; m_parentState = parent; }
18
22 void SetParentState (WeaponStateBase parent) { m_parentState = parent; }
27
28 bool HasFSM () { return m_fsm != NULL; }
29 WeaponFSM GetFSM () { return m_fsm; }
30
31 void SetInternalStateID (int i) { m_InternalID = i; }
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
54 bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
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
111 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { " + this.Type().ToString()); }
112 }
113
119 void OnUpdate (float dt)
120 {
121 if (HasFSM() && m_fsm.IsRunning())
122 m_fsm.GetCurrentState().OnUpdate(dt);
123 }
124
130 {
131 if (HasFSM() && m_fsm.IsRunning())
132 {
133 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " OnAbort " + this.Type().ToString() + " Has Sub-FSM! Aborting submachine..."); }
134 m_fsm.Abort(e);
135 }
136 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } ABORTED " + this.Type().ToString()); }
137 }
138
144 {
145 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } " + this.Type().ToString()); }
146 }
147
152 bool IsWaitingForActionFinish () { return HasFSM() && m_fsm.IsRunning() && m_fsm.GetCurrentState().IsWaitingForActionFinish(); }
153
158 bool IsIdle () { return false; }
159
163 bool IsBoltOpen () { return false; }
164
171
178};
179
180
void wpnDebugSpam(string s)
Definition Debug.c:17
void wpnDebugPrint(string s)
Definition Debug.c:9
enum FSMTransition WeaponTransition
static bool IsWeaponLogEnable()
Definition Debug.c:640
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
Weapon_Base m_weapon
bool IsIdle()
idle state does not expect any animation events
void SetInternalStateID(int i)
WeaponFSM GetFSM()
void OnEntry(WeaponEventBase e)
bool ProcessEvent(WeaponEventBase e)
void OnSubMachineChanged(WeaponStateBase src, WeaponStateBase dst)
called when sub-machine has changed its state
ref WeaponFSM m_fsm
hierarchical parent state of this state (or null)
WeaponStateBase GetParentState()
bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
bool SaveCurrentFSMState(ParamsWriteContext ctx)
void SetParentState(WeaponStateBase parent)
allows construction of hierarchical state machine
WeaponStateBase m_parentState
weapon that this state relates to
bool IsWaitingForActionFinish()
void WeaponStateBase(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
internal state id used for load/restore
int m_InternalID
nested state machine (or null)
void OnUpdate(float dt)
void OnAbort(WeaponEventBase e)
void AddTransition(WeaponTransition t)
adds transition into m_fsm transition table
void OnStateChanged(WeaponStateBase src, WeaponStateBase dst)
called on current state when state machine has changed its state
void OnExit(WeaponEventBase e)
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90