Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weaponejectbullet.c
Go to the documentation of this file.
1 // eject
2 //TODO MW delete this file
3 class WeaponEjectBullet_Start extends WeaponStartAction
4 { };
5 /*
6 class WeaponEjectBullet_Cartridge extends WeaponStateBase
7 {
8  Magazine m_dstMagazine; /// destination of the cartridge
9 
10  override void OnEntry (WeaponEventBase e)
11  {
12  super.OnEntry(e);
13 
14  DayZPlayer p = e.m_player;
15  int mi = m_weapon.GetCurrentMuzzle();
16 
17  ejectBulletAndStoreInMagazine(m_weapon, mi, m_dstMagazine, p); // MP-safe
18  }
19 
20  override void OnAbort (WeaponEventBase e)
21  {
22  m_dstMagazine = NULL;
23  super.OnAbort(e);
24  }
25 
26  override void OnExit (WeaponEventBase e)
27  {
28  m_dstMagazine = NULL;
29  super.OnExit(e);
30  }
31 };
32 */
33 /*
34 class WeaponEjectBullet_Cartridge_W4T extends WeaponEjectBullet_Cartridge
35 {
36  override bool IsWaitingForActionFinish () { return true; }
37 };
38 */
39 class WeaponEjectBullet extends WeaponStateBase
40 {
42  int m_actionType;
43  Magazine m_dstMagazine;
44 
45  ref WeaponEjectBullet_Start m_start;
46  ref WeaponEjectBullet_Cartridge_W4T m_eject; // @TODO: workaround for missing BH event
47  ref BulletHide_W4T m_hideB;
48  ref WeaponChamberFromAttMag_W4T m_chamber;
49 
50  void WeaponEjectBullet (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
51  {
52  m_action = action;
53  m_actionType = actionType;
54 
55  // setup nested state machine
56  m_start = new WeaponEjectBullet_Start(m_weapon, this, m_action, m_actionType);
57  m_eject = new WeaponEjectBullet_Cartridge_W4T(m_weapon, this); // @TODO: workaround for missing BH event (_W4T)
58  m_hideB = new BulletHide_W4T(m_weapon, this);
59  m_chamber = new WeaponChamberFromAttMag_W4T(m_weapon, this);
60 
61  // events
62  WeaponEventBase __be_ = new WeaponEventAnimBulletEject;
63  WeaponEventBase __bh_ = new WeaponEventAnimBulletHide;
64  WeaponEventBase __ck_ = new WeaponEventAnimCocked;
65  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
66 
67  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
68  // transitions
69  m_fsm.AddTransition(new WeaponTransition( m_start, __be_, m_eject));
70  m_fsm.AddTransition(new WeaponTransition( m_eject, __bh_, m_hideB));
71 
72  m_fsm.AddTransition(new WeaponTransition( m_eject, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
73  m_fsm.AddTransition(new WeaponTransition( m_hideB, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
74 
75  m_fsm.AddTransition(new WeaponTransition( m_hideB, _fin_, NULL));
76  m_fsm.AddTransition(new WeaponTransition( m_eject, _fin_, NULL)); // @TODO: workaround for missing BH event
77  m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
78 
79  // Safety exits
80  m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
81 
82  m_fsm.SetInitialState(m_start);
83  }
84 
85  override void OnEntry (WeaponEventBase e)
86  {
87  if (e)
88  {
89  if (e.m_magazine)
90  m_dstMagazine = e.m_magazine;
91  m_eject.m_dstMagazine = m_dstMagazine;
92 
93  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet m_mag=" + m_dstMagazine.ToString() + ", e.mag=" + e.m_magazine.ToString()); }
94  }
95 
96  super.OnEntry(e); // @NOTE: super after submachine init (prevent override from submachine start)
97 
98  }
99 
100  override void OnAbort (WeaponEventBase e)
101  {
102  m_dstMagazine = NULL;
103  super.OnAbort(e);
104  }
105 
106  override void OnExit (WeaponEventBase e)
107  {
108  m_dstMagazine = NULL;
109  super.OnExit(e);
110  }
111 
112  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
113  {
114  if (!super.SaveCurrentFSMState(ctx))
115  return false;
116 
117  if (!ctx.Write(m_dstMagazine))
118  {
119  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet.LoadCurrentFSMState: cannot write m_dstMagazine for weapon=" + m_weapon);
120  return false;
121  }
122  return true;
123  }
124 
125  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
126  {
127  if (!super.LoadCurrentFSMState(ctx, version))
128  return false;
129 
130  if (!ctx.Read(m_dstMagazine))
131  {
132  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
133  return false;
134  }
135  return true;
136  }
137 };
138 
139 
LoadCurrentFSMState
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
Definition: weaponchambering.c:867
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
OnAbort
override void OnAbort()
Definition: remotedetonator.c:300
LogManager
Definition: debug.c:734
OnExit
override void OnExit(HandEventBase e)
Definition: hand_states.c:28
wpnDebugPrint
void wpnDebugPrint(string s)
Definition: debug.c:9
m_eject
ref WeaponEjectCasingMultiMuzzle m_eject
Definition: weaponchambering.c:638
m_chamber
ref WeaponChambering_Base m_chamber
Definition: weaponchambering.c:639
m_action
class WeaponEndAction extends WeaponStartAction m_action
WeaponStartAction
simple class starting animation action specified by m_action and m_actionType
Definition: weaponchambering.c:2
WeaponActions
WeaponActions
actions
Definition: human.c:808
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
m_start
ref WeaponStateBase m_start
Definition: weaponchambering.c:637
SaveCurrentFSMState
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
Definition: weaponchambering.c:848
Object
Definition: objecttyped.c:1
WeaponTransition
enum FSMTransition WeaponTransition
WeaponGuardHasAmmo
void WeaponGuardHasAmmo(Weapon_Base w=NULL)
Definition: guards.c:99
WeaponEventBase
signalize mechanism manipulation
Definition: events.c:34
WeaponStateBase
represent weapon state base
Definition: bullethide.c:1
m_weapon
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition: guards.c:583
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
WeaponFSM
weapon finite state machine
OnEntry
HandStateEquipped OnEntry
Definition: weaponchambering.c:208