Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
15 class XBUncockedEmpty extends WeaponStableState
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; }
24  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.E}; }
25 };
26 class XBCockedEmpty extends WeaponStableState
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; }
35  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.E}; }
36 };
37 class 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; }
46  override void InitMuzzleArray () { m_muzzleHasBullet = {MuzzleState.L}; }
47 };
48 
54 {
55  void Crossbow_Base();
56 
57  override RecoilBase SpawnRecoilObject()
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);
76  WeaponStableState C = new XBCockedEmpty(this, NULL, XBAnimState.cocked);
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 
86  WeaponStateBase Trigger_U = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_UNCOCKED);
87  WeaponStateBase Trigger_C = new WeaponDryFire(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED);
88  WeaponStateBase Trigger_L = new WeaponFireLast(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL);
89 
90  WeaponStateBase Unjam_J = new WeaponUnjamming(this, NULL, WeaponActions.UNJAMMING, WeaponActionUnjammingTypes.UNJAMMING_START);
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 
166  override void OnDebugSpawnEx(DebugSpawnParams params)
167  {
168  //super.OnDebugSpawn();
169 
170 
171 
172  GetInventory().CreateInInventory( "ACOGOptic_6x" );
173 
174  EntityAI entity;
175 
176  GameInventory inv = null;
177  if (params.m_Player)
178  {
179  inv = params.m_Player.GetInventory();
180  }
181 
182  SpawnInInventoryOrGroundPos("Ammo_HuntingBolt", inv, GetPosition());
183  SpawnInInventoryOrGroundPos("Ammo_ImprovisedBolt_1", inv, GetPosition());
184  SpawnInInventoryOrGroundPos("Ammo_ImprovisedBolt_2", inv, GetPosition());
185 
186  SpawnInInventoryOrGroundPos("ACOGOptic", inv, GetPosition());
187  entity = SpawnInInventoryOrGroundPos("M68Optic", inv, GetPosition());
188  entity.GetInventory().CreateInInventory( "Battery9V" );
189  entity = SpawnInInventoryOrGroundPos("M4_T3NRDSOptic", inv, GetPosition());
190  entity.GetInventory().CreateInInventory( "Battery9V" );
191  entity = SpawnInInventoryOrGroundPos("ReflexOptic", inv, GetPosition());
192  entity.GetInventory().CreateInInventory( "Battery9V" );
193  entity = SpawnInInventoryOrGroundPos("StarlightOptic", inv, GetPosition());
194  entity.GetInventory().CreateInInventory( "Battery9V" );
195  }
196 
197  override bool CanBeUsedForSuicide()
198  {
199  float ammoDamage;
200  string ammoTypeName;
201  GetCartridgeInfo(GetCurrentMuzzle(), ammoDamage, ammoTypeName);
202  if (ammoTypeName == "Bullet_CupidsBolt")
203  return false;
204 
205  return super.CanBeUsedForSuicide();
206  }
207 }
208 
209 class Crossbow : Crossbow_Base {}
210 class Crossbow_Autumn : Crossbow_Base {}
211 class Crossbow_Summer : Crossbow_Base {}
212 class Crossbow_Black : Crossbow_Base {}
213 class Crossbow_Wood : Crossbow_Base {}
XBStableStateID
XBStableStateID
Definition: crossbow.c:7
OnExit
override void OnExit(WeaponEventBase e)
Definition: crossbow.c:18
LogManager
Definition: debug.c:734
InitMuzzleArray
override void InitMuzzleArray()
Definition: crossbow.c:24
WeaponActionUnjammingTypes
WeaponActionUnjammingTypes
Definition: human.c:904
WeaponActionFireTypes
WeaponActionFireTypes
Definition: human.c:912
Loaded
Loaded
Definition: crossbow.c:5
Crossbow_Base
base for Crossbow @NOTE name copies config base class
Definition: crossbow.c:53
WeaponGuardWeaponDischarged
void WeaponGuardWeaponDischarged(Weapon_Base w=NULL)
Definition: guards.c:580
Archery_Base
base for Archery @NOTE name copies config base class
Definition: archery_base.c:5
L
@ L
LOADED.
Definition: weaponstablestate.c:23
IsJammed
override bool IsJammed()
Definition: crossbow.c:22
WeaponActions
WeaponActions
actions
Definition: human.c:808
CrossbowRecoil
Definition: crossbowrecoil.c:1
XBAnimState
XBAnimState
Definition: crossbow.c:1
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
OnEntry
class XBCockedEmpty extends WeaponStableState OnEntry
RecoilBase
Definition: recoilbase.c:1
WeaponUnjamming
unjam submachine
HasBullet
override bool HasBullet()
Definition: crossbow.c:20
Object
Definition: objecttyped.c:1
m_muzzleHasBullet
ref array< MuzzleState > m_muzzleHasBullet
Definition: weaponstablestate.c:30
uncocked
@ uncocked
default weapon state, closed and discharged
Definition: crossbow.c:3
WeaponTransition
enum FSMTransition WeaponTransition
HasMagazine
override bool HasMagazine()
Definition: crossbow.c:21
CockedEmpty
CockedEmpty
Definition: crossbow.c:4
GetCurrentStateID
override int GetCurrentStateID()
Definition: crossbow.c:19
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
wpnPrint
void wpnPrint(string s)
Definition: debug.c:1
IsRepairEnabled
override bool IsRepairEnabled()
Definition: crossbow.c:23
cocked
@ cocked
Definition: crossbow.c:4
WeaponActionChamberingTypes
WeaponActionChamberingTypes
Definition: human.c:868
WeaponFSM
weapon finite state machine
EntityAI
Definition: building.c:5
UNKNOWN
UNKNOWN
Definition: crossbow.c:2
WeaponStableState
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
Definition: crossbow.c:26
UncockedEmpty
UncockedEmpty
Definition: crossbow.c:3
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78
U
@ U
UNKNOWN.
Definition: weaponstablestate.c:17
MuzzleState
MuzzleState
Definition: weaponstablestate.c:14