Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
hitdirectionbase.c
Go to the documentation of this file.
1 
2 
4 {
5  const float DURATION_COEF_MIN = 0.6;
6  const float INTENSITY_MIN = 0.6;
7 
8  float m_HitDirection;
9  float m_Duration;
10  float m_BreakPoint;
11  float m_TimeActive;
12  float m_IntensityMax;
13 
14  Widget m_LayoutRoot;
15  Widget m_Image;
16 
17  DayZPlayer m_Player;
18 
19  bool m_Initialized;
20  int m_SizeXEnf;
21  int m_SizeYEnf;
22  float m_PosX;
23  float m_PosY;
24  float m_PosXScreenEdge;
25  float m_PosYScreenEdge;
26  float m_AngleRad;
27  float m_AngleRadPrev;
28  float m_SmoothVel[1];
29 
30  ref HitDirectionImagesBase m_ImageData;
31 
33  {
34  m_Initialized = false;
35  m_PosX = 0.0;
36  m_PosY = 0.0;
37  m_AngleRad = 0.0;
38  m_SmoothVel[0] = 0.0;
39 
40  m_ImageData = GetImageData();
41  m_ImageData.GetCurrentImageData(m_LayoutRoot,m_Image);
42  }
43 
45  void Init(DayZPlayer player, float hit_direction, float intensity_max)
46  {
47  m_Player = player;
48  float duration_coef = Math.Clamp(intensity_max,DURATION_COEF_MIN,1);
49  m_IntensityMax = Math.Clamp(intensity_max,INTENSITY_MIN,1);
50  m_Duration = m_DurationMax * duration_coef;
51  m_BreakPoint = Math.Clamp(m_BreakPointBase * m_Duration,0,m_Duration);
52  m_Scatter = Math.Clamp(m_Scatter,0.0,180.0);
53  m_HitDirection = hit_direction + (Math.RandomFloatInclusive(0,m_Scatter) * Math.Pow(-1.0,Math.RandomIntInclusive(0,1)));
54 
55  Widget w = m_LayoutRoot;
56  w = w.GetChildren();
57  while (w)
58  {
59  w.Show(m_Image == w);
60  w = w.GetSibling();
61  }
62 
63  m_Image.SetColor(m_Color);
64 
65  m_LayoutRoot.Show(true);
66 
67  CalculateArrowPosition();
68  SetIndicatorRotation();
69  SetIndicatorPositon();
70  m_Initialized = true;
71  }
72 
73  HitDirectionImagesBase GetImageData(){}
74 
76  {
77  m_LayoutRoot.Show(false);
78  delete m_LayoutRoot;
79  }
80 
81  bool DurationCheck()
82  {
83  if ( m_TimeActive >= m_Duration )
84  {
85  return true;
86  }
87  return false;
88  }
89 
90  void Update( float timeslice )
91  {
92  float intensity;
93 
94  if ( m_TimeActive <= m_BreakPoint )
95  {
96  intensity = m_IntensityMax;
97  }
98  else
99  {
100  float tmp_value = Math.InverseLerp(m_BreakPoint, m_Duration, m_TimeActive);
101  intensity = Math.Lerp(m_IntensityMax,0.0,tmp_value);
102  }
103 
104  m_TimeActive += timeslice;
105  intensity = Math.Clamp(intensity,0,1);
106 
107  if ( m_TimeActive >= m_Duration )
108  {
109  m_LayoutRoot.Show(false);
110  }
111  else
112  {
113  m_LayoutRoot.SetAlpha(intensity);
114  if ( m_Mode == HitDirectionModes.DYNAMIC )
115  {
116  CalculateArrowPosition(timeslice);
117  SetIndicatorPositon(timeslice);
118  SetIndicatorRotation(timeslice);
119  }
120  }
121  }
122 
123  void CalculateArrowPosition(float timeslice = -1.0)
124  {
125  m_HitDirection = Math.NormalizeAngle(m_HitDirection);
126 
127  float angle_direction = m_Player.GetOrientation()[0];
128  angle_direction = Math.NormalizeAngle(angle_direction);
129  float camera_angle = GetGame().GetCurrentCameraDirection().VectorToAngles()[0];
130  camera_angle = Math.NormalizeAngle(camera_angle);
131 
132  float angle_camera_diff = angle_direction - camera_angle;
133  m_AngleRad = m_HitDirection + angle_camera_diff;
134  m_AngleRad = Math.NormalizeAngle(m_AngleRad);
135  m_AngleRad = m_AngleRad * Math.DEG2RAD;
136 
137  m_PosX = 0.0;
138  m_PosY = 0.0;
139 
140  GetScreenSize(m_SizeXEnf,m_SizeYEnf);
141 
142  if ( m_Initialized && timeslice != -1.0 )
143  {
144  float val = m_AngleRadPrev - m_AngleRad + Math.PI;
145  val = Math.ModFloat(val, Math.PI2);
146  val -= Math.PI;
147  m_AngleRad = m_AngleRadPrev - Math.SmoothCD(0, val, m_SmoothVel, 0.1, 1000, timeslice);
148  }
149  m_AngleRadPrev = m_AngleRad;
150 
151  m_PosXScreenEdge = Math.Clamp(Math.Sin(m_AngleRad)/Math.Sin(Math.PI/4),-1,1) * ( m_SizeXEnf/2 + m_DistanceAdjust * m_SizeXEnf);
152  m_PosYScreenEdge = Math.Clamp(-1 * Math.Cos(m_AngleRad)/Math.Cos(Math.PI/4),-1,1) * ( m_SizeYEnf/2 + m_DistanceAdjust * m_SizeYEnf);
153 
154  FinalizePositionCalculation();
155  }
156 
158  void FinalizePositionCalculation(){}
159  void SetIndicatorRotation(float timeslice = -1.0){}
160 
161  void SetIndicatorPositon(float timeslice = -1.0)
162  {
163  m_LayoutRoot.SetPos(m_PosX,m_PosY,true);
164  }
165 
166  //-----------------------------------------------------------------------
167  //Static stuff below
168  //-----------------------------------------------------------------------
169  static bool m_ServerOverrideEnabled;
170  static int m_Mode;
171  static int m_ID;
172  static int m_Color;
173  static protected typename m_Type;
174  static float m_DurationMax;
175  static float m_BreakPointBase;
176  static float m_DistanceAdjust;
177  static int m_RotationOverride;
178  static float m_Scatter;
179 
181  static void CheckValues()
182  {
183  m_ServerOverrideEnabled = CfgGameplayHandler.GetHitIndicationOverrideEnabled();
184  if (m_ServerOverrideEnabled)
185  {
186  m_Mode = CfgGameplayHandler.GetHitIndicationMode();
187  m_ID = CfgGameplayHandler.GetHitIndicationTypeID();
188  m_Color = CfgGameplayHandler.GetHitIndicationIndicatorColor();
189  m_DurationMax = CfgGameplayHandler.GetHitIndicationMaxDuration();
190  m_BreakPointBase = CfgGameplayHandler.GetHitIndicationBreakPoint();
191  m_Scatter = CfgGameplayHandler.GetHitIndicationScatter();
192  }
193  else
194  {
195  m_Mode = HitDirectionModes.STATIC;
196  m_ID = HitIndicatorType.SPLASH;
197  m_Color = HitDirectionConstants.COLOR_DEFAULT;
198  m_DurationMax = HitDirectionConstants.DURATION_BASE;
199  m_BreakPointBase = HitDirectionConstants.BREAKPOINT_BASE;
200  m_Scatter = HitDirectionConstants.SCATTER;
201  }
202  m_DistanceAdjust = HitDirectionConstants.DISTANCE_ADJUST;
203  m_RotationOverride = HitDirectionConstants.ROTATION_DEFAULT;
204  }
205 
206  static typename GetCurrentType()
207  {
208  switch (m_ID)
209  {
210  case HitIndicatorType.SPLASH:
211  m_Type = HitDirectionEffectSplash;
212  break;
213 
214  case HitIndicatorType.SPIKE:
215  m_Type = HitDirectionEffectSpike;
216  break;
217 
218  case HitIndicatorType.ARROW:
219  m_Type = HitDirectionEffectArrow;
220  break;
221 
222  default:
223  ErrorEx("Unknown HitDirection mode, using HitIndicatorType.SPLASH",ErrorExSeverity.INFO);
224  m_Type = HitDirectionEffectSplash;
225  break;
226  }
227 
228  return m_Type;
229  }
230 }
GetGame
proto native CGame GetGame()
m_Duration
float m_Duration
Definition: bullethitreaction.c:56
GetScreenSize
proto void GetScreenSize(out int x, out int y)
HitDirectionImagesBase
Definition: hitdirectionimagesbase.c:2
DayZPlayer
Definition: dayzplayerimplement.c:72
ErrorEx
enum ShapeType ErrorEx
HitDirectionModes
HitDirectionModes
Definition: constants.c:97
ErrorExSeverity
ErrorExSeverity
Definition: endebug.c:61
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
CfgGameplayHandler
Definition: cfggameplayhandler.c:1
HitDirectionEffectBase
Definition: hitdirectionarrow.c:2
m_Color
string m_Color
Definition: enentity.c:848
m_Initialized
protected bool m_Initialized
Definition: uihintpanel.c:23
m_TimeActive
class DamageDealtEffect m_TimeActive
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
m_ID
protected int m_ID
ID of effect, given by SEffectManager when registered (automatically done when playing through it)
Definition: effect.c:49