Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
handanimated_guards.c
Go to the documentation of this file.
1 int SlotToAnimType(notnull Man player, notnull InventoryLocation src, InventoryLocation dst = null)
2 {
3  //Print("src.GetType() " + src.GetType());
5  //InventoryLocation invloc2 = new InventoryLocation;
6 
7  if ( (dst && dst.GetParent() && !dst.GetParent().GetHierarchyRootPlayer()) || (src && src.GetParent() && !src.GetParent().GetHierarchyRootPlayer()) )
8  return -1;
9 
10  if (dst && (dst.GetType() == InventoryLocationType.ATTACHMENT || dst.GetType() == InventoryLocationType.CARGO))
11  {
12  invloc1.Copy(dst);
13  //invloc2.Copy(src);
14  }
15  else if (src.GetType() == InventoryLocationType.ATTACHMENT || src.GetType() == InventoryLocationType.CARGO)
16  {
17  invloc1.Copy(src);
18  //invloc2.Copy(dst);
19  }
20  else
21  {
22  return -1;
23  }
24 
25  int val = -1;
26  if ( invloc1.GetItem() && invloc1.GetItem().GetInventoryHandAnimation(invloc1,val) )
27  {
28  return val;
29  }
30 
31  if (invloc1.GetType() == InventoryLocationType.ATTACHMENT /*|| src.GetType() == InventoryLocationType.HANDS*/)
32  {
33  //return WeaponHideShowTypes.HIDESHOW_SLOT_KNIFEBACK;
34  switch (invloc1.GetSlot())
35  {
36  case InventorySlots.SHOULDER:
37  {
38  if (invloc1.GetItem() && invloc1.GetItem().IsWeapon())
39  {
40  return WeaponHideShowTypes.HIDESHOW_SLOT_RFLLEFTBACK;
41  }
42  else if (invloc1.GetItem() && invloc1.GetItem().IsOneHandedBehaviour())
43  {
44  return WeaponHideShowTypes.HIDESHOW_SLOT_1HDLEFTBACK;
45  }
46  return WeaponHideShowTypes.HIDESHOW_SLOT_2HDLEFTBACK;
47  }
48  case InventorySlots.MELEE:
49  {
50  if (invloc1.GetItem() && invloc1.GetItem().IsWeapon())
51  {
52  return WeaponHideShowTypes.HIDESHOW_SLOT_RFLRIGHTBACK;
53  }
54  else if (invloc1.GetItem() && invloc1.GetItem().IsOneHandedBehaviour())
55  {
56  return WeaponHideShowTypes.HIDESHOW_SLOT_1HDRIGHTBACK;
57  }
58  return WeaponHideShowTypes.HIDESHOW_SLOT_2HDRIGHTBACK;
59  }
60  case InventorySlots.PISTOL:
61  {
62  EntityAI parent_item = invloc1.GetParent(); // belt
63  Man owner;
64  if (parent_item)
65  owner = parent_item.GetHierarchyRootPlayer(); // player
66  if (!owner)
67  return -1;
68 
69  EntityAI item1 = owner.GetInventory().FindAttachment(InventorySlots.HIPS);
70  EntityAI item2 = parent_item.GetHierarchyParent();
71  if (owner && item1 == item2) // is the pistol in a belt holster?
72  {
73  return WeaponHideShowTypes.HIDESHOW_SLOT_PISTOLBELT;
74  }
75  return WeaponHideShowTypes.HIDESHOW_SLOT_PISTOLCHEST;
76  }
77  case InventorySlots.KNIFE:
78  return WeaponHideShowTypes.HIDESHOW_SLOT_KNIFEBACK;
79 
80  /*case InventorySlots.VEST:
81  case InventorySlots.FEET:
82  case InventorySlots.BODY:
83  case InventorySlots.LEGS:
84  case InventorySlots.BACK:
85  case InventorySlots.HIPS:
86  case InventorySlots.HEADGEAR:
87  return WeaponHideShowTypes.HIDESHOW_SLOT_INVENTORY;*/
88 
89  default:
90  return WeaponHideShowTypes.HIDESHOW_SLOT_INVENTORY;
91  //Print("[hndfsm] SlotToAnimType - not animated slot in src_loc=" + InventoryLocation.DumpToStringNullSafe(invloc1));
92  };
93  //
94  //if (InventorySlots.GetSlotIdFromString("Pistol"))
95  }
96  else if (invloc1.GetType() == InventoryLocationType.CARGO)
97  {
98  if ( invloc1.GetItem() && (invloc1.GetItem().GetInventory().HasInventorySlot(InventorySlots.SHOULDER) || invloc1.GetItem().GetInventory().HasInventorySlot(InventorySlots.MELEE)) )
99  {
100  //Print("Special inventory anim");
101  if (invloc1.GetItem() && invloc1.GetItem().IsWeapon())
102  {
103  return WeaponHideShowTypes.HIDESHOW_SLOT_RFLRIGHTBACK;
104  }
105  else if (invloc1.GetItem() && invloc1.GetItem().IsOneHandedBehaviour())
106  {
107  return WeaponHideShowTypes.HIDESHOW_SLOT_1HDRIGHTBACK;
108  }
109  return WeaponHideShowTypes.HIDESHOW_SLOT_2HDRIGHTBACK;
110  }
111  //Print("Default inventory anim");
112  return WeaponHideShowTypes.HIDESHOW_SLOT_INVENTORY; //default item animation
113  }
114  return -1;
115 }
116 
117 bool SelectAnimationOfTakeToHands(notnull Man player, notnull InventoryLocation src, notnull InventoryLocation dst, out int animType)
118 {
119  if (player.IsInTransport())
120  return false;
121  if (src.GetType() == InventoryLocationType.GROUND)
122  return false;
123 
124  if (src.GetItem().GetHierarchyRootPlayer() == player)
125  {
126  animType = SlotToAnimType(player, src);
127  if (animType != -1)
128  {
129  if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfTakeToHands - selected animType=" + animType + " for item=" + src.GetItem());
130  return true;
131  }
132  }
133  if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfTakeToHands - no animation");
134  return false;
135 }
136 
137 bool SelectAnimationOfMoveFromHands(notnull Man player, notnull InventoryLocation src, notnull InventoryLocation dst, out int animType)
138 {
139  if (player.IsInTransport())
140  return false;
141 
142  if (src.GetItem().GetHierarchyRootPlayer() == player)
143  {
144  animType = SlotToAnimType(player, dst);
145  if (animType != -1)
146  {
147  if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfMoveFromHands guard - selected animType=" + animType + " for item=" + src.GetItem());
148  return true;
149  }
150  }
151  if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfMoveFromHands - no animation");
152  return false;
153 }
154 
155 bool SelectAnimationOfForceSwapInHands(notnull Man player, notnull InventoryLocation old_src, notnull InventoryLocation new_src, notnull InventoryLocation old_dst, notnull InventoryLocation new_dst, out int animType1, out int animType2)
156 {
157  if (player.IsInTransport())
158  return false;
159 
160  if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SlotToAnimType - old_src=" + InventoryLocation.DumpToStringNullSafe(old_src) + " new_src=" + InventoryLocation.DumpToStringNullSafe(new_src) + " old_dst=" + InventoryLocation.DumpToStringNullSafe(old_dst) + " new_dst=" + InventoryLocation.DumpToStringNullSafe(new_dst));
161 
162  if (old_src.GetItem().GetHierarchyRootPlayer() == player || new_src.GetItem().GetHierarchyRootPlayer() == player)
163  {
164  animType1 = SlotToAnimType(player, old_src, old_dst);
165  animType2 = SlotToAnimType(player, new_src, new_dst);
166  //Print("animType1 = " + animType1);
167  //Print("animType2 = " + animType2);
168  if (animType1 != -1 && animType2 != -1)
169  {
170  if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfForceSwapInHands guard - selected animType1=" + animType1 + " animType2=" + animType2 + " for old_item=" + old_src.GetItem() + " for new_item=" + new_src.GetItem());
171  return true;
172  }
173  /*else if (animType1 != -1 || animType2 != -1) //HACK
174  {
175  animType1 = -1;
176  animType2 = -1;
177  return false;
178  }*/
179  }
180  if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] SelectAnimationOfForceSwapInHands - no animation");
181  return false;
182 }
183 
184 
185 class HandSelectAnimationOfTakeToHandsEvent extends HandGuardBase
186 {
187  void HandSelectAnimationOfTakeToHandsEvent(Man p = null) { }
188 
189  override bool GuardCondition(HandEventBase e)
190  {
191  int animType = -1;
192  if (SelectAnimationOfTakeToHands(e.m_Player, e.GetSrc(), e.GetDst(), animType))
193  {
194  e.m_AnimationID = animType;
195  return true;
196  }
197  return false;
198  }
199 };
200 
201 class HandSelectAnimationOfMoveFromHandsEvent extends HandGuardBase
202 {
203  protected Man m_Player;
204 
205  void HandSelectAnimationOfMoveFromHandsEvent(Man p = null)
206  {
207  m_Player = p;
208  }
209 
210  override bool GuardCondition(HandEventBase e)
211  {
212  EntityAI eai = m_Player.GetHumanInventory().GetEntityInHands();
213  if (eai)
214  {
216  if (eai.GetInventory().GetCurrentInventoryLocation(src))
217  {
218  if (e.m_IsJuncture == false && e.m_IsRemote == false)
219  {
220  if (!GameInventory.LocationCanMoveEntity(src, e.GetDst()))
221  {
222  if (LogManager.IsInventoryHFSMLogEnable())
223  {
224  hndDebugPrint("[hndfsm] HandSelectAnimationOfMoveFromHandsEvent - rejected");
225  }
226 
227  return false;
228  }
229  }
230 
231  int animType = -1;
232  if (SelectAnimationOfMoveFromHands(e.m_Player, src, e.GetDst(), animType))
233  {
234  e.m_AnimationID = animType;
235  return true;
236  }
237  return false;
238  }
239  }
240  return false;
241  }
242 };
243 
245 {
246  protected Man m_Player;
247 
248  void HandSelectAnimationOfForceSwapInHandsEvent(Man p = NULL) { m_Player = p; }
249 
250  bool ProcessSwapEvent(notnull HandEventBase e, out int animType1, out int animType2)
251  {
252  HandEventSwap es = HandEventSwap.Cast(e);
253  if (es)
254  return SelectAnimationOfForceSwapInHands(e.m_Player, es.m_Src, es.m_Src2, es.m_Dst, es.m_Dst2, animType1, animType2);
255  Error("HandSelectAnimationOfForceSwapInHandsEvent - not an swap event");
256  return false;
257  }
258 
259  override bool GuardCondition(HandEventBase e)
260  {
261  HandEventForceSwap es = HandEventForceSwap.Cast(e);
262  if (es)
263  {
264  if (LogManager.IsInventoryHFSMLogEnable())
265  {
266  hndDebugPrint("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent FSwap e=" + e.DumpToString());
267  }
268 
269  if (!es.m_Src2.IsValid() || !es.m_Src.IsValid())
270  {
271  Error("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent - invalid item source");
272  return false;
273  }
274 
275  bool allow = e.m_IsJuncture || e.m_IsRemote;
276  if (allow == false)
277  {
278  if (GameInventory.CanSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Src2.GetItem()))
279  {
280  allow = true; // allow if ordinary swap
281  }
282  else if (es.m_Dst2)
283  {
284  if (GameInventory.CanForceSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Dst, es.m_Src2.GetItem(), es.m_Dst2) == false)
285  {
286  Error("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent - no room at dst=" + InventoryLocation.DumpToStringNullSafe(es.m_Dst2));
287  }
288  else
289  {
290  allow = true;
291  }
292  }
293  }
294 
295  if (allow)
296  {
297  int animType1 = -1;
298  int animType2 = -1;
299  if (ProcessSwapEvent(e, animType1, animType2))
300  {
301  e.m_AnimationID = animType1;
302  es.m_Animation2ID = animType2;
303  return true;
304  }
305  }
306  else
307  {
308  Error("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent - m_HasRoomGuard.GuardCondition failed");
309  }
310  }
311  else
312  {
313  Error("[hndfsm] HandSelectAnimationOfForceSwapInHandsEvent - not a swap event");
314  }
315  return false;
316  }
317 };
318 
319 class HandSelectAnimationOfSwapInHandsEvent extends HandSelectAnimationOfForceSwapInHandsEvent
320 {
321  override bool GuardCondition(HandEventBase e)
322  {
323  HandEventSwap es = HandEventSwap.Cast(e);
324  if (es)
325  {
326  int animType1 = -1;
327  int animType2 = -1;
328  if (ProcessSwapEvent(e, animType1, animType2))
329  {
330  e.m_AnimationID = animType1;
331  es.m_Animation2ID = animType2;
332  return true;
333  }
334  }
335  else
336  Error("[hndfsm] HandSelectAnimationOfSwapInHandsEvent - not a swap event");
337  return false;
338  }
339 };
340 
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
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
SelectAnimationOfTakeToHands
bool SelectAnimationOfTakeToHands(notnull Man player, notnull InventoryLocation src, notnull InventoryLocation dst, out int animType)
Definition: handanimated_guards.c:117
LogManager
Definition: debug.c:734
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
HandEventSwap
Definition: hand_events.c:659
HandSelectAnimationOfForceSwapInHandsEvent
Definition: handanimated_guards.c:319
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
HandEventBase
Abstracted event, not to be used, only inherited.
Definition: hand_events.c:194
SelectAnimationOfMoveFromHands
bool SelectAnimationOfMoveFromHands(notnull Man player, notnull InventoryLocation src, notnull InventoryLocation dst, out int animType)
Definition: handanimated_guards.c:137
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
hndDebugPrint
void hndDebugPrint(string s)
Definition: handfsm.c:1
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
SelectAnimationOfForceSwapInHands
bool SelectAnimationOfForceSwapInHands(notnull Man player, notnull InventoryLocation old_src, notnull InventoryLocation new_src, notnull InventoryLocation old_dst, notnull InventoryLocation new_dst, out int animType1, out int animType2)
Definition: handanimated_guards.c:155
GuardCondition
class BulletHide extends WeaponStateBase GuardCondition
Definition: guards.c:582
SlotToAnimType
int SlotToAnimType(notnull Man player, notnull InventoryLocation src, InventoryLocation dst=null)
Definition: handanimated_guards.c:1
WeaponHideShowTypes
WeaponHideShowTypes
Definition: human.c:922
EntityAI
Definition: building.c:5
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78