DayZ 1.24
Loading...
Searching...
No Matches
WeaponReChamber.c
Go to the documentation of this file.
1
2// rechamber (== eject cartridge + load another + store the old one)
3class WeaponRechamber extends WeaponStateBase
4{
11
12 ref WeaponEjectBullet m_eje;
13 ref WeaponChambering m_loa;
14
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 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber - error, cannot prepare mag for catridge, magType=" + magazineTypeName);
53 }
54
55 e.m_magazine = m_dstMagazine; // @NOTE: override event mag - @TODO
56 }
57 super.OnEntry(e); // @NOTE: super after submachine init (prevent override from submachine start)
58 }
59
60 override void OnExit(WeaponEventBase e)
61 {
62 super.OnExit(e);
63 m_dstMagazine = NULL;
64 m_eje.m_dstMagazine = NULL;
65 m_loa.m_srcMagazine = NULL;
66 }
67
69 {
70 if (!super.SaveCurrentFSMState(ctx))
71 return false;
72
73 if (!ctx.Write(m_dstMagazine))
74 {
75 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot save m_dstMagazine for weapon=" + m_weapon);
76 return false;
77 }
78 if (!ctx.Write(m_srcMagazine))
79 {
80 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
81 return false;
82 }
83 return true;
84 }
85
86 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
87 {
88 if (!super.LoadCurrentFSMState(ctx, version))
89 return false;
90
91 if (!ctx.Read(m_dstMagazine))
92 {
93 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
94 return false;
95 }
96 if (!ctx.Read(m_srcMagazine))
97 {
98 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
99 return false;
100 }
101 return true;
102 }
103};
104
void wpnDebugPrint(string s)
Definition Debug.c:9
void DayZPlayerUtils()
cannot be instantiated
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition Guards.c:602
enum FSMTransition WeaponTransition
Magazine m_srcMagazine
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
represent weapon state base
Definition BulletHide.c:2
void WeaponEjectBullet(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
Magazine m_srcMagazine
destination of the ejected cartridge
void WeaponChambering(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
ref WeaponEjectBullet m_eje
source of the loaded cartridge
override void OnEntry(WeaponEventBase e)
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
ref WeaponChambering m_loa
void WeaponRechamber(Weapon_Base w=NULL, WeaponStateBase parent=NULL, int actionEject=-1, int actionTypeEject=-1, int actionLoad=-1, int actionTypeLoad=-1)
override void OnExit(WeaponEventBase e)
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90