Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weaponcharging.c
Go to the documentation of this file.
1 
5 {
7  int m_actionType;
8 
9  ref WeaponCharging_Start m_start;
10  ref WeaponCharging_CK m_onCK;
11  ref WeaponChamberFromAttMag_W4T m_chamber;
12  ref WeaponEjectAndChamberFromAttMag m_ejectChamber;
14 
15  void WeaponCharging (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
16  {
17  m_action = action;
18  m_actionType = actionType;
19 
20  // setup nested state machine
21  m_start = new WeaponCharging_Start(m_weapon, this, m_action, m_actionType);
22  m_onCK = new WeaponCharging_CK(m_weapon, this);
23  m_chamber = new WeaponChamberFromAttMag_W4T(m_weapon, this);
24  m_ejectChamber = new WeaponEjectAndChamberFromAttMag(m_weapon, this);
26 
27  // events
28  WeaponEventBase __be_ = new WeaponEventAnimBulletEject;
29  WeaponEventBase __bh_ = new WeaponEventAnimBulletHide;
30  WeaponEventBase __ck_ = new WeaponEventAnimCocked;
31  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
32 
33  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
34  // transitions
35  m_fsm.AddTransition(new WeaponTransition( m_start, __be_, m_ejectChamber, NULL, new WeaponGuardHasAmmo(m_weapon) ));
36  m_fsm.AddTransition(new WeaponTransition( m_start, __be_, m_eject ));
37  m_fsm.AddTransition(new WeaponTransition( m_start, _fin_, NULL ));
38 
39  //m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_eject, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
40  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon))); // some anims do not send BE event
41  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_onCK)); // some anims do not send BE event
42 
43  m_fsm.AddTransition(new WeaponTransition( m_ejectChamber, __ck_, m_onCK ));
44  m_fsm.AddTransition(new WeaponTransition( m_ejectChamber, _fin_, NULL ));
45  m_fsm.AddTransition(new WeaponTransition( m_eject, __ck_, m_onCK));
46  m_fsm.AddTransition(new WeaponTransition( m_eject, _fin_, NULL));
47 
48  m_fsm.AddTransition(new WeaponTransition( m_onCK, _fin_, NULL));
49 
50  m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
51 
52  m_fsm.SetInitialState(m_start);
53  }
54 };
55 
56 class WeaponCharging_Start extends WeaponStartAction
57 {
58  override bool IsWaitingForActionFinish ()
59  {
60  return true;
61  }
62 };
63 
64 class WeaponCharging_BE extends WeaponStateBase
65 {
66 };
67 
68 class WeaponCharging_CK extends WeaponStateBase
69 {
70  override bool IsWaitingForActionFinish () { return true; }
71  override void OnEntry (WeaponEventBase e)
72  {
73  super.OnEntry(e);
74  m_weapon.SetCharged(true);
75  m_weapon.SetWeaponOpen(false);
76  }
77 };
78 
79 class WeaponEjectBullet_Cartridge extends WeaponStateBase
80 {
81  Magazine m_dstMagazine;
82 
83  override void OnEntry (WeaponEventBase e)
84  {
85  super.OnEntry(e);
86  if(e)
87  {
88  DayZPlayer p = e.m_player;
89  int mi = m_weapon.GetCurrentMuzzle();
90 
91  ejectBulletAndStoreInMagazine(m_weapon, mi, m_dstMagazine, p); // MP-safe
92  }
93  }
94 
95  override void OnAbort (WeaponEventBase e)
96  {
97  m_dstMagazine = NULL;
98  super.OnAbort(e);
99  }
100 
101  override void OnExit (WeaponEventBase e)
102  {
103  m_dstMagazine = NULL;
104  super.OnExit(e);
105  }
106 
107  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
108  {
109  if (!super.SaveCurrentFSMState(ctx))
110  return false;
111 
112  if (!ctx.Write(m_dstMagazine))
113  {
114  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet_Cartridge.SaveCurrentFSMState: cannot write m_dstMagazine for weapon=" + m_weapon);
115  return false;
116  }
117  return true;
118  }
119 
120  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
121  {
122  if (!super.LoadCurrentFSMState(ctx, version))
123  return false;
124 
125  if (!ctx.Read(m_dstMagazine))
126  {
127  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet_Cartridge.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
128  return false;
129  }
130  return true;
131  }
132 
133 };
134 
136 {
137  Magazine m_dstMagazine;
138 
139  override void OnEntry (WeaponEventBase e)
140  {
141  super.OnEntry(e);
142  if(e)
143  {
144  DayZPlayer p = e.m_player;
145  for(int i = 0; i < m_weapon.GetMuzzleCount(); i++)
146  {
147  m_weapon.CreateRound(i);
148  ejectBulletAndStoreInMagazine(m_weapon, i, m_dstMagazine, p); // MP-safe
149  m_weapon.EffectBulletHide(i);
150  m_weapon.HideBullet(i);
151  }
152  }
153  }
154 
155  override void OnAbort (WeaponEventBase e)
156  {
157  m_dstMagazine = NULL;
158  super.OnAbort(e);
159  }
160 
161  override void OnExit (WeaponEventBase e)
162  {
163  m_dstMagazine = NULL;
164  super.OnExit(e);
165  }
166 
167  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
168  {
169  if (!super.SaveCurrentFSMState(ctx))
170  return false;
171 
172  if (!ctx.Write(m_dstMagazine))
173  {
174  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet_Cartridge.SaveCurrentFSMState: cannot write m_dstMagazine for weapon=" + m_weapon);
175  return false;
176  }
177  return true;
178  }
179 
180  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
181  {
182  if (!super.LoadCurrentFSMState(ctx, version))
183  return false;
184 
185  if (!ctx.Read(m_dstMagazine))
186  {
187  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet_Cartridge.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
188  return false;
189  }
190  return true;
191  }
192 
193 };
194 
195 class WeaponEjectBullet_Cartridge_W4T extends WeaponEjectBulletMultiMuzzle_Cartridge
196 {
197  override bool IsWaitingForActionFinish () { return true; }
198 };
199 
200 
204 class WeaponChargingInnerMag extends WeaponStateBase
205 {
207  int m_actionType;
208 
209  ref WeaponCharging_Start m_start;
210  ref WeaponEjectBullet_Cartridge_W4T m_onBE;
211  ref WeaponEjectCasing_W4T m_onBEFireOut;
212  ref BulletHide_W4T m_hideB;
213  ref WeaponCharging_CK m_onCK;
214  ref WeaponChamberFromInnerMag_W4T m_chamber;
215 
216  void WeaponChargingInnerMag (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
217  {
218  m_action = action;
219  m_actionType = actionType;
220 
221  // setup nested state machine
222  m_start = new WeaponCharging_Start(m_weapon, this, m_action, m_actionType);
223  m_onBE = new WeaponEjectBullet_Cartridge_W4T(m_weapon, this);
224  m_onBEFireOut = new WeaponEjectCasing_W4T(m_weapon, this);
225  m_hideB = new BulletHide_W4T(m_weapon, this);
226  m_onCK = new WeaponCharging_CK(m_weapon, this);
227  m_chamber = new WeaponChamberFromInnerMag_W4T(m_weapon, this);
228 
229  // events
230  WeaponEventBase __be_ = new WeaponEventAnimBulletEject;
231  WeaponEventBase __bh_ = new WeaponEventAnimBulletHide;
232  WeaponEventBase __ck_ = new WeaponEventAnimCocked;
233  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
234 
235  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
236  // transitions
237  m_fsm.AddTransition(new WeaponTransition( m_start, __be_, m_onBEFireOut, NULL, new WeaponGuardCurrentChamberFiredOut(m_weapon)));
238  m_fsm.AddTransition(new WeaponTransition( m_start, __be_, m_onBE, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
239  m_fsm.AddTransition(new WeaponTransition( m_onBE, __bh_, m_hideB));
240  m_fsm.AddTransition(new WeaponTransition( m_onBEFireOut, __bh_, m_hideB));
241 
242  //TODO after inner magazine rework this events must load new bullet
243 
244  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_onBEFireOut, NULL, new GuardAnd(new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon)), new WeaponGuardCurrentChamberFiredOut(m_weapon))));
245  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_onBE, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
246  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_chamber, NULL, new WeaponGuardHasAmmoInnerMagazine(m_weapon))); // some anims do not send BE event
247  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_onCK)); // some anims do not send BE event
248  m_fsm.AddTransition(new WeaponTransition( m_onBE, __ck_, m_chamber, NULL, new WeaponGuardHasAmmoInnerMagazine(m_weapon)));
249  m_fsm.AddTransition(new WeaponTransition( m_onBE, __ck_, m_onCK));
250  m_fsm.AddTransition(new WeaponTransition( m_onBEFireOut, __ck_, m_chamber, NULL, new WeaponGuardHasAmmoInnerMagazine(m_weapon)));
251  m_fsm.AddTransition(new WeaponTransition( m_onBEFireOut, __ck_, m_onCK));
252  m_fsm.AddTransition(new WeaponTransition( m_hideB, __ck_, m_chamber, NULL, new WeaponGuardHasAmmoInnerMagazine(m_weapon)));
253  m_fsm.AddTransition(new WeaponTransition( m_hideB, __ck_, m_onCK));
254 
255  m_fsm.AddTransition(new WeaponTransition( m_start, _fin_, NULL ));
256  m_fsm.AddTransition(new WeaponTransition( m_onBEFireOut, _fin_, NULL));
257  m_fsm.AddTransition(new WeaponTransition( m_onBE, _fin_, NULL));
258  m_fsm.AddTransition(new WeaponTransition( m_hideB, _fin_, NULL));
259  m_fsm.AddTransition(new WeaponTransition( m_onCK, _fin_, NULL));
260  m_fsm.AddTransition(new WeaponTransition( m_chamber, _fin_, NULL));
261 
262  m_fsm.SetInitialState(m_start);
263  }
264 
265  override void OnEntry (WeaponEventBase e)
266  {
267  super.OnEntry(e);
268  }
269  override void OnExit (WeaponEventBase e)
270  {
271  super.OnExit(e);
272  }
273 };
274 
275 
279 class WeaponChargingMultiple extends WeaponStateBase
280 {
282  int m_actionType;
283 
284  ref WeaponCharging_Start m_start;
285  ref WeaponEjectBullet_Cartridge_W4T m_onBE;
286  ref WeaponEjectCasing_W4T m_onBEFireOut;
287  ref BulletHide_W4T m_hideB;
288  ref WeaponCharging_CK m_onCK;
289  ref WeaponChamberFromAttMag_W4T m_chamber;
290 
291  void WeaponChargingMultiple (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
292  {
293  m_action = action;
294  m_actionType = actionType;
295 
296  // setup nested state machine
297  m_start = new WeaponCharging_Start(m_weapon, this, m_action, m_actionType);
298  m_onBE = new WeaponEjectBullet_Cartridge_W4T(m_weapon, this);
299  m_onBEFireOut = new WeaponEjectCasing_W4T(m_weapon, this);
300  m_hideB = new BulletHide_W4T(m_weapon, this);
301  m_onCK = new WeaponCharging_CK(m_weapon, this);
302  m_chamber = new WeaponChamberFromAttMag_W4T(m_weapon, this);
303 
304  // events
305  WeaponEventBase __be_ = new WeaponEventAnimBulletEject;
306  WeaponEventBase __bh_ = new WeaponEventAnimBulletHide;
307  WeaponEventBase __ck_ = new WeaponEventAnimCocked;
308  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
309 
310  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
311  // transitions
312  m_fsm.AddTransition(new WeaponTransition( m_start, __be_, m_onBEFireOut, NULL, new WeaponGuardCurrentChamberFiredOut(m_weapon)));
313  m_fsm.AddTransition(new WeaponTransition( m_start, __be_, m_onBE, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
314  m_fsm.AddTransition(new WeaponTransition( m_onBE, __bh_, m_hideB));
315  m_fsm.AddTransition(new WeaponTransition( m_onBEFireOut, __bh_, m_hideB));
316 
317  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_onBE, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
318  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon))); // some anims do not send BE event
319  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_onCK)); // some anims do not send BE event
320  m_fsm.AddTransition(new WeaponTransition( m_onBE, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
321  m_fsm.AddTransition(new WeaponTransition( m_onBE, __ck_, m_onCK));
322  m_fsm.AddTransition(new WeaponTransition( m_onBEFireOut, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
323  m_fsm.AddTransition(new WeaponTransition( m_onBEFireOut, __ck_, m_onCK));
324  m_fsm.AddTransition(new WeaponTransition( m_hideB, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
325  m_fsm.AddTransition(new WeaponTransition( m_hideB, __ck_, m_onCK));
326 
327  m_fsm.AddTransition(new WeaponTransition( m_start, _fin_, NULL ));
328  m_fsm.AddTransition(new WeaponTransition( m_onBEFireOut, _fin_, NULL));
329  m_fsm.AddTransition(new WeaponTransition( m_onBE, _fin_, NULL));
330  m_fsm.AddTransition(new WeaponTransition( m_hideB, _fin_, NULL));
331  m_fsm.AddTransition(new WeaponTransition( m_onCK, _fin_, NULL));
332  m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
333 
334  m_fsm.SetInitialState(m_start);
335  }
336 
337  override void OnEntry (WeaponEventBase e)
338  {
339  super.OnEntry(e);
340  }
341  override void OnExit (WeaponEventBase e)
342  {
343  super.OnExit(e);
344  }
345 };
346 
350 class WeaponChargingStretch extends WeaponStateBase
351 {
353  int m_actionType;
354 
355  ref WeaponCharging_Start m_start;
356  ref WeaponCharging_CK m_onCK;
357 
358  void WeaponChargingStretch (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
359  {
360  m_action = action;
361  m_actionType = actionType;
362 
363  // setup nested state machine
364  m_start = new WeaponCharging_Start(m_weapon, this, m_action, m_actionType);
365  m_onCK = new WeaponCharging_CK(m_weapon, this);
366 
367  // events
368  WeaponEventBase __ck_ = new WeaponEventAnimCocked;
369  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
370 
371  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
372  // transitions
373  m_fsm.AddTransition(new WeaponTransition( m_start, _fin_, NULL ));
374  m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_onCK)); // some anims do not send BE event
375  m_fsm.AddTransition(new WeaponTransition( m_onCK, _fin_, NULL));
376 
377  m_fsm.SetInitialState(m_start);
378  }
379 };
380 
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
OnAbort
override void OnAbort()
Definition: remotedetonator.c:300
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
m_eject
ref WeaponEjectCasingMultiMuzzle m_eject
Definition: weaponchambering.c:638
m_chamber
ref WeaponChambering_Base m_chamber
Definition: weaponchambering.c:639
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
IsWaitingForActionFinish
class WeaponChambering_Cartridge_InnerMag extends WeaponChambering_Base IsWaitingForActionFinish
Definition: weaponchambering.c:190
m_start
ref WeaponStateBase m_start
Definition: weaponchambering.c:637
WeaponEjectBulletMultiMuzzle_Cartridge
Definition: weaponcharging.c:195
SaveCurrentFSMState
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
Definition: weaponchambering.c:848
Object
Definition: objecttyped.c:1
WeaponCharging
charging of weapon without ammo to be chambered
WeaponTransition
enum FSMTransition WeaponTransition
WeaponEjectAllMuzzles
Definition: weaponchamberfromattmag.c:62
WeaponGuardHasAmmo
void WeaponGuardHasAmmo(Weapon_Base w=NULL)
Definition: guards.c:99
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
OnEntry
HandStateEquipped OnEntry
Definition: weaponchambering.c:208