DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
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
9 float m_Duration;
13
16
18
22 float m_PosX;
23 float m_PosY;
28 float m_SmoothVel[1];
29
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
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;
52 m_Scatter = Math.Clamp(m_Scatter,0.0,180.0);
54
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
70 m_Initialized = true;
71 }
72
74
76 {
77 m_LayoutRoot.Show(false);
78 delete m_LayoutRoot;
79 }
80
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
95 {
96 intensity = m_IntensityMax;
97 }
98 else
99 {
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 {
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;
136
137 m_PosX = 0.0;
138 m_PosY = 0.0;
139
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 }
150
153
155 }
156
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 //-----------------------------------------------------------------------
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;
178 static float m_Scatter;
179
181 static void CheckValues()
182 {
185 {
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}
proto native vector GetCurrentCameraDirection()
static int GetHitIndicationTypeID()
static int GetHitIndicationMode()
static float GetHitIndicationScatter()
static float GetHitIndicationMaxDuration()
static bool GetHitIndicationOverrideEnabled()
static int GetHitIndicationIndicatorColor()
static float GetHitIndicationBreakPoint()
override HitDirectionImagesBase GetImageData()
ref HitDirectionImagesBase m_ImageData
void Init(DayZPlayer player, float hit_direction, float intensity_max)
Called manually after object spawn.
override void FinalizePositionCalculation()
static bool m_ServerOverrideEnabled
void FinalizePositionCalculation()
specific handling on individual indicator type
void Update(float timeslice)
override void SetIndicatorRotation(float timeslice=-1.0)
void SetIndicatorRotation(float timeslice=-1.0)
void SetIndicatorPositon(float timeslice=-1.0)
static void CheckValues()
range 0..180, randomized offset of direction to make it less acurate
void CalculateArrowPosition(float timeslice=-1.0)
static float m_DistanceAdjust
range 0..1, a point where the fading starts
HitDirectionImagesBase GetImageData()
void GetCurrentImageData(out Widget layout, out Widget image)
Layout should be sufficient for generic manipulation of the hit image.
Definition EnMath.c:7
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
proto native CGame GetGame()
HitDirectionModes
Definition constants.c:86
ErrorExSeverity
Definition EnDebug.c:62
enum ShapeType ErrorEx
static proto float Cos(float angle)
Returns cosinus of angle in radians.
static proto float ModFloat(float x, float y)
Returns the floating-point remainder of x/y rounded towards zero.
static proto float Pow(float v, float power)
Return power of v ^ power.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:86
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:53
static proto float SmoothCD(float val, float target, inout float velocity[], float smoothTime, float maxVelocity, float dt)
Does the CD smoothing function - easy in | easy out / S shaped smoothing.
static const float PI
Definition EnMath.c:12
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static const float PI2
Definition EnMath.c:13
static proto float NormalizeAngle(float ang)
Normalizes the angle (0...360)
static const float DEG2RAD
Definition EnMath.c:17
static proto float Sin(float angle)
Returns sinus of angle in radians.
proto void GetScreenSize(out int x, out int y)