Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
gewidgetsmetadatableeding.c
Go to the documentation of this file.
1 
3 class 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
7  protected ref map<int,ref BleedingIndicator> m_RegisteredInstances;
8  protected ref array<int> m_CleanupQueue;
9  protected ref array<int> m_RunningIndicators;
10  protected int m_LastDropIdx;
11  protected int m_ImageWidgetCount; //number of available blood drop image widgets
12  protected ref map<int,ref array<float>> m_ProbabilityMap;
13  protected ref array<Widget> m_PositioningFramesArray;
14  protected Widget m_BloodDropsFrame;
15 
16  protected int m_LastPositionFrameUsed;
17 
18  void GameplayEffectsDataBleeding(array<ref Widget> input, int type, int user_override = -1)
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  {
28  super.Init(input, type, layout_root, user_override);
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 
38  BuildProbabilityData(BleedingIndicationConstants.INDICATOR_SEVERITY_LOW,BleedingIndicationConstants.SEQUENCE_DROP_AVERAGE_LOW);
39  BuildProbabilityData(BleedingIndicationConstants.INDICATOR_SEVERITY_MEDIUM,BleedingIndicationConstants.SEQUENCE_DROP_AVERAGE_MEDIUM);
40  BuildProbabilityData(BleedingIndicationConstants.INDICATOR_SEVERITY_HIGH,BleedingIndicationConstants.SEQUENCE_DROP_AVERAGE_HIGH);
41  BuildPositioningData();
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 
76  RegisterBleedingIndicatorInstance(par.param2,par.param3);
77  }
78  }
79 
80  void RegisterBleedingIndicatorInstance(int bit, float flow_modifier)
81  {
82  int severity = CalculateSeverity(flow_modifier);
83  BleedingIndicator indicator = new BleedingIndicator(bit,severity,this); //source_ID == bit for the purpose of pairing
84  m_RegisteredInstances.Set(bit,indicator);
85  }
86 
87  void SpawnBleedingIndicator(int source_ID, vector position)
88  {
89  if (m_RunningIndicators.Find(source_ID) != -1)
90  {
91  return;
92  }
93  BleedingIndicator indicator = m_RegisteredInstances.Get(source_ID);
94  //indicator.InitIndicator(position); //would be nice if we could pair the indicator position to the hit position that caused the bleeding, wouldn't it
95  indicator.InitIndicator(GenerateSequenceRandomPosition());
96  m_RunningIndicators.Insert(source_ID);
97  }
98 
99  int CalculateSeverity(float flow_modifier)
100  {
101  switch (flow_modifier)
102  {
103  case PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_LOW:
104  return BleedingIndicationConstants.INDICATOR_SEVERITY_LOW;
105 
106  case PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_MEDIUM:
107  return BleedingIndicationConstants.INDICATOR_SEVERITY_MEDIUM;
108 
109  case PlayerConstants.BLEEDING_SOURCE_FLOW_MODIFIER_HIGH:
110  return BleedingIndicationConstants.INDICATOR_SEVERITY_HIGH;
111  }
112  return BleedingIndicationConstants.INDICATOR_SEVERITY_LOW;
113  }
114 
115  ImageWidget GetNextDropImage()
116  {
117  m_LastDropIdx++;
118  if (m_LastDropIdx > (m_ImageWidgetCount - 1))
119  {
120  m_LastDropIdx = 0;
121  }
122 
123  return ImageWidget.Cast(m_WidgetArray[m_LastDropIdx]);
124  }
125 
126  void StopBleedingIndicator(int source_ID, bool instant = false)
127  {
128  m_RegisteredInstances.Get(source_ID).StopIndicator(instant); //stop queued, evaluated on update!
129  }
130 
131  void UpdateBleedingIndicators(float timeSlice)
132  {
133  BleedingIndicator bib;
134  for (int i = 0; i < m_RunningIndicators.Count(); i++)
135  {
136  bib = m_RegisteredInstances.Get(m_RunningIndicators[i]);
137  bib.Update(timeSlice);
138  if ( bib.GetEndNow() )
139  {
140  m_CleanupQueue.Insert(m_RunningIndicators[i]);
141  }
142  }
143  }
144 
145  void CleanupBleedingIndicators()
146  {
147  for (int i = 0; i < m_CleanupQueue.Count(); i++)
148  {
149  m_RunningIndicators.RemoveItem(m_CleanupQueue[i]);
150  }
151  m_CleanupQueue.Clear();
152  }
153 
154  override void Update(float timeSlice = 0, Param p = null, int handle = -1)
155  {
156  //starts or ends a bleeding indicator
157  if (p)
158  {
159  //start/stop of the indicator
160  //<state,bit,position,immediate>
161  Param4<bool,int,vector,bool> par;
162 
163  //hide/show of bleeding effect visuals
164  //<state>
165  Param1<bool> parShow;
166 
167  if (Class.CastTo(par,p))
168  {
169  bool state = par.param1;
170  if (state) //queue add indicator
171  {
172  SpawnBleedingIndicator(par.param2,par.param3);
173  }
174  else //queue stop indicator
175  {
176  StopBleedingIndicator(par.param2,par.param4);
177  }
178  }
179  else if (Class.CastTo(parShow,p) && m_Visible != parShow.param1)
180  {
181  m_Visible = parShow.param1;
182  m_BloodDropsFrame.Show(m_Visible);
183  }
184  }
185 
186  //updates bleeding indicators
187  UpdateBleedingIndicators(timeSlice);
188  CleanupBleedingIndicators();
189 
190  if (m_RunningIndicators.Count() <= 0)
191  {
192  GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.BLEEDING_LAYER});
193  m_WidgetArray.ShuffleArray();
194  }
195  }
196 
197  override void UpdateVisibility(bool state)
198  {
199  m_Visible = g_Game.GetProfileOption(EDayZProfilesOptions.BLEEDINGINDICATION); //ugh
200  //manage layout visibility
201  Widget w = m_BloodDropsFrame;
202  while (w && w != m_LayoutRoot && m_Visible == state && w.IsVisibleHierarchy() != state)
203  {
204  w.Show(state);
205  w = w.GetParent();
206  }
207  }
208 
210  override void ForceStop()
211  {
212  super.ForceStop();
213 
214  foreach (int i: m_RunningIndicators)
215  {
216  m_RegisteredInstances.Get(i).StopIndicator(true);
217  }
218  Update();
219  }
220 
221  void BuildProbabilityData(int severity, float frequency)
222  {
223  if (!m_ProbabilityMap)
224  {
225  m_ProbabilityMap = new map<int,ref array<float>>;
226  }
227 
228  array<float> probabilities = new array<float>;
229 
230  for (int i = 0; i < BleedingIndicationConstants.SEQUENCE_STEPS; i++)
231  {
232  probabilities.Insert(Math.Poisson(frequency,i));
233  }
234 
235  m_ProbabilityMap.Insert(severity,probabilities);
236  }
237 
238  array<float> GetProbabilities(int severity)
239  {
240  array<float> ret = m_ProbabilityMap.Get(severity);
241  if (!ret)
242  {
243  ErrorEx("No defined data for the selected severity!");
244  }
245  return ret;
246  }
247 
248  void BuildPositioningData()
249  {
250  Widget frameParent = m_LayoutRoot.FindAnyWidget("PoisitioningFrames");
251  if (frameParent)
252  {
253  if (!m_PositioningFramesArray)
254  {
255  m_PositioningFramesArray = new array<Widget>;
256  }
257 
258  Widget frame = frameParent.GetChildren();
259  while (frame)
260  {
261  m_PositioningFramesArray.Insert(frame);
262  frame = frame.GetSibling();
263  }
264  }
265  }
266 
267  vector GenerateSequenceRandomPosition()
268  {
269  if (m_PositioningFramesArray)
270  {
271  int arrayCount = m_PositioningFramesArray.Count();
272  int index = Math.RandomInt(0,arrayCount);
273  if (index == m_LastPositionFrameUsed)
274  {
275  index++;
276  if (index >= arrayCount)
277  {
278  index = 0;
279  }
280  }
281 
282  Widget frame = m_PositioningFramesArray[index];
283  m_LastPositionFrameUsed = index;
284 
285  if (frame)
286  {
287  int screenX,screenY;
288  float x,y,x_size,y_size;
289  frame.GetScreenPos(x,y);
290  frame.GetScreenSize(x_size,y_size);
291 
292  x = Math.RandomFloatInclusive(x,x+x_size);
293  y = Math.RandomFloatInclusive(y,y+y_size);
294 
295  return Vector(x,y,0);
296  }
297  }
298  return vector.Zero;
299  }
300 }
GetGame
proto native CGame GetGame()
BleedingIndicationConstants
Definition: bleedingindicationconstants.c:1
EDayZProfilesOptions
EDayZProfilesOptions
Definition: edayzprofilesoptions.c:1
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
y
Icon y
Param3
Definition: entityai.c:95
ErrorEx
enum ShapeType ErrorEx
map
map
Definition: controlsxboxnew.c:3
PlayerConstants
Definition: playerconstants.c:1
vector
Definition: enconvert.c:105
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
m_Visible
bool m_Visible
Definition: enentity.c:850
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
x
Icon x
Debug
Definition: debug.c:13
m_Initialized
protected bool m_Initialized
Definition: uihintpanel.c:23
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
GameplayEffectsData
Manages all bleeding indicators and their updates.
Definition: gewidgetsmetadatableeding.c:3