DayZ 1.24
Loading...
Searching...
No Matches
WeaponCharging.c
Go to the documentation of this file.
5{
7 int m_actionType;
8
12 ref WeaponEjectAndChamberFromAttMag m_ejectChamber;
14
16 {
18 m_actionType = actionType;
19
20 // setup nested state machine
21 m_start = new WeaponCharging_Start(m_weapon, this, m_action, m_actionType);
22 m_onCK = new WeaponCharging_CK(m_weapon, this);
24 m_ejectChamber = new WeaponEjectAndChamberFromAttMag(m_weapon, this);
26
27 // events
28 WeaponEventBase __be_ = new WeaponEventAnimBulletEject;
29 WeaponEventBase __bh_ = new WeaponEventAnimBulletHide;
30 WeaponEventBase __ck_ = new WeaponEventAnimCocked;
31 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
32
33 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
34 // transitions
35 m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_ejectChamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
36 m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_eject));
37 m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, NULL));
38
39 //m_fsm.AddTransition(new WeaponTransition( m_start, __ck_, m_eject, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
40 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon))); // some anims do not send BE event
41 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_onCK)); // some anims do not send BE event
42
43 m_fsm.AddTransition(new WeaponTransition(m_ejectChamber, __ck_, m_onCK));
44 m_fsm.AddTransition(new WeaponTransition(m_ejectChamber, _fin_, NULL));
45 m_fsm.AddTransition(new WeaponTransition(m_eject, __ck_, m_onCK));
46 m_fsm.AddTransition(new WeaponTransition(m_eject, _fin_, NULL));
47
48 m_fsm.AddTransition(new WeaponTransition(m_onCK, _fin_, NULL));
49
50 m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
51
52 m_fsm.SetInitialState(m_start);
53 }
54};
55
57{
59 {
60 return true;
61 }
62};
63
65{
66};
67
69{
70 override bool IsWaitingForActionFinish() { return true; }
71 override void OnEntry(WeaponEventBase e)
72 {
73 super.OnEntry(e);
74 m_weapon.SetCharged(true);
75 m_weapon.SetWeaponOpen(false);
76 }
77};
78
80{
81 Magazine m_dstMagazine;
82
83 override void OnEntry(WeaponEventBase e)
84 {
85 super.OnEntry(e);
86 if (e)
87 {
88 DayZPlayer p = e.m_player;
89 int mi = m_weapon.GetCurrentMuzzle();
90
91 ejectBulletAndStoreInMagazine(m_weapon, mi, m_dstMagazine, p); // MP-safe
92 }
93 }
94
95 override void OnAbort(WeaponEventBase e)
96 {
97 m_dstMagazine = NULL;
98 super.OnAbort(e);
99 }
100
101 override void OnExit(WeaponEventBase e)
102 {
103 m_dstMagazine = NULL;
104 super.OnExit(e);
105 }
106
108 {
109 if (!super.SaveCurrentFSMState(ctx))
110 return false;
111
112 if (!ctx.Write(m_dstMagazine))
113 {
114 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet_Cartridge.SaveCurrentFSMState: cannot write m_dstMagazine for weapon=" + m_weapon);
115 return false;
116 }
117 return true;
118 }
119
120 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
121 {
122 if (!super.LoadCurrentFSMState(ctx, version))
123 return false;
124
125 if (!ctx.Read(m_dstMagazine))
126 {
127 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet_Cartridge.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
128 return false;
129 }
130 return true;
131 }
132
133};
134
136{
137 Magazine m_dstMagazine;
138
139 override void OnEntry(WeaponEventBase e)
140 {
141 super.OnEntry(e);
142 if (e)
143 {
144 DayZPlayer p = e.m_player;
145 for (int i = 0; i < m_weapon.GetMuzzleCount(); i++)
146 {
147 m_weapon.CreateRound(i);
148 ejectBulletAndStoreInMagazine(m_weapon, i, m_dstMagazine, p); // MP-safe
149 m_weapon.EffectBulletHide(i);
150 m_weapon.HideBullet(i);
151 }
152 }
153 }
154
155 override void OnAbort(WeaponEventBase e)
156 {
157 m_dstMagazine = NULL;
158 super.OnAbort(e);
159 }
160
161 override void OnExit(WeaponEventBase e)
162 {
163 m_dstMagazine = NULL;
164 super.OnExit(e);
165 }
166
168 {
169 if (!super.SaveCurrentFSMState(ctx))
170 return false;
171
172 if (!ctx.Write(m_dstMagazine))
173 {
174 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet_Cartridge.SaveCurrentFSMState: cannot write m_dstMagazine for weapon=" + m_weapon);
175 return false;
176 }
177 return true;
178 }
179
180 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
181 {
182 if (!super.LoadCurrentFSMState(ctx, version))
183 return false;
184
185 if (!ctx.Read(m_dstMagazine))
186 {
187 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponEjectBullet_Cartridge.LoadCurrentFSMState: cannot read m_dstMagazine for weapon=" + m_weapon);
188 return false;
189 }
190 return true;
191 }
192
193};
194
199
200
204class WeaponChargingInnerMag extends WeaponStateBase
205{
207 int m_actionType;
208
215
217 {
219 m_actionType = actionType;
220
221 // setup nested state machine
222 m_start = new WeaponCharging_Start(m_weapon, this, m_action, m_actionType);
223 m_onBE = new WeaponEjectBullet_Cartridge_W4T(m_weapon, this);
224 m_onBEFireOut = new WeaponEjectCasing_W4T(m_weapon, this);
225 m_hideB = new BulletHide_W4T(m_weapon, this);
226 m_onCK = new WeaponCharging_CK(m_weapon, this);
228
229 // events
230 WeaponEventBase __be_ = new WeaponEventAnimBulletEject;
231 WeaponEventBase __bh_ = new WeaponEventAnimBulletHide;
232 WeaponEventBase __ck_ = new WeaponEventAnimCocked;
233 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
234
235 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
236 // transitions
237 m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_onBEFireOut, NULL, new WeaponGuardCurrentChamberFiredOut(m_weapon)));
238 m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_onBE, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
239 m_fsm.AddTransition(new WeaponTransition(m_onBE, __bh_, m_hideB));
240 m_fsm.AddTransition(new WeaponTransition(m_onBEFireOut, __bh_, m_hideB));
241
242 //TODO after inner magazine rework this events must load new bullet
243
244 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_onBEFireOut, NULL, new GuardAnd(new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon)), new WeaponGuardCurrentChamberFiredOut(m_weapon))));
245 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_onBE, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
246 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_chamber, NULL, new WeaponGuardHasAmmoInnerMagazine(m_weapon))); // some anims do not send BE event
247 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_onCK)); // some anims do not send BE event
248 m_fsm.AddTransition(new WeaponTransition(m_onBE, __ck_, m_chamber, NULL, new WeaponGuardHasAmmoInnerMagazine(m_weapon)));
249 m_fsm.AddTransition(new WeaponTransition(m_onBE, __ck_, m_onCK));
250 m_fsm.AddTransition(new WeaponTransition(m_onBEFireOut, __ck_, m_chamber, NULL, new WeaponGuardHasAmmoInnerMagazine(m_weapon)));
251 m_fsm.AddTransition(new WeaponTransition(m_onBEFireOut, __ck_, m_onCK));
252 m_fsm.AddTransition(new WeaponTransition(m_hideB, __ck_, m_chamber, NULL, new WeaponGuardHasAmmoInnerMagazine(m_weapon)));
253 m_fsm.AddTransition(new WeaponTransition(m_hideB, __ck_, m_onCK));
254
255 m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, NULL));
256 m_fsm.AddTransition(new WeaponTransition(m_onBEFireOut, _fin_, NULL));
257 m_fsm.AddTransition(new WeaponTransition(m_onBE, _fin_, NULL));
258 m_fsm.AddTransition(new WeaponTransition(m_hideB, _fin_, NULL));
259 m_fsm.AddTransition(new WeaponTransition(m_onCK, _fin_, NULL));
260 m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
261
262 m_fsm.SetInitialState(m_start);
263 }
264
265 override void OnEntry(WeaponEventBase e)
266 {
267 super.OnEntry(e);
268 }
269 override void OnExit(WeaponEventBase e)
270 {
271 super.OnExit(e);
272 }
273};
274
275
279class WeaponChargingMultiple extends WeaponStateBase
280{
282 int m_actionType;
283
290
292 {
294 m_actionType = actionType;
295
296 // setup nested state machine
297 m_start = new WeaponCharging_Start(m_weapon, this, m_action, m_actionType);
298 m_onBE = new WeaponEjectBullet_Cartridge_W4T(m_weapon, this);
299 m_onBEFireOut = new WeaponEjectCasing_W4T(m_weapon, this);
300 m_hideB = new BulletHide_W4T(m_weapon, this);
301 m_onCK = new WeaponCharging_CK(m_weapon, this);
303
304 // events
305 WeaponEventBase __be_ = new WeaponEventAnimBulletEject;
306 WeaponEventBase __bh_ = new WeaponEventAnimBulletHide;
307 WeaponEventBase __ck_ = new WeaponEventAnimCocked;
308 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
309
310 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
311 // transitions
312 m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_onBEFireOut, NULL, new WeaponGuardCurrentChamberFiredOut(m_weapon)));
313 m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_onBE, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
314 m_fsm.AddTransition(new WeaponTransition(m_onBE, __bh_, m_hideB));
315 m_fsm.AddTransition(new WeaponTransition(m_onBEFireOut, __bh_, m_hideB));
316
317 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_onBE, NULL, new GuardNot(new WeaponGuardCurrentChamberEmpty(m_weapon))));
318 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon))); // some anims do not send BE event
319 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_onCK)); // some anims do not send BE event
320 m_fsm.AddTransition(new WeaponTransition(m_onBE, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
321 m_fsm.AddTransition(new WeaponTransition(m_onBE, __ck_, m_onCK));
322 m_fsm.AddTransition(new WeaponTransition(m_onBEFireOut, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
323 m_fsm.AddTransition(new WeaponTransition(m_onBEFireOut, __ck_, m_onCK));
324 m_fsm.AddTransition(new WeaponTransition(m_hideB, __ck_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
325 m_fsm.AddTransition(new WeaponTransition(m_hideB, __ck_, m_onCK));
326
327 m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, NULL));
328 m_fsm.AddTransition(new WeaponTransition(m_onBEFireOut, _fin_, NULL));
329 m_fsm.AddTransition(new WeaponTransition(m_onBE, _fin_, NULL));
330 m_fsm.AddTransition(new WeaponTransition(m_hideB, _fin_, NULL));
331 m_fsm.AddTransition(new WeaponTransition(m_onCK, _fin_, NULL));
332 m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
333
334 m_fsm.SetInitialState(m_start);
335 }
336
337 override void OnEntry(WeaponEventBase e)
338 {
339 super.OnEntry(e);
340 }
341 override void OnExit(WeaponEventBase e)
342 {
343 super.OnExit(e);
344 }
345};
346
350class WeaponChargingStretch extends WeaponStateBase
351{
353 int m_actionType;
354
357
359 {
361 m_actionType = actionType;
362
363 // setup nested state machine
364 m_start = new WeaponCharging_Start(m_weapon, this, m_action, m_actionType);
365 m_onCK = new WeaponCharging_CK(m_weapon, this);
366
367 // events
368 WeaponEventBase __ck_ = new WeaponEventAnimCocked;
369 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
370
371 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
372 // transitions
373 m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, NULL));
374 m_fsm.AddTransition(new WeaponTransition(m_start, __ck_, m_onCK)); // some anims do not send BE event
375 m_fsm.AddTransition(new WeaponTransition(m_onCK, _fin_, NULL));
376
377 m_fsm.SetInitialState(m_start);
378 }
379};
380
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition Guards.c:602
void WeaponGuardHasAmmo(Weapon_Base w=NULL)
Definition Guards.c:99
enum FSMTransition WeaponTransition
ref WeaponStateBase m_start
class WeaponEndAction extends WeaponStartAction m_action
ref WeaponChambering_Base m_chamber
ref WeaponEjectCasingMultiMuzzle m_eject
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
charging of weapon without ammo to be chambered
signalize mechanism manipulation
Definition Events.c:35
weapon finite state machine
simple class starting animation action specified by m_action and m_actionType
override bool IsWaitingForActionFinish()
represent weapon state base
Definition BulletHide.c:2
ref BulletHide_W4T m_hideB
ref WeaponEjectAndChamberFromAttMag m_ejectChamber
int m_actionType
action to be played
void WeaponChargingMultiple(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
ref WeaponEjectBullet_Cartridge_W4T m_onBE
ref WeaponChamberFromInnerMag_W4T m_chamber
WeaponActions m_action
ref WeaponCharging_Start m_start
ref WeaponChambering_Cartridge m_chamber
override bool IsWaitingForActionFinish()
override void OnEntry(WeaponEventBase e)
void WeaponChargingInnerMag(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
ref WeaponCharging_CK m_onCK
ref WeaponStateBase m_start
source of the cartridge
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
ref WeaponEjectCasing_W4T m_onBEFireOut
override void OnAbort(WeaponEventBase e)
void WeaponChargingStretch(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
void WeaponCharging(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
override void OnExit(WeaponEventBase e)
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
WeaponActions
actions
Definition human.c:796
void ejectBulletAndStoreInMagazine(Weapon_Base weapon, int muzzleIndex, Magazine mag, DayZPlayer p)