Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
repeater.c
Go to the documentation of this file.
2 {
3  DEFAULT = 0,
4  CHARGED = 1,
5  JAMMED = 2,
6 };
7 
9 {
10  UNKNOWN = 0,
11  EmptyDischarged = 1,
12  LoadedCharged = 2,
13  LoadedDischarged = 3,
14  LoadedJammed = 4,
15 }
16 
17 
18 class RPTEmptyDischarged extends WeaponStableState
19 {
20  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { EmptyDischarged C0"); } super.OnEntry(e); }
21  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } EmptyDischarged C0"); } }
22  override int GetCurrentStateID () { return RPTStableStateID.EmptyDischarged; }
23  override bool HasBullet () { return false; }
24  override bool HasMagazine () { return false; }
25  override bool IsJammed () { return false; }
26  override bool IsRepairEnabled () { return true; }
27  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.E}; }
28 };
29 class RPTLoadedCharged extends WeaponStableState
30 {
31  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { LoadedCharged C1"); } super.OnEntry(e); }
32  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } LoadedCharged C1"); } }
33  override int GetCurrentStateID () { return RPTStableStateID.LoadedCharged; }
34  override bool HasBullet () { return true; }
35  override bool HasMagazine () { return false; }
36  override bool IsJammed () { return false; }
37  override bool IsRepairEnabled () { return true; }
38  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.L}; }
39 };
40 class RPTLoadedDischarged extends WeaponStableState
41 {
42  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { LoadedDischarged D1"); } super.OnEntry(e); }
43  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } LoadedDischarged D1"); } }
44  override int GetCurrentStateID () { return RPTStableStateID.LoadedDischarged; }
45  override bool HasBullet () { return true; }
46  override bool HasMagazine () { return false; }
47  override bool IsJammed () { return false; }
48  override bool IsRepairEnabled () { return true; }
49  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.F}; }
50 };
51 class RPTLoadedJammed extends WeaponStateJammed
52 {
53  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { LoadedJammed JF"); } super.OnEntry(e); }
54  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } LoadedJammed JF"); } }
55  override int GetCurrentStateID () { return RPTStableStateID.LoadedJammed; }
56  override bool HasBullet () { return true; }
57  override bool HasMagazine () { return false; }
58  override bool IsJammed () { return true; }
59  override bool IsRepairEnabled () { return true; }
60  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.F}; }
61 };
62 
66 class Repeater_Base extends Rifle_Base
67 {
68  ref WeaponStableState D0;
69  ref WeaponStableState C0;
70  ref WeaponStableState C1;
71  ref WeaponStableState DF;
72  ref WeaponStableState JF;
73 
74 
75  override void InitStateMachine ()
76  {
77  m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED));
78  m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_OPENED));
79  m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_SHOTGUN_COCKED));
80  m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_SHOTGUN_UNCOCKED));
81  m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE));
82  m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_START));
83  m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_END));
84  m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL));
85  m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED));
86  m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_UNCOCKED));
87  m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_DRY));
88 
89  D0 = new RPTEmptyDischarged(this, NULL, RPTAnimState.DEFAULT);
90  C0 = new RPTEmptyDischarged(this, NULL, RPTAnimState.CHARGED);
91  DF = new RPTLoadedDischarged(this, NULL, RPTAnimState.DEFAULT);
92  C1 = new RPTLoadedCharged(this, NULL, RPTAnimState.CHARGED);
93  JF = new RPTLoadedJammed(this, NULL, RPTAnimState.JAMMED);
94 
95  //WeaponStateBase Mech_D0 = new WeaponChargingInnerMag(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
96  WeaponStateBase Mech_C1 = new WeaponChargingInnerMag(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_OPENED);
97  WeaponStateBase Mech_DF = new WeaponChargingInnerMag(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
98 
99  LoopedChamberingEjectLast Chamber_D0 = new LoopedChamberingEjectLast(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_SHOTGUN_UNCOCKED, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE);
100  LoopedChamberingEjectLast Chamber_C0 = new LoopedChamberingEjectLast(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_SHOTGUN_UNCOCKED, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE);
101  LoopedChamberingEjectLast Chamber_C1 = new LoopedChamberingEjectLast(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_SHOTGUN_COCKED, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE);
102  LoopedChamberingEjectLast Chamber_DF = new LoopedChamberingEjectLast(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_SHOTGUN_UNCOCKED, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE);
103 
104  WeaponStateBase Unjam_JF = new WeaponUnjamming(this, NULL, WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_START);
105 
106  WeaponStateBase Trigger_D0 = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_DRY);
107  WeaponStateBase Trigger_C0 = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL);
108  WeaponStateBase Trigger_C1 = new WeaponFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL);
109  WeaponStateBase Trigger_DF = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_DRY);
110  WeaponStateBase Trigger_JF = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_DRY);
111 
112  WeaponStateBase Trigger_C1J = new WeaponFireToJam(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_JAM);
113 
114 
115  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
116  WeaponEventBase __L__ = new WeaponEventLoad1Bullet;
117  WeaponEventBase __T__ = new WeaponEventTrigger;
118  WeaponEventBase __TJ_ = new WeaponEventTriggerToJam;
119  WeaponEventBase __U__ = new WeaponEventUnjam;
120  WeaponEventBase __M__ = new WeaponEventMechanism;
121  WeaponEventBase _abt_ = new WeaponEventHumanCommandActionAborted;
122  WeaponEventBase _rto_ = new WeaponEventReloadTimeout;
123  WeaponEventBase _dto_ = new WeaponEventDryFireTimeout;
124 
125  m_fsm = new WeaponFSM();
126 
127  // Mechanism
128 //----------------------------------------
129  m_fsm.AddTransition(new WeaponTransition( D0, __M__, Mech_DF));
130  m_fsm.AddTransition(new WeaponTransition( C0, __M__, Mech_C1));
131 
132  m_fsm.AddTransition(new WeaponTransition( C1, __M__, Mech_C1));
133  m_fsm.AddTransition(new WeaponTransition( Mech_C1, _fin_, C0, NULL, new WeaponGuardCurrentChamberEmpty(this)));
134  m_fsm.AddTransition(new WeaponTransition( Mech_C1, _fin_, C1));
135  m_fsm.AddTransition(new WeaponTransition( Mech_C1, _abt_, C0, NULL, new WeaponGuardCurrentChamberEmpty(this)));
136  m_fsm.AddTransition(new WeaponTransition( Mech_C1, _abt_, C1));
137 
138  m_fsm.AddTransition(new WeaponTransition( DF, __M__, Mech_DF));
139  m_fsm.AddTransition(new WeaponTransition( Mech_DF, _fin_, C0, NULL, new WeaponGuardCurrentChamberEmpty(this)));
140  m_fsm.AddTransition(new WeaponTransition( Mech_DF, _fin_, DF, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
141  m_fsm.AddTransition(new WeaponTransition( Mech_DF, _fin_, C1));
142  m_fsm.AddTransition(new WeaponTransition( Mech_DF, _abt_, C0, NULL, new WeaponGuardCurrentChamberEmpty(this)));
143  m_fsm.AddTransition(new WeaponTransition( Mech_DF, _abt_, DF, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
144  m_fsm.AddTransition(new WeaponTransition( Mech_DF, _abt_, C1));
145 
146 
147 //----------------------------------------
148  m_fsm.AddTransition(new WeaponTransition( C0, __L__, Chamber_D0));
149 
150  m_fsm.AddTransition(new WeaponTransition( D0, __L__, Chamber_D0));
151  m_fsm.AddTransition(new WeaponTransition( Chamber_D0, _fin_, C1));
152  m_fsm.AddTransition(new WeaponTransition( Chamber_D0, _abt_, C0, NULL, new WeaponGuardCurrentChamberEmpty(this)));
153  m_fsm.AddTransition(new WeaponTransition( Chamber_D0, _abt_, C1));
154 
155  m_fsm.AddTransition(new WeaponTransition( C1, __L__, Chamber_C1, NULL, new GuardNot(new WeaponGuardInnerMagazineFull(this))));
156  m_fsm.AddTransition(new WeaponTransition( Chamber_C1, _fin_, C1));
157  m_fsm.AddTransition(new WeaponTransition( Chamber_C1, _abt_, C1));
158 
159  m_fsm.AddTransition(new WeaponTransition( DF, __L__, Chamber_DF, NULL, new GuardNot(new WeaponGuardInnerMagazineFull(this))));
160  m_fsm.AddTransition(new WeaponTransition( Chamber_DF, _fin_, C1));
161  m_fsm.AddTransition(new WeaponTransition( Chamber_DF, _abt_, DF, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
162  m_fsm.AddTransition(new WeaponTransition( Chamber_DF, _abt_, C1));
163 
164 //------------------------------------------
165 
166  m_fsm.AddTransition(new WeaponTransition( JF, __U__, Unjam_JF));
167  m_fsm.AddTransition(new WeaponTransition( Unjam_JF, _fin_, JF, NULL, new WeaponGuardJammed(this)));
168  m_fsm.AddTransition(new WeaponTransition( Unjam_JF, _fin_, C0, NULL, new WeaponGuardCurrentChamberEmpty(this)));
169  m_fsm.AddTransition(new WeaponTransition( Unjam_JF, _fin_, C1));
170  m_fsm.AddTransition(new WeaponTransition( Unjam_JF, _abt_, JF, NULL, new WeaponGuardJammed(this)));
171  m_fsm.AddTransition(new WeaponTransition( Unjam_JF, _abt_, C0, NULL, new WeaponGuardCurrentChamberEmpty(this)));
172  m_fsm.AddTransition(new WeaponTransition( Unjam_JF, _abt_, C1));
173 
174 
175 //-----------------------------------------
176 
177  // fire
178  m_fsm.AddTransition(new WeaponTransition( D0, __T__, Trigger_D0)); // fire.cocked
179  m_fsm.AddTransition(new WeaponTransition( Trigger_D0, _fin_, D0));
180  m_fsm.AddTransition(new WeaponTransition( Trigger_D0, _dto_, D0));
181  m_fsm.AddTransition(new WeaponTransition( Trigger_D0, _abt_, D0));
182 
183  m_fsm.AddTransition(new WeaponTransition( C0, __T__, Trigger_C0)); // fire.cocked
184  m_fsm.AddTransition(new WeaponTransition( Trigger_C0, _fin_, D0));
185  m_fsm.AddTransition(new WeaponTransition( Trigger_C0, _dto_, D0));
186  m_fsm.AddTransition(new WeaponTransition( Trigger_C0, _abt_, D0));
187 
188  m_fsm.AddTransition(new WeaponTransition( C1, __T__, Trigger_C1)); // fire.cocked
189  m_fsm.AddTransition(new WeaponTransition( Trigger_C1, _fin_, DF));
190  m_fsm.AddTransition(new WeaponTransition( Trigger_C1, _rto_, DF));
191  m_fsm.AddTransition(new WeaponTransition( Trigger_C1, _abt_, DF));
192 
193  m_fsm.AddTransition(new WeaponTransition( DF, __T__, Trigger_DF)); // fire.cocked
194  m_fsm.AddTransition(new WeaponTransition( Trigger_DF, _fin_, DF));
195  m_fsm.AddTransition(new WeaponTransition( Trigger_DF, _dto_, DF));
196  m_fsm.AddTransition(new WeaponTransition( Trigger_DF, _abt_, DF));
197 
198  m_fsm.AddTransition(new WeaponTransition( JF, __T__, Trigger_JF)); // fire.cocked
199  m_fsm.AddTransition(new WeaponTransition( Trigger_JF, _fin_, JF));
200  m_fsm.AddTransition(new WeaponTransition( Trigger_JF, _dto_, JF));
201  m_fsm.AddTransition(new WeaponTransition( Trigger_JF, _abt_, JF));
202 
203 
204  m_fsm.AddTransition(new WeaponTransition( JF, __TJ_, Trigger_C1J)); // fire.cocked
205  m_fsm.AddTransition(new WeaponTransition( Trigger_C1J, _fin_, JF));
206  m_fsm.AddTransition(new WeaponTransition( Trigger_C1J, _rto_, JF));
207  m_fsm.AddTransition(new WeaponTransition( Trigger_C1J, _abt_, JF));
208 
209 //---------------------------------------------
210 
211  SetInitialState(D0);
212 
213  SelectionBulletHide();
214  HideMagazine();
215 
216  m_fsm.Start();
217  }
218 
219  override bool CanChamberBullet (int muzzleIndex, Magazine mag)
220  {
221  return CanChamberFromMag(muzzleIndex, mag) && !IsInternalMagazineFull(muzzleIndex);
222  }
223 
224  override void SetActions()
225  {
226  super.SetActions();
228 
231 
232  }
233 };
234 
235 class Repeater : Repeater_Base
236 {
237  override RecoilBase SpawnRecoilObject()
238  {
239  return new RepeaterRecoil(this);
240  }
241 
242 
243  //Debug menu Spawn Ground Special
244  override void OnDebugSpawn()
245  {
246  super.OnDebugSpawn();
247 
248  EntityAI entity;
249  if ( Class.CastTo(entity, this) )
250  {
251  entity.SpawnEntityOnGroundPos("Ammo_357", entity.GetPosition());
252  }
253  }
254 };
EmptyDischarged
EmptyDischarged
Definition: repeater.c:3
GetCurrentStateID
override int GetCurrentStateID()
Definition: repeater.c:22
LogManager
Definition: debug.c:734
RPTAnimState
RPTAnimState
Definition: repeater.c:1
HasMagazine
override bool HasMagazine()
Definition: repeater.c:24
InitMuzzleArray
override void InitMuzzleArray()
Definition: repeater.c:27
RepeaterRecoil
Definition: repeaterrecoil.c:1
WeaponActionUnjammingTypes
WeaponActionUnjammingTypes
Definition: human.c:904
FirearmActionLoadMultiBullet
Definition: firearmactionloadmultibullet.c:1
FirearmActionLoadBulletQuick
FirearmActionLoadMultiBullet FirearmActionLoadBulletQuick
WeaponFire
Definition: weaponfire.c:98
RemoveAction
void RemoveAction(typename actionName)
Definition: advancedcommunication.c:118
FirearmActionLoadMultiBulletQuick
Definition: firearmactionloadmultibullet.c:94
WeaponActionFireTypes
WeaponActionFireTypes
Definition: human.c:912
CHARGED
@ CHARGED
Definition: repeater.c:4
JAMMED
@ JAMMED
Definition: repeater.c:5
OnEntry
class RPTLoadedCharged extends WeaponStableState OnEntry
UNKNOWN
UNKNOWN
Definition: repeater.c:2
WeaponActions
WeaponActions
actions
Definition: human.c:808
LoadedJammed
LoadedJammed
Definition: repeater.c:6
RPTStableStateID
RPTStableStateID
Definition: repeater.c:8
RecoilBase
Definition: recoilbase.c:1
WeaponUnjamming
unjam submachine
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Object
Definition: objecttyped.c:1
m_muzzleHasBullet
ref array< MuzzleState > m_muzzleHasBullet
Definition: weaponstablestate.c:30
Rifle_Base
base for rifles @NOTE name copies config base class
Definition: sks.c:69
SetActions
void SetActions()
Definition: advancedcommunication.c:79
WeaponTransition
enum FSMTransition WeaponTransition
IsRepairEnabled
override bool IsRepairEnabled()
Definition: repeater.c:26
IsJammed
override bool IsJammed()
Definition: repeater.c:25
Repeater
Definition: repeater.c:235
AbilityRecord
pair ( action, actionType )
Definition: weapon_base.c:4
OnExit
override void OnExit(WeaponEventBase e)
Definition: repeater.c:21
DEFAULT
@ DEFAULT
default weapon state, closed and discharged
Definition: repeater.c:3
WeaponEventBase
signalize mechanism manipulation
Definition: events.c:34
WeaponStateBase
represent weapon state base
Definition: bullethide.c:1
m_weapon
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition: guards.c:583
WeaponStateJammed
handle jamming state set jam/unjam state for weapon
Definition: sks.c:52
wpnPrint
void wpnPrint(string s)
Definition: debug.c:1
LoadedDischarged
LoadedDischarged
Definition: repeater.c:5
WeaponActionChamberingTypes
WeaponActionChamberingTypes
Definition: human.c:868
WeaponFSM
weapon finite state machine
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5
LoadedCharged
LoadedCharged
Definition: repeater.c:4
HasBullet
override bool HasBullet()
Definition: repeater.c:23
WeaponStableState
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
Definition: crossbow.c:26
MuzzleState
MuzzleState
Definition: weaponstablestate.c:14