Advertisement
Guest User

Untitled

a guest
Oct 24th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.48 KB | None | 0 0
  1. [CODE]/* DynamicWeatherEffects.sqf version 1.01 by Engima of Ostgota Ops
  2.  
  3. * Description:
  4.  
  5. * Script that generates dynamic (random) weather. Works in single player, multiplayer (hosted and dedicated), and is JIP compatible.
  6.  
  7. * Arguments:
  8.  
  9. * [_initialFog]: Optional. Fog when mission starts. Must be between 0 and 1 where 0 = no fog, 1 = maximum fog. -1 = random fog.
  10.  
  11. * [_initialOvercast]: Optional. Overcast when mission starts. Must be between 0 and 1 where 0 = no overcast, 1 = maximum overcast. -1 = random overcast.
  12.  
  13. * [_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).
  14.  
  15. * [_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.
  16.  
  17. * [_debug]: Optional. true if debug text is to be shown, otherwise false.
  18.  
  19. */
  20.  
  21.  
  22.  
  23.  
  24. private ["_initialFog", "_initialOvercast", "_initialRain", "_initialWind", "_debug"];
  25.  
  26. private ["_minWeatherChangeTimeMin", "_maxWeatherChangeTimeMin", "_minTimeBetweenWeatherChangesMin", "_maxTimeBetweenWeatherChangesMin", "_rainIntervalRainProbability", "_windChangeProbability"];
  27.  
  28. private ["_minimumFog", "_maximumFog", "_minimumOvercast", "_maximumOvercast", "_minimumRain", "_maximumRain", "_minimumWind", "_maximumWind", "_minRainIntervalTimeMin", "_maxRainIntervalTimeMin", "_forceRainToStopAfterOneRainInterval", "_maxWind"];
  29.  
  30.  
  31.  
  32.  
  33. if (isNil "_this") then { _this = []; };
  34.  
  35. if (count _this > 0) then { _initialFog = _this select 0; } else { _initialFog = -1; };
  36.  
  37. if (count _this > 1) then { _initialOvercast = _this select 1; } else { _initialOvercast = -1; };
  38.  
  39. if (count _this > 2) then { _initialRain = _this select 2; } else { _initialRain = -1; };
  40.  
  41. if (count _this > 3) then { _initialWind = _this select 3; } else { _initialWind = [-1, -1]; };
  42.  
  43. if (count _this > 4) then { _debug = _this select 4; } else { _debug = false; };
  44.  
  45.  
  46.  
  47.  
  48. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49.  
  50. // The following variables can be changed to tweak weather behaviour
  51.  
  52.  
  53.  
  54.  
  55. // 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
  56.  
  57. // _maxWeatherChangeTimeMin. When weather changes, it is fog OR overcast that changes, not both at the same time. (Suggested value: 10).
  58.  
  59. _minWeatherChangeTimeMin = 10;
  60.  
  61.  
  62.  
  63.  
  64. // Maximum time in minutes for the weather (fog and overcast) to change. Must be greater than or equal to _minWeatherChangeTimeMin.
  65.  
  66. // (Suggested value: 20).
  67.  
  68. _maxWeatherChangeTimeMin = 20;
  69.  
  70.  
  71.  
  72.  
  73. // Minimum time in minutes that weather (fog and overcast) stays constant between weather changes. Must be less than or equal to 0 and
  74.  
  75. // greater than or equal to _minWeatherChangeTimeMin. (Suggested value: 5).
  76.  
  77. _minTimeBetweenWeatherChangesMin = 5;
  78.  
  79.  
  80.  
  81.  
  82. // Maximum time in minutes that weather (fog and overcast) stays unchanged between weather changes. Must be greater than or equal to
  83.  
  84. // _minWeatherChangeTimeMin. (Suggested value: 10).
  85.  
  86. _maxTimeBetweenWeatherChangesMin = 10;
  87.  
  88.  
  89.  
  90.  
  91. // Fog intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumFog
  92.  
  93. // (0 = no fog, 1 = pea soup). (Suggested value: 0).
  94.  
  95. _minimumFog = 0;
  96.  
  97.  
  98.  
  99.  
  100. // Fog intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumFog
  101.  
  102. // (0 = no fog, 1 = pea soup). (Suggested value: 0.8).
  103.  
  104. _maximumFog = 0;
  105.  
  106.  
  107.  
  108.  
  109. // Overcast intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumOvercast
  110.  
  111. // (0 = no overcast, 1 = maximum overcast). (Suggested value: 0).
  112.  
  113. _minimumOvercast = 0;
  114.  
  115.  
  116.  
  117.  
  118. // Overcast intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumOvercast
  119.  
  120. // (0 = no overcast, 1 = maximum overcast). (Suggested value: 1).
  121.  
  122. _maximumOvercast = 0;
  123.  
  124.  
  125.  
  126.  
  127. // When raining, rain intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumRain
  128.  
  129. // (0 = no rain, 1 = maximum rain intensity). (Suggested value: 0);
  130.  
  131. _minimumRain = 0;
  132.  
  133.  
  134.  
  135.  
  136. // When raining, rain intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumRain
  137.  
  138. // (0 = no rain, 1 = maximum rain intensity). (Suggested value: 0.8);
  139.  
  140. _maximumRain = 0;
  141.  
  142.  
  143.  
  144.  
  145. // Wind vector strength never falls below this value. Must be greater or equal to 0 and less than or equal to _maximumWind.
  146.  
  147. // (Suggested value: 0);
  148.  
  149. _minimumWind = 0;
  150.  
  151.  
  152.  
  153.  
  154. // Wind vector strength never exceeds this value. Must be greater or equal to 0 and greater than or equal to _minimumWind.
  155.  
  156. // (Suggested value: 8).
  157.  
  158. _maximumWind = 8;
  159.  
  160.  
  161.  
  162.  
  163. // 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
  164.  
  165. // change every time the weather (fog or overcast) start to change. (Suggested value: 25);
  166.  
  167. _windChangeProbability = 25;
  168.  
  169.  
  170.  
  171.  
  172. // 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
  173.  
  174. // goes above 0.75, a chain of rain intervals (defined below) is started. It cycles on until overcast falls below 0.75. At overcast
  175.  
  176. // below 0.75 rain intervals never execute (thus it cannot rain).
  177.  
  178.  
  179.  
  180.  
  181. // 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
  182.  
  183. // 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
  184.  
  185. // lower this value and vice versa. (Suggested value: 50).
  186.  
  187. _rainIntervalRainProbability = 50;
  188.  
  189.  
  190.  
  191.  
  192. // Minimum time in minutes for rain intervals. Must be greater or equal to 0 and less than or equal to _maxRainIntervalTimeMin.
  193.  
  194. // (Suggested value: 0).
  195.  
  196. _minRainIntervalTimeMin = 0;
  197.  
  198.  
  199.  
  200.  
  201. // Maximum time in minutes for rain intervals. Must be greater than or equal to _minRainIntervalTimeMin. (Suggested value:
  202.  
  203. // (_maxWeatherChangeTimeMin + _maxTimeBetweenWeatherChangesMin) / 2).
  204.  
  205. _maxRainIntervalTimeMin = (_maxWeatherChangeTimeMin + _maxTimeBetweenWeatherChangesMin) / 2;
  206.  
  207.  
  208.  
  209.  
  210. // 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
  211.  
  212. // small occational cloudbursts ). If set to false, then the rain may stop, but it may also just change intensity for an
  213.  
  214. // immedeate new rain interval. (Suggested value: false).
  215.  
  216. _forceRainToStopAfterOneRainInterval = false;
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225.  
  226. // Don't touch anything beneath this line
  227.  
  228.  
  229.  
  230.  
  231. drn_DynamicWeather_DebugTextEventArgs = []; // Empty
  232.  
  233.  
  234.  
  235.  
  236. "drn_DynamicWeather_DebugTextEventArgs" addPublicVariableEventHandler {
  237.  
  238. drn_DynamicWeather_DebugTextEventArgs call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  239.  
  240. };
  241.  
  242.  
  243.  
  244.  
  245. /*
  246.  
  247. * Summary: Shows debug text on local client.
  248.  
  249. * Arguments:
  250.  
  251. * _text: Debug text.
  252.  
  253. */
  254.  
  255. drn_fnc_DynamicWeather_ShowDebugTextLocal = {
  256.  
  257. private ["_minutes", "_seconds"];
  258.  
  259.  
  260.  
  261. if (!isNull player) then {
  262.  
  263. player sideChat (_this select 0);
  264.  
  265. };
  266.  
  267.  
  268.  
  269. _minutes = floor (time / 60);
  270.  
  271. _seconds = floor (time - (_minutes * 60));
  272.  
  273. diag_log ((str _minutes + ":" + str _seconds) + " Debug: " + (_this select 0));
  274.  
  275. };
  276.  
  277.  
  278.  
  279.  
  280. /*
  281.  
  282. * Summary: Shows debug text on all clients.
  283.  
  284. * Arguments:
  285.  
  286. * _text: Debug text.
  287.  
  288. */
  289.  
  290. drn_fnc_DynamicWeather_ShowDebugTextAllClients = {
  291.  
  292. drn_DynamicWeather_DebugTextEventArgs = _this;
  293.  
  294. publicVariable "drn_DynamicWeather_DebugTextEventArgs";
  295.  
  296. drn_DynamicWeather_DebugTextEventArgs call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  297.  
  298. };
  299.  
  300.  
  301.  
  302.  
  303. if (_debug) then {
  304.  
  305. ["Starting script WeatherEffects.sqf..."] call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  306.  
  307. };
  308.  
  309.  
  310.  
  311.  
  312. 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]
  313.  
  314. drn_AskServerDynamicWeatherEventArgs = []; // []
  315.  
  316.  
  317.  
  318.  
  319. drn_fnc_DynamicWeather_SetWeatherLocal = {
  320.  
  321. private ["_currentOvercast", "_currentFog", "_currentRain", "_currentWeatherChange", "_targetWeatherValue", "_timeUntilCompletion", "_currentWindX", "_currentWindZ"];
  322.  
  323.  
  324.  
  325.  
  326. _currentOvercast = _this select 0;
  327.  
  328. _currentFog = _this select 1;
  329.  
  330. _currentRain = _this select 2;
  331.  
  332. _currentWeatherChange = _this select 3;
  333.  
  334. _targetWeatherValue = _this select 4;
  335.  
  336. _timeUntilCompletion = _this select 5;
  337.  
  338. _currentWindX = _this select 6;
  339.  
  340. _currentWindZ = _this select 7;
  341.  
  342.  
  343.  
  344. // Set current weather values
  345.  
  346. 0 setOvercast _currentOvercast;
  347.  
  348. 0 setFog _currentFog;
  349.  
  350. drn_var_DynamicWeather_Rain = _currentRain;
  351.  
  352. setWind [_currentWindX, _currentWindZ, true];
  353.  
  354.  
  355.  
  356. // Set forecast
  357.  
  358. if (_currentWeatherChange == "OVERCAST") then {
  359.  
  360. _timeUntilCompletion setOvercast _targetWeatherValue;
  361.  
  362. };
  363.  
  364. if (_currentWeatherChange == "FOG") then {
  365.  
  366. _timeUntilCompletion setFog _targetWeatherValue;
  367.  
  368. };
  369.  
  370. };
  371.  
  372.  
  373.  
  374.  
  375. if (!isServer) then {
  376.  
  377. "drn_DynamicWeatherEventArgs" addPublicVariableEventHandler {
  378.  
  379. drn_DynamicWeatherEventArgs call drn_fnc_DynamicWeather_SetWeatherLocal;
  380.  
  381. };
  382.  
  383.  
  384.  
  385.  
  386. waitUntil {!isNil "drn_var_DynamicWeather_ServerInitialized"};
  387.  
  388.  
  389.  
  390. drn_AskServerDynamicWeatherEventArgs = [true];
  391.  
  392. publicVariable "drn_AskServerDynamicWeatherEventArgs";
  393.  
  394. };
  395.  
  396.  
  397.  
  398.  
  399. if (isServer) then {
  400.  
  401. drn_fnc_DynamicWeather_SetWeatherAllClients = {
  402.  
  403. private ["_timeUntilCompletion", "_currentWeatherChange"];
  404.  
  405.  
  406.  
  407. _timeUntilCompletion = drn_DynamicWeather_WeatherChangeCompletedTime - drn_DynamicWeather_WeatherChangeStartedTime;
  408.  
  409. if (_timeUntilCompletion > 0) then {
  410.  
  411. _currentWeatherChange = drn_DynamicWeather_CurrentWeatherChange;
  412.  
  413. }
  414.  
  415. else {
  416.  
  417. _currentWeatherChange = "";
  418.  
  419. };
  420.  
  421.  
  422.  
  423. drn_DynamicWeatherEventArgs = [overcast, fog, drn_var_DynamicWeather_Rain, _currentWeatherChange, drn_DynamicWeather_WeatherTargetValue, _timeUntilCompletion, drn_DynamicWeather_WindX, drn_DynamicWeather_WindZ];
  424.  
  425. publicVariable "drn_DynamicWeatherEventArgs";
  426.  
  427. drn_DynamicWeatherEventArgs call drn_fnc_DynamicWeather_SetWeatherLocal;
  428.  
  429. };
  430.  
  431.  
  432.  
  433. "drn_AskServerDynamicWeatherEventArgs" addPublicVariableEventHandler {
  434.  
  435. call drn_fnc_DynamicWeather_SetWeatherAllClients;
  436.  
  437. };
  438.  
  439.  
  440.  
  441. drn_DynamicWeather_CurrentWeatherChange = "";
  442.  
  443. drn_DynamicWeather_WeatherTargetValue = 0;
  444.  
  445. drn_DynamicWeather_WeatherChangeStartedTime = time;
  446.  
  447. drn_DynamicWeather_WeatherChangeCompletedTime = time;
  448.  
  449. drn_DynamicWeather_WindX = _initialWind select 0;
  450.  
  451. drn_DynamicWeather_WindZ = _initialWind select 1;
  452.  
  453.  
  454.  
  455. if (_initialFog == -1) then {
  456.  
  457. _initialFog = (_minimumFog + random (_maximumFog - _minimumFog));
  458.  
  459. }
  460.  
  461. else {
  462.  
  463. if (_initialFog < _minimumFog) then {
  464.  
  465. _initialFog = _minimumFog;
  466.  
  467. };
  468.  
  469. if (_initialFog > _maximumFog) then {
  470.  
  471. _initialFog = _maximumFog;
  472.  
  473. };
  474.  
  475. };
  476.  
  477.  
  478.  
  479. 0 setFog _initialFog;
  480.  
  481.  
  482.  
  483. if (_initialOvercast == -1) then {
  484.  
  485. _initialOvercast = (_minimumOvercast + random (_maximumOvercast - _minimumOvercast));
  486.  
  487. }
  488.  
  489. else {
  490.  
  491. if (_initialOvercast < _minimumOvercast) then {
  492.  
  493. _initialOvercast = _minimumOvercast;
  494.  
  495. };
  496.  
  497. if (_initialOvercast > _maximumOvercast) then {
  498.  
  499. _initialOvercast = _maximumOvercast;
  500.  
  501. };
  502.  
  503. };
  504.  
  505.  
  506.  
  507. 0 setOvercast _initialOvercast;
  508.  
  509.  
  510.  
  511. if (_initialOvercast >= 0.75) then {
  512.  
  513. if (_initialRain == -1) then {
  514.  
  515. _initialRain = (_minimumRain + random (_minimumRain - _minimumRain));
  516.  
  517. }
  518.  
  519. else {
  520.  
  521. if (_initialRain < _minimumRain) then {
  522.  
  523. _initialRain = _minimumRain;
  524.  
  525. };
  526.  
  527. if (_initialRain > _maximumRain) then {
  528.  
  529. _initialRain = _maximumRain;
  530.  
  531. };
  532.  
  533. };
  534.  
  535. }
  536.  
  537. else {
  538.  
  539. _initialRain = 0;
  540.  
  541. };
  542.  
  543.  
  544.  
  545. drn_var_DynamicWeather_Rain = _initialRain;
  546.  
  547. 0 setRain drn_var_DynamicWeather_Rain;
  548.  
  549.  
  550.  
  551. _maxWind = _minimumWind + random (_maximumWind - _minimumWind);
  552.  
  553.  
  554.  
  555. if (drn_DynamicWeather_WindX == -1) then {
  556.  
  557. if (random 100 < 50) then {
  558.  
  559. drn_DynamicWeather_WindX = -_minimumWind - random (_maxWind - _minimumWind);
  560.  
  561. }
  562.  
  563. else {
  564.  
  565. drn_DynamicWeather_WindX = _minimumWind + random (_maxWind - _minimumWind);
  566.  
  567. };
  568.  
  569. };
  570.  
  571.  
  572.  
  573. if (drn_DynamicWeather_WindZ == -1) then {
  574.  
  575. if (random 100 < 50) then {
  576.  
  577. drn_DynamicWeather_WindZ = -_minimumWind - random (_maxWind - _minimumWind);
  578.  
  579. }
  580.  
  581. else {
  582.  
  583. drn_DynamicWeather_WindZ = _minimumWind + random (_maxWind - _minimumWind);
  584.  
  585. };
  586.  
  587. };
  588.  
  589.  
  590.  
  591. setWind [drn_DynamicWeather_WindX, drn_DynamicWeather_WindZ, true];
  592.  
  593.  
  594.  
  595. sleep 0.05;
  596.  
  597.  
  598.  
  599. publicVariable "drn_var_DynamicWeather_Rain";
  600.  
  601. drn_var_DynamicWeather_ServerInitialized = true;
  602.  
  603. publicVariable "drn_var_DynamicWeather_ServerInitialized";
  604.  
  605.  
  606.  
  607. // Start weather thread
  608.  
  609. [_minWeatherChangeTimeMin, _maxWeatherChangeTimeMin, _minTimeBetweenWeatherChangesMin, _maxTimeBetweenWeatherChangesMin, _minimumFog, _maximumFog, _minimumOvercast, _maximumOvercast, _minimumWind, _maximumWind, _windChangeProbability, _debug] spawn {
  610.  
  611. private ["_minWeatherChangeTimeMin", "_maxWeatherChangeTimeMin", "_minTimeBetweenWeatherChangesMin", "_maxTimeBetweenWeatherChangesMin", "_minimumFog", "_maximumFog", "_minimumOvercast", "_maximumOvercast", "_minimumWind", "_maximumWind", "_windChangeProbability", "_debug"];
  612.  
  613. private ["_weatherType", "_fogLevel", "_overcastLevel", "_oldFogLevel", "_oldOvercastLevel", "_weatherChangeTimeSek"];
  614.  
  615.  
  616.  
  617. _minWeatherChangeTimeMin = _this select 0;
  618.  
  619. _maxWeatherChangeTimeMin = _this select 1;
  620.  
  621. _minTimeBetweenWeatherChangesMin = _this select 2;
  622.  
  623. _maxTimeBetweenWeatherChangesMin = _this select 3;
  624.  
  625. _minimumFog = _this select 4;
  626.  
  627. _maximumFog = _this select 5;
  628.  
  629. _minimumOvercast = _this select 6;
  630.  
  631. _maximumOvercast = _this select 7;
  632.  
  633. _minimumWind = _this select 8;
  634.  
  635. _maximumWind = _this select 9;
  636.  
  637. _windChangeProbability = _this select 10;
  638.  
  639. _debug = _this select 11;
  640.  
  641.  
  642.  
  643. // Set initial fog level
  644.  
  645. _fogLevel = 2;
  646.  
  647. _overcastLevel = 2;
  648.  
  649.  
  650.  
  651. while {true} do {
  652.  
  653. // Sleep a while until next weather change
  654.  
  655. sleep floor (_minTimeBetweenWeatherChangesMin * 60 + random ((_maxTimeBetweenWeatherChangesMin - _minTimeBetweenWeatherChangesMin) * 60));
  656.  
  657.  
  658.  
  659. if (_minimumFog == _maximumFog && _minimumOvercast != _maximumOvercast) then {
  660.  
  661. _weatherType = "OVERCAST";
  662.  
  663. };
  664.  
  665. if (_minimumFog != _maximumFog && _minimumOvercast == _maximumOvercast) then {
  666.  
  667. _weatherType = "FOG";
  668.  
  669. };
  670.  
  671. if (_minimumFog != _maximumFog && _minimumOvercast != _maximumOvercast) then {
  672.  
  673.  
  674.  
  675. // Select type of weather to change
  676.  
  677. if ((random 100) < 50) then {
  678.  
  679. _weatherType = "OVERCAST";
  680.  
  681. }
  682.  
  683. else {
  684.  
  685. _weatherType = "FOG";
  686.  
  687. };
  688.  
  689. };
  690.  
  691.  
  692.  
  693. // DEBUG
  694.  
  695. //_weatherType = "OVERCAST";
  696.  
  697.  
  698.  
  699. if (_weatherType == "FOG") then {
  700.  
  701.  
  702.  
  703. drn_DynamicWeather_CurrentWeatherChange = "FOG";
  704.  
  705.  
  706.  
  707. // Select a new fog level
  708.  
  709. _oldFogLevel = _fogLevel;
  710.  
  711. _fogLevel = floor ((random 100) / 25);
  712.  
  713.  
  714.  
  715. while {_fogLevel == _oldFogLevel} do {
  716.  
  717. _fogLevel = floor ((random 100) / 25);
  718.  
  719. };
  720.  
  721.  
  722.  
  723. if (_fogLevel == 0) then {
  724.  
  725. drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * random 0.05;
  726.  
  727. };
  728.  
  729. if (_fogLevel == 1) then {
  730.  
  731. drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.05 + random 0.2);
  732.  
  733. };
  734.  
  735. if (_fogLevel == 2) then {
  736.  
  737. drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.25 + random 0.3);
  738.  
  739. };
  740.  
  741. if (_fogLevel == 3) then {
  742.  
  743. drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.55 + random 0.45);
  744.  
  745. };
  746.  
  747.  
  748.  
  749. drn_DynamicWeather_WeatherChangeStartedTime = time;
  750.  
  751. _weatherChangeTimeSek = _minWeatherChangeTimeMin * 60 + random ((_maxWeatherChangeTimeMin - _minWeatherChangeTimeMin) * 60);
  752.  
  753. drn_DynamicWeather_WeatherChangeCompletedTime = time + _weatherChangeTimeSek;
  754.  
  755.  
  756.  
  757. if (_debug) then {
  758.  
  759. ["Weather forecast: Fog " + str drn_DynamicWeather_WeatherTargetValue + " in " + str round (_weatherChangeTimeSek / 60) + " minutes."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  760.  
  761. };
  762.  
  763. };
  764.  
  765.  
  766.  
  767. if (_weatherType == "OVERCAST") then {
  768.  
  769.  
  770.  
  771. drn_DynamicWeather_CurrentWeatherChange = "OVERCAST";
  772.  
  773.  
  774.  
  775. // Select a new overcast level
  776.  
  777. _oldOvercastLevel = _overcastLevel;
  778.  
  779. //_overcastLevel = floor ((random 100) / 25);
  780.  
  781. _overcastLevel = 3;
  782.  
  783.  
  784.  
  785. while {_overcastLevel == _oldOvercastLevel} do {
  786.  
  787. _overcastLevel = floor ((random 100) / 25);
  788.  
  789. };
  790.  
  791.  
  792.  
  793. if (_overcastLevel == 0) then {
  794.  
  795. drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * random 0.05;
  796.  
  797. };
  798.  
  799. if (_overcastLevel == 1) then {
  800.  
  801. drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.05 + random 0.3);
  802.  
  803. };
  804.  
  805. if (_overcastLevel == 2) then {
  806.  
  807. drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.35 + random 0.35);
  808.  
  809. };
  810.  
  811. if (_overcastLevel == 3) then {
  812.  
  813. drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.7 + random 0.3);
  814.  
  815. };
  816.  
  817.  
  818.  
  819. // DEBUG
  820.  
  821. /*
  822.  
  823. if (overcast > 0.8) then {
  824.  
  825. drn_DynamicWeather_WeatherTargetValue = 0.5;
  826.  
  827. }
  828.  
  829. else {
  830.  
  831. drn_DynamicWeather_WeatherTargetValue = 0.85;
  832.  
  833. };
  834.  
  835. */
  836.  
  837.  
  838.  
  839. drn_DynamicWeather_WeatherChangeStartedTime = time;
  840.  
  841. _weatherChangeTimeSek = _minWeatherChangeTimeMin * 60 + random ((_maxWeatherChangeTimeMin - _minWeatherChangeTimeMin) * 60);
  842.  
  843. drn_DynamicWeather_WeatherChangeCompletedTime = time + _weatherChangeTimeSek;
  844.  
  845.  
  846.  
  847. if (_debug) then {
  848.  
  849. ["Weather forecast: Overcast " + str drn_DynamicWeather_WeatherTargetValue + " in " + str round (_weatherChangeTimeSek / 60) + " minutes."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  850.  
  851. };
  852.  
  853. };
  854.  
  855.  
  856.  
  857. // On average every one fourth of weather changes, change wind too
  858.  
  859. if (random 100 < _windChangeProbability) then {
  860.  
  861. private ["_maxWind"];
  862.  
  863.  
  864.  
  865. _maxWind = _minimumWind + random (_maximumWind - _minimumWind);
  866.  
  867.  
  868.  
  869. if (random 100 < 50) then {
  870.  
  871. drn_DynamicWeather_WindX = -_minimumWind - random (_maxWind - _minimumWind);
  872.  
  873. }
  874.  
  875. else {
  876.  
  877. drn_DynamicWeather_WindX = _minimumWind + random (_maxWind - _minimumWind);
  878.  
  879. };
  880.  
  881. if (random 100 < 50) then {
  882.  
  883. drn_DynamicWeather_WindZ = -_minimumWind - random (_maxWind - _minimumWind);
  884.  
  885. }
  886.  
  887. else {
  888.  
  889. drn_DynamicWeather_WindZ = _minimumWind + random (_maxWind - _minimumWind);
  890.  
  891. };
  892.  
  893.  
  894.  
  895. if (_debug) then {
  896.  
  897. ["Wind changes: [" + str drn_DynamicWeather_WindX + ", " + str drn_DynamicWeather_WindZ + "]."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  898.  
  899. };
  900.  
  901. };
  902.  
  903.  
  904.  
  905. call drn_fnc_DynamicWeather_SetWeatherAllClients;
  906.  
  907.  
  908.  
  909. sleep _weatherChangeTimeSek;
  910.  
  911. };
  912.  
  913. };
  914.  
  915.  
  916.  
  917. // Start rain thread
  918.  
  919. if (_rainIntervalRainProbability > 0) then {
  920.  
  921. [_minimumRain, _maximumRain, _forceRainToStopAfterOneRainInterval, _minRainIntervalTimeMin, _maxRainIntervalTimeMin, _rainIntervalRainProbability, _debug] spawn {
  922.  
  923. private ["_minimumRain", "_maximumRain", "_forceRainToStopAfterOneRainInterval", "_minRainIntervalTimeMin", "_maxRainIntervalTimeMin", "_rainIntervalRainProbability", "_debug"];
  924.  
  925. private ["_nextRainEventTime", "_forceStop"];
  926.  
  927.  
  928.  
  929. _minimumRain = _this select 0;
  930.  
  931. _maximumRain = _this select 1;
  932.  
  933. _forceRainToStopAfterOneRainInterval = _this select 2;
  934.  
  935. _minRainIntervalTimeMin = _this select 3;
  936.  
  937. _maxRainIntervalTimeMin = _this select 4;
  938.  
  939. _rainIntervalRainProbability = _this select 5;
  940.  
  941. _debug = _this select 6;
  942.  
  943.  
  944.  
  945. if (rain > 0) then {
  946.  
  947. drn_var_DynamicWeather_Rain = rain;
  948.  
  949. publicVariable "drn_var_DynamicWeather_Rain";
  950.  
  951. };
  952.  
  953.  
  954.  
  955. _nextRainEventTime = time;
  956.  
  957. _forceStop = false;
  958.  
  959.  
  960.  
  961. while {true} do {
  962.  
  963.  
  964.  
  965. if (overcast > 0.75) then {
  966.  
  967.  
  968.  
  969. if (time >= _nextRainEventTime) then {
  970.  
  971. private ["_rainTimeSec"];
  972.  
  973.  
  974.  
  975. // At every rain event time, start or stop rain with 50% probability
  976.  
  977. if (random 100 < _rainIntervalRainProbability && !_forceStop) then {
  978.  
  979. drn_var_DynamicWeather_rain = _minimumRain + random (_maximumRain - _minimumRain);
  980.  
  981. publicVariable "drn_var_DynamicWeather_rain";
  982.  
  983.  
  984.  
  985. _forceStop = _forceRainToStopAfterOneRainInterval;
  986.  
  987. }
  988.  
  989. else {
  990.  
  991. drn_var_DynamicWeather_rain = 0;
  992.  
  993. publicVariable "drn_var_DynamicWeather_rain";
  994.  
  995.  
  996.  
  997. _forceStop = false;
  998.  
  999. };
  1000.  
  1001.  
  1002.  
  1003. // Pick a time for next rain change
  1004.  
  1005. _rainTimeSec = _minRainIntervalTimeMin * 60 + random ((_maxRainIntervalTimeMin - _minRainIntervalTimeMin) * 60);
  1006.  
  1007. _nextRainEventTime = time + _rainTimeSec;
  1008.  
  1009.  
  1010.  
  1011. if (_debug) then {
  1012.  
  1013. ["Rain set to " + str drn_var_DynamicWeather_rain + " for " + str (_rainTimeSec / 60) + " minutes"] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  1014.  
  1015. };
  1016.  
  1017. };
  1018.  
  1019. }
  1020.  
  1021. else {
  1022.  
  1023. if (drn_var_DynamicWeather_rain != 0) then {
  1024.  
  1025. drn_var_DynamicWeather_rain = 0;
  1026.  
  1027. publicVariable "drn_var_DynamicWeather_rain";
  1028.  
  1029.  
  1030.  
  1031. if (_debug) then {
  1032.  
  1033. ["Rain stops due to low overcast."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  1034.  
  1035. };
  1036.  
  1037. };
  1038.  
  1039.  
  1040.  
  1041. _nextRainEventTime = time;
  1042.  
  1043. _forceStop = false;
  1044.  
  1045. };
  1046.  
  1047.  
  1048.  
  1049. if (_debug) then {
  1050.  
  1051. sleep 1;
  1052.  
  1053. }
  1054.  
  1055. else {
  1056.  
  1057. sleep 10;
  1058.  
  1059. };
  1060.  
  1061. };
  1062.  
  1063. };
  1064.  
  1065. };
  1066.  
  1067. };
  1068.  
  1069.  
  1070.  
  1071.  
  1072. [_rainIntervalRainProbability, _debug] spawn {
  1073.  
  1074. private ["_rainIntervalRainProbability", "_debug"];
  1075.  
  1076. private ["_rain", "_rainPerSecond"];
  1077.  
  1078.  
  1079.  
  1080. _rainIntervalRainProbability = _this select 0;
  1081.  
  1082. _debug = _this select 1;
  1083.  
  1084.  
  1085.  
  1086. if (_debug) then {
  1087.  
  1088. _rainPerSecond = 0.2;
  1089.  
  1090. }
  1091.  
  1092. else {
  1093.  
  1094. _rainPerSecond = 0.03;
  1095.  
  1096. };
  1097.  
  1098.  
  1099.  
  1100. if (_rainIntervalRainProbability > 0) then {
  1101.  
  1102. _rain = drn_var_DynamicWeather_Rain;
  1103.  
  1104. }
  1105.  
  1106. else {
  1107.  
  1108. _rain = 0;
  1109.  
  1110. };
  1111.  
  1112.  
  1113.  
  1114. 0 setRain _rain;
  1115.  
  1116. sleep 0.1;
  1117.  
  1118.  
  1119.  
  1120. while {true} do {
  1121.  
  1122. if (_rainIntervalRainProbability > 0) then {
  1123.  
  1124. if (_rain < drn_var_DynamicWeather_Rain) then {
  1125.  
  1126. _rain = _rain + _rainPerSecond;
  1127.  
  1128. if (_rain > 1) then { _rain = 1; };
  1129.  
  1130. };
  1131.  
  1132. if (_rain > drn_var_DynamicWeather_Rain) then {
  1133.  
  1134. _rain = _rain - _rainPerSecond;
  1135.  
  1136. if (_rain < 0) then { _rain = 0; };
  1137.  
  1138. };
  1139.  
  1140. }
  1141.  
  1142. else {
  1143.  
  1144. _rain = 0;
  1145.  
  1146. };
  1147.  
  1148.  
  1149.  
  1150. 3 setRain _rain;
  1151.  
  1152.  
  1153.  
  1154. sleep 3;
  1155.  
  1156. };
  1157.  
  1158. };[/CODE]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement