2015-05-11 08:59:07 +00:00
|
|
|
/*
|
|
|
|
* Author: Ruthberg
|
|
|
|
* Calculates the true wind speed at a given world position
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: world position - posASL <POSTION>
|
2016-01-05 07:39:29 +00:00
|
|
|
* 1: Account for wind gradient (used in advanced ballistics) <BOOL>
|
2015-05-11 08:59:07 +00:00
|
|
|
* 2: Account for terrain <BOOL>
|
|
|
|
* 3: Account for obstacles <BOOL>
|
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-04 00:11:24 +00:00
|
|
|
* wind speed - m/s <NUMBER>
|
2015-05-11 08:59:07 +00:00
|
|
|
*
|
2016-01-05 07:39:29 +00:00
|
|
|
* Example:
|
|
|
|
* [eyePos ACE_player, true, true, true] call ace_weather_fnc_calculateWindSpeed;
|
|
|
|
*
|
2015-05-11 08:59:07 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-04 00:11:24 +00:00
|
|
|
params ["_position", "_windGradientEnabled", "_terrainEffectEnabled", "_obstacleEffectEnabled"];
|
2015-05-11 08:59:07 +00:00
|
|
|
|
2016-01-05 07:39:29 +00:00
|
|
|
private _fnc_polar2vect = {
|
|
|
|
params ["_mag","_dir","_elev"];
|
|
|
|
private _mag2D = _mag * cos(_elev);
|
|
|
|
[_mag2D * sin(_dir), _mag2D * cos(_dir), _mag * sin(_elev)];
|
2015-05-11 08:59:07 +00:00
|
|
|
};
|
|
|
|
|
2017-11-10 14:44:15 +00:00
|
|
|
private _windSpeed = vectorMagnitude wind;
|
|
|
|
private _windDir = (wind select 0) atan2 (wind select 1);
|
2016-01-05 07:39:29 +00:00
|
|
|
private _windDirAdjusted = _windDir + 180;
|
2015-05-11 08:59:07 +00:00
|
|
|
|
|
|
|
// Wind gradient
|
|
|
|
if (_windGradientEnabled) then {
|
|
|
|
if (_windSpeed > 0.05) then {
|
2016-01-05 07:39:29 +00:00
|
|
|
private _height = (ASLToATL _position) select 2;
|
2017-12-08 16:44:12 +00:00
|
|
|
if (_height > 0 && _height < 20) then {
|
2016-01-05 07:39:29 +00:00
|
|
|
private _roughnessLength = _position call FUNC(calculateRoughnessLength);
|
2017-12-08 16:44:12 +00:00
|
|
|
_windSpeed = _windSpeed * (0 max (ln(_height / _roughnessLength) / ln(20 / _roughnessLength)));
|
2015-05-11 08:59:07 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Terrain effect on wind
|
|
|
|
if (_terrainEffectEnabled) then {
|
|
|
|
if (_windSpeed > 0.05) then {
|
2016-01-05 07:39:29 +00:00
|
|
|
private _newWindSpeed = 0;
|
2015-05-11 08:59:07 +00:00
|
|
|
{
|
2016-01-05 07:39:29 +00:00
|
|
|
private _windSource = [100, _windDirAdjusted, _x] call _fnc_polar2vect;
|
2015-05-11 08:59:07 +00:00
|
|
|
if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith {
|
|
|
|
_newWindSpeed = cos(_x * 9) * _windSpeed;
|
|
|
|
};
|
2015-08-04 23:53:11 +00:00
|
|
|
_windSource = [100, _windDirAdjusted + _x, 0] call _fnc_polar2vect;
|
2015-05-11 08:59:07 +00:00
|
|
|
if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith {
|
|
|
|
_newWindSpeed = cos(_x * 9) * _windSpeed;
|
|
|
|
};
|
2015-08-04 23:53:11 +00:00
|
|
|
_windSource = [100, _windDirAdjusted - _x, 0] call _fnc_polar2vect;
|
2015-05-11 08:59:07 +00:00
|
|
|
if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith {
|
|
|
|
_newWindSpeed = cos(_x * 9) * _windSpeed;
|
|
|
|
};
|
2016-01-05 07:39:29 +00:00
|
|
|
nil
|
2015-08-04 23:53:11 +00:00
|
|
|
} count [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
2015-05-11 08:59:07 +00:00
|
|
|
_windSpeed = _newWindSpeed;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Obstacle effect on wind
|
|
|
|
if (_obstacleEffectEnabled) then {
|
|
|
|
if (_windSpeed > 0.05) then {
|
2016-01-05 07:39:29 +00:00
|
|
|
private _newWindSpeed = 0;
|
2015-05-11 08:59:07 +00:00
|
|
|
{
|
2016-01-05 07:39:29 +00:00
|
|
|
private _windSource = [20, _windDirAdjusted, _x] call _fnc_polar2vect;
|
2015-05-11 08:59:07 +00:00
|
|
|
if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith {
|
|
|
|
_newWindSpeed = cos(_x * 2) * _windSpeed;
|
|
|
|
};
|
2015-08-04 23:53:11 +00:00
|
|
|
_windSource = [20, _windDirAdjusted + _x, 0] call _fnc_polar2vect;
|
2015-05-11 08:59:07 +00:00
|
|
|
if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith {
|
|
|
|
_newWindSpeed = cos(_x * 2) * _windSpeed;
|
|
|
|
};
|
2015-08-04 23:53:11 +00:00
|
|
|
_windSource = [20, _windDirAdjusted - _x, 0] call _fnc_polar2vect;
|
2015-05-11 08:59:07 +00:00
|
|
|
if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith {
|
|
|
|
_newWindSpeed = cos(_x * 2) * _windSpeed;
|
|
|
|
};
|
2016-01-05 07:39:29 +00:00
|
|
|
nil
|
2015-08-04 23:53:11 +00:00
|
|
|
} count [0, 5, 10, 15, 20, 25, 30, 35, 40, 45];
|
2015-05-11 08:59:07 +00:00
|
|
|
_windSpeed = _newWindSpeed;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
_windSpeed = 0 max _windSpeed;
|
|
|
|
|
|
|
|
_windSpeed
|