From 2040f4dcc331d78ad6672a51d4e0823900c63ebd Mon Sep 17 00:00:00 2001 From: ulteq Date: Sun, 12 Apr 2015 23:25:58 +0200 Subject: [PATCH] Improved the wind speed calculation if AB is not enabled --- addons/kestrel4500/XEH_preInit.sqf | 1 + .../functions/fnc_calculateWindSpeed.sqf | 68 +++++++++++++++++++ .../kestrel4500/functions/fnc_collectData.sqf | 2 + .../functions/fnc_generateOutputData.sqf | 2 + 4 files changed, 73 insertions(+) create mode 100644 addons/kestrel4500/functions/fnc_calculateWindSpeed.sqf diff --git a/addons/kestrel4500/XEH_preInit.sqf b/addons/kestrel4500/XEH_preInit.sqf index b1a6bca0e5..293eb79f99 100644 --- a/addons/kestrel4500/XEH_preInit.sqf +++ b/addons/kestrel4500/XEH_preInit.sqf @@ -3,6 +3,7 @@ ADDON = false; PREP(buttonPressed); +PREP(calculateWindSpeed); PREP(canShow); PREP(collectData); PREP(createKestrelDialog); diff --git a/addons/kestrel4500/functions/fnc_calculateWindSpeed.sqf b/addons/kestrel4500/functions/fnc_calculateWindSpeed.sqf new file mode 100644 index 0000000000..8267f7f729 --- /dev/null +++ b/addons/kestrel4500/functions/fnc_calculateWindSpeed.sqf @@ -0,0 +1,68 @@ +/* + * Author: Ruthberg + * + * Calculates the wind speed at a given world position + * + * Arguments: + * 0: _this - world position + * + * Return Value: + * 0: wind speed - m/s + * + * Public: No + */ +#include "script_component.hpp" + +private ["_windSpeed", "_windDir", "_newWindSpeed", "_windSource"]; + +fnc_polar2vect = { + private ["_mag2D"]; + _mag2D = (_this select 0) * cos((_this select 2)); + [_mag2D * sin((_this select 1)), _mag2D * cos((_this select 1)), (_this select 0) * sin((_this select 2))]; +}; + +_windSpeed = vectorMagnitude ACE_wind; +_windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); + +// Terrain effect on wind +if (_windSpeed > 0.05) then { + _newWindSpeed = 0; + { + _windSource = [100, _windDir + 180, _x] call fnc_polar2vect; + if (!(terrainIntersectASL [_this, _this vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 9) * _windSpeed; + }; + _windSource = [100, _windDir + 180 + _x, 0] call fnc_polar2vect; + if (!(terrainIntersectASL [_this, _this vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 9) * _windSpeed; + }; + _windSource = [100, _windDir + 180 - _x, 0] call fnc_polar2vect; + if (!(terrainIntersectASL [_this, _this vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 9) * _windSpeed; + }; + } forEach [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + _windSpeed = _newWindSpeed; +}; + +// Obstacle effect on wind +if (_windSpeed > 0.05) then { + _newWindSpeed = 0; + { + _windSource = [20, _windDir + 180, _x] call fnc_polar2vect; + if (!(lineIntersects [_this, _this vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 2) * _windSpeed; + }; + _windSource = [20, _windDir + 180 + _x, 0] call fnc_polar2vect; + if (!(lineIntersects [_this, _this vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 2) * _windSpeed; + }; + _windSource = [20, _windDir + 180 - _x, 0] call fnc_polar2vect; + if (!(lineIntersects [_this, _this vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 2) * _windSpeed; + }; + } forEach [0, 5, 10, 15, 20, 25, 30, 35, 40, 45]; + _windSpeed = _newWindSpeed; +}; +_windSpeed = 0 max _windSpeed; + +_windSpeed diff --git a/addons/kestrel4500/functions/fnc_collectData.sqf b/addons/kestrel4500/functions/fnc_collectData.sqf index ba6ec383ed..5e6a6572b7 100644 --- a/addons/kestrel4500/functions/fnc_collectData.sqf +++ b/addons/kestrel4500/functions/fnc_collectData.sqf @@ -48,6 +48,8 @@ if (GVAR(MinAvgMaxMode) == 1) then { if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { _windSpeed = (eyePos ACE_player) call EFUNC(advanced_ballistics,calculateWindSpeed); _windSpeed = abs(cos(_playerDir - _windDir)) * _windSpeed; + } else { + _windSpeed = (eyePos ACE_player) call FUNC(calculateWindSpeed); }; GVAR(MIN) set [1, (GVAR(MIN) select 1) min abs(_windSpeed)]; diff --git a/addons/kestrel4500/functions/fnc_generateOutputData.sqf b/addons/kestrel4500/functions/fnc_generateOutputData.sqf index d164aa3a9f..3d874edade 100644 --- a/addons/kestrel4500/functions/fnc_generateOutputData.sqf +++ b/addons/kestrel4500/functions/fnc_generateOutputData.sqf @@ -45,6 +45,8 @@ _playerDir = getDir ACE_player; if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { _windSpeed = (eyePos ACE_player) call EFUNC(advanced_ballistics,calculateWindSpeed); _windSpeed = abs(cos(_playerDir - _windDir)) * _windSpeed; +} else { + _windSpeed = (eyePos ACE_player) call FUNC(calculateWindSpeed); }; if (_windSpeed > 0.3) then {