DayZ 1.24
Loading...
Searching...
No Matches
UndergroundHandlerClient.c
Go to the documentation of this file.
2{
3 NONE,//player is not interacting with underground at any level
4 OUTER,//player is on the outskirts of the underdound, some effects are already in effect, while others might not be
5 TRANSITIONING,//player has entered underground and is in the process of screen darkening transition
6 FULL//the player is now fully entered underground
8
10{
11 const float LIGHT_BLEND_SPEED_IN = 5;
12 const float LIGHT_BLEND_SPEED_OUT = 1.75;
13 const float MAX_RATIO = 0.9;//how much max ratio between 0..1 can a single breadcrumb occupy
14 const float RATIO_CUTOFF = 0;//what's the minimum ratio a breadcrumb needs to have to be considered when calculatiing accommodation
15 const float DISTANCE_CUTOFF = 5;//we ignore breadcrumbs further than this distance
16 const float ACCO_MODIFIER = 1;//when we calculate eye accommodation between 0..1 based on the breadcrumbs values and distances, we multiply the result by this modifier to get the final eye accommodation value
18 const string UNDERGROUND_LIGHTING = "dz\\data\\lighting\\lighting_underground.txt";
20
25
26 protected float m_EyeAccoTarget = 1;
27 protected float m_AccoInterpolationSpeed;
28 protected float m_EyeAcco = 1;
29 protected float m_LightingLerpTarget;
30 protected float m_LightingLerp;
32
34
36 {
37 GetGame().GetWorld().LoadUserLightingCfg(UNDERGROUND_LIGHTING, "Underground");
40 }
41
43 {
44 if (GetGame())
45 {
46 GetGame().GetWorld().SetExplicitVolumeFactor_EnvSounds2D(1, 0.5);
47 GetGame().GetWeather().SuppressLightningSimulation(false);
48 GetGame().GetWorld().SetUserLightingLerp(0);
51 }
52 }
53
55 {
56 if (!m_Requester)
57 {
58 m_Requester = PPERUndergroundAcco.Cast(PPERequesterBank.GetRequester(PPERequesterBank.REQ_UNDERGROUND));
59 m_Requester.Start();
60 }
61 return m_Requester;
62 }
63
70
78
79 protected void CalculateEyeAccoTarget()
80 {
81 if (m_TransitionalTrigger && m_TransitionalTrigger.m_Data.Breadcrumbs.Count() >= 2)
82 {
83 float closestDist = float.MAX;
84 float acco;
87
88
89 int excludeMask = 0;
90 foreach (int indx, auto crumb: m_TransitionalTrigger.m_Data.Breadcrumbs)
91 {
92 if (indx > 32)//error handling for exceeding this limit is handled elsewhere
93 break;
94
95 float dist = vector.Distance(m_Player.GetPosition(), crumb.GetPosition());
96 float crumbRadius = m_TransitionalTrigger.m_Data.Breadcrumbs[indx].Radius;
98
99 if (crumbRadius != -1)
102 excludeMask = (excludeMask | (1 << indx));
103 else if (m_TransitionalTrigger.m_Data.Breadcrumbs[indx].UseRaycast)
104 {
105 int idx = m_Player.GetBoneIndexByName("Head");
106 vector rayStart = m_Player.GetBonePositionWS(idx);
107 vector rayEnd = crumb.GetPosition();
109 float hitFraction;
111
113 excludeMask = (excludeMask | (1 << indx));
114 }
115
116 distances.Insert(dist);
117
118#ifdef DIAG_DEVELOPER
119 if (DiagMenu.GetBool(DiagMenuIDs.UNDERGROUND_SHOW_BREADCRUMB))
120 Debug.DrawSphere(crumb.GetPosition(), 0.1, COLOR_RED, ShapeFlags.ONCE);
121#endif
122 }
123 float baseDst = distances[0];
124 float sum = 0;
125 //Print(excludeMask);
126 foreach (float dst: distances)
127 {
128 if (dst == 0)
129 dst = 0.1;
130 float dstInv = (baseDst / dst) * baseDst;
131 sum += dstInv;
133 }
134 float sumCheck = 0;
135 float eyeAcco = 0;
136 foreach (int i, float dstInvert: distancesInverted)
137 {
138 /*
139 //Print(m_TransitionalTrigger.m_Data.Breadcrumbs[i].EyeAccommodation);
140 //Print(m_TransitionalTrigger.m_Data.Breadcrumbs.Count());
141 */
142 if ((1 << i) & excludeMask)
143 continue;
144 float ratio = dstInvert / sum;
145 if (ratio > MAX_RATIO)
147 if (ratio > RATIO_CUTOFF)
148 {
149#ifdef DIAG_DEVELOPER
150 if (DiagMenu.GetBool(DiagMenuIDs.UNDERGROUND_SHOW_BREADCRUMB))
151 {
152 float intensity = (1 - ratio) * 255;
153 Debug.DrawLine(GetGame().GetPlayer().GetPosition() + "0 1 0", m_TransitionalTrigger.m_Data.Breadcrumbs[i].GetPosition(), ARGB(0, 255, intensity, intensity), ShapeFlags.ONCE);
154 }
155#endif
156 eyeAcco += ratio * m_TransitionalTrigger.m_Data.Breadcrumbs[i].EyeAccommodation;
157
158 }
159
160 }
162 }
163 }
164
165 protected void ProcessEyeAcco(float timeSlice)
166 {
169 ApplyEyeAcco();
170 if (reachedTarget && !m_Player.m_UndergroundPresence)
171 {
172 GetRequester().Stop();
174 //m_NVRequester.SetUndergroundExposureCoef(1.0);
175 m_Player.KillUndergroundHandler();
176 }
177
178 }
179
180 protected void ProcessLighting(float timeSlice)
181 {
182#ifdef DEVELOPER
183 if (!DiagMenu.GetBool(DiagMenuIDs.UNDERGROUND_DISABLE_DARKENING))
184 GetGame().GetWorld().SetUserLightingLerp(m_LightingLerp);
185 else
186 GetGame().GetWorld().SetUserLightingLerp(0);
187#else
188 GetGame().GetWorld().SetUserLightingLerp(m_LightingLerp);
189#endif
190 }
191
192 protected void ProcessSound(float timeSlice)
193 {
194 GetGame().GetWorld().SetExplicitVolumeFactor_EnvSounds2D(m_EyeAcco, 0);
195 if (m_AmbientSound)
196 {
198 //Print(m_AmbientSound.GetSoundVolume());
199 }
200 else
201 m_Player.PlaySoundSetLoop(m_AmbientSound, "Underground_SoundSet", 3, 3);
202 }
203
204 void Tick(float timeSlice)
205 {
206 if (!m_Player.IsAlive())
207 return;
208
212
213#ifdef DIAG_DEVELOPER
214 if (DiagMenu.GetBool(DiagMenuIDs.UNDERGROUND_SHOW_BREADCRUMB))
215 DisplayDebugInfo(GetGame().GetWorld().GetEyeAccom(), m_LightingLerp);
216#endif
217
218 }
219
220 protected void ApplyEyeAcco()
221 {
222#ifdef DIAG_DEVELOPER
223 if (!DiagMenu.GetBool(DiagMenuIDs.UNDERGROUND_DISABLE_DARKENING))
224 GetRequester().SetEyeAccommodation(m_EyeAcco);
225 else
226 GetRequester().SetEyeAccommodation(1);
227#else
228 GetRequester().SetEyeAccommodation(m_EyeAcco);
229#endif
230
232 if (m_LightingLerp >= 1.0 || GetDayZGame().GetWorld().IsNight())
234 //m_NVRequester.SetUndergroundExposureCoef(undergrounNVExposureCoef);
236 }
237
238 protected void UpdateNVGRequester(float value)
239 {
240 m_NVRequester.SetUndergroundExposureCoef(value);
241 }
242
243 protected bool CalculateEyeAcco(float timeSlice)
244 {
245 if (m_TransitionalTrigger || !m_Player.m_UndergroundPresence || (m_EyeAccoTarget == 1))
246 {
250 if (Math.AbsFloat(accoDiff) < 0.01)
251 {
253 return true;
254 }
255 }
256 else
258 return false;
259 }
260
261
262 protected void OnTriggerInsiderUpdate()
263 {
267 m_EyeAccoTarget = 1;
269
270 foreach (auto t: m_InsideTriggers)
271 {
272 if (t.m_Type > bestType)
273 {
274 bestTrigger = t;
275 bestType = t.m_Type;
276 }
277 }
278 //Print(m_InsideTriggers.Count());
279 //Print(bestType);
280 if (bestTrigger)
281 {
282 if (bestTrigger.m_Type == EUndergroundTriggerType.TRANSITIONING)
284 m_EyeAccoTarget = bestTrigger.m_Accommodation;
285 if (bestTrigger.m_InterpolationSpeed != -1 && bestTrigger.m_InterpolationSpeed != 0)
286 m_AccoInterpolationSpeed = bestTrigger.m_InterpolationSpeed;
287 }
288
290 }
291
292
294 {
296 EUndergroundPresence oldPresence = m_Player.m_UndergroundPresence;
297
298 if (trigger)
299 {
300 if (trigger.m_Type == EUndergroundTriggerType.OUTER)
302 else if (trigger.m_Type == EUndergroundTriggerType.TRANSITIONING)
303 newPresence = EUndergroundPresence.TRANSITIONING;
304 else if (trigger.m_Type == EUndergroundTriggerType.INNER)
306 }
307
308 if (newPresence != oldPresence)//was there a change ?
309 {
311 m_Player.SetUnderground(newPresence);
312 }
313
314
315 }
316
317 protected void EnableLights(bool enable)
318 {
319 foreach (ScriptedLightBase light: ScriptedLightBase.m_NightTimeOnlyLights)
320 light.SetVisibleDuringDaylight(enable);
321 }
322
324
326 {
328 return;
329 float value01 = m_AnimTimerLightBlend.GetValue();
332
333 }
334
336 {
338 return;
339 float value01 = m_AnimTimerLightBlend.GetValue();
342 }
343
344
346 {
347 //Print("-----> On Undeground Presence update " + EnumTools.EnumToString(EUndergroundPresence, newPresence) + " " + EnumTools.EnumToString(EUndergroundPresence, oldPresence));
349 {
351 EnableLights(true);
353 {
354 GetGame().GetWeather().SuppressLightningSimulation(true);
355 m_Player.PlaySoundSetLoop(m_AmbientSound, "Underground_SoundSet", 3, 3);
356 }
358 {
360 m_AnimTimerLightBlend.Run(1, this, "OnUpdateTimerIn", "OnUpdateTimerEnd", 0, false, LIGHT_BLEND_SPEED_IN);
361 }
362 }
364 {
366 m_AnimTimerLightBlend.Run(0, this, "OnUpdateTimerOut", "OnUpdateTimerEnd", m_LightingLerp, false, LIGHT_BLEND_SPEED_OUT);
367 }
369 {
370 GetGame().GetWeather().SuppressLightningSimulation(false);
371 if (m_AmbientSound)
372 m_Player.StopSoundSet(m_AmbientSound);
373 }
375 {
376 GetGame().GetWorld().SetUserLightingLerp(0);
377 EnableLights(false);
378 }
379 }
380
381#ifdef DIAG_DEVELOPER
382 protected void DisplayDebugInfo(float acco, float lighting)
383 {
384 if (acco < 0.0001)
385 acco = 0;
386 DbgUI.Begin(String("Underground Areas"), 20, 20);
387 DbgUI.Text(String("Eye Accomodation: " + acco.ToString()));
388 DbgUI.Text(String("Lighting lerp: " + lighting.ToString()));
389 DbgUI.End();
390 }
391#endif
392}
DayZGame GetDayZGame()
Definition DayZGame.c:3530
PhxInteractionLayers
Definition DayZPhysics.c:2
DiagMenuIDs
Definition EDiagMenuIDs.c:2
DayZPlayer m_Player
Definition Hand_Events.c:42
void ProcessSound()
void Tick()
bool CalculateEyeAcco(float timeSlice)
void ApplyEyeAcco()
void UndergroundHandlerClient(PlayerBase player)
ref AnimationTimer m_AnimTimerLightBlend
const float DEFAULT_INTERPOLATION_SPEED
const float DISTANCE_CUTOFF
void OnTriggerLeave(UndergroundTrigger trigger)
UndergroundTrigger m_TransitionalTrigger
PPERUndergroundAcco m_Requester
void UpdateNVGRequester(float value)
const float ACCO_MODIFIER
void CalculateEyeAccoTarget()
ref set< UndergroundTrigger > m_InsideTriggers
enum EUndergroundPresence LIGHT_BLEND_SPEED_IN
PPERUndergroundAcco GetRequester()
EffectSound m_AmbientSound
void OnTriggerInsiderUpdate()
void OnUpdateTimerEnd()
const float RATIO_CUTOFF
float m_EyeAcco
void ProcessLighting(float timeSlice)
void EnableLights(bool enable)
float m_LightingLerpTarget
const float LIGHT_BLEND_SPEED_OUT
void ~UndergroundHandlerClient()
void OnUndergroundPresenceUpdate(EUndergroundPresence newPresence, EUndergroundPresence oldPresence)
float m_EyeAccoTarget
PPERequester_CameraNV m_NVRequester
float m_AccoInterpolationSpeed
void OnTriggerEnter(UndergroundTrigger trigger)
void OnUpdateTimerIn()
void OnUpdateTimerOut()
void ProcessEyeAcco(float timeSlice)
float m_LightingLerp
const string UNDERGROUND_LIGHTING
void SetUndergroundPresence(UndergroundTrigger trigger)
const float MAX_RATIO
AnimationTimer class. This timer is for animating float value. usage:
Definition tools.c:618
static proto bool RayCastBullet(vector begPos, vector endPos, PhxInteractionLayers layerMask, Object ignoreObj, out Object hitObject, out vector hitPosition, out vector hitNormal, out float hitFraction)
Definition DbgUI.c:60
Definition Debug.c:14
static Shape DrawSphere(vector pos, float size=1, int color=0x1fff7f7f, ShapeFlags flags=ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
Definition Debug.c:434
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Definition Debug.c:489
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition Easing.c:3
static float EaseInQuint(float t)
Definition Easing.c:78
static float EaseOutCubic(float t)
Definition Easing.c:42
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
void SetSoundVolume(float volume)
Set the RELATIVE volume for the sound.
override void Stop()
Stops sound.
Definition EnMath.c:7
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()
const int COLOR_RED
Definition constants.c:64
ShapeFlags
Definition EnDebug.c:126
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
static proto bool GetBool(int id, bool reverse=false)
Get value as bool from the given script id.
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition EnScript.c:338
static proto float AbsFloat(float f)
Returns absolute value.
int ARGB(int a, int r, int g, int b)
Definition proto.c:322