Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
bleedchancedata.c
Go to the documentation of this file.
1
typedef
map<int,float>
BleedChanceMaxMap
;
//<bloodDamageReceived,chanceMax>
2
4
class
BleedChanceData
:
Managed
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 ENABLE_LOGGING
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 ENABLE_LOGGING
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 ENABLE_LOGGING
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
BleedChanceData
Static data of bleeding chance probabilities; currently used for melee only.
Definition
bleedchancedata.c:5
BleedChanceData::Cleanup
static void Cleanup()
Definition
bleedchancedata.c:64
BleedChanceData::BLOOD_HITPOINTS_UNIVERSAL
static const float BLOOD_HITPOINTS_UNIVERSAL
Definition
bleedchancedata.c:6
BleedChanceData::CalculateBleedChance
static bool CalculateBleedChance(string damageType, float bloodDamage, float bleedThreshold, out float bleedChance)
returns 'false' when damageType is unhandled
Definition
bleedchancedata.c:70
BleedChanceData::InitBleedChanceData
static void InitBleedChanceData()
Definition
bleedchancedata.c:10
BleedChanceData::InitInfectedChanceMap
static void InitInfectedChanceMap()
Definition
bleedchancedata.c:41
BleedChanceData::m_DamageTypeMap
static ref map< string, ref BleedChanceMaxMap > m_DamageTypeMap
Definition
bleedchancedata.c:8
BleedChanceData::InitMeleeChanceMap
static void InitMeleeChanceMap()
Definition
bleedchancedata.c:18
Debug
Definition
debug.c:2
Debug::BleedingChancesLog
static void BleedingChancesLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Definition
debug.c:222
LogManager
Definition
debug.c:692
LogManager::IsBleedingChancesLogEnable
static bool IsBleedingChancesLogEnable()
Definition
debug.c:831
Managed
TODO doc.
Definition
enscript.c:118
Math
Definition
enmath.c:7
float::ToString
proto string ToString(bool simple=true)
map
Definition
cachedequipmentstorage.c:4
map
map
Definition
controlsxboxnew.c:4
ErrorEx
enum ShapeType ErrorEx
Math::Max
static proto float Max(float x, float y)
Returns bigger of two given values.
Math::InverseLerp
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
Math::Min
static proto float Min(float x, float y)
Returns smaller of two given values.
Math::Lerp
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
Math::Ceil
static proto float Ceil(float f)
Returns ceil of value.
Math::Floor
static proto float Floor(float f)
Returns floor of value.
Games
Dayz
scripts
3_game
bleedchancedata.c
Generated by
1.17.0