DayZ 1.24
Loading...
Searching...
No Matches
GEWidgetsMetaDataBleeding.c
Go to the documentation of this file.
1
3class GameplayEffectsDataBleeding extends GameplayEffectsData
4{
5 protected bool m_Initialized; //tied to initialization of 'BleedingSourcesManagerBase' on player object, skips updates until ready, even when formally active
6 protected bool m_Visible; //overall visibility
10 protected int m_LastDropIdx;
11 protected int m_ImageWidgetCount; //number of available blood drop image widgets
15
17
19 {
20 m_RegisteredInstances = new map<int, ref BleedingIndicator>;
21 m_CleanupQueue = new array<int>;
22 m_RunningIndicators = new array<int>;
23 m_Initialized = false;
24 }
25
26 override void Init(array<ref Widget> input, int type, Widget layout_root, int user_override = -1)
27 {
29
30 m_WidgetArray.ShuffleArray(); //shuffles order of the widgets on every init
31 m_ImageWidgetCount = m_WidgetArray.Count();
32 m_BloodDropsFrame = m_LayoutRoot.FindAnyWidgetById(EffectWidgetsTypes.BLEEDING_LAYER);
33 m_Visible = g_Game.GetProfileOption(EDayZProfilesOptions.BLEEDINGINDICATION);
34 m_BloodDropsFrame.Show(m_Visible);
35 m_LastDropIdx = -1;
36 m_LastPositionFrameUsed = -1;
37
42 }
43
44 override bool HasDefinedHandle()
45 {
46 return true;
47 }
48
49 override bool DataInitialized()
50 {
51 return m_Initialized;
52 }
53
54 override void RegisterData(Param p)
55 {
56 if (m_Initialized)
57 {
58#ifdef DEVELOPER
59 ErrorEx("" + this + " is already initialized, further registration not possible!");
60#else
61 Debug.Log("ERROR: " + this + " is already initialized, further registration not possible!");
62#endif
63 return;
64 }
65
66 //<finish registration,bit,flow_modifier>
68 if (Class.CastTo(par, p))
69 {
70 if (par.param1 == true) //finish registration
71 {
72 m_Initialized = true;
73 return;
74 }
75
77 }
78 }
79
81 {
83 BleedingIndicator indicator = new BleedingIndicator(bit, severity, this); //source_ID == bit for the purpose of pairing
84 m_RegisteredInstances.Set(bit, indicator);
85 }
86
88 {
89 if (m_RunningIndicators.Find(source_ID) != -1)
90 return;
91 BleedingIndicator indicator = m_RegisteredInstances.Get(source_ID);
92 //indicator.InitIndicator(position); //would be nice if we could pair the indicator position to the hit position that caused the bleeding, wouldn't it
94 m_RunningIndicators.Insert(source_ID);
95 }
96
112
114 {
115 m_LastDropIdx++;
116 if (m_LastDropIdx > (m_ImageWidgetCount - 1))
117 m_LastDropIdx = 0;
118
119 return ImageWidget.Cast(m_WidgetArray[m_LastDropIdx]);
120 }
121
123 {
124 m_RegisteredInstances.Get(source_ID).StopIndicator(instant); //stop queued, evaluated on update!
125 }
126
128 {
129 BleedingIndicator bib;
130 for (int i = 0; i < m_RunningIndicators.Count(); i++)
131 {
132 bib = m_RegisteredInstances.Get(m_RunningIndicators[i]);
133 bib.Update(timeSlice);
134 if (bib.GetEndNow())
135 m_CleanupQueue.Insert(m_RunningIndicators[i]);
136 }
137 }
138
140 {
141 for (int i = 0; i < m_CleanupQueue.Count(); i++)
142 m_RunningIndicators.RemoveItem(m_CleanupQueue[i]);
143 m_CleanupQueue.Clear();
144 }
145
146 override void Update(float timeSlice = 0, Param p = null, int handle = -1)
147 {
148 //starts or ends a bleeding indicator
149 if (p)
150 {
151 //start/stop of the indicator
152 //<state,bit,position,immediate>
154
155 //hide/show of bleeding effect visuals
156 //<state>
158
159 if (Class.CastTo(par, p))
160 {
161 bool state = par.param1;
162 if (state) //queue add indicator
163 SpawnBleedingIndicator(par.param2, par.param3);
164 else //queue stop indicator
165 StopBleedingIndicator(par.param2, par.param4);
166 }
167 else if (Class.CastTo(parShow, p) && m_Visible != parShow.param1)
168 {
169 m_Visible = parShow.param1;
170 m_BloodDropsFrame.Show(m_Visible);
171 }
172 }
173
174 //updates bleeding indicators
177
178 if (m_RunningIndicators.Count() <= 0)
179 {
180 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.BLEEDING_LAYER});
181 m_WidgetArray.ShuffleArray();
182 }
183 }
184
185 override void UpdateVisibility(bool state)
186 {
187 m_Visible = g_Game.GetProfileOption(EDayZProfilesOptions.BLEEDINGINDICATION); //ugh
188 //manage layout visibility
190 while (w && w != m_LayoutRoot && m_Visible == state && w.IsVisibleHierarchy() != state)
191 {
192 w.Show(state);
193 w = w.GetParent();
194 }
195 }
196
198 override void ForceStop()
199 {
200 super.ForceStop();
201
202 foreach (int i: m_RunningIndicators)
203 m_RegisteredInstances.Get(i).StopIndicator(true);
204 Update();
205 }
206
208 {
209 if (!m_ProbabilityMap)
210 m_ProbabilityMap = new map<int, ref array<float>>;
211
213
216
217 m_ProbabilityMap.Insert(severity, probabilities);
218 }
219
221 {
222 array<float> ret = m_ProbabilityMap.Get(severity);
223 if (!ret)
224 ErrorEx("No defined data for the selected severity!");
225 return ret;
226 }
227
229 {
230 Widget frameParent = m_LayoutRoot.FindAnyWidget("PoisitioningFrames");
231 if (frameParent)
232 {
233 if (!m_PositioningFramesArray)
234 m_PositioningFramesArray = new array<Widget>;
235
236 Widget frame = frameParent.GetChildren();
237 while (frame)
238 {
239 m_PositioningFramesArray.Insert(frame);
240 frame = frame.GetSibling();
241 }
242 }
243 }
244
246 {
247 if (m_PositioningFramesArray)
248 {
249 int arrayCount = m_PositioningFramesArray.Count();
250 int index = Math.RandomInt(0, arrayCount);
251 if (index == m_LastPositionFrameUsed)
252 {
253 index++;
254 if (index >= arrayCount)
255 index = 0;
256 }
257
258 Widget frame = m_PositioningFramesArray[index];
259 m_LastPositionFrameUsed = index;
260
261 if (frame)
262 {
263 int screenX, screenY;
264 float x, y, x_size, y_size;
265 frame.GetScreenPos(x, y);
266 frame.GetScreenSize(x_size, y_size);
267
270
271 return Vector(x, y, 0);
272 }
273 }
274 return vector.Zero;
275 }
276}
DayZGame g_Game
Definition DayZGame.c:3528
EDayZProfilesOptions
Icon x
Icon y
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
Manages all bleeding indicators and their updates.
override void Init(array< ref Widget > input, int type, Widget layout_root, int user_override=-1)
ref map< int, ref BleedingIndicator > m_RegisteredInstances
override void ForceStop()
stops and re-sets indicators and images even out of sequence. Should still be tied to the 'player' up...
override void RegisterData(Param p)
ref array< Widget > m_PositioningFramesArray
void SpawnBleedingIndicator(int source_ID, vector position)
array< float > GetProbabilities(int severity)
override void Update(float timeSlice=0, Param p=null, int handle=-1)
void BuildProbabilityData(int severity, float frequency)
int CalculateSeverity(float flow_modifier)
override void UpdateVisibility(bool state)
ref array< int > m_RunningIndicators
void GameplayEffectsDataBleeding(array< ref Widget > input, int type, int user_override=-1)
ref map< int, ref array< float > > m_ProbabilityMap
void StopBleedingIndicator(int source_ID, bool instant=false)
void UpdateBleedingIndicators(float timeSlice)
void RegisterBleedingIndicatorInstance(int bit, float flow_modifier)
Definition EnMath.c:7
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
static const float BLEEDING_SOURCE_FLOW_MODIFIER_LOW
static const float BLEEDING_SOURCE_FLOW_MODIFIER_HIGH
static const float BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM
static const vector Zero
Definition EnConvert.c:110
proto native CGame GetGame()
enum ShapeType ErrorEx
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
bool m_Visible
Definition EnEntity.c:847
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static float Poisson(float mean, int occurences)
occurences values above '12' will cause Factorial to overflow int.
Definition EnMath.c:681
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:106
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
proto native volatile void Update()