Advertisement
Guest User

dynamic weather

a guest
Nov 1st, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.81 KB | None | 0 0
  1. /* DynamicWeatherEffects.sqf version 1.01 by Engima of Ostgota Ops
  2. * Description:
  3. * Script that generates dynamic (random) weather. Works in single player, multiplayer (hosted and dedicated), and is JIP compatible.
  4. * Arguments:
  5. * [_initialFog]: Optional. Fog when mission starts. Must be between 0 and 1 where 0 = no fog, 1 = maximum fog. -1 = random fog.
  6. * [_initialOvercast]: Optional. Overcast when mission starts. Must be between 0 and 1 where 0 = no overcast, 1 = maximum overcast. -1 = random overcast.
  7. * [_initialRain]: Optional. Rain when mission starts. Must be between 0 and 1 where 0 = no rain, 1 = maximum rain. -1 = random rain. (Overcast must be greater than or equal to 0.75).
  8. * [_initialWind]: Optional. Wind when mission starts. Must be an array of form [x, z], where x is one wind strength vector and z is the other. x and z must be greater than or equal to 0. [-1, -1] = random wind.
  9. * [_debug]: Optional. true if debug text is to be shown, otherwise false.
  10. */
  11.  
  12. private ["_initialFog", "_initialOvercast", "_initialRain", "_initialWind", "_debug"];
  13. private ["_minWeatherChangeTimeMin", "_maxWeatherChangeTimeMin", "_minTimeBetweenWeatherChangesMin", "_maxTimeBetweenWeatherChangesMin", "_rainIntervalRainProbability", "_windChangeProbability"];
  14. private ["_minimumFog", "_maximumFog", "_minimumOvercast", "_maximumOvercast", "_minimumRain", "_maximumRain", "_minimumWind", "_maximumWind", "_minRainIntervalTimeMin", "_maxRainIntervalTimeMin", "_forceRainToStopAfterOneRainInterval", "_maxWind"];
  15.  
  16. if (isNil "_this") then { _this = []; };
  17. if (count _this > 0) then { _initialFog = _this select 0; } else { _initialFog = -1; };
  18. if (count _this > 1) then { _initialOvercast = _this select 1; } else { _initialOvercast = -1; };
  19. if (count _this > 2) then { _initialRain = _this select 2; } else { _initialRain = -1; };
  20. if (count _this > 3) then { _initialWind = _this select 3; } else { _initialWind = [-1, -1]; };
  21. if (count _this > 4) then { _debug = _this select 4; } else { _debug = false; };
  22.  
  23. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  24. // The following variables can be changed to tweak weather behaviour
  25.  
  26. // Minimum time in minutes for the weather (fog and overcast) to change. Must be greater than or equal to 1 and less than or equal to
  27. // _maxWeatherChangeTimeMin. When weather changes, it is fog OR overcast that changes, not both at the same time. (Suggested value: 10).
  28. _minWeatherChangeTimeMin = 10;
  29.  
  30. // Maximum time in minutes for the weather (fog and overcast) to change. Must be greater than or equal to _minWeatherChangeTimeMin.
  31. // (Suggested value: 20).
  32. _maxWeatherChangeTimeMin = 20;
  33.  
  34. // Minimum time in minutes that weather (fog and overcast) stays constant between weather changes. Must be less than or equal to 0 and
  35. // greater than or equal to _minWeatherChangeTimeMin. (Suggested value: 5).
  36. _minTimeBetweenWeatherChangesMin = 5;
  37.  
  38. // Maximum time in minutes that weather (fog and overcast) stays unchanged between weather changes. Must be greater than or equal to
  39. // _minWeatherChangeTimeMin. (Suggested value: 10).
  40. _maxTimeBetweenWeatherChangesMin = 10;
  41.  
  42. // Fog intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumFog
  43. // (0 = no fog, 1 = pea soup). (Suggested value: 0).
  44. _minimumFog = 0;
  45.  
  46. // Fog intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumFog
  47. // (0 = no fog, 1 = pea soup). (Suggested value: 0.8).
  48. _maximumFog = 0.5;
  49.  
  50. // Overcast intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumOvercast
  51. // (0 = no overcast, 1 = maximum overcast). (Suggested value: 0).
  52. _minimumOvercast = 0;
  53.  
  54. // Overcast intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumOvercast
  55. // (0 = no overcast, 1 = maximum overcast). (Suggested value: 1).
  56. _maximumOvercast = 1;
  57.  
  58. // When raining, rain intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumRain
  59. // (0 = no rain, 1 = maximum rain intensity). (Suggested value: 0);
  60. _minimumRain = 0;
  61.  
  62. // When raining, rain intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumRain
  63. // (0 = no rain, 1 = maximum rain intensity). (Suggested value: 0.8);
  64. _maximumRain = 0.8;
  65.  
  66. // Wind vector strength never falls below this value. Must be greater or equal to 0 and less than or equal to _maximumWind.
  67. // (Suggested value: 0);
  68. _minimumWind = 0;
  69.  
  70. // Wind vector strength never exceeds this value. Must be greater or equal to 0 and greater than or equal to _minimumWind.
  71. // (Suggested value: 8).
  72. _maximumWind = 8;
  73.  
  74. // Probability in percent for wind to change when weather changes. If set to 0 then wind will never change. If set to 100 then rain will
  75. // change every time the weather (fog or overcast) start to change. (Suggested value: 25);
  76. _windChangeProbability = 25;
  77.  
  78. // A "rain interval" is defined as "a time interval during which it may rain in any intensity (or it may not rain at all)". When overcast
  79. // goes above 0.75, a chain of rain intervals (defined below) is started. It cycles on until overcast falls below 0.75. At overcast
  80. // below 0.75 rain intervals never execute (thus it cannot rain).
  81.  
  82. // Probability in percent (0-100) for rain to start at every rain interval. Set this to 0 if you don't want rain at all. Set this to 100
  83. // if you want it to rain constantly when overcast is greater than 0.75. In short: if you think that it generally rains to often then
  84. // lower this value and vice versa. (Suggested value: 50).
  85. _rainIntervalRainProbability = 50;
  86.  
  87. // Minimum time in minutes for rain intervals. Must be greater or equal to 0 and less than or equal to _maxRainIntervalTimeMin.
  88. // (Suggested value: 0).
  89. _minRainIntervalTimeMin = 0;
  90.  
  91. // Maximum time in minutes for rain intervals. Must be greater than or equal to _minRainIntervalTimeMin. (Suggested value:
  92. // (_maxWeatherChangeTimeMin + _maxTimeBetweenWeatherChangesMin) / 2).
  93. _maxRainIntervalTimeMin = (_maxWeatherChangeTimeMin + _maxTimeBetweenWeatherChangesMin) / 2;
  94.  
  95. // If set to true, then the rain is forced to stop after one rain interval during which it has rained (use this for example if you only want
  96. // small occational cloudbursts ). If set to false, then the rain may stop, but it may also just change intensity for an
  97. // immedeate new rain interval. (Suggested value: false).
  98. _forceRainToStopAfterOneRainInterval = false;
  99.  
  100.  
  101. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. // Don't touch anything beneath this line
  103.  
  104. drn_DynamicWeather_DebugTextEventArgs = []; // Empty
  105.  
  106. "drn_DynamicWeather_DebugTextEventArgs" addPublicVariableEventHandler {
  107. drn_DynamicWeather_DebugTextEventArgs call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  108. };
  109.  
  110. /*
  111. * Summary: Shows debug text on local client.
  112. * Arguments:
  113. * _text: Debug text.
  114. */
  115. drn_fnc_DynamicWeather_ShowDebugTextLocal = {
  116. private ["_minutes", "_seconds"];
  117.  
  118. if (!isNull player) then {
  119. player sideChat (_this select 0);
  120. };
  121.  
  122. _minutes = floor (time / 60);
  123. _seconds = floor (time - (_minutes * 60));
  124. diag_log ((str _minutes + ":" + str _seconds) + " Debug: " + (_this select 0));
  125. };
  126.  
  127. /*
  128. * Summary: Shows debug text on all clients.
  129. * Arguments:
  130. * _text: Debug text.
  131. */
  132. drn_fnc_DynamicWeather_ShowDebugTextAllClients = {
  133. drn_DynamicWeather_DebugTextEventArgs = _this;
  134. publicVariable "drn_DynamicWeather_DebugTextEventArgs";
  135. drn_DynamicWeather_DebugTextEventArgs call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  136. };
  137.  
  138. if (_debug) then {
  139. ["Starting script WeatherEffects.sqf..."] call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  140. };
  141.  
  142. drn_DynamicWeatherEventArgs = []; // [current overcast, current fog, current rain, current weather change ("OVERCAST", "FOG" or ""), target weather value, time until weather completion (in seconds), current wind x, current wind z]
  143. drn_AskServerDynamicWeatherEventArgs = []; // []
  144.  
  145. drn_fnc_DynamicWeather_SetWeatherLocal = {
  146. private ["_currentOvercast", "_currentFog", "_currentRain", "_currentWeatherChange", "_targetWeatherValue", "_timeUntilCompletion", "_currentWindX", "_currentWindZ"];
  147.  
  148. if(daytime<6||daytime>18)then {
  149. _currentOvercast = 0;
  150. _currentFog = 0;
  151. _currentRain = 0;
  152. _currentWeatherChange = _this select 3;
  153. _targetWeatherValue = _this select 4;
  154. _timeUntilCompletion = _this select 5;
  155. _currentWindX = _this select 6;
  156. _currentWindZ = _this select 7;
  157. }
  158. else {
  159. _currentOvercast = _this select 0;
  160. _currentFog = _this select 1;
  161. _currentRain = _this select 2;
  162. _currentWeatherChange = _this select 3;
  163. _targetWeatherValue = _this select 4;
  164. _timeUntilCompletion = _this select 5;
  165. _currentWindX = _this select 6;
  166. _currentWindZ = _this select 7;
  167. };
  168.  
  169. // Set current weather values
  170. 0 setOvercast _currentOvercast;
  171. 0 setFog _currentFog;
  172. drn_var_DynamicWeather_Rain = _currentRain;
  173. setWind [_currentWindX, _currentWindZ, true];
  174.  
  175. // Set forecast
  176. if (_currentWeatherChange == "OVERCAST") then {
  177. _timeUntilCompletion setOvercast _targetWeatherValue;
  178. };
  179. if (_currentWeatherChange == "FOG") then {
  180. _timeUntilCompletion setFog _targetWeatherValue;
  181. };
  182. };
  183.  
  184. if (!isServer) then {
  185. "drn_DynamicWeatherEventArgs" addPublicVariableEventHandler {
  186. drn_DynamicWeatherEventArgs call drn_fnc_DynamicWeather_SetWeatherLocal;
  187. };
  188.  
  189. waitUntil {!isNil "drn_var_DynamicWeather_ServerInitialized"};
  190.  
  191. drn_AskServerDynamicWeatherEventArgs = [true];
  192. publicVariable "drn_AskServerDynamicWeatherEventArgs";
  193. };
  194.  
  195. if (isServer) then {
  196. drn_fnc_DynamicWeather_SetWeatherAllClients = {
  197. private ["_timeUntilCompletion", "_currentWeatherChange"];
  198.  
  199. _timeUntilCompletion = drn_DynamicWeather_WeatherChangeCompletedTime - drn_DynamicWeather_WeatherChangeStartedTime;
  200. if (_timeUntilCompletion > 0) then {
  201. _currentWeatherChange = drn_DynamicWeather_CurrentWeatherChange;
  202. }
  203. else {
  204. _currentWeatherChange = "";
  205. };
  206.  
  207. drn_DynamicWeatherEventArgs = [overcast, fog, drn_var_DynamicWeather_Rain, _currentWeatherChange, drn_DynamicWeather_WeatherTargetValue, _timeUntilCompletion, drn_DynamicWeather_WindX, drn_DynamicWeather_WindZ];
  208. publicVariable "drn_DynamicWeatherEventArgs";
  209. drn_DynamicWeatherEventArgs call drn_fnc_DynamicWeather_SetWeatherLocal;
  210. };
  211.  
  212. "drn_AskServerDynamicWeatherEventArgs" addPublicVariableEventHandler {
  213. call drn_fnc_DynamicWeather_SetWeatherAllClients;
  214. };
  215.  
  216. drn_DynamicWeather_CurrentWeatherChange = "";
  217. drn_DynamicWeather_WeatherTargetValue = 0;
  218. drn_DynamicWeather_WeatherChangeStartedTime = time;
  219. drn_DynamicWeather_WeatherChangeCompletedTime = time;
  220. drn_DynamicWeather_WindX = _initialWind select 0;
  221. drn_DynamicWeather_WindZ = _initialWind select 1;
  222.  
  223. if (_initialFog == -1) then {
  224. _initialFog = (_minimumFog + random (_maximumFog - _minimumFog));
  225. }
  226. else {
  227. if (_initialFog < _minimumFog) then {
  228. _initialFog = _minimumFog;
  229. };
  230. if (_initialFog > _maximumFog) then {
  231. _initialFog = _maximumFog;
  232. };
  233. };
  234.  
  235. 0 setFog _initialFog;
  236.  
  237. if (_initialOvercast == -1) then {
  238. _initialOvercast = (_minimumOvercast + random (_maximumOvercast - _minimumOvercast));
  239. }
  240. else {
  241. if (_initialOvercast < _minimumOvercast) then {
  242. _initialOvercast = _minimumOvercast;
  243. };
  244. if (_initialOvercast > _maximumOvercast) then {
  245. _initialOvercast = _maximumOvercast;
  246. };
  247. };
  248.  
  249. 0 setOvercast _initialOvercast;
  250.  
  251. if (_initialOvercast >= 0.75) then {
  252. if (_initialRain == -1) then {
  253. _initialRain = (_minimumRain + random (_minimumRain - _minimumRain));
  254. }
  255. else {
  256. if (_initialRain < _minimumRain) then {
  257. _initialRain = _minimumRain;
  258. };
  259. if (_initialRain > _maximumRain) then {
  260. _initialRain = _maximumRain;
  261. };
  262. };
  263. }
  264. else {
  265. _initialRain = 0;
  266. };
  267.  
  268. drn_var_DynamicWeather_Rain = _initialRain;
  269. 0 setRain drn_var_DynamicWeather_Rain;
  270.  
  271. _maxWind = _minimumWind + random (_maximumWind - _minimumWind);
  272.  
  273. if (drn_DynamicWeather_WindX == -1) then {
  274. if (random 100 < 50) then {
  275. drn_DynamicWeather_WindX = -_minimumWind - random (_maxWind - _minimumWind);
  276. }
  277. else {
  278. drn_DynamicWeather_WindX = _minimumWind + random (_maxWind - _minimumWind);
  279. };
  280. };
  281.  
  282. if (drn_DynamicWeather_WindZ == -1) then {
  283. if (random 100 < 50) then {
  284. drn_DynamicWeather_WindZ = -_minimumWind - random (_maxWind - _minimumWind);
  285. }
  286. else {
  287. drn_DynamicWeather_WindZ = _minimumWind + random (_maxWind - _minimumWind);
  288. };
  289. };
  290.  
  291. setWind [drn_DynamicWeather_WindX, drn_DynamicWeather_WindZ, true];
  292.  
  293. sleep 0.05;
  294.  
  295. publicVariable "drn_var_DynamicWeather_Rain";
  296. drn_var_DynamicWeather_ServerInitialized = true;
  297. publicVariable "drn_var_DynamicWeather_ServerInitialized";
  298.  
  299. // Start weather thread
  300. [_minWeatherChangeTimeMin, _maxWeatherChangeTimeMin, _minTimeBetweenWeatherChangesMin, _maxTimeBetweenWeatherChangesMin, _minimumFog, _maximumFog, _minimumOvercast, _maximumOvercast, _minimumWind, _maximumWind, _windChangeProbability, _debug] spawn {
  301. private ["_minWeatherChangeTimeMin", "_maxWeatherChangeTimeMin", "_minTimeBetweenWeatherChangesMin", "_maxTimeBetweenWeatherChangesMin", "_minimumFog", "_maximumFog", "_minimumOvercast", "_maximumOvercast", "_minimumWind", "_maximumWind", "_windChangeProbability", "_debug"];
  302. private ["_weatherType", "_fogLevel", "_overcastLevel", "_oldFogLevel", "_oldOvercastLevel", "_weatherChangeTimeSek"];
  303.  
  304. _minWeatherChangeTimeMin = _this select 0;
  305. _maxWeatherChangeTimeMin = _this select 1;
  306. _minTimeBetweenWeatherChangesMin = _this select 2;
  307. _maxTimeBetweenWeatherChangesMin = _this select 3;
  308. _minimumFog = _this select 4;
  309. _maximumFog = _this select 5;
  310. _minimumOvercast = _this select 6;
  311. _maximumOvercast = _this select 7;
  312. _minimumWind = _this select 8;
  313. _maximumWind = _this select 9;
  314. _windChangeProbability = _this select 10;
  315. _debug = _this select 11;
  316.  
  317. // Set initial fog level
  318. _fogLevel = 2;
  319. _overcastLevel = 2;
  320.  
  321. while {true} do {
  322. // Sleep a while until next weather change
  323. sleep floor (_minTimeBetweenWeatherChangesMin * 60 + random ((_maxTimeBetweenWeatherChangesMin - _minTimeBetweenWeatherChangesMin) * 60));
  324.  
  325. if (_minimumFog == _maximumFog && _minimumOvercast != _maximumOvercast) then {
  326. _weatherType = "OVERCAST";
  327. };
  328. if (_minimumFog != _maximumFog && _minimumOvercast == _maximumOvercast) then {
  329. _weatherType = "FOG";
  330. };
  331. if (_minimumFog != _maximumFog && _minimumOvercast != _maximumOvercast) then {
  332.  
  333. // Select type of weather to change
  334. if ((random 100) < 50) then {
  335. _weatherType = "OVERCAST";
  336. }
  337. else {
  338. _weatherType = "FOG";
  339. };
  340. };
  341.  
  342. // DEBUG
  343. //_weatherType = "OVERCAST";
  344.  
  345. if (_weatherType == "FOG") then {
  346.  
  347. drn_DynamicWeather_CurrentWeatherChange = "FOG";
  348.  
  349. // Select a new fog level
  350. _oldFogLevel = _fogLevel;
  351. _fogLevel = floor ((random 100) / 25);
  352.  
  353. while {_fogLevel == _oldFogLevel} do {
  354. _fogLevel = floor ((random 100) / 25);
  355. };
  356.  
  357. if (_fogLevel == 0) then {
  358. drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * random 0.05;
  359. };
  360. if (_fogLevel == 1) then {
  361. drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.05 + random 0.2);
  362. };
  363. if (_fogLevel == 2) then {
  364. drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.25 + random 0.3);
  365. };
  366. if (_fogLevel == 3) then {
  367. drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.55 + random 0.45);
  368. };
  369.  
  370. drn_DynamicWeather_WeatherChangeStartedTime = time;
  371. _weatherChangeTimeSek = _minWeatherChangeTimeMin * 60 + random ((_maxWeatherChangeTimeMin - _minWeatherChangeTimeMin) * 60);
  372. drn_DynamicWeather_WeatherChangeCompletedTime = time + _weatherChangeTimeSek;
  373.  
  374. if (_debug) then {
  375. ["Weather forecast: Fog " + str drn_DynamicWeather_WeatherTargetValue + " in " + str round (_weatherChangeTimeSek / 60) + " minutes."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  376. };
  377. };
  378.  
  379. if (_weatherType == "OVERCAST") then {
  380.  
  381. drn_DynamicWeather_CurrentWeatherChange = "OVERCAST";
  382.  
  383. // Select a new overcast level
  384. _oldOvercastLevel = _overcastLevel;
  385. //_overcastLevel = floor ((random 100) / 25);
  386. _overcastLevel = 3;
  387.  
  388. while {_overcastLevel == _oldOvercastLevel} do {
  389. _overcastLevel = floor ((random 100) / 25);
  390. };
  391.  
  392. if (_overcastLevel == 0) then {
  393. drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * random 0.05;
  394. };
  395. if (_overcastLevel == 1) then {
  396. drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.05 + random 0.3);
  397. };
  398. if (_overcastLevel == 2) then {
  399. drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.35 + random 0.35);
  400. };
  401. if (_overcastLevel == 3) then {
  402. drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.7 + random 0.3);
  403. };
  404.  
  405. // DEBUG
  406. /*
  407. if (overcast > 0.8) then {
  408. drn_DynamicWeather_WeatherTargetValue = 0.5;
  409. }
  410. else {
  411. drn_DynamicWeather_WeatherTargetValue = 0.85;
  412. };
  413. */
  414.  
  415. drn_DynamicWeather_WeatherChangeStartedTime = time;
  416. _weatherChangeTimeSek = _minWeatherChangeTimeMin * 60 + random ((_maxWeatherChangeTimeMin - _minWeatherChangeTimeMin) * 60);
  417. drn_DynamicWeather_WeatherChangeCompletedTime = time + _weatherChangeTimeSek;
  418.  
  419. if (_debug) then {
  420. ["Weather forecast: Overcast " + str drn_DynamicWeather_WeatherTargetValue + " in " + str round (_weatherChangeTimeSek / 60) + " minutes."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  421. };
  422. };
  423.  
  424. // On average every one fourth of weather changes, change wind too
  425. if (random 100 < _windChangeProbability) then {
  426. private ["_maxWind"];
  427.  
  428. _maxWind = _minimumWind + random (_maximumWind - _minimumWind);
  429.  
  430. if (random 100 < 50) then {
  431. drn_DynamicWeather_WindX = -_minimumWind - random (_maxWind - _minimumWind);
  432. }
  433. else {
  434. drn_DynamicWeather_WindX = _minimumWind + random (_maxWind - _minimumWind);
  435. };
  436. if (random 100 < 50) then {
  437. drn_DynamicWeather_WindZ = -_minimumWind - random (_maxWind - _minimumWind);
  438. }
  439. else {
  440. drn_DynamicWeather_WindZ = _minimumWind + random (_maxWind - _minimumWind);
  441. };
  442.  
  443. if (_debug) then {
  444. ["Wind changes: [" + str drn_DynamicWeather_WindX + ", " + str drn_DynamicWeather_WindZ + "]."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  445. };
  446. };
  447.  
  448. call drn_fnc_DynamicWeather_SetWeatherAllClients;
  449.  
  450. sleep _weatherChangeTimeSek;
  451. };
  452. };
  453.  
  454. // Start rain thread
  455. if (_rainIntervalRainProbability > 0) then {
  456. [_minimumRain, _maximumRain, _forceRainToStopAfterOneRainInterval, _minRainIntervalTimeMin, _maxRainIntervalTimeMin, _rainIntervalRainProbability, _debug] spawn {
  457. private ["_minimumRain", "_maximumRain", "_forceRainToStopAfterOneRainInterval", "_minRainIntervalTimeMin", "_maxRainIntervalTimeMin", "_rainIntervalRainProbability", "_debug"];
  458. private ["_nextRainEventTime", "_forceStop"];
  459.  
  460. _minimumRain = _this select 0;
  461. _maximumRain = _this select 1;
  462. _forceRainToStopAfterOneRainInterval = _this select 2;
  463. _minRainIntervalTimeMin = _this select 3;
  464. _maxRainIntervalTimeMin = _this select 4;
  465. _rainIntervalRainProbability = _this select 5;
  466. _debug = _this select 6;
  467.  
  468. if (rain > 0) then {
  469. drn_var_DynamicWeather_Rain = rain;
  470. publicVariable "drn_var_DynamicWeather_Rain";
  471. };
  472.  
  473. _nextRainEventTime = time;
  474. _forceStop = false;
  475.  
  476. while {true} do {
  477.  
  478. if (overcast > 0.75) then {
  479.  
  480. if (time >= _nextRainEventTime) then {
  481. private ["_rainTimeSec"];
  482.  
  483. // At every rain event time, start or stop rain with 50% probability
  484. if (random 100 < _rainIntervalRainProbability && !_forceStop) then {
  485. drn_var_DynamicWeather_rain = _minimumRain + random (_maximumRain - _minimumRain);
  486. publicVariable "drn_var_DynamicWeather_rain";
  487.  
  488. _forceStop = _forceRainToStopAfterOneRainInterval;
  489. }
  490. else {
  491. drn_var_DynamicWeather_rain = 0;
  492. publicVariable "drn_var_DynamicWeather_rain";
  493.  
  494. _forceStop = false;
  495. };
  496.  
  497. // Pick a time for next rain change
  498. _rainTimeSec = _minRainIntervalTimeMin * 60 + random ((_maxRainIntervalTimeMin - _minRainIntervalTimeMin) * 60);
  499. _nextRainEventTime = time + _rainTimeSec;
  500.  
  501. if (_debug) then {
  502. ["Rain set to " + str drn_var_DynamicWeather_rain + " for " + str (_rainTimeSec / 60) + " minutes"] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  503. };
  504. };
  505. }
  506. else {
  507. if (drn_var_DynamicWeather_rain != 0) then {
  508. drn_var_DynamicWeather_rain = 0;
  509. publicVariable "drn_var_DynamicWeather_rain";
  510.  
  511. if (_debug) then {
  512. ["Rain stops due to low overcast."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  513. };
  514. };
  515.  
  516. _nextRainEventTime = time;
  517. _forceStop = false;
  518. };
  519.  
  520. if (_debug) then {
  521. sleep 1;
  522. }
  523. else {
  524. sleep 10;
  525. };
  526. };
  527. };
  528. };
  529. };
  530.  
  531. [_rainIntervalRainProbability, _debug] spawn {
  532. private ["_rainIntervalRainProbability", "_debug"];
  533. private ["_rain", "_rainPerSecond"];
  534.  
  535. _rainIntervalRainProbability = _this select 0;
  536. _debug = _this select 1;
  537.  
  538. if (_debug) then {
  539. _rainPerSecond = 0.2;
  540. }
  541. else {
  542. _rainPerSecond = 0.03;
  543. };
  544.  
  545. if (_rainIntervalRainProbability > 0) then {
  546. _rain = drn_var_DynamicWeather_Rain;
  547. }
  548. else {
  549. _rain = 0;
  550. };
  551.  
  552. 0 setRain _rain;
  553. sleep 0.1;
  554.  
  555. while {true} do {
  556. if (_rainIntervalRainProbability > 0) then {
  557. if (_rain < drn_var_DynamicWeather_Rain) then {
  558. _rain = _rain + _rainPerSecond;
  559. if (_rain > 1) then { _rain = 1; };
  560. };
  561. if (_rain > drn_var_DynamicWeather_Rain) then {
  562. _rain = _rain - _rainPerSecond;
  563. if (_rain < 0) then { _rain = 0; };
  564. };
  565. }
  566. else {
  567. _rain = 0;
  568. };
  569.  
  570. 3 setRain _rain;
  571.  
  572. sleep 3;
  573. };
  574. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement