Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
riflechambering.c
Go to the documentation of this file.
1 class RifleChambering extends WeaponStateBase
2 {
4  int m_actionType;
5  Magazine m_srcMagazine;
6 
10  ref WeaponChambering_W4T m_w4t;
11 
12  void RifleChambering (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
13  {
14  m_action = action;
15  m_actionType = actionType;
16 
17  // setup nested state machine
18  m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_actionType);
19  m_eject = new WeaponEjectCasing(m_weapon, this);
21  m_w4t = new WeaponChambering_W4T(m_weapon, this);
22  // events
23  WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
24  WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
25  WeaponEventAnimBulletInChamber __bc_ = new WeaponEventAnimBulletInChamber;
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_start , __be_, m_eject));
30  m_fsm.AddTransition(new WeaponTransition(m_eject , __bs_, m_chamber));
31  m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_w4t));
32  m_fsm.AddTransition(new WeaponTransition(m_w4t , _fin_, NULL));
33 
34  // Safety exits
35  m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
36  m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
37  m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
38 
39  m_fsm.SetInitialState(m_start);
40  }
41 
42  override void OnEntry (WeaponEventBase e)
43  {
44  if (e != NULL)
45  {
46  if (e.m_magazine != NULL)
47  {
48  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RifleChambering, taking mag from event e.mag=" + e.m_magazine.ToString()); }
49  m_srcMagazine = e.m_magazine;
50  m_chamber.m_srcMagazine = m_srcMagazine;
51  }
52  }
53  else
54  {
55  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RifleChambering (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString()); }
56  }
57  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " m_srcMagazine=" + m_srcMagazine.ToString()); }
58 
59  super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
60  }
61 
62  override void OnAbort (WeaponEventBase e)
63  {
64  super.OnAbort(e);
65  m_srcMagazine = NULL;
66  }
67 
68  override void OnExit (WeaponEventBase e)
69  {
70  super.OnExit(e);
71  m_srcMagazine = NULL;
72  }
73 
74  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
75  {
76  if (!super.SaveCurrentFSMState(ctx))
77  return false;
78 
79  if (!ctx.Write(m_srcMagazine))
80  {
81  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RifleChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
82  return false;
83  }
84  return true;
85  }
86 
87  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
88  {
89  if (!super.LoadCurrentFSMState(ctx, version))
90  return false;
91 
92  if (!ctx.Read(m_srcMagazine))
93  {
94  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RifleChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
95  return false;
96  }
97  return true;
98  }
99 };
100 
LoadCurrentFSMState
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
Definition: weaponchambering.c:867
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
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
WeaponEjectCasing
Definition: weaponejectcasingandchamberfromattmag.c:126
OnEntry
HandStateEquipped OnEntry
Definition: weaponchambering.c:208