Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
riflesingleshot_base.c
Go to the documentation of this file.
2 {
3  DEFAULT = 0,
4 };
5 
7 {
8  UNKNOWN = 0,
9  Empty = 1,
10  Fireout = 2,
11  Loaded = 3,
12  Jammed = 4,
13 }
14 
15 class RSSEmpty extends WeaponStableState
16 {
17  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Empty E"); } super.OnEntry(e); }
18  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Empty E"); } }
19  override int GetCurrentStateID () { return RSSStableStateID.Empty; }
20  override bool HasBullet () { return false; }
21  override bool HasMagazine () { return false; }
22  override bool IsJammed () { return false; }
23  override bool IsRepairEnabled () { return true; }
24  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.E}; }
25 };
26 class RSSFireout extends WeaponStableState
27 {
28  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Fireout F"); } super.OnEntry(e); }
29  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Fireout F"); } }
30  override int GetCurrentStateID () { return RSSStableStateID.Fireout; }
31  override bool HasBullet () { return true; }
32  override bool HasMagazine () { return false; }
33  override bool IsJammed () { return false; }
34  override bool IsRepairEnabled () { return true; }
35  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.F}; }
36 };
37 class RSSLoaded extends WeaponStableState
38 {
39  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Loaded C"); } super.OnEntry(e); }
40  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Loaded C"); } }
41  override int GetCurrentStateID () { return RSSStableStateID.Loaded; }
42  override bool HasBullet () { return true; }
43  override bool HasMagazine () { return false; }
44  override bool IsJammed () { return false; }
45  override bool IsRepairEnabled () { return true; }
46  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.L}; }
47 };
48 class RSSJammed extends WeaponStateJammed
49 {
50  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Jammed J"); } super.OnEntry(e); }
51  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Jammed J"); } }
52  override int GetCurrentStateID () { return RSSStableStateID.Jammed; }
53  override bool HasBullet () { return true; }
54  override bool HasMagazine () { return false; }
55  override bool IsJammed () { return true; }
56  override bool IsBoltOpen () { return true; }
57  override bool IsRepairEnabled () { return true; }
58  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.F}; }
59 };
60 
65 class RifleSingleShot_Base extends Rifle_Base
66 {
67  void RifleSingleShot_Base ()
68  {
69  }
70 
71  override void InitStateMachine()
72  {
73  // setup abilities
74  m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED));
75  m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED));
76  m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_START));
77  m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_END));
78  m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL));
79  m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED));
80 
81  // setup state machine
82  // basic weapon states
83  WeaponStableState E = new RSSEmpty(this, NULL, RSSAnimState.DEFAULT);
84  WeaponStableState F = new RSSFireout(this, NULL, RSSAnimState.DEFAULT);
85  WeaponStableState J = new RSSJammed(this, NULL, RSSAnimState.DEFAULT);
86  WeaponStableState L = new RSSLoaded(this, NULL, RSSAnimState.DEFAULT);
87  // unstable (intermediate) states
88  WeaponStateBase Mech_F = new WeaponCharging(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
89  WeaponStateBase Mech_L = new WeaponEjectBullet(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
90 
91  WeaponChambering Chamber_E = new WeaponChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
92  WeaponChambering Chamber_F = new WeaponChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
93  //WeaponStateBase Chamber_L = new RifleReChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
94 
95  WeaponStateBase Trigger_E = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED);
96  WeaponStateBase Trigger_L = new WeaponFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL);
97  WeaponStateBase Trigger_F = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED);
98 
99  WeaponStateBase Trigger_LJ = new WeaponFireToJam(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_JAM);
100 
101  WeaponStateBase Unjam_J = new WeaponUnjamming(this, NULL, WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_START);
102 
103  // events
104  WeaponEventBase __M__ = new WeaponEventMechanism;
105  WeaponEventBase __T__ = new WeaponEventTrigger;
106  WeaponEventBase __TJ_ = new WeaponEventTriggerToJam;
107  WeaponEventBase __L__ = new WeaponEventLoad1Bullet;
108  WeaponEventBase __U__ = new WeaponEventUnjam;
109  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
110  WeaponEventBase _abt_ = new WeaponEventHumanCommandActionAborted;
111  WeaponEventBase _dto_ = new WeaponEventDryFireTimeout;
112 
113  m_fsm = new WeaponFSM();
114  // charging
115  m_fsm.AddTransition(new WeaponTransition( E, __M__, Mech_F));
116  m_fsm.AddTransition(new WeaponTransition( F, __M__, Mech_F));
117  m_fsm.AddTransition(new WeaponTransition( Mech_F, _fin_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
118  m_fsm.AddTransition(new WeaponTransition( Mech_F, _fin_, E));
119  m_fsm.AddTransition(new WeaponTransition( Mech_F, _abt_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
120  m_fsm.AddTransition(new WeaponTransition( Mech_F, _abt_, E));
121 
122  // eject good cartridge
123  m_fsm.AddTransition(new WeaponTransition( L, __M__, Mech_L));
124  m_fsm.AddTransition(new WeaponTransition( Mech_L, _fin_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
125  m_fsm.AddTransition(new WeaponTransition( Mech_L, _fin_, L));
126  m_fsm.AddTransition(new WeaponTransition( Mech_L, _abt_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
127  m_fsm.AddTransition(new WeaponTransition( Mech_L, _abt_, L));
128 
129  // load bullet
130  m_fsm.AddTransition(new WeaponTransition( E, __L__, Chamber_E));
131  m_fsm.AddTransition(new WeaponTransition( Chamber_E, _fin_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
132  m_fsm.AddTransition(new WeaponTransition( Chamber_E, _fin_, L));
133  m_fsm.AddTransition(new WeaponTransition( Chamber_E, _abt_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
134  m_fsm.AddTransition(new WeaponTransition( Chamber_E, _abt_, L));
135 
136 
137  m_fsm.AddTransition(new WeaponTransition( F, __L__, Chamber_F));
138  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _fin_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
139  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _fin_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
140  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _fin_, L));
141  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _abt_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
142  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _abt_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
143  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _abt_, L));
144 
145 
146  // fire
147  m_fsm.AddTransition(new WeaponTransition( E, __T__, Trigger_E)); // fire cocked
148  m_fsm.AddTransition(new WeaponTransition( Trigger_E, _fin_, E));
149  m_fsm.AddTransition(new WeaponTransition( Trigger_E, _dto_, E));
150  m_fsm.AddTransition(new WeaponTransition( Trigger_E, _abt_, E));
151 
152  m_fsm.AddTransition(new WeaponTransition( F, __T__, Trigger_F)); // fire uncocked
153  m_fsm.AddTransition(new WeaponTransition( Trigger_F, _fin_, F));
154  m_fsm.AddTransition(new WeaponTransition( Trigger_F, _dto_, F));
155  m_fsm.AddTransition(new WeaponTransition( Trigger_F, _abt_, F));
156 
157  m_fsm.AddTransition(new WeaponTransition( L, __T__, Trigger_L)); // a) fire if not jammed
158  m_fsm.AddTransition(new WeaponTransition( Trigger_L, _fin_, F));
159  m_fsm.AddTransition(new WeaponTransition( Trigger_L, _abt_, F));
160 
161  m_fsm.AddTransition(new WeaponTransition( L, __TJ_, Trigger_LJ)); // a) fire if not jammed
162  m_fsm.AddTransition(new WeaponTransition( Trigger_LJ, _fin_, J));
163  m_fsm.AddTransition(new WeaponTransition( Trigger_LJ, _abt_, J));
164 
165  // unjam
166  m_fsm.AddTransition(new WeaponTransition( J, __U__, Unjam_J));
167  m_fsm.AddTransition(new WeaponTransition( Unjam_J, _fin_, J, NULL, new WeaponGuardJammed(this)));
168  m_fsm.AddTransition(new WeaponTransition( Unjam_J, _fin_, E));
169 
170  // initial state setup
171  bool empty = true;
172  bool discharged = false; // @TODO:
173  WeaponStableState init_state = E;
174  if (empty)
175  {
176  if (!discharged)
177  init_state = E;
178  }
179  else
180  {
181  init_state = L; // can init state == load/jammed?
182  }
183  SetInitialState(init_state);
184 
185  SelectionBulletHide();
186 
187  m_fsm.Start();
188  }
189 
190  override float GetChanceToJam()
191  {
192  return 0.0;
193  }
194 };
E
@ E
EMPTY.
Definition: weaponstablestate.c:19
HasMagazine
override bool HasMagazine()
Definition: riflesingleshot_base.c:21
IsRepairEnabled
override bool IsRepairEnabled()
Definition: riflesingleshot_base.c:23
LogManager
Definition: debug.c:734
RifleSingleShot_Base
Definition: izh18.c:5
WeaponActionUnjammingTypes
WeaponActionUnjammingTypes
Definition: human.c:904
WeaponFire
Definition: weaponfire.c:98
WeaponActionFireTypes
WeaponActionFireTypes
Definition: human.c:912
HasBullet
override bool HasBullet()
Definition: riflesingleshot_base.c:20
OnExit
override void OnExit(WeaponEventBase e)
Definition: riflesingleshot_base.c:18
L
@ L
LOADED.
Definition: weaponstablestate.c:23
UNKNOWN
UNKNOWN
Definition: riflesingleshot_base.c:2
WeaponActions
WeaponActions
actions
Definition: human.c:808
F
@ F
FIRED.
Definition: weaponstablestate.c:21
Empty
Empty
Definition: riflesingleshot_base.c:3
Loaded
Loaded
Definition: riflesingleshot_base.c:5
WeaponUnjamming
unjam submachine
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
WeaponCharging
charging of weapon without ammo to be chambered
WeaponTransition
enum FSMTransition WeaponTransition
OnEntry
class RSSFireout extends WeaponStableState OnEntry
IsBoltOpen
override bool IsBoltOpen()
Definition: flaregun.c:23
IsJammed
override bool IsJammed()
Definition: riflesingleshot_base.c:22
InitMuzzleArray
override void InitMuzzleArray()
Definition: riflesingleshot_base.c:24
AbilityRecord
pair ( action, actionType )
Definition: weapon_base.c:4
RSSAnimState
RSSAnimState
Definition: riflesingleshot_base.c:1
WeaponEventBase
signalize mechanism manipulation
Definition: events.c:34
DEFAULT
@ DEFAULT
default weapon state, closed and discharged
Definition: riflesingleshot_base.c:3
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
Fireout
Fireout
Definition: riflesingleshot_base.c:4
RSSStableStateID
RSSStableStateID
Definition: riflesingleshot_base.c:6
Jammed
Jammed
Definition: riflesingleshot_base.c:6
WeaponActionChamberingTypes
WeaponActionChamberingTypes
Definition: human.c:868
WeaponFSM
weapon finite state machine
GetCurrentStateID
override int GetCurrentStateID()
Definition: riflesingleshot_base.c:19
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