Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
damagesystem.c
Go to the documentation of this file.
2 {
3  proto native float GetDamage(string zoneName, string healthType);
4  proto native float GetHighestDamage(string healthType);
5 };
6 
7 //-----------------------------------------------------------------------------
8 
11 {
12  CLOSE_COMBAT, // 0
13  FIRE_ARM, // 1
14  EXPLOSION,
15  STUN,
16  CUSTOM
17 }
18 
19 //-----------------------------------------------------------------------------
20 class DamageSystem
21 {
22  static proto native void CloseCombatDamage(EntityAI source, Object targetObject, int targetComponentIndex, string ammoTypeName, vector worldPos, int directDamageFlags = ProcessDirectDamageFlags.ALL_TRANSFER);
23  static proto native void CloseCombatDamageName(EntityAI source, Object targetObject, string targetComponentName, string ammoTypeName, vector worldPos, int directDamageFlags = ProcessDirectDamageFlags.ALL_TRANSFER);
24 
25  static proto native void ExplosionDamage(EntityAI source, Object directHitObject, string ammoTypeName, vector worldPos, int damageType);
26 
27  static bool GetDamageZoneMap(EntityAI entity, out DamageZoneMap zoneMap)
28  {
29  string path_base;
30  string path;
31 
32  if (entity.IsWeapon())
33  {
34  path_base = CFG_WEAPONSPATH;
35  }
36  else if (entity.IsMagazine())
37  {
38  path_base = CFG_MAGAZINESPATH;
39  }
40  else
41  {
42  path_base = CFG_VEHICLESPATH;
43  }
44 
45  path_base = string.Format("%1 %2 DamageSystem DamageZones", path_base, entity.GetType());
46 
47  if (!GetGame().ConfigIsExisting(path_base))
48  {
49  return false;
50  }
51  else
52  {
53  string zone;
54  array<string> zone_names = new array<string>;
55  array<string> component_names;
56 
57  entity.GetDamageZones(zone_names);
58  for (int i = 0; i < zone_names.Count(); i++)
59  {
60  component_names = new array<string>;
61  zone = zone_names.Get(i);
62 
63  path = string.Format("%1 %2 componentNames ", path_base, zone);
64  if (GetGame().ConfigIsExisting(path))
65  {
66  GetGame().ConfigGetTextArray(path,component_names);
67  }
68  zoneMap.Insert(zone,component_names);
69  }
70 
71  return true;
72  }
73  }
74 
76  static bool GetDamageZoneFromComponentName(notnull EntityAI entity, string component, out string damageZone)
77  {
78  DamageZoneMap zoneMap = entity.GetEntityDamageZoneMap();
79  array<array<string>> components;
80  components = zoneMap.GetValueArray();
81  for (int i = 0; i < components.Count(); i++)
82  {
83  array<string> inner = components.Get(i);
84  for (int j = 0; j < inner.Count(); j++)
85  {
86  string innerComponentName = inner.Get(j);
87  innerComponentName.ToLower();
88 
89  //We don't have a component name, no need to proceed
90  if ( innerComponentName == "" )
91  break;
92 
93  if (innerComponentName == component)
94  {
95  damageZone = zoneMap.GetKey(i);
96  return true;
97  }
98  }
99  }
100  damageZone = "";
101  return false;
102  }
103 
104  static bool GetComponentNamesFromDamageZone(notnull EntityAI entity, string damageZone, out array<string> componentNames)
105  {
106  string path;
107 
108  if (entity.IsWeapon())
109  {
111  }
112  else if (entity.IsMagazine())
113  {
115  }
116  else
117  {
119  }
120 
121  path = string.Format("%1 %2 DamageSystem DamageZones %3 componentNames", path, entity.GetType(), damageZone);
122  if (GetGame().ConfigIsExisting(path))
123  {
124  GetGame().ConfigGetTextArray(path,componentNames);
125  return true;
126  }
127 
128  return false;
129  }
130 
131  static string GetDamageDisplayName(EntityAI entity, string zone)
132  {
133  string component_name;
134  entity.GetEntityDamageDisplayNameMap().Find(zone.Hash(), component_name);
135  component_name = Widget.TranslateString(component_name);
136  return component_name;
137  }
138 
139  static void ResetAllZones(EntityAI entity)
140  {
141  DamageZoneMap zonesMap = new DamageZoneMap();
142  DamageSystem.GetDamageZoneMap(entity, zonesMap);
143  array<string> zones = zonesMap.GetKeyArray();
144  entity.SetHealth("", "Health", entity.GetMaxHealth("","Health"));
145  entity.SetHealth("", "Shock", entity.GetMaxHealth("","Shock"));
146  entity.SetHealth("", "Blood", entity.GetMaxHealth("","Blood"));
147 
148  foreach (string zone : zones)
149  {
150  entity.SetHealth(zone, "Health", entity.GetMaxHealth(zone,"Health"));
151  entity.SetHealth(zone, "Shock", entity.GetMaxHealth(zone,"Shock"));
152  entity.SetHealth(zone, "Blood", entity.GetMaxHealth(zone,"Blood"));
153  }
154  }
155 }
156 
157 typedef map<string,ref array<string>> DamageZoneMap; //<zone_name,<components>>
GetGame
proto native CGame GetGame()
EXPLOSION
EXPLOSION
Definition: damagesystem.c:4
STUN
STUN
Definition: damagesystem.c:5
FIRE_ARM
FIRE_ARM
Definition: damagesystem.c:3
DamageZoneMap
map< string, ref array< string > > DamageZoneMap
Definition: damagesystem.c:157
CloseCombatDamage
enum DamageType CloseCombatDamage(EntityAI source, Object targetObject, int targetComponentIndex, string ammoTypeName, vector worldPos, int directDamageFlags=ProcessDirectDamageFlags.ALL_TRANSFER)
Managed
TODO doc.
Definition: enscript.c:117
CLOSE_COMBAT
CLOSE_COMBAT
Definition: damagesystem.c:2
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
CFG_VEHICLESPATH
const string CFG_VEHICLESPATH
Definition: constants.c:209
TotalDamageResult
Definition: damagesystem.c:1
DamageType
DamageType
exposed from C++ (do not change)
Definition: damagesystem.c:10
Object
Definition: objecttyped.c:1
CFG_MAGAZINESPATH
const string CFG_MAGAZINESPATH
Definition: constants.c:211
CFG_WEAPONSPATH
const string CFG_WEAPONSPATH
Definition: constants.c:210
array< string >
Widget
Definition: enwidgets.c:189
ProcessDirectDamageFlags
ProcessDirectDamageFlags
Definition: object.c:1
CUSTOM
CUSTOM
Definition: damagesystem.c:7
EntityAI
Definition: building.c:5
path
string path
Definition: optionselectormultistate.c:135