DayZ 1.24
Loading...
Searching...
No Matches
Flaregun.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
15class FLAREEmpty 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 FLAREStableStateID.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; }
26};
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 FLAREStableStateID.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; }
38};
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 FLAREStableStateID.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; }
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 FLAREEmpty(this, NULL, FLAREAnimState.UNCOCKED);
66 WeaponStableState F = new FLAREFireout(this, NULL, FLAREAnimState.UNCOCKED);
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
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:
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};
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
FLAREStableStateID
Definition Flaregun.c:8
override bool IsBoltOpen()
Definition Flaregun.c:23
UNKNOWN
Definition Flaregun.c:18
Empty
Definition Flaregun.c:19
Fireout
Definition Flaregun.c:20
FLAREAnimState
Definition Flaregun.c:2
@ UNCOCKED
default weapon state, closed and discharged
Definition Flaregun.c:4
@ COCKED
default weapon state, closed and discharged
Definition Flaregun.c:3
Loaded
Definition Flaregun.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
enum FSMTransition WeaponTransition
MuzzleState
@ E
EMPTY.
@ L
LOADED.
@ F
FIRED.
ref array< MuzzleState > m_muzzleHasBullet
pair ( action, actionType )
Definition Weapon_Base.c:5
override void InitStateMachine()
Definition Flaregun.c:54
static bool IsWeaponLogEnable()
Definition Debug.c:799
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 IsBoltOpen()
Definition Flaregun.c:35
override bool IsJammed()
Definition Flaregun.c:34
override void OnExit(WeaponEventBase e)
Definition Flaregun.c:30
override void InitMuzzleArray()
Definition Flaregun.c:37
override void OnEntry(WeaponEventBase e)
Definition Flaregun.c:29
override bool HasBullet()
Definition Flaregun.c:32
override int GetCurrentStateID()
Definition Flaregun.c:31
override bool IsRepairEnabled()
Definition Flaregun.c:36
override bool HasMagazine()
Definition Flaregun.c:33
represent weapon state base
Definition BulletHide.c:2
WeaponActionChamberingTypes
Definition human.c:856
WeaponActions
actions
Definition human.c:796
WeaponActionFireTypes
Definition human.c:900