Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
worlddata.c
Go to the documentation of this file.
1
3{
4 const float SPAWN_CHANCE_CHOLERA_DEF = 50;
5 const float COLD_AREA_TOOL_DMG_MODIF_DEF = 1;
6
8 float m_TemperaturePerHeightReductionModifier;
9 float m_CloudsTemperatureEffectModifier;
10 float m_TemperatureInsideBuildingsModifier;
11 float m_WaterContactTemperatureModifier;
12
13 protected float SUDDENCHANGE_TIME_MULTIPLIER = 0.2;
14 protected float SUDDENCHANGE_LENGTH_MULTIPLIER = 0.4;
15 protected float WIND_MAGNITUDE_TIME_MULTIPLIER = 0.1;
16 protected float WIND_DIRECTION_TIME_MULTIPLIER = 0.05;
17
18 protected Weather m_Weather;
19 protected float m_EnvironmentTemperature;
20 protected bool m_EnTempUpdated;
21 protected float m_Timer;
22 protected float m_MaxTemps[12];
23 protected float m_MinTemps[12];
24 protected float m_Sunrise_Jan;
25 protected float m_Sunset_Jan;
26 protected float m_Sunrise_Jul;
27 protected float m_Sunset_Jul;
28 protected ref array<vector> m_FiringPos; // Where we should fire from. On Init set the relevant data
29 protected bool m_Pollution;
32 protected ref WorldDataLiquidSettings m_LiquidSettings;
34
36 protected int m_BadWeatherChance;
37 protected int m_ClearWeatherChance;
38 protected bool m_IsSuddenChange;
39 protected float m_WorldWindCoef;
40
42
43 //used at next weather calculation
44 protected int m_SameWeatherCnt = 0;
45 protected int m_StepValue = 5;
46 protected int m_Chance = 50;
47 protected int m_ChoosenWeather = 1;
48 protected int m_LastWeather = 0;
49
50 void WorldData()
51 {
52 Init();
56 }
57
58 void Init()
59 {
62
63 m_EnTempUpdated = false;
64 m_Weather = g_Game.GetWeather();
66 m_Timer = 0.0;
67 m_Sunrise_Jan = 8.54;
68 m_Sunset_Jan = 15.52;
69 m_Sunrise_Jul = 3.26;
70 m_Sunset_Jul = 20.73;
71 m_MaxTemps = {3,5,7,14,19,24,26,25,21,16,10,5};
72 m_MinTemps = {-3,-2,0,4,9,14,18,17,12,7,4,0};
73 m_Pollution = EPollution.NONE;
74 m_WorldWindCoef = 0.5;
75
77
78 m_TemperaturePerHeightReductionModifier = 0.02;
79 m_CloudsTemperatureEffectModifier = 3.0;
80 m_TemperatureInsideBuildingsModifier = 1.0;
81 m_WaterContactTemperatureModifier = 20.0;
82
85
87 }
88
89 float GetApproxSunriseTime( float monthday )
90 {
91 if ( monthday <= 8.0 )
92 return ( ( m_Sunrise_Jan - m_Sunrise_Jul ) / ( 8 - 1 ) ) * ( 1 - monthday ) + m_Sunrise_Jan;
93 else
94 return ( ( ( monthday - 8 ) * ( m_Sunrise_Jan - m_Sunrise_Jul ) ) / ( 13 - 8 ) ) + m_Sunrise_Jul;
95 }
96 float GetApproxSunsetTime( float monthday )
97 {
98 if ( monthday <= 8.0 )
99 return ( ( m_Sunset_Jan - m_Sunset_Jul ) / (8 - 1) ) * ( 1 - monthday ) + m_Sunset_Jan;
100 else
101 return ( ( ( monthday - 8 ) * ( m_Sunset_Jan - m_Sunset_Jul ) ) / ( 13 - 8 ) ) + m_Sunset_Jul;
102 }
103
105 {
106 int year, month, day, hour, minute;
107 GetGame().GetWorld().GetDate(year, month, day, hour, minute);
108
109 float sunriseTimeStart = g_Game.GetMission().GetWorldData().GetApproxSunriseTime(month);
110 float sunsetTimeStart = g_Game.GetMission().GetWorldData().GetApproxSunsetTime(month);
111
112 if (hour >= sunriseTimeStart && hour < (sunriseTimeStart + 2))
113 return WorldDataDaytime.DAWN;
114 else if (hour >= (sunriseTimeStart + 2) && hour < sunsetTimeStart)
115 return WorldDataDaytime.DAY;
116 else if (hour >= sunsetTimeStart && hour < (sunsetTimeStart + 2))
117 return WorldDataDaytime.DUSK;
118
119 return WorldDataDaytime.NIGHT;
120 }
121
122 protected float CalcBaseEnvironmentTemperature( float monthday, float daytime )
123 {
124 float approxSunrise = GetApproxSunriseTime( monthday );
125 float approxSunset = GetApproxSunsetTime( monthday );
126 float dayLight = approxSunset - approxSunrise;
127 float nightTime = 24.0 - dayLight;
128 int tempArrayIndex = Math.Floor(monthday) - 1;
129 int tempArrayIndexToLerp = tempArrayIndex + 1;
130 if ( tempArrayIndexToLerp >= 12 )
131 tempArrayIndexToLerp = 0;
132 float tempArrayLerp = monthday - Math.Floor(monthday);
133 float minTempA = m_MinTemps[tempArrayIndex];
134 float minTempB = m_MinTemps[tempArrayIndexToLerp];
135 float maxTempA = m_MaxTemps[tempArrayIndex];
136 float maxTempB = m_MaxTemps[tempArrayIndexToLerp];
137 float eveningMinA = minTempA + ( 0.5 * Math.AbsFloat( minTempA - maxTempA ) );
138 float eveningMinB = minTempB + ( 0.5 * Math.AbsFloat( minTempB - maxTempB ) );
139
140 if ( ( daytime >= approxSunrise ) && ( daytime <= approxSunset ) ) {
141 if ( daytime <= ( approxSunrise + ( dayLight * 0.75 ) ) )
142 return Math.Lerp(
143 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
144 Math.Lerp( maxTempA, maxTempB, tempArrayLerp ),
145 ( ( daytime - approxSunrise ) / ( dayLight * 0.75 ) ) );
146 else
147 return Math.Lerp(
148 Math.Lerp( maxTempA, maxTempB, tempArrayLerp ),
149 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
150 ( ( ( daytime - approxSunrise ) - ( dayLight * 0.75 ) ) / ( dayLight - ( dayLight * 0.75 ) ) ) );
151 } else {
152 if ( ( daytime > approxSunset ) && ( daytime < 24 ) )
153 return Math.Lerp(
154 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
155 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
156 ( ( daytime - approxSunset ) / ( 24 - approxSunset ) ) / 2.0 );
157 else
158 return Math.Lerp(
159 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
160 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
161 ( ( ( daytime + ( 24 - approxSunset ) ) / nightTime ) / 2.0 ) + 0.5 );
162 }
163 }
164 void UpdateBaseEnvTemperature(float timeslice)
165 {
166 m_Timer += timeslice;
167 if (m_Timer > 30 || !m_EnTempUpdated)
168 {
169 int year, month, day, hour, minute;
170 GetGame().GetWorld().GetDate( year, month, day, hour, minute );
171 m_EnvironmentTemperature = CalcBaseEnvironmentTemperature( month + ( day / 32.0 ), hour + ( minute / 60.0 ) );
172 m_Timer = 0;
173
174 if (!m_EnTempUpdated)
175 m_EnTempUpdated = true;
176 }
177 }
178
184 void UpdateWeatherEffects( Weather weather, float timeslice )
185 {
186 float snowflakeScale = ComputeSnowflakeScale( weather );
187 weather.SetSnowflakeScale( snowflakeScale );
188 }
189
195 {
196 float overcast01 = Math.Clamp( Math.InverseLerp( 0.4, 1.0, weather.GetOvercast().GetActual() ), 0.0, 1.0 ); // remap range to <0.4, 1.0> snowfall overcast threshold
197 float wind01 = weather.GetWindSpeed() / weather.GetWindMaximumSpeed();
198
199 float overcastScale = Math.Lerp( 0.50, 1.25, overcast01 );
200 float windScale = Math.Lerp( 1.25, 1.00, wind01 );
201
202 return Math.Clamp( overcastScale * windScale, 0.50, 1.25 );
203 }
204
205 // getter for the new base enviro temperature
207 {
209 }
210
212 {
214 }
215
217 {
218 float terrainHeight = pos[1];
219 float heightCorrection = Math.Max(0, (terrainHeight * m_TemperaturePerHeightReductionModifier));
220 return m_EnvironmentTemperature - heightCorrection;
221 }
222
223 float GetBaseEnvTemperatureExact(int month, int day, int hour, int minute)
224 {
225 return CalcBaseEnvironmentTemperature( month + ( day / 32.0 ), hour + ( minute / 60.0 ) );
226 }
227
228 float GetLiquidTypeEnviroTemperature(int liquidType)
229 {
230 if (m_LiquidSettings.m_Temperatures.Count() > 0 && m_LiquidSettings.m_Temperatures.Contains(liquidType) != INDEX_NOT_FOUND)
231 return m_LiquidSettings.m_Temperatures.Get(liquidType);
232
233 #ifdef DEVELOPER
234 ErrorEx("Undefined enviro temperature for liquid type: " + liquidType);
235 #endif
236
238 }
239
240 bool WeatherOnBeforeChange( EWeatherPhenomenon type, float actual, float change, float time )
241 {
242 // default behaviour is same like setting MissionWeather (in Weather) to true
243 return false;
244 }
245
246 // Used to return the artillery firing positions
248 {
249 return m_FiringPos;
250 }
251
252 // Returns chance percentage for selected agent to spawn, used with spawned loot
254 {
255 if (agent == eAgents.CHOLERA)
256 return SPAWN_CHANCE_CHOLERA_DEF;
257
258 return 0;
259 }
260
261 // Returns modifier which is added to the tool damage logic when player is in cold area
263 {
264 return COLD_AREA_TOOL_DMG_MODIF_DEF;
265 }
266
267 // debug
268 void BaseTempDebug(int month, int day)
269 {
270 Print("--------------------");
271 for ( int i = 0; i < 24; i++ )
272 {
273 for ( int j = 0; j < 6; j++ )
274 {
275 int minute = ( j * 10 );
276 Print(string.Format( "%1:%2 %3", i, minute, GetBaseEnvTemperatureExact( month, day, i, minute ) ) );
277 }
278 }
279 }
280
282 {
283 return m_Pollution;
284 }
285
287 {
288 return m_WorldWindCoef;
289 }
290
295
302 {
303 // EEnvironmentTemperatureComponent.BASE only
304 float temperature = GetBaseEnvTemperature();
305
306 if (object && properties & EEnvironmentTemperatureComponent.ALTITUDE)
307 temperature = GetBaseEnvTemperatureAtObject(object);
308
309 if (properties & EEnvironmentTemperatureComponent.OVERCAST)
310 temperature += m_Weather.GetOvercast().GetActual() * m_CloudsTemperatureEffectModifier;
311
312 if (properties & EEnvironmentTemperatureComponent.WIND)
313 temperature += WindEffectTemperatureValue(temperature);
314
315 if (properties & EEnvironmentTemperatureComponent.FOG)
316 temperature += m_Weather.GetFog().GetActual() * GameConstants.ENVIRO_FOG_TEMP_EFFECT;
317
318 return temperature;
319 }
320
326 float GetTemperatureComponentValue(float temperatureIn, EEnvironmentTemperatureComponent properties = 0)
327 {
328 float temperatureOut = 0.0;
329
330 if ((properties & EEnvironmentTemperatureComponent.OVERCAST) == EEnvironmentTemperatureComponent.OVERCAST)
331 temperatureOut = m_Weather.GetOvercast().GetActual() * m_CloudsTemperatureEffectModifier;
332 else if ((properties & EEnvironmentTemperatureComponent.WIND) == EEnvironmentTemperatureComponent.WIND)
333 temperatureOut = WindEffectTemperatureValue(temperatureIn);
335 temperatureOut = m_Weather.GetFog().GetActual() * GameConstants.ENVIRO_FOG_TEMP_EFFECT;
336 else
337 {
338 Debug.Log(string.Format("Only OVERCAST, WIND and FOG parameters are supported"));
339 }
340
341 return temperatureOut;
342 }
343
344 protected float WindEffectTemperatureValue(float temperatureInput)
345 {
346 float temperatureOutput = 0.0;
347
348 temperatureOutput = (temperatureInput - GameConstants.ENVIRO_WIND_CHILL_LIMIT) / (GameConstants.ENVIRO_WIND_EFFECT_SLOPE - GameConstants.ENVIRO_WIND_CHILL_LIMIT);
349 temperatureOutput = temperatureOutput * m_Weather.GetWindMagnitude().GetActual() * GetWindCoef();
350
351 return -temperatureOutput;
352 }
353
354 protected void CalculateWind(int newWeather, bool suddenChange, out float magnitude, out float direction);
355
356 protected void CalculateVolFog(float lerpValue, float windMagnitude, float changeTime);
357
358 protected void CreateYieldBank()
359 {
361 }
362
364 protected void InitYieldBank()
365 {
366 GetDayZGame().GetYieldDataInitInvoker().Invoke(m_YieldBank); //injects defaults from 4_World and above
367 }
368
373
374 protected void SetupLiquidTemperatures()
375 {
376 m_LiquidSettings = new WorldDataLiquidSettings();
377
378 m_LiquidSettings.m_Temperatures[LIQUID_SALTWATER] = 23.0;
379 m_LiquidSettings.m_Temperatures[LIQUID_WATER] = 15.0;
380 m_LiquidSettings.m_Temperatures[LIQUID_STILLWATER] = 15.0;
381 m_LiquidSettings.m_Temperatures[LIQUID_RIVERWATER] = 15.0;
382 m_LiquidSettings.m_Temperatures[LIQUID_FRESHWATER] = 15.0;
383 m_LiquidSettings.m_Temperatures[LIQUID_CLEANWATER] = 10.0;
384 m_LiquidSettings.m_Temperatures[LIQUID_SNOW] = -5.0;
385 }
386
391
396
397
401
402 protected float m_DayTemperature = 10; // legacy, no longer used
403 protected float m_NightTemperature = 6; // legacy, no longer used
404
406 {
407 return m_DayTemperature;
408 }
409
411 {
412 return m_NightTemperature;
413 }
414}
415
416class WorldDataWeatherConstants
417{
418 const int CLEAR_WEATHER = 1;
419 const int CLOUDY_WEATHER = 2;
420 const int BAD_WEATHER = 3;
421}
422
424{
425 int m_OvercastMinTime = 600;
426 int m_OvercastMaxTime = 900;
427 int m_OvercastMinLength = 600;
428 int m_OvercastMaxLength = 900;
429
430 float m_RainThreshold = 0.6;
431 int m_RainTimeMin = 60;
432 int m_RainTimeMax = 120;
433 int m_RainLengthMin = 60;
434 int m_RainLengthMax = 120;
435
436 float m_StormThreshold = 0.85;
437 float m_ThundersnowThreshold = 0.98;
438
439 float m_SnowfallThreshold = 0.3;
440 int m_SnowfallTimeMin = 60;
441 int m_SnowfallTimeMax = 120;
442 int m_SnowfallLengthMin = 150;
443 int m_SnowfallLengthMax = 300;
444
445 int m_GlobalSuddenChance = 95;
446 int m_ClearWeatherChance = 30;
447 int m_BadWeatherChance = 80;
448 int m_BadWeatherSuddenChance = 95;
449
450 int m_FoggyMorningHeigthBiasLowLimit = 155;
451 int m_DefaultHeigthBias = 170;
452
453 int m_CalmAfterStormTimeMin = 480;
454 int m_CalmAfterStormTimeMax = 600;
455}
456
457class WorldDataLiquidSettings
458{
460}
461
463{
464 static int ANY = -1;
465 static int NIGHT = 0;
466 static int DAY = 1;
467 static int DUSK = 2;
468 static int DAWN = 3;
469
470 static string ToString(int value)
471 {
472 switch (value)
473 {
474 case NIGHT:
475 return "NIGHT";
476 case DAY:
477 return "DAY";
478 case DUSK:
479 return "DUSK";
480 case DAWN:
481 return "DAWN";
482 }
483
484 return "ANYTIME";
485 }
486}
#define LIQUID_RIVERWATER
#define LIQUID_FRESHWATER
#define LIQUID_SNOW
#define LIQUID_WATER
#define LIQUID_SALTWATER
#define LIQUID_CLEANWATER
#define LIQUID_STILLWATER
Definition debug.c:2
Definition enmath.c:7
Keeps information about currently loaded world, like temperature.
Definition worlddata.c:3
float GetAgentSpawnChance(eAgents agent)
Definition worlddata.c:253
float GetApproxSunriseTime(float monthday)
Definition worlddata.c:89
void Init()
Definition worlddata.c:58
float ComputeSnowflakeScale(Weather weather)
Returns the desired snowflake scale based on weather simulation state.
Definition worlddata.c:194
float SUDDENCHANGE_TIME_MULTIPLIER
Definition worlddata.c:13
float m_Timer
Definition worlddata.c:21
float GetTemperature(Object object, EEnvironmentTemperatureComponent properties=EEnvironmentTemperatureComponent.BASE)
Return actual temperature of environment based on provided parameters.
Definition worlddata.c:301
void UpdateBaseEnvTemperature(float timeslice)
Definition worlddata.c:164
void CalculateWind(int newWeather, bool suddenChange, out float magnitude, out float direction)
float SUDDENCHANGE_LENGTH_MULTIPLIER
Definition worlddata.c:14
ref WorldDataLiquidSettings m_LiquidSettings
Definition worlddata.c:32
bool m_Pollution
Definition worlddata.c:29
float GetNightTemperature()
Definition worlddata.c:410
float WIND_DIRECTION_TIME_MULTIPLIER
Definition worlddata.c:16
CatchYieldBank GetCatchYieldBank()
Definition worlddata.c:387
void CreateYieldBank()
Definition worlddata.c:358
float m_Sunset_Jan
Definition worlddata.c:25
float GetBaseEnvTemperature()
Definition worlddata.c:206
float m_WorldWindCoef
Definition worlddata.c:39
float m_Sunrise_Jan
Definition worlddata.c:24
float GetBaseEnvTemperatureAtObject(notnull Object object)
Definition worlddata.c:211
float GetDayTemperature()
Definition worlddata.c:405
float m_DayTemperature
Definition worlddata.c:402
int m_ClearWeatherChance
Definition worlddata.c:37
float GetBaseEnvTemperatureAtPosition(vector pos)
Definition worlddata.c:216
int GetPollution()
Definition worlddata.c:281
bool WeatherOnBeforeChange(EWeatherPhenomenon type, float actual, float change, float time)
Definition worlddata.c:240
ref WorldDataWeatherSettings m_WeatherDefaultSettings
Definition worlddata.c:31
float GetApproxSunsetTime(float monthday)
Definition worlddata.c:96
void WorldData()
Definition worlddata.c:50
array< vector > GetArtyFiringPos()
Definition worlddata.c:247
ref array< vector > m_FiringPos
Definition worlddata.c:28
TStringArray GetDefaultPRAPaths()
Definition worlddata.c:392
void UpdateWeatherEffects(Weather weather, float timeslice)
Updates local weather effects.
Definition worlddata.c:184
ref CatchYieldBank m_YieldBank
Definition worlddata.c:30
int m_Chance
Definition worlddata.c:46
float GetBaseEnvTemperatureExact(int month, int day, int hour, int minute)
Definition worlddata.c:223
int m_LastWeather
Definition worlddata.c:48
float GetWindCoef()
Definition worlddata.c:286
float m_MaxTemps[12]
Definition worlddata.c:22
void CalculateVolFog(float lerpValue, float windMagnitude, float changeTime)
int m_SameWeatherCnt
Definition worlddata.c:44
void BaseTempDebug(int month, int day)
Definition worlddata.c:268
float m_MinTemps[12]
Definition worlddata.c:23
ref TStringArray m_DefaultPlayerRestrictedAreas
Definition worlddata.c:33
float GetUniversalTemperatureSourceCapModifier()
Definition worlddata.c:291
int m_BadWeatherChance
weather related
Definition worlddata.c:36
int m_StepValue
Definition worlddata.c:45
float GetColdAreaToolDamageModifier()
Definition worlddata.c:262
float WIND_MAGNITUDE_TIME_MULTIPLIER
Definition worlddata.c:15
bool m_IsSuddenChange
Definition worlddata.c:38
float m_EnvironmentTemperature
Definition worlddata.c:19
float m_NightTemperature
Definition worlddata.c:403
void SetupWeatherSettings()
Definition worlddata.c:369
bool m_EnTempUpdated
Definition worlddata.c:20
float m_UniversalTemperatureSourceCapModifier
Definition worlddata.c:41
float GetLiquidTypeEnviroTemperature(int liquidType)
Definition worlddata.c:228
void SetupLiquidTemperatures()
Definition worlddata.c:374
Weather m_Weather
Definition worlddata.c:18
float GetTemperatureComponentValue(float temperatureIn, EEnvironmentTemperatureComponent properties=0)
Return value of queried EEnvironmentTemperatureComponent which can be used in future calculation(s)
Definition worlddata.c:326
int GetDaytime()
Definition worlddata.c:104
void InitYieldBank()
override this to properly register world-specific yields
Definition worlddata.c:364
float CalcBaseEnvironmentTemperature(float monthday, float daytime)
Definition worlddata.c:122
float m_Sunset_Jul
Definition worlddata.c:27
int m_ChoosenWeather
Definition worlddata.c:47
float m_Sunrise_Jul
Definition worlddata.c:26
float WindEffectTemperatureValue(float temperatureInput)
Definition worlddata.c:344
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3868
DayZGame GetDayZGame()
Definition dayzgame.c:3870
eAgents
Definition eagents.c:3
proto string ToString()
const int INDEX_NOT_FOUND
Definition gameplay.c:13
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
enum ShapeType ErrorEx
class JsonUndergroundAreaTriggerData GetPosition
EWeatherPhenomenon
Definition weather.c:11
class WorldDataWeatherSettings m_Temperatures
const int BAD_WEATHER
Definition worlddata.c:420
class WorldData CLEAR_WEATHER
const int CLOUDY_WEATHER
Definition worlddata.c:419