Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weaponstatebase.c
Go to the documentation of this file.
1 
10 class WeaponStateBase
11 {
12  Weapon_Base m_weapon;
13  WeaponStateBase m_parentState;
14  ref WeaponFSM m_fsm;
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; }
26  WeaponStateBase GetParentState () { return m_parentState; }
27 
28  bool HasFSM () { return m_fsm != NULL; }
29  WeaponFSM GetFSM () { return m_fsm; }
30 
31  void SetInternalStateID (int i) { m_InternalID = i; }
32  int GetInternalStateID () { return m_InternalID; }
33 
34  bool SaveCurrentFSMState (ParamsWriteContext ctx)
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 
80  bool ProcessEvent (WeaponEventBase e)
81  {
82  if (HasFSM())
83  return m_fsm.ProcessEvent(e);
84  return false;
85  }
89  void AddTransition (WeaponTransition t)
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 
103  void OnEntry (WeaponEventBase e)
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 
129  void OnAbort (WeaponEventBase e)
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 
143  void OnExit (WeaponEventBase e)
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 
170  void OnSubMachineChanged (WeaponStateBase src, WeaponStateBase dst) { }
171 
177  void OnStateChanged (WeaponStateBase src, WeaponStateBase dst) { }
178 };
179 
180 
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
LogManager
Definition: debug.c:734
wpnDebugPrint
void wpnDebugPrint(string s)
Definition: debug.c:9
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
Object
Definition: objecttyped.c:1
WeaponTransition
enum FSMTransition WeaponTransition
wpnDebugSpam
void wpnDebugSpam(string s)
Definition: debug.c:17
WeaponEventBase
signalize mechanism manipulation
Definition: events.c:34
WeaponStateBase
represent weapon state base
Definition: bullethide.c:1
m_weapon
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition: guards.c:583
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
WeaponFSM
weapon finite state machine