enoch.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. //#define WEATHER_DATA_LOGGING
  2. class EnochData : WorldData
  3. {
  4. //-------test variables & methods ------
  5. #ifdef WEATHER_DATA_LOGGING
  6. int overcastChangeCount = 0;
  7. int suddenChangeCount = 0;
  8. int stormCount = 0;
  9. int suddenStormCount = 0;
  10. int badWeatherCount = 0;
  11. int cloudyWeatherCount = 0;
  12. int clearWeatherCount = 0;
  13. int startYear = 0;
  14. int startMonth = 0;
  15. int startDay = 0;
  16. int startHour = 0;
  17. int startMinute = 0;
  18. int currentDay = 0;
  19. int daysToRun = 10;
  20. bool dayInit = false;
  21. #endif
  22. //------------------------
  23. protected static const ref array<vector> LIVONIA_ARTY_STRIKE_POS =
  24. {
  25. "7440.00 417.00 -500.00",
  26. "-500.00 276.00 5473.00",
  27. "-500.00 265.00 9852.00",
  28. "4953.00 240.00 13300.00",
  29. "9620.00 188.00 13300.00",
  30. "13300.00 204.00 10322.00",
  31. "13300.00 288.00 6204.00",
  32. "13300.00 296.00 -500.00"
  33. };
  34. override void Init()
  35. {
  36. super.Init();
  37. // new temperature curve settings
  38. m_Sunrise_Jan = 8.4;
  39. m_Sunset_Jan = 15.63;
  40. m_Sunrise_Jul = 3.65;
  41. m_Sunset_Jul = 20.35;
  42. int tempIdx;
  43. m_MinTemps = {-7,-7.4,-4.1,1.5,7,11.3,20.4,19.1,18,5.3,0.8,-3.6}; //{-7,-7.4,-4.1,1.5,7,11.3,13.4,13.1,9.3,5.3,0.8,-3.6} original values, due to altitude of the map, changed the values drastically
  44. if (CfgGameplayHandler.GetEnvironmentMinTemps() && CfgGameplayHandler.GetEnvironmentMinTemps().Count() == 12)
  45. {
  46. for (tempIdx = 0; tempIdx < CfgGameplayHandler.GetEnvironmentMinTemps().Count(); tempIdx++)
  47. {
  48. m_MinTemps[tempIdx] = CfgGameplayHandler.GetEnvironmentMinTemps().Get(tempIdx);
  49. }
  50. }
  51. m_MaxTemps = {-2.5,-2.1,2.3,9,15.5,19.4,25,22,21,10.5,4.2,0.1}; //{-2.5,-2.1,2.3,9,15.5,19.4,20.9,20.4,16,10.5,4.2,0.1} original values
  52. if (CfgGameplayHandler.GetEnvironmentMaxTemps() && CfgGameplayHandler.GetEnvironmentMaxTemps().Count() == 12)
  53. {
  54. for (tempIdx = 0; tempIdx < CfgGameplayHandler.GetEnvironmentMaxTemps().Count(); tempIdx++)
  55. {
  56. m_MaxTemps[tempIdx] = CfgGameplayHandler.GetEnvironmentMaxTemps().Get(tempIdx);
  57. }
  58. }
  59. m_FiringPos = LIVONIA_ARTY_STRIKE_POS;
  60. m_CloudsTemperatureEffectModifier = -5.0;
  61. m_WorldWindCoef = 0.3;
  62. m_TemperaturePerHeightReductionModifier = 0.01;
  63. m_UniversalTemperatureSourceCapModifier = 1.0;
  64. if (GetGame().IsServer() || !GetGame().IsMultiplayer())
  65. {
  66. m_Weather.SetDynVolFogHeightBias(m_WeatherDefaultSettings.m_DefaultHeigthBias);
  67. if (GetGame().IsMultiplayer())
  68. {
  69. float startingOvercast = Math.RandomFloat(0.2,0.75);
  70. m_Weather.GetOvercast().Set(startingOvercast,0,5); //forcing a random weather at a clean server start and an instant change for overcast
  71. CalculateVolFog(startingOvercast, m_Weather.GetWindSpeed(), 0);
  72. }
  73. }
  74. }
  75. override void InitYieldBank()
  76. {
  77. super.InitYieldBank();
  78. m_YieldBank.ClearAllRegisteredItems();
  79. //fishies
  80. m_YieldBank.RegisterYieldItem(new YieldItemCarp(42));
  81. m_YieldBank.RegisterYieldItem(new YieldItemMackerel(42));
  82. m_YieldBank.RegisterYieldItem(new YieldItemSardines(15));
  83. m_YieldBank.RegisterYieldItem(new YieldItemBitterlings(15));
  84. //fishy junk
  85. m_YieldBank.RegisterYieldItem(new YieldItemJunk(1,"Wellies_Brown"));
  86. m_YieldBank.RegisterYieldItem(new YieldItemJunk(1,"Wellies_Grey"));
  87. m_YieldBank.RegisterYieldItem(new YieldItemJunk(1,"Wellies_Green"));
  88. m_YieldBank.RegisterYieldItem(new YieldItemJunk(1,"Wellies_Black"));
  89. m_YieldBank.RegisterYieldItem(new YieldItemJunkEmpty(1,"Pot"));
  90. //non-fishies
  91. m_YieldBank.RegisterYieldItem(new YieldItemDeadRabbit(4));
  92. m_YieldBank.RegisterYieldItem(new YieldItemDeadRooster(1));
  93. m_YieldBank.RegisterYieldItem(new YieldItemDeadChicken_White(1));
  94. m_YieldBank.RegisterYieldItem(new YieldItemDeadChicken_Spotted(1));
  95. m_YieldBank.RegisterYieldItem(new YieldItemDeadChicken_Brown(1));
  96. m_YieldBank.RegisterYieldItem(new YieldItemDeadFox(2));
  97. }
  98. override void SetupWeatherSettings()
  99. {
  100. super.SetupWeatherSettings();
  101. m_WeatherDefaultSettings.m_ClearWeatherChance = 50;
  102. m_WeatherDefaultSettings.m_BadWeatherChance = 75;
  103. m_WeatherDefaultSettings.m_BadWeatherSuddenChance = 0;
  104. }
  105. override void SetupLiquidTemperatures()
  106. {
  107. m_LiquidSettings = new WorldDataLiquidSettings();
  108. m_LiquidSettings.m_Temperatures[LIQUID_SALTWATER] = 25;
  109. m_LiquidSettings.m_Temperatures[LIQUID_WATER] = 25.0;
  110. m_LiquidSettings.m_Temperatures[LIQUID_STILLWATER] = 25.0;
  111. m_LiquidSettings.m_Temperatures[LIQUID_RIVERWATER] = 20.0;
  112. m_LiquidSettings.m_Temperatures[LIQUID_FRESHWATER] = 20.0;
  113. m_LiquidSettings.m_Temperatures[LIQUID_CLEANWATER] = 15.0;
  114. }
  115. override bool WeatherOnBeforeChange( EWeatherPhenomenon type, float actual, float change, float time )
  116. {
  117. #ifdef WEATHER_DATA_LOGGING
  118. if ( !dayInit )
  119. {
  120. GetGame().GetWorld().GetDate(startYear, startMonth, startDay, startHour, startMinute);
  121. dayInit = true;
  122. }
  123. #endif
  124. float phmnTime = 5;
  125. float phmnLength = 10;
  126. float phmnValue = 0;
  127. int year, month, day, hour, minute;
  128. GetGame().GetWorld().GetDate(year, month, day, hour, minute);
  129. m_Weather.SetStorm( 1.0, m_WeatherDefaultSettings.m_StormThreshold, 20 );
  130. m_Weather.SetRainThresholds( m_WeatherDefaultSettings.m_RainThreshold, 1.0, 60 );
  131. m_Weather.SetWindMaximumSpeed( 20 );
  132. switch (type)
  133. {
  134. //-----------------------------------------------------------------------------------------------------------------------------
  135. case EWeatherPhenomenon.OVERCAST:
  136. {
  137. #ifdef WEATHER_DATA_LOGGING
  138. overcastChangeCount++;
  139. #endif
  140. float windDirection, windMag;
  141. //went something goes wrong choose some default random weather
  142. phmnValue = Math.RandomFloatInclusive( 0.1, 0.4 );
  143. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinTime, m_WeatherDefaultSettings.m_OvercastMaxTime );
  144. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinLength, m_WeatherDefaultSettings.m_OvercastMaxLength );
  145. //----
  146. //calculate next weather
  147. m_Chance = Math.RandomIntInclusive( 0, 100 );
  148. //--
  149. if ( m_LastWeather == WorldDataWeatherConstants.CLEAR_WEATHER )
  150. {
  151. m_ClearWeatherChance -= ( m_StepValue * m_SameWeatherCnt); //decrease the chance of the same weather
  152. }
  153. if ( m_LastWeather == WorldDataWeatherConstants.CLOUDY_WEATHER )
  154. {
  155. m_ClearWeatherChance += ( m_StepValue * m_SameWeatherCnt); //increase the chance of the better weather
  156. m_BadWeatherChance -= ( m_StepValue * m_SameWeatherCnt);
  157. }
  158. if ( m_LastWeather == WorldDataWeatherConstants.BAD_WEATHER )
  159. {
  160. m_ClearWeatherChance += m_StepValue; //increase the chance of the better weather slightly
  161. m_BadWeatherChance += ( m_StepValue * m_SameWeatherCnt ); //decrease the chance of the same weather
  162. }
  163. //----
  164. if ( m_Chance > m_WeatherDefaultSettings.m_GlobalSuddenChance && !m_IsSuddenChange) //checks if previous weather was a sudden change
  165. {
  166. m_IsSuddenChange = true;
  167. m_ChoosenWeather = WorldDataWeatherConstants.BAD_WEATHER;
  168. if ( m_LastWeather == WorldDataWeatherConstants.BAD_WEATHER )
  169. m_SameWeatherCnt ++;
  170. }
  171. else if ( m_Chance < m_ClearWeatherChance )
  172. {
  173. m_ChoosenWeather = WorldDataWeatherConstants.CLEAR_WEATHER;
  174. m_IsSuddenChange = false;
  175. if ( m_LastWeather == WorldDataWeatherConstants.CLEAR_WEATHER )
  176. m_SameWeatherCnt ++;
  177. }
  178. else if ( m_Chance > m_BadWeatherChance )
  179. {
  180. m_ChoosenWeather = WorldDataWeatherConstants.BAD_WEATHER;
  181. m_IsSuddenChange = false;
  182. if ( m_LastWeather == WorldDataWeatherConstants.BAD_WEATHER )
  183. m_SameWeatherCnt ++;
  184. }
  185. else
  186. {
  187. m_ChoosenWeather = WorldDataWeatherConstants.CLOUDY_WEATHER;
  188. m_IsSuddenChange = false;
  189. if ( m_LastWeather == WorldDataWeatherConstants.CLOUDY_WEATHER )
  190. m_SameWeatherCnt ++;
  191. }
  192. if ( m_ChoosenWeather != m_LastWeather )
  193. m_SameWeatherCnt = 0;
  194. m_ClearWeatherChance = m_WeatherDefaultSettings.m_ClearWeatherChance;
  195. m_BadWeatherChance = m_WeatherDefaultSettings.m_BadWeatherChance;
  196. //----
  197. //set choosen weather
  198. if ( m_ChoosenWeather == WorldDataWeatherConstants.CLEAR_WEATHER )
  199. {
  200. m_LastWeather = WorldDataWeatherConstants.CLEAR_WEATHER;
  201. #ifdef WEATHER_DATA_LOGGING
  202. clearWeatherCount++;
  203. #endif
  204. phmnValue = Math.RandomFloatInclusive( 0.0, 0.3 );
  205. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinTime, m_WeatherDefaultSettings.m_OvercastMaxTime );
  206. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinLength, m_WeatherDefaultSettings.m_OvercastMaxLength );
  207. }
  208. if ( m_ChoosenWeather == WorldDataWeatherConstants.CLOUDY_WEATHER )
  209. {
  210. m_LastWeather = WorldDataWeatherConstants.CLOUDY_WEATHER;
  211. #ifdef WEATHER_DATA_LOGGING
  212. cloudyWeatherCount++;
  213. #endif
  214. phmnValue = Math.RandomFloatInclusive( 0.3, 0.7 );
  215. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinTime, m_WeatherDefaultSettings.m_OvercastMaxTime );
  216. phmnLength = Math.RandomIntInclusive( 0, m_WeatherDefaultSettings.m_OvercastMinLength );
  217. }
  218. if ( m_ChoosenWeather == WorldDataWeatherConstants.BAD_WEATHER )
  219. {
  220. m_LastWeather = WorldDataWeatherConstants.BAD_WEATHER;
  221. phmnValue = Math.RandomFloatInclusive( 0.7, 1.0 );
  222. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinTime, m_WeatherDefaultSettings.m_OvercastMaxTime );
  223. phmnLength = Math.RandomIntInclusive( 0, m_WeatherDefaultSettings.m_OvercastMinLength );
  224. #ifdef WEATHER_DATA_LOGGING
  225. badWeatherCount++;
  226. #endif
  227. if ( m_IsSuddenChange )
  228. {
  229. #ifdef WEATHER_DATA_LOGGING
  230. suddenChangeCount++;
  231. badWeatherCount--;
  232. #endif
  233. phmnTime *= SUDDENCHANGE_TIME_MULTIPLIER;
  234. phmnLength *= SUDDENCHANGE_LENGTH_MULTIPLIER;
  235. }
  236. #ifdef WEATHER_DATA_LOGGING
  237. if ( phmnValue > m_WeatherDefaultSettings.m_StormThreshold )
  238. {
  239. if ( m_IsSuddenChange )
  240. {
  241. suddenChangeCount--;
  242. suddenStormCount++;
  243. }
  244. else
  245. { stormCount++;
  246. badWeatherCount--;
  247. }
  248. }
  249. #endif
  250. }
  251. m_Weather.GetOvercast().Set( phmnValue, phmnTime, phmnLength );
  252. //we want to control wind with the overcast calculation and change with it.
  253. CalculateWind( m_ChoosenWeather, m_IsSuddenChange, windMag, windDirection );
  254. m_Weather.GetWindMagnitude().Set( windMag, phmnTime * WIND_MAGNITUDE_TIME_MULTIPLIER , phmnTime * (1 - WIND_MAGNITUDE_TIME_MULTIPLIER) ); // magnitude change happens during the overcast change, after overcast change finishes wind will decrease a bit
  255. m_Weather.GetWindDirection().Set( windDirection, phmnTime * WIND_DIRECTION_TIME_MULTIPLIER , phmnTime - (phmnTime * WIND_DIRECTION_TIME_MULTIPLIER) + phmnLength + 1000 );
  256. CalculateVolFog(phmnValue, windMag, phmnTime);
  257. if( m_IsSuddenChange )
  258. {
  259. m_Weather.GetRain().Set(Math.RandomFloatInclusive( 0.4, 0.8 ), phmnTime, 0); //forces to rain in the suddenchange.
  260. }
  261. Debug.WeatherLog(string.Format("Enoch::Weather::Overcast:: (%1) overcast: %2", g_Game.GetDayTime(), actual));
  262. Debug.WeatherLog(string.Format("Enoch::Weather::Overcast::Rain:: (%1) %2", g_Game.GetDayTime(), m_Weather.GetRain().GetActual()));
  263. #ifdef WEATHER_DATA_LOGGING
  264. int testYear = 0;
  265. int testMonth = 0;
  266. int testDay = 0;
  267. int testHour = 0;
  268. int testMinute = 0;
  269. GetGame().GetWorld().GetDate(testYear, testMonth, testDay, testHour, testMinute);
  270. if ( testDay - startDay > currentDay && testHour - startHour >= 0 && testMinute - startMinute >= 0 )
  271. {
  272. FileHandle file = OpenFile("$profile:OvercastCountsLivonia" + (currentDay + 1) + ".log", FileMode.WRITE);
  273. FPrintln(file, "================================================================");
  274. FPrintln(file," ================== Day " + (currentDay + 1) + " ================== ");
  275. FPrintln(file, "================================================================");
  276. FPrintln(file, "Overcast Change Count: " + overcastChangeCount);
  277. FPrintln(file, "Bad Weather Change Count: " + badWeatherCount);
  278. FPrintln(file, "Sudden Change Count: " + suddenChangeCount);
  279. FPrintln(file, "Storm Count: " + stormCount);
  280. FPrintln(file, "Sudden Storm Count: " + suddenStormCount);
  281. FPrintln(file, "Cloudy Weather Count: " + cloudyWeatherCount);
  282. FPrintln(file, "Clear Weather Count: " + clearWeatherCount);
  283. currentDay++;
  284. CloseFile(file);
  285. if ( currentDay == daysToRun )
  286. {
  287. g_Game.RequestExit(IDC_MAIN_QUIT);
  288. }
  289. overcastChangeCount = 0;
  290. suddenChangeCount = 0;
  291. stormCount = 0;
  292. suddenStormCount = 0;
  293. badWeatherCount = 0;
  294. cloudyWeatherCount = 0;
  295. clearWeatherCount = 0;
  296. }
  297. #endif
  298. return true;
  299. }
  300. //-----------------------------------------------------------------------------------------------------------------------------
  301. case EWeatherPhenomenon.RAIN:
  302. {
  303. float actualOvercast = m_Weather.GetOvercast().GetActual();
  304. m_Chance = Math.RandomIntInclusive( 0, 100 );
  305. phmnValue = 0.2;
  306. phmnTime = 90;
  307. phmnLength = 30;
  308. if ( actualOvercast <= m_WeatherDefaultSettings.m_RainThreshold)
  309. {
  310. m_Weather.GetRain().Set( 0.0, m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  311. Debug.WeatherLog (string.Format("Enoch::Weather::Rain::ForceEnd:: (%1) %2 -> 0", g_Game.GetDayTime(), actual));
  312. return true;
  313. }
  314. if ( actualOvercast > m_WeatherDefaultSettings.m_StormThreshold )
  315. {
  316. if( m_Weather.GetOvercast().GetActual() > m_Weather.GetOvercast().GetForecast() ) //ensure to have a pause to rain after the storm
  317. {
  318. phmnValue = 0;
  319. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax ) * 2;
  320. phmnLength = Math.RandomInt( m_WeatherDefaultSettings.m_CalmAfterStormTimeMin, m_WeatherDefaultSettings.m_CalmAfterStormTimeMax );
  321. }
  322. else
  323. {
  324. phmnValue = Math.RandomFloatInclusive( 0.8, 1.0 );
  325. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  326. phmnLength = 0;
  327. }
  328. m_Weather.GetRain().Set( phmnValue, phmnTime, phmnLength );
  329. Debug.WeatherLog(string.Format("Enoch::Weather::Rain::ForceStorm:: (%1) %2 -> %3", g_Game.GetDayTime(), actual, phmnValue));
  330. return true;
  331. }
  332. //make a differnce in "normal rain"
  333. if ( actualOvercast < 0.75 )
  334. {
  335. if ( m_Chance < 30 )
  336. {
  337. phmnValue = Math.RandomFloatInclusive( 0.1, 0.3 );
  338. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  339. phmnLength = Math.RandomInt( m_WeatherDefaultSettings.m_RainLengthMin, m_WeatherDefaultSettings.m_RainLengthMax );
  340. }
  341. else if ( m_Chance < 60 )
  342. {
  343. phmnValue = Math.RandomFloatInclusive( 0.2, 0.4 );
  344. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  345. phmnLength = Math.RandomInt( m_WeatherDefaultSettings.m_RainLengthMin, m_WeatherDefaultSettings.m_RainLengthMax );
  346. }
  347. else if ( m_Chance < 85 )
  348. {
  349. phmnValue = Math.RandomFloatInclusive( 0.05, 0.2 );
  350. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  351. phmnLength = Math.RandomInt( m_WeatherDefaultSettings.m_RainLengthMin, m_WeatherDefaultSettings.m_RainLengthMax );
  352. }
  353. else //also have the chance to not have rain at all
  354. {
  355. phmnValue = 0;
  356. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  357. phmnLength = Math.RandomInt( m_WeatherDefaultSettings.m_RainLengthMin, m_WeatherDefaultSettings.m_RainLengthMax ) * 4;
  358. }
  359. }
  360. else //overcast between storm threshold and 0.75
  361. {
  362. if ( m_Chance < 15 )
  363. {
  364. phmnValue = Math.RandomFloatInclusive( 0.4, 0.6 );
  365. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  366. phmnLength = 0;
  367. }
  368. else if ( m_Chance < 50 )
  369. {
  370. phmnValue = Math.RandomFloatInclusive( 0.2, 0.4 );
  371. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  372. phmnLength = 0;
  373. }
  374. else if ( m_Chance < 90 )
  375. {
  376. phmnValue = Math.RandomFloatInclusive( 0.6, 0.8 );
  377. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  378. phmnLength = 0;
  379. }
  380. else //also have the chance to not have rain at all
  381. {
  382. phmnValue = 0;
  383. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  384. phmnLength = Math.RandomInt( m_WeatherDefaultSettings.m_RainLengthMin, m_WeatherDefaultSettings.m_RainLengthMax ) * 4;
  385. }
  386. }
  387. m_Weather.GetRain().Set( phmnValue, phmnTime, phmnLength );
  388. Debug.WeatherLog(string.Format("Enoch::Weather::Rain:: (%1) %2", g_Game.GetDayTime(), actual));
  389. return true;
  390. }
  391. //-----------------------------------------------------------------------------------------------------------------------------
  392. case EWeatherPhenomenon.FOG:
  393. {
  394. if (( hour >= 2 ) && ( hour <= 5 ))
  395. {
  396. m_Weather.GetFog().Set( 0.13, 900, 0 );
  397. }
  398. else
  399. {
  400. m_Weather.GetFog().Set( 0.01, 900, 0 );
  401. }
  402. Debug.WeatherLog(string.Format("Enoch::Weather::Fog:: (%1) %2", g_Game.GetDayTime(), actual));
  403. return true;
  404. }
  405. //-----------------------------------------------------------------------------------------------------------------------------
  406. case EWeatherPhenomenon.WIND_MAGNITUDE:
  407. {
  408. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_RainTimeMin, m_WeatherDefaultSettings.m_RainTimeMax );
  409. m_Weather.GetWindMagnitude().Set(m_Weather.GetWindMagnitude().GetActual() * 0.75, phmnTime , m_WeatherDefaultSettings.m_OvercastMaxLength); // next change will be happen with the overcast change
  410. return true;
  411. }
  412. }
  413. return false;
  414. }
  415. protected override void CalculateWind(int newWeather, bool suddenChange, out float magnitude, out float direction)
  416. {
  417. magnitude = 5;
  418. direction = 0;
  419. float windChance = Math.RandomIntInclusive( 0, 100 );
  420. if ( newWeather == WorldDataWeatherConstants.CLEAR_WEATHER )
  421. {
  422. if ( windChance < 10 )
  423. {
  424. magnitude = Math.RandomFloatInclusive( 2 , 4 );
  425. direction = Math.RandomFloatInclusive( -2.3 , -1.8);
  426. }
  427. else if ( windChance < 50 )
  428. {
  429. magnitude = Math.RandomFloatInclusive( 4 , 8 );
  430. direction = Math.RandomFloatInclusive( -3.14 , -2.3);
  431. }
  432. else
  433. {
  434. magnitude = Math.RandomFloatInclusive( 6 , 12 );
  435. direction = Math.RandomFloatInclusive( 2.3 , 3.14);
  436. }
  437. }
  438. else if ( newWeather == WorldDataWeatherConstants.CLOUDY_WEATHER )
  439. {
  440. if ( windChance < 45 )
  441. {
  442. magnitude = Math.RandomFloatInclusive( 5 , 10 );
  443. direction = Math.RandomFloatInclusive( -1.8 , -1.0);
  444. }
  445. else if ( windChance < 90 )
  446. {
  447. magnitude = Math.RandomFloatInclusive( 8 , 12 );
  448. direction = Math.RandomFloatInclusive( -1.0, -0.7);
  449. }
  450. else
  451. {
  452. magnitude = Math.RandomFloatInclusive( 10 , 14 );
  453. direction = Math.RandomFloatInclusive( -2.4 , -1.8);
  454. }
  455. }
  456. else
  457. {
  458. if ( suddenChange || m_Weather.GetOvercast().GetActual() > m_WeatherDefaultSettings.m_StormThreshold || m_Weather.GetOvercast().GetForecast() - m_Weather.GetOvercast().GetActual() >= 0.4 )
  459. {
  460. magnitude = Math.RandomFloatInclusive( 17 , 20 );
  461. direction = Math.RandomFloatInclusive( -0.2 , 1.0);
  462. }
  463. else if ( windChance < 45 )
  464. {
  465. magnitude = Math.RandomFloatInclusive( 6 , 12 );
  466. direction = Math.RandomFloatInclusive( -0.6, 0);
  467. }
  468. else if ( windChance < 90 )
  469. {
  470. magnitude = Math.RandomFloatInclusive( 7 , 10 );
  471. direction = Math.RandomFloatInclusive( 1.3 , 1.9);
  472. }
  473. else
  474. {
  475. magnitude = Math.RandomFloatInclusive( 4 , 8 );
  476. direction = Math.RandomFloatInclusive( -1.8, -1.3 );
  477. }
  478. }
  479. }
  480. protected override void CalculateVolFog(float lerpValue, float windMagnitude, float changeTime)
  481. {
  482. float distanceDensity, heigthDensity, heightBias;
  483. int year, month, day, hour, minute;
  484. GetGame().GetWorld().GetDate(year, month, day, hour, minute);
  485. if ( hour < 6 && hour >= 3 )
  486. {
  487. heightBias = m_Weather.GetDynVolFogHeightBias();
  488. if ( heightBias == m_WeatherDefaultSettings.m_DefaultHeigthBias ) //verify if the foggy morning check has been done
  489. {
  490. bool foggyMorning = Math.RandomIntInclusive(0,1);
  491. if (foggyMorning)
  492. {
  493. heightBias = Math.RandomInt(m_WeatherDefaultSettings.m_FoggyMorningHeigthBiasLowLimit, m_WeatherDefaultSettings.m_DefaultHeigthBias);
  494. }
  495. else
  496. {
  497. heightBias = m_WeatherDefaultSettings.m_FoggyMorningHeigthBiasLowLimit - 1;
  498. }
  499. }
  500. if (heightBias == m_WeatherDefaultSettings.m_FoggyMorningHeigthBiasLowLimit - 1) //not foggy morning
  501. {
  502. distanceDensity = Math.Lerp( 0.01, 0.03, lerpValue ) * Math.Clamp(1 - (windMagnitude / m_Weather.GetWindMaximumSpeed()), 0.1, 1);
  503. heigthDensity = Math.Lerp( 0.9, 1, lerpValue);
  504. }
  505. else //foggy morning
  506. {
  507. distanceDensity = Math.Lerp( 0.5, 0.1, lerpValue ) * Math.Clamp(1 - (windMagnitude / m_Weather.GetWindMaximumSpeed()), 0.1, 1);
  508. heigthDensity = Math.Lerp( 0.2, 1, lerpValue);
  509. }
  510. }
  511. else if ( hour < 18 && hour >= 6 )
  512. {
  513. distanceDensity = Math.Lerp( 0.01, 0.05, lerpValue ) * Math.Clamp(1 - (windMagnitude / m_Weather.GetWindMaximumSpeed()), 0.1, 1);
  514. heigthDensity = Math.Lerp( 0.9, 1, lerpValue);
  515. heightBias = m_WeatherDefaultSettings.m_DefaultHeigthBias;
  516. }
  517. else
  518. {
  519. distanceDensity = Math.Lerp( 0.01, 0.03, lerpValue ) * Math.Clamp(1 - (windMagnitude / m_Weather.GetWindMaximumSpeed()), 0.1, 1);
  520. heigthDensity = Math.Lerp( 0.9, 1, lerpValue);
  521. heightBias = m_WeatherDefaultSettings.m_DefaultHeigthBias;
  522. }
  523. m_Weather.SetDynVolFogDistanceDensity(distanceDensity, changeTime);
  524. m_Weather.SetDynVolFogHeightDensity(heigthDensity, changeTime);
  525. m_Weather.SetDynVolFogHeightBias(heightBias, changeTime);
  526. }
  527. bool LogWeatherData() //called from mission file to check if the logging should start
  528. {
  529. #ifdef WEATHER_DATA_LOGGING
  530. return true;
  531. #endif
  532. return false;
  533. }
  534. //! DEPRECATED (see WorldDataWeatherConstants)
  535. const int CLEAR_WEATHER = 1;
  536. const int CLOUDY_WEATHER = 2;
  537. const int BAD_WEATHER = 3;
  538. //! DEPRECATED (see WorldDataWeatherSettings)
  539. const int OVERCAST_MIN_TIME = 600;
  540. const int OVERCAST_MAX_TIME = 900;
  541. const float RAIN_THRESHOLD = 0.6;
  542. const int RAIN_TIME_MIN = 60;
  543. const int RAIN_TIME_MAX = 120;
  544. const float STORM_THRESHOLD = 0.85;
  545. protected int m_clearWeatherChance = m_ClearWeatherChance;
  546. protected int m_badWeatherChance = m_BadWeatherChance;
  547. protected int m_sameWeatherCnt = m_SameWeatherCnt;
  548. protected int m_stepValue = m_StepValue;
  549. protected int m_chance = m_Chance;
  550. protected int m_choosenWeather = m_ChoosenWeather;
  551. protected int m_lastWeather = m_LastWeather;
  552. }