Advertisement
Guest User

Untitled

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