From 9155056a501456030ca71d3cd7f642f33f53fcbd Mon Sep 17 00:00:00 2001 From: ulteq Date: Mon, 20 Apr 2015 15:11:14 +0200 Subject: [PATCH] Proof of concept wind code (custom debug output enabled) --- addons/weather/functions/fnc_getWind.sqf | 66 +++++++++++++++------ addons/weather/functions/fnc_updateWind.sqf | 2 +- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/addons/weather/functions/fnc_getWind.sqf b/addons/weather/functions/fnc_getWind.sqf index 54ec6efad3..9163d7e854 100644 --- a/addons/weather/functions/fnc_getWind.sqf +++ b/addons/weather/functions/fnc_getWind.sqf @@ -10,25 +10,53 @@ * Wind */ #include "script_component.hpp" -private ["_dir","_dirInc","_dirRange","_period","_periodPercent","_periodPosition","_return","_spd","_spdInc","_spdRange"]; -_return = [0,0,0]; -if(!isNil "ACE_WIND_PARAMS") then { - _dir = ACE_WIND_PARAMS select 0; - _dirRange = (ACE_WIND_PARAMS select 1) - (ACE_WIND_PARAMS select 0); - _spd = ACE_WIND_PARAMS select 2; - _spdRange = (ACE_WIND_PARAMS select 3) - (ACE_WIND_PARAMS select 2); - _period = ACE_WIND_PARAMS select 4; +// Source: https://weatherspark.com/averages/32194/Lemnos-Limnos-North-Aegean-Islands-Greece +_AB_Wind_Speed_Max = [[8.8, 5.5], [8.8, 5], [8.6, 4.8], [7.6, 3.4], [7.0, 3.0], [7.1, 3.0], [7.5, 3.1], [8.0, 3.2], [7.6, 3.5], [7.8, 4.6], [7.9, 5.0], [8.2, 5.5]]; +_AB_Wind_Speed_Mean = [4.8, 4.9, 4.6, 4.1, 3.5, 3.5, 4.3, 4.4, 4.1, 4.5, 4.5, 5.0]; +_AB_Wind_Speed_Min = [[0.2, 5.0], [0.1, 5.0], [0.2, 4.3], [0.0, 3.0], [0.0, 2.1], [0.0, 2.0], [0.1, 3.1], [0.3, 3.1], [0.0, 3.6], [0.0, 4.2], [0.1, 5.0], [0.2, 5.5]]; +_AB_Wind_Direction_Probabilities = [[0.06, 0.32, 0.05, 0.04, 0.15, 0.06, 0.02, 0.02], // January + [0.08, 0.32, 0.04, 0.04, 0.18, 0.06, 0.02, 0.02], // February + [0.09, 0.30, 0.04, 0.04, 0.20, 0.06, 0.02, 0.03], // March + [0.10, 0.25, 0.03, 0.04, 0.22, 0.06, 0.02, 0.04], // April + [0.18, 0.25, 0.03, 0.04, 0.18, 0.04, 0.01, 0.05], // May + [0.25, 0.25, 0.03, 0.03, 0.15, 0.03, 0.00, 0.08], // June + [0.32, 0.30, 0.02, 0.02, 0.10, 0.01, 0.00, 0.09], // July + [0.28, 0.35, 0.02, 0.01, 0.08, 0.01, 0.00, 0.08], // August + [0.20, 0.37, 0.03, 0.01, 0.11, 0.01, 0.01, 0.05], // September + [0.10, 0.39, 0.04, 0.02, 0.15, 0.02, 0.01, 0.03], // October + [0.08, 0.38, 0.06, 0.04, 0.19, 0.03, 0.02, 0.02], // November + [0.06, 0.37, 0.05, 0.03, 0.18, 0.04, 0.02, 0.02]];// December + +_PI = 3.14159265; +_c1 = 0.2 + random 0.2; +_c2 = 0.3 + random 0.2; +_c3 = 0.5 + random 0.2; +_c4 = 0.7 + random 0.2; - _periodPosition = (time - GVAR(wind_period_start_time)) min _period; - _periodPercent = _periodPosition/_period; - _spdInc = _spdRange * _periodPercent; - _dirInc = _dirRange * _periodPercent; - _spd = (_spd + _spdInc); - _dir = _dir + _dirInc; - if (_dir > 360) then {_dir = _dir - 360}; - if (_dir < 0) then {_dir = _dir + 360}; - - _return = [_spd * sin _dir, _spd * cos _dir, 0]; +_month = date select 1; +_windDirectionProbabilities = _AB_Wind_Direction_Probabilities select (_month - 1); +while {isNil QGVAR(windDirection)} do { + _random = random 1; + for "_i" from 0 to 7 do { + if (_random < (_windDirectionProbabilities select _i)) exitWith { + GVAR(windDirection) = 45 * _i; + }; + }; + GVAR(windDirection) = GVAR(windDirection) + (random 22.5) - (random 22.5); }; -_return; \ No newline at end of file + +_min = _AB_Wind_Speed_Min select (_month - 1); +_min = (_min select 0) + (random (_min select 1)) - (random (_min select 1)); +_min = 0 max _min; +_max = _AB_Wind_Speed_Max select (_month - 1); +_max = (_max select 0) + (random (_max select 1)) - (random (_max select 1)); +_max = 0 max _max; + +_x = time * 180 / _PI; +_ratio = 0 max ((1 + _c1 * sin(_x/1.5) + _c2 * sin(_x/3) + _c3 * sin(_x/12) + _c4 * sin(_x/18)) / (1 + _c1 + _c2 + _c3 + _c4)); +_windSpeed = _min + (_max - _min) * _ratio; + +systemChat format["Speed: %1, Direction: %2", _windSpeed, GVAR(windDirection)]; + +[-1 * sin(GVAR(windDirection)) * _windSpeed, -1 * cos(GVAR(windDirection)) * _windSpeed, 0] diff --git a/addons/weather/functions/fnc_updateWind.sqf b/addons/weather/functions/fnc_updateWind.sqf index e5a52348a8..7c79da0069 100644 --- a/addons/weather/functions/fnc_updateWind.sqf +++ b/addons/weather/functions/fnc_updateWind.sqf @@ -18,4 +18,4 @@ setWind [ACE_wind select 0, ACE_wind select 1, true]; // Set waves: 0 when no wind, 1 when wind >= 16 m/s 1 setWaves (((vectorMagnitude ACE_wind) / 16.0) min 1.0); -//hintSilent format["Wind: %1\nACE_wind: %2\nDeviation: %3 (m/s)", wind, ACE_wind, Round((vectorMagnitude (ACE_wind vectorDiff wind)) * 1000) / 1000]; +hintSilent format["Wind: %1\nACE_wind: %2\nDeviation: %3 (m/s)", wind, ACE_wind, Round((vectorMagnitude (ACE_wind vectorDiff wind)) * 1000) / 1000];