Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
bleedingindicator.c
Go to the documentation of this file.
1 
3 class BleedingIndicator extends Managed
4 {
5  protected bool m_Initialized;
6  protected bool m_Terminating = false; //doesn't spawn more drops and ends when the last one does
7  protected bool m_EndNow = false;
8  protected bool m_IsRunning = false;
9  protected int m_DropSpawnsQueued;
10  protected int m_ActiveDropsCount;
11  protected int m_Severity;
12  protected int m_SourceID; //pairs this with the 'BleedingSource' bit/ID
13  protected GameplayEffectsDataBleeding m_ParentMetaData;
14  protected array<float> m_DropProbabilityArray;
15 
16  protected float m_AverageFrequency; //average drops per interval. NOT changeable on the fly, just a helper value!
17  protected float m_SequenceTick;
18  protected float m_SequenceDuration;
19  protected float m_TimeElapsedTotal;
20  protected float m_TimeElapsedSequence;
21  protected float m_LastDropSpawnTime; //relative to the TOTAL time, not the sequence!
22  protected float m_DropSpawnMinDelay;
23  protected float m_DropSpawnMaxDelay;
24  protected int m_CurrentDropProbabilityStep;
25  protected int m_DropProbabilityRollsCount;
26  protected vector m_BasePosition;
27 
28  ref set<ref BleedingIndicatorDropData> m_ActiveDrops;
29  ref set<int> m_CleanupQueue;
30 
31  void BleedingIndicator(int source_ID, int severity, GameplayEffectsDataBleeding parent)
32  {
33  m_Initialized = false;
34  m_SourceID = source_ID;
35  m_Severity = severity;
36  m_ParentMetaData = parent;
37  m_CurrentDropProbabilityStep = 0;
38  m_ActiveDrops = new set<ref BleedingIndicatorDropData>;
39  m_CleanupQueue = new set<int>;
40  m_DropProbabilityArray = m_ParentMetaData.GetProbabilities(m_Severity);
41  m_DropProbabilityRollsCount = m_DropProbabilityArray.Count();
42 
43  switch (m_Severity)
44  {
45  case BleedingIndicationConstants.INDICATOR_SEVERITY_LOW:
46  {
47  m_SequenceDuration = BleedingIndicationConstants.SEQUENCE_DURATION_LOW;
48  m_AverageFrequency = BleedingIndicationConstants.SEQUENCE_DROP_AVERAGE_LOW;
49  m_DropSpawnMinDelay = BleedingIndicationConstants.SEQUENCE_DROP_DELAY_MIN_LOW;
50  m_DropSpawnMaxDelay = BleedingIndicationConstants.SEQUENCE_DROP_DELAY_MAX_LOW;
51  break;
52  }
53  case BleedingIndicationConstants.INDICATOR_SEVERITY_MEDIUM:
54  {
55  m_SequenceDuration = BleedingIndicationConstants.SEQUENCE_DURATION_MEDIUM;
56  m_AverageFrequency = BleedingIndicationConstants.SEQUENCE_DROP_AVERAGE_MEDIUM;
57  m_DropSpawnMinDelay = BleedingIndicationConstants.SEQUENCE_DROP_DELAY_MIN_MEDIUM;
58  m_DropSpawnMaxDelay = BleedingIndicationConstants.SEQUENCE_DROP_DELAY_MAX_MEDIUM;
59  break;
60  }
61  case BleedingIndicationConstants.INDICATOR_SEVERITY_HIGH:
62  {
63  m_SequenceDuration = BleedingIndicationConstants.SEQUENCE_DURATION_HIGH;
64  m_AverageFrequency = BleedingIndicationConstants.SEQUENCE_DROP_AVERAGE_HIGH;
65  m_DropSpawnMinDelay = BleedingIndicationConstants.SEQUENCE_DROP_DELAY_MIN_HIGH;
66  m_DropSpawnMaxDelay = BleedingIndicationConstants.SEQUENCE_DROP_DELAY_MAX_HIGH;
67  break;
68  }
69 
70  default:
71  {
72  m_AverageFrequency = BleedingIndicationConstants.SEQUENCE_DROP_AVERAGE_LOW;
73  m_DropSpawnMinDelay = BleedingIndicationConstants.SEQUENCE_DROP_DELAY_MIN_LOW;
74  m_DropSpawnMaxDelay = BleedingIndicationConstants.SEQUENCE_DROP_DELAY_MAX_LOW;
75  Debug.Log("Unknown severity value!");
76  }
77 #ifdef DIAG_DEVELOPER
78  if (DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues)
79  {
80  m_SequenceDuration = DbgBleedingIndicationStaticInfo.m_DbgSequenceDuration;
81  m_DropSpawnMinDelay = DbgBleedingIndicationStaticInfo.m_DbgDropMinDelay;
82  m_DropSpawnMaxDelay = DbgBleedingIndicationStaticInfo.m_DbgDropMaxDelay;
83  }
84 #endif
85  }
86 
87  m_TimeElapsedTotal = 0;
88  m_TimeElapsedSequence = 0;
89  }
90 
91  void InitIndicator(vector position)
92  {
93  m_BasePosition = position;
94  ResetIndicator();
95  m_Initialized = true;
96  }
97 
98  void StopIndicator(bool instant = false)
99  {
100  if (!m_Terminating)
101  {
102  m_IsRunning = false;
103 
104  if (instant)
105  {
106  m_EndNow = true;
107  }
108  m_Terminating = true;
109  }
110  }
111 
112  protected void StartRunningDrops()
113  {
114  m_ActiveDropsCount = 0;
115  m_IsRunning = true;
116  TrySpawnNextDrop();
117  m_DropSpawnsQueued = 0;
118 
119  m_CurrentDropProbabilityStep = (int)(m_DropProbabilityRollsCount - (m_DropProbabilityRollsCount / m_AverageFrequency));
120  }
121 
123  protected bool IsRunningDrops()
124  {
125  return m_ActiveDropsCount > 0;
126  }
127 
128  void TrySpawnNextDrop()
129  {
130  ImageWidget dropImage;
131  if (Class.CastTo(dropImage,m_ParentMetaData.GetNextDropImage()) && !dropImage.IsVisible()) //IsVisible false means the drop is free to be used
132  {
133  BleedingIndicatorDropData data = new BleedingIndicatorDropData(dropImage,m_Severity);
134  data.SetBasePosition(m_BasePosition);
135  data.StartDrop();
136 
137  m_ActiveDrops.Insert(data);
138  m_ActiveDropsCount++;
139  }
140 
141  m_LastDropSpawnTime = m_TimeElapsedTotal;
142  m_DropSpawnsQueued--;
143  }
144 
145  protected void ResetSequence()
146  {
147  m_CurrentDropProbabilityStep = 0;
148  m_TimeElapsedSequence = 0;
149  m_DropSpawnsQueued = 0;
150  }
151 
152  void ResetIndicator()
153  {
154  m_Terminating = false;
155  m_EndNow = false;
156  m_TimeElapsedTotal = 0;
157  m_CurrentDropProbabilityStep = 0;
158  m_TimeElapsedSequence = 0;
159  m_LastDropSpawnTime = 0;
160  m_DropSpawnsQueued = 0;
161  }
162 
163  void Update(float timeSlice)
164  {
165  if ( !m_Initialized )
166  {
167  return;
168  }
169 
170 #ifdef DIAG_DEVELOPER
171  if (DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues)
172  {
173  m_SequenceDuration = DbgBleedingIndicationStaticInfo.m_DbgSequenceDuration;
174  }
175 #endif
176  m_SequenceTick = m_SequenceDuration / m_DropProbabilityRollsCount;
177 
178  //run drops, if possible
179  if (!m_Terminating)
180  {
181  if (m_IsRunning)
182  {
183  if (m_TimeElapsedSequence > (m_SequenceTick * m_CurrentDropProbabilityStep))
184  {
185  if (m_CurrentDropProbabilityStep < m_DropProbabilityRollsCount)
186  {
187  float rnd = Math.RandomFloat01();
188  if (rnd < m_DropProbabilityArray[m_CurrentDropProbabilityStep])
189  {
190  m_DropSpawnsQueued++;
191  }
192 
193  m_CurrentDropProbabilityStep++;
194  }
195  }
196 
197  float sinceLastDrop = m_TimeElapsedTotal - m_LastDropSpawnTime;
198  if (m_TimeElapsedSequence > m_SequenceDuration)
199  {
200  ResetSequence();
201  }
202  else if (m_DropSpawnsQueued > 0) //spawn queued drop
203  {
204  if (sinceLastDrop >= m_DropSpawnMinDelay)
205  {
206  TrySpawnNextDrop();
207  }
208  }
209  else if (sinceLastDrop > m_DropSpawnMaxDelay)
210  {
211  TrySpawnNextDrop(); //guaranteed drop
212  m_CurrentDropProbabilityStep++; //substitutes a regular roll..
213  }
214  }
215  else //1st drop ignores delay
216  {
217  StartRunningDrops();
218  }
219  }
220 
221  for (int i = 0; i < m_ActiveDropsCount; i++)
222  {
223  if (!m_EndNow)
224  {
225  //Simulate drops
226  m_ActiveDrops[i].Update(timeSlice);
227  }
228  else
229  {
230  m_ActiveDrops[i].StopDrop();
231  }
232 
233  if (!m_ActiveDrops[i].IsRunning())
234  {
235  m_CleanupQueue.Insert(i);
236  }
237  }
238 
239  //Cleanup drops
240  for (i = m_CleanupQueue.Count() - 1; i >= 0; i--)
241  {
242  m_ActiveDrops.Remove(m_CleanupQueue[i]);
243  m_ActiveDropsCount--;
244  }
245  m_CleanupQueue.Clear();
246 
247  if (m_Terminating && !IsRunningDrops())
248  {
249  m_EndNow = true;
250  }
251 
252  m_TimeElapsedTotal += timeSlice;
253  m_TimeElapsedSequence += timeSlice;
254  }
255 
256  bool GetEndNow()
257  {
258  return m_EndNow;
259  }
260 
261  int GetSeverity()
262  {
263  return m_Severity;
264  }
265 }
BleedingIndicatorDropData
Definition: bleedingdrop.c:2
IsRunning
bool IsRunning()
Definition: tools.c:264
BleedingIndicationConstants
Definition: bleedingindicationconstants.c:1
Managed
TODO doc.
Definition: enscript.c:117
vector
Definition: enconvert.c:105
DbgBleedingIndicationStaticInfo
static info (non-constants)
Definition: bleedingindicationstaticinfo.c:2
array< float >
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
m_IsRunning
protected bool m_IsRunning
Definition: pperequestplatformsbase.c:2
int
Param3 int
Debug
Definition: debug.c:13
m_Initialized
protected bool m_Initialized
Definition: uihintpanel.c:23
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10