sakhal.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. //#define WEATHER_DATA_LOGGING
  2. class SakhalData : WorldData
  3. {
  4. const float SPAWN_CHANCE_CHOLERA = 20;
  5. const float COLD_AREA_TOOL_DMG_MODIF = 1.2;
  6. //-------test variables & methods ------
  7. #ifdef WEATHER_DATA_LOGGING
  8. int overcastChangeCount = 0;
  9. int directSuddenChangeCount = 0;
  10. int badWeatherSuddenChangeCount = 0;
  11. int thundersnowCount = 0;
  12. int suddenThundersnowCount = 0;
  13. int badWeatherCount = 0;
  14. int cloudyWeatherCount = 0;
  15. int clearWeatherCount = 0;
  16. int startYear = 0;
  17. int startMonth = 0;
  18. int startDay = 0;
  19. int startHour = 0;
  20. int startMinute = 0;
  21. int currentDay = 0;
  22. int daysToRun = 10;
  23. bool dayInit = false;
  24. #endif
  25. //------------------------
  26. override void Init()
  27. {
  28. super.Init();
  29. // new temperature curve settings
  30. m_Sunrise_Jan = 8.41;
  31. m_Sunset_Jan = 15.58;
  32. m_Sunrise_Jul = 3.75;
  33. m_Sunset_Jul = 20.25;
  34. int tempIdx;
  35. m_MinTemps = {-6.5, -9.5, -6.5, -9.5, 2, 6, 9, 10, 6, 1, -5, -10}; //{-13, -11, -7, -3, 2, 6, 9, 10, 6, 1, -5, -10} original values
  36. if (CfgGameplayHandler.GetEnvironmentMinTemps() && CfgGameplayHandler.GetEnvironmentMinTemps().Count() == 12)
  37. {
  38. for (tempIdx = 0; tempIdx < CfgGameplayHandler.GetEnvironmentMinTemps().Count(); tempIdx++)
  39. {
  40. m_MinTemps[tempIdx] = CfgGameplayHandler.GetEnvironmentMinTemps().Get(tempIdx);
  41. }
  42. }
  43. m_MaxTemps = {-3, -5, -3, -5, 9, 14, 16, 17, 14, 8, 1, -3}; //{-6, -4, -1, 3, 9, 14, 16, 17, 14, 8, 1, -3} original values
  44. if (CfgGameplayHandler.GetEnvironmentMaxTemps() && CfgGameplayHandler.GetEnvironmentMaxTemps().Count() == 12)
  45. {
  46. for (tempIdx = 0; tempIdx < CfgGameplayHandler.GetEnvironmentMaxTemps().Count(); tempIdx++)
  47. {
  48. m_MaxTemps[tempIdx] = CfgGameplayHandler.GetEnvironmentMaxTemps().Get(tempIdx);
  49. }
  50. }
  51. m_Pollution = m_Pollution | EPollution.HEAVYMETAL;
  52. m_TemperatureInsideBuildingsModifier = -1.0;
  53. m_UniversalTemperatureSourceCapModifier = -3.0;
  54. m_ClearWeatherChance = m_WeatherDefaultSettings.m_ClearWeatherChance;
  55. m_BadWeatherChance = m_WeatherDefaultSettings.m_BadWeatherChance;
  56. if (GetGame().IsServer() || !GetGame().IsMultiplayer())
  57. {
  58. m_Weather.SetDynVolFogHeightDensity( 1, 0 );
  59. m_Weather.SetDynVolFogHeightBias( 0, 0 );
  60. m_Weather.GetFog().Set(0,0,1000);
  61. m_Weather.GetFog().SetLimits(0,0);
  62. m_Weather.GetOvercast().SetLimits(0.07, 1);
  63. if (GetGame().IsMultiplayer())
  64. {
  65. m_Weather.GetOvercast().Set(Math.RandomFloat(0,0.75),0,5); //forcing a random weather at a clean server start and an instant change for overcast
  66. CalculateVolFog(m_Weather.GetSnowfall().GetActual(),m_Weather.GetWindSpeed(),0);
  67. }
  68. m_DefaultPlayerRestrictedAreas = {"pra/warheadstorage.json"};
  69. }
  70. }
  71. override void InitYieldBank()
  72. {
  73. super.InitYieldBank();
  74. m_YieldBank.ClearAllRegisteredItems();
  75. //fishies
  76. m_YieldBank.RegisterYieldItem(new YieldItemWalleyePollock(61));
  77. m_YieldBank.RegisterYieldItem(new YieldItemSteelheadTrout(36));
  78. m_YieldBank.RegisterYieldItem(new YieldItemShrimp(1));
  79. //fishy junk
  80. m_YieldBank.RegisterYieldItem(new YieldItemJunk(1,"Wellies_Brown"));
  81. m_YieldBank.RegisterYieldItem(new YieldItemJunk(1,"Wellies_Grey"));
  82. m_YieldBank.RegisterYieldItem(new YieldItemJunk(1,"Wellies_Green"));
  83. m_YieldBank.RegisterYieldItem(new YieldItemJunk(1,"Wellies_Black"));
  84. m_YieldBank.RegisterYieldItem(new YieldItemJunkEmpty(1,"Pot"));
  85. //non-fishies
  86. m_YieldBank.RegisterYieldItem(new YieldItemDeadRabbit(1));
  87. m_YieldBank.RegisterYieldItem(new YieldItemDeadFox(1));
  88. //m_YieldBank.RegisterYieldItem(new YieldItemGenericSmallAnimal(1,"Animal_UrsusArctos",AnimalCatchingConstants.MASK_ENVIRO_FOREST,AnimalCatchingConstants.MASK_METHOD_LANDTRAP_MEATBAIT));
  89. }
  90. override void SetupWeatherSettings()
  91. {
  92. super.SetupWeatherSettings();
  93. m_WeatherDefaultSettings.m_GlobalSuddenChance = 95; // works if the randomization value is bigger than this. we do not want to decrease the clear sky chance
  94. m_WeatherDefaultSettings.m_ClearWeatherChance = 20;
  95. m_WeatherDefaultSettings.m_BadWeatherChance = 65;
  96. m_WeatherDefaultSettings.m_BadWeatherSuddenChance = 15;
  97. }
  98. override void SetupLiquidTemperatures()
  99. {
  100. m_LiquidSettings = new WorldDataLiquidSettings();
  101. m_LiquidSettings.m_Temperatures[LIQUID_SALTWATER] = -0.5;
  102. m_LiquidSettings.m_Temperatures[LIQUID_WATER] = 2.0;
  103. m_LiquidSettings.m_Temperatures[LIQUID_STILLWATER] = 2.0;
  104. m_LiquidSettings.m_Temperatures[LIQUID_RIVERWATER] = 2.0;
  105. m_LiquidSettings.m_Temperatures[LIQUID_FRESHWATER] = 2.0;
  106. m_LiquidSettings.m_Temperatures[LIQUID_CLEANWATER] = 5.0;
  107. m_LiquidSettings.m_Temperatures[LIQUID_SNOW] = -5.0;
  108. m_LiquidSettings.m_Temperatures[LIQUID_HOTWATER] = 90.0;
  109. }
  110. override bool WeatherOnBeforeChange( EWeatherPhenomenon type, float actual, float change, float time )
  111. {
  112. #ifdef WEATHER_DATA_LOGGING
  113. if ( !dayInit )
  114. {
  115. GetGame().GetWorld().GetDate(startYear, startMonth, startDay, startHour, startMinute);
  116. dayInit = true;
  117. }
  118. #endif
  119. float phmnTime = 120;
  120. float phmnLength = 10;
  121. float phmnValue = 0;
  122. m_Weather.GetRain().SetLimits(0, 0);//since we decided that it will not rain in sakhal...
  123. m_Weather.GetOvercast().SetLimits(0.07, 1);
  124. m_Weather.GetSnowfall().SetLimits(0, 1);
  125. m_Weather.SetSnowfallThresholds( m_WeatherDefaultSettings.m_SnowfallThreshold, 1.0, 60 );
  126. m_Weather.GetSnowfall().SetForecastChangeLimits(0, 1);
  127. m_Weather.SetStorm( 1.0, m_WeatherDefaultSettings.m_ThundersnowThreshold, 45 );
  128. m_Weather.SetWindMaximumSpeed( 20 );
  129. m_Weather.GetWindMagnitude().SetForecastChangeLimits( 0, 20 );
  130. m_Weather.GetFog().SetLimits(0,0);
  131. switch (type)
  132. {
  133. //-----------------------------------------------------------------------------------------------------------------------------
  134. case EWeatherPhenomenon.OVERCAST:
  135. {
  136. float windDirection, windMag;
  137. #ifdef WEATHER_DATA_LOGGING
  138. overcastChangeCount++;
  139. #endif
  140. //went something goes wrong choose some default random weather
  141. phmnValue = Math.RandomFloatInclusive( 0.2, 0.7 );
  142. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinTime, m_WeatherDefaultSettings.m_OvercastMaxTime );
  143. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinLength, m_WeatherDefaultSettings.m_OvercastMaxLength );
  144. //----
  145. //--
  146. if ( m_LastWeather == WorldDataWeatherConstants.CLEAR_WEATHER )
  147. {
  148. m_ClearWeatherChance -= ( m_StepValue * m_SameWeatherCnt); //decrease the chance of the same weather
  149. }
  150. if ( m_LastWeather == WorldDataWeatherConstants.CLOUDY_WEATHER )
  151. {
  152. m_ClearWeatherChance += ( m_StepValue * m_SameWeatherCnt); //increase the chance of the better weather
  153. }
  154. if ( m_LastWeather == WorldDataWeatherConstants.BAD_WEATHER )
  155. {
  156. m_ClearWeatherChance += m_StepValue; //increase the chance of the better weather slightly
  157. m_BadWeatherChance += (( m_StepValue * m_SameWeatherCnt ) + m_StepValue ); //decrease the chance of the same weather rapidly
  158. }
  159. //----
  160. //calculate next weather
  161. m_Chance = Math.RandomIntInclusive( 0, 100 );
  162. if ( m_Chance > m_WeatherDefaultSettings.m_GlobalSuddenChance && !m_IsSuddenChange) //checks if previous weather was a sudden change
  163. {
  164. #ifdef WEATHER_DATA_LOGGING
  165. directSuddenChangeCount++;
  166. #endif
  167. m_IsSuddenChange = true;
  168. m_ChoosenWeather = WorldDataWeatherConstants.BAD_WEATHER;
  169. if ( m_LastWeather == WorldDataWeatherConstants.BAD_WEATHER )
  170. m_SameWeatherCnt ++;
  171. }
  172. else if ( m_Chance < m_ClearWeatherChance )
  173. {
  174. m_ChoosenWeather = WorldDataWeatherConstants.CLEAR_WEATHER;
  175. m_IsSuddenChange = false;
  176. if ( m_LastWeather == WorldDataWeatherConstants.CLEAR_WEATHER )
  177. m_SameWeatherCnt ++;
  178. }
  179. else if ( m_Chance > m_BadWeatherChance )
  180. {
  181. m_ChoosenWeather = WorldDataWeatherConstants.BAD_WEATHER;
  182. if ( m_LastWeather == WorldDataWeatherConstants.BAD_WEATHER )
  183. m_SameWeatherCnt ++;
  184. if ( m_IsSuddenChange )
  185. {
  186. m_IsSuddenChange = false;
  187. #ifdef WEATHER_DATA_LOGGING
  188. badWeatherCount++;
  189. #endif
  190. }
  191. else
  192. {
  193. if ( Math.RandomIntInclusive( 0, 100 ) < m_WeatherDefaultSettings.m_BadWeatherSuddenChance )
  194. {
  195. m_IsSuddenChange = true;
  196. #ifdef WEATHER_DATA_LOGGING
  197. badWeatherSuddenChangeCount++;
  198. #endif
  199. }
  200. else
  201. {
  202. #ifdef WEATHER_DATA_LOGGING
  203. badWeatherCount++;
  204. #endif
  205. }
  206. }
  207. }
  208. else
  209. {
  210. m_ChoosenWeather = WorldDataWeatherConstants.CLOUDY_WEATHER;
  211. m_IsSuddenChange = false;
  212. if ( m_LastWeather == WorldDataWeatherConstants.CLOUDY_WEATHER )
  213. m_SameWeatherCnt ++;
  214. }
  215. if ( m_ChoosenWeather != m_LastWeather )
  216. m_SameWeatherCnt = 0;
  217. m_ClearWeatherChance = m_WeatherDefaultSettings.m_ClearWeatherChance;
  218. m_BadWeatherChance = m_WeatherDefaultSettings.m_BadWeatherChance;
  219. //----
  220. //set choosen weather
  221. if ( m_ChoosenWeather == WorldDataWeatherConstants.CLEAR_WEATHER )
  222. {
  223. m_LastWeather = WorldDataWeatherConstants.CLEAR_WEATHER;
  224. #ifdef WEATHER_DATA_LOGGING
  225. clearWeatherCount++;
  226. #endif
  227. phmnValue = Math.RandomFloatInclusive( 0.07, 0.3 );
  228. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinTime, m_WeatherDefaultSettings.m_OvercastMaxTime );
  229. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinLength, m_WeatherDefaultSettings.m_OvercastMaxLength );
  230. }
  231. if ( m_ChoosenWeather == CLOUDY_WEATHER )
  232. {
  233. #ifdef WEATHER_DATA_LOGGING
  234. cloudyWeatherCount++;
  235. #endif
  236. m_LastWeather = CLOUDY_WEATHER;
  237. phmnValue = Math.RandomFloatInclusive( 0.3, 0.6 );
  238. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinTime, m_WeatherDefaultSettings.m_OvercastMaxTime );
  239. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinLength, m_WeatherDefaultSettings.m_OvercastMaxLength );
  240. }
  241. if ( m_ChoosenWeather == WorldDataWeatherConstants.BAD_WEATHER )
  242. {
  243. m_LastWeather = WorldDataWeatherConstants.BAD_WEATHER;
  244. phmnValue = Math.RandomFloatInclusive( 0.6, 1.0 );
  245. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinTime, m_WeatherDefaultSettings.m_OvercastMaxTime );
  246. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_OvercastMinLength, m_WeatherDefaultSettings.m_OvercastMaxLength );
  247. if ( m_IsSuddenChange )
  248. {
  249. phmnTime *= SUDDENCHANGE_TIME_MULTIPLIER;
  250. phmnLength *= SUDDENCHANGE_LENGTH_MULTIPLIER;
  251. }
  252. #ifdef WEATHER_DATA_LOGGING
  253. if ( phmnValue > m_WeatherDefaultSettings.m_ThundersnowThreshold )
  254. {
  255. if ( m_IsSuddenChange )
  256. {
  257. suddenThundersnowCount++;
  258. if ( m_Chance < m_WeatherDefaultSettings.m_GlobalSuddenChance )
  259. {
  260. directSuddenChangeCount--;
  261. }
  262. else
  263. {
  264. badWeatherSuddenChangeCount--;
  265. }
  266. }
  267. else
  268. {
  269. thundersnowCount++;
  270. badWeatherCount--;
  271. }
  272. }
  273. #endif
  274. }
  275. m_Weather.GetOvercast().Set( phmnValue, phmnTime, phmnLength );
  276. //we want to control wind with the overcast calculation and change with it.
  277. CalculateWind( m_ChoosenWeather, m_IsSuddenChange, windMag, windDirection );
  278. m_Weather.GetWindMagnitude().Set( windMag, phmnTime * WIND_MAGNITUDE_TIME_MULTIPLIER , phmnTime - (phmnTime * WIND_MAGNITUDE_TIME_MULTIPLIER) + phmnLength + 1000 );
  279. m_Weather.GetWindDirection().Set( windDirection, phmnTime * WIND_DIRECTION_TIME_MULTIPLIER , phmnTime - (phmnTime * WIND_DIRECTION_TIME_MULTIPLIER) + phmnLength + 1000 );
  280. if( m_IsSuddenChange )
  281. {
  282. m_Weather.GetSnowfall().Set(Math.RandomFloatInclusive( 0.4, 0.8 ), phmnTime, 0); //forces to snow in the suddenchange.
  283. }
  284. Debug.WeatherLog(string.Format("Sakhal::Weather::Overcast:: (%1) overcast: %2", g_Game.GetDayTime(), actual));
  285. Debug.WeatherLog(string.Format("Sakhal::Weather::Overcast::Snow:: (%1) %2", g_Game.GetDayTime(), m_Weather.GetRain().GetActual()));
  286. #ifdef WEATHER_DATA_LOGGING
  287. int testYear = 0;
  288. int testMonth = 0;
  289. int testDay = 0;
  290. int testHour = 0;
  291. int testMinute = 0;
  292. GetGame().GetWorld().GetDate(testYear, testMonth, testDay, testHour, testMinute);
  293. if ( testDay - startDay > currentDay && testHour - startHour >= 0 && testMinute - startMinute >= 0 )
  294. {
  295. FileHandle file = OpenFile("$profile:OvercastCountsSakhal" + (currentDay + 1) + ".log", FileMode.WRITE);
  296. FPrintln(file, "================================================================");
  297. FPrintln(file," ================== Day " + (currentDay + 1) + " ================== ");
  298. FPrintln(file, "================================================================");
  299. FPrintln(file, "Overcast Change Count: " + overcastChangeCount);
  300. FPrintln(file, "Bad Weather Change Count: " + badWeatherCount);
  301. FPrintln(file, "Bad Weather Sudden Change Count: " + badWeatherSuddenChangeCount);
  302. FPrintln(file, "Global Sudden Change Count: " + directSuddenChangeCount);
  303. FPrintln(file, "Thunder Snow Count: " + thundersnowCount);
  304. FPrintln(file, "Sudden Thundersnow Count: " + suddenThundersnowCount);
  305. FPrintln(file, "Cloudy Weather Count: " + cloudyWeatherCount);
  306. FPrintln(file, "Clear Weather Count: " + clearWeatherCount);
  307. currentDay++;
  308. CloseFile(file);
  309. if ( currentDay == daysToRun )
  310. {
  311. g_Game.RequestExit(IDC_MAIN_QUIT);
  312. }
  313. overcastChangeCount = 0;
  314. directSuddenChangeCount = 0;
  315. badWeatherSuddenChangeCount = 0;
  316. thundersnowCount = 0;
  317. suddenThundersnowCount = 0;
  318. badWeatherCount = 0;
  319. cloudyWeatherCount = 0;
  320. clearWeatherCount = 0;
  321. }
  322. #endif
  323. return true;
  324. }
  325. //-----------------------------------------------------------------------------------------------------------------------------
  326. case EWeatherPhenomenon.SNOWFALL:
  327. {
  328. float actualOvercast = m_Weather.GetOvercast().GetActual();
  329. m_Chance = Math.RandomIntInclusive( 0, 100 );
  330. phmnValue = 0.2;
  331. phmnTime = 90;
  332. phmnLength = 20;
  333. if ( actualOvercast <= m_WeatherDefaultSettings.m_SnowfallThreshold )
  334. {
  335. m_Weather.GetSnowfall().Set( 0.0, m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMin );
  336. CalculateVolFog(0.0, m_Weather.GetWindMagnitude().GetForecast(), phmnTime);
  337. Debug.WeatherLog(string.Format("Sakhal::Weather::Snow::ForceEnd:: (%1) %2 -> 0", g_Game.GetDayTime(), actual));
  338. return true;
  339. }
  340. if ( actualOvercast > m_WeatherDefaultSettings.m_ThundersnowThreshold )
  341. {
  342. phmnValue = Math.RandomFloatInclusive( 0.8, 1.0 );
  343. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax ) * 0.5;
  344. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax ) * 1.2;
  345. m_Weather.GetSnowfall().Set( phmnValue, phmnTime, phmnLength );
  346. CalculateVolFog(phmnValue, m_Weather.GetWindMagnitude().GetForecast(), phmnTime);
  347. Debug.WeatherLog(string.Format("Sakhal::Weather::Snow::ForceStorm:: (%1) %2 -> %3", g_Game.GetDayTime(), actual, phmnValue));
  348. return true;
  349. }
  350. if ( actualOvercast == m_Weather.GetOvercast().GetForecast() && m_Weather.GetSnowfall().GetActual() >= 0.8 && m_Weather.GetWindSpeed() >= 10 ) //if overcast is not changing and there was high snowfall
  351. {
  352. phmnValue = Math.RandomFloatInclusive( 0.2, 0.4 );
  353. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax ) * 0.5;
  354. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax ) * 1.2;
  355. m_Weather.GetWindMagnitude().Set(m_Weather.GetWindMagnitude().GetActual() * 0.2, phmnTime , phmnLength); // next change will be happen in phenomenon change and reset the wind speed
  356. m_Weather.GetSnowfall().Set( phmnValue, phmnTime, phmnLength );
  357. CalculateVolFog(phmnValue, m_Weather.GetWindMagnitude().GetForecast(), phmnTime);
  358. Debug.WeatherLog(string.Format("Sakhal::Weather::Snow::ForceStorm:: (%1) %2 -> %3", g_Game.GetDayTime(), actual, phmnValue));
  359. return true;
  360. }
  361. if ( actualOvercast < 0.6 ) //snowfall treshold to 0.6 overcast, snowfall in this bracket does not increase wetness
  362. {
  363. if ( m_Chance < 40 )
  364. {
  365. phmnValue = Math.RandomFloatInclusive( 0.02, 0.4 );
  366. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  367. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax ) * 1.2;
  368. }
  369. else //also have the chance to not have snow at all
  370. {
  371. phmnValue = 0;
  372. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  373. phmnLength = Math.RandomIntInclusive(m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax) * 2;
  374. }
  375. }
  376. else if ( actualOvercast < 0.75 ) //0.6 to 0.75 overcast
  377. {
  378. if ( m_Chance < 30 )
  379. {
  380. phmnValue = Math.RandomFloatInclusive( 0.5, 0.8 );
  381. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  382. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax );
  383. }
  384. else if ( m_Chance < 60 )
  385. {
  386. phmnValue = Math.RandomFloat( 0.3, 0.5 ); //0.5 snowfall starts to increase wetness
  387. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  388. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax );
  389. }
  390. else if ( m_Chance < 75 )
  391. {
  392. phmnValue = Math.RandomFloatInclusive( 0.02, 0.3 );
  393. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  394. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax );
  395. }
  396. else //also have the chance to not have snow at all
  397. {
  398. if ( m_IsSuddenChange )
  399. {
  400. phmnValue = Math.RandomFloat( 0.3, 0.5 ); //0.5 snowfall starts to increase wetness
  401. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  402. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax );
  403. }
  404. else
  405. {
  406. phmnValue = 0;
  407. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  408. phmnLength = Math.RandomIntInclusive(m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax) * 1.2;
  409. }
  410. }
  411. }
  412. else //0.75 to thunderstorm threshold overcast
  413. {
  414. if ( m_Chance < 35 )
  415. {
  416. phmnValue = Math.RandomFloatInclusive( 0.7, 1.0 );
  417. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  418. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax );
  419. }
  420. else if ( m_Chance < 75 )
  421. {
  422. phmnValue = Math.RandomFloatInclusive( 0.5, 0.7 );
  423. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  424. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax ) ;
  425. }
  426. else if ( m_Chance < 85 )
  427. {
  428. phmnValue = Math.RandomFloat( 0.2, 0.5 ); //0.5 snowfall starts to increase wetness
  429. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  430. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax );
  431. }
  432. else
  433. {
  434. if ( m_IsSuddenChange )
  435. {
  436. phmnValue = Math.RandomFloat( 0.5, 0.7 ); //0.5 snowfall starts to increase wetness
  437. phmnTime = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  438. phmnLength = Math.RandomIntInclusive( m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax );
  439. }
  440. else
  441. {
  442. phmnValue = Math.RandomFloat( 0.02, 0.1 );
  443. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  444. phmnLength = Math.RandomIntInclusive(m_WeatherDefaultSettings.m_SnowfallLengthMin, m_WeatherDefaultSettings.m_SnowfallLengthMax) * 1.2;
  445. }
  446. }
  447. }
  448. m_Weather.GetSnowfall().Set( phmnValue, phmnTime, phmnLength );
  449. CalculateVolFog(phmnValue, m_Weather.GetWindMagnitude().GetForecast(), phmnTime);
  450. Debug.WeatherLog(string.Format("Sakhal::Weather::Snow:: (%1) %2", g_Game.GetDayTime(), actual));
  451. return true;
  452. }
  453. //-----------------------------------------------------------------------------------------------------------------------------
  454. case EWeatherPhenomenon.FOG:
  455. {
  456. m_Weather.GetFog().Set(0,0,100000);
  457. return true;
  458. /*float fogMin = 0.0;
  459. float fogMax = 0.15;
  460. float fogTime = 1800.0;
  461. if ( m_Weather.GetWindSpeed() >= 10 )
  462. {
  463. m_Weather.GetFog().Set( 0, 300, 0);
  464. Debug.WeatherLog(string.Format("Sakhal::Weather::Fog:: (%1) %2", g_Game.GetDayTime(), actual));
  465. return true;
  466. }
  467. if ( m_Weather.GetOvercast().GetActual() < 0.3 )
  468. {
  469. fogMin = 0.0;
  470. fogMax = 0.1;
  471. fogTime = 600.0;
  472. }
  473. else if ( m_Weather.GetOvercast().GetActual() > 0.6 )
  474. {
  475. fogMin = 0.1;
  476. fogMax = 0.3;
  477. fogTime = 600.0;
  478. }
  479. else
  480. {
  481. fogMin = 0.0;
  482. fogMax = 0.15;
  483. fogTime = 600.0;
  484. }
  485. m_Weather.GetFog().Set( Math.RandomFloatInclusive( fogMin, fogMax ), fogTime, 0);
  486. Debug.WeatherLog(string.Format("Sakhal::Weather::Fog:: (%1) %2", g_Game.GetDayTime(), actual));
  487. return true;*/
  488. }
  489. //-----------------------------------------------------------------------------------------------------------------------------
  490. case EWeatherPhenomenon.WIND_MAGNITUDE:
  491. {
  492. phmnTime = Math.RandomInt( m_WeatherDefaultSettings.m_SnowfallTimeMin, m_WeatherDefaultSettings.m_SnowfallTimeMax );
  493. m_Weather.GetWindMagnitude().Set(m_Weather.GetWindMagnitude().GetActual() / 0.2, phmnTime , m_WeatherDefaultSettings.m_OvercastMaxTime + 1000); // next change will be happen with the overcast or snowfall change
  494. CalculateVolFog(m_Weather.GetSnowfall().GetForecast(), m_Weather.GetWindMagnitude().GetForecast(), phmnTime);
  495. return true;
  496. }
  497. }
  498. return false;
  499. }
  500. protected override void CalculateWind(int newWeather, bool suddenChange, out float magnitude, out float direction)
  501. {
  502. magnitude = 5;
  503. direction = 0;
  504. float windChance = Math.RandomIntInclusive( 0, 100 );
  505. if ( newWeather == WorldDataWeatherConstants.CLEAR_WEATHER )
  506. {
  507. if ( windChance < 15 )
  508. {
  509. magnitude = Math.RandomFloatInclusive( 2 , 4 );
  510. direction = Math.RandomFloatInclusive( -0.35 , 0.35);
  511. }
  512. else if ( windChance < 90 )
  513. {
  514. magnitude = Math.RandomFloatInclusive( 3 , 6 );
  515. direction = Math.RandomFloatInclusive( 0 , 2.2);
  516. }
  517. else
  518. {
  519. magnitude = Math.RandomFloatInclusive( 8 , 15 );
  520. direction = Math.RandomFloatInclusive( -3.0 , -2.25);
  521. }
  522. }
  523. else if ( newWeather == WorldDataWeatherConstants.CLOUDY_WEATHER )
  524. {
  525. if ( windChance < 45 )
  526. {
  527. magnitude = Math.RandomFloatInclusive( 5 , 10 );
  528. direction = Math.RandomFloatInclusive( 1.0 , 1.25);
  529. }
  530. else if ( windChance < 90 )
  531. {
  532. magnitude = Math.RandomFloatInclusive( 8 , 14 );
  533. direction = Math.RandomFloatInclusive( -1.8, -1.4);
  534. }
  535. else
  536. {
  537. magnitude = Math.RandomFloatInclusive( 2 , 4 );
  538. direction = Math.RandomFloatInclusive( -1.0 , -0.4);
  539. }
  540. }
  541. else
  542. {
  543. if ( suddenChange || m_Weather.GetOvercast().GetForecast() > 0.85 )
  544. {
  545. magnitude = Math.RandomFloatInclusive( 18 , 20 );
  546. direction = Math.RandomFloatInclusive( 2.25 , 3.14);
  547. }
  548. else if ( windChance < 45 )
  549. {
  550. magnitude = Math.RandomFloatInclusive( 6 , 12 );
  551. direction = Math.RandomFloatInclusive( -1.8 , -1.4);
  552. }
  553. else if ( windChance < 90 )
  554. {
  555. magnitude = Math.RandomFloatInclusive( 8 , 20 );
  556. direction = Math.RandomFloatInclusive( 1.6 , 2.0);
  557. }
  558. else
  559. {
  560. magnitude = Math.RandomFloatInclusive( 4 , 10 );
  561. direction = Math.RandomFloatInclusive( 1.5, 1.75 );
  562. }
  563. }
  564. CalculateVolFog(m_Weather.GetSnowfall().GetForecast(), magnitude, 60);
  565. }
  566. protected override void CalculateVolFog(float lerpValue, float windMagnitude, float changeTime)// in sakhal volfog supports snowfall effect
  567. {
  568. float maxVolFogDistanceDensity = Math.Lerp( 0, 0.35, Easing.EaseInQuart(lerpValue) );
  569. float minVolFogDistanceDensity = Math.Lerp(0.001, 0.01, m_Weather.GetOvercast().GetActual());
  570. if (minVolFogDistanceDensity > maxVolFogDistanceDensity)
  571. maxVolFogDistanceDensity = minVolFogDistanceDensity;
  572. float volFogDistanceDensity = Math.Lerp( minVolFogDistanceDensity, maxVolFogDistanceDensity, windMagnitude/m_Weather.GetWindMaximumSpeed() );
  573. m_Weather.SetDynVolFogDistanceDensity(volFogDistanceDensity, changeTime);
  574. }
  575. override float GetAgentSpawnChance(eAgents agent)
  576. {
  577. if (agent == eAgents.CHOLERA)
  578. return SPAWN_CHANCE_CHOLERA;
  579. return 0;
  580. }
  581. override float GetColdAreaToolDamageModifier()
  582. {
  583. return COLD_AREA_TOOL_DMG_MODIF;
  584. }
  585. bool LogWeatherData() //called from mission file to check if the logging should start
  586. {
  587. #ifdef WEATHER_DATA_LOGGING
  588. return true;
  589. #endif
  590. return false;
  591. }
  592. //! DEPRECATED (see WorldDataWeatherConstants)
  593. const int CLEAR_WEATHER = 1;
  594. const int CLOUDY_WEATHER = 2;
  595. const int BAD_WEATHER = 3;
  596. }