DayZ 1.24
Loading...
Searching...
No Matches
WeaponUnjamming.c
Go to the documentation of this file.
2{
3 override bool IsWaitingForActionFinish() { return true; }
4};
5
7{
8 override bool IsWaitingForActionFinish() { return true; }
9};
10
11class WeaponUnjamming_Start extends WeaponStartAction
12{
13 float m_dtAccumulator;
14 float m_jamTime;
15
17 {
18 m_dtAccumulator = 0.0;
19 m_jamTime = 0.0;
20 }
21
22 override void OnEntry(WeaponEventBase e)
23 {
24 super.OnEntry(e);
25 }
26
27 override void OnUpdate(float dt)
28 {
30
32 Class.CastTo(p, m_weapon.GetHierarchyParent());
33 if (p)
34 {
35 HumanInputController hic = p.GetInputController();
36 HumanCommandWeapons hcw = p.GetCommandModifier_Weapons();
37
38 if (m_dtAccumulator >= m_jamTime)
39 {
40 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " Unjammed!");
41 hcw.StartAction(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_END);
42 m_weapon.ProcessWeaponEvent(new WeaponEventUnjammingTimeout(p));
43 return; // unjammed successfuly
44 }
45
46
47 if (hic.IsReloadOrMechanismContinuousUse())
48 {
49 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " Unjamming...");
50 }
51#ifndef PLATFORM_CONSOLE
52#ifndef SERVER_FOR_CONSOLE
53 else
54 {
55 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " Unjamming failed, weapon still jammed");
56 hcw.StartAction(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_INTERRUPT);
57 m_weapon.ProcessWeaponEvent(new WeaponEventUnjammingFailedTimeout(p));
58 }
59#endif
60#endif
61 }
62 }
63
64 override void OnExit(WeaponEventBase e)
65 {
66 m_dtAccumulator = 0.0;
67 m_jamTime = 0.0;
68 super.OnExit(e);
69 }
70};
71
73{
74 float m_damage;
75 string m_type;
76
77 override void OnEntry(WeaponEventBase e)
78 {
79 super.OnEntry(e);
80 if (e)
81 {
82 m_type = string.Empty;
83
84 float dmg;
85 string type;
86
87 m_weapon.SetJammed(false);
88
89 int mi = m_weapon.GetCurrentMuzzle();
90
91 if (m_weapon.IsChamberFiredOut(mi))
92 {
93 m_weapon.EjectCasing(mi);
94 m_weapon.EffectBulletHide(mi);
95 m_weapon.SelectionBulletHide();
96 }
97
98 if (!m_weapon.IsChamberEmpty(mi))
99 {
100 DayZPlayer p = e.m_player;
101
102 m_weapon.CreateRound(mi);
104
105 m_weapon.EffectBulletHide(mi);
106 m_weapon.SelectionBulletHide();
107 }
108 }
109 }
110 override void OnExit(WeaponEventBase e)
111 {
112 m_type = string.Empty;
113 super.OnExit(e);
114 }
115
117 {
118 if (!super.SaveCurrentFSMState(ctx))
119 return false;
120
121 if (!ctx.Write(m_damage))
122 {
123 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponUnjamming_Cartridge.SaveCurrentFSMState: cannot write m_damage for weapon=" + m_weapon);
124 return false;
125 }
126 if (!ctx.Write(m_type))
127 {
128 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponUnjamming_Cartridge.SaveCurrentFSMState: cannot write m_type for weapon=" + m_weapon);
129 return false;
130 }
131 return true;
132 }
133
134 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
135 {
136 if (!super.LoadCurrentFSMState(ctx, version))
137 return false;
138
139 if (!ctx.Read(m_damage))
140 {
141 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponUnjamming_Cartridge.LoadCurrentFSMState: cannot read m_damage for weapon=" + m_weapon);
142 return false;
143 }
144 if (!ctx.Read(m_type))
145 {
146 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponUnjamming_Cartridge.LoadCurrentFSMState: cannot read m_type for weapon=" + m_weapon);
147 return false;
148 }
149 return true;
150 }
151
152};
153
155{
156 override bool IsWaitingForActionFinish() { return true; }
157};
158
160{
161 override bool IsWaitingForActionFinish() { return true; }
162};
163
164
169{
171 int m_actionType;
172 float m_dtAccumulator;
174
175 ref WeaponUnjamming_Start m_start;
179
181 {
183 m_actionType = actionType;
184
185 // setup nested state machine
186 m_start = new WeaponUnjamming_Start(m_weapon, this, m_action, m_actionType);
189 m_w4t = new WeaponUnjamming_W4T(m_weapon, this);
190
191 // events
192 WeaponEventBase _uto_ = new WeaponEventUnjammingTimeout;
193 WeaponEventBase _fto_ = new WeaponEventUnjammingFailedTimeout;
194 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
195 WeaponEventBase __uj_ = new WeaponEventAnimUnjammed;
196
197 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
198 // transitions
199 m_fsm.AddTransition(new WeaponTransition(m_start, _uto_, m_eject));
200 m_fsm.AddTransition(new WeaponTransition(m_start, _fto_, m_w4t));
201 m_fsm.AddTransition(new WeaponTransition(m_eject, __uj_, m_chamber, NULL, new WeaponGuardHasAmmo(m_weapon)));
202 m_fsm.AddTransition(new WeaponTransition(m_eject, _fin_, NULL));
203 m_fsm.AddTransition(new WeaponTransition(m_w4t, _fin_, NULL));
204 m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
205
206 // Safety exits
207 m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, null));
208
209 m_fsm.SetInitialState(m_start);
210 }
211
212 override void OnEntry(WeaponEventBase e)
213 {
214 super.OnEntry(e);
215 if (e)
216 {
217 m_dtAccumulator = 0.0;
218 m_jamTime = 5.0; // @TODO: rand
219
220 m_start.m_dtAccumulator = m_dtAccumulator;
221 m_start.m_jamTime = m_jamTime;
222 }
223 }
224
225 override void OnExit(WeaponEventBase e)
226 {
227 m_dtAccumulator = 0.0;
228 m_jamTime = 0.0;
229 super.OnExit(e);
230 }
231};
232
void wpnDebugPrint(string s)
Definition Debug.c:9
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
class WeaponFireWithEject extends WeaponFire m_dtAccumulator
Super root of all classes in Enforce script.
Definition EnScript.c:11
static bool IsWeaponLogEnable()
Definition Debug.c:799
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
override bool IsWaitingForActionFinish()
override bool IsWaitingForActionFinish()
signalize mechanism manipulation
Definition Events.c:35
weapon finite state machine
simple class starting animation action specified by m_action and m_actionType
void WeaponUnjamming_Start(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
override void OnEntry(WeaponEventBase e)
float m_dtAccumulator
Definition WeaponFire.c:4
override void OnExit(WeaponEventBase e)
override void OnUpdate(float dt)
represent weapon state base
Definition BulletHide.c:2
void WeaponUnjamming(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
ref WeaponUnjamming_W4T m_w4t
override bool IsWaitingForActionFinish()
override void OnEntry(WeaponEventBase e)
ref WeaponUnjamming_Cartridge_W4T m_eject
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
ref WeaponUnjamming_Start m_start
override void OnExit(WeaponEventBase e)
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
override bool IsWaitingForActionFinish()
unjam submachine
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.
static const string Empty
Definition EnString.c:7
WeaponActions
actions
Definition human.c:796
WeaponActionUnjammingTypes
Definition human.c:892
void ejectBulletAndStoreInMagazine(Weapon_Base weapon, int muzzleIndex, Magazine mag, DayZPlayer p)