Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
weaponchamberinglooped.c
Go to the documentation of this file.
1// load x bullets
2class LoopedChambering_EndLoop extends WeaponStartAction
3{
4 override bool IsWaitingForActionFinish () { return true; }
5};
6
7class LoopedChambering_Wait4ShowBullet2 extends WeaponStateBase
8{
9 override bool IsWaitingForActionFinish () { return false; }
10};
11
12class LoopedChambering extends WeaponStateBase
13{
14 WeaponActions m_action;
17 Magazine m_srcMagazine;
19
23 ref LoopedChambering_Wait4ShowBullet2 m_w4sb2;
25 ref BulletHide_W4T m_hideB;
26
27 void LoopedChambering (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int startActionType = -1, int endActionType = -1)
28 {
29 m_action = action;
30 m_startActionType = startActionType;
31 m_endActionType = endActionType;
32
33 // setup nested state machine
34 m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_startActionType);
36 m_chamber = new WeaponChambering_Cartridge_ChambToMag(m_weapon, this);
37 m_w4sb2 = new LoopedChambering_Wait4ShowBullet2(m_weapon, this);
38 m_hideB = new BulletHide_W4T(m_weapon, this);
39 m_endLoop = new LoopedChambering_EndLoop(m_weapon, this, m_action, m_endActionType); // @NOTE: termination playing action - dummy?
40 // events
41 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
42 WeaponEventContinuousLoadBulletStart __lS_ = new WeaponEventContinuousLoadBulletStart;
43 WeaponEventContinuousLoadBulletEnd __lE_ = new WeaponEventContinuousLoadBulletEnd;
44 WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
45 WeaponEventAnimBulletHide __bh_ = new WeaponEventAnimBulletHide;
46 WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
47 WeaponEventAnimBulletInMagazine __bM_ = new WeaponEventAnimBulletInMagazine;
48 WeaponEventAnimBulletShow2 _bs2_ = new WeaponEventAnimBulletShow2;
49
50 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
51 m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_eject));
52 m_fsm.AddTransition(new WeaponTransition(m_start, __bs_, m_chamber));
53 m_fsm.AddTransition(new WeaponTransition(m_eject, __bs_, m_chamber));
54
55
56 m_fsm.AddTransition(new WeaponTransition(m_chamber, __bM_, m_w4sb2, NULL, new GuardAnd(new GuardAnd(new WeaponGuardHasAmmoInLoopedState(m_chamber), new WeaponGuardInternalMagazineHasRoomForBullet(m_weapon)),new WeaponGuardWeaponManagerWantContinue())));
57 m_fsm.AddTransition(new WeaponTransition(m_chamber, __bM_, m_endLoop));
58 m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __bh_, m_hideB));
59 m_fsm.AddTransition(new WeaponTransition(m_hideB, __bs_, m_chamber));
60
61 m_fsm.AddTransition(new WeaponTransition(m_endLoop, _fin_, NULL));
62
63 // Safety exits
64 m_fsm.AddTransition(new WeaponTransition(m_hideB, _fin_, null));
65 m_fsm.AddTransition(new WeaponTransition(m_w4sb2, _fin_, null));
66 m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
67 m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
68 m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
69
70 m_fsm.SetInitialState(m_start);
71 }
72
73 override void OnEntry (WeaponEventBase e)
74 {
75 if (e != NULL)
76 {
77
78 m_srcMagazine = e.m_magazine;
79 if (m_srcMagazine != NULL)
80 {
81 m_weapon.SelectionBulletHide();
83 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
84
86
87 // move to LH
89 lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
90 if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
91 {
92 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from inv (inv->LHand)"); }
93 }
94 else
95 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot remove ammo pile from inv");
96
97 m_chamber.m_srcMagazine = m_srcMagazine;
98 }
99 else
100 {
101 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering m_srcMagazine = NULL");
102 }
103 }
104 else
105 {
106 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString());
107 }
108
109 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
110 }
111 override void OnExit (WeaponEventBase e)
112 {
113 bool done = false;
114 if (m_srcMagazine)
115 {
116 e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
117
118 InventoryLocation leftHandIl = new InventoryLocation;
119 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
120 if (leftHandIl.IsValid())
121 {
123 {
124 if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
125 {
127 {
129 {
130 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
131 done = true;
132 }
133 }
134 }
135 }
136
137 if( !done)
138 {
140 e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
141
142 if(!il || !il.IsValid())
143 {
144 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
145 {
146 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - no inventory space for ammo pile - dropped to ground - exit"); }
147 }
148 else
149 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
150
151 }
152 else
153 {
154 if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
155 {
156 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
157 }
158 else
159 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot remove ammo pile from wpn - exit");
160 }
161 }
162 }
163 }
164
165 super.OnExit(e);
166 m_srcMagazine = NULL;
167 m_chamber.m_srcMagazine = NULL;
169 }
170 override void OnAbort (WeaponEventBase e)
171 {
172 bool done = false;
173 if (m_srcMagazine)
174 {
175 e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
176
177 InventoryLocation leftHandIl = new InventoryLocation;
178 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
179 if (leftHandIl.IsValid())
180 {
182 {
183 if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
184 {
186 {
188 {
189 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
190 done = true;
191 }
192 }
193 }
194 }
195
196 if( !done)
197 {
199 e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
200
201 if(!il || !il.IsValid())
202 {
203 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
204 {
205 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - no inventory space for ammo pile - dropped to ground - abort"); }
206 }
207 else
208 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
209
210 }
211 else
212 {
213 if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
214 {
215 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
216 }
217 else
218 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot remove ammo pile from wpn - abort");
219 }
220 }
221 }
222 }
223
224 super.OnAbort(e);
225 m_srcMagazine = NULL;
226 m_chamber.m_srcMagazine = NULL;
228 }
229
230 override bool SaveCurrentFSMState (ParamsWriteContext ctx)
231 {
232 if (!super.SaveCurrentFSMState(ctx))
233 return false;
234
235 if (!ctx.Write(m_srcMagazine))
236 {
237 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
238 return false;
239 }
240
242 {
243 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
244 return false;
245 }
246
247 return true;
248 }
249
250 override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
251 {
252 if (!super.LoadCurrentFSMState(ctx, version))
253 return false;
254
255 if (!ctx.Read(m_srcMagazine))
256 {
257 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
258 return false;
259 }
260
262 {
263 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
264 return false;
265 }
266 return true;
267 }
268};
269
270class LoopedChamberingEjectLast extends WeaponStateBase
271{
272 WeaponActions m_action;
274 int m_endActionType;
275 Magazine m_srcMagazine;
277
280 ref LoopedChambering_Wait4ShowBullet2 m_w4sb2;
282 ref BulletHide_W4T m_hideB;
283 ref WeaponChamberFromInnerMag_W4T m_chamberFromInnerMag;
284 ref WeaponChambering_Base m_mag;
285
286 void LoopedChamberingEjectLast (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int startActionType = -1, int endActionType = -1)
287 {
288 m_action = action;
289 m_startActionType = startActionType;
290 m_endActionType = endActionType;
291
292 // setup nested state machine
293 m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_startActionType);
295 m_mag = new WeaponChambering_InternalMagazine_OnExit(m_weapon, this);
296 m_w4sb2 = new LoopedChambering_Wait4ShowBullet2(m_weapon, this);
297 m_hideB = new BulletHide_W4T(m_weapon, this);
298 m_chamberFromInnerMag = new WeaponChamberFromInnerMag_W4T(m_weapon, this);
299 m_endLoop = new LoopedChambering_EndLoop(m_weapon, this, m_action, m_endActionType); // @NOTE: termination playing action - dummy?
300 // events
301 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
302 WeaponEventContinuousLoadBulletStart __lS_ = new WeaponEventContinuousLoadBulletStart;
303 WeaponEventContinuousLoadBulletEnd __lE_ = new WeaponEventContinuousLoadBulletEnd;
304 WeaponEventAnimCocked __wc_ = new WeaponEventAnimCocked;
305 WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
306 WeaponEventAnimBulletHide __bh_ = new WeaponEventAnimBulletHide;
307 WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
308 WeaponEventAnimBulletInMagazine __bM_ = new WeaponEventAnimBulletInMagazine;
309 WeaponEventAnimBulletShow2 _bs2_ = new WeaponEventAnimBulletShow2;
310
311 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
312 m_fsm.AddTransition(new WeaponTransition(m_start , __bs_, m_mag));
313
314
315 m_fsm.AddTransition(new WeaponTransition(m_mag, __bM_, m_w4sb2, NULL, new GuardAnd(new GuardAnd(new WeaponGuardHasAmmoInLoopedState(m_mag), new WeaponGuardInternalMagazineHasRoomForBullet(m_weapon)),new WeaponGuardWeaponManagerWantContinue())));
316 m_fsm.AddTransition(new WeaponTransition(m_mag, __bM_, m_endLoop));
317 m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __bh_, m_hideB));
318 m_fsm.AddTransition(new WeaponTransition(m_hideB, __bs_, m_mag));
319
320
321 m_fsm.AddTransition(new WeaponTransition(m_endLoop, _fin_, NULL));
322
323 m_fsm.AddTransition(new WeaponTransition(m_hideB, __be_, m_eject));
324 m_fsm.AddTransition(new WeaponTransition(m_endLoop, __be_, m_eject));
325 m_fsm.AddTransition(new WeaponTransition(m_eject, __wc_, m_chamberFromInnerMag));
326 m_fsm.AddTransition(new WeaponTransition(m_chamberFromInnerMag, _fin_, NULL));
327
328 // Safety exits
329 m_fsm.AddTransition(new WeaponTransition(m_hideB, _fin_, null));
330 m_fsm.AddTransition(new WeaponTransition(m_w4sb2, _fin_, null));
331 m_fsm.AddTransition(new WeaponTransition(m_mag, _fin_, null));
332 m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
333 m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
334
335 m_fsm.SetInitialState(m_start);
336 }
337
338 override void OnEntry (WeaponEventBase e)
339 {
340 if (e != NULL)
341 {
342 m_srcMagazine = e.m_magazine;
343 if (m_srcMagazine != NULL)
344 {
346 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
347
349
350 // move to LH
352 lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
353 if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
354 {
355 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from inv (inv->LHand)"); }
356 }
357 else
358 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from inv");
359
360 m_mag.m_srcMagazine = m_srcMagazine;
361 }
362 else
363 {
364 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast m_srcMagazine = NULL");
365 }
366 }
367 else
368 {
369 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString());
370 }
371
372 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
373 }
374 override void OnExit (WeaponEventBase e)
375 {
376 bool done = false;
377 if (m_srcMagazine)
378 {
379 e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
380
381 InventoryLocation leftHandIl = new InventoryLocation;
382 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
383 if (leftHandIl.IsValid())
384 {
386 {
387 if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
388 {
390 {
392 {
393 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
394 done = true;
395 }
396 }
397 }
398 }
399
400 if (!done)
401 {
403 e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
404
405 if (!il || !il.IsValid())
406 {
407 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
408 {
409 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - no inventory space for ammo pile - dropped to ground - exit"); }
410 }
411 else
412 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
413
414 }
415 else
416 {
417 if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
418 {
419 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
420 }
421 else
422 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from wpn - exit");
423 }
424 }
425 }
426 }
427
428 super.OnExit(e);
429 m_srcMagazine = NULL;
430 m_mag.m_srcMagazine = NULL;
432 }
433 override void OnAbort (WeaponEventBase e)
434 {
435 bool done = false;
436 if (m_srcMagazine)
437 {
438 e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
439
440 InventoryLocation leftHandIl = new InventoryLocation;
441 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
442 if (leftHandIl.IsValid())
443 {
445 {
446 if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
447 {
449 {
451 {
452 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
453 done = true;
454 }
455 }
456 }
457 }
458
459 if (!done)
460 {
462 e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
463
464 if (!il || !il.IsValid())
465 {
466 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
467 {
468 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - no inventory space for ammo pile - dropped to ground - abort"); }
469 }
470 else
471 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
472
473 }
474 else
475 {
476 if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
477 {
478 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
479 }
480 else
481 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from wpn - abort");
482 }
483 }
484 }
485 }
486
487 super.OnAbort(e);
488 m_srcMagazine = NULL;
489 m_mag.m_srcMagazine = NULL;
491 }
492
493 override bool SaveCurrentFSMState (ParamsWriteContext ctx)
494 {
495 if (!super.SaveCurrentFSMState(ctx))
496 return false;
497
498 if (!ctx.Write(m_srcMagazine))
499 {
500 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
501 return false;
502 }
503
505 {
506 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
507 return false;
508 }
509 return true;
510 }
511
512 override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
513 {
514 if (!super.LoadCurrentFSMState(ctx, version))
515 return false;
516
517 if (!ctx.Read(m_srcMagazine))
518 {
519 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
520 return false;
521 }
522
524 {
525 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
526 return false;
527 }
528 return true;
529 }
530};
531
532class LoopedChamberingCombineChamberInternalMagazine extends WeaponStateBase
533{
534 WeaponActions m_action;
536 int m_endActionType;
537 Magazine m_srcMagazine;
539
541
542 ref LoopedChambering_Wait4ShowBullet2 m_w4sb2;
544 ref BulletHide_W4T m_hideB;
545 ref WeaponChamberFromInnerMag_W4T m_chamberFromInnerMag;
546
548 ref WeaponChambering_Base m_mag;
549
550
551 void LoopedChamberingCombineChamberInternalMagazine (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int startActionType = -1, int endActionType = -1)
552 {
553 m_action = action;
554 m_startActionType = startActionType;
555 m_endActionType = endActionType;
556
557 // setup nested state machine
558 m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_startActionType);
559 m_chamber = new WeaponChambering_Cartridge(m_weapon, this);
560 m_mag = new WeaponChambering_InternalMagazine_OnExit(m_weapon, this);
561 m_w4sb2 = new LoopedChambering_Wait4ShowBullet2(m_weapon, this);
562 m_hideB = new BulletHide_W4T(m_weapon, this);
563 m_chamberFromInnerMag = new WeaponChamberFromInnerMag_W4T(m_weapon, this);
564 m_endLoop = new LoopedChambering_EndLoop(m_weapon, this, m_action, m_endActionType); // @NOTE: termination playing action - dummy?
565 // events
566 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
567 WeaponEventContinuousLoadBulletStart __lS_ = new WeaponEventContinuousLoadBulletStart;
568 WeaponEventContinuousLoadBulletEnd __lE_ = new WeaponEventContinuousLoadBulletEnd;
569 WeaponEventAnimCocked __wc_ = new WeaponEventAnimCocked;
570 WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
571 WeaponEventAnimBulletHide __bh_ = new WeaponEventAnimBulletHide;
572 WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
573 WeaponEventAnimBulletInMagazine __bM_ = new WeaponEventAnimBulletInMagazine;
574 WeaponEventAnimBulletInChamber __bc_ = new WeaponEventAnimBulletInChamber;
575 WeaponEventAnimBulletShow2 _bs2_ = new WeaponEventAnimBulletShow2;
576
577 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
578 m_fsm.AddTransition(new WeaponTransition(m_start , __bs_, m_chamber));
579
580
581 m_fsm.AddTransition(new WeaponTransition(m_mag, __bM_, m_w4sb2, NULL, new GuardAnd(new GuardAnd(new WeaponGuardHasAmmoInLoopedState(m_mag), new WeaponGuardInternalMagazineHasRoomForBullet(m_weapon)),new WeaponGuardWeaponManagerWantContinue())));
582 m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_w4sb2, NULL, new GuardAnd(new GuardAnd(new WeaponGuardHasAmmoInLoopedState(m_chamber), new WeaponGuardInternalMagazineHasRoomForBullet(m_weapon)),new WeaponGuardWeaponManagerWantContinue())));
583 m_fsm.AddTransition(new WeaponTransition(m_mag, __bM_, m_endLoop));
584 m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_endLoop));
585
586 m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __bh_, m_hideB));
587 m_fsm.AddTransition(new WeaponTransition(m_hideB, __bs_, m_mag));
588
589
590 m_fsm.AddTransition(new WeaponTransition(m_endLoop, _fin_, NULL));
591
592 //m_fsm.AddTransition(new WeaponTransition(m_chamberFromInnerMag, _fin_, NULL));
593
594 // Safety exits
595 m_fsm.AddTransition(new WeaponTransition(m_hideB, _fin_, null));
596 m_fsm.AddTransition(new WeaponTransition(m_w4sb2, _fin_, null));
597 m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
598 m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
599
600 m_fsm.SetInitialState(m_start);
601 }
602
603 override void OnEntry (WeaponEventBase e)
604 {
605 if (e != NULL)
606 {
607 m_srcMagazine = e.m_magazine;
608 if (m_srcMagazine != NULL)
609 {
611 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
612
614
615 // move to LH
617 lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
618 if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
619 {
620 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from inv (inv->LHand)"); }
621 }
622 else
623 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from inv");
624
625 m_chamber.m_srcMagazine = m_srcMagazine;
626 m_mag.m_srcMagazine = m_srcMagazine;
627 }
628 else
629 {
630 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast m_srcMagazine = NULL");
631 }
632 }
633 else
634 {
635 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString());
636 }
637
638 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
639 }
640 override void OnExit (WeaponEventBase e)
641 {
642 bool done = false;
643 if (m_srcMagazine)
644 {
645 e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
646
647 InventoryLocation leftHandIl = new InventoryLocation;
648 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
649 if (leftHandIl.IsValid())
650 {
652 {
653 if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
654 {
656 {
658 {
659 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
660 done = true;
661 }
662 }
663 }
664 }
665
666 if (!done)
667 {
669 e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
670
671 if (!il || !il.IsValid())
672 {
673 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
674 {
675 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - no inventory space for ammo pile - dropped to ground - exit"); }
676 }
677 else
678 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
679
680 }
681 else
682 {
683 if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
684 {
685 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
686 }
687 else
688 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from wpn - exit");
689 }
690 }
691 }
692 }
693
694 super.OnExit(e);
695 m_srcMagazine = NULL;
696 m_chamber.m_srcMagazine = NULL;
697 m_mag.m_srcMagazine = NULL;
699 }
700 override void OnAbort (WeaponEventBase e)
701 {
702 bool done = false;
703 if (m_srcMagazine)
704 {
705 e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
706
707 InventoryLocation leftHandIl = new InventoryLocation;
708 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
709 if (leftHandIl.IsValid())
710 {
712 {
713 if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
714 {
716 {
718 {
719 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
720 done = true;
721 }
722 }
723 }
724 }
725
726 if (!done)
727 {
729 e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
730
731 if (!il || !il.IsValid())
732 {
733 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
734 {
735 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - no inventory space for ammo pile - dropped to ground - abort"); }
736 }
737 else
738 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
739
740 }
741 else
742 {
743 if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
744 {
745 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
746 }
747 else
748 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from wpn - abort");
749 }
750 }
751 }
752 }
753
754 super.OnAbort(e);
755 m_srcMagazine = NULL;
756 m_chamber.m_srcMagazine = NULL;
757 m_mag.m_srcMagazine = NULL;
759 }
760
761 override bool SaveCurrentFSMState (ParamsWriteContext ctx)
762 {
763 if (!super.SaveCurrentFSMState(ctx))
764 return false;
765
766 if (!ctx.Write(m_srcMagazine))
767 {
768 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
769 return false;
770 }
771
773 {
774 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
775 return false;
776 }
777 return true;
778 }
779
780 override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
781 {
782 if (!super.LoadCurrentFSMState(ctx, version))
783 return false;
784
785 if (!ctx.Read(m_srcMagazine))
786 {
787 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
788 return false;
789 }
790
792 {
793 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
794 return false;
795 }
796 return true;
797 }
798};
void wpnDebugPrint(string s)
Definition debug.c:9
script counterpart to engine's class Inventory
Definition inventory.c:79
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
synchronously removes item from current inventory location and adds it to destination no anims involv...
static proto native bool LocationCanMoveEntity(notnull InventoryLocation src, notnull InventoryLocation dst)
queries if the entity contained in inv_loc.m_item can be moved to another location This is a shorthan...
InventoryLocation.
provides access to slot configuration
Serialization general interface. Serializer API works with:
Definition serializer.c:56
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
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)
override void OnAbort()
enum FSMTransition WeaponTransition
ref LoopedChambering_Wait4ShowBullet2 m_w4sb2
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
override bool SaveCurrentFSMState(ParamsWriteContext ctx)