DayZ 1.24
Loading...
Searching...
No Matches
RifleSingleShotManual_Base.c
Go to the documentation of this file.
1
6{
10
11 override void InitStateMachine()
12 {
13 // setup abilities
14 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED));
15 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_OPENED));
16 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED));
17 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_OPENED));
18 m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_START));
19 m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_END));
20 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL));
21 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED));
22
23 // setup state machine
24 // basic weapon states
25 WeaponStableState E = new RSSEmpty(this, NULL, RSSAnimState.DEFAULT);
26 WeaponStableState F = new RSSFireout(this, NULL, RSSAnimState.DEFAULT);
27 WeaponStableState J = new RSSJammed(this, NULL, RSSAnimState.DEFAULT);
28 WeaponStableState L = new RSSLoaded(this, NULL, RSSAnimState.DEFAULT);
29 // unstable (intermediate) states
30 WeaponStateBase Mech_E = new WeaponCharging(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_OPENED);
31 WeaponStateBase Mech_F = new WeaponCharging(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
32 WeaponStateBase Mech_L = new WeaponEjectBullet(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
33
34 WeaponChambering Chamber_E = new WeaponChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
35 WeaponChambering Chamber_F = new WeaponChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_OPENED);
36 //WeaponStateBase Chamber_L = new RifleReChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
37
41
43
45
46 // events
47 WeaponEventBase __M__ = new WeaponEventMechanism;
48 WeaponEventBase __T__ = new WeaponEventTrigger;
49 WeaponEventBase __TJ_ = new WeaponEventTriggerToJam;
50 WeaponEventBase __L__ = new WeaponEventLoad1Bullet;
51 WeaponEventBase __U__ = new WeaponEventUnjam;
52 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
53 WeaponEventBase _abt_ = new WeaponEventHumanCommandActionAborted;
54 WeaponEventBase _dto_ = new WeaponEventDryFireTimeout;
55
56 m_fsm = new WeaponFSM();
57 // charging
58 m_fsm.AddTransition(new WeaponTransition(E, __M__, Mech_E));
59 m_fsm.AddTransition(new WeaponTransition(Mech_E, _fin_, E));
60 m_fsm.AddTransition(new WeaponTransition(Mech_E, _abt_, E));
61
62 m_fsm.AddTransition(new WeaponTransition(F, __M__, Mech_F));
63 m_fsm.AddTransition(new WeaponTransition(Mech_F, _fin_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
64 m_fsm.AddTransition(new WeaponTransition(Mech_F, _fin_, E));
65 m_fsm.AddTransition(new WeaponTransition(Mech_F, _abt_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
66 m_fsm.AddTransition(new WeaponTransition(Mech_F, _abt_, E));
67
68 // eject good cartridge
69 m_fsm.AddTransition(new WeaponTransition(L, __M__, Mech_L));
70 m_fsm.AddTransition(new WeaponTransition(Mech_L, _fin_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
71 m_fsm.AddTransition(new WeaponTransition(Mech_L, _fin_, L));
72 m_fsm.AddTransition(new WeaponTransition(Mech_L, _abt_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
73 m_fsm.AddTransition(new WeaponTransition(Mech_L, _abt_, L));
74
75 // load bullet
76 m_fsm.AddTransition(new WeaponTransition(E, __L__, Chamber_E));
77 m_fsm.AddTransition(new WeaponTransition(Chamber_E, _fin_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
78 m_fsm.AddTransition(new WeaponTransition(Chamber_E, _fin_, L));
79 m_fsm.AddTransition(new WeaponTransition(Chamber_E, _abt_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
80 m_fsm.AddTransition(new WeaponTransition(Chamber_E, _abt_, L));
81
82 m_fsm.AddTransition(new WeaponTransition(F, __L__, Chamber_F));
83 m_fsm.AddTransition(new WeaponTransition(Chamber_F, _fin_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
84 m_fsm.AddTransition(new WeaponTransition(Chamber_F, _fin_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
85 m_fsm.AddTransition(new WeaponTransition(Chamber_F, _fin_, L));
86 m_fsm.AddTransition(new WeaponTransition(Chamber_F, _abt_, F, NULL, new WeaponGuardCurrentChamberFiredOut(this)));
87 m_fsm.AddTransition(new WeaponTransition(Chamber_F, _abt_, E, NULL, new WeaponGuardCurrentChamberEmpty(this)));
88 m_fsm.AddTransition(new WeaponTransition(Chamber_F, _abt_, L));
89
90 // fire
91 m_fsm.AddTransition(new WeaponTransition(E, __T__, Trigger_E)); // fire cocked
92 m_fsm.AddTransition(new WeaponTransition(Trigger_E, _fin_, E));
93 m_fsm.AddTransition(new WeaponTransition(Trigger_E, _dto_, E));
94 m_fsm.AddTransition(new WeaponTransition(Trigger_E, _abt_, E));
95
96 m_fsm.AddTransition(new WeaponTransition(F, __T__, Trigger_F)); // fire uncocked
97 m_fsm.AddTransition(new WeaponTransition(Trigger_F, _fin_, F));
98 m_fsm.AddTransition(new WeaponTransition(Trigger_F, _dto_, F));
99 m_fsm.AddTransition(new WeaponTransition(Trigger_F, _abt_, F));
100
101 m_fsm.AddTransition(new WeaponTransition(L, __T__, Trigger_L)); // a) fire if not jammed
102 m_fsm.AddTransition(new WeaponTransition(Trigger_L, _fin_, F));
103 m_fsm.AddTransition(new WeaponTransition(Trigger_L, _abt_, F));
104
105 m_fsm.AddTransition(new WeaponTransition(L, __TJ_, Trigger_LJ)); // a) fire if not jammed
106 m_fsm.AddTransition(new WeaponTransition(Trigger_LJ, _fin_, J));
107 m_fsm.AddTransition(new WeaponTransition(Trigger_LJ, _abt_, J));
108
109 // unjam
110 m_fsm.AddTransition(new WeaponTransition(J, __U__, Unjam_J));
111 m_fsm.AddTransition(new WeaponTransition(Unjam_J, _fin_, J, NULL, new WeaponGuardJammed(this)));
112 m_fsm.AddTransition(new WeaponTransition(Unjam_J, _fin_, E));
113
114 // initial state setup
115 bool empty = true;
116 bool discharged = false; // @TODO:
118 if (empty)
119 {
120 if (!discharged)
121 init_state = E;
122 }
123 else
124 {
125 init_state = L; // can init state == load/jammed?
126 }
127 SetInitialState(init_state);
128
129 SelectionBulletHide();
130
131 m_fsm.Start();
132 }
133};
enum FSMTransition WeaponTransition
@ E
EMPTY.
@ L
LOADED.
@ F
FIRED.
pair ( action, actionType )
Definition Weapon_Base.c:5
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
represent weapon state base
Definition BulletHide.c:2
unjam submachine
WeaponActionChamberingTypes
Definition human.c:856
WeaponActions
actions
Definition human.c:796
WeaponActionUnjammingTypes
Definition human.c:892
WeaponActionFireTypes
Definition human.c:900