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