Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
bleedingsourcesmanagerbase.c
Go to the documentation of this file.
2 {
5  ref map<int, int> m_BleedingSourcesByLocation = new map<int, int>;
6  static ref map<int, int> m_BleedingSourcesZonesMaskByLocation = new map<int, int>;//for each inventory location, keep a bitmask where a bit is set to 1 for each bleeding source zone that belongs to that location
7  static ref set<int> m_BleedingSourcesLocationsList = new set<int>;
8  ItemBase m_Item;//item used to remove the bleeding source
9  PlayerBase m_Player;
10  //ref map<string, int> m_FireGeomToBit = new map<string, int>;
11  ref map<int, string> m_BitToFireGeom = new map<int, string>;
12  protected int m_Bit;
13  int m_BitOffset = 0;
14 
16  {
17  m_Player = player;
18  Init();
19  }
20 
21  protected void Init()
22  {
23  //dmgZone_head
24  RegisterBleedingZoneEx("Head",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.MASK);
25  //dmgZone_torso
26  RegisterBleedingZoneEx("Neck", PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL,"", "-180 0 0" , "0.02 -0.05 0.05", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.HEADGEAR);
27  RegisterBleedingZoneEx("Pelvis",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -135 0" , "0 0.12 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
28  RegisterBleedingZoneEx("Spine",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 55 0" , "0 -0.1 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
29  RegisterBleedingZoneEx("Spine1",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 155 0" , "0 -0.1 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
30  RegisterBleedingZoneEx("Spine2",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 55 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
31  RegisterBleedingZoneEx("Spine3",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 155 0" , "0 -0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH, "BleedingSourceEffect",InventorySlots.BODY);
32  //dmgZone_leftArm
33  RegisterBleedingZoneEx("LeftShoulder",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect", InventorySlots.BODY);
34  RegisterBleedingZoneEx("LeftArm", PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "","0 90 90" , "0 -0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
35  RegisterBleedingZoneEx("LeftArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
36  RegisterBleedingZoneEx("LeftForeArm",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
37  //dmgZone_rightArm
38  RegisterBleedingZoneEx("RightShoulder",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
39  RegisterBleedingZoneEx("RightArm", PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL,"", "0 -90 0" , "0 0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
40  RegisterBleedingZoneEx("RightArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
41  RegisterBleedingZoneEx("RightForeArm",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.05 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.BODY);
42  //dmgZone_leftHand
43  RegisterBleedingZoneEx("LeftForeArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0.1 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.GLOVES);
44  //dmgZone_rightHand
45  RegisterBleedingZoneEx("RightForeArmRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "-0.1 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.GLOVES);
46  //dmgZone_leftLeg
47  RegisterBleedingZoneEx("LeftLeg",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
48  RegisterBleedingZoneEx("LeftLegRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
49  RegisterBleedingZoneEx("LeftUpLeg",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.12 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
50  RegisterBleedingZoneEx("LeftUpLegRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM , "BleedingSourceEffect",InventorySlots.LEGS);
51  //dmgZone_rightLeg
52  RegisterBleedingZoneEx("RightLeg",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.06 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
53  RegisterBleedingZoneEx("RightLegRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
54  RegisterBleedingZoneEx("RightUpLeg",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.12 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
55  RegisterBleedingZoneEx("RightUpLegRoll",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.06 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM, "BleedingSourceEffect",InventorySlots.LEGS);
56  //dmgZone_leftFoot
57  RegisterBleedingZoneEx("LeftFoot",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 180 0" , "0 0 0.035", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.LEGS);
58  RegisterBleedingZoneEx("LeftToeBase",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 -90 0" , "0 0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffect",InventorySlots.FEET);
59  //dmgZone_rightFoot
60  RegisterBleedingZoneEx("RightFoot",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 0 0" , "0 0 -0.035", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffectLight", InventorySlots.LEGS);
61  RegisterBleedingZoneEx("RightToeBase",PlayerConstants.BLEEDING_SOURCE_DURATION_NORMAL, "", "0 90 0" , "0 -0.07 0", PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW, "BleedingSourceEffect", InventorySlots.FEET);
62  }
63 
64  protected void SetItem(ItemBase item)
65  {
66  m_Item = item;
67  }
68 
69 
70  set<int> GetBleedingSourcesLocations()
71  {
72  return m_BleedingSourcesLocationsList;
73  }
74 
75 
76  //for inventory location, get the active bits
77  int GetBleedingSourceBitsByInvLocation(int inv_location)
78  {
79  if (m_BleedingSourcesByLocation.Contains(inv_location))
80  {
81  return m_BleedingSourcesByLocation.Get(inv_location);
82  }
83 
84  return 0;
85  }
86 
87  //for inventory location, get the active bits
88  int GetFreeBleedingSourceBitsByInvLocation(int inv_location)
89  {
90  if (m_BleedingSourcesZonesMaskByLocation.Contains(inv_location))
91  {
92  return (~m_BleedingSourcesZonesMaskByLocation.Get(inv_location) & GetBleedingSourceBitsByInvLocation(inv_location)) | (m_BleedingSourcesZonesMaskByLocation.Get(inv_location) & ~GetBleedingSourceBitsByInvLocation(inv_location));//xor
93  }
94 
95  return 0;
96  }
97 
98  bool IsBleedingSourceActive(string name)
99  {
100  name.ToLower();
101  int bit = GetBitFromSelectionName(name);
102 
103  return m_Player.GetBleedingBits() & bit;
104  }
105 
106 
107  protected int GetBitFromSelectionID(int id)
108  {
109  CachedObjectsArrays.ARRAY_STRING.Clear();
110  m_Player.GetActionComponentNameList(id, CachedObjectsArrays.ARRAY_STRING, "fire");
111 
112  for (int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
113  {
114  /*
115  string name = CachedObjectsArrays.ARRAY_STRING.Get(i);
116  PrintString(name);
117  */
118  int bit = GetBitFromSelectionName(CachedObjectsArrays.ARRAY_STRING.Get(i));
119  if ( bit !=0 )
120  {
121  return bit;
122  }
123  }
124  return 0;
125  }
126 
127  protected BleedingSourceZone GetBleedingSourceMeta(int bit)
128  {
129  return m_BleedingSourceZone.Get(GetSelectionNameFromBit(bit));
130  }
131 
132  int GetRegisteredSourcesCount()
133  {
134  return m_BitOffset;
135  }
136 
137  protected void RegisterBleedingZoneEx(string name, int max_time, string bone = "", vector orientation = "0 0 0", vector offset = "0 0 0", float flow_modifier = 1, string particle_name = "BleedingSourceEffect", int inv_location = 0)
138  {
139  if ( m_BitOffset == BIT_INT_SIZE)
140  {
141  Error("Too many bleeding sources, max is "+BIT_INT_SIZE.ToString());
142  }
143  else
144  {
145  name.ToLower();
146  //PrintString(name);
147  //int bit = Math.Pow(2, m_BitOffset);
148  m_Bit = 1 << m_BitOffset;
149  //PrintString(bit.ToString());
150  string bone_name = bone;
151 
152  if (bone_name == "")
153  {
154  bone_name = name;
155  }
156 
157  m_BleedingSourceZone.Insert(name, new BleedingSourceZone(name, m_Bit, offset, orientation, bone_name, max_time, flow_modifier, particle_name));
158  m_BleedingSourceZone.Get(name).SetInvLocation(inv_location);
159  m_BitToFireGeom.Insert(m_Bit, name);
160  m_BleedingSourcesZonesMaskByLocation.Set( inv_location, m_BleedingSourcesZonesMaskByLocation.Get(inv_location) | m_Bit);//set a bit to 1 to already existing bitmask for that location
161  m_BleedingSourcesLocationsList.Insert(inv_location);
162  m_BitOffset++;
163  }
164  }
165  protected void RegisterBleedingZone(string name, int max_time, string bone = "", vector orientation = "0 0 0", vector offset = "0 0 0", float flow_modifier = 1, string particle_name = "BleedingSourceEffect")
166  {
167  RegisterBleedingZoneEx(name, max_time, bone, orientation, offset, flow_modifier, particle_name);
168  }
169 
170  void RemoveAllSources()
171  {
172  //int count = m_BleedingSources.Count();
173  while (m_BleedingSources.Count() > 0 )
174  {
175  int bit = m_BleedingSources.GetKey(0);
176  RemoveBleedingSource(bit);
177  }
178  }
179 
180  protected int GetBitFromSelectionName(string name)
181  {
182  if (!m_BleedingSourceZone.Get(name))
183  {
184  return 0;
185  }
186  return m_BleedingSourceZone.Get(name).GetBit();
187  }
188 
189  protected string GetSelectionNameFromBit(int bit)
190  {
191  return m_BitToFireGeom.Get(bit);
192  }
193 
194  bool AttemptAddBleedingSource(int component)
195  {
196  int bit = GetBitFromSelectionID(component);
197 
198  if ( bit == 0 )
199  {
200  return false;
201  }
202 
203  if ( CanAddBleedingSource(bit) )
204  {
205  AddBleedingSource(bit);
206  return true;
207  }
208  return false;
209  }
210 
211  bool AttemptAddBleedingSourceBySelection(string selection_name)
212  {
213  selection_name.ToLower();
214  int bit = GetBitFromSelectionName(selection_name);
215 
216  if ( bit == 0 )
217  {
218  return false;
219  }
220 
221  if ( CanAddBleedingSource(bit) )
222  {
223  AddBleedingSource(bit);
224  return true;
225  }
226  return false;
227  }
228 
229 
230  bool AttemptAddBleedingSourceDirectly(int bit, eBleedingSourceType type = eBleedingSourceType.NORMAL, int context = 0)
231  {
232  if(CanAddBleedingSource(bit))
233  {
234  AddBleedingSourceEx(bit, type, context);
235  return true;
236  }
237  return false;
238  }
239 
240 
241  protected bool CanAddBleedingSource(int bit)
242  {
243  if (!GetBleedingSourceMeta(bit))
244  {
245  return false;
246  }
247  if ((m_Player.GetBleedingBits() & bit) == 0)
248  {
249  return true;
250  }
251  return false;
252  }
253 
254  protected void AddBleedingSourceEx(int bit, eBleedingSourceType type = eBleedingSourceType.NORMAL, int context = 0)
255  {
256  AddBleedingSource(bit);
257  m_BleedingSources.Get(bit).SetType(type);
258  }
259 
260  protected void AddBleedingSource(int bit)
261  {
262  BleedingSourceZone bsz = GetBleedingSourceMeta(bit);
263  vector orientation = bsz.GetOrientation();
264  vector offset = bsz.GetOffset();
265  string bone_name = bsz.GetBoneName();
266  float flow_modifier = bsz.GetFlowModifier();
267  int max_time = bsz.GetMaxTime();
268  string particle_name = bsz.GetParticleName();
269  int inventory_loc = bsz.GetInvLocation();
270  m_BleedingSourcesByLocation.Set(inventory_loc, (m_BleedingSourcesByLocation.Get(inventory_loc) | bit));
271  m_BleedingSources.Insert(bit, new BleedingSource(m_Player, bit,bone_name, orientation, offset, max_time, flow_modifier, particle_name) );
272  }
273 
274  int GetBleedingSourceActiveTime(int bit)
275  {
276  int time = -1;
277  if (m_BleedingSources.Contains(bit))
278  {
279  time = m_BleedingSources.Get(bit).GetActiveTime();
280  }
281  return time;
282  }
283 
284  void SetBleedingSourceActiveTime(int bit, int time)
285  {
286  if (m_BleedingSources.Contains(bit))
287  {
288  m_BleedingSources.Get(bit).SetActiveTime(time);
289  }
290  }
291 
292  void SetBleedingSourceType(int bit, eBleedingSourceType type)
293  {
294  if (m_BleedingSources.Contains(bit))
295  {
296  m_BleedingSources.Get(bit).SetType(type);
297  }
298  }
299  eBleedingSourceType GetBleedingSourceType(int bit)
300  {
301  if (m_BleedingSources.Contains(bit))
302  {
303  return m_BleedingSources.Get(bit).GetType();
304  }
305  return -1;
306  }
307 
308  protected bool RemoveBleedingSource(int bit)
309  {
310  if (m_BleedingSources.Contains(bit))
311  {
312  BleedingSourceZone bsz = GetBleedingSourceMeta(bit);
313  int inventory_loc = bsz.GetInvLocation();
314  m_BleedingSourcesByLocation.Set(inventory_loc, (m_BleedingSourcesByLocation.Get(inventory_loc) & ~bit));//deactivate the bit
315  m_BleedingSources.Remove(bit);
316  return true;
317  }
318  return false;
319  }
320 
321  int GetBleedingSourcesCount()
322  {
323  return m_BleedingSources.Count();
324  }
325 
326  /*void ChangeBleedingIndicatorVisibility(bool visible)
327  {
328  int count = m_BleedingSources.Count();
329  for (int i = 0; i < count; i++)
330  {
331  m_BleedingSources.GetElement(i).ToggleSourceBleedingIndication(visible);
332  }
333  }*/
334 }
ItemBase
Definition: inventoryitem.c:730
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
BleedingSourcesManagerBase
Definition: bleedingsourcesmanagerbase.c:1
eBleedingSourceType
eBleedingSourceType
Definition: bleedingsource.c:1
BleedingSource
void BleedingSource(PlayerBase player, int bit, string bone, vector orientation, vector offset, int max_time, float flow_modifier, string particle_name)
Definition: bleedingsource.c:27
BleedingSourceZone
Definition: bleedingsourcezone.c:1
m_Item
protected EntityAI m_Item
Definition: radialquickbarmenu.c:14
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
PlayerConstants
Definition: playerconstants.c:1
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
m_Bit
int m_Bit
Definition: bleedingsource.c:12
BIT_INT_SIZE
const int BIT_INT_SIZE
Definition: bitarray.c:4
CachedObjectsArrays
Definition: utilityclasses.c:40