Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weaponstablestate.c
Go to the documentation of this file.
1 
15 {
17  U = -1,
19  E = 0,
21  F = 1,
23  L = 2
24 }
25 
27 {
28  int m_animState;
29 
31 
32  void WeaponStableState(Weapon_Base w = NULL, WeaponStateBase parent = NULL, int anim_state = -1)
33  {
34  m_animState = anim_state;
35  InitMuzzleArray();
37  }
38 
40  {
41  int curr = m_weapon.GetWeaponAnimState();
42  if (curr != m_animState)
43  {
44  //if (LogManager.IsWeaponLogEnable()) fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " synchronizing anim state: " + curr + " --> " + m_animState);
45  PlayerBase p;
46  if (Class.CastTo(p, m_weapon.GetHierarchyParent()))
47  {
48  if (p.GetItemInHands() == m_weapon)
49  {
50  HumanCommandWeapons hcw = p.GetCommandModifier_Weapons();
51  if (hcw)
52  {
53  hcw.SetInitState(m_animState);
54  if (LogManager.IsWeaponLogEnable()) fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " state=" + m_weapon.GetCurrentState().Type() + " synchronized anim state: " + typename.EnumToString(PistolAnimState, curr) + " --> " + typename.EnumToString(PistolAnimState, m_animState));
55  }
56  else
57  {
58  Human wpnOwner = Human.Cast(m_weapon.GetHierarchyRootPlayer());
59  HumanCommandWeapons.StaticSetInitState(wpnOwner, m_animState);
60  if (LogManager.IsWeaponLogEnable()) fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " state=" + m_weapon.GetCurrentState().Type() + " synchronized remote anim state: " + typename.EnumToString(PistolAnimState, curr) + " --> " + typename.EnumToString(PistolAnimState, m_animState));
61  }
62  }
63  m_weapon.SetWeaponAnimState(m_animState);
64  }
65  else
66  {
67  m_weapon.SetGroundAnimFrameIndex(m_animState);
68  }
69  }
70  }
71 
72  override void OnEntry(WeaponEventBase e)
73  {
74  super.OnEntry(e);
75  m_weapon.SetJammed(false);
76  if (e)
77  SyncAnimState();
78  m_weapon.ResetWeaponAnimState();
79  }
80  override void OnUpdate(float dt)
81  {
82  super.OnUpdate(dt);
83  SyncAnimState();
84  }
85  override void OnExit(WeaponEventBase e)
86  {
87  m_weapon.ResetWeaponAnimState();
88  super.OnExit(e);
89  }
90 
91  override bool IsIdle() { return true; }
92 
93  int GetCurrentStateID() { return 0; }
94 
106 
115  bool IsRepairEnabled() { return false; }
116 
122  bool HasBullet() { return false; }
123 
125  bool HasMagazine() { return false; }
126 
128  bool IsJammed() { return false; }
129 
131  bool IsDischarged() { return false; }
132 
134  bool IsWeaponOpen() { return false; }
135 
137  void InitMuzzleArray() { m_muzzleHasBullet = { MuzzleState.U }; }
138 
140  bool IsSingleState() { return false; }
141 
143 
148 
150  MuzzleState GetMuzzleState(int idx) { return m_muzzleHasBullet[idx]; }
151  int GetMuzzleStateCount() { return m_muzzleHasBullet.Count(); }
152  bool IsChamberValid(int idx) { return m_muzzleHasBullet[idx] != MuzzleState.U; }
153  bool IsChamberFiredOut(int idx) { return m_muzzleHasBullet[idx] == MuzzleState.F; }
154  bool IsChamberFull(int idx) { return m_muzzleHasBullet[idx] != MuzzleState.E; }
155 
157 
160  {
161  // There is only one
162  if (IsSingleState())
163  return;
164 
165  bool failed = false;
166 
167  if (!failed)
168  {
169  foreach (MuzzleState state : m_muzzleHasBullet)
170  {
171  if ( state == MuzzleState.U )
172  {
173  failed = true;
174  break;
175  }
176  }
177  }
178 
179  if (failed)
180  {
181  ErrorExSeverity severity = ErrorExSeverity.ERROR;
182 
183  #ifdef DEVELOPER
184  if (DayZGame.m_IsPreviewSpawn)
185  {
186  // we do not want VMEs when spawning the item in order to visualize it for preview in script console
187  severity = ErrorExSeverity.INFO;
188  }
189  #endif
190 
191  ErrorEx("Muzzle array validation has failed. Please set up the correct muzzle states by overriding InitMuzzleArray.", severity);
192  }
193  }
194 };
195 
196 
GetMuzzleState
MuzzleState GetMuzzleState(int idx)
Get chamber state of the muzzle at index.
Definition: weaponstablestate.c:150
PistolAnimState
PistolAnimState
Definition: pistol_base.c:2
E
@ E
EMPTY.
Definition: weaponstablestate.c:19
IsIdle
override bool IsIdle()
Definition: weaponstablestate.c:91
LogManager
Definition: debug.c:734
m_animState
enum MuzzleState m_animState
IsChamberFull
bool IsChamberFull(int idx)
Definition: weaponstablestate.c:154
WeaponStableState
void WeaponStableState(Weapon_Base w=NULL, WeaponStateBase parent=NULL, int anim_state=-1)
Definition: weaponstablestate.c:32
IsChamberFiredOut
bool IsChamberFiredOut(int idx)
Definition: weaponstablestate.c:153
IsSingleState
bool IsSingleState()
Special one for when the weapon only has one singular state (like Magnum)
Definition: weaponstablestate.c:140
L
@ L
LOADED.
Definition: weaponstablestate.c:23
ErrorEx
enum ShapeType ErrorEx
ValidateMuzzleArray
void ValidateMuzzleArray()
Safety check and error message in case not set up correctly.
Definition: weaponstablestate.c:159
F
@ F
FIRED.
Definition: weaponstablestate.c:21
PlayerBase
Definition: playerbaseclient.c:1
fsmDebugSpam
void fsmDebugSpam(string s)
Definition: hfsmbase.c:9
ErrorExSeverity
ErrorExSeverity
Definition: endebug.c:61
Object
Definition: objecttyped.c:1
m_muzzleHasBullet
ref array< MuzzleState > m_muzzleHasBullet
Definition: weaponstablestate.c:30
OnUpdate
override void OnUpdate(float dt)
Definition: weaponstablestate.c:80
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
HumanCommandWeapons
Definition: human.c:986
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
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
IsChamberValid
bool IsChamberValid(int idx)
Definition: weaponstablestate.c:152
IsWeaponOpen
bool IsWeaponOpen()
Whether the gun is open.
Definition: weaponstablestate.c:134
GetMuzzleStateCount
int GetMuzzleStateCount()
Definition: weaponstablestate.c:151
SyncAnimState
void SyncAnimState()
Definition: weaponstablestate.c:39
WeaponStableState
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
Definition: crossbow.c:26
U
@ U
UNKNOWN.
Definition: weaponstablestate.c:17
MuzzleState
MuzzleState
Definition: weaponstablestate.c:14