Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
hand_guards.c
Go to the documentation of this file.
1 
7 {
14  bool GuardCondition(HandEventBase e) { return true; }
15 };
16 
17 
18 class HandGuardAnd extends HandGuardBase
19 {
20  ref HandGuardBase m_arg0;
21  ref HandGuardBase m_arg1;
22 
23  void HandGuardAnd(HandGuardBase arg0 = null, HandGuardBase arg1 = null) { m_arg0 = arg0; m_arg1 = arg1; }
24 
25  override bool GuardCondition(HandEventBase e)
26  {
27  bool result = m_arg0.GuardCondition(e) && m_arg1.GuardCondition(e);
28 
29  #ifdef DEVELOPER
30  if ( LogManager.IsInventoryHFSMLogEnable() )
31  {
32  Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type() + " && " + m_arg1.Type(), "HandGuardAnd" , "n/a", "GuardCondition", e.m_Player.ToString() );
33  }
34  #endif
35 
36  return result;
37  }
38 };
39 
40 class HandGuardNot extends HandGuardBase
41 {
42  ref HandGuardBase m_arg0;
43 
44  void HandGuardNot(HandGuardBase arg0 = null) { m_arg0 = arg0; }
45 
46  override bool GuardCondition(HandEventBase e)
47  {
48  bool result = !m_arg0.GuardCondition(e);
49 
50  #ifdef DEVELOPER
51  if ( LogManager.IsInventoryHFSMLogEnable() )
52  {
53  Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type(), "HandGuardNot" , "n/a", "GuardCondition", e.m_Player.ToString() );
54  }
55  #endif
56  return result;
57  }
58 };
59 
60 class HandGuardOr extends HandGuardBase
61 {
62  ref HandGuardBase m_arg0;
63  ref HandGuardBase m_arg1;
64 
65  void HandGuardOr(HandGuardBase arg0 = null, HandGuardBase arg1 = null) { m_arg0 = arg0; m_arg1 = arg1; }
66 
67  override bool GuardCondition(HandEventBase e)
68  {
69  bool result = m_arg0.GuardCondition(e) || m_arg1.GuardCondition(e);
70 
71  #ifdef DEVELOPER
72  if ( LogManager.IsInventoryHFSMLogEnable() )
73  {
74  Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type() + " || " + m_arg1.Type(), "HandGuardOr" , "n/a", "GuardCondition", e.m_Player.ToString() );
75  }
76  #endif
77  return result;
78  }
79 };
80 
82 {
83  protected Man m_Player;
84  void HandGuardHasItemInEvent(Man p = null) { m_Player = p; }
85 
86  override bool GuardCondition(HandEventBase e)
87  {
88  EntityAI eai = e.GetSrcEntity();
89  if (eai != NULL /* && CanTakeInHands*/)
90  {
91  #ifdef DEVELOPER
92  if ( LogManager.IsInventoryHFSMLogEnable() )
93  {
94  Debug.InventoryHFSMLog("GuardCondition result: true - " + eai, "HandGuardHasItemInEvent" , "n/a", "GuardCondition", m_Player.ToString() );
95  }
96  #endif
97  return true;
98  }
99 
100  #ifdef DEVELOPER
101  if ( LogManager.IsInventoryHFSMLogEnable() )
102  {
103  Debug.InventoryHFSMLog("GuardCondition result: false - " + eai, "HandGuardHasItemInEvent" , "n/a", "GuardCondition", m_Player.ToString() );
104  }
105  #endif
106 
107  return false;
108  }
109 };
110 
111 class HandGuardHasWeaponInEvent extends HandGuardHasItemInEvent
112 {
113  void HandGuardHasWeapoonInEvent (Man p = null) { }
114 
115  override bool GuardCondition(HandEventBase e)
116  {
117  EntityAI eai = e.GetSrcEntity();
118  bool result = false;
119  if (eai)
120  {
121  if (eai.IsWeapon())
122  {
123  result = true;
124  }
125  }
126  #ifdef DEVELOPER
127  if ( LogManager.IsInventoryHFSMLogEnable() )
128  {
129  Debug.InventoryHFSMLog("GuardCondition result: " + result,"HandGuardHasWeaponInEvent", "n/a", "GuardCondition", e.m_Player.ToString() );
130  }
131  #endif
132  return result;
133  }
134 };
135 
136 class HandGuardIsSameItemInHands extends HandGuardBase
137 {
138  protected Man m_Player;
139  void HandGuardIsSameItemInHands(Man p = null) { m_Player = p; }
140 
141  override bool GuardCondition(HandEventBase e)
142  {
143  bool result = false;
144  if (e.GetSrcEntity() == m_Player.GetHumanInventory().GetEntityInHands())
145  {
146  result = true;
147  }
148 
149  #ifdef DEVELOPER
150  if ( LogManager.IsInventoryHFSMLogEnable() )
151  {
152  Debug.InventoryHFSMLog("GuardCondition result: " + result + " - srcItem = " + e.GetSrcEntity() + " hnd= " + m_Player.GetHumanInventory().GetEntityInHands(), "HandGuardIsSameItemInHands" , "n/a", "GuardCondition", e.m_Player.ToString() );
153  }
154  #endif
155  return result;
156  }
157 };
158 
159 class HandGuardHasDestroyedItemInHands extends HandGuardBase
160 {
161  protected Man m_Player;
162  void HandGuardHasDestroyedItemInHands(Man p = null) { m_Player = p; }
163 
164  override bool GuardCondition(HandEventBase e)
165  {
166  EntityAI hnd = m_Player.GetHumanInventory().GetEntityInHands();
167  if (e.GetSrcEntity())
168  {
169  if (e.GetSrcEntity() == hnd)
170  {
171  #ifdef DEVELOPER
172  if ( LogManager.IsInventoryHFSMLogEnable() )
173  {
174  Debug.InventoryHFSMLog("GuardCondition result: true - has same entity in hands " + hnd, "HandGuardHasDestroyedItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
175  }
176  #endif
177  return true;
178  }
179 
180  if (hnd == null)
181  {
182  #ifdef DEVELOPER
183  if ( LogManager.IsInventoryHFSMLogEnable() )
184  {
185  Debug.InventoryHFSMLog("GuardCondition result: true - hands already empty", "HandGuardHasDestroyedItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
186  }
187  #endif
188  return true;
189  }
190  }
191  else
192  {
193  #ifdef DEVELOPER
194  if ( LogManager.IsInventoryHFSMLogEnable() )
195  {
196  Debug.InventoryHFSMLog("GuardCondition result: true - hands already empty and item destroyed", "HandGuardHasDestroyedItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
197  }
198  #endif
199  return true;
200  }
201  #ifdef DEVELOPER
202  if ( LogManager.IsInventoryHFSMLogEnable() )
203  {
204  Debug.InventoryHFSMLog("GuardCondition result: false - destroyed entity not in hands", "HandGuardHasDestroyedItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
205  }
206  #endif
207  return false;
208  }
209 };
210 
211 class HandGuardHasItemInHands extends HandGuardBase
212 {
213  protected Man m_Player;
214  void HandGuardHasItemInHands(Man p = null) { m_Player = p; }
215 
216  override bool GuardCondition(HandEventBase e)
217  {
218  bool result = false;
219  if (m_Player.GetHumanInventory().GetEntityInHands())
220  {
221  result = true;
222  }
223 
224  #ifdef DEVELOPER
225  if ( LogManager.IsInventoryHFSMLogEnable() )
226  {
227  Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_Player.GetHumanInventory().GetEntityInHands(), "HandGuardHasItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
228  }
229  #endif
230  return result;
231  }
232 };
233 
235 class HandGuardHasRoomForItem extends HandGuardBase
236 {
237  protected Man m_Player;
238  void HandGuardHasRoomForItem(Man p = null) { m_Player = p; }
239 
240  override bool GuardCondition(HandEventBase e)
241  {
242  if (e.GetDst() && e.GetDst().IsValid())
243  {
244  if ( !GetGame().IsDedicatedServer())
245  {
246  if (m_Player)
247  m_Player.GetHumanInventory().ClearInventoryReservationEx(e.GetDst().GetItem(),e.GetDst());
248  }
249 
250  if (!GameInventory.LocationTestAddEntity(e.GetDst(), false, true, true, true, true, false))
251  {
252  #ifdef DEVELOPER
253  if ( LogManager.IsInventoryHFSMLogEnable() )
254  {
255  Debug.InventoryHFSMLog("GuardCondition result: false - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()), "HandGuardHasRoomForItem" , "n/a", "GuardCondition", m_Player.ToString() );
256  }
257  #endif
258  //if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] HandGuardHasRoomForItem - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()));
259  //Error("[hndfsm] HandGuardHasRoomForItem - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()));
260  return false;
261  }
262 
263 
264  if ( !GetGame().IsDedicatedServer())
265  {
266  if (m_Player)
267  m_Player.GetHumanInventory().AddInventoryReservationEx(e.GetDst().GetItem(), e.GetDst(), GameInventory.c_InventoryReservationTimeoutShortMS);
268  }
269 
270  #ifdef DEVELOPER
271  if ( LogManager.IsInventoryHFSMLogEnable() )
272  {
273  Debug.InventoryHFSMLog("GuardCondition result: true", "HandGuardHasRoomForItem" , "n/a", "GuardCondition", m_Player.ToString() );
274  }
275  #endif
276  return true;
277  }
278 
279  #ifdef DEVELOPER
280  if ( LogManager.IsInventoryHFSMLogEnable() )
281  {
282  Debug.InventoryHFSMLog("GuardCondition result: false - e.m_Dst is null", "HandGuardHasRoomForItem" , "n/a", "GuardCondition", m_Player.ToString() );
283  }
284  #endif
285 
286  return false;
287  }
288 };
289 
290 class HandGuardCanMove extends HandGuardBase
291 {
292  protected Man m_Player;
293  void HandGuardCanMove(Man p = null) { m_Player = p; }
294 
295  override bool GuardCondition(HandEventBase e)
296  {
297  HandEventMoveTo es = HandEventMoveTo.Cast(e);
298 
299  bool result = e.m_IsJuncture || e.m_IsRemote;
300  if (result == false)
301  {
302  result = GameInventory.LocationCanMoveEntity(es.GetSrc(), es.GetDst());
303  }
304 
305  #ifdef DEVELOPER
306  if ( LogManager.IsInventoryHFSMLogEnable() )
307  {
308  Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanMove" , "n/a", "GuardCondition", m_Player.ToString() );
309  }
310  #endif
311 
312  return result;
313  }
314 };
315 
316 class HandGuardCanSwap extends HandGuardBase
317 {
318  protected Man m_Player;
319  void HandGuardCanSwap(Man p = NULL) { m_Player = p; }
320 
321  override bool GuardCondition(HandEventBase e)
322  {
323  HandEventSwap es = HandEventSwap.Cast(e);
324 
325  bool result = e.m_IsJuncture || e.m_IsRemote;
326  if (result == false)
327  {
328  result = GameInventory.CanSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Src2.GetItem());
329  }
330 
331  #ifdef DEVELOPER
332  if ( LogManager.IsInventoryHFSMLogEnable() )
333  {
334  Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanSwap" , "n/a", "GuardCondition", m_Player.ToString() );
335  }
336  #endif
337  //if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] HandGuardCanSwap guard - cannot swap");
338  return result;
339  }
340 };
341 
342 class HandGuardCanForceSwap extends HandGuardBase
343 {
344  protected Man m_Player;
345  void HandGuardCanForceSwap(Man p = NULL) { m_Player = p; }
346 
347  override bool GuardCondition(HandEventBase e)
348  {
349  HandEventForceSwap es = HandEventForceSwap.Cast(e);
350 
351  bool result = e.m_IsJuncture || e.m_IsRemote;
352  if (result == false)
353  {
354  result = GameInventory.CanSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Src2.GetItem());
355 
356  if (result == false && es.m_Dst2)
357  {
358  result = GameInventory.CanForceSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Dst, es.m_Src2.GetItem(), es.m_Dst2);
359  }
360  }
361 
362  #ifdef DEVELOPER
363  if ( LogManager.IsInventoryHFSMLogEnable() )
364  {
365  Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanForceSwap" , "n/a", "GuardCondition", m_Player.ToString() );
366  }
367  #endif
368 
369  return result;
370  }
371 };
372 
373 class HandGuardInstantForceSwap extends HandGuardBase
374 {
375  protected Man m_Player;
376  void HandGuardInstantForceSwap(Man p = NULL) { m_Player = p; }
377 
378  override bool GuardCondition(HandEventBase e)
379  {
380  HandEventForceSwap es = HandEventForceSwap.Cast(e);
381 
382  InventoryLocation src1 = es.m_Src;
383  InventoryLocation dst2 = es.m_Dst2;
384 
385  bool result = false;
386  if (src1.GetType() == InventoryLocationType.CARGO && dst2.GetType() == InventoryLocationType.CARGO)
387  {
388  if (src1.GetParent() == dst2.GetParent())
389  {
390  result = true;
391  }
392  }
393 
394  #ifdef DEVELOPER
395  if (LogManager.IsInventoryHFSMLogEnable())
396  {
397  Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardInstantForceSwap" , "n/a", "GuardCondition", m_Player.ToString() );
398  }
399  #endif
400 
401  return result;
402  }
403 };
404 
406 
GetGame
proto native CGame GetGame()
HandGuardBase
TODO(kumarjac): This guard is unused but it has a fault and doesn't conform with maximimal/minimal ch...
Definition: hand_guards.c:6
LogManager
Definition: debug.c:734
HandEventSwap
Definition: hand_events.c:659
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
HandEventBase
Abstracted event, not to be used, only inherited.
Definition: hand_events.c:194
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
HandGuardHasItemInEvent
Definition: hand_guards.c:111
Debug
Definition: debug.c:13
GuardCondition
class BulletHide extends WeaponStateBase GuardCondition
Definition: guards.c:582
EntityAI
Definition: building.c:5
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78