DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
BleedChanceData.c
См. документацию.
1typedef map<int,float> BleedChanceMaxMap; //<bloodDamageReceived,chanceMax>
2
5{
6 private static const float BLOOD_HITPOINTS_UNIVERSAL = 100.0;
7
9
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
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 ENABLE_LOGGING
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 ENABLE_LOGGING
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 ENABLE_LOGGING
124 {
125 Debug.BleedingChancesLog(bleedChance.ToString(), "BleedChanceData" , "n/a", "bleeding chance:");
126 }
127 #endif
128
129 return true;
130 }
131}
map< int, float > BleedChanceMaxMap
Определения BleedChanceData.c:1
map
Определения ControlsXboxNew.c:4
static void InitMeleeChanceMap()
Определения BleedChanceData.c:18
static bool CalculateBleedChance(string damageType, float bloodDamage, float bleedThreshold, out float bleedChance)
returns 'false' when damageType is unhandled
Определения BleedChanceData.c:70
static void InitInfectedChanceMap()
Определения BleedChanceData.c:41
static void Cleanup()
Определения BleedChanceData.c:64
static void InitBleedChanceData()
Определения BleedChanceData.c:10
static ref map< string, ref BleedChanceMaxMap > m_DamageTypeMap
Определения BleedChanceData.c:8
static const float BLOOD_HITPOINTS_UNIVERSAL
Определения BleedChanceData.c:6
Static data of bleeding chance probabilities; currently used for melee only.
Определения BleedChanceData.c:5
static void BleedingChancesLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Определения Debug.c:162
Определения Debug.c:2
static bool IsBleedingChancesLogEnable()
Определения Debug.c:733
Определения Debug.c:594
TODO doc.
Определения EnScript.c:118
Определения EnMath.c:7
proto string ToString(bool simple=true)
enum ShapeType ErrorEx
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto float Floor(float f)
Returns floor of value.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float Min(float x, float y)
Returns smaller of two given values.
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 float Ceil(float f)
Returns ceil of value.