DayZ 1.24
Loading...
Searching...
No Matches
RifleReChambering.c
Go to the documentation of this file.
1class RifleReChambering extends WeaponStateBase
2{
4 int m_actionType;
7
12
14 {
16 m_actionType = actionType;
17
18 // setup nested state machine
19 m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_actionType);
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();
60 {
61 m_dstMagazine = DayZPlayerUtils.SelectStoreCartridge(e.m_player, m_weapon, mi, m_srcMagazine, damage, magazineTypeName);
62 if (!m_dstMagazine)
63 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber - error, cannot prepare mag for catridge, magType=" + magazineTypeName);
64 }
65 }
66 m_eject.m_dstMagazine = m_dstMagazine;
67 }
68 super.OnEntry(e); // @NOTE: super after submachine init (prevent override from submachine start)
69
70 }
71
72 override void OnAbort(WeaponEventBase e)
73 {
74 super.OnAbort(e);
76 m_dstMagazine = NULL;
77 }
78
79 override void OnExit(WeaponEventBase e)
80 {
81 super.OnExit(e);
83 m_dstMagazine = NULL;
84 }
85
87 {
88 if (!super.SaveCurrentFSMState(ctx))
89 return false;
90
91 if (!ctx.Write(m_dstMagazine))
92 {
93 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber.SaveCurrentFSMState: cannot save m_dstMagazine for weapon=" + m_weapon);
94 return false;
95 }
96 if (!ctx.Write(m_srcMagazine))
97 {
98 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
99 return false;
100 }
101 return true;
102 }
103
104 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
105 {
106 if (!super.LoadCurrentFSMState(ctx, version))
107 return false;
108
109 if (!ctx.Read(m_dstMagazine))
110 {
111 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
112 return false;
113 }
114 if (!ctx.Read(m_srcMagazine))
115 {
116 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponRechamber.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
117 return false;
118 }
119 return true;
120 }
121};
122
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
ref WeaponStateBase m_start
class WeaponEndAction extends WeaponStartAction m_action
ref WeaponChambering_Base m_chamber
ref WeaponEjectCasingMultiMuzzle m_eject
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
int m_actionType
action to be played
ref WeaponChambering_W4T m_w4t
Magazine m_srcMagazine
destination of the ejected cartridge
ref WeaponEjectBullet_Cartridge m_eject
WeaponActions m_action
ref WeaponChambering_Cartridge m_chamber
override void OnEntry(WeaponEventBase e)
ref WeaponStateBase m_start
source of the cartridge
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
void RifleReChambering(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
override void OnAbort(WeaponEventBase e)
override void OnExit(WeaponEventBase e)
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
WeaponActions
actions
Definition human.c:796