Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weaponrechamber.c
Go to the documentation of this file.
1 
2 // rechamber (== eject cartridge + load another + store the old one)
3 class WeaponRechamber extends WeaponStateBase
4 {
5  int m_actionEject;
6  int m_actionTypeEject;
7  int m_actionLoad;
8  int m_actionTypeLoad;
9  Magazine m_dstMagazine;
10  Magazine m_srcMagazine;
11 
12  ref WeaponEjectBullet m_eje;
13  ref WeaponChambering m_loa;
14 
15  void WeaponRechamber (Weapon_Base w = NULL, WeaponStateBase parent = NULL, int actionEject = -1, int actionTypeEject = -1, int actionLoad = -1, int actionTypeLoad = -1)
16  {
17  m_actionEject = actionEject;
18  m_actionTypeEject = actionTypeEject;
19  m_actionLoad = actionLoad;
20  m_actionTypeLoad = actionTypeLoad;
21 
22  // setup nested state machine
23  m_eje = new WeaponEjectBullet(m_weapon, this, m_actionEject, m_actionTypeEject);
24  m_loa = new WeaponChambering(m_weapon, this, m_actionLoad, m_actionTypeLoad);
25  // events
26  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
27 
28  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
29  m_fsm.AddTransition(new WeaponTransition(m_eje, _fin_, m_loa));
30  m_fsm.AddTransition(new WeaponTransition(m_loa, _fin_, NULL));
31 
32  m_fsm.SetInitialState(m_eje);
33  }
34 
35  override void OnEntry (WeaponEventBase e)
36  {
37  if (e)
38  {
39  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber, mag=" + e.m_magazine.ToString()); }
40  m_srcMagazine = e.m_magazine;
41  m_loa.m_srcMagazine = m_srcMagazine;
42 
43  // prepare magazine for ejected ammo
44  int mi = m_weapon.GetCurrentMuzzle();
45  string magazineTypeName = m_weapon.GetChamberedCartridgeMagazineTypeName(mi);
46  float damage = 0.0;
47  string type;
48  if (m_weapon.GetCartridgeInfo(mi, damage, type))
49  {
50  m_dstMagazine = DayZPlayerUtils.SelectStoreCartridge(e.m_player, m_weapon, mi, m_srcMagazine, damage, magazineTypeName);
51  if (!m_dstMagazine)
52  {
53  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber - error, cannot prepare mag for catridge, magType=" + magazineTypeName);
54  }
55  }
56 
57  e.m_magazine = m_dstMagazine; // @NOTE: override event mag - @TODO
58  }
59  super.OnEntry(e); // @NOTE: super after submachine init (prevent override from submachine start)
60  }
61 
62  override void OnExit (WeaponEventBase e)
63  {
64  super.OnExit(e);
65  m_dstMagazine = NULL;
66  m_eje.m_dstMagazine = NULL;
67  m_loa.m_srcMagazine = NULL;
68  }
69 
70  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
71  {
72  if (!super.SaveCurrentFSMState(ctx))
73  return false;
74 
75  if (!ctx.Write(m_dstMagazine))
76  {
77  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot save m_dstMagazine for weapon=" + m_weapon);
78  return false;
79  }
80  if (!ctx.Write(m_srcMagazine))
81  {
82  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
83  return false;
84  }
85  return true;
86  }
87 
88  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
89  {
90  if (!super.LoadCurrentFSMState(ctx, version))
91  return false;
92 
93  if (!ctx.Read(m_dstMagazine))
94  {
95  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
96  return false;
97  }
98  if (!ctx.Read(m_srcMagazine))
99  {
100  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
101  return false;
102  }
103  return true;
104  }
105 };
106 
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
m_srcMagazine
Magazine m_srcMagazine
Definition: weaponchambering.c:634
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
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
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