DayZ 1.24
Loading...
Searching...
No Matches
WeaponChamberingLooped.c
Go to the documentation of this file.
1// load x bullets
3{
4 override bool IsWaitingForActionFinish() { return true; }
5};
6
8{
9 override bool IsWaitingForActionFinish() { return false; }
10};
11
12class LoopedChambering extends WeaponStateBase
13{
19
26
28 {
32
33 // setup nested state machine
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);
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 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering m_srcMagazine = NULL");
101 }
102 else
103 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString());
104
105 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
106 }
107 override void OnExit(WeaponEventBase e)
108 {
109 bool done = false;
110 if (m_srcMagazine)
111 {
112 e.m_player.GetInventory().ClearInventoryReservationEx(m_srcMagazine, m_srcMagazinePrevLocation);
113
115 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
116 if (leftHandIl.IsValid())
117 {
119 {
121 {
123 {
125 {
126 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit");
127 done = true;
128 }
129 }
130 }
131 }
132
133 if (!done)
134 {
136 e.m_player.GetInventory().FindFreeLocationFor(m_srcMagazine, FindInventoryLocationType.CARGO, il);
137
138 if (!il || !il.IsValid())
139 {
140 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
141 {
142 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - no inventory space for ammo pile - dropped to ground - exit");
143 }
144 else
145 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
146
147 }
148 else
149 {
151 {
152 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from left hand (LHand->inv) - exit");
153 }
154 else
155 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot remove ammo pile from wpn - exit");
156 }
157 }
158 }
159 }
160
161 super.OnExit(e);
163 m_chamber.m_srcMagazine = NULL;
165 }
166 override void OnAbort(WeaponEventBase e)
167 {
168 bool done = false;
169 if (m_srcMagazine)
170 {
171 e.m_player.GetInventory().ClearInventoryReservationEx(m_srcMagazine, m_srcMagazinePrevLocation);
172
174 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
175 if (leftHandIl.IsValid())
176 {
178 {
180 {
182 {
184 {
185 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort");
186 done = true;
187 }
188 }
189 }
190 }
191
192 if (!done)
193 {
195 e.m_player.GetInventory().FindFreeLocationFor(m_srcMagazine, FindInventoryLocationType.CARGO, il);
196
197 if (!il || !il.IsValid())
198 {
199 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
200 {
201 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - no inventory space for ammo pile - dropped to ground - abort");
202 }
203 else
204 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
205
206 }
207 else
208 {
210 {
211 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, ok - ammo pile removed from left hand (LHand->inv) - abort");
212 }
213 else
214 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot remove ammo pile from wpn - abort");
215 }
216 }
217 }
218 }
219
220 super.OnAbort(e);
222 m_chamber.m_srcMagazine = NULL;
224 }
225
227 {
228 if (!super.SaveCurrentFSMState(ctx))
229 return false;
230
231 if (!ctx.Write(m_srcMagazine))
232 {
233 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
234 return false;
235 }
236
238 {
239 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
240 return false;
241 }
242
243 return true;
244 }
245
246 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
247 {
248 if (!super.LoadCurrentFSMState(ctx, version))
249 return false;
250
251 if (!ctx.Read(m_srcMagazine))
252 {
253 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
254 return false;
255 }
256
258 {
259 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
260 return false;
261 }
262 return true;
263 }
264};
265
266class LoopedChamberingEjectLast extends WeaponStateBase
267{
270 int m_endActionType;
273
281
283 {
287
288 // setup nested state machine
293 m_hideB = new BulletHide_W4T(m_weapon, this);
294 m_chamberFromInnerMag = new WeaponChamberFromInnerMag_W4T(m_weapon, this);
295 m_endLoop = new LoopedChambering_EndLoop(m_weapon, this, m_action, m_endActionType); // @NOTE: termination playing action - dummy?
296 // events
297 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
298 WeaponEventContinuousLoadBulletStart __lS_ = new WeaponEventContinuousLoadBulletStart;
299 WeaponEventContinuousLoadBulletEnd __lE_ = new WeaponEventContinuousLoadBulletEnd;
300 WeaponEventAnimCocked __wc_ = new WeaponEventAnimCocked;
301 WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
302 WeaponEventAnimBulletHide __bh_ = new WeaponEventAnimBulletHide;
303 WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
304 WeaponEventAnimBulletInMagazine __bM_ = new WeaponEventAnimBulletInMagazine;
305 WeaponEventAnimBulletShow2 _bs2_ = new WeaponEventAnimBulletShow2;
306
307 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
308 m_fsm.AddTransition(new WeaponTransition(m_start, __bs_, m_chamber));
309
310
311 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())));
312 m_fsm.AddTransition(new WeaponTransition(m_chamber, __bM_, m_endLoop));
313 m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __bh_, m_hideB));
314 m_fsm.AddTransition(new WeaponTransition(m_hideB, __bs_, m_chamber));
315
316 m_fsm.AddTransition(new WeaponTransition(m_endLoop, _fin_, NULL));
317
318 m_fsm.AddTransition(new WeaponTransition(m_hideB, __be_, m_eject));
319 m_fsm.AddTransition(new WeaponTransition(m_endLoop, __be_, m_eject));
320 m_fsm.AddTransition(new WeaponTransition(m_eject, __wc_, m_chamberFromInnerMag));
321 m_fsm.AddTransition(new WeaponTransition(m_chamberFromInnerMag, _fin_, NULL));
322
323 // Safety exits
324 m_fsm.AddTransition(new WeaponTransition(m_hideB, _fin_, null));
325 m_fsm.AddTransition(new WeaponTransition(m_w4sb2, _fin_, null));
326 m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
327 m_fsm.AddTransition(new WeaponTransition(m_eject, _fin_, null));
328 m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, null));
329
330 m_fsm.SetInitialState(m_start);
331 }
332
333 override void OnEntry(WeaponEventBase e)
334 {
335 if (e != NULL)
336 {
337 m_srcMagazine = e.m_magazine;
338 if (m_srcMagazine != NULL)
339 {
341 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
342
344
345 // move to LH
347 lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
349 {
350 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from inv (inv->LHand)");
351 }
352 else
353 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from inv");
354
355 m_chamber.m_srcMagazine = m_srcMagazine;
356 }
357 else
358 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast m_srcMagazine = NULL");
359 }
360 else
361 Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString());
362
363 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
364 }
365 override void OnExit(WeaponEventBase e)
366 {
367 bool done = false;
368 if (m_srcMagazine)
369 {
370 e.m_player.GetInventory().ClearInventoryReservationEx(m_srcMagazine, m_srcMagazinePrevLocation);
371
373 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
374 if (leftHandIl.IsValid())
375 {
377 {
379 {
381 {
383 {
384 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit");
385 done = true;
386 }
387 }
388 }
389 }
390
391 if (!done)
392 {
394 e.m_player.GetInventory().FindFreeLocationFor(m_srcMagazine, FindInventoryLocationType.CARGO, il);
395
396 if (!il || !il.IsValid())
397 {
398 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
399 {
400 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - no inventory space for ammo pile - dropped to ground - exit");
401 }
402 else
403 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
404
405 }
406 else
407 {
409 {
410 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand (LHand->inv) - exit");
411 }
412 else
413 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from wpn - exit");
414 }
415 }
416 }
417 }
418
419 super.OnExit(e);
421 m_chamber.m_srcMagazine = NULL;
423 }
424 override void OnAbort(WeaponEventBase e)
425 {
426 bool done = false;
427 if (m_srcMagazine)
428 {
429 e.m_player.GetInventory().ClearInventoryReservationEx(m_srcMagazine, m_srcMagazinePrevLocation);
430
432 m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
433 if (leftHandIl.IsValid())
434 {
436 {
438 {
440 {
442 {
443 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort");
444 done = true;
445 }
446 }
447 }
448 }
449
450 if (!done)
451 {
453 e.m_player.GetInventory().FindFreeLocationFor(m_srcMagazine, FindInventoryLocationType.CARGO, il);
454
455 if (!il || !il.IsValid())
456 {
457 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
458 {
459 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - no inventory space for ammo pile - dropped to ground - abort");
460 }
461 else
462 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
463
464 }
465 else
466 {
468 {
469 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, ok - ammo pile removed from left hand (LHand->inv) - abort");
470 }
471 else
472 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast, error - cannot remove ammo pile from wpn - abort");
473 }
474 }
475 }
476 }
477
478 super.OnAbort(e);
480 m_chamber.m_srcMagazine = NULL;
482 }
483
485 {
486 if (!super.SaveCurrentFSMState(ctx))
487 return false;
488
489 if (!ctx.Write(m_srcMagazine))
490 {
491 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
492 return false;
493 }
494
496 {
497 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
498 return false;
499 }
500 return true;
501 }
502
503 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
504 {
505 if (!super.LoadCurrentFSMState(ctx, version))
506 return false;
507
508 if (!ctx.Read(m_srcMagazine))
509 {
510 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
511 return false;
512 }
513
515 {
516 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChamberingEjectLast.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
517 return false;
518 }
519 return true;
520 }
521};
void wpnDebugPrint(string s)
Definition Debug.c:9
void DayZPlayerUtils()
cannot be instantiated
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition Guards.c:602
FindInventoryLocationType
flags for searching locations in inventory
bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
enum FSMTransition WeaponTransition
ref LoopedChambering_Wait4ShowBullet2 m_w4sb2
int m_startActionType
int m_endActionType
Magazine m_srcMagazine
ref InventoryLocation m_srcMagazinePrevLocation
source of the cartridge
ref WeaponEndAction m_endLoop
ref WeaponStateBase m_start
class WeaponEndAction extends WeaponStartAction m_action
ref WeaponChambering_Base m_chamber
ref WeaponEjectCasingMultiMuzzle m_eject
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
static bool IsWeaponLogEnable()
Definition Debug.c:799
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
signalize mechanism manipulation
Definition Events.c:35
weapon finite state machine
const float MAX_DROP_MAGAZINE_DISTANCE_SQ
simple class starting animation action specified by m_action and m_actionType
override bool IsWaitingForActionFinish()
represent weapon state base
Definition BulletHide.c:2
ref BulletHide_W4T m_hideB
ref WeaponChamberFromInnerMag_W4T m_chamberFromInnerMag
void LoopedChamberingEjectLast(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int startActionType=-1, int endActionType=-1)
ref WeaponStartAction m_endLoop
Magazine m_srcMagazine
destination of the ejected cartridge
ref LoopedChambering_Wait4ShowBullet2 m_w4sb2
WeaponActions m_action
ref WeaponChambering_Cartridge m_chamber
override bool IsWaitingForActionFinish()
override void OnEntry(WeaponEventBase e)
ref WeaponStateBase m_start
source of the cartridge
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
ref WeaponEjectCasing m_eject
ref InventoryLocation m_srcMagazinePrevLocation
source of the cartridge
override void OnAbort(WeaponEventBase e)
void WeaponEjectCasing(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
void LoopedChambering(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int startActionType=-1, int endActionType=-1)
override void OnExit(WeaponEventBase e)
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
proto void Print(void var)
Prints content of variable to console/log.
WeaponActions
actions
Definition human.c:796