Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weaponunjamming.c
Go to the documentation of this file.
1 class WeaponChamberFromAttMag_W4T extends WeaponChamberFromAttMag
2 {
3  override bool IsWaitingForActionFinish () { return true; }
4 };
5 
6 class WeaponChamberFromInnerMag_W4T extends WeaponChamberFromInnerMag
7 {
8  override bool IsWaitingForActionFinish () { return true; }
9 };
10 
11 class WeaponUnjamming_Start extends WeaponStartAction
12 {
13  float m_dtAccumulator;
14  float m_jamTime;
15 
16  void WeaponUnjamming_Start (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
17  {
18  m_dtAccumulator = 0.0;
19  m_jamTime = 0.0;
20  }
21 
22  override void OnEntry (WeaponEventBase e)
23  {
24  super.OnEntry(e);
25  }
26 
27  override void OnUpdate (float dt)
28  {
29  m_dtAccumulator += dt;
30 
31  DayZPlayer p;
32  Class.CastTo(p, m_weapon.GetHierarchyParent());
33  if(p)
34  {
35  HumanInputController hic = p.GetInputController();
36  HumanCommandWeapons hcw = p.GetCommandModifier_Weapons();
37 
38  if (m_dtAccumulator >= m_jamTime)
39  {
40  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " Unjammed!"); }
41  hcw.StartAction(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_END);
42  m_weapon.ProcessWeaponEvent(new WeaponEventUnjammingTimeout(p));
43  return; // unjammed successfuly
44  }
45 
46 
47  if (hic.IsReloadOrMechanismContinuousUse())
48  {
49  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " Unjamming..."); }
50  }
51  #ifndef PLATFORM_CONSOLE
52  #ifndef SERVER_FOR_CONSOLE
53  else
54  {
55  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " Unjamming failed, weapon still jammed"); }
56  hcw.StartAction(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_INTERRUPT);
57  m_weapon.ProcessWeaponEvent(new WeaponEventUnjammingFailedTimeout(p));
58  }
59  #endif
60  #endif
61  }
62  }
63 
64  override void OnExit (WeaponEventBase e)
65  {
66  m_dtAccumulator = 0.0;
67  m_jamTime = 0.0;
68  super.OnExit(e);
69  }
70 };
71 
73 {
74  float m_damage;
75  string m_type;
76 
77  override void OnEntry (WeaponEventBase e)
78  {
79  super.OnEntry(e);
80  if (e)
81  {
82  m_type = string.Empty;
83 
84  float dmg;
85  string type;
86 
87  m_weapon.SetJammed(false);
88 
89  int mi = m_weapon.GetCurrentMuzzle();
90 
91  if (m_weapon.IsChamberFiredOut(mi))
92  {
93  m_weapon.EjectCasing(mi);
94  m_weapon.EffectBulletHide(mi);
95  m_weapon.SelectionBulletHide();
96  }
97 
98  if (!m_weapon.IsChamberEmpty(mi))
99  {
100  DayZPlayer p = e.m_player;
101 
102  m_weapon.CreateRound(mi);
104 
105  m_weapon.EffectBulletHide(mi);
106  m_weapon.SelectionBulletHide();
107  }
108  }
109  }
110  override void OnExit (WeaponEventBase e)
111  {
112  m_type = string.Empty;
113  super.OnExit(e);
114  }
115 
116  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
117  {
118  if (!super.SaveCurrentFSMState(ctx))
119  return false;
120 
121  if (!ctx.Write(m_damage))
122  {
123  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponUnjamming_Cartridge.SaveCurrentFSMState: cannot write m_damage for weapon=" + m_weapon);
124  return false;
125  }
126  if (!ctx.Write(m_type))
127  {
128  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponUnjamming_Cartridge.SaveCurrentFSMState: cannot write m_type for weapon=" + m_weapon);
129  return false;
130  }
131  return true;
132  }
133 
134  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
135  {
136  if (!super.LoadCurrentFSMState(ctx, version))
137  return false;
138 
139  if (!ctx.Read(m_damage))
140  {
141  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponUnjamming_Cartridge.LoadCurrentFSMState: cannot read m_damage for weapon=" + m_weapon);
142  return false;
143  }
144  if (!ctx.Read(m_type))
145  {
146  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponUnjamming_Cartridge.LoadCurrentFSMState: cannot read m_type for weapon=" + m_weapon);
147  return false;
148  }
149  return true;
150  }
151 
152 };
153 
154 class WeaponUnjamming_Cartridge_W4T extends WeaponUnjamming_Cartridge
155 {
156  override bool IsWaitingForActionFinish () { return true; }
157 };
158 
159 class WeaponUnjamming_W4T extends WeaponStateBase
160 {
161  override bool IsWaitingForActionFinish () { return true; }
162 };
163 
164 
168 class WeaponUnjamming extends WeaponStateBase
169 {
171  int m_actionType;
172  float m_dtAccumulator;
173  float m_jamTime;
174 
175  ref WeaponUnjamming_Start m_start;
176  ref WeaponUnjamming_Cartridge_W4T m_eject;
177  ref WeaponUnjamming_W4T m_w4t;
178  ref WeaponChamberFromAttMag_W4T m_chamber;
179 
180  void WeaponUnjamming (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
181  {
182  m_action = action;
183  m_actionType = actionType;
184 
185  // setup nested state machine
186  m_start = new WeaponUnjamming_Start(m_weapon, this, m_action, m_actionType);
187  m_eject = new WeaponUnjamming_Cartridge_W4T(m_weapon, this);
188  m_chamber = new WeaponChamberFromAttMag_W4T(m_weapon, this);
189  m_w4t = new WeaponUnjamming_W4T(m_weapon, this);
190 
191  // events
192  WeaponEventBase _uto_ = new WeaponEventUnjammingTimeout;
193  WeaponEventBase _fto_ = new WeaponEventUnjammingFailedTimeout;
194  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
195  WeaponEventBase __uj_ = new WeaponEventAnimUnjammed;
196 
197  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
198  // transitions
199  m_fsm.AddTransition(new WeaponTransition( m_start, _uto_, m_eject));
200  m_fsm.AddTransition(new WeaponTransition( m_start, _fto_, m_w4t));
201  m_fsm.AddTransition(new WeaponTransition( m_eject, __uj_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
202  m_fsm.AddTransition(new WeaponTransition( m_eject, _fin_, NULL));
203  m_fsm.AddTransition(new WeaponTransition( m_w4t, _fin_, NULL));
204  m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
205 
206  // Safety exits
207  m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, null));
208 
209  m_fsm.SetInitialState(m_start);
210  }
211 
212  override void OnEntry (WeaponEventBase e)
213  {
214  super.OnEntry(e);
215  if (e)
216  {
217  m_dtAccumulator = 0.0;
218  m_jamTime = 5.0; // @TODO: rand
219 
220  m_start.m_dtAccumulator = m_dtAccumulator;
221  m_start.m_jamTime = m_jamTime;
222  }
223  }
224 
225  override void OnExit (WeaponEventBase e)
226  {
227  m_dtAccumulator = 0.0;
228  m_jamTime = 0.0;
229  super.OnExit(e);
230  }
231 };
232 
LoadCurrentFSMState
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
Definition: weaponchambering.c:867
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
WeaponChamberFromInnerMag
Definition: weaponunjamming.c:6
LogManager
Definition: debug.c:734
ejectBulletAndStoreInMagazine
void ejectBulletAndStoreInMagazine(Weapon_Base weapon, int muzzleIndex, Magazine mag, DayZPlayer p)
Definition: weapon_utils.c:58
OnExit
override void OnExit(HandEventBase e)
Definition: hand_states.c:28
wpnDebugPrint
void wpnDebugPrint(string s)
Definition: debug.c:9
WeaponActionUnjammingTypes
WeaponActionUnjammingTypes
Definition: human.c:904
m_eject
ref WeaponEjectCasingMultiMuzzle m_eject
Definition: weaponchambering.c:638
m_chamber
ref WeaponChambering_Base m_chamber
Definition: weaponchambering.c:639
m_dtAccumulator
class WeaponFireWithEject extends WeaponFire m_dtAccumulator
m_action
class WeaponEndAction extends WeaponStartAction m_action
WeaponStartAction
simple class starting animation action specified by m_action and m_actionType
Definition: weaponchambering.c:2
DayZPlayer
Definition: dayzplayerimplement.c:72
WeaponActions
WeaponActions
actions
Definition: human.c:808
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
WeaponUnjamming_Cartridge
Definition: weaponunjamming.c:154
IsWaitingForActionFinish
class WeaponChambering_Cartridge_InnerMag extends WeaponChambering_Base IsWaitingForActionFinish
Definition: weaponchambering.c:190
m_start
ref WeaponStateBase m_start
Definition: weaponchambering.c:637
WeaponUnjamming
unjam submachine
SaveCurrentFSMState
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
Definition: weaponchambering.c:848
OnUpdate
proto native void OnUpdate()
Definition: tools.c:349
Object
Definition: objecttyped.c:1
WeaponTransition
enum FSMTransition WeaponTransition
HumanInputController
Definition: human.c:17
WeaponGuardHasAmmo
void WeaponGuardHasAmmo(Weapon_Base w=NULL)
Definition: guards.c:99
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
WeaponFSM
weapon finite state machine
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
WeaponChamberFromAttMag
Definition: weaponunjamming.c:1
OnEntry
HandStateEquipped OnEntry
Definition: weaponchambering.c:208