Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
riflerechambering.c
Go to the documentation of this file.
1 class RifleReChambering extends WeaponStateBase
2 {
4  int m_actionType;
5  Magazine m_dstMagazine;
6  Magazine m_srcMagazine;
7 
9  ref WeaponEjectBullet_Cartridge m_eject;
11  ref WeaponChambering_W4T m_w4t;
12 
13  void RifleReChambering (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
14  {
15  m_action = action;
16  m_actionType = actionType;
17 
18  // setup nested state machine
19  m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_actionType);
20  m_eject = new WeaponEjectBullet_Cartridge(m_weapon, this);
22  m_w4t = new WeaponChambering_W4T(m_weapon, this);
23  // events
24  WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
25  WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
26  WeaponEventAnimBulletInChamber __bc_ = new WeaponEventAnimBulletInChamber;
27  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
28 
29  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
30  m_fsm.AddTransition(new WeaponTransition(m_start , __be_, m_eject));
31  m_fsm.AddTransition(new WeaponTransition(m_eject , __bs_, m_chamber));
32  m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_w4t));
33  m_fsm.AddTransition(new WeaponTransition(m_w4t , _fin_, NULL));
34 
35  // Safety exits
36  m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
37  m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
38  m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
39 
40  m_fsm.SetInitialState(m_start);
41  }
42 
43  override void OnEntry (WeaponEventBase e)
44  {
45  if (e)
46  {
47  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber, mag=" + e.m_magazine.ToString()); }
48  m_srcMagazine = e.m_magazine;
49  m_chamber.m_srcMagazine = m_srcMagazine;
50 
51  // prepare magazine for ejected ammo
52  int mi = m_weapon.GetCurrentMuzzle();
53  string magazineTypeName = m_weapon.GetChamberedCartridgeMagazineTypeName(mi);
54  float damage = 0.0;
55  string type;
56  if (m_weapon.GetCartridgeInfo(mi, damage, type))
57  {
58  bool is_single_or_server = !GetGame().IsMultiplayer() || GetGame().IsServer();
59  if (is_single_or_server)
60  {
61  m_dstMagazine = DayZPlayerUtils.SelectStoreCartridge(e.m_player, m_weapon, mi, m_srcMagazine, damage, magazineTypeName);
62  if (!m_dstMagazine)
63  {
64  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber - error, cannot prepare mag for catridge, magType=" + magazineTypeName);
65  }
66  }
67  }
68  m_eject.m_dstMagazine = m_dstMagazine;
69  }
70  super.OnEntry(e); // @NOTE: super after submachine init (prevent override from submachine start)
71 
72  }
73 
74  override void OnAbort (WeaponEventBase e)
75  {
76  super.OnAbort(e);
77  m_srcMagazine = NULL;
78  m_dstMagazine = NULL;
79  }
80 
81  override void OnExit (WeaponEventBase e)
82  {
83  super.OnExit(e);
84  m_srcMagazine = NULL;
85  m_dstMagazine = NULL;
86  }
87 
88  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
89  {
90  if (!super.SaveCurrentFSMState(ctx))
91  return false;
92 
93  if (!ctx.Write(m_dstMagazine))
94  {
95  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber.SaveCurrentFSMState: cannot save m_dstMagazine for weapon=" + m_weapon);
96  return false;
97  }
98  if (!ctx.Write(m_srcMagazine))
99  {
100  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
101  return false;
102  }
103  return true;
104  }
105 
106  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
107  {
108  if (!super.LoadCurrentFSMState(ctx, version))
109  return false;
110 
111  if (!ctx.Read(m_dstMagazine))
112  {
113  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
114  return false;
115  }
116  if (!ctx.Read(m_srcMagazine))
117  {
118  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
119  return false;
120  }
121  return true;
122  }
123 };
124 
LoadCurrentFSMState
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
Definition: weaponchambering.c:867
GetGame
proto native CGame GetGame()
WeaponChambering_Cartridge
Definition: weaponchambering.c:164
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
m_srcMagazine
Magazine m_srcMagazine
Definition: weaponchambering.c:634
OnAbort
override void OnAbort()
Definition: remotedetonator.c:300
LogManager
Definition: debug.c:734
DayZPlayerUtils
private void DayZPlayerUtils()
cannot be instantiated
Definition: dayzplayerutils.c:461
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
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
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