Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weaponchambering.c
Go to the documentation of this file.
1 // load 1 bullet
2 class WeaponChambering_Start extends WeaponStartAction
3 {
4  override void OnEntry (WeaponEventBase e)
5  {
6  super.OnEntry(e);
7  if (e)
8  {
9  m_weapon.SelectionBulletHide();
10  m_weapon.ForceSyncSelectionState();
11  }
12  }
13 
14  override bool IsWaitingForActionFinish()
15  {
16  return true;
17  }
18 };
19 
21 {
22  float m_damage;
23  string m_type;
24  string m_magazineType;
25  Magazine m_srcMagazine;
26 
27  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
28  {
29  if (!super.SaveCurrentFSMState(ctx))
30  return false;
31 
32  if (!ctx.Write(m_damage))
33  {
34  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_damage for weapon=" + m_weapon);
35  return false;
36  }
37  if (!ctx.Write(m_type))
38  {
39  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_type for weapon=" + m_weapon);
40  return false;
41  }
42  if (!ctx.Write(m_magazineType))
43  {
44  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_magazineType for weapon=" + m_weapon);
45  return false;
46  }
47  if (!ctx.Write(m_srcMagazine))
48  {
49  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_srcMagazine for weapon=" + m_weapon);
50  return false;
51  }
52  return true;
53  }
54 
55  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
56  {
57  if (!super.LoadCurrentFSMState(ctx, version))
58  return false;
59 
60  if (!ctx.Read(m_damage))
61  {
62  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_damage for weapon=" + m_weapon);
63  return false;
64  }
65  if (!ctx.Read(m_type))
66  {
67  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_type for weapon=" + m_weapon);
68  return false;
69  }
70  if (!ctx.Read(m_magazineType))
71  {
72  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_magazineType for weapon=" + m_weapon);
73  return false;
74  }
75  if (!ctx.Read(m_srcMagazine))
76  {
77  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
78  return false;
79  }
80  return true;
81  }
82 };
83 
84 
86 {
87  override bool IsWaitingForActionFinish () { return true; }
88  override void OnEntry (WeaponEventBase e)
89  {
90  super.OnEntry(e);
91  if (e)
92  {
93  if (m_srcMagazine)
94  {
95  m_magazineType = m_srcMagazine.GetType();
96 
97  if (m_srcMagazine.ServerAcquireCartridge(m_damage, m_type))
98  {
99  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - cartridge acquired: dmg=" + m_damage + " type=" + m_type); }
100  m_weapon.SelectionBulletShow();
101  m_weapon.ShowBullet(m_weapon.GetCurrentMuzzle());
102  m_weapon.EffectBulletShow( m_weapon.GetCurrentMuzzle(), m_damage, m_type);
103  m_weapon.SetWeaponOpen(false);
104  }
105  else
106  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot take cartridge from magazine");
107  }
108  else
109  {
110  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - no magazine to load from (m_srcMagazine=NULL)");
111  }
112  }
113  }
114 
115  override void OnAbort(WeaponEventBase e)
116  {
117  int mi = m_weapon.GetCurrentMuzzle();
118 
119  string magazineTypeName;
120 
121  if (m_magazineType.Length() > 0)
122  magazineTypeName = m_magazineType;
123  else
124  magazineTypeName = m_weapon.GetChamberAmmoTypeName(mi);
125 
126  if ( GetGame().IsServer() )
127  {
128  if (DayZPlayerUtils.HandleDropCartridge(e.m_player, m_damage, m_type, magazineTypeName))
129  {
130  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - aborting, chambering cartridge dropped to ground"); }
131  }
132  else
133  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot abort removal from wpn (of old mag)");
134  }
135 
136  m_weapon.EffectBulletHide(mi);
137  m_weapon.SelectionBulletHide(); // force hide on abort
138 
139  m_magazineType = string.Empty;
140  m_type = string.Empty;
141  super.OnAbort(e);
142  }
143 
144  override void OnExit (WeaponEventBase e)
145  {
146  int mi = m_weapon.GetCurrentMuzzle();
147  //if ( m_weapon.IsChamberFiredOut(mi) )
148  // m_weapon.EjectCasing(mi);
149  if (m_weapon.PushCartridgeToChamber(mi, m_damage, m_type))
150  {
151  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - loaded chamber"); }
152  }
153  else
154  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot load chamber chamber!"); }
155 
156  m_weapon.SetCharged(true);
157  m_magazineType = string.Empty;
158  m_type = string.Empty;
159  super.OnExit(e);
160  }
161 
162 };
163 
164 class WeaponChambering_Cartridge_ChambToMag extends WeaponChambering_Cartridge
165 {
166  override void OnExit (WeaponEventBase e)
167  {
168  float ammoDamage;
169  string ammoTypeName;
170  int mi = m_weapon.GetCurrentMuzzle();
171  if (m_weapon.IsChamberFull(mi))
172  {
173  m_weapon.PopCartridgeFromChamber(mi, ammoDamage, ammoTypeName);
174  if (m_weapon.PushCartridgeToInternalMagazine(mi, ammoDamage, ammoTypeName))
175  {
176  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - loaded chamber"); }
177  }
178  else
179  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot load chamber chamber!"); }
180  }
181 
182  m_weapon.SetWeaponOpen(false);
183  super.OnExit(e);
184  }
185 }
186 
187 //-----------MAGNUM-----------
188 class WeaponChambering_MultiMuzzleMagnum extends WeaponChambering_Cartridge
189 {
190  override bool IsWaitingForActionFinish () { return false; }
191  override void OnEntry(WeaponEventBase e)
192  {
193  super.OnEntry(e);
194 
195  /*for(int i = 0; i < m_weapon.GetMuzzleCount(); i++ )
196  {
197  if(!m_weapon.IsChamberFull(i))
198  {
199  m_weapon.ShowBullet(i);
200  m_weapon.EffectBulletShow(i, m_damage, m_type);
201  return;
202  }
203  }*/
204  }
205 
206  override void OnExit(WeaponEventBase e)
207  {
208  m_weapon.SelectionBulletHide();
209  int muzzle = m_weapon.GetCurrentMuzzle();
210 
211  if (!m_weapon.IsChamberFull(muzzle))
212  {
213  if (m_weapon.PushCartridgeToChamber(muzzle, m_damage, m_type))
214  {
215  Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(m_weapon.GetAttachmentByType(Magnum_Cylinder));
216 
217  if (cylinder)
218  {
219  string bullet = "bullet";
220  string bullet_nose = "bullet_nose";
221 
222  if (muzzle > 0)
223  {
224  bullet = string.Format("bullet_" + ( muzzle + 1 ));
225  bullet_nose = string.Format("bullet_nose_" + ( muzzle + 1 ));
226  }
227  cylinder.ShowSelection(bullet);
228  cylinder.ShowSelection(bullet_nose);
229  }
230  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_MultiMuzzleMagnum, ok - loaded chamber"); }
231  }
232  else
233  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_MultiMuzzleMagnum, error - cannot load chamber chamber!"); }
234  m_type = string.Empty;
235  return;
236  }
237  else
238  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_MultiMuzzleMagnum, error - cannot load chamber chamber!"); }
239 
240  //super.OnExit(e);
241  }
242 }
243 
244 
245 
246 //----------------------------
247 
248 class WeaponChambering_MultiMuzzle extends WeaponChambering_Cartridge
249 {
250  override bool IsWaitingForActionFinish () { return true; }
251  override void OnEntry(WeaponEventBase e)
252  {
253  super.OnEntry(e);
254 
255  for(int i = 0; i < m_weapon.GetMuzzleCount(); i++ )
256  {
257  if(!m_weapon.IsChamberFull(i))
258  {
259  m_weapon.ShowBullet(i);
260  m_weapon.EffectBulletShow(i, m_damage, m_type);
261  return;
262  }
263  }
264  }
265 
266  override void OnExit (WeaponEventBase e)
267  {
268  for(int i = 0; i < m_weapon.GetMuzzleCount(); i++ )
269  {
270  if(!m_weapon.IsChamberFull(i))
271  {
272  if (m_weapon.PushCartridgeToChamber(i, m_damage, m_type))
273  {
274  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - loaded chamber"); }
275  }
276  else
277  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot load chamber chamber!"); }
278  m_type = string.Empty;
279  return;
280  }
281  }
282 
283  super.OnExit(e);
284  }
285 }
286 
287 class WeaponChambering_MultiMuzzle_W4T extends WeaponChambering_MultiMuzzle
288 {
289  override bool IsWaitingForActionFinish () { return true; }
290 };
291 
292 
293 class WeaponChambering_Cartridge_InnerMag extends WeaponChambering_Base
294 {
295  override void OnEntry (WeaponEventBase e)
296  {
297  super.OnEntry(e);
298  if (e)
299  {
300  if (m_srcMagazine)
301  {
302  m_magazineType = m_srcMagazine.GetType();
303 
304  if (m_srcMagazine.ServerAcquireCartridge(m_damage, m_type))
305  {
306  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, ok - cartridge acquired: dmg=" + m_damage + " type=" + m_type); }
307  }
308  else
309  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, error - cannot take cartridge from magazine");
310  }
311  else
312  {
313  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, error - no magazine to load from (m_srcMagazine=NULL)");
314  }
315 
316  m_weapon.SelectionBulletShow();
317  m_weapon.EffectBulletShow(m_weapon.GetCurrentMuzzle(),m_damage,m_type);
318  }
319  }
320 
321  override void OnAbort(WeaponEventBase e)
322  {
323  int mi = m_weapon.GetCurrentMuzzle();
324  string magazineTypeName;
325 
326  if (m_magazineType.Length() > 0)
327  magazineTypeName = m_magazineType;
328  else
329  magazineTypeName = m_weapon.GetChamberAmmoTypeName(mi);
330 
331  if ( !GetGame().IsMultiplayer() || GetGame().IsServer() )
332  {
333  if (DayZPlayerUtils.HandleDropCartridge(e.m_player, m_damage, m_type, magazineTypeName))
334  {
335  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, ok - aborting, chambering cartridge dropped to ground"); }
336  }
337  else
338  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, error - cannot abort removal from wpn (of old mag)");
339  }
340 
341  m_weapon.SelectionBulletHide(); // force hide on abort
342  m_weapon.EffectBulletHide(m_weapon.GetCurrentMuzzle());
343 
344  m_magazineType = string.Empty;
345  m_type = string.Empty;
346  super.OnAbort(e);
347  }
348 
349  override void OnExit (WeaponEventBase e)
350  {
351  float ammoDamage;
352  string ammoTypeName;
353  int mi = m_weapon.GetCurrentMuzzle();
354  if (!m_weapon.IsInternalMagazineFull(mi))
355  {
356  if (m_weapon.PushCartridgeToInternalMagazine(mi, m_damage, m_type))
357  {
358  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, ok - loaded chamber"); }
359  }
360  else
361  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, error - cannot load chamber chamber!"); }
362  }
363  m_magazineType = string.Empty;
364  super.OnExit(e);
365  }
366 };
367 
368 class WeaponChambering_W4T extends WeaponStateBase
369 {
370  override bool IsWaitingForActionFinish () { return true; }
371 };
372 
373 class WeaponChambering extends WeaponStateBase
374 {
376  int m_actionType;
377  Magazine m_srcMagazine;
379 
383  ref WeaponChambering_W4T m_w4t;
384  ref WeaponCharging_CK m_onCK;
385 
386  void WeaponChambering (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
387  {
388  m_action = action;
389  m_actionType = actionType;
390 
391  // setup nested state machine
392  m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_actionType);
394  m_w4t = new WeaponChambering_W4T(m_weapon, this);
395  m_eject = new WeaponEjectCasing(m_weapon, this);
396  m_onCK = new WeaponCharging_CK(m_weapon, this);
397  // events
398  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
399  WeaponEventAnimBulletInChamber __bc_ = new WeaponEventAnimBulletInChamber;
400  WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
401  WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
402  WeaponEventAnimCocked __ck_ = new WeaponEventAnimCocked;
403 
404  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
405  m_fsm.AddTransition(new WeaponTransition(m_start , __be_, m_eject));
406  m_fsm.AddTransition(new WeaponTransition(m_start , __ck_, m_onCK));
407  m_fsm.AddTransition(new WeaponTransition(m_start , __bs_, m_chamber));
408  m_fsm.AddTransition(new WeaponTransition(m_onCK , __be_, m_eject));
409  m_fsm.AddTransition(new WeaponTransition(m_onCK , __bs_, m_chamber));
410  m_fsm.AddTransition(new WeaponTransition(m_eject , __bs_, m_chamber));
411  m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_w4t));
412  m_fsm.AddTransition(new WeaponTransition(m_w4t , _fin_, null));
413 
414  // Safety exits
415  m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
416  m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
417  m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
418 
419  m_fsm.SetInitialState(m_start);
420  }
421 
422  override void OnEntry (WeaponEventBase e)
423  {
424  if (e != NULL)
425  {
426  m_srcMagazine = e.m_magazine;
427  if (m_srcMagazine != NULL)
428  {
430  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
431 
432  m_srcMagazinePrevLocation = newSrc;
433 
434  // move to LH
436  lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
437  if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
438  {
439  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from inv (inv->LHand)"); }
440  }
441  else
442  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot remove ammo pile from inv");
443 
444  m_chamber.m_srcMagazine = m_srcMagazine;
445  }
446  else
447  {
448  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering m_srcMagazine = NULL"); }
449  }
450  }
451  else
452  {
453  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString()); }
454  }
455 
456  super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
457  }
458 
459  override void OnAbort (WeaponEventBase e)
460  {
461  bool done = false;
462  if (m_srcMagazine)
463  {
464  e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
465 
466  InventoryLocation leftHandIl = new InventoryLocation;
467  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
468  if (leftHandIl.IsValid())
469  {
471  {
472  if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(),leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
473  {
474  if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
475  {
476  if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
477  {
478  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
479  done = true;
480  }
481  }
482  }
483  }
484 
485  if( !done)
486  {
488  e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
489 
490  if(!il || !il.IsValid())
491  {
492  if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
493  {
494  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - no inventory space for ammo pile - dropped to ground - abort"); }
495  }
496  else
497  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
498 
499  }
500  else
501  {
502  if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
503  {
504  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
505  }
506  else
507  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot remove ammo pile from wpn - abort");
508  }
509  }
510  }
511  }
512 
513  super.OnAbort(e);
514  m_srcMagazine = NULL;
515  m_chamber.m_srcMagazine = NULL;
517  }
518 
519  override void OnExit (WeaponEventBase e)
520  {
521  bool done = false;
522  if (m_srcMagazine)
523  {
524  e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
525 
526  InventoryLocation leftHandIl = new InventoryLocation;
527  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
528  if (leftHandIl.IsValid())
529  {
531  {
532  if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
533  {
534  if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
535  {
536  if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
537  {
538  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
539  done = true;
540  }
541  }
542  }
543  }
544 
545  if( !done)
546  {
548  e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
549 
550  if(!il || !il.IsValid())
551  {
552  if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
553  {
554  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - no inventory space for ammo pile - dropped to ground - exit"); }
555  }
556  else
557  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
558 
559  }
560  else
561  {
562  if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
563  {
564  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
565  }
566  else
567  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot remove ammo pile from wpn - exit");
568  }
569  }
570  }
571  }
572 
573  super.OnExit(e);
574  m_srcMagazine = NULL;
575  m_chamber.m_srcMagazine = NULL;
577  }
578 
579  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
580  {
581  if (!super.SaveCurrentFSMState(ctx))
582  return false;
583 
584  if (!ctx.Write(m_srcMagazine))
585  {
586  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
587  return false;
588  }
589 
591  {
592  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
593  return false;
594  }
595  return true;
596  }
597 
598  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
599  {
600  if (!super.LoadCurrentFSMState(ctx, version))
601  return false;
602 
603  if (!ctx.Read(m_srcMagazine))
604  {
605  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
606  return false;
607  }
608 
610  {
611  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
612  return false;
613  }
614  return true;
615  }
616 };
617 
618 //----------------------------------------------
619 //----------------------------------------------
620 //----------------------------------------------
621 class WeaponEndAction extends WeaponStartAction
622 {
623  override bool IsWaitingForActionFinish()
624  {
625  return true;
626  }
627 }
628 
630 {
634  Magazine m_srcMagazine;
636 
641  ref LoopedChambering_Wait4ShowBullet2 m_w4sb2;
642  ref WeaponEndAction m_endLoop;
643  ref BulletShow_W4T m_showB;
644  ref BulletShow2_W4T m_showB2;
645 
646  void ChamberMultiBullet (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int startActionType = -1, int endActionType = -1)
647  {
648  m_action = action;
649  m_startActionType = startActionType;
650  m_endActionType = endActionType;
651 
652  // setup nested state machine
653  m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_startActionType);
655  m_chamber = new WeaponChambering_MultiMuzzle_W4T(m_weapon, this);
656  m_chamber_end = new WeaponChambering_MultiMuzzle_W4T(m_weapon, this);
657  m_w4sb2 = LoopedChambering_Wait4ShowBullet2(m_weapon, this);
658  m_showB = new BulletShow_W4T(m_weapon, this);
659  m_showB2= new BulletShow2_W4T(m_weapon, this);
660 
661  m_endLoop = new WeaponEndAction(m_weapon, this, m_action, m_endActionType); // @NOTE: termination playing action - dummy?
662  // events
663  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
664  WeaponEventContinuousLoadBulletStart __lS_ = new WeaponEventContinuousLoadBulletStart;
665  WeaponEventContinuousLoadBulletEnd __lE_ = new WeaponEventContinuousLoadBulletEnd;
666  WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
667  WeaponEventAnimBulletShow2 _bs2_ = new WeaponEventAnimBulletShow2;
668  WeaponEventAnimBulletHide __bh_ = new WeaponEventAnimBulletHide;
669  WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
670  WeaponEventAnimBulletInChamber __bc_ = new WeaponEventAnimBulletInChamber;
671 
672  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
673  m_fsm.AddTransition(new WeaponTransition(m_start , __be_, m_eject));
674 
675  m_fsm.AddTransition(new WeaponTransition(m_start , __bs_, m_chamber));
676  m_fsm.AddTransition(new WeaponTransition(m_eject , __bs_, m_chamber));
677 
678  m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_w4sb2, NULL, new GuardAnd(new GuardAnd(new WeaponGuardHasAmmoInLoopedState(m_chamber), new WeaponGuardChamberMultiHasRoomBulltet(m_weapon)),new WeaponGuardWeaponManagerWantContinue())));
679  m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_endLoop));
680  m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __bs_, m_chamber));
681 
682  m_fsm.AddTransition(new WeaponTransition(m_w4sb2 , _fin_, NULL));
683  m_fsm.AddTransition(new WeaponTransition(m_chamber , _fin_, NULL));
684  m_fsm.AddTransition(new WeaponTransition(m_endLoop , _fin_, NULL));
685 
686  // Safety exits
687  m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
688  m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
689 
690  m_fsm.SetInitialState(m_start);
691  }
692 
693  override void OnEntry (WeaponEventBase e)
694  {
695  if (e != NULL)
696  {
697  m_srcMagazine = e.m_magazine;
698  if (m_srcMagazine != NULL)
699  {
701  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
702 
703  m_srcMagazinePrevLocation = newSrc;
704 
705  // move to LH
707  lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
708  if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
709  {
710  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from inv (inv->LHand)"); }
711  }
712  else
713  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot remove ammo pile from inv");
714 
715  m_chamber.m_srcMagazine = m_srcMagazine;
716  }
717  else
718  {
719  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet m_srcMagazine = NULL"); }
720  }
721  }
722  else
723  {
724  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString()); }
725  }
726 
727  super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
728  }
729  override void OnExit (WeaponEventBase e)
730  {
731  bool done = false;
732  if (m_srcMagazine)
733  {
734  e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
735 
736  InventoryLocation leftHandIl = new InventoryLocation;
737  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
738  if (leftHandIl.IsValid())
739  {
741  {
742  if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
743  {
744  if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
745  {
746  if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
747  {
748  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
749  done = true;
750  }
751  }
752  }
753  }
754 
755  if( !done)
756  {
758  e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
759 
760  if(!il || !il.IsValid())
761  {
762  if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
763  {
764  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - no inventory space for ammo pile - dropped to ground - exit"); }
765  }
766  else
767  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
768 
769  }
770  else
771  {
772  if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
773  {
774  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
775  }
776  else
777  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot remove ammo pile from wpn - exit");
778  }
779  }
780  }
781  }
782 
783  super.OnExit(e);
784  m_srcMagazine = NULL;
785  m_chamber.m_srcMagazine = NULL;
787  }
788  override void OnAbort (WeaponEventBase e)
789  {
790  bool done = false;
791  if (m_srcMagazine)
792  {
793  e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
794 
795  InventoryLocation leftHandIl = new InventoryLocation;
796  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
797  if (leftHandIl.IsValid())
798  {
800  {
801  if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
802  {
803  if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
804  {
805  if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
806  {
807  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
808  done = true;
809  }
810  }
811  }
812  }
813 
814  if( !done)
815  {
817  e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
818 
819  if(!il || !il.IsValid())
820  {
821  if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
822  {
823  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - no inventory space for ammo pile - dropped to ground - abort"); }
824  }
825  else
826  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
827 
828  }
829  else
830  {
831  if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
832  {
833  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
834  }
835  else
836  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot remove ammo pile from wpn - abort");
837  }
838  }
839  }
840  }
841 
842  super.OnAbort(e);
843  m_srcMagazine = NULL;
844  m_chamber.m_srcMagazine = NULL;
846  }
847 
849  {
850  if (!super.SaveCurrentFSMState(ctx))
851  return false;
852 
853  if (!ctx.Write(m_srcMagazine))
854  {
855  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
856  return false;
857  }
858 
860  {
861  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
862  return false;
863  }
864  return true;
865  }
866 
867  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
868  {
869  if (!super.LoadCurrentFSMState(ctx, version))
870  return false;
871 
872  if (!ctx.Read(m_srcMagazine))
873  {
874  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
875  return false;
876  }
877 
879  {
880  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
881  return false;
882  }
883  return true;
884  }
885 };
886 //------------------------------------------------------
887 //------------------ROTATE------------------------------
888 //------------------------------------------------------
889 class WeaponCylinderRotate extends WeaponStateBase
890 {
891  bool FindNextFreeMuzzle(int currentMuzzle, out int nextMuzzle)
892  {
893  nextMuzzle = currentMuzzle;
894  int nMuzzles = m_weapon.GetMuzzleCount();
895 
896  for (int i = 0; i < nMuzzles; ++i)
897  {
898  --nextMuzzle;
899  nextMuzzle = Math.WrapInt(nextMuzzle, 0, nMuzzles);
900  if (m_weapon.IsChamberEmpty(nextMuzzle))
901  return true;
902  }
903 
904  return false;
905  }
906 
907  override void OnEntry(WeaponEventBase e)
908  {
909  int nextMuzzle;
910  if (FindNextFreeMuzzle(m_weapon.GetCurrentMuzzle(), nextMuzzle))
911  {
912  Magnum_Base magnum = Magnum_Base.Cast(m_weapon);
913  magnum.SetCylinderRotationAnimationPhase(magnum.GetCylinderRotation(nextMuzzle));
914  m_weapon.SetCurrentMuzzle(nextMuzzle);
915  }
916  else
917  {
918  Print("WTF");
919  }
920 
921  super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
922  }
923 
924 };
925 
926 
927 //------------------------------------------------------
928 //------------------MAGNUM------------------------------
929 //------------------------------------------------------
930 class WeaponMagnumChambering extends WeaponStateBase
931 {
933  int m_startActionType;
934  int m_endActionType;
935  Magazine m_srcMagazine;
937 
940  ref WeaponCylinderRotate m_rotate;
942  ref LoopedChambering_Wait4ShowBullet2 m_w4sb2;
944  ref BulletHide_W4T m_hideB;
945 
946  void WeaponMagnumChambering(Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int startActionType = -1, int endActionType = -1)
947  {
948  m_action = action;
949  m_startActionType = startActionType;
950  m_endActionType = endActionType;
951 
952  // setup nested state machine
953  m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_startActionType);
955  m_rotate = new WeaponCylinderRotate(m_weapon, this);
956  m_chamber = new WeaponChambering_MultiMuzzleMagnum(m_weapon, this);
957  m_w4sb2 = LoopedChambering_Wait4ShowBullet2(m_weapon, this);
958  m_hideB = new BulletHide_W4T(m_weapon, this);
959  m_endLoop = new LoopedChambering_EndLoop(m_weapon, this, m_action, m_endActionType); // @NOTE: termination playing action - dummy?
960  // events
961  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
962  WeaponEventContinuousLoadBulletStart __lS_ = new WeaponEventContinuousLoadBulletStart;
963  WeaponEventContinuousLoadBulletEnd __lE_ = new WeaponEventContinuousLoadBulletEnd;
964  WeaponEventCylinderRotate __cr_ = new WeaponEventCylinderRotate;
965  WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
966  WeaponEventAnimBulletHide __bh_ = new WeaponEventAnimBulletHide;
967  WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
968  WeaponEventAnimBulletInMagazine __bM_ = new WeaponEventAnimBulletInMagazine;
969  WeaponEventAnimBulletShow2 _bs2_ = new WeaponEventAnimBulletShow2;
970 
971  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
972  m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_eject));
973  m_fsm.AddTransition(new WeaponTransition(m_start, __cr_, m_rotate));
974 
975  m_fsm.AddTransition(new WeaponTransition(m_eject, __cr_, m_rotate));
976  m_fsm.AddTransition(new WeaponTransition(m_rotate, __be_, m_eject));
977 
978  m_fsm.AddTransition(new WeaponTransition(m_eject, __bs_, m_chamber));
979  m_fsm.AddTransition(new WeaponTransition(m_rotate, __bs_, m_chamber));
980 
981  m_fsm.AddTransition(new WeaponTransition(m_chamber, __bM_, m_w4sb2, null, new GuardAnd(new GuardAnd(new WeaponGuardHasAmmoInLoopedState(m_chamber), new WeaponGuardChamberMultiHasRoomBulltet(m_weapon)),new WeaponGuardWeaponManagerWantContinue())));
982  m_fsm.AddTransition(new WeaponTransition(m_chamber, __bM_, m_endLoop));
983  //m_fsm.AddTransition(new WeaponTransition(m_rotate, __bh_, m_chamber));
984  //m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __bh_, m_hideB));
985  m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __cr_, m_rotate));
986 
987  m_fsm.AddTransition(new WeaponTransition(m_endLoop, _fin_, null));
988 
989  // Safety exits
990  m_fsm.AddTransition(new WeaponTransition(m_w4sb2, _fin_, null));
991  m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
992  m_fsm.AddTransition(new WeaponTransition(m_rotate, _fin_, null));
993  m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
994  m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
995 
996  m_fsm.SetInitialState(m_start);
997  }
998 
999  override void OnEntry(WeaponEventBase e)
1000  {
1001  if (e != NULL)
1002  {
1003 
1004  m_srcMagazine = e.m_magazine;
1005  if (m_srcMagazine != NULL)
1006  {
1007  InventoryLocation newSrc = new InventoryLocation;
1008  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
1009 
1010  m_srcMagazinePrevLocation = newSrc;
1011 
1012  // move to LH
1014  lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
1015  if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
1016  {
1017  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from inv (inv->LHand)"); }
1018  }
1019  else
1020  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, error - cannot remove ammo pile from inv");
1021 
1022  m_chamber.m_srcMagazine = m_srcMagazine;
1023  }
1024  else
1025  {
1026  Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering m_srcMagazine = NULL");
1027  }
1028  }
1029  else
1030  {
1031  Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString());
1032  }
1033 
1034  super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
1035  }
1036 
1037  override void OnExit(WeaponEventBase e)
1038  {
1039  bool done = false;
1040  if (m_srcMagazine)
1041  {
1042  e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
1043 
1044  InventoryLocation leftHandIl = new InventoryLocation;
1045  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
1046  if (leftHandIl.IsValid())
1047  {
1049  {
1050  if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
1051  {
1052  if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
1053  {
1054  if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
1055  {
1056  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
1057  done = true;
1058  }
1059  }
1060  }
1061  }
1062 
1063  if ( !done)
1064  {
1066  e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
1067 
1068  if (!il || !il.IsValid())
1069  {
1070  if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
1071  {
1072  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - no inventory space for ammo pile - dropped to ground - exit"); }
1073  }
1074  else
1075  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
1076 
1077  }
1078  else
1079  {
1080  if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
1081  {
1082  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
1083  }
1084  else
1085  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, error - cannot remove ammo pile from wpn - exit");
1086  }
1087  }
1088  }
1089  }
1090 
1091  super.OnExit(e);
1092  m_srcMagazine = NULL;
1093  m_chamber.m_srcMagazine = NULL;
1095  }
1096 
1097  override void OnAbort(WeaponEventBase e)
1098  {
1099  bool done = false;
1100  if (m_srcMagazine)
1101  {
1102  e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
1103 
1104  InventoryLocation leftHandIl = new InventoryLocation;
1105  m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
1106  if (leftHandIl.IsValid())
1107  {
1109  {
1110  if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
1111  {
1112  if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
1113  {
1114  if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
1115  {
1116  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
1117  done = true;
1118  }
1119  }
1120  }
1121  }
1122 
1123  if ( !done)
1124  {
1126  e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
1127 
1128  if (!il || !il.IsValid())
1129  {
1130  if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
1131  {
1132  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - no inventory space for ammo pile - dropped to ground - abort"); }
1133  }
1134  else
1135  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
1136 
1137  }
1138  else
1139  {
1140  if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
1141  {
1142  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
1143  }
1144  else
1145  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot remove ammo pile from wpn - abort");
1146  }
1147  }
1148  }
1149  }
1150 
1151  super.OnAbort(e);
1152  m_srcMagazine = NULL;
1153  m_chamber.m_srcMagazine = NULL;
1155  }
1156 
1157  override bool SaveCurrentFSMState(ParamsWriteContext ctx)
1158  {
1159  if (!super.SaveCurrentFSMState(ctx))
1160  return false;
1161 
1162  if (!ctx.Write(m_srcMagazine))
1163  {
1164  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
1165  return false;
1166  }
1167 
1169  {
1170  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
1171  return false;
1172  }
1173 
1174  return true;
1175  }
1176 
1177  override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
1178  {
1179  if (!super.LoadCurrentFSMState(ctx, version))
1180  return false;
1181 
1182  if (!ctx.Read(m_srcMagazine))
1183  {
1184  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
1185  return false;
1186  }
1187 
1189  {
1190  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
1191  return false;
1192  }
1193  return true;
1194  }
1195 };
LoadCurrentFSMState
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
Definition: weaponchambering.c:867
GetGame
proto native CGame GetGame()
WeaponChambering_Cartridge
Definition: weaponchambering.c:164
m_chamber_end
ref WeaponChambering_Base m_chamber_end
Definition: weaponchambering.c:640
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
Magnum_Base
Definition: magnum.c:362
m_srcMagazine
Magazine m_srcMagazine
Definition: weaponchambering.c:634
LogManager
Definition: debug.c:734
OnEntry
override void OnEntry(WeaponEventBase e)
Definition: weaponchambering.c:191
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
DayZPlayerUtils
private void DayZPlayerUtils()
cannot be instantiated
Definition: dayzplayerutils.c:461
OptionalLocationReadFromContext
bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
Definition: inventorylocation.c:605
wpnDebugPrint
void wpnDebugPrint(string s)
Definition: debug.c:9
m_eject
ref WeaponEjectCasingMultiMuzzle m_eject
Definition: weaponchambering.c:638
m_startActionType
int m_startActionType
Definition: weaponchambering.c:632
m_w4sb2
ref LoopedChambering_Wait4ShowBullet2 m_w4sb2
Definition: weaponchambering.c:641
Print
proto void Print(void var)
Prints content of variable to console/log.
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
OnExit
override void OnExit(WeaponEventBase e)
Definition: weaponchambering.c:2
ChamberMultiBullet
void ChamberMultiBullet(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int startActionType=-1, int endActionType=-1)
Definition: weaponchambering.c:646
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
WeaponChambering_Base
Definition: weaponchambering.c:85
WeaponActions
WeaponActions
actions
Definition: human.c:808
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
OptionalLocationWriteToContext
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
Definition: inventorylocation.c:583
IsWaitingForActionFinish
class WeaponChambering_Cartridge_InnerMag extends WeaponChambering_Base IsWaitingForActionFinish
Definition: weaponchambering.c:190
vector
Definition: enconvert.c:105
m_start
ref WeaponStateBase m_start
Definition: weaponchambering.c:637
SaveCurrentFSMState
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
Definition: weaponchambering.c:848
Object
Definition: objecttyped.c:1
m_showB
ref BulletShow_W4T m_showB
Definition: weaponchambering.c:643
WeaponTransition
enum FSMTransition WeaponTransition
WeaponEjectAllMuzzles
Definition: weaponchamberfromattmag.c:62
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
m_endActionType
int m_endActionType
Definition: weaponchambering.c:633
m_endLoop
ref WeaponEndAction m_endLoop
Definition: weaponchambering.c:642
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
WeaponEjectCasingMultiMuzzle
Definition: weaponejectcasingandchamberfromattmag.c:51
WeaponFSM
weapon finite state machine
m_showB2
ref BulletShow2_W4T m_showB2
Definition: weaponchambering.c:644
Math
Definition: enmath.c:6
OnAbort
override void OnAbort(WeaponEventBase e)
Definition: weaponchambering.c:788
WeaponEjectCasing
Definition: weaponejectcasingandchamberfromattmag.c:126
m_srcMagazinePrevLocation
ref InventoryLocation m_srcMagazinePrevLocation
source of the cartridge
Definition: weaponchambering.c:635
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78
WeaponManager
Definition: weaponmanager.c:1