Advertisement
Guest User

realweather

a guest
Jun 22nd, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. /*
  2. Author: code34 nicolas_boiteux@yahoo.fr
  3. Copyright (C) 2013 Nicolas BOITEUX
  4.  
  5. Real weather for MP GAMES v 1.2
  6.  
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21. private ["_lastrain", "_rain", "_fog", "_mintime", "_maxtime", "_overcast", "_realtime", "_random", "_skiptime", "_startingdate", "_startingweather", "_timeforecast", "_timeratio", "_timesync", "_wind"];
  22.  
  23. // Real time vs fast time
  24. // true: Real time is more realistic weather conditions change slowly (ideal for persistent game)
  25. // false: fast time give more different weather conditions (ideal for non persistent game)
  26. _realtime = true;
  27.  
  28. // Random time before new forecast
  29. // true: forecast happens bewteen mintime and maxtime
  30. // false: forecast happens at mintime
  31. _random = true;
  32.  
  33. // Min time seconds (real time) before a new weather forecast
  34. _mintime = 600;
  35.  
  36. // Max time seconds (real time) before a new weather forecast
  37. _maxtime = 1200;
  38.  
  39. // If Fastime is on
  40. // Ratio 1 real time second for x game time seconds
  41. // Default: 1 real second = 3.6 second in game
  42. _timeratio = 3.6;
  43.  
  44. // send sync data across the network each xxx seconds
  45. // 60 seconds by default is a good value
  46. // shortest time do not improve weather sync
  47. _timesync = 30;
  48.  
  49. // Mission starting date is 25/09/2013 at 12:00
  50. _startingdate = [2014, 07, 01, 04, 45];
  51.  
  52. if (G_DEBUG) then { _startingdate = [2014, 07, 01, 12, 00]; };
  53. //if (G_DEBUG) then { _startingdate = [2014, 10, 30, 1, 00]; };
  54.  
  55. // Mission starting weather "CLEAR|CLOUDY|RAIN";
  56. _startingweather = "CLEAR";
  57.  
  58. /////////////////////////////////////////////////////////////////
  59. // Do not edit below
  60. /////////////////////////////////////////////////////////////////
  61.  
  62. if(_mintime > _maxtime) exitwith {hint format["Real weather: Max time: %1 can no be higher than Min time: %2", _maxtime, _mintime];};
  63. _timeforecast = _mintime;
  64.  
  65. // we check the skiptime for 10 seconds
  66. _skiptime = _timeratio * 0.000278 * 10;
  67.  
  68. setdate _startingdate;
  69.  
  70. switch(toUpper(_startingweather)) do {
  71. case "CLEAR": {
  72. wcweather = [0, 0, 0, [random 3, random 3, true], date];
  73. };
  74.  
  75. case "CLOUDY": {
  76. wcweather = [0, 0, 0.6, [random 3, random 3, true], date];
  77. };
  78.  
  79. case "RAIN": {
  80. wcweather = [1, 0, 1, [random 3, random 3, true], date];
  81. };
  82.  
  83. default {
  84. // clear
  85. wcweather = [0, 0, 0, [random 3, random 3, true], date];
  86. diag_log "Real weather: wrong starting weather";
  87. };
  88. };
  89.  
  90. // add handler
  91. if (local player) then {
  92. wcweatherstart = true;
  93. "wcweather" addPublicVariableEventHandler {
  94. // first JIP synchronization
  95. if(wcweatherstart) then {
  96. wcweatherstart = false;
  97. skipTime -24;
  98. 86400 setRain (wcweather select 0);
  99. 86400 setfog (wcweather select 1);
  100. 86400 setOvercast (wcweather select 2);
  101. skipTime 24;
  102. simulweatherSync;
  103. setwind (wcweather select 3);
  104. setdate (wcweather select 4);
  105. }else{
  106. wcweather = _this select 1;
  107. 60 setRain (wcweather select 0);
  108. 60 setfog (wcweather select 1);
  109. 60 setOvercast (wcweather select 2);
  110. setwind (wcweather select 3);
  111. setdate (wcweather select 4);
  112. };
  113. };
  114. };
  115.  
  116. // accelerate time
  117. if!(_realtime) then {
  118. [_skiptime] spawn {
  119. private["_skiptime"];
  120. _skiptime = _this select 0;
  121.  
  122. while {true} do {
  123. skiptime _skiptime;
  124. sleep 10;
  125. };
  126. };
  127. };
  128.  
  129. // SERVER SIDE SCRIPT
  130. if (!isServer) exitWith{};
  131.  
  132. // apply weather
  133. skipTime -24;
  134. 86400 setRain (wcweather select 0);
  135. 86400 setfog (wcweather select 1);
  136. 86400 setOvercast (wcweather select 2);
  137. skipTime 24;
  138. simulweatherSync;
  139. setwind (wcweather select 3);
  140. setdate (wcweather select 4);
  141.  
  142. // sync server & client weather & time
  143. [_timesync] spawn {
  144. private["_timesync"];
  145. _timesync = _this select 0;
  146.  
  147. while { true } do {
  148. wcweather set [4, date];
  149. publicvariable "wcweather";
  150. sleep _timesync;
  151. };
  152. };
  153.  
  154. _lastrain = 0;
  155. _rain = 0;
  156. _overcast = 0;
  157.  
  158. while {true} do
  159. {
  160. _overcast = random 1;
  161.  
  162. if(_overcast > 0.68) then
  163. {
  164. _rain = random 0.7;
  165. } else {
  166. _rain = 0;
  167. };
  168.  
  169. if((date select 3 > 2) and (date select 3 <5)) then
  170. {
  171. _fog = 0.2 + (random 0.1);
  172. } else
  173. {
  174. if((_lastrain > 0.6) and (_rain < 0.2)) then
  175. {
  176. _fog = random 0.2;
  177. } else {
  178. _fog = 0;
  179. };
  180. };
  181.  
  182. if (random 1 > 0.95) then
  183. {
  184. _wind = [random 7, random 7, true];
  185. } else {
  186. _wind = [random 3, random 3, true];
  187. };
  188.  
  189. _lastrain = _rain;
  190.  
  191. wcweather = [_rain, _fog, _overcast, _wind, date];
  192. 60 setRain (wcweather select 0);
  193. 60 setfog (wcweather select 1);
  194. 60 setOvercast (wcweather select 2);
  195. setwind (wcweather select 3);
  196. if(_random) then {
  197. _timeforecast = _mintime + (random (_maxtime - _mintime));
  198. };
  199. sleep _timeforecast;
  200. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement