Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
worlddata.c
Go to the documentation of this file.
1 class WorldData
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();
27  m_EnvironmentTemperature = 12.0;
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
106  float GetBaseEnvTemperature()
107  {
108  return m_EnvironmentTemperature;
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
116  float GetDayTemperature()
117  {
118  return m_DayTemperature;
119  }
120  // legacy, no longer used
121  float GetNightTemperature()
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
133  array<vector> GetArtyFiringPos()
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 };
GetGame
proto native CGame GetGame()
m_Timer
ref Timer m_Timer
Definition: dayzgame.c:690
Print
proto void Print(void var)
Prints content of variable to console/log.
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
WorldData
Keeps information about currently loaded world, like temperature.
Definition: worlddata.c:2
array< vector >
EWeatherPhenomenon
EWeatherPhenomenon
Definition: weather.c:10
Math
Definition: enmath.c:6
Weather
Definition: weather.c:154