DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
WorldData.c
Go to the documentation of this file.
1
3{
4 protected float m_DayTemperature; // legacy, no longer used
5 protected float m_NightTemperature; // legacy, no longer used
6 protected Weather m_Weather;
7 protected float m_EnvironmentTemperature;
8 protected float m_Timer;
9 protected float m_MaxTemps[12];
10 protected float m_MinTemps[12];
11 protected float m_Sunrise_Jan;
12 protected float m_Sunset_Jan;
13 protected float m_Sunrise_Jul;
14 protected float m_Sunset_Jul;
15 protected ref array<vector> m_FiringPos; // Where we should fire from. On Init set the relevant data
16
17 void WorldData()
18 {
19 Init();
20 }
21
22 void Init()
23 {
24 m_DayTemperature = 10; // legacy, no longer used
25 m_NightTemperature = 6; // legacy, no longer used
26 m_Weather = g_Game.GetWeather();
28 m_Timer = 0.0;
29 m_Sunrise_Jan = 8.54;
30 m_Sunset_Jan = 15.52;
31 m_Sunrise_Jul = 3.26;
32 m_Sunset_Jul = 20.73;
33 m_MaxTemps = {3,5,7,14,19,24,26,25,21,16,10,5};
34 m_MinTemps = {-3,-2,0,4,9,14,18,17,12,7,4,0};
35 }
36
37 float GetApproxSunriseTime( float monthday )
38 {
39 if ( monthday <= 8.0 )
40 return ( ( m_Sunrise_Jan - m_Sunrise_Jul ) / ( 8 - 1 ) ) * ( 1 - monthday ) + m_Sunrise_Jan;
41 else
42 return ( ( ( monthday - 8 ) * ( m_Sunrise_Jan - m_Sunrise_Jul ) ) / ( 13 - 8 ) ) + m_Sunrise_Jul;
43 }
44 float GetApproxSunsetTime( float monthday )
45 {
46 if ( monthday <= 8.0 )
47 return ( ( m_Sunset_Jan - m_Sunset_Jul ) / (8 - 1) ) * ( 1 - monthday ) + m_Sunset_Jan;
48 else
49 return ( ( ( monthday - 8 ) * ( m_Sunset_Jan - m_Sunset_Jul ) ) / ( 13 - 8 ) ) + m_Sunset_Jul;
50 }
51 protected float CalcBaseEnvironmentTemperature( float monthday, float daytime )
52 {
53 float approxSunrise = GetApproxSunriseTime( monthday );
54 float approxSunset = GetApproxSunsetTime( monthday );
55 float dayLight = approxSunset - approxSunrise;
56 float nightTime = 24.0 - dayLight;
57 int tempArrayIndex = Math.Floor(monthday) - 1;
58 int tempArrayIndexToLerp = tempArrayIndex + 1;
59 if ( tempArrayIndexToLerp >= 12 )
60 tempArrayIndexToLerp = 0;
61 float tempArrayLerp = monthday - Math.Floor(monthday);
62 float minTempA = m_MinTemps[tempArrayIndex];
63 float minTempB = m_MinTemps[tempArrayIndexToLerp];
64 float maxTempA = m_MaxTemps[tempArrayIndex];
65 float maxTempB = m_MaxTemps[tempArrayIndexToLerp];
66 float eveningMinA = minTempA + ( 0.5 * Math.AbsFloat( minTempA - maxTempA ) );
67 float eveningMinB = minTempB + ( 0.5 * Math.AbsFloat( minTempB - maxTempB ) );
68
69 if ( ( daytime >= approxSunrise ) && ( daytime <= approxSunset ) ) {
70 if ( daytime <= ( approxSunrise + ( dayLight * 0.75 ) ) )
71 return Math.Lerp(
72 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
73 Math.Lerp( maxTempA, maxTempB, tempArrayLerp ),
74 ( ( daytime - approxSunrise ) / ( dayLight * 0.75 ) ) );
75 else
76 return Math.Lerp(
77 Math.Lerp( maxTempA, maxTempB, tempArrayLerp ),
78 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
79 ( ( ( daytime - approxSunrise ) - ( dayLight * 0.75 ) ) / ( dayLight - ( dayLight * 0.75 ) ) ) );
80 } else {
81 if ( ( daytime > approxSunset ) && ( daytime < 24 ) )
82 return Math.Lerp(
83 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
84 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
85 ( ( daytime - approxSunset ) / ( 24 - approxSunset ) ) / 2.0 );
86 else
87 return Math.Lerp(
88 Math.Lerp( eveningMinA, eveningMinB, tempArrayLerp ),
89 Math.Lerp( minTempA, minTempB, tempArrayLerp ),
90 ( ( ( daytime + ( 24 - approxSunset ) ) / nightTime ) / 2.0 ) + 0.5 );
91 }
92 }
93 void UpdateBaseEnvTemperature(float timeslice)
94 {
95 m_Timer += timeslice;
96 if ( m_Timer > 30 )
97 {
98 int year, month, day, hour, minute;
99 GetGame().GetWorld().GetDate( year, month, day, hour, minute );
100 m_EnvironmentTemperature = CalcBaseEnvironmentTemperature( month + ( day / 32.0 ), hour + ( minute / 60.0 ) );
101 m_Timer = 0;
102 }
103 }
104
105 // getter for the new base enviro temperature
107 {
109 }
110 float GetBaseEnvTemperatureExact(int month, int day, int hour, int minute)
111 {
112 return CalcBaseEnvironmentTemperature( month + ( day / 32.0 ), hour + ( minute / 60.0 ) );
113 }
114
115 // legacy, no longer used
117 {
118 return m_DayTemperature;
119 }
120 // legacy, no longer used
122 {
123 return m_NightTemperature;
124 }
125
126 bool WeatherOnBeforeChange( EWeatherPhenomenon type, float actual, float change, float time )
127 {
128 // default behaviour is same like setting MissionWeather (in Weather) to true
129 return false;
130 }
131
132 // Used to return the artillery firing positions
134 {
135 return m_FiringPos;
136 }
137
138 // debug
139 void BaseTempDebug(int month, int day)
140 {
141 Print("--------------------");
142 for ( int i = 0; i < 24; i++ )
143 {
144 for ( int j = 0; j < 6; j++ )
145 {
146 int minute = ( j * 10 );
147 Print(string.Format( "%1:%2 %3", i, minute, GetBaseEnvTemperatureExact( month, day, i, minute ) ) );
148 }
149 }
150 }
151};
DayZGame g_Game
Definition DayZGame.c:3654
EWeatherPhenomenon
Definition Weather.c:11
proto native World GetWorld()
Definition EnMath.c:7
Keeps information about currently loaded world, like temperature.
Definition WorldData.c:3
protected ref array< vector > m_FiringPos
Definition WorldData.c:15
float GetNightTemperature()
Definition WorldData.c:121
float GetBaseEnvTemperatureExact(int month, int day, int hour, int minute)
Definition WorldData.c:110
protected float m_MaxTemps[12]
Definition WorldData.c:9
float GetApproxSunsetTime(float monthday)
Definition WorldData.c:44
protected float m_Sunrise_Jan
Definition WorldData.c:11
float GetApproxSunriseTime(float monthday)
Definition WorldData.c:37
void Init()
Definition WorldData.c:22
protected float m_Sunset_Jan
Definition WorldData.c:12
bool WeatherOnBeforeChange(EWeatherPhenomenon type, float actual, float change, float time)
Definition WorldData.c:126
protected Weather m_Weather
Definition WorldData.c:6
protected float m_Sunrise_Jul
Definition WorldData.c:13
float GetDayTemperature()
Definition WorldData.c:116
void BaseTempDebug(int month, int day)
Definition WorldData.c:139
void UpdateBaseEnvTemperature(float timeslice)
Definition WorldData.c:93
float GetBaseEnvTemperature()
Definition WorldData.c:106
void WorldData()
Definition WorldData.c:17
protected float CalcBaseEnvironmentTemperature(float monthday, float daytime)
Definition WorldData.c:51
protected float m_EnvironmentTemperature
Definition WorldData.c:7
protected float m_MinTemps[12]
Definition WorldData.c:10
protected float m_NightTemperature
Definition WorldData.c:5
protected float m_Sunset_Jul
Definition WorldData.c:14
array< vector > GetArtyFiringPos()
Definition WorldData.c:133
protected float m_Timer
Definition WorldData.c:8
protected float m_DayTemperature
Definition WorldData.c:4
proto void GetDate(out int year, out int month, out int day, out int hour, out int minute)
Get actual ingame world time.
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
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.