Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
worlddata.c
Go to the documentation of this file.
1
3{
4 const float SPAWN_CHANCE_CHOLERA_DEF = 50;
6
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
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)
258
259 return 0;
260 }
261
262 // Returns modifier which is added to the tool damage logic when player is in cold area
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
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
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}
Definition debug.c:2
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition debug.c:182
Definition enmath.c:7
Weather controller.
Definition weather.c:168
proto native float GetWindMaximumSpeed()
Returns maximal wind speed in metre per second.
proto native void SetSnowflakeScale(float scale)
Sets the overall scale of snowflakes during snowfall phenomenon.
proto native Overcast GetOvercast()
Returns an overcast phenomenon object.
proto native float GetWindSpeed()
Returns actual wind speed in metre per second.
proto native float GetActual()
Returns actual value of phenomenon in range <0, 1>. (does not apply for Wind, which always returns th...
static int NIGHT
Definition worlddata.c:466
static int ANY
Definition worlddata.c:465
static int DAY
Definition worlddata.c:467
static int DAWN
Definition worlddata.c:469
static int DUSK
Definition worlddata.c:468
static string ToString(int value)
Definition worlddata.c:471
float GetNightTemperature()
Definition worlddata.c:411
float GetBaseEnvTemperatureExact(int month, int day, int hour, int minute)
Definition worlddata.c:224
float m_Sunrise_Jan
Definition worlddata.c:24
float GetApproxSunsetTime(float monthday)
Definition worlddata.c:96
int m_ClearWeatherChance
Definition worlddata.c:37
void SetupLiquidTemperatures()
Definition worlddata.c:375
float GetLiquidTypeEnviroTemperature(int liquidType)
Definition worlddata.c:229
float m_MaxTemps[12]
Definition worlddata.c:22
int m_LastWeather
Definition worlddata.c:48
float CalcBaseEnvironmentTemperature(float monthday, float daytime)
Definition worlddata.c:123
float GetApproxSunriseTime(float monthday)
Definition worlddata.c:89
float m_Sunrise_Jul
Definition worlddata.c:26
void Init()
Definition worlddata.c:58
int GetPollution()
Definition worlddata.c:282
float m_UniversalTemperatureSourceCapModifier
Definition worlddata.c:41
float SUDDENCHANGE_TIME_MULTIPLIER
Definition worlddata.c:13
bool WeatherOnBeforeChange(EWeatherPhenomenon type, float actual, float change, float time)
Definition worlddata.c:241
float GetTemperature(Object object, EEnvironmentTemperatureComponent properties=EEnvironmentTemperatureComponent.BASE)
Return actual temperature of environment based on provided parameters.
Definition worlddata.c:302
float GetBaseEnvTemperatureAtObject(notnull Object object)
Definition worlddata.c:212
float m_EnvironmentTemperature
Definition worlddata.c:19
bool m_Pollution
Definition worlddata.c:29
void CreateYieldBank()
Definition worlddata.c:359
void UpdateWeatherEffects(Weather weather, float timeslice)
Updates local weather effects.
Definition worlddata.c:185
int m_ChoosenWeather
Definition worlddata.c:47
float GetDayTemperature()
Definition worlddata.c:406
float m_CloudsTemperatureEffectModifier
amount of °C reduced for each 100 meteres of height above water level
Definition worlddata.c:9
const float SPAWN_CHANCE_CHOLERA_DEF
Definition worlddata.c:4
void BaseTempDebug(int month, int day)
Definition worlddata.c:269
void UpdateBaseEnvTemperature(float timeslice)
Definition worlddata.c:165
void CalculateVolFog(float lerpValue, float windMagnitude, float changeTime)
float GetBaseEnvTemperature()
Definition worlddata.c:207
float WindEffectTemperatureValue(float temperatureInput)
Definition worlddata.c:345
float m_Sunset_Jul
Definition worlddata.c:27
int m_BadWeatherChance
weather related
Definition worlddata.c:36
float m_TemperatureInsideBuildingsModifier
how many % of environment temperature can be lowered by clouds
Definition worlddata.c:10
float WIND_MAGNITUDE_TIME_MULTIPLIER
Definition worlddata.c:15
void WorldData()
Definition worlddata.c:50
float GetBaseEnvTemperatureAtPosition(vector pos)
Definition worlddata.c:217
int m_StepValue
Definition worlddata.c:45
float m_Timer
Definition worlddata.c:21
int m_Chance
Definition worlddata.c:46
float GetTemperatureComponentValue(float temperatureIn, EEnvironmentTemperatureComponent properties=0)
Return value of queried EEnvironmentTemperatureComponent which can be used in future calculation(s).
Definition worlddata.c:327
float WIND_DIRECTION_TIME_MULTIPLIER
Definition worlddata.c:16
float GetUniversalTemperatureSourceCapModifier()
Definition worlddata.c:292
void InitYieldBank()
override this to properly register world-specific yields
Definition worlddata.c:365
ref WorldDataLiquidSettings m_LiquidSettings
Definition worlddata.c:32
CatchYieldBank GetCatchYieldBank()
Definition worlddata.c:388
float GetColdAreaToolDamageModifier()
Definition worlddata.c:263
float m_NightTemperature
Definition worlddata.c:404
float m_TemperaturePerHeightReductionModifier
directly accesible (defined/overriden in Init())
Definition worlddata.c:8
ref WorldDataWeatherSettings m_WeatherDefaultSettings
Definition worlddata.c:31
float m_Sunset_Jan
Definition worlddata.c:25
Weather m_Weather
Definition worlddata.c:18
const float COLD_AREA_TOOL_DMG_MODIF_DEF
Definition worlddata.c:5
bool m_EnTempUpdated
Definition worlddata.c:20
void SetupWeatherSettings()
Definition worlddata.c:370
void CalculateWind(int newWeather, bool suddenChange, out float magnitude, out float direction)
int GetDaytime()
Definition worlddata.c:104
float m_MinTemps[12]
Definition worlddata.c:23
float m_WorldWindCoef
Definition worlddata.c:39
float m_DayTemperature
DEPRECATED.
Definition worlddata.c:403
int m_SameWeatherCnt
Definition worlddata.c:44
float GetAgentSpawnChance(eAgents agent)
Definition worlddata.c:254
ref TStringArray m_DefaultPlayerRestrictedAreas
Definition worlddata.c:33
array< vector > GetArtyFiringPos()
Definition worlddata.c:248
ref array< vector > m_FiringPos
Definition worlddata.c:28
float m_WaterContactTemperatureModifier
Definition worlddata.c:11
float GetWindCoef()
Definition worlddata.c:287
float SUDDENCHANGE_LENGTH_MULTIPLIER
Definition worlddata.c:14
bool m_IsSuddenChange
Definition worlddata.c:38
float ComputeSnowflakeScale(Weather weather)
Returns the desired snowflake scale based on weather simulation state.
Definition worlddata.c:195
ref CatchYieldBank m_YieldBank
Definition worlddata.c:30
TStringArray GetDefaultPRAPaths()
Definition worlddata.c:393
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
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
const float ENVIRO_FOG_TEMP_EFFECT
how many % of ENVIRO_SUN_INCREMENT is reduced by fog
Definition constants.c:732
const float ENVIRO_WIND_EFFECT_SLOPE
time modifier, how much longer it takes to dig up worms while in a cold area
Definition constants.c:797
const float ENVIRO_WIND_CHILL_LIMIT
Affects the slope of calculation.
Definition constants.c:798
const int LIQUID_STILLWATER
Definition constants.c:555
const int LIQUID_FRESHWATER
Definition constants.c:554
const int LIQUID_CLEANWATER
Definition constants.c:557
const int LIQUID_WATER
Definition constants.c:544
const int LIQUID_RIVERWATER
Definition constants.c:545
const int LIQUID_SALTWATER
Definition constants.c:553
const int LIQUID_SNOW
Definition constants.c:552
static proto float Max(float x, float y)
Returns bigger of two given values.
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 proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float AbsFloat(float f)
Returns absolute value.
static proto float Floor(float f)
Returns floor of value.
vector GetPosition()
Get the world position of the Effect.
Definition effect.c:473
EWeatherPhenomenon
All classes related to game weather.
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