Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
singleshotpistol_base.c
Go to the documentation of this file.
2 {
3  COCKED = 0,
4  UNCOCKED = 1,
5 };
6 
8 {
9  UNKNOWN = 0,
10  Empty = 1,
11  Fireout = 2,
12  Loaded = 3,
13 }
14 
15 class SSPEmpty 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 SSPStableStateID.Empty; }
20  override bool HasBullet () { return false; }
21  override bool HasMagazine () { return false; }
22  override bool IsJammed () { return false; }
23  override bool IsBoltOpen () { return false; }
24  override bool IsRepairEnabled () { return true; }
25  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.E}; }
26 };
27 class SSPFireout extends WeaponStableState
28 {
29  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Fireout F"); } super.OnEntry(e); }
30  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Fireout F"); } }
31  override int GetCurrentStateID () { return SSPStableStateID.Fireout; }
32  override bool HasBullet () { return true; }
33  override bool HasMagazine () { return false; }
34  override bool IsJammed () { return false; }
35  override bool IsBoltOpen () { return false; }
36  override bool IsRepairEnabled () { return true; }
37  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.F}; }
38 };
39 class SSPLoaded extends WeaponStableState
40 {
41  override void OnEntry (WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Loaded C"); } super.OnEntry(e); }
42  override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Loaded C"); } }
43  override int GetCurrentStateID () { return SSPStableStateID.Loaded; }
44  override bool HasBullet () { return true; }
45  override bool HasMagazine () { return false; }
46  override bool IsJammed () { return false; }
47  override bool IsBoltOpen () { return false; }
48  override bool IsRepairEnabled () { return true; }
49  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.L}; }
50 };
51 
53 {
54  override void InitStateMachine()
55  {
56  // setup abilities
57  m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED));
58  m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_OPENED));
59  m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED));
60  m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL));
61  m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_UNCOCKED));
62 
63  // setup state machine
64  // basic weapon states
65  WeaponStableState E = new SSPEmpty(this, NULL, SSPAnimState.UNCOCKED);
66  WeaponStableState F = new SSPFireout(this, NULL, SSPAnimState.UNCOCKED);
67  WeaponStableState L = new SSPLoaded(this, NULL, SSPAnimState.COCKED);
68  // unstable (intermediate) states
69  WeaponStateBase Mech_F = new WeaponCharging(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
70  WeaponStateBase Mech_L = new WeaponEjectBullet(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_OPENED);
71 
72  WeaponStateBase Chamber_E = new WeaponChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
73  WeaponStateBase Chamber_F = new WeaponChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
74  //WeaponStateBase Chamber_L = new RifleReChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
75 
76  WeaponStateBase Trigger_E = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_UNCOCKED);
77  WeaponStateBase Trigger_L = new WeaponFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL);
78  WeaponStateBase Trigger_F = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_UNCOCKED);
79 
80 
81  // events
82  WeaponEventBase __M__ = new WeaponEventMechanism;
83  WeaponEventBase __T__ = new WeaponEventTrigger;
84  WeaponEventBase __TJ_ = new WeaponEventTriggerToJam;
85  WeaponEventBase __L__ = new WeaponEventLoad1Bullet;
86  WeaponEventBase __U__ = new WeaponEventUnjam;
87  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
88  WeaponEventBase _abt_ = new WeaponEventHumanCommandActionAborted;
89  WeaponEventBase _dto_ = new WeaponEventDryFireTimeout;
90 
91  m_fsm = new WeaponFSM();
92  // charging
93  m_fsm.AddTransition(new WeaponTransition( E, __M__, Mech_F));
94  m_fsm.AddTransition(new WeaponTransition( F, __M__, Mech_F));
95  m_fsm.AddTransition(new WeaponTransition( Mech_F, _fin_, E));
96  m_fsm.AddTransition(new WeaponTransition( Mech_F, _abt_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
97  m_fsm.AddTransition(new WeaponTransition( Mech_F, _abt_, E));
98 
99  // eject good cartridge
100  m_fsm.AddTransition(new WeaponTransition( L, __M__, Mech_L));
101  m_fsm.AddTransition(new WeaponTransition( Mech_L, _fin_, E));
102  m_fsm.AddTransition(new WeaponTransition( Mech_L, _abt_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
103  m_fsm.AddTransition(new WeaponTransition( Mech_L, _abt_, L));
104 
105  m_fsm.AddTransition(new WeaponTransition( E, __L__, Chamber_F));
106  m_fsm.AddTransition(new WeaponTransition( F, __L__, Chamber_F));
107  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _fin_, L));
108  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _abt_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
109  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _abt_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
110  m_fsm.AddTransition(new WeaponTransition( Chamber_F, _abt_, L));
111 
112  // fire
113  m_fsm.AddTransition(new WeaponTransition( E, __T__, Trigger_E)); // fire cocked
114  m_fsm.AddTransition(new WeaponTransition( Trigger_E, _fin_, E));
115  m_fsm.AddTransition(new WeaponTransition( Trigger_E, _dto_, E));
116  m_fsm.AddTransition(new WeaponTransition( Trigger_E, _abt_, E));
117 
118  m_fsm.AddTransition(new WeaponTransition( F, __T__, Trigger_F)); // fire uncocked
119  m_fsm.AddTransition(new WeaponTransition( Trigger_F, _fin_, F));
120  m_fsm.AddTransition(new WeaponTransition( Trigger_F, _dto_, F));
121  m_fsm.AddTransition(new WeaponTransition( Trigger_F, _abt_, F));
122 
123  m_fsm.AddTransition(new WeaponTransition( L, __T__, Trigger_L)); // a) fire if not jammed
124  m_fsm.AddTransition(new WeaponTransition( Trigger_L, _fin_, F));
125  m_fsm.AddTransition(new WeaponTransition( Trigger_L, _abt_, F));
126 
127 
128  // initial state setup
129  bool empty = true;
130  bool discharged = false; // @TODO:
131  WeaponStableState init_state = E;
132  if (empty)
133  {
134  if (!discharged)
135  init_state = E;
136  }
137  else
138  {
139  init_state = L; // can init state == load/jammed?
140  }
141  SetInitialState(init_state);
142 
143  SelectionBulletHide();
144 
145  m_fsm.Start();
146  }
147 };
E
@ E
EMPTY.
Definition: weaponstablestate.c:19
LogManager
Definition: debug.c:734
COCKED
@ COCKED
default weapon state, closed and discharged
Definition: singleshotpistol_base.c:3
UNKNOWN
UNKNOWN
Definition: singleshotpistol_base.c:2
SingleShotPistol_Base
Definition: singleshotpistol_base.c:52
OnExit
override void OnExit(WeaponEventBase e)
Definition: singleshotpistol_base.c:18
HasBullet
override bool HasBullet()
Definition: singleshotpistol_base.c:20
IsJammed
override bool IsJammed()
Definition: singleshotpistol_base.c:22
HasMagazine
override bool HasMagazine()
Definition: singleshotpistol_base.c:21
GetCurrentStateID
override int GetCurrentStateID()
Definition: singleshotpistol_base.c:19
WeaponFire
Definition: weaponfire.c:98
WeaponActionFireTypes
WeaponActionFireTypes
Definition: human.c:912
L
@ L
LOADED.
Definition: weaponstablestate.c:23
WeaponActions
WeaponActions
actions
Definition: human.c:808
F
@ F
FIRED.
Definition: weaponstablestate.c:21
IsRepairEnabled
override bool IsRepairEnabled()
Definition: singleshotpistol_base.c:24
Empty
Empty
Definition: singleshotpistol_base.c:3
Loaded
Loaded
Definition: singleshotpistol_base.c:5
Object
Definition: objecttyped.c:1
m_muzzleHasBullet
ref array< MuzzleState > m_muzzleHasBullet
Definition: weaponstablestate.c:30
OnEntry
class SSPFireout extends WeaponStableState OnEntry
WeaponCharging
charging of weapon without ammo to be chambered
WeaponTransition
enum FSMTransition WeaponTransition
UNCOCKED
@ UNCOCKED
default weapon state, closed and discharged
Definition: singleshotpistol_base.c:4
SSPStableStateID
SSPStableStateID
Definition: singleshotpistol_base.c:7
AbilityRecord
pair ( action, actionType )
Definition: weapon_base.c:4
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
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
wpnPrint
void wpnPrint(string s)
Definition: debug.c:1
IsBoltOpen
override bool IsBoltOpen()
Definition: singleshotpistol_base.c:23
WeaponActionChamberingTypes
WeaponActionChamberingTypes
Definition: human.c:868
WeaponFSM
weapon finite state machine
SSPAnimState
SSPAnimState
Definition: singleshotpistol_base.c:1
InitMuzzleArray
override void InitMuzzleArray()
Definition: singleshotpistol_base.c:25
Fireout
Fireout
Definition: singleshotpistol_base.c:4
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