DayZ 1.24
Loading...
Searching...
No Matches
WeaponDetachingMag.c
Go to the documentation of this file.
1
2// detach magazine composite state
4{ };
5
7{
10
11 override void OnEntry(WeaponEventBase e)
12 {
13 //if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, Detaching mag=" + m_magazine.ToString() + "to loc=" + InventoryLocation.DumpToStringNullSafe(m_dst)); }
14 super.OnEntry(e);
15 if (e)
16 {
17 if (!m_magazine || !m_dst)
18 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, error - no magazine to load from (m_magazine=NULL)");
19 }
20 }
21
22 override void OnAbort(WeaponEventBase e)
23 {
24 m_magazine = NULL;
25 m_dst = NULL;
26
27 super.OnAbort(e);
28 }
29
30 override void OnExit(WeaponEventBase e)
31 {
33 if (m_magazine.GetInventory().GetCurrentInventoryLocation(il))
34 {
36 {
37 m_weapon.HideMagazine();
38 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, ok - magazine removed from inv (inv->dst)");
39 }
40 else
41 {
42 // @TODO: drop on gnd
43 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, error - cannot store detached magazine!");
44 }
45 }
46 else
47 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, error - cannot get curr location");
48
49 m_magazine = NULL;
50 m_dst = NULL;
51 super.OnExit(e);
52 }
53
55 {
56 if (!super.SaveCurrentFSMState(ctx))
57 return false;
58
59 if (!ctx.Write(m_magazine))
60 {
61 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store.SaveCurrentFSMState: cannot write m_magazine for weapon=" + m_weapon);
62 return false;
63 }
64
66 {
67 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store.SaveCurrentFSMState: cannot write m_st for weapon=" + m_weapon);
68 return false;
69 }
70 return true;
71 }
72
73 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
74 {
75 if (!super.LoadCurrentFSMState(ctx, version))
76 return false;
77
78 if (!ctx.Read(m_magazine))
79 {
80 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store.LoadCurrentFSMState: cannot read m_magazine for weapon=" + m_weapon);
81 return false;
82 }
84 {
85 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store.LoadCurrentFSMState: cannot read m_dst for weapon=" + m_weapon);
86 return false;
87 }
88 return true;
89 }
90};
91
92/*class WeaponDetachingMag_Store_W4T extends WeaponDetachingMag_Store
93 {
94 override bool IsWaitingForActionFinish () { return true; }
95 };*/
96
97class WeaponDetachingMag extends WeaponStateBase
98{
100 int m_actionType;
103
107
109 {
111 m_actionType = actionType;
112
113 // setup nested state machine
114 m_start = new WeaponDetachingMag_1(m_weapon, this, m_action, m_actionType);
115 m_store = new WeaponDetachingMag_Store(m_weapon, this);
116 m_hideM = new MagazineHide_W4T(m_weapon, this);
117 // events
118 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
119 WeaponEventBase __md_ = new WeaponEventAnimMagazineDetached;
120 WeaponEventBase __mh_ = new WeaponEventAnimMagazineHide;
121
122 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
123 m_fsm.AddTransition(new WeaponTransition(m_start, __md_, m_store));
124 m_fsm.AddTransition(new WeaponTransition(m_store, __mh_, m_hideM));
125 m_fsm.AddTransition(new WeaponTransition(m_hideM, _fin_, NULL));
126
127 // Safety exits
128 m_fsm.AddTransition(new WeaponTransition(m_store, _fin_, null));
129 m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, null));
130
131 m_fsm.SetInitialState(m_start);
132 }
133
134 override void OnEntry(WeaponEventBase e)
135 {
136 if (e != NULL)
137 {
138 WeaponEventDetachMagazine de;
139 if (Class.CastTo(de, e))
140 {
141 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("WeaponDetachingMag type=" + typename.EnumToString(InventoryLocationType, de.m_dst.GetType()));
142 m_magazine = e.m_magazine;
143 m_dst = de.m_dst;
144
145 m_store.m_magazine = m_magazine;
146 m_store.m_dst = m_dst;
147 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("WeaponDetachingMag type=" + typename.EnumToString(InventoryLocationType, m_store.m_dst.GetType()));
148 }
149 }
150 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
151 }
152
153 override void OnExit(WeaponEventBase e)
154 {
155 m_dst = NULL;
156 m_magazine = NULL;
157 super.OnExit(e);
158 }
159
161 {
162 if (!super.SaveCurrentFSMState(ctx))
163 return false;
164
165 if (!ctx.Write(m_magazine))
166 {
167 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag.SaveCurrentFSMState: cannot write m_magazine for weapon=" + m_weapon);
168 return false;
169 }
170
172 {
173 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag.SaveCurrentFSMState: cannot write m_st for weapon=" + m_weapon);
174 return false;
175 }
176 return true;
177 }
178
179 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
180 {
181 if (!super.LoadCurrentFSMState(ctx, version))
182 return false;
183
184 if (!ctx.Read(m_magazine))
185 {
186 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag.LoadCurrentFSMState: cannot read m_magazine for weapon=" + m_weapon);
187 return false;
188 }
190 {
191 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag.LoadCurrentFSMState: cannot read m_dst for weapon=" + m_weapon);
192 return false;
193 }
194 return true;
195 }
196};
197
void wpnDebugPrint(string s)
Definition Debug.c:9
ref InventoryLocation m_dst
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition Guards.c:602
bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
InventoryLocationType
types of Inventory Location
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
enum FSMTransition WeaponTransition
ref WeaponStateBase m_start
class WeaponEndAction extends WeaponStartAction m_action
Super root of all classes in Enforce script.
Definition EnScript.c:11
script counterpart to engine's class Inventory
Definition Inventory.c:79
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
synchronously removes item from current inventory location and adds it to destination no anims involv...
InventoryLocation.
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
simple class starting animation action specified by m_action and m_actionType
represent weapon state base
Definition BulletHide.c:2
int m_actionType
action to be played
ref WeaponDetachingMag_Store m_store
void WeaponDetachingMag(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
WeaponActions m_action
override void OnEntry(WeaponEventBase e)
ref WeaponStateBase m_start
source of the cartridge
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
ref InventoryLocation m_dst
magazine that will be detached
override void OnAbort(WeaponEventBase e)
ref MagazineHide_W4T m_hideM
override void OnExit(WeaponEventBase e)
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
WeaponActions
actions
Definition human.c:796