DayZ 1.24
Loading...
Searching...
No Matches
BleedingIndicator.c
Go to the documentation of this file.
1
3class 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;
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;
27
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 {
46 {
51 break;
52 }
54 {
59 break;
60 }
62 {
67 break;
68 }
69
70 default:
71 {
75 Debug.Log("Unknown severity value!");
76 }
77#ifdef DIAG_DEVELOPER
79 {
83 }
84#endif
85 }
86
87 m_TimeElapsedTotal = 0;
88 m_TimeElapsedSequence = 0;
89 }
90
92 {
93 m_BasePosition = position;
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 m_EndNow = true;
106 m_Terminating = true;
107 }
108 }
109
110 protected void StartRunningDrops()
111 {
112 m_ActiveDropsCount = 0;
113 m_IsRunning = true;
115 m_DropSpawnsQueued = 0;
116
117 m_CurrentDropProbabilityStep = (int)(m_DropProbabilityRollsCount - (m_DropProbabilityRollsCount / m_AverageFrequency));
118 }
119
121 protected bool IsRunningDrops()
122 {
123 return m_ActiveDropsCount > 0;
124 }
125
127 {
129 if (Class.CastTo(dropImage, m_ParentMetaData.GetNextDropImage()) && !dropImage.IsVisible()) //IsVisible false means the drop is free to be used
130 {
132 data.SetBasePosition(m_BasePosition);
133 data.StartDrop();
134
135 m_ActiveDrops.Insert(data);
136 m_ActiveDropsCount++;
137 }
138
139 m_LastDropSpawnTime = m_TimeElapsedTotal;
140 m_DropSpawnsQueued--;
141 }
142
143 protected void ResetSequence()
144 {
145 m_CurrentDropProbabilityStep = 0;
146 m_TimeElapsedSequence = 0;
147 m_DropSpawnsQueued = 0;
148 }
149
151 {
152 m_Terminating = false;
153 m_EndNow = false;
154 m_TimeElapsedTotal = 0;
155 m_CurrentDropProbabilityStep = 0;
156 m_TimeElapsedSequence = 0;
157 m_LastDropSpawnTime = 0;
158 m_DropSpawnsQueued = 0;
159 }
160
161 void Update(float timeSlice)
162 {
163 if (!m_Initialized)
164 return;
165
166#ifdef DIAG_DEVELOPER
169#endif
170 m_SequenceTick = m_SequenceDuration / m_DropProbabilityRollsCount;
171
172 //run drops, if possible
173 if (!m_Terminating)
174 {
175 if (m_IsRunning)
176 {
177 if (m_TimeElapsedSequence > (m_SequenceTick * m_CurrentDropProbabilityStep))
178 {
179 if (m_CurrentDropProbabilityStep < m_DropProbabilityRollsCount)
180 {
181 float rnd = Math.RandomFloat01();
182 if (rnd < m_DropProbabilityArray[m_CurrentDropProbabilityStep])
183 m_DropSpawnsQueued++;
184
185 m_CurrentDropProbabilityStep++;
186 }
187 }
188
189 float sinceLastDrop = m_TimeElapsedTotal - m_LastDropSpawnTime;
190 if (m_TimeElapsedSequence > m_SequenceDuration)
192 else if (m_DropSpawnsQueued > 0) //spawn queued drop
193 {
194 if (sinceLastDrop >= m_DropSpawnMinDelay)
196 }
197 else if (sinceLastDrop > m_DropSpawnMaxDelay)
198 {
199 TrySpawnNextDrop(); //guaranteed drop
200 m_CurrentDropProbabilityStep++; //substitutes a regular roll..
201 }
202 }
203 else //1st drop ignores delay
205 }
206
207 for (int i = 0; i < m_ActiveDropsCount; i++)
208 {
209 if (!m_EndNow)
210 {
211 //Simulate drops
212 m_ActiveDrops[i].Update(timeSlice);
213 }
214 else
215 m_ActiveDrops[i].StopDrop();
216
217 if (!m_ActiveDrops[i].IsRunning())
218 m_CleanupQueue.Insert(i);
219 }
220
221 //Cleanup drops
222 for (i = m_CleanupQueue.Count() - 1; i >= 0; i--)
223 {
224 m_ActiveDrops.Remove(m_CleanupQueue[i]);
225 m_ActiveDropsCount--;
226 }
227 m_CleanupQueue.Clear();
228
229 if (m_Terminating && !IsRunningDrops())
230 m_EndNow = true;
231
232 m_TimeElapsedTotal += timeSlice;
233 m_TimeElapsedSequence += timeSlice;
234 }
235
237 {
238 return m_EndNow;
239 }
240
242 {
243 return m_Severity;
244 }
245}
Param3 int
bool m_IsRunning
bool m_Initialized
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
TODO doc.
Definition EnScript.c:118
float m_SequenceDuration
ref set< ref BleedingIndicatorDropData > m_ActiveDrops
void ResetSequence()
ref set< int > m_CleanupQueue
GameplayEffectsDataBleeding m_ParentMetaData
int m_CurrentDropProbabilityStep
int m_ActiveDropsCount
array< float > m_DropProbabilityArray
bool IsRunningDrops()
Are any drops currently being animated?
void InitIndicator(vector position)
void BleedingIndicator(int source_ID, int severity, GameplayEffectsDataBleeding parent)
int m_DropSpawnsQueued
float m_TimeElapsedTotal
float m_LastDropSpawnTime
void StopIndicator(bool instant=false)
float m_SequenceTick
void StartRunningDrops()
bool m_Initialized
void ResetIndicator()
float m_TimeElapsedSequence
int m_DropProbabilityRollsCount
float m_AverageFrequency
void Update(float timeSlice)
float m_DropSpawnMinDelay
float m_DropSpawnMaxDelay
void TrySpawnNextDrop()
vector m_BasePosition
Definition EnMath.c:7
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:126
bool IsRunning()
Definition tools.c:252