DayZ 1.24
Loading...
Searching...
No Matches
BleedingSourcesManagerServer.c
Go to the documentation of this file.
2{
3 const float TICK_INTERVAL_SEC = 3;
4 float m_Tick;
5 bool m_DisableBloodLoss = false;
6 ref array<int> m_DeleteList = new array<int>;
7
8 const int STORAGE_VERSION = 103;
9
11 {
12 return m_BleedingSourceZone.Get(GetSelectionNameFromBit(bit));
13 }
14
16 {
17 return STORAGE_VERSION;
18 }
19
21 {
22 m_DeleteList.Insert(bit);
23 }
24
25 override protected void AddBleedingSource(int bit)
26 {
27#ifdef DEVELOPER
28 if (m_Player && !m_Player.GetAllowDamage())//full invincibility prevents bleeding source creation
29 return;
30#endif
31
32 m_Player.SetBleedingBits(m_Player.GetBleedingBits() | bit);
33 super.AddBleedingSource(bit);
34 m_Player.OnBleedingSourceAdded();
35 }
36
37 override protected bool RemoveBleedingSource(int bit)
38 {
39 if (!super.RemoveBleedingSource(bit))
40 Error("Failed to remove bleeding source:" + bit);
41 else
42 m_Player.OnBleedingSourceRemovedEx(m_Item);
43
45 m_Player.SetBleedingBits(m_Player.GetBleedingBits() & inverse_bit_mask);
46
47
48 //infection moved here to allow proper working in singleplayer
49 float chanceToInfect;
50
51 if (m_Item)
53 else
55 float diceRoll = Math.RandomFloat01();
57 m_Player.InsertAgent(eAgents.WOUND_AGENT);
58
59 m_Item = null;//reset, so that next call, if induced by self-healing, will have no item
60
61 return true;
62 }
63
65 {
66 int bleeding_sources_bits = m_Player.GetBleedingBits();
68
69 RemoveBleedingSource(rightmost_bit);
70 }
71
73 {
74 int bit = GetMostSignificantBleedingSource();
75 if (bit != 0)
76 RemoveBleedingSource(bit);
77 }
78
80 {
82 RemoveMostSignificantBleedingSource();
83 }
84
86 {
87 int bleeding_sources_bits = m_Player.GetBleedingBits();
88
89 float highest_flow;
91 int bit_offset;
92
93 for (int i = 0; i < BIT_INT_SIZE; i++)
94 {
95 int bit = 1 << bit_offset;
96
97 if ((bit & bleeding_sources_bits) != 0)
98 {
99 BleedingSourceZone meta = GetBleedingSourceMeta(bit);
100 if (meta)
101 {
102 if (meta.GetFlowModifier() > highest_flow)
103 {
104 highest_flow = meta.GetFlowModifier();
106 //Print(meta.GetSelectionName());
107 }
108 }
109 }
110 bit_offset++;
111 }
112 return highest_flow_bit;
113 }
114
115 void OnTick(float delta_time)
116 {
118 if (m_Tick > TICK_INTERVAL_SEC)
119 {
120 while (m_DeleteList.Count() > 0)
121 {
122 RemoveBleedingSource(m_DeleteList.Get(0));
123 m_DeleteList.Remove(0);
124 }
125
128
129 for (int i = 0; i < m_BleedingSources.Count(); i++)
130 m_BleedingSources.GetElement(i).OnUpdateServer(m_Tick, blood_scale, m_DisableBloodLoss);
131 m_Tick = 0;
132 }
133 }
134
136 {
137 for (int i = 0; i < m_BleedingSourceZone.Count(); i++)
138 {
139 int bit = m_BleedingSourceZone.GetElement(i).GetBit();
140 if (CanAddBleedingSource(bit))
141 AddBleedingSource(bit);
142 }
143 }
144
145 //damage must be to "Blood" healthType
146 void ProcessHit(float damage, EntityAI source, int component, string zone, string ammo, vector modelPos)
147 {
148 float dmg_max = m_Player.GetMaxHealth(zone, "Blood");
149 float bleed_threshold = GetGame().ConfigGetFloat("CfgAmmo " + ammo + " DamageApplied bleedThreshold");
150 string damageTypeString = GetGame().ConfigGetTextOut("CfgAmmo " + ammo + " DamageApplied type");
152 float bleedingChance;
153 bool createBleedingSource = false;
154
155 // 'true' only when the damageTypeString is handled there
157 {
158 float roll = Math.RandomFloat01();
160
161#ifdef DEVELOPER
163 Debug.BleedingChancesLog(roll.ToString(), "BleedingSourcesManagerServer", "n/a", "bleeding random roll:");
164#endif
165 }
166 else if (source && source.IsZombie())
167 {
168 int chance = Math.RandomInt(0, 100);
169 if (chance <= damage)
171 }
172 else if (damage > (dmg_max * (1 - bleed_threshold)))
174
176 {
177#ifdef DEVELOPER
179 Debug.BleedingChancesLog("true", "BleedingSourcesManagerServer", "n/a", "Attempting to create bleeding source");
180#endif
181 AttemptAddBleedingSource(component);
182 }
183 }
184
186 {
187 RemoveAllSources();
188
189 if (source >= m_BleedingSourceZone.Count() || !m_BleedingSourceZone.GetElement(source)) return;
190
191 int bit = m_BleedingSourceZone.GetElement(source).GetBit();
192
193 if (bit && CanAddBleedingSource(bit))
194 AddBleedingSource(bit);
195 }
196
198 {
199 m_DisableBloodLoss = status;
200 }
201
203 {
204 //int count = m_BleedingSources.Count();
205 int active_bits = m_Player.GetBleedingBits();
206 ctx.Write(active_bits);
207
208 int bit_offset = 0;
209 for (int i = 0; i < BIT_INT_SIZE; i++)
210 {
211 int bit = 1 << bit_offset;
212 if ((bit & active_bits) != 0)
213 {
214 int active_time = GetBleedingSourceActiveTime(bit);
215 eBleedingSourceType type = GetBleedingSourceType(bit);
216
217 ctx.Write(active_time);
218 ctx.Write(type);
219 }
220 bit_offset++;
221 }
222 }
223
225 {
226 int active_bits;
227 if (!ctx.Read(active_bits))
228 return false;
229
230 int bit_offset = 0;
231 for (int i = 0; i < BIT_INT_SIZE; i++)
232 {
233 int bit = 1 << bit_offset;
234 if ((bit & active_bits) != 0 && CanAddBleedingSource(bit))
235 {
236 AddBleedingSource(bit);
237 int active_time = 0;
238 if (!ctx.Read(active_time))
239 return false;
240 else
241 SetBleedingSourceActiveTime(bit, active_time);
242 if (version >= 121) //type was added in this version
243 {
245 if (!ctx.Read(type))
246 return false;
247 else
248 SetBleedingSourceType(bit, type);
249 }
250 }
251 bit_offset++;
252 }
253 return true;
254 }
255
256
258 {
259 if (m_Player && !m_Player.IsAlive())
260 RemoveAllSources();
261 }
262}
eBleedingSourceType
ItemBase m_Item
Definition ActionInput.c:16
const int BIT_INT_SIZE
Definition BitArray.c:4
eAgents
Definition EAgents.c:3
DayZPlayer m_Player
Definition Hand_Events.c:42
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
const int STORAGE_VERSION
void SetItem(EntityAI item)
float m_Tick
Static data of bleeding chance probabilities; currently used for melee only.
static bool CalculateBleedChance(string damageType, float bloodDamage, float bleedThreshold, out float bleedChance)
returns 'false' when damageType is unhandled
void OnStoreSave(ParamsWriteContext ctx)
void ProcessHit(float damage, EntityAI source, int component, string zone, string ammo, vector modelPos)
bool OnStoreLoad(ParamsReadContext ctx, int version)
void RemoveMostSignificantBleedingSourceEx(ItemBase item)
BleedingSourceZone GetBleedingSourceZone(int bit)
static ref Param1< bool > PARAM1_BOOL
Definition Debug.c:14
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:213
override float GetInfectionChance(int system=0, Param param=null)
static bool IsBleedingChancesLogEnable()
Definition Debug.c:814
Definition EnMath.c:7
static const float BLEEDING_LOW_PRESSURE_MIN_MOD
static const float BLEEDING_LOW_PRESSURE_BLOOD
static const float BLEEDING_SOURCE_CLOSE_INFECTION_CHANCE
static const int BLOOD_THRESHOLD_FATAL
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:126
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].