Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weapondetachingmag.c
Go to the documentation of this file.
1 
2 // detach magazine composite state
3 class WeaponDetachingMag_1 extends WeaponStartAction
4 { };
5 
6 class WeaponDetachingMag_Store extends WeaponStateBase
7 {
8  Magazine m_magazine;
10 
11  override void OnEntry (WeaponEventBase e)
12  {
13  //if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, Detaching mag=" + m_magazine.ToString() + "to loc=" + InventoryLocation.DumpToStringNullSafe(m_dst)); }
14  super.OnEntry(e);
15  if (e)
16  {
17  if (!m_magazine || !m_dst)
18  {
19  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, error - no magazine to load from (m_magazine=NULL)");
20  }
21  }
22  }
23 
24  override void OnAbort (WeaponEventBase e)
25  {
26  m_magazine = NULL;
27  m_dst = NULL;
28 
29  super.OnAbort(e);
30  }
31 
32  override void OnExit (WeaponEventBase e)
33  {
35  if (m_magazine.GetInventory().GetCurrentInventoryLocation(il))
36  {
37  if (GameInventory.LocationSyncMoveEntity(il, m_dst))
38  {
39  m_weapon.HideMagazine();
40  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, ok - magazine removed from inv (inv->dst)"); }
41  }
42  else
43  {
44  // @TODO: drop on gnd
45  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, error - cannot store detached magazine!");
46  }
47  }
48  else
49  {
50  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store, error - cannot get curr location");
51  }
52 
53  m_magazine = NULL;
54  m_dst = NULL;
55  super.OnExit(e);
56  }
57 
58  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
59  {
60  if (!super.SaveCurrentFSMState(ctx))
61  return false;
62 
63  if (!ctx.Write(m_magazine))
64  {
65  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store.SaveCurrentFSMState: cannot write m_magazine for weapon=" + m_weapon);
66  return false;
67  }
68 
70  {
71  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store.SaveCurrentFSMState: cannot write m_st for weapon=" + m_weapon);
72  return false;
73  }
74  return true;
75  }
76 
77  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
78  {
79  if (!super.LoadCurrentFSMState(ctx, version))
80  return false;
81 
82  if (!ctx.Read(m_magazine))
83  {
84  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store.LoadCurrentFSMState: cannot read m_magazine for weapon=" + m_weapon);
85  return false;
86  }
88  {
89  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag_Store.LoadCurrentFSMState: cannot read m_dst for weapon=" + m_weapon);
90  return false;
91  }
92  return true;
93  }
94 };
95 
96 /*class WeaponDetachingMag_Store_W4T extends WeaponDetachingMag_Store
97 {
98  override bool IsWaitingForActionFinish () { return true; }
99 };*/
100 
101 class WeaponDetachingMag extends WeaponStateBase
102 {
104  int m_actionType;
105  Magazine m_magazine;
107 
109  ref WeaponDetachingMag_Store m_store;
110  ref MagazineHide_W4T m_hideM;
111 
112  void WeaponDetachingMag (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
113  {
114  m_action = action;
115  m_actionType = actionType;
116 
117  // setup nested state machine
118  m_start = new WeaponDetachingMag_1(m_weapon, this, m_action, m_actionType);
119  m_store = new WeaponDetachingMag_Store(m_weapon, this);
120  m_hideM = new MagazineHide_W4T(m_weapon, this);
121  // events
122  WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
123  WeaponEventBase __md_ = new WeaponEventAnimMagazineDetached;
124  WeaponEventBase __mh_ = new WeaponEventAnimMagazineHide;
125 
126  m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
127  m_fsm.AddTransition(new WeaponTransition(m_start, __md_, m_store));
128  m_fsm.AddTransition(new WeaponTransition(m_store, __mh_, m_hideM));
129  m_fsm.AddTransition(new WeaponTransition(m_hideM, _fin_, NULL));
130 
131  // Safety exits
132  m_fsm.AddTransition(new WeaponTransition(m_store , _fin_, null));
133  m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
134 
135  m_fsm.SetInitialState(m_start);
136  }
137 
138  override void OnEntry (WeaponEventBase e)
139  {
140  if (e != NULL)
141  {
142  WeaponEventDetachMagazine de;
143  if (Class.CastTo(de, e))
144  {
145  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("WeaponDetachingMag type=" + typename.EnumToString(InventoryLocationType, de.m_dst.GetType())); }
146  m_magazine = e.m_magazine;
147  m_dst = de.m_dst;
148 
149  m_store.m_magazine = m_magazine;
150  m_store.m_dst = m_dst;
151  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("WeaponDetachingMag type=" + typename.EnumToString(InventoryLocationType, m_store.m_dst.GetType())); }
152  }
153  }
154  super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
155  }
156 
157  override void OnExit (WeaponEventBase e)
158  {
159  m_dst = NULL;
160  m_magazine = NULL;
161  super.OnExit(e);
162  }
163 
164  override bool SaveCurrentFSMState (ParamsWriteContext ctx)
165  {
166  if (!super.SaveCurrentFSMState(ctx))
167  return false;
168 
169  if (!ctx.Write(m_magazine))
170  {
171  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag.SaveCurrentFSMState: cannot write m_magazine for weapon=" + m_weapon);
172  return false;
173  }
174 
176  {
177  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag.SaveCurrentFSMState: cannot write m_st for weapon=" + m_weapon);
178  return false;
179  }
180  return true;
181  }
182 
183  override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
184  {
185  if (!super.LoadCurrentFSMState(ctx, version))
186  return false;
187 
188  if (!ctx.Read(m_magazine))
189  {
190  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag.LoadCurrentFSMState: cannot read m_magazine for weapon=" + m_weapon);
191  return false;
192  }
194  {
195  Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponDetachingMag.LoadCurrentFSMState: cannot read m_dst for weapon=" + m_weapon);
196  return false;
197  }
198  return true;
199  }
200 };
201 
LoadCurrentFSMState
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
Definition: weaponchambering.c:867
m_dst
ref InventoryLocation m_dst
Definition: dayzplayerinventory.c:13
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
OnAbort
override void OnAbort()
Definition: remotedetonator.c:300
LogManager
Definition: debug.c:734
OptionalLocationReadFromContext
bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
Definition: inventorylocation.c:605
OnExit
override void OnExit(HandEventBase e)
Definition: hand_states.c:28
wpnDebugPrint
void wpnDebugPrint(string s)
Definition: debug.c:9
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
m_action
class WeaponEndAction extends WeaponStartAction m_action
WeaponStartAction
simple class starting animation action specified by m_action and m_actionType
Definition: weaponchambering.c:2
WeaponActions
WeaponActions
actions
Definition: human.c:808
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
OptionalLocationWriteToContext
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
Definition: inventorylocation.c:583
m_start
ref WeaponStateBase m_start
Definition: weaponchambering.c:637
SaveCurrentFSMState
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
Definition: weaponchambering.c:848
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
Object
Definition: objecttyped.c:1
WeaponTransition
enum FSMTransition WeaponTransition
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
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
WeaponFSM
weapon finite state machine
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
OnEntry
HandStateEquipped OnEntry
Definition: weaponchambering.c:208
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78