Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
bleedchancedata.c
Go to the documentation of this file.
1 typedef map<int,float> BleedChanceMaxMap; //<bloodDamageReceived,chanceMax>
2 
5 {
6  private static const float BLOOD_HITPOINTS_UNIVERSAL = 100.0;
7 
8  private static ref map<string, ref BleedChanceMaxMap> m_DamageTypeMap;
9 
10  static void InitBleedChanceData()
11  {
12  m_DamageTypeMap = new map<string,ref BleedChanceMaxMap>();
13 
14  InitMeleeChanceMap();
15  InitInfectedChanceMap();
16  }
17 
18  static void InitMeleeChanceMap()
19  {
20  if (m_DamageTypeMap.Contains("Melee"))
21  ErrorEx("'Melee' damage type bleed chances already initialized!");
22 
23  BleedChanceMaxMap bleedChanceMaxMap = new BleedChanceMaxMap();
24 
25  //keys have to be integers, recalculated later
26  bleedChanceMaxMap.Set(0,0.0);
27  bleedChanceMaxMap.Set(10,5.0);
28  bleedChanceMaxMap.Set(20,15.0);
29  bleedChanceMaxMap.Set(30,23.4);
30  bleedChanceMaxMap.Set(40,31.2);
31  bleedChanceMaxMap.Set(50,39.0);
32  bleedChanceMaxMap.Set(60,46.8);
33  bleedChanceMaxMap.Set(70,54.6);
34  bleedChanceMaxMap.Set(80,62.4);
35  bleedChanceMaxMap.Set(90,70.2);
36  bleedChanceMaxMap.Set(BLOOD_HITPOINTS_UNIVERSAL,100.0);
37 
38  m_DamageTypeMap.Set("Melee",bleedChanceMaxMap);
39  }
40 
41  static void InitInfectedChanceMap()
42  {
43  if (m_DamageTypeMap.Contains("Infected"))
44  ErrorEx("'Infected' damage type bleed chances already initialized!");
45 
46  BleedChanceMaxMap bleedChanceMaxMap = new BleedChanceMaxMap();
47 
48  //keys have to be integers, recalculated later
49  bleedChanceMaxMap.Set(0,0.0);
50  bleedChanceMaxMap.Set(10,5.0);
51  bleedChanceMaxMap.Set(20,15.0);
52  bleedChanceMaxMap.Set(30,27.5);
53  bleedChanceMaxMap.Set(40,40.0);
54  bleedChanceMaxMap.Set(50,55.0);
55  bleedChanceMaxMap.Set(60,60.0);
56  bleedChanceMaxMap.Set(70,70.0);
57  bleedChanceMaxMap.Set(80,75.0);
58  bleedChanceMaxMap.Set(90,85.0);
59  bleedChanceMaxMap.Set(BLOOD_HITPOINTS_UNIVERSAL,100.0);
60 
61  m_DamageTypeMap.Set("Infected",bleedChanceMaxMap);
62  }
63 
64  static void Cleanup()
65  {
66  delete m_DamageTypeMap;
67  }
68 
70  static bool CalculateBleedChance(string damageType, float bloodDamage, float bleedThreshold, out float bleedChance)
71  {
72  map<int,float> bleedChanceMap = m_DamageTypeMap.Get(damageType);
73  if (!bleedChanceMap)
74  return false;
75 
76  float armor = bloodDamage / BLOOD_HITPOINTS_UNIVERSAL;
77  float valueHigher = Math.Max(bleedThreshold,armor) * BLOOD_HITPOINTS_UNIVERSAL;
78  float valueLower = Math.Min(bleedThreshold,armor) * BLOOD_HITPOINTS_UNIVERSAL;
79 
80  #ifdef DEVELOPER
81  if (LogManager.IsBleedingChancesLogEnable())
82  {
83  Debug.BleedingChancesLog(armor.ToString(), "BleedChanceData" , "n/a", "armor:");
84  Debug.BleedingChancesLog(bleedThreshold.ToString(), "BleedChanceData" , "n/a", "bleedThreshold:");
85  }
86  #endif
87 
88  //unexpected values, unhandled
89  if (valueLower > BLOOD_HITPOINTS_UNIVERSAL)
90  {
91  bleedChance = 1.0;
92 
93  #ifdef DEVELOPER
94  if (LogManager.IsBleedingChancesLogEnable())
95  {
96  Debug.BleedingChancesLog(bleedChance.ToString(), "BleedChanceData" , "n/a", "Unhandleed values, default bleeding chance used:");
97  }
98  #endif
99 
100  return true;
101  }
102 
103  if (bleedChanceMap.Contains(valueLower))
104  {
105  bleedChance = bleedChanceMap.Get(valueLower) * valueHigher / 10000;
106  }
107  else
108  {
109  float chanceMaxActual;
110 
111  float floor = Math.Floor(valueLower / 10) * 10;
112  float ceil = Math.Ceil(valueLower / 10) * 10;
113  float pos = Math.InverseLerp(floor,ceil,valueLower);
114 
115  float chanceMin = bleedChanceMap.Get(floor);
116  float chanceMax = bleedChanceMap.Get(ceil);
117 
118  chanceMaxActual = Math.Lerp(chanceMin,chanceMax,pos);
119  bleedChance = valueHigher * chanceMaxActual / 10000;
120  }
121 
122  #ifdef DEVELOPER
123  if (LogManager.IsBleedingChancesLogEnable())
124  {
125  Debug.BleedingChancesLog(bleedChance.ToString(), "BleedChanceData" , "n/a", "bleeding chance:");
126  }
127  #endif
128 
129  return true;
130  }
131 }
BleedChanceMaxMap
map< int, float > BleedChanceMaxMap
Definition: bleedchancedata.c:1
LogManager
Definition: debug.c:734
Managed
TODO doc.
Definition: enscript.c:117
ErrorEx
enum ShapeType ErrorEx
map
map
Definition: controlsxboxnew.c:3
BleedChanceData
Static data of bleeding chance probabilities; currently used for melee only.
Definition: bleedchancedata.c:4
Debug
Definition: debug.c:13
Math
Definition: enmath.c:6