Dayz  1.11.153731
Dayz Code Explorer by Zeroy
BleedingSourcesManagerServer.c
Go to the documentation of this file.
1 class BleedingSourcesManagerServer extends BleedingSourcesManagerBase
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 
20  void RequestDeletion(int bit)
21  {
22  m_DeleteList.Insert(bit);
23  }
24 
25  override protected void AddBleedingSource(int bit)
26  {
27  m_Player.SetBleedingBits(m_Player.GetBleedingBits() | bit );
28  super.AddBleedingSource(bit);
29  }
30 
31  override protected bool RemoveBleedingSource(int bit)
32  {
33  if(!super.RemoveBleedingSource(bit))
34  {
35  Error("Failed to remove bleeding source:" + bit);
36  }
37 
38  int inverse_bit_mask = ~bit;
39  m_Player.SetBleedingBits(m_Player.GetBleedingBits() & inverse_bit_mask );
40  return true;
41  }
42 
44  {
45  int bleeding_sources_bits = m_Player.GetBleedingBits();
46  int rightmost_bit = bleeding_sources_bits & (-bleeding_sources_bits);
47 
48  RemoveBleedingSource(rightmost_bit);
49  }
50 
52  {
55  }
56 
58  {
59  int bleeding_sources_bits = m_Player.GetBleedingBits();
60 
61  float highest_flow;
62  int highest_flow_bit;
63  int bit_offset;
64 
65  for(int i = 0; i < BIT_INT_SIZE; i++)
66  {
67  int bit = 1 << bit_offset;
68 
69  if( (bit & bleeding_sources_bits) != 0 )
70  {
72  if(meta)
73  {
74  if( meta.GetFlowModifier() > highest_flow )
75  {
76  highest_flow = meta.GetFlowModifier();
77  highest_flow_bit = bit;
78  //Print(meta.GetSelectionName());
79  }
80  }
81  }
82  bit_offset++;
83  }
84  return highest_flow_bit;
85  }
86 
87  void OnTick(float delta_time)
88  {
89  m_Tick += delta_time;
90  if( m_Tick > TICK_INTERVAL_SEC )
91  {
92  while( m_DeleteList.Count() > 0 )
93  {
94  RemoveBleedingSource(m_DeleteList.Get(0));
95  m_DeleteList.Remove(0);
96  }
97 
98  float blood_scale = Math.InverseLerp(PlayerConstants.BLOOD_THRESHOLD_FATAL, PlayerConstants.BLEEDING_LOW_PRESSURE_BLOOD, m_Player.GetHealth( "GlobalHealth", "Blood" ));
99  blood_scale = Math.Clamp( blood_scale, PlayerConstants.BLEEDING_LOW_PRESSURE_MIN_MOD, 1 );
100 
101  for(int i = 0; i < m_BleedingSources.Count(); i++)
102  {
103  m_BleedingSources.GetElement(i).OnUpdateServer( TICK_INTERVAL_SEC, blood_scale, m_DisableBloodLoss );
104  }
105  m_Tick = 0;
106  }
107  }
108 
110  {
111  for(int i = 0; i < m_BleedingSourceZone.Count(); i++)
112  {
113  int bit = m_BleedingSourceZone.GetElement(i).GetBit();
114  if( CanAddBleedingSource(bit) )
115  {
116  AddBleedingSource(bit);
117  }
118  }
119  }
120 
121  //damage must be to "Blood" healthType
122  void ProcessHit(float damage, EntityAI source, int component, string zone, string ammo, vector modelPos)
123  {
124  float dmg_max = m_Player.GetMaxHealth(zone, "Blood");
125  float dmg = damage;
126  float bleed_threshold = GetGame().ConfigGetFloat( "CfgAmmo " + ammo + " DamageApplied " + "bleedThreshold" );
127  bleed_threshold = Math.Clamp(bleed_threshold,0,1);
128  //Print("dmg_max = " + dmg_max);
129  //Print("dmg = " + dmg);
130  //Print("bleed_threshold = " + bleed_threshold);
131 
132  //hackerino for zombino:
133  if (source.IsZombie())
134  {
135  int chance = Math.RandomInt(0,10); //10%
136  if (chance == 1)
137  {
138  AttemptAddBleedingSource(component);
139  }
140  }
141  else if ( dmg > (dmg_max * (1 - bleed_threshold)) )
142  {
143  AttemptAddBleedingSource(component);
144  //Print("BLEEDING");
145  }
146 
147  }
148 
150  {
152 
153  if(source >= m_BleedingSourceZone.Count() || !m_BleedingSourceZone.GetElement(source)) return;
154 
155  int bit = m_BleedingSourceZone.GetElement(source).GetBit();
156 
157  if( bit && CanAddBleedingSource(bit) )
158  {
159  AddBleedingSource(bit);
160  }
161  }
162 
163  void SetBloodLoss(bool status)
164  {
165  m_DisableBloodLoss = status;
166  }
167 
169  {
170  //int count = m_BleedingSources.Count();
171  int active_bits = m_Player.GetBleedingBits();
172  ctx.Write(active_bits);
173 
174  int bit_offset = 0;
175  for(int i = 0; i < BIT_INT_SIZE; i++)
176  {
177  int bit = 1 << bit_offset;
178  if( (bit & active_bits) != 0 )
179  {
180  int active_time = GetBleedingSourceActiveTime(bit);
181  ctx.Write(active_time);
182  }
183  bit_offset++;
184  }
185  }
186 
188  {
189  int active_bits;
190  if(!ctx.Read(active_bits))
191  {
192  return false;
193  }
194 
195  int bit_offset = 0;
196  for(int i = 0; i < BIT_INT_SIZE; i++)
197  {
198  int bit = 1 << bit_offset;
199  if( (bit & active_bits) != 0 && CanAddBleedingSource(bit))
200  {
201  AddBleedingSource(bit);
202  int active_time = 0;
203  if(!ctx.Read(active_time))
204  {
205  return false;
206  }
207  else
208  {
209  SetBleedingSourceActiveTime(bit,active_time);
210  }
211 
212  }
213  bit_offset++;
214  }
215  return true;
216  }
217 
219  {
220  if (m_Player && !m_Player.IsAlive())
222  }
223 }
GetGame
proto native CGame GetGame()
BleedingSourcesManagerBase::GetBleedingSourceZone
protected BleedingSourceZone GetBleedingSourceZone(int bit)
Definition: BleedingSourcesManagerServer.c:10
Error
void Error(string err)
Messagebox with error message.
Definition: EnDebug.c:42
m_Player
Man m_Player
Definition: Hand_Events.c:42
Math::Clamp
static 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'.
Definition: EnMath.c:317
BleedingSourcesManagerBase::~BleedingSourcesManagerServer
void ~BleedingSourcesManagerServer()
Definition: BleedingSourcesManagerServer.c:218
BleedingSourcesManagerBase::m_Tick
float m_Tick
Definition: BleedingSourcesManagerServer.c:4
BleedingSourcesManagerBase::RemoveBleedingSource
override protected bool RemoveBleedingSource(int bit)
Definition: BleedingSourcesManagerServer.c:31
BleedingSourcesManagerBase::RemoveMostSignificantBleedingSource
void RemoveMostSignificantBleedingSource()
Definition: BleedingSourcesManagerServer.c:51
BleedingSourcesManagerBase::GetBleedingSourceMeta
protected BleedingSourceZone GetBleedingSourceMeta(int bit)
Definition: BleedingSourcesManagerBase.c:80
BleedingSourcesManagerBase::STORAGE_VERSION
const int STORAGE_VERSION
Definition: BleedingSourcesManagerServer.c:8
BleedingSourcesManagerBase
Definition: BleedingSourcesManagerBase.c:1
BleedingSourcesManagerBase::OnTick
void OnTick(float delta_time)
Definition: BleedingSourcesManagerServer.c:87
BleedingSourceZone
Definition: BleedingSourceZone.c:1
STORAGE_VERSION
const int STORAGE_VERSION
Definition: ModifiersManager.c:54
BleedingSourcesManagerBase::RemoveBleedingSource
protected bool RemoveBleedingSource(int bit)
Definition: BleedingSourcesManagerBase.c:208
BIT_INT_SIZE
const int BIT_INT_SIZE
Definition: BitArray.c:4
BleedingSourcesManagerBase::GetMostSignificantBleedingSource
int GetMostSignificantBleedingSource()
Definition: BleedingSourcesManagerServer.c:57
BleedingSourcesManagerBase::CanAddBleedingSource
protected bool CanAddBleedingSource(int bit)
Definition: BleedingSourcesManagerBase.c:171
BleedingSourcesManagerBase::DebugActivateBleedingSource
void DebugActivateBleedingSource(int source)
Definition: BleedingSourcesManagerServer.c:149
Serializer::Write
proto bool Write(void value_out)
Serializer
Serialization general interface.
Definition: Serializer.c:55
BleedingSourcesManagerBase::SetBloodLoss
void SetBloodLoss(bool status)
Definition: BleedingSourcesManagerServer.c:163
BleedingSourcesManagerBase::ProcessHit
void ProcessHit(float damage, EntityAI source, int component, string zone, string ammo, vector modelPos)
Definition: BleedingSourcesManagerServer.c:122
BleedingSourcesManagerBase::AddBleedingSource
override protected void AddBleedingSource(int bit)
Definition: BleedingSourcesManagerServer.c:25
vector
Definition: EnConvert.c:95
PlayerConstants
Definition: PlayerConstants.c:1
PlayerConstants::BLEEDING_LOW_PRESSURE_MIN_MOD
static const float BLEEDING_LOW_PRESSURE_MIN_MOD
Definition: PlayerConstants.c:152
BleedingSourcesManagerBase::AttemptAddBleedingSource
bool AttemptAddBleedingSource(int component)
Definition: BleedingSourcesManagerBase.c:135
BleedingSourcesManagerBase::ActivateAllBS
void ActivateAllBS()
Definition: BleedingSourcesManagerServer.c:109
BleedingSourcesManagerBase::OnStoreLoad
bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition: BleedingSourcesManagerServer.c:187
version
version
Definition: $PBOPREFIX$.txt:4
BleedingSourcesManagerBase::GetBleedingSourceActiveTime
int GetBleedingSourceActiveTime(int bit)
Definition: BleedingSourcesManagerBase.c:189
BleedingSourcesManagerBase::AddBleedingSource
protected void AddBleedingSource(int bit)
Definition: BleedingSourcesManagerBase.c:177
BleedingSourcesManagerBase::RequestDeletion
void RequestDeletion(int bit)
Definition: BleedingSourcesManagerServer.c:20
BleedingSourcesManagerBase::SetBleedingSourceActiveTime
void SetBleedingSourceActiveTime(int bit, int time)
Definition: BleedingSourcesManagerBase.c:199
BleedingSourcesManagerBase::GetSelectionNameFromBit
protected string GetSelectionNameFromBit(int bit)
Definition: BleedingSourcesManagerBase.c:130
Math::InverseLerp
static float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
Definition: EnMath.c:461
PlayerConstants::BLEEDING_LOW_PRESSURE_BLOOD
static const float BLEEDING_LOW_PRESSURE_BLOOD
Definition: PlayerConstants.c:151
BleedingSourcesManagerBase::OnStoreSave
void OnStoreSave(ParamsWriteContext ctx)
Definition: BleedingSourcesManagerServer.c:168
BleedingSourcesManagerBase::RemoveAllSources
void RemoveAllSources()
Definition: BleedingSourcesManagerBase.c:111
Serializer::Read
proto bool Read(void value_in)
PlayerConstants::BLOOD_THRESHOLD_FATAL
static const int BLOOD_THRESHOLD_FATAL
Definition: PlayerConstants.c:79
CGame::ConfigGetFloat
proto native float ConfigGetFloat(string path)
Get float value from config on path.
Math
Definition: EnMath.c:6
EntityAI
Base native class of all vehicles in game.
Definition: Building.c:4
BleedingSourcesManagerBase::RemoveAnyBleedingSource
void RemoveAnyBleedingSource()
Definition: BleedingSourcesManagerServer.c:43
BleedingSourceZone::GetFlowModifier
float GetFlowModifier()
Definition: BleedingSourceZone.c:49
Math::RandomInt
proto static native int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
BleedingSourcesManagerBase::GetStorageVersion
int GetStorageVersion()
Definition: BleedingSourcesManagerServer.c:15