DayZ 1.24
Loading...
Searching...
No Matches
Crossbow.c
Go to the documentation of this file.
2{
3 uncocked = 0,
4 cocked = 1,
5};
6
8{
9 UNKNOWN = 0,
10 UncockedEmpty = 1,
11 CockedEmpty = 2,
12 Loaded = 3,
13}
14
16{
17 override void OnEntry(WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Uncocked Empty UE"); m_weapon.SetCharged(false); super.OnEntry(e); }
18 override void OnExit(WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Uncocked Empty UE"); }
19 override int GetCurrentStateID() { return XBStableStateID.UncockedEmpty; }
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};
27{
28 override void OnEntry(WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Cocked Empty CE"); m_weapon.SetCharged(true); super.OnEntry(e); }
29 override void OnExit(WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Cocked Empty CE"); }
30 override int GetCurrentStateID() { return XBStableStateID.CockedEmpty; }
31 override bool HasBullet() { return false; }
32 override bool HasMagazine() { return false; }
33 override bool IsJammed() { return false; }
34 override bool IsRepairEnabled() { return true; }
36};
37class XBLoaded extends WeaponStableState
38{
39 override void OnEntry(WeaponEventBase e) { if (LogManager.IsWeaponLogEnable()) wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " { Loaded L"); m_weapon.SetCharged(true); super.OnEntry(e); }
40 override void OnExit(WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) wpnPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " } Loaded L"); }
41 override int GetCurrentStateID() { return XBStableStateID.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};
48
54{
56
58 {
59 return new CrossbowRecoil(this);
60 }
61
62 override void InitStateMachine()
63 {
64 // setup abilities
65 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_OPENED));
66 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_SPECIAL));
67 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_CROSSBOW_OPENED));
68 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_CROSSBOW_CLOSED));
69 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL));
70 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_UNCOCKED));
71 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED));
72
73 // setup state machine
74 // basic weapon states
75 WeaponStableState U = new XBUncockedEmpty(this, NULL, XBAnimState.uncocked);
77 WeaponStableState L = new XBLoaded(this, NULL, XBAnimState.cocked);
78 // unstable (intermediate) states
79 WeaponChargingStretch Mech_U = new WeaponChargingStretch(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_OPENED);
80 WeaponEjectBullet Mech_L = new WeaponEjectBullet(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_SPECIAL);
81
82 WeaponChambering Chamber_U = new WeaponChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_CROSSBOW_OPENED);
83 WeaponChambering Chamber_C = new WeaponChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_CROSSBOW_CLOSED);
84 //CrossbowReChambering Chamber_L = new CrossbowReChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ONEBULLET_CLOSED);
85
88 WeaponStateBase Trigger_L = new WeaponFireLast(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL);
89
91
92 // events
93 WeaponEventBase __M__ = new WeaponEventMechanism;
94 WeaponEventBase __T__ = new WeaponEventTrigger;
95 WeaponEventBase __TJ_ = new WeaponEventTriggerToJam;
96 WeaponEventBase __L__ = new WeaponEventLoad1Bullet;
97 WeaponEventBase __U__ = new WeaponEventUnjam;
98 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
99 WeaponEventBase _abt_ = new WeaponEventHumanCommandActionAborted;
100 WeaponEventBase _dto_ = new WeaponEventDryFireTimeout;
101
102 m_fsm = new WeaponFSM();
103
104 //Charging
105 m_fsm.AddTransition(new WeaponTransition(C, __M__, C));
106
107 m_fsm.AddTransition(new WeaponTransition(U, __M__, Mech_U));
108 m_fsm.AddTransition(new WeaponTransition(Mech_U, _fin_, U, null, new WeaponGuardWeaponDischarged(this)));
109 m_fsm.AddTransition(new WeaponTransition(Mech_U, _fin_, C));
110 m_fsm.AddTransition(new WeaponTransition(Mech_U, _abt_, U, null, new WeaponGuardWeaponDischarged(this)));
111 m_fsm.AddTransition(new WeaponTransition(Mech_U, _abt_, C));
112
113 m_fsm.AddTransition(new WeaponTransition(L, __M__, Mech_L));
114 m_fsm.AddTransition(new WeaponTransition(Mech_L, _fin_, C, null, new WeaponGuardChamberEmpty(this)));
115 m_fsm.AddTransition(new WeaponTransition(Mech_L, _fin_, L));
116 m_fsm.AddTransition(new WeaponTransition(Mech_L, _abt_, C, null, new WeaponGuardChamberEmpty(this)));
117 m_fsm.AddTransition(new WeaponTransition(Mech_L, _abt_, L));
118
119
120 //Chamber bolt
121 m_fsm.AddTransition(new WeaponTransition(U, __L__, Chamber_U));
122 m_fsm.AddTransition(new WeaponTransition(Chamber_U, _fin_, L, null, new WeaponGuardChamberFull(this)));
123 m_fsm.AddTransition(new WeaponTransition(Chamber_U, _fin_, C, null, new WeaponGuardWeaponCharged(this)));
124 m_fsm.AddTransition(new WeaponTransition(Chamber_U, _fin_, U));
125 m_fsm.AddTransition(new WeaponTransition(Chamber_U, _abt_, L, null, new WeaponGuardChamberFull(this)));
126 m_fsm.AddTransition(new WeaponTransition(Chamber_U, _abt_, C, null, new WeaponGuardWeaponCharged(this)));
127 m_fsm.AddTransition(new WeaponTransition(Chamber_U, _abt_, U));
128
129
130 m_fsm.AddTransition(new WeaponTransition(C, __L__, Chamber_C));
131 m_fsm.AddTransition(new WeaponTransition(Chamber_C, _fin_, L, null, new WeaponGuardChamberFull(this)));
132 m_fsm.AddTransition(new WeaponTransition(Chamber_C, _fin_, C));
133 m_fsm.AddTransition(new WeaponTransition(Chamber_C, _abt_, L, null, new WeaponGuardChamberFull(this)));
134 m_fsm.AddTransition(new WeaponTransition(Chamber_C, _abt_, C));
135
136 m_fsm.AddTransition(new WeaponTransition(C, __T__, Trigger_C));
137 m_fsm.AddTransition(new WeaponTransition(Trigger_C, _fin_, U));
138 m_fsm.AddTransition(new WeaponTransition(Trigger_C, _abt_, U));
139 m_fsm.AddTransition(new WeaponTransition(Trigger_C, _dto_, U));
140 m_fsm.AddTransition(new WeaponTransition(Trigger_C, _abt_, U));
141
142 m_fsm.AddTransition(new WeaponTransition(U, __T__, Trigger_U));
143 m_fsm.AddTransition(new WeaponTransition(Trigger_U, _fin_, U));
144 m_fsm.AddTransition(new WeaponTransition(Trigger_U, _abt_, U));
145 m_fsm.AddTransition(new WeaponTransition(Trigger_U, _dto_, U));
146 m_fsm.AddTransition(new WeaponTransition(Trigger_U, _abt_, U));
147
148 m_fsm.AddTransition(new WeaponTransition(L, __T__, Trigger_L));
149 m_fsm.AddTransition(new WeaponTransition(Trigger_L, _fin_, U));
150 m_fsm.AddTransition(new WeaponTransition(Trigger_L, _abt_, U));
151 m_fsm.AddTransition(new WeaponTransition(Trigger_L, _dto_, U));
152 m_fsm.AddTransition(new WeaponTransition(Trigger_L, _abt_, U));
153
154 SelectionBulletHide();
155 EffectBulletHide(0);
156
157 SetInitialState(U);
158 m_fsm.Start();
159 }
160
161 override float GetChanceToJam()
162 {
163 return 0.0;
164 }
165
167 {
168 //super.OnDebugSpawn();
169
170
171 GetInventory().CreateInInventory("ACOGOptic_6x");
172
174
176 if (params.m_Player)
177 inv = params.m_Player.GetInventory();
178
179 SpawnInInventoryOrGroundPos("Ammo_HuntingBolt", inv, GetPosition());
180 SpawnInInventoryOrGroundPos("Ammo_ImprovisedBolt_1", inv, GetPosition());
181 SpawnInInventoryOrGroundPos("Ammo_ImprovisedBolt_2", inv, GetPosition());
182
183 SpawnInInventoryOrGroundPos("ACOGOptic", inv, GetPosition());
184 entity = SpawnInInventoryOrGroundPos("M68Optic", inv, GetPosition());
185 entity.GetInventory().CreateInInventory("Battery9V");
186 entity = SpawnInInventoryOrGroundPos("M4_T3NRDSOptic", inv, GetPosition());
187 entity.GetInventory().CreateInInventory("Battery9V");
188 entity = SpawnInInventoryOrGroundPos("ReflexOptic", inv, GetPosition());
189 entity.GetInventory().CreateInInventory("Battery9V");
190 entity = SpawnInInventoryOrGroundPos("StarlightOptic", inv, GetPosition());
191 entity.GetInventory().CreateInInventory("Battery9V");
192 }
193
194 override bool CanBeUsedForSuicide()
195 {
196 float ammoDamage;
197 string ammoTypeName;
198 GetCartridgeInfo(GetCurrentMuzzle(), ammoDamage, ammoTypeName);
199 if (ammoTypeName == "Bullet_CupidsBolt")
200 return false;
201
202 return super.CanBeUsedForSuicide();
203 }
204}
205
206class Crossbow : Crossbow_Base {}
void wpnPrint(string s)
Definition Debug.c:1
Loaded
Definition Crossbow.c:21
override bool IsRepairEnabled()
Definition Crossbow.c:23
UNKNOWN
Definition Crossbow.c:18
UncockedEmpty
Definition Crossbow.c:19
CockedEmpty
Definition Crossbow.c:20
override bool IsJammed()
Definition Crossbow.c:22
override bool HasBullet()
Definition Crossbow.c:20
XBStableStateID
Definition Crossbow.c:8
XBAnimState
Definition Crossbow.c:2
@ uncocked
default weapon state, closed and discharged
Definition Crossbow.c:3
@ cocked
Definition Crossbow.c:4
override void InitMuzzleArray()
Definition Crossbow.c:24
override bool HasMagazine()
Definition Crossbow.c:21
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition Guards.c:602
void WeaponGuardWeaponDischarged(Weapon_Base w=NULL)
Definition Guards.c:578
override int GetCurrentStateID()
Definition Hand_States.c:29
override void OnExit(HandEventBase e)
Definition Hand_States.c:28
HandStateEquipped OnEntry
class JsonUndergroundAreaTriggerData GetPosition
enum FSMTransition WeaponTransition
MuzzleState
@ U
UNKNOWN.
@ L
LOADED.
ref array< MuzzleState > m_muzzleHasBullet
pair ( action, actionType )
Definition Weapon_Base.c:5
base for Archery @NOTE name copies config base class
Definition Archery_Base.c:6
base for Crossbow @NOTE name copies config base class
Definition Crossbow.c:54
override float GetChanceToJam()
Definition Crossbow.c:161
override void InitStateMachine()
Definition Crossbow.c:62
override RecoilBase SpawnRecoilObject()
Definition Crossbow.c:57
void Crossbow_Base()
override bool CanBeUsedForSuicide()
Definition Crossbow.c:194
override void OnDebugSpawnEx(DebugSpawnParams params)
Definition Crossbow.c:166
script counterpart to engine's class Inventory
Definition Inventory.c:79
static bool IsWeaponLogEnable()
Definition Debug.c:799
ref WeaponStableState C
Definition Magnum.c:51
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()
Definition Crossbow.c:33
override void OnExit(WeaponEventBase e)
Definition Crossbow.c:29
override void InitMuzzleArray()
Definition Crossbow.c:35
override void OnEntry(WeaponEventBase e)
Definition Crossbow.c:28
override bool HasBullet()
Definition Crossbow.c:31
override int GetCurrentStateID()
Definition Crossbow.c:30
override bool IsRepairEnabled()
Definition Crossbow.c:34
override bool HasMagazine()
Definition Crossbow.c:32
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