Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
weaponstablestate.c
Go to the documentation of this file.
1
15{
17 U = -1,
19 E = 0,
21 F = 1,
23 L = 2
25
27{
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
76 if (e)
78
79 m_weapon.SetJammed(IsJammed());
80 m_weapon.SetCharged(!IsDischarged());
81 m_weapon.SetWeaponOpen(IsWeaponOpen());
82 m_weapon.ResetWeaponAnimState();
83 }
84 override void OnUpdate(float dt)
85 {
86 super.OnUpdate(dt);
88 }
89 override void OnExit(WeaponEventBase e)
90 {
91 m_weapon.ResetWeaponAnimState();
92 super.OnExit(e);
93 }
94
95 override bool IsIdle() { return true; }
96
97 int GetCurrentStateID() { return 0; }
98
110
119 bool IsRepairEnabled() { return false; }
120
126 bool HasBullet() { return false; }
127
129 bool HasMagazine() { return false; }
130
132 bool IsJammed() { return false; }
133
135 bool IsDischarged() { return false; }
136
138 bool IsWeaponOpen() { return false; }
139
141 void InitMuzzleArray() { m_muzzleHasBullet = { MuzzleState.U }; }
142
144 bool IsSingleState() { return false; }
145
147
152
155 int GetMuzzleStateCount() { return m_muzzleHasBullet.Count(); }
156 bool IsChamberValid(int idx) { return m_muzzleHasBullet[idx] != MuzzleState.U; }
157 bool IsChamberFiredOut(int idx) { return m_muzzleHasBullet[idx] == MuzzleState.F; }
158 bool IsChamberFull(int idx) { return m_muzzleHasBullet[idx] != MuzzleState.E; }
159
161
164 {
165 // There is only one
166 if (IsSingleState())
167 return;
168
169 bool failed = false;
170
171 if (!failed)
172 {
173 foreach (MuzzleState state : m_muzzleHasBullet)
174 {
175 if ( state == MuzzleState.U )
176 {
177 failed = true;
178 break;
179 }
180 }
181 }
182
183 if (failed)
184 {
185 ErrorExSeverity severity = ErrorExSeverity.ERROR;
186
187 #ifdef DEVELOPER
188 if (DayZGame.m_IsPreviewSpawn)
189 {
190 // we do not want VMEs when spawning the item in order to visualize it for preview in script console
191 severity = ErrorExSeverity.INFO;
192 }
193 #endif
194
195 ErrorEx("Muzzle array validation has failed. Please set up the correct muzzle states by overriding InitMuzzleArray.", severity);
196 }
197 }
198};
199
200
Super root of all classes in Enforce script.
Definition enscript.c:11
signalize mechanism manipulation
Definition events.c:35
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
Definition crossbow.c:27
represent weapon state base
Definition bullethide.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition guards.c:604
void fsmDebugSpam(string s)
Definition hfsmbase.c:9
PistolAnimState
Definition pistol_base.c:3
class SSPFireout extends WeaponStableState OnEntry
class WeaponChambering_Chamber_OnEntry extends WeaponChambering_Base OnExit
int GetMuzzleStateCount()
bool IsChamberValid(int idx)
void SyncAnimState()
enum MuzzleState m_animState
MuzzleState
@ E
EMPTY.
@ U
UNKNOWN.
@ L
LOADED.
@ F
FIRED.
void ValidateMuzzleArray()
Safety check and error message in case not set up correctly.
override bool IsIdle()
ref array< MuzzleState > m_muzzleHasBullet
bool IsSingleState()
Special one for when the weapon only has one singular state (like Magnum)
void WeaponStableState(Weapon_Base w=NULL, WeaponStateBase parent=NULL, int anim_state=-1)
bool IsChamberFiredOut(int idx)
bool IsWeaponOpen()
Whether the gun is open.
MuzzleState GetMuzzleState(int idx)
Get chamber state of the muzzle at index.
bool IsChamberFull(int idx)