DayZ 1.24
Loading...
Searching...
No Matches
DayZPlayerImplementFallDamage.c
Go to the documentation of this file.
17
19{
20 static const string FALL_DAMAGE_AMMO_HEALTH = "FallDamageHealth";
21 static const string FALL_DAMAGE_AMMO_SHOCK = "FallDamageShock";
22
23 static const string FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT = "FallDamageHealthAttachment";
24 static const string FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS = "FallDamageHealthOtherAttachments";
25
26 const float HEALTH_HEIGHT_LOW = 5;
27 const float HEALTH_HEIGHT_HIGH = 14;
28
29 private const float SHOCK_HEIGHT_LOW = 3;
30 private const float SHOCK_HEIGHT_HIGH = 12;
31 private const float BROKENLEGS_HEIGHT_LOW = 5;
32 private const float BROKENLEGS_HEIGHT_HIGH = 9;
33
34 private const float GLOVES_HEALTH_HEIGHT_LOW = 5;
35 private const float GLOVES_HEALTH_HEIGHT_HIGH = 15;
36 private const float SHOES_HEALTH_HEIGHT_LOW = 2;
37 private const float SHOES_HEALTH_HEIGHT_HIGH = 15;
38 private const float PANTS_HEALTH_HEIGHT_LOW = 5;
39 private const float PANTS_HEALTH_HEIGHT_HIGH = 16;
40
41 private const float BLEEDINGHANDS_HEIGHT_LOW = 5;
42 private const float BLEEDINGFEET_HEIGHT_LOW = 3;
43 private const float BLEEDINGLEGS_HEIGHT_LOW = 10;
44
45 private const float RANDOM_THRESHOLD_HEALTH_LOW = 0.05;
46 private const float RANDOM_THRESHOLD_HEALTH_HIGH = 0.1;
47 private const float RANDOM_THRESHOLD_LEGS_LOW = 0.05;
48 private const float RANDOM_THRESHOLD_LEGS_HIGH = 0.1;
49 private const float RANDOM_THRESHOLD_ATTACHMENTS_LOW = 0;
50 private const float RANDOM_THRESHOLD_ATTACHMENTS_HIGH = 0.2;
51
52 private const float BLEEDING_CHANCE_HEIGHT_LOW = 3;
53 private const float BLEEDING_CHANCE_HEIGHT_HIGH = 15;
54
55 private static const float BROKENLEGS_HEALTH_DAMAGE_MAX = 125;
56
57 private static const string BLEEDING_HANDS_SELECTIONS[2] = {"LeftForeArmRoll", "RightForeArmRoll"};
58 private static const string BLEEDING_FEET_SELECTIONS[2] = {"LeftFoot", "RightFoot"};
59 private static const string BLEEDING_LEGS_SELECTIONS[2] = {"LeftLeg", "RightLeg"};
60
61 private const int DAMAGE_TYPE_GLOBAL = 0;
62 private const int DAMAGE_TYPE_LEGS = 1;
63 private const int DAMAGE_TYPE_ATTACHMENTS = 2;
64
67
68#ifdef DIAG_DEVELOPER
69 bool m_Debug = false;
71#endif
72
74 {
77
78#ifdef DIAG_DEVELOPER
80#endif
81 }
82
83 float GetHeight()
84 {
85 return m_FallDamageData.m_Height;
86 }
87
89 {
90 return m_FallDamageData.m_LandType;
91 }
92
94 {
96
99 m_FallDamageData.m_HealthCoef = Math.Clamp(m_FallDamageData.m_HealthCoef, 0, 1);
100
102 m_FallDamageData.m_ShockCoef = Math.Clamp(m_FallDamageData.m_ShockCoef, 0, 1);
103
105 m_FallDamageData.m_BrokenLegsCoef = Randomize(DAMAGE_TYPE_LEGS, m_FallDamageData.m_BrokenLegsCoef);
106 m_FallDamageData.m_BrokenLegsCoef = Math.Clamp(m_FallDamageData.m_BrokenLegsCoef, 0, 1);
107
108 m_FallDamageData.m_BleedingHandsCoef = Math.InverseLerp(0, BLEEDINGHANDS_HEIGHT_LOW, pData.m_Height);
109 m_FallDamageData.m_BleedingHandsCoef = Math.Clamp(m_FallDamageData.m_BleedingHandsCoef, 0, 1);
110
111 m_FallDamageData.m_BleedingFeetCoef = Math.InverseLerp(0, BLEEDINGFEET_HEIGHT_LOW, pData.m_Height);
112 m_FallDamageData.m_BleedingFeetCoef = Math.Clamp(m_FallDamageData.m_BleedingFeetCoef, 0, 1);
113
114 m_FallDamageData.m_BleedingLegsCoef = Math.InverseLerp(0, BLEEDINGLEGS_HEIGHT_LOW, pData.m_Height);
115 m_FallDamageData.m_BleedingLegsCoef = Math.Clamp(m_FallDamageData.m_BleedingLegsCoef, 0, 1);
116
118 m_FallDamageData.m_GlovesHealthCoef = Randomize(DAMAGE_TYPE_ATTACHMENTS, m_FallDamageData.m_GlovesHealthCoef);
119 m_FallDamageData.m_GlovesHealthCoef = Math.Clamp(m_FallDamageData.m_GlovesHealthCoef, 0, 1);
120
122 m_FallDamageData.m_ShoesHealthCoef = Randomize(DAMAGE_TYPE_ATTACHMENTS, m_FallDamageData.m_ShoesHealthCoef);
123 m_FallDamageData.m_ShoesHealthCoef = Math.Clamp(m_FallDamageData.m_ShoesHealthCoef, 0, 1);
124
126 m_FallDamageData.m_PantsHealthCoef = Randomize(DAMAGE_TYPE_ATTACHMENTS, m_FallDamageData.m_PantsHealthCoef);
127 m_FallDamageData.m_PantsHealthCoef = Math.Clamp(m_FallDamageData.m_PantsHealthCoef, 0, 1);
128
130 m_FallDamageData.m_BleedingChanceCoef = Math.Clamp(m_FallDamageData.m_BleedingChanceCoef, 0, 0.7);
131
132 m_FallDamageData.m_BleedingChanceLegsCoef = 0.15;
133
134 if (GetGame().IsServer())
135 {
137 if (playerBase)
138 {
141 playerBase.DamageAllLegs(BROKENLEGS_HEALTH_DAMAGE_MAX * m_FallDamageData.m_BrokenLegsCoef);
142 }
143
144 vector posMS = m_Player.WorldToModel(m_Player.GetPosition());
145
146 m_Player.ProcessDirectDamage(DamageType.CUSTOM, m_Player, "", FALL_DAMAGE_AMMO_HEALTH, posMS, m_FallDamageData.m_HealthCoef);
147 m_Player.ProcessDirectDamage(DamageType.CUSTOM, m_Player, "", FALL_DAMAGE_AMMO_SHOCK, posMS, m_FallDamageData.m_ShockCoef);
148
149 if (playerBase)
150 playerBase.ForceUpdateInjuredState();
151 }
152 }
153
178
180 {
182
184 BleedingSourcesManagerServer bleedingManager = pPlayer.GetBleedingManagerServer();
185 if (Math.RandomFloatInclusive(0.0, 1.0) <= m_FallDamageData.m_BleedingChanceCoef && m_FallDamageData.m_BleedingHandsCoef == 1.0 && pPlayer.FindAttachmentBySlotName("Gloves") == null)
186 {
188 bleedingManager.AttemptAddBleedingSourceBySelection(BLEEDING_HANDS_SELECTIONS[bleedingSelectionIndex]);
189 }
190
191 if (Math.RandomFloatInclusive(0.0, 1.0) <= m_FallDamageData.m_BleedingChanceCoef && m_FallDamageData.m_BleedingFeetCoef == 1.0 && pPlayer.FindAttachmentBySlotName("Feet") == null)
192 {
193
195 bleedingManager.AttemptAddBleedingSourceBySelection(BLEEDING_FEET_SELECTIONS[bleedingSelectionIndex]);
196 }
197 if (Math.RandomFloatInclusive(0.0, 1.0) <= m_FallDamageData.m_BleedingChanceLegsCoef && m_FallDamageData.m_BleedingLegsCoef == 1.0)
198 {
199
201 bleedingManager.AttemptAddBleedingSourceBySelection(BLEEDING_LEGS_SELECTIONS[bleedingSelectionIndex]);
202 }
203 }
204
206 {
207 EntityAI gloves = pPlayer.FindAttachmentBySlotName("Gloves");
208 if (gloves)
209 gloves.ProcessDirectDamage(DT_CUSTOM, pPlayer, "", FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS, gloves.WorldToModel(gloves.GetPosition()), m_FallDamageData.m_GlovesHealthCoef);
210
211 EntityAI shoes = pPlayer.FindAttachmentBySlotName("Feet");
212 if (shoes)
213 shoes.ProcessDirectDamage(DT_CUSTOM, pPlayer, "", FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS, shoes.WorldToModel(shoes.GetPosition()), m_FallDamageData.m_ShoesHealthCoef);
214
215 EntityAI pants = pPlayer.FindAttachmentBySlotName("Legs");
216 if (pants)
217 pants.ProcessDirectDamage(DT_CUSTOM, pPlayer, "", FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT, pants.WorldToModel(pants.GetPosition()), m_FallDamageData.m_PantsHealthCoef);
218 }
219
220#ifdef DIAG_DEVELOPER
222 {
224 data.Synch(this);
225
226 return data;
227 }
228
230 {
233 }
234
235 private static string LandTypeToString(int landType)
236 {
237 switch (landType)
238 {
239 case 1:
240 return "LIGHT";
241 case 2:
242 return "MEDIUM";
243 case 3:
244return "HEAVY":
245 }
246
247 return "NONE";
248 }
249
250 private void PreloadAmmoTypeData()
251 {
252 if (m_AmmoTypeData == null)
254
259 }
260
262 {
264 values[0] = GetGame().ConfigGetFloat(string.Format("CfgAmmo %1 DamageApplied Health damage", pAmmoType));
265 values[1] = GetGame().ConfigGetFloat(string.Format("CfgAmmo %1 DamageApplied Blood damage", pAmmoType));
266 values[2] = GetGame().ConfigGetFloat(string.Format("CfgAmmo %1 DamageApplied Shock damage", pAmmoType));
267
268 return values;
269 }
270
272 {
273 int windowPosX = 10;
274 int windowPosY = 200;
275
276 DbgUI.Begin("Fall Damage (last)", windowPosX, windowPosY);
277 if (enabled)
278 {
279 DbgUI.Text(string.Format("Height:\t%1", Math.Clamp(data.m_Height, 0, float.MAX)));
280 DbgUI.Text(string.Format("Land Type:\t%1 (%2)", data.m_LandType, LandTypeToString(data.m_LandType)));
281 DbgUI.Text("");
282 DbgUI.Text("Health");
283 DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_HealthCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_HEALTH] * data.m_HealthCoef));
284 DbgUI.Text("Shock");
285 DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_ShockCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_SHOCK] * data.m_ShockCoef));
286 DbgUI.Text("Broken Legs:");
287 DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_BrokenLegsCoef, BROKENLEGS_HEALTH_DAMAGE_MAX * data.m_BrokenLegsCoef));
288 DbgUI.Text("Gloves damage:");
289 DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_GlovesHealthCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS] * data.m_GlovesHealthCoef));
290 DbgUI.Text("Shoes damage:");
291 DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_ShoesHealthCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS] * data.m_ShoesHealthCoef));
292 DbgUI.Text("Pants damage:");
293 DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_PantsHealthCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT] * data.m_PantsHealthCoef));
294 DbgUI.Text("Bleeding coefs:");
295 DbgUI.Text(string.Format(" hands:%1", data.m_BleedingHandsCoef));
296 DbgUI.Text(string.Format(" feet:%1", data.m_BleedingFeetCoef));
297 DbgUI.Text(string.Format(" legs:%1", data.m_BleedingLegsCoef));
298 DbgUI.Text(string.Format(" H&F chance:%1", data.m_BleedingChanceCoef));
299
300
301 }
302 DbgUI.End();
303 }
304
306 {
307 data.m_Height = m_FallDamageData.m_Height;
308 data.m_LandType = m_FallDamageData.m_LandType;
309 data.m_HealthCoef = m_FallDamageData.m_HealthCoef;
310 data.m_ShockCoef = m_FallDamageData.m_ShockCoef;
311 data.m_BrokenLegsCoef = m_FallDamageData.m_BrokenLegsCoef;
312 data.m_GlovesHealthCoef = m_FallDamageData.m_GlovesHealthCoef;
313 data.m_ShoesHealthCoef = m_FallDamageData.m_ShoesHealthCoef;
314 data.m_PantsHealthCoef = m_FallDamageData.m_PantsHealthCoef;
315
316 data.m_BleedingHandsCoef = m_FallDamageData.m_BleedingHandsCoef;
317 data.m_BleedingFeetCoef = m_FallDamageData.m_BleedingFeetCoef;
318 data.m_BleedingLegsCoef = m_FallDamageData.m_BleedingLegsCoef;
319 data.m_BleedingChanceCoef = m_FallDamageData.m_BleedingChanceCoef;
320 }
321#endif
322
326 const string FD_AMMO = "FallDamage";
327 const float FD_DMG_FROM_HEIGHT = 2.5;
328 const float FD_MAX_DMG_AT_HEIGHT = 15;
329 const float FD_MAX_HEIGHT_LEG_BREAK = 8;
330
332 float DamageCoef(float pHeight);
333}
334
335#ifdef DIAG_DEVELOPER
337{
338 int m_LandType;
339 float m_Height;
340 float m_HealthCoef;
341 float m_ShockCoef;
342 float m_BrokenLegsCoef;
343 float m_GlovesHealthCoef;
344 float m_ShoesHealthCoef;
345 float m_PantsHealthCoef;
346 float m_BleedingHandsCoef;
347 float m_BleedingFeetCoef;
348 float m_BleedingLegsCoef;
349 float m_BleedingChanceCoef;
350
352 {
353 m_Height = fallDamage.GetHeight();
354 m_LandType = fallDamage.GetLandType();
355
356 fallDamage.FillDebugFallDamageData(this);
357 }
358
359 override bool Serialize(Serializer ctx)
360 {
361 return ctx.Write(m_Height) && ctx.Write(m_LandType) && ctx.Write(m_HealthCoef) && ctx.Write(m_ShockCoef) && ctx.Write(m_BrokenLegsCoef) && ctx.Write(m_GlovesHealthCoef) && ctx.Write(m_ShoesHealthCoef) && ctx.Write(m_PantsHealthCoef) && ctx.Write(m_BleedingHandsCoef) && ctx.Write(m_BleedingFeetCoef) && ctx.Write(m_BleedingLegsCoef);
362 }
363
364 override bool Deserializer(Serializer ctx)
365 {
366 return ctx.Read(m_Height) && ctx.Read(m_LandType) && ctx.Read(m_HealthCoef) && ctx.Read(m_ShockCoef) && ctx.Write(m_BrokenLegsCoef) && ctx.Read(m_GlovesHealthCoef) && ctx.Read(m_ShoesHealthCoef) && ctx.Read(m_PantsHealthCoef) && ctx.Read(m_BleedingHandsCoef) && ctx.Read(m_BleedingFeetCoef) && ctx.Read(m_BleedingLegsCoef);
367 }
368}
369#endif
void Serialize()
Definition Inventory.c:193
DamageType
exposed from C++ (do not change)
class FallDamageData FALL_DAMAGE_AMMO_HEALTH
void DamageAttachedGear(notnull PlayerBase pPlayer)
const float RANDOM_THRESHOLD_HEALTH_LOW
const float FD_DMG_FROM_HEIGHT
damage will not be taken into account bellow this HeightToDamage
const float BLEEDINGFEET_HEIGHT_LOW
const float BLEEDING_CHANCE_HEIGHT_LOW
const float BLEEDINGLEGS_HEIGHT_LOW
const float SHOES_HEALTH_HEIGHT_HIGH
ref FallDamageData m_FallDamageData
static const string FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS
const float HEALTH_HEIGHT_LOW
void DayZPlayerImplementFallDamage(DayZPlayer pPlayer)
const float PANTS_HEALTH_HEIGHT_HIGH
const float RANDOM_THRESHOLD_LEGS_LOW
const float GLOVES_HEALTH_HEIGHT_LOW
const float FD_MAX_HEIGHT_LEG_BREAK
height where legs break most of the time
const float FD_MAX_DMG_AT_HEIGHT
height where player gets 100% damage
static const string BLEEDING_FEET_SELECTIONS[2]
static const string FALL_DAMAGE_AMMO_SHOCK
static const string FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT
const float BROKENLEGS_HEIGHT_LOW
const float SHOCK_HEIGHT_HIGH
static const string BLEEDING_HANDS_SELECTIONS[2]
const float BLEEDINGHANDS_HEIGHT_LOW
const float RANDOM_THRESHOLD_HEALTH_HIGH
void AttachBleedingToZonesByHeight(notnull PlayerBase pPlayer)
const int DAMAGE_TYPE_LEGS
float DamageCoef(float pHeight)
void HandleFallDamage(FallDamageData pData)
const float GLOVES_HEALTH_HEIGHT_HIGH
const string FD_AMMO
ammo type used for damaging
const int DAMAGE_TYPE_GLOBAL
const float SHOES_HEALTH_HEIGHT_LOW
const float PANTS_HEALTH_HEIGHT_LOW
static const float BROKENLEGS_HEALTH_DAMAGE_MAX
const float RANDOM_THRESHOLD_LEGS_HIGH
const int DAMAGE_TYPE_ATTACHMENTS
static const string BLEEDING_LEGS_SELECTIONS[2]
const float SHOCK_HEIGHT_LOW
const float BROKENLEGS_HEIGHT_HIGH
float Randomize(int pType, float pValue)
const float RANDOM_THRESHOLD_ATTACHMENTS_LOW
const float BLEEDING_CHANCE_HEIGHT_HIGH
const float RANDOM_THRESHOLD_ATTACHMENTS_HIGH
const float HEALTH_HEIGHT_HIGH
DayZPlayer m_Player
Definition Hand_Events.c:42
static int m_Height
float GetTime()
class PresenceNotifierNoiseEvents windowPosX
dbgUI settings
const int windowPosY
void Synch(EntityAI victim)
keeping "step" here for consistency only
Definition TrapBase.c:280
Definition DbgUI.c:60
Definition EnMath.c:7
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
static const vector Zero
Definition EnConvert.c:110
proto native CGame GetGame()
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
static proto int Randomize(int seed)
Sets the seed for the random number generator.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:106
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54