DayZ 1.24
Loading...
Searching...
No Matches
WeaponStableState.c File Reference

Go to the source code of this file.

Enumerations

enum  MuzzleState { U = -1 , E = 0 , F = 1 , L = 2 }
 

Functions

void WeaponStableState (Weapon_Base w=NULL, WeaponStateBase parent=NULL, int anim_state=-1)
 
void SyncAnimState ()
 
override void OnEntry (WeaponEventBase e)
 
override void OnUpdate (float dt)
 
override void OnExit (WeaponEventBase e)
 
override bool IsIdle ()
 
int GetCurrentStateID ()
 
Weapon state properties

Properties defining the state in several properties for other systems Override these to set them up

Several systems depends on this: WeaponFSM.RandomizeFSMState, which picks out a suitable FSM state when attaching magazine through CE WeaponFSM.ValidateAndRepair, which will attempt to identify a desync and repair the FSM state if so

@WARNING So it is important to set these up correctly to prevent any desync of weapon FSM and actual wepon state

bool IsRepairEnabled ()
 Whether WeaponFSM.ValidateAndRepair should be applied on this state @NOTE: This property was implemented at the same time as ValARep To have it disabled by default In case there are modders who created their own state But potentially did not set up their properties correctly As having ValARep run on an improper setup would result in horrible VME spam and desync @WARNING: When enabling repair, it is imperative that all properties are set up correctly.
 
bool HasBullet ()
 Whether there is a bullet in the chamber @NOTE: This should only be false when it is empty So this is true when there is a bullet in the chamber Regardless of the bullet being loaded, firedout or jammed.
 
bool HasMagazine ()
 Whether there is a magazine attached.
 
bool IsJammed ()
 Whether the gun is jammed.
 
bool IsDischarged ()
 Whether the gun is discharged.
 
bool IsWeaponOpen ()
 Whether the gun is open.
 
void InitMuzzleArray ()
 Override with the filling of m_muzzleHasBullet.
 
bool IsSingleState ()
 Special one for when the weapon only has one singular state (like Magnum)
 
Weapon state properties helpers

Several helpers for better access of certain properties

MuzzleState GetMuzzleState (int idx)
 Get chamber state of the muzzle at index.
 
int GetMuzzleStateCount ()
 
bool IsChamberValid (int idx)
 
bool IsChamberFiredOut (int idx)
 
bool IsChamberFull (int idx)
 
void ValidateMuzzleArray ()
 Safety check and error message in case not set up correctly.
 

Variables

enum MuzzleState m_animState
 
ref array< MuzzleStatem_muzzleHasBullet = new array<MuzzleState>()
 

Enumeration Type Documentation

◆ MuzzleState

Enumerator

UNKNOWN.

EMPTY.

FIRED.

LOADED.

Definition at line 14 of file WeaponStableState.c.

15{
17 U = -1,
19 E = 0,
21 F = 1,
23 L = 2
24}
@ E
EMPTY.
@ U
UNKNOWN.
@ L
LOADED.
@ F
FIRED.

Function Documentation

◆ GetCurrentStateID()

int GetCurrentStateID ( )

Definition at line 91 of file WeaponStableState.c.

91{ return 0; }

◆ GetMuzzleState()

MuzzleState GetMuzzleState ( int idx)

Get chamber state of the muzzle at index.

Definition at line 148 of file WeaponStableState.c.

148{ return m_muzzleHasBullet[idx]; }
ref array< MuzzleState > m_muzzleHasBullet

References m_muzzleHasBullet.

◆ GetMuzzleStateCount()

int GetMuzzleStateCount ( )

Definition at line 149 of file WeaponStableState.c.

149{ return m_muzzleHasBullet.Count(); }

References m_muzzleHasBullet.

◆ HasBullet()

bool HasBullet ( )

Whether there is a bullet in the chamber @NOTE: This should only be false when it is empty So this is true when there is a bullet in the chamber Regardless of the bullet being loaded, firedout or jammed.

Definition at line 120 of file WeaponStableState.c.

120{ return false; }

◆ HasMagazine()

bool HasMagazine ( )

Whether there is a magazine attached.

Definition at line 123 of file WeaponStableState.c.

123{ return false; }

◆ InitMuzzleArray()

void InitMuzzleArray ( )

Override with the filling of m_muzzleHasBullet.

Definition at line 135 of file WeaponStableState.c.

MuzzleState

References m_muzzleHasBullet.

◆ IsChamberFiredOut()

◆ IsChamberFull()

◆ IsChamberValid()

bool IsChamberValid ( int idx)

Definition at line 150 of file WeaponStableState.c.

150{ return m_muzzleHasBullet[idx] != MuzzleState.U; }

References m_muzzleHasBullet.

◆ IsDischarged()

bool IsDischarged ( )

Whether the gun is discharged.

Definition at line 129 of file WeaponStableState.c.

129{ return false; }

◆ IsIdle()

override bool IsIdle ( )

Definition at line 89 of file WeaponStableState.c.

89{ return true; }

Referenced by Weapon::CanRemoveFromHands(), and ManBase::OnQuickBarSingleUse().

◆ IsJammed()

bool IsJammed ( )

Whether the gun is jammed.

Definition at line 126 of file WeaponStableState.c.

126{ return false; }

◆ IsRepairEnabled()

bool IsRepairEnabled ( )

Whether WeaponFSM.ValidateAndRepair should be applied on this state @NOTE: This property was implemented at the same time as ValARep To have it disabled by default In case there are modders who created their own state But potentially did not set up their properties correctly As having ValARep run on an improper setup would result in horrible VME spam and desync @WARNING: When enabling repair, it is imperative that all properties are set up correctly.

Definition at line 113 of file WeaponStableState.c.

113{ return false; }

◆ IsSingleState()

bool IsSingleState ( )

Special one for when the weapon only has one singular state (like Magnum)

Definition at line 138 of file WeaponStableState.c.

138{ return false; }

Referenced by ValidateMuzzleArray().

◆ IsWeaponOpen()

bool IsWeaponOpen ( )

Whether the gun is open.

Definition at line 132 of file WeaponStableState.c.

132{ return false; }

◆ OnEntry()

Definition at line 70 of file WeaponStableState.c.

71 {
72 super.OnEntry(e);
73 m_weapon.SetJammed(false);
74 if (e)
76 m_weapon.ResetWeaponAnimState();
77 }
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition Guards.c:602
void SyncAnimState()

References m_weapon, and SyncAnimState().

◆ OnExit()

Definition at line 83 of file WeaponStableState.c.

84 {
85 m_weapon.ResetWeaponAnimState();
86 super.OnExit(e);
87 }

References m_weapon.

◆ OnUpdate()

override void OnUpdate ( float dt)

Definition at line 78 of file WeaponStableState.c.

79 {
80 super.OnUpdate(dt);
82 }

References SyncAnimState().

◆ SyncAnimState()

void SyncAnimState ( )

Definition at line 39 of file WeaponStableState.c.

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);
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());
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 m_weapon.SetGroundAnimFrameIndex(m_animState);
67 }
68 }
void fsmDebugSpam(string s)
Definition HFSMBase.c:9
PistolAnimState
Definition Pistol_Base.c:3
enum MuzzleState m_animState
Super root of all classes in Enforce script.
Definition EnScript.c:11
proto static native void StaticSetInitState(Human pHuman, int pFrameIdx)
just static version of SetInitState
static bool IsWeaponLogEnable()
Definition Debug.c:799
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.

References Class::CastTo(), fsmDebugSpam(), LogManager::IsWeaponLogEnable(), m_animState, m_weapon, and HumanCommandWeapons::StaticSetInitState().

Referenced by HandStateBase::OnEntry(), OnEntry(), HandStateBase::OnUpdate(), and OnUpdate().

◆ ValidateMuzzleArray()

void ValidateMuzzleArray ( )

Safety check and error message in case not set up correctly.

Definition at line 157 of file WeaponStableState.c.

158 {
159 // There is only one
160 if (IsSingleState())
161 return;
162
163 bool failed = false;
164
165 if (!failed)
166 {
168 {
169 if (state == MuzzleState.U)
170 {
171 failed = true;
172 break;
173 }
174 }
175 }
176
177 if (failed)
178 {
180
181#ifdef DEVELOPER
182 if (DayZGame.m_IsPreviewSpawn)
183 {
184 // we do not want VMEs when spawning the item in order to visualize it for preview in script console
186 }
187#endif
188
189 ErrorEx("Muzzle array validation has failed. Please set up the correct muzzle states by overriding InitMuzzleArray.", severity);
190 }
191 }
bool IsSingleState()
Special one for when the weapon only has one singular state (like Magnum)
ErrorExSeverity
Definition EnDebug.c:62
enum ShapeType ErrorEx

References ErrorEx, IsSingleState(), and m_muzzleHasBullet.

Referenced by WeaponStableState().

◆ WeaponStableState()

void WeaponStableState ( Weapon_Base w = NULL,
WeaponStateBase parent = NULL,
int anim_state = -1 )

Definition at line 32 of file WeaponStableState.c.

33 {
37 }
void InitMuzzleArray()
Override with the filling of m_muzzleHasBullet.
void ValidateMuzzleArray()
Safety check and error message in case not set up correctly.

References WeaponStableState::InitMuzzleArray(), m_animState, and ValidateMuzzleArray().

Referenced by Weapon_Base::InitStateMachine().

Variable Documentation

◆ m_animState

enum MuzzleState m_animState

Referenced by SyncAnimState(), and WeaponStableState().

◆ m_muzzleHasBullet