DayZ 1.24
Loading...
Searching...
No Matches
Magnum.c
Go to the documentation of this file.
1const float MAGNUM_ROTATION_POSITION_M1 = -0.167;
2const float MAGNUM_ROTATION_POSITION_0 = 0.0;
3const float MAGNUM_ROTATION_POSITION_1 = 0.167;
4const float MAGNUM_ROTATION_POSITION_2 = 0.334;
5const float MAGNUM_ROTATION_POSITION_3 = 0.500;
6const float MAGNUM_ROTATION_POSITION_4 = 0.668;
7const float MAGNUM_ROTATION_POSITION_5 = 0.835;
8const float MAGNUM_ROTATION_POSITION_6 = 1.0;
9
10
12{
13 DEFAULT = 0,
14};
15
17{
19 DEFAULT = 1,
20}
21
23{
24 bool init = false;
25 override void OnEntry(WeaponEventBase e)
26 {
27 if (LogManager.IsWeaponLogEnable()) wpnPrint("[wpnstate] { Magnum stable state");
28 super.OnEntry(e);
29 if (init)
30 {
32 if (CastTo(magnum, m_weapon))
33 {
34 magnum.SyncCylinderRotation();
35 //magnum.SyncSelectionStateFromState();
36 }
37 }
38 init = true;
39 }
40 override void OnExit(WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) wpnPrint("[wpnstate] } Magnum stable state"); }
41 override int GetCurrentStateID() { return MagnumStableStateID.DEFAULT; }
42 override bool HasBullet() { return m_weapon.IsChamberFull(m_weapon.GetCurrentMuzzle()); }
43 override bool HasMagazine() { return false; }
44 override bool IsJammed() { return m_weapon.IsJammed(); }
45 override bool IsSingleState() { return true; }
46};
47
48
49class Magnum_Base extends Weapon_Base
50{
54 const string ATT_SLOT_CYLINDER = "RevolverCylinder";
55 const string ATT_SLOT_EJECTOR = "RevolverEjector";
56
57 override void SetActions()
58 {
59 super.SetActions();
61
64
65 }
66
68 {
69 return new MagnumRecoil(this);
70 }
71
73 {
74 m_LastMuzzleloaded = 0;
75 m_ActiveMuzzle = 0;
76
77 /*m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionTypes.CHAMBERING_STARTLOOPABLE_CLOSED));
78 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionTypes.CHAMBERING_ENDLOOPABLE));
79 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionTypes.MECHANISM_CLOSED));
80 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionTypes.MECHANISM_SPECIAL));
81 m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionTypes.UNJAMMING_START));
82 m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionTypes.UNJAMMING_END));
83 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionTypes.FIRE_NORMAL));
84 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionTypes.FIRE_COCKED));*/
85 }
86
87 override void InitStateMachine()
88 {
89 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_CLOSED));
90 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_CLOSED_KEEP));
91 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE));
92 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED));
93 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_SPECIAL));
94 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL));
95 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED));
96 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_UNCOCKED));
97
98
99 // setup state machine
100 // basic weapon state
101 C = new Magnum_Static_State(this, NULL, MagnumAnimState.DEFAULT);
102
103
104 WeaponMagnumChambering Chamber = new WeaponMagnumChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_CLOSED_KEEP, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE);
105 WeaponMagnumChambering Chamber_E = new WeaponMagnumChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_CLOSED, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE);
106 //WeaponMagnumChambering Chamber_CC00 = new WeaponMagnumChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_END);
107
108 WeaponCharging Mech = new WeaponCharging(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
109
112
113 // events
114
115 WeaponEventBase __L__ = new WeaponEventLoad1Bullet;
116 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
117 WeaponEventBase _abt_ = new WeaponEventHumanCommandActionAborted;
118 WeaponEventBase __M__ = new WeaponEventMechanism;
119 WeaponEventBase __T__ = new WeaponEventTrigger;
120
121
122 WeaponEventBase _rto_ = new WeaponEventReloadTimeout;
123 WeaponEventBase _dto_ = new WeaponEventDryFireTimeout;
124
125
126 m_fsm = new WeaponFSM();
127
128
129 m_fsm.AddTransition(new WeaponTransition(C, __L__, Chamber, null, new WeaponGuardAnyChamberFiredOut(this))); // chamber from closed charged
130 m_fsm.AddTransition(new WeaponTransition(Chamber, _fin_, C));
131 m_fsm.AddTransition(new WeaponTransition(Chamber, _abt_, C));
132
133
134 m_fsm.AddTransition(new WeaponTransition(C, __L__, Chamber_E)); // chamber from closed charged
135 m_fsm.AddTransition(new WeaponTransition(Chamber_E, _fin_, C));
136 m_fsm.AddTransition(new WeaponTransition(Chamber_E, _abt_, C));
137
138
139 m_fsm.AddTransition(new WeaponTransition(C, __M__, Mech)); // charge from closed
140 m_fsm.AddTransition(new WeaponTransition(Mech, _fin_, C));
141 m_fsm.AddTransition(new WeaponTransition(Mech, _abt_, C));
142
143
144 m_fsm.AddTransition(new WeaponTransition(C, __T__, Trigger_normal, null, new GuardAnd(new WeaponGuardCurrentChamberFull(this), new GuardNot(new WeaponGuardCurrentChamberFiredOut(this))))); // fire.cocked
145 m_fsm.AddTransition(new WeaponTransition(Trigger_normal, _fin_, C));
146 m_fsm.AddTransition(new WeaponTransition(Trigger_normal, _dto_, C));
147 m_fsm.AddTransition(new WeaponTransition(Trigger_normal, _abt_, C));
148
149 m_fsm.AddTransition(new WeaponTransition(C, __T__, Trigger_dry)); // fire.cocked
150 m_fsm.AddTransition(new WeaponTransition(Trigger_dry, _fin_, C));
151 m_fsm.AddTransition(new WeaponTransition(Trigger_dry, _dto_, C));
152 m_fsm.AddTransition(new WeaponTransition(Trigger_dry, _abt_, C));
153
154
155 SetInitialState(C);
156 SelectionBulletHide();
157 SetCurrentMuzzle(0);
158 //HideMagazine();
159 m_fsm.Start();
160 }
161
163 {
164 for (int i = 0; i < GetMuzzleCount(); i++)
165 {
166 if (CanChamberFromMag(i, mag))
167 {
168 if (IsChamberEmpty(i))
169 return true;
170
171 if (IsChamberFiredOut(i))
172 return true;
173 }
174 }
175 return false;
176 }
177
178 override void AssembleGun()
179 {
180 super.AssembleGun();
181
182 if (!FindAttachmentBySlotName(ATT_SLOT_EJECTOR))
183 GetInventory().CreateAttachment("Magnum_Ejector");
184
185 if (!FindAttachmentBySlotName(ATT_SLOT_CYLINDER))
186 GetInventory().CreateAttachment("Magnum_Cylinder");
187
188 ForceSyncSelectionState();
189 SyncCylinderRotation();
190 }
191
193 {
194 switch (muzzleIndex)
195 {
196 case 0:
198 case 1:
200 case 2:
202 case 3:
204 case 4:
206 case 5:
208 }
209
210 ErrorEx(string.Format("Invalid muzzle index: %1", muzzleIndex));
211
213 }
214
215 void SetCylinderRotationAnimationPhase(float rot, bool reset = false)
216 {
217 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
218 Magnum_Ejector ejector = Magnum_Ejector.Cast(GetAttachmentByType(Magnum_Ejector));
219 if (cylinder && ejector)
220 {
221 float anim_phase = cylinder.GetAnimationPhase("Rotate_Cylinder");
222 if (Math.AbsFloat(anim_phase - rot) > 0.1)
223 {
224 if (reset)
225 {
226 cylinder.ResetAnimationPhase("Rotate_Cylinder", rot);
227 ejector.ResetAnimationPhase("Rotate_Ejector", rot);
228 }
230 {
231 cylinder.ResetAnimationPhase("Rotate_Cylinder", MAGNUM_ROTATION_POSITION_M1);
232 ejector.ResetAnimationPhase("Rotate_Ejector", MAGNUM_ROTATION_POSITION_M1);
233 }
234
235 cylinder.SetAnimationPhase("Rotate_Cylinder", rot);
236 ejector.SetAnimationPhase("Rotate_Ejector", rot);
237 }
238 }
239 }
240
241 void SyncCylinderRotation(bool reset = true)
242 {
243 SetCylinderRotationAnimationPhase(GetCylinderRotation(GetCurrentMuzzle()), reset);
244 }
245
246 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
247 {
248 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
249
250 if (GetGame().IsClient())
251 return;
252
253 SetAttachmentsHealth();
254 }
255
256 //sets health of cylinder and ejector objects
258 {
261 for (int i = 0; i < GetInventory().AttachmentCount(); i++)
262 {
263 entity = GetInventory().GetAttachmentFromIndex(i);
265 attachment.SetHealth01("", "Health", GetHealth01());
266 }
267 }
268
269 override void OnFire(int muzzle_index)
270 {
271 super.OnFire(muzzle_index);
272 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
273 if (cylinder)
274 {
275 string bullet_nose = "bullet_nose";
276 if (muzzle_index > 0)
277 bullet_nose = string.Format("bullet_nose_" + (muzzle_index + 1));
278 cylinder.HideSelection(bullet_nose);
279 }
280 }
281
283 {
284 return false;
285 }
286
287 override bool CanEjectBullet()
288 {
289 for (int i = 0; i < GetMuzzleCount(); i++)
290 {
291 if (IsChamberFull(i))
292 return true;
293 }
294 return false;
295 }
296
297 override void ShowBullet(int muzzleIndex)
298 {
299 super.ShowBullet(muzzleIndex);
300
301 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
302 if (cylinder)
303 {
304 string bullet = "bullet";
305 if (muzzleIndex > 0)
306 bullet = string.Format("bullet_" + (muzzleIndex + 1));
307
308 cylinder.ShowSelection(bullet);
309
311 {
312 string bullet_nose = "bullet_nose";
313 if (muzzleIndex > 0)
314 bullet_nose = string.Format("bullet_nose_" + (muzzleIndex + 1));
315 cylinder.ShowSelection(bullet_nose);
316 }
317 }
318 }
319
320 override void HideBullet(int muzzleIndex)
321 {
322 super.HideBullet(muzzleIndex);
323
324 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
325 if (cylinder)
326 {
327 string bullet = "bullet";
328 if (muzzleIndex > 0)
329 bullet = string.Format("bullet_" + (muzzleIndex + 1));
330
331 cylinder.HideSelection(bullet);
332
333 string bullet_nose = "bullet_nose";
334 if (muzzleIndex > 0)
335 bullet_nose = string.Format("bullet_nose_" + (muzzleIndex + 1));
336 cylinder.HideSelection(bullet_nose);
337 }
338 }
339
340 //Debug menu Spawn Ground Special
341 override void OnDebugSpawn()
342 {
343 super.OnDebugSpawn();
344
346 if (Class.CastTo(entity, this))
347 entity.SpawnEntityOnGroundPos("Ammo_357", entity.GetPosition());
348 }
349};
350
351class Magnum extends Magnum_Base
352{
354 {
355 super.GetDebugActions(outputList);
356
357 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.LIGHT_GREY));
359 }
360
362 {
363 if (GetGame().IsServer())
364 {
365 if (action_id == EActions.SPIN)
366 {
367 const float animPhaseOffset = 0.167;
368
369 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
370 Magnum_Ejector ejector = Magnum_Ejector.Cast(GetAttachmentByType(Magnum_Ejector));
371
372 if (cylinder)
373 {
374 float animPhase = cylinder.GetAnimationPhase("Rotate_Cylinder");
375 if (animPhase + animPhaseOffset > 1.0)
376 {
377 animPhase -= 1.0;
378 cylinder.ResetAnimationPhase("Rotate_Cylinder", animPhase);
379 ejector.ResetAnimationPhase("Rotate_Ejector", animPhase);
380 }
381
382 cylinder.SetAnimationPhase("Rotate_Cylinder", animPhase);
383 ejector.ResetAnimationPhase("Rotate_Ejector", animPhase);
384 }
385 }
386 }
387
388 return super.OnAction(action_id, player, ctx);
389 }
390}
391
393class Magnum_Cylinder extends DummyItem {};
394class Magnum_Ejector extends DummyItem {};
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition EntityAI.c:97
void wpnPrint(string s)
Definition Debug.c:1
void AddAction(typename actionName)
void RemoveAction(typename actionName)
override bool IsJammed()
Definition Crossbow.c:22
override bool HasBullet()
Definition Crossbow.c:20
override bool HasMagazine()
Definition Crossbow.c:21
EActions
Definition EActions.c:2
FirearmActionLoadBullet FirearmActionBase FirearmActionLoadBulletQuick()
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition Guards.c:602
override int GetCurrentStateID()
Definition Hand_States.c:29
override void OnExit(HandEventBase e)
Definition Hand_States.c:28
HandStateEquipped OnEntry
enum MagnumStableStateID init
const float MAGNUM_ROTATION_POSITION_2
Definition Magnum.c:4
const float MAGNUM_ROTATION_POSITION_1
Definition Magnum.c:3
const float MAGNUM_ROTATION_POSITION_3
Definition Magnum.c:5
const float MAGNUM_ROTATION_POSITION_4
Definition Magnum.c:6
const float MAGNUM_ROTATION_POSITION_6
Definition Magnum.c:8
MagnumStableStateID
Definition Magnum.c:17
@ UNKNOWN
Definition Magnum.c:18
@ DEFAULT
default weapon state
Definition Magnum.c:13
MagnumAnimState
Definition Magnum.c:12
const float MAGNUM_ROTATION_POSITION_M1
Definition Magnum.c:1
const float MAGNUM_ROTATION_POSITION_5
Definition Magnum.c:7
const float MAGNUM_ROTATION_POSITION_0
Definition Magnum.c:2
enum FSMTransition WeaponTransition
bool IsSingleState()
Special one for when the weapon only has one singular state (like Magnum)
bool IsChamberFiredOut(int idx)
bool IsChamberFull(int idx)
pair ( action, actionType )
Definition Weapon_Base.c:5
Super root of all classes in Enforce script.
Definition EnScript.c:11
static bool IsWeaponLogEnable()
Definition Debug.c:799
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition Magnum.c:361
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition Magnum.c:353
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
int m_LastMuzzleloaded
Definition Magnum.c:52
override void InitStateMachine()
Definition Magnum.c:87
override void HideBullet(int muzzleIndex)
Definition Magnum.c:320
ref WeaponStableState C
Definition Magnum.c:51
override RecoilBase SpawnRecoilObject()
Definition Magnum.c:67
override bool IsShowingChamberedBullet()
Definition Magnum.c:282
override void ShowBullet(int muzzleIndex)
Definition Magnum.c:297
override void AssembleGun()
Definition Magnum.c:178
int m_ActiveMuzzle
Definition Magnum.c:53
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition Magnum.c:246
override void SetActions()
Definition Magnum.c:57
void SyncCylinderRotation(bool reset=true)
Definition Magnum.c:241
override bool CanEjectBullet()
Definition Magnum.c:287
static float GetCylinderRotation(int muzzleIndex)
Definition Magnum.c:192
override bool CanChamberBullet(int muzzleIndex, Magazine mag)
Definition Magnum.c:162
override void OnFire(int muzzle_index)
Definition Magnum.c:269
override void OnDebugSpawn()
Definition Magnum.c:341
void SetCylinderRotationAnimationPhase(float rot, bool reset=false)
Definition Magnum.c:215
void Magnum_Base()
Definition Magnum.c:72
void SetAttachmentsHealth()
Definition Magnum.c:257
charging of weapon without ammo to be chambered
signalize mechanism manipulation
Definition Events.c:35
weapon finite state machine
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
Definition Crossbow.c:27
represent weapon state base
Definition BulletHide.c:2
proto native CGame GetGame()
enum ShapeType ErrorEx
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float AbsFloat(float f)
Returns absolute value.
const int SAT_DEBUG_ACTION
Definition constants.c:424
WeaponActionChamberingTypes
Definition human.c:856
WeaponActions
actions
Definition human.c:796
WeaponActionFireTypes
Definition human.c:900