Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
enoch.c
Go to the documentation of this file.
1 class EnochData extends WorldData
2 {
3  const float RAIN_THRESHOLD = 0.6;
4  const float STORM_THRESHOLD = 0.85;
5 
6  const int OVERCAST_MIN_TIME = 600;
7  const int OVERCAST_MAX_TIME = 900;
8 
9  const int RAIN_TIME_MIN = 60;
10  const int RAIN_TIME_MAX = 120;
11 
12  const int CLEAR_WEATHER = 1;
13  const int CLOUDY_WEATHER = 2;
14  const int BAD_WEATHER = 3;
15 
16  const int CLEAR_WEATHER_CHANCE = 50;
17  const int BAD_WEATHER_CHANCE = 75;
18 
19  protected int m_clearWeatherChance = CLEAR_WEATHER_CHANCE;
20  //protected int m_badCloudyChance = 80;
21  protected int m_badWeatherChance = BAD_WEATHER_CHANCE;
22 
23  protected int m_stepValue = 5;
24 
25  protected int m_sameWeatherCnt = 0;
26  protected int m_chance = 50;
27 
28  protected int m_choosenWeather = 1;
29  protected int m_lastWeather = 0;
30 
31  protected static const ref array<vector> LIVONIA_ARTY_STRIKE_POS =
32  {
33  "7440.00 417.00 -500.00",
34  "-500.00 276.00 5473.00",
35  "-500.00 265.00 9852.00",
36  "4953.00 240.00 13300.00",
37  "9620.00 188.00 13300.00",
38  "13300.00 204.00 10322.00",
39  "13300.00 288.00 6204.00",
40  "13300.00 296.00 -500.00"
41  };
42 
43  override void Init()
44  {
45  super.Init();
46 
47  // new temperature curve settings
48  m_Sunrise_Jan = 8.4;
49  m_Sunset_Jan = 15.63;
50  m_Sunrise_Jul = 3.65;
51  m_Sunset_Jul = 20.35;
52 
53  int tempIdx;
54  m_MinTemps = {-7,-7.4,-4.1,1.5,7,11.3,13.4,13.1,9.3,5.3,0.8,-3.6};
55  if (CfgGameplayHandler.GetEnvironmentMinTemps() && CfgGameplayHandler.GetEnvironmentMinTemps().Count() == 12)
56  {
57  for (tempIdx = 0; tempIdx < CfgGameplayHandler.GetEnvironmentMinTemps().Count(); tempIdx++)
58  {
59  m_MinTemps[tempIdx] = CfgGameplayHandler.GetEnvironmentMinTemps().Get(tempIdx);
60  }
61  }
62 
63  m_MaxTemps = {-2.5,-2.1,2.3,9,15.5,19.4,20.9,20.4,16,10.5,4.2,0.1};
64  if (CfgGameplayHandler.GetEnvironmentMaxTemps() && CfgGameplayHandler.GetEnvironmentMaxTemps().Count() == 12)
65  {
66  for (tempIdx = 0; tempIdx < CfgGameplayHandler.GetEnvironmentMaxTemps().Count(); tempIdx++)
67  {
68  m_MaxTemps[tempIdx] = CfgGameplayHandler.GetEnvironmentMaxTemps().Get(tempIdx);
69  }
70  }
71 
72  m_FiringPos = LIVONIA_ARTY_STRIKE_POS;
73  }
74 
75  override bool WeatherOnBeforeChange( EWeatherPhenomenon type, float actual, float change, float time )
76  {
77  int phmnTime = 5;
78  int phmnLength = 10;
79  float phmnValue = 0;
80 
81  m_Weather.SetStorm( 1.0, STORM_THRESHOLD, 20 );
82 
83  m_Weather.SetRainThresholds( 0.0, 1.0, 60 );
84  m_Weather.SetWindMaximumSpeed( 20 );
85  m_Weather.SetWindFunctionParams( 0.1, 1.0, 20 );
86 
87  switch (type)
88  {
89  //-----------------------------------------------------------------------------------------------------------------------------
90  case EWeatherPhenomenon.OVERCAST:
91 
92  //went something goes wrong choose some default random weather
93  phmnValue = Math.RandomFloatInclusive( 0.1, 0.4 );
94  phmnTime = Math.RandomIntInclusive( OVERCAST_MIN_TIME, OVERCAST_MAX_TIME );
95  phmnLength = Math.RandomIntInclusive( OVERCAST_MIN_TIME, OVERCAST_MAX_TIME );
96 
97  //----
98  //calculate next weather
99  m_chance = Math.RandomIntInclusive( 0, 100 );
100 
101  //--
102  if ( m_lastWeather == CLEAR_WEATHER )
103  {
104  m_clearWeatherChance -= ( m_stepValue * m_sameWeatherCnt); //decrease the chance of the same weather
105  }
106 
107  if ( m_lastWeather == CLOUDY_WEATHER )
108  {
109  m_clearWeatherChance += ( m_stepValue * m_sameWeatherCnt); //increase the chance of the better weather
110  m_badWeatherChance -= ( m_stepValue * m_sameWeatherCnt);
111  }
112 
113  if ( m_lastWeather == BAD_WEATHER )
114  {
115  m_clearWeatherChance += m_stepValue; //increase the chance of the better weather slightly
116  m_badWeatherChance += ( m_stepValue * m_sameWeatherCnt ); //decrease the chance of the same weather
117  }
118 
119  //----
120  if ( m_chance < m_clearWeatherChance )
121  {
122  m_choosenWeather = CLEAR_WEATHER;
123  if ( m_lastWeather == CLEAR_WEATHER )
124  m_sameWeatherCnt ++;
125  }
126  else if ( m_chance > m_badWeatherChance )
127  {
128  m_choosenWeather = BAD_WEATHER;
129  if ( m_lastWeather == BAD_WEATHER )
130  m_sameWeatherCnt ++;
131  }
132  else
133  {
134  m_choosenWeather = CLOUDY_WEATHER;
135  if ( m_lastWeather == CLOUDY_WEATHER )
136  m_sameWeatherCnt ++;
137  }
138 
139  if ( m_choosenWeather != m_lastWeather )
140  m_sameWeatherCnt = 0;
141 
142  m_clearWeatherChance = CLEAR_WEATHER_CHANCE;
143  m_badWeatherChance = BAD_WEATHER_CHANCE;
144 
145  //----
146  //set choosen weather
147  if ( m_choosenWeather == CLEAR_WEATHER )
148  {
149  m_lastWeather = CLEAR_WEATHER;
150 
151  phmnValue = Math.RandomFloatInclusive( 0.0, 0.3 );
152  phmnTime = Math.RandomIntInclusive( OVERCAST_MIN_TIME, OVERCAST_MAX_TIME );
153  phmnLength = Math.RandomIntInclusive( OVERCAST_MIN_TIME, OVERCAST_MAX_TIME );
154  }
155 
156  if ( m_choosenWeather == CLOUDY_WEATHER )
157  {
158  m_lastWeather = CLOUDY_WEATHER;
159 
160  phmnValue = Math.RandomFloatInclusive( 0.3, 0.7 );
161  phmnTime = Math.RandomIntInclusive( OVERCAST_MIN_TIME, OVERCAST_MAX_TIME );
162  phmnLength = Math.RandomIntInclusive( 0, OVERCAST_MIN_TIME );
163  }
164 
165  if ( m_choosenWeather == BAD_WEATHER )
166  {
167  m_lastWeather = BAD_WEATHER;
168 
169  phmnValue = Math.RandomFloatInclusive( 0.7, 1.0 );
170  phmnTime = Math.RandomIntInclusive( OVERCAST_MIN_TIME, OVERCAST_MAX_TIME );
171  phmnLength = Math.RandomIntInclusive( 0, OVERCAST_MIN_TIME );
172  }
173 
174  m_Weather.GetOvercast().Set( phmnValue, phmnTime, phmnLength );
175 
176  Debug.WeatherLog(string.Format("Enoch::Weather::Overcast:: (%1) overcast: %2", g_Game.GetDayTime(), actual));
177  Debug.WeatherLog(string.Format("Enoch::Weather::Overcast::Rain:: (%1) %2", g_Game.GetDayTime(), m_Weather.GetRain().GetActual()));
178 
179  return true;
180 
181  //-----------------------------------------------------------------------------------------------------------------------------
182  case EWeatherPhenomenon.RAIN:
183  float actualOvercast = m_Weather.GetOvercast().GetActual();
184 
185  m_chance = Math.RandomIntInclusive( 0, 100 );
186  phmnValue = 0.2;
187  phmnTime = 90;
188  phmnLength = 30;
189 
190  if ( actualOvercast <= RAIN_THRESHOLD )
191  {
192  m_Weather.GetRain().Set( 0.0, RAIN_TIME_MIN, RAIN_TIME_MAX );
193  Debug.WeatherLog (string.Format("Enoch::Weather::Rain::ForceEnd:: (%1) %2 -> 0", g_Game.GetDayTime(), actual));
194  return true;
195  }
196 
197  if ( actualOvercast > STORM_THRESHOLD )
198  {
199  phmnValue = Math.RandomFloatInclusive( 0.8, 1.0 );
200  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
201  phmnLength = 0;
202 
203  m_Weather.GetRain().Set( phmnValue, phmnTime, phmnLength );
204  Debug.WeatherLog(string.Format("Enoch::Weather::Rain::ForceStorm:: (%1) %2 -> %3", g_Game.GetDayTime(), actual, phmnValue));
205  return true;
206  }
207 
208  //make a differnce in "normal rain"
209  if ( actualOvercast < 0.75 )
210  {
211  if ( m_chance < 30 )
212  {
213  phmnValue = Math.RandomFloatInclusive( 0.1, 0.3 );
214  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
215  phmnLength = 0;
216  }
217  else if ( m_chance < 60 )
218  {
219  phmnValue = Math.RandomFloatInclusive( 0.2, 0.4 );
220  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
221  phmnLength = 0;
222  }
223  else if ( m_chance < 85 )
224  {
225  phmnValue = Math.RandomFloatInclusive( 0.0, 0.2 );
226  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
227  phmnLength = 0;
228  }
229  else //also have the chance to not have rain at all
230  {
231  phmnValue = 0;
232  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
233  phmnLength = 120;
234  }
235  }
236  else if ( actualOvercast < STORM_THRESHOLD )
237  {
238  if ( m_chance < 15 )
239  {
240  phmnValue = Math.RandomFloatInclusive( 0.4, 0.6 );
241  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
242  phmnLength = 0;
243  }
244  else if ( m_chance < 50 )
245  {
246  phmnValue = Math.RandomFloatInclusive( 0.2, 0.4 );
247  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
248  phmnLength = 0;
249  }
250  else if ( m_chance < 90 )
251  {
252  phmnValue = Math.RandomFloatInclusive( 0.6, 0.8 );
253  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
254  phmnLength = 0;
255  }
256  else //also have the chance to not have rain at all
257  {
258  phmnValue = 0;
259  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
260  phmnLength = 120;
261  }
262  }
263  else
264  {
265  if ( m_chance < 50 )
266  {
267  phmnValue = Math.RandomFloatInclusive( 0.9, 1.0 );
268  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
269  phmnLength = 0;
270  }
271  else
272  {
273  phmnValue = Math.RandomFloatInclusive( 0.8, 0.9 );
274  phmnTime = Math.RandomInt( RAIN_TIME_MIN, RAIN_TIME_MAX );
275  phmnLength = 0;
276  }
277  }
278 
279  m_Weather.GetRain().Set( phmnValue, phmnTime, phmnLength );
280 
281  Debug.WeatherLog(string.Format("Enoch::Weather::Rain:: (%1) %2", g_Game.GetDayTime(), actual));
282  return true;
283 
284  //-----------------------------------------------------------------------------------------------------------------------------
285  case EWeatherPhenomenon.FOG:
286  int year, month, day, hour, minute;
287  GetGame().GetWorld().GetDate(year, month, day, hour, minute);
288  if (( hour >= 1 ) && ( hour <= 5 ))
289  {
290  m_Weather.GetFog().Set( 0.1, 1800, 0 );
291  } else {
292  m_Weather.GetFog().Set( 0.0, 1800, 0 );
293  }
294 
295  Debug.WeatherLog(string.Format("Enoch::Weather::Fog:: (%1) %2", g_Game.GetDayTime(), actual));
296 
297  return true;
298  }
299  return false;
300  }
301 };
GetGame
proto native CGame GetGame()
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
WorldData
Keeps information about currently loaded world, like temperature.
Definition: worlddata.c:2
CfgGameplayHandler
Definition: cfggameplayhandler.c:1
array< vector >
EWeatherPhenomenon
EWeatherPhenomenon
Definition: weather.c:10
Debug
Definition: debug.c:13
Math
Definition: enmath.c:6
Count
@ Count
Definition: randomgeneratorsyncmanager.c:7