Dayz Explorer 1.29.162510
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 g_Game.GetWorld().GetDate(year, month, day, hour, minute);
108
109 WorldData worldData = g_Game.GetMission().GetWorldData();
110 float sunriseTimeStart = worldData.GetApproxSunriseTime(month);
111 float sunsetTimeStart = worldData.GetApproxSunsetTime(month);
112
113 if (hour >= sunriseTimeStart && hour < (sunriseTimeStart + 2))
114 return WorldDataDaytime.DAWN;
115 else if (hour >= (sunriseTimeStart + 2) && hour < sunsetTimeStart)
116 return WorldDataDaytime.DAY;
117 else if (hour >= sunsetTimeStart && hour < (sunsetTimeStart + 2))
118 return WorldDataDaytime.DUSK;
119
120 return WorldDataDaytime.NIGHT;
121 }
122
123 protected float CalcBaseEnvironmentTemperature( float monthday, float daytime )
124 {
125 float approxSunrise = GetApproxSunriseTime( monthday );
126 float approxSunset = GetApproxSunsetTime( monthday );
127 float dayLight = approxSunset - approxSunrise;
128 float nightTime = 24.0 - dayLight;
129 int tempArrayIndex = Math.Floor(monthday) - 1;
130 int tempArrayIndexToLerp = tempArrayIndex + 1;
131 if ( tempArrayIndexToLerp >= 12 )
132 tempArrayIndexToLerp = 0;
133 float tempArrayLerp = monthday - Math.Floor(monthday);
134 float minTempA = m_MinTemps[tempArrayIndex];
135 float minTempB = m_MinTemps[tempArrayIndexToLerp];
136 float maxTempA = m_MaxTemps[tempArrayIndex];
137 float maxTempB = m_MaxTemps[tempArrayIndexToLerp];
138 float eveningMinA = minTempA + ( 0.5 * Math.AbsFloat( minTempA - maxTempA ) );
139 float eveningMinB = minTempB + ( 0.5 * Math.AbsFloat( minTempB - maxTempB ) );
140
141 if ( ( daytime >= approxSunrise ) && ( daytime <= approxSunset ) ) {
142 if ( daytime <= ( approxSunrise + ( dayLight * 0.75 ) ) )
143 return Math.Lerp(
144 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
145 Math.Lerp( maxTempA, maxTempB, tempArrayLerp ),
146 ( ( daytime - approxSunrise ) / ( dayLight * 0.75 ) ) );
147 else
148 return Math.Lerp(
149 Math.Lerp( maxTempA, maxTempB, tempArrayLerp ),
150 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
151 ( ( ( daytime - approxSunrise ) - ( dayLight * 0.75 ) ) / ( dayLight - ( dayLight * 0.75 ) ) ) );
152 } else {
153 if ( ( daytime > approxSunset ) && ( daytime < 24 ) )
154 return Math.Lerp(
155 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
156 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
157 ( ( daytime - approxSunset ) / ( 24 - approxSunset ) ) / 2.0 );
158 else
159 return Math.Lerp(
160 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
161 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
162 ( ( ( daytime + ( 24 - approxSunset ) ) / nightTime ) / 2.0 ) + 0.5 );
163 }
164 }
165 void UpdateBaseEnvTemperature(float timeslice)
166 {
167 m_Timer += timeslice;
168 if (m_Timer > 30 || !m_EnTempUpdated)
169 {
170 int year, month, day, hour, minute;
171 g_Game.GetWorld().GetDate( year, month, day, hour, minute );
172 m_EnvironmentTemperature = CalcBaseEnvironmentTemperature( month + ( day / 32.0 ), hour + ( minute / 60.0 ) );
173 m_Timer = 0;
174
175 if (!m_EnTempUpdated)
176 m_EnTempUpdated = true;
177 }
178 }
179
185 void UpdateWeatherEffects( Weather weather, float timeslice )
186 {
187 float snowflakeScale = ComputeSnowflakeScale( weather );
188 weather.SetSnowflakeScale( snowflakeScale );
189 }
190
196 {
197 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
198 float wind01 = weather.GetWindSpeed() / weather.GetWindMaximumSpeed();
199
200 float overcastScale = Math.Lerp( 0.50, 1.25, overcast01 );
201 float windScale = Math.Lerp( 1.25, 1.00, wind01 );
202
203 return Math.Clamp( overcastScale * windScale, 0.50, 1.25 );
204 }
205
206 // getter for the new base enviro temperature
208 {
210 }
211
213 {
215 }
216
218 {
219 float terrainHeight = pos[1];
220 float heightCorrection = Math.Max(0, (terrainHeight * m_TemperaturePerHeightReductionModifier));
221 return m_EnvironmentTemperature - heightCorrection;
222 }
223
224 float GetBaseEnvTemperatureExact(int month, int day, int hour, int minute)
225 {
226 return CalcBaseEnvironmentTemperature( month + ( day / 32.0 ), hour + ( minute / 60.0 ) );
227 }
228
229 float GetLiquidTypeEnviroTemperature(int liquidType)
230 {
231 if (m_LiquidSettings.m_Temperatures.Count() > 0 && m_LiquidSettings.m_Temperatures.Contains(liquidType) != INDEX_NOT_FOUND)
232 return m_LiquidSettings.m_Temperatures.Get(liquidType);
233
234 #ifdef DEVELOPER
235 ErrorEx("Undefined enviro temperature for liquid type: " + liquidType);
236 #endif
237
239 }
240
241 bool WeatherOnBeforeChange( EWeatherPhenomenon type, float actual, float change, float time )
242 {
243 // default behaviour is same like setting MissionWeather (in Weather) to true
244 return false;
245 }
246
247 // Used to return the artillery firing positions
249 {
250 return m_FiringPos;
251 }
252
253 // Returns chance percentage for selected agent to spawn, used with spawned loot
255 {
256 if (agent == eAgents.CHOLERA)
257 return SPAWN_CHANCE_CHOLERA_DEF;
258
259 return 0;
260 }
261
262 // Returns modifier which is added to the tool damage logic when player is in cold area
264 {
265 return COLD_AREA_TOOL_DMG_MODIF_DEF;
266 }
267
268 // debug
269 void BaseTempDebug(int month, int day)
270 {
271 Print("--------------------");
272 for ( int i = 0; i < 24; i++ )
273 {
274 for ( int j = 0; j < 6; j++ )
275 {
276 int minute = ( j * 10 );
277 Print(string.Format( "%1:%2 %3", i, minute, GetBaseEnvTemperatureExact( month, day, i, minute ) ) );
278 }
279 }
280 }
281
283 {
284 return m_Pollution;
285 }
286
288 {
289 return m_WorldWindCoef;
290 }
291
296
303 {
304 // EEnvironmentTemperatureComponent.BASE only
305 float temperature = GetBaseEnvTemperature();
306
307 if (object && properties & EEnvironmentTemperatureComponent.ALTITUDE)
308 temperature = GetBaseEnvTemperatureAtObject(object);
309
310 if (properties & EEnvironmentTemperatureComponent.OVERCAST)
311 temperature += m_Weather.GetOvercast().GetActual() * m_CloudsTemperatureEffectModifier;
312
313 if (properties & EEnvironmentTemperatureComponent.WIND)
314 temperature += WindEffectTemperatureValue(temperature);
315
316 if (properties & EEnvironmentTemperatureComponent.FOG)
317 temperature += m_Weather.GetFog().GetActual() * GameConstants.ENVIRO_FOG_TEMP_EFFECT;
318
319 return temperature;
320 }
321
327 float GetTemperatureComponentValue(float temperatureIn, EEnvironmentTemperatureComponent properties = 0)
328 {
329 float temperatureOut = 0.0;
330
331 if ((properties & EEnvironmentTemperatureComponent.OVERCAST) == EEnvironmentTemperatureComponent.OVERCAST)
332 temperatureOut = m_Weather.GetOvercast().GetActual() * m_CloudsTemperatureEffectModifier;
333 else if ((properties & EEnvironmentTemperatureComponent.WIND) == EEnvironmentTemperatureComponent.WIND)
334 temperatureOut = WindEffectTemperatureValue(temperatureIn);
336 temperatureOut = m_Weather.GetFog().GetActual() * GameConstants.ENVIRO_FOG_TEMP_EFFECT;
337 else
338 {
339 Debug.Log(string.Format("Only OVERCAST, WIND and FOG parameters are supported"));
340 }
341
342 return temperatureOut;
343 }
344
345 protected float WindEffectTemperatureValue(float temperatureInput)
346 {
347 float temperatureOutput = 0.0;
348
349 temperatureOutput = (temperatureInput - GameConstants.ENVIRO_WIND_CHILL_LIMIT) / (GameConstants.ENVIRO_WIND_EFFECT_SLOPE - GameConstants.ENVIRO_WIND_CHILL_LIMIT);
350 temperatureOutput = temperatureOutput * m_Weather.GetWindMagnitude().GetActual() * GetWindCoef();
351
352 return -temperatureOutput;
353 }
354
355 protected void CalculateWind(int newWeather, bool suddenChange, out float magnitude, out float direction);
356
357 protected void CalculateVolFog(float lerpValue, float windMagnitude, float changeTime);
358
359 protected void CreateYieldBank()
360 {
362 }
363
365 protected void InitYieldBank()
366 {
367 GetDayZGame().GetYieldDataInitInvoker().Invoke(m_YieldBank); //injects defaults from 4_World and above
368 }
369
374
375 protected void SetupLiquidTemperatures()
376 {
377 m_LiquidSettings = new WorldDataLiquidSettings();
378
379 m_LiquidSettings.m_Temperatures[LIQUID_SALTWATER] = 23.0;
380 m_LiquidSettings.m_Temperatures[LIQUID_WATER] = 15.0;
381 m_LiquidSettings.m_Temperatures[LIQUID_STILLWATER] = 15.0;
382 m_LiquidSettings.m_Temperatures[LIQUID_RIVERWATER] = 15.0;
383 m_LiquidSettings.m_Temperatures[LIQUID_FRESHWATER] = 15.0;
384 m_LiquidSettings.m_Temperatures[LIQUID_CLEANWATER] = 10.0;
385 m_LiquidSettings.m_Temperatures[LIQUID_SNOW] = -5.0;
386 }
387
392
397
398
402
403 protected float m_DayTemperature = 10; // legacy, no longer used
404 protected float m_NightTemperature = 6; // legacy, no longer used
405
407 {
408 return m_DayTemperature;
409 }
410
412 {
413 return m_NightTemperature;
414 }
415}
416
417class WorldDataWeatherConstants
418{
419 const int CLEAR_WEATHER = 1;
420 const int CLOUDY_WEATHER = 2;
421 const int BAD_WEATHER = 3;
422}
423
425{
426 int m_OvercastMinTime = 600;
427 int m_OvercastMaxTime = 900;
428 int m_OvercastMinLength = 600;
429 int m_OvercastMaxLength = 900;
430
431 float m_RainThreshold = 0.6;
432 int m_RainTimeMin = 60;
433 int m_RainTimeMax = 120;
434 int m_RainLengthMin = 60;
435 int m_RainLengthMax = 120;
436
437 float m_StormThreshold = 0.85;
438 float m_ThundersnowThreshold = 0.98;
439
440 float m_SnowfallThreshold = 0.3;
441 int m_SnowfallTimeMin = 60;
442 int m_SnowfallTimeMax = 120;
443 int m_SnowfallLengthMin = 150;
444 int m_SnowfallLengthMax = 300;
445
446 int m_GlobalSuddenChance = 95;
447 int m_ClearWeatherChance = 30;
448 int m_BadWeatherChance = 80;
449 int m_BadWeatherSuddenChance = 95;
450
451 int m_FoggyMorningHeigthBiasLowLimit = 155;
452 int m_DefaultHeigthBias = 170;
453
454 int m_CalmAfterStormTimeMin = 480;
455 int m_CalmAfterStormTimeMax = 600;
456}
457
458class WorldDataLiquidSettings
459{
461}
462
464{
465 static int ANY = -1;
466 static int NIGHT = 0;
467 static int DAY = 1;
468 static int DUSK = 2;
469 static int DAWN = 3;
470
471 static string ToString(int value)
472 {
473 switch (value)
474 {
475 case NIGHT:
476 return "NIGHT";
477 case DAY:
478 return "DAY";
479 case DUSK:
480 return "DUSK";
481 case DAWN:
482 return "DAWN";
483 }
484
485 return "ANYTIME";
486 }
487}
#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
float GetAgentSpawnChance(eAgents agent)
Definition worlddata.c:254
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:195
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:302
void UpdateBaseEnvTemperature(float timeslice)
Definition worlddata.c:165
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:411
float WIND_DIRECTION_TIME_MULTIPLIER
Definition worlddata.c:16
CatchYieldBank GetCatchYieldBank()
Definition worlddata.c:388
void CreateYieldBank()
Definition worlddata.c:359
float m_Sunset_Jan
Definition worlddata.c:25
float GetBaseEnvTemperature()
Definition worlddata.c:207
float m_WorldWindCoef
Definition worlddata.c:39
float m_Sunrise_Jan
Definition worlddata.c:24
float GetBaseEnvTemperatureAtObject(notnull Object object)
Definition worlddata.c:212
float GetDayTemperature()
Definition worlddata.c:406
float m_DayTemperature
Definition worlddata.c:403
int m_ClearWeatherChance
Definition worlddata.c:37
float GetBaseEnvTemperatureAtPosition(vector pos)
Definition worlddata.c:217
int GetPollution()
Definition worlddata.c:282
bool WeatherOnBeforeChange(EWeatherPhenomenon type, float actual, float change, float time)
Definition worlddata.c:241
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:248
ref array< vector > m_FiringPos
Definition worlddata.c:28
TStringArray GetDefaultPRAPaths()
Definition worlddata.c:393
void UpdateWeatherEffects(Weather weather, float timeslice)
Updates local weather effects.
Definition worlddata.c:185
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:224
int m_LastWeather
Definition worlddata.c:48
float GetWindCoef()
Definition worlddata.c:287
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:269
float m_MinTemps[12]
Definition worlddata.c:23
ref TStringArray m_DefaultPlayerRestrictedAreas
Definition worlddata.c:33
float GetUniversalTemperatureSourceCapModifier()
Definition worlddata.c:292
int m_BadWeatherChance
weather related
Definition worlddata.c:36
int m_StepValue
Definition worlddata.c:45
float GetColdAreaToolDamageModifier()
Definition worlddata.c:263
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:404
void SetupWeatherSettings()
Definition worlddata.c:370
bool m_EnTempUpdated
Definition worlddata.c:20
float m_UniversalTemperatureSourceCapModifier
Definition worlddata.c:41
float GetLiquidTypeEnviroTemperature(int liquidType)
Definition worlddata.c:229
void SetupLiquidTemperatures()
Definition worlddata.c:375
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:327
int GetDaytime()
Definition worlddata.c:104
void InitYieldBank()
override this to properly register world-specific yields
Definition worlddata.c:365
float CalcBaseEnvironmentTemperature(float monthday, float daytime)
Definition worlddata.c:123
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:345
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
DayZGame GetDayZGame()
Definition dayzgame.c:3944
eAgents
Definition eagents.c:3
proto string ToString()
const int INDEX_NOT_FOUND
Definition gameplay.c:13
proto void Print(void var)
Prints content of variable to console/log.
enum ShapeType ErrorEx
array< string > TStringArray
Definition enscript.c:712
vector GetPosition()
Get the world position of the Effect.
Definition effect.c:473
EWeatherPhenomenon
Definition weather.c:11
class WorldDataWeatherSettings m_Temperatures
const int BAD_WEATHER
Definition worlddata.c:421
class WorldData CLEAR_WEATHER
const int CLOUDY_WEATHER
Definition worlddata.c:420