Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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 }
86
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 float GetCoolDown() { return 0; }
180};
181
182
void wpnDebugSpam(string s)
Definition debug.c:17
void wpnDebugPrint(string s)
Definition debug.c:9
static bool IsWeaponLogEnable()
Definition debug.c:816
signalize mechanism manipulation
Definition events.c:35
weapon finite state machine
represent weapon state base
Definition bullethide.c:2
Weapon_Base m_weapon
void SetInternalStateID(int i)
void AddTransition(WeaponTransition t)
WeaponFSM GetFSM()
bool IsIdle()
idle state does not expect any animation events
void OnEntry(WeaponEventBase e)
bool ProcessEvent(WeaponEventBase e)
ref WeaponFSM m_fsm
hierarchical parent state of this state (or null)
bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
bool SaveCurrentFSMState(ParamsWriteContext ctx)
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 OnSubMachineChanged(WeaponStateBase src, WeaponStateBase dst)
void OnUpdate(float dt)
void OnStateChanged(WeaponStateBase src, WeaponStateBase dst)
void OnAbort(WeaponEventBase e)
WeaponStateBase GetParentState()
void SetParentState(WeaponStateBase parent)
void OnExit(WeaponEventBase e)
Serializer ParamsReadContext
Definition gameplay.c:15
Serializer ParamsWriteContext
Definition gameplay.c:16
void Error(string err)
Messagebox with error message.
Definition endebug.c:90
enum FSMTransition WeaponTransition