DayZ 1.24
Loading...
Searching...
No Matches
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
15class 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; }
25};
26class 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; }
36};
37class 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; }
47};
48class 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; }
59};
60
66{
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
98
100
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:
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};
void wpnPrint(string s)
Definition Debug.c:1
override bool IsRepairEnabled()
Definition Crossbow.c:23
override bool IsJammed()
Definition Crossbow.c:22
override bool HasBullet()
Definition Crossbow.c:20
override void InitMuzzleArray()
Definition Crossbow.c:24
override bool HasMagazine()
Definition Crossbow.c:21
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
@ DEFAULT
default weapon state, closed and discharged
RSSStableStateID
enum FSMTransition WeaponTransition
MuzzleState
@ E
EMPTY.
@ L
LOADED.
@ F
FIRED.
ref array< MuzzleState > m_muzzleHasBullet
pair ( action, actionType )
Definition Weapon_Base.c:5
static bool IsWeaponLogEnable()
Definition Debug.c:799
base for rifles @NOTE name copies config base class
Definition SKS.c:70
void RifleSingleShot_Base()
override float GetChanceToJam()
override void InitStateMachine()
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
override bool IsJammed()
override void OnExit(WeaponEventBase e)
override void InitMuzzleArray()
override void OnEntry(WeaponEventBase e)
override bool HasBullet()
override int GetCurrentStateID()
override bool IsRepairEnabled()
override bool HasMagazine()
represent weapon state base
Definition BulletHide.c:2
handle jamming state set jam/unjam state for weapon
Definition SKS.c:53
override bool IsBoltOpen()
override void InitMuzzleArray()
override bool HasMagazine()
override bool IsRepairEnabled()
override void OnEntry(WeaponEventBase e)
override int GetCurrentStateID()
override bool IsJammed()
override bool HasBullet()
override void OnExit(WeaponEventBase e)
unjam submachine
WeaponActionChamberingTypes
Definition human.c:856
WeaponActions
actions
Definition human.c:796
WeaponActionUnjammingTypes
Definition human.c:892
WeaponActionFireTypes
Definition human.c:900