From b03333c9e8fb03febd5ee17ee98ce868c251bfb1 Mon Sep 17 00:00:00 2001 From: ulteq Date: Mon, 11 May 2015 10:59:07 +0200 Subject: [PATCH] Moved all wind calculations into the weather module --- addons/advanced_ballistics/XEH_preInit.sqf | 2 - .../functions/fnc_calculateWindSpeed.sqf | 78 -------- addons/config.cpp | 167 ------------------ addons/kestrel4500/XEH_preInit.sqf | 1 - .../functions/fnc_calculateWindSpeed.sqf | 68 ------- .../functions/fnc_measureWindSpeed.sqf | 7 +- addons/weather/XEH_preInit.sqf | 2 + addons/weather/config.cpp | 4 +- .../fnc_calculateRoughnessLength.sqf | 0 .../functions/fnc_calculateWindSpeed.sqf | 90 ++++++++++ .../weather/functions/fnc_displayWindInfo.sqf | 13 +- 11 files changed, 104 insertions(+), 328 deletions(-) delete mode 100644 addons/advanced_ballistics/functions/fnc_calculateWindSpeed.sqf delete mode 100644 addons/config.cpp delete mode 100644 addons/kestrel4500/functions/fnc_calculateWindSpeed.sqf rename addons/{advanced_ballistics => weather}/functions/fnc_calculateRoughnessLength.sqf (100%) create mode 100644 addons/weather/functions/fnc_calculateWindSpeed.sqf diff --git a/addons/advanced_ballistics/XEH_preInit.sqf b/addons/advanced_ballistics/XEH_preInit.sqf index 1d19a9c492..6fdd849b12 100644 --- a/addons/advanced_ballistics/XEH_preInit.sqf +++ b/addons/advanced_ballistics/XEH_preInit.sqf @@ -6,9 +6,7 @@ PREP(calculateAmmoTemperatureVelocityShift); PREP(calculateAtmosphericCorrection); PREP(calculateBarrelLengthVelocityShift); PREP(calculateRetardation); -PREP(calculateRoughnessLength); PREP(calculateStabilityFactor); -PREP(calculateWindSpeed); PREP(displayProtractor); PREP(handleFired); PREP(initializeTerrainExtension); diff --git a/addons/advanced_ballistics/functions/fnc_calculateWindSpeed.sqf b/addons/advanced_ballistics/functions/fnc_calculateWindSpeed.sqf deleted file mode 100644 index e7b0a322e8..0000000000 --- a/addons/advanced_ballistics/functions/fnc_calculateWindSpeed.sqf +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Author: Ruthberg - * - * Calculates the true 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", "_height", "_newWindSpeed", "_windSource", "_roughnessLength"]; - -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); - -// Wind gradient -if (_windSpeed > 0.05) then { - _height = (ASLToATL _this) select 2; - _height = 0 max _height min 20; - if (_height < 20) then { - _roughnessLength = _this call FUNC(calculateRoughnessLength); - _windSpeed = _windSpeed * ln(_height / _roughnessLength) / ln(20 / _roughnessLength); - }; -}; - -// 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/config.cpp b/addons/config.cpp deleted file mode 100644 index 27647f8d00..0000000000 --- a/addons/config.cpp +++ /dev/null @@ -1,167 +0,0 @@ -#include "script_component.hpp" - -class CfgPatches { - class ADDON { - units[] = {"ACE_Box_Misc", "ACE_bananaItem"}; - weapons[] = {"ACE_ItemCore","ACE_FakePrimaryWeapon", "ACE_Banana"}; - requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"ace_main"}; - author[] = {"KoffeinFlummi"}; - authorUrl = "https://github.com/KoffeinFlummi/"; - VERSION_CONFIG; - }; -}; - -#include "CfgEventHandlers.hpp" - -#include "CfgSounds.hpp" -#include "CfgVehicles.hpp" -#include "CfgWeapons.hpp" -#include "CfgMagazines.hpp" - -#include "CfgActions.hpp" -#include "CfgMoves.hpp" -#include "CfgVoice.hpp" -#include "CfgUnitInsignia.hpp" - -class ACE_Rsc_Display_Base { - idd = -1; - type = 0; - style = 48; - name = ""; - duration = 999999; - fadeIn = 0; - fadeOut = 0; - font = "TahomaB"; - size = 1; - colorBackground[] = {1, 1, 1, 0}; - colorText[] = {1, 1, 1, 1}; -}; - -class ACE_Rsc_Control_Base { - idc = 1; - type = 0; - style = 48; - access = 0; - lineSpacing = 0; - moving = 1; - text = ""; - size = 1; - sizeEx = 0; - font = "TahomaB"; - colorBackground[] = {1, 1, 1, 0}; - colorText[] = {1, 1, 1, 1}; - x = 0; - y = 0; - w = 0; - h = 0; -}; - -class ACE_Settings { - /* - *class GVAR(sampleSetting) { - * Value - * value = 1; - * - * Type (SCALAR, BOOL, STRING, ARRAY, COLOR) - * typeName = "SCALAR"; - * - * Force the setting? - * force = 0; - * - * Does it appear on the options menu? - * isClientSettable = 1; - * - * The following settings only apply when isClientSettable == 1 - * Stringtable entry with the setting name - * displayName = "$STR_ACE_Common_SettingName"; - * - * Stringtable entry with the setting description - * description = "$STR_ACE_Common_SettingDescription"; - * - * Stringtable entries that describe the options - * Only applies if typeName == "SCALAR"; - * values[] = {"Disabled", "Enabled", "Only Cursor", "Only On Keypress", "Only Cursor and KeyPress"}; - *}; - */ - class GVAR(forceAllSettings) { - value = 0; - typeName = "BOOL"; - }; - /*class GVAR(enableNumberHotkeys) { - value = 1; - typeName = "BOOL"; - isClientSettable = 1; - displayName = "$STR_ACE_Common_EnableNumberHotkeys"; - };*/ - class GVAR(settingFeedbackIcons) { - value = 1; - typeName = "SCALAR"; - force = 0; - isClientSettable = 1; - displayName = "$STR_ACE_Common_SettingFeedbackIconsName"; - description = "$STR_ACE_Common_SettingFeedbackIconsDesc"; - values[] = {"Hide", "Top right, downwards", "Top right, to the left", "Top left, downwards", "Top left, to the right"}; - }; - class GVAR(SettingProgressBarLocation) { - value = 0; - typeName = "SCALAR"; - force = 0; - isClientSettable = 1; - displayName = "$STR_ACE_Common_SettingProgressbarLocationName"; - description = "$STR_ACE_Common_SettingProgressbarLocationDesc"; - values[] = {"Top", "Bottom"}; - }; - class GVAR(displayTextColor) { - value[] = {0,0,0,0.1}; - typeName = "COLOR"; - isClientSettable = 1; - displayName = "$STR_ACE_Common_SettingDisplayTextColorName"; - description = "$STR_ACE_Common_SettingDisplayTextColorDesc"; - }; - class GVAR(displayTextFontColor) { - value[] = {1,1,1,1}; - typeName = "COLOR"; - isClientSettable = 1; - displayName = "$STR_ACE_Common_SettingDisplayTextFontColorName"; - description = "$STR_ACE_Common_SettingDisplayTextFontColorDesc"; - }; -}; - -#include "define.hpp" -#include -#include -#include - -class CfgUIGrids { - class IGUI { - class Presets { - class Arma3 { - class Variables { - grid_ACE_displayText[] = {{((safezoneX + safezoneW) - (10 *(((safezoneW / safezoneH) min 1.2) / 40)) - 2.9 *(((safezoneW / safezoneH) min 1.2) / 40)),safeZoneY + 0.175 * safezoneH, (10 *(((safezoneW / safezoneH) min 1.2) / 40)), (2 *((((safezoneW / safezoneH) min 1.2) / 1.2) / 25))}, "(((safezoneW / safezoneH) min 1.2) / 40)","((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"}; - }; - }; - }; - - class Variables { - class grid_ACE_displayText { - displayName = "ACE Hint"; - description = "Textual in game feedback to the player."; - preview = "\a3\Ui_f\data\GUI\Cfg\UIGrids\grid_hint_ca.paa"; - saveToProfile[] = {0,1}; - }; - }; - }; -}; - -/* -// check dll -class RscStandardDisplay; -class RscDisplayMain: RscStandardDisplay { - onLoad = QUOTE([ARR_4(""onLoad"",_this,""RscDisplayMain"",'GUI')] call (uinamespace getvariable 'BIS_fnc_initDisplay'); [ARR_5('header','tail',{0},{},_this select 0)] call COMPILE_FILE(functions\fnc_errorMessage)); -}; -*/ - -class ACE_Extensions { - extensions[] = {}; -}; diff --git a/addons/kestrel4500/XEH_preInit.sqf b/addons/kestrel4500/XEH_preInit.sqf index 2d5e211a54..4e29b9bdbf 100644 --- a/addons/kestrel4500/XEH_preInit.sqf +++ b/addons/kestrel4500/XEH_preInit.sqf @@ -3,7 +3,6 @@ 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 deleted file mode 100644 index 8267f7f729..0000000000 --- a/addons/kestrel4500/functions/fnc_calculateWindSpeed.sqf +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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_measureWindSpeed.sqf b/addons/kestrel4500/functions/fnc_measureWindSpeed.sqf index eb718906aa..73b4e228d6 100644 --- a/addons/kestrel4500/functions/fnc_measureWindSpeed.sqf +++ b/addons/kestrel4500/functions/fnc_measureWindSpeed.sqf @@ -19,12 +19,13 @@ private ["_playerDir", "_windSpeed", "_windDir"]; _playerDir = getDir ACE_player; _windSpeed = vectorMagnitude ACE_wind; _windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); - if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { - _windSpeed = (eyePos ACE_player) call EFUNC(advanced_ballistics,calculateWindSpeed); + // With wind gradient + _windSpeed = [eyePos ACE_player, true, true, true] call EFUNC(weather,calculateWindSpeed); _windSpeed = abs(cos(_playerDir - _windDir)) * _windSpeed; } else { - _windSpeed = (eyePos ACE_player) call FUNC(calculateWindSpeed); + // Without wind gradient + _windSpeed = [eyePos ACE_player, false, true, true] call EFUNC(weather,calculateWindSpeed); }; if (_windSpeed > 0.3 || {GVAR(MeasuredWindSpeed) > 0.1 && _windSpeed > 0.125}) then { diff --git a/addons/weather/XEH_preInit.sqf b/addons/weather/XEH_preInit.sqf index 0f49226432..6e6e008a67 100644 --- a/addons/weather/XEH_preInit.sqf +++ b/addons/weather/XEH_preInit.sqf @@ -5,6 +5,8 @@ ADDON = false; PREP(calculateAirDensity); PREP(calculateBarometricPressure); +PREP(calculateRoughnessLength); +PREP(calculateWindSpeed); PREP(displayWindInfo); PREP(getMapData); PREP(getWind); diff --git a/addons/weather/config.cpp b/addons/weather/config.cpp index 39cf223518..18059fe9e8 100644 --- a/addons/weather/config.cpp +++ b/addons/weather/config.cpp @@ -5,8 +5,8 @@ class CfgPatches { units[] = {}; weapons[] = {}; requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"ace_common"}; - author[] = {"q1184", "Rocko", "esteldunedain","Ruthberg"}; + requiredAddons[] = {"ace_common", "ace_modules"}; + author[] = {"q1184", "Rocko", "esteldunedain", "Ruthberg"}; VERSION_CONFIG; }; }; diff --git a/addons/advanced_ballistics/functions/fnc_calculateRoughnessLength.sqf b/addons/weather/functions/fnc_calculateRoughnessLength.sqf similarity index 100% rename from addons/advanced_ballistics/functions/fnc_calculateRoughnessLength.sqf rename to addons/weather/functions/fnc_calculateRoughnessLength.sqf diff --git a/addons/weather/functions/fnc_calculateWindSpeed.sqf b/addons/weather/functions/fnc_calculateWindSpeed.sqf new file mode 100644 index 0000000000..b5cde4e959 --- /dev/null +++ b/addons/weather/functions/fnc_calculateWindSpeed.sqf @@ -0,0 +1,90 @@ +/* + * Author: Ruthberg + * + * Calculates the true wind speed at a given world position + * + * Arguments: + * 0: world position - posASL + * 1: Account for wind gradient + * 2: Account for terrain + * 3: Account for obstacles + * + * Return Value: + * 0: wind speed - m/s + * + * Public: No + */ +#include "script_component.hpp" + +private ["_windSpeed", "_windDir", "_height", "_newWindSpeed", "_windSource", "_roughnessLength"]; + +EXPLODE_4_PVT(_this,_position,_windGradientEnabled,_terrainEffectEnabled,_obstacleEffectEnabled); + +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); + +// Wind gradient +if (_windGradientEnabled) then { + if (_windSpeed > 0.05) then { + _height = (ASLToATL _position) select 2; + _height = 0 max _height min 20; + if (_height < 20) then { + _roughnessLength = _position call FUNC(calculateRoughnessLength); + _windSpeed = _windSpeed * abs(ln(_height / _roughnessLength) / ln(20 / _roughnessLength)); + }; + }; +}; + +// Terrain effect on wind +if (_terrainEffectEnabled) then { + if (_windSpeed > 0.05) then { + _newWindSpeed = 0; + { + _windSource = [100, _windDir + 180, _x] call fnc_polar2vect; + if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 9) * _windSpeed; + }; + _windSource = [100, _windDir + 180 + _x, 0] call fnc_polar2vect; + if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 9) * _windSpeed; + }; + _windSource = [100, _windDir + 180 - _x, 0] call fnc_polar2vect; + if (!(terrainIntersectASL [_position, _position 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 (_obstacleEffectEnabled) then { + if (_windSpeed > 0.05) then { + _newWindSpeed = 0; + { + _windSource = [20, _windDir + 180, _x] call fnc_polar2vect; + if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 2) * _windSpeed; + }; + _windSource = [20, _windDir + 180 + _x, 0] call fnc_polar2vect; + if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith { + _newWindSpeed = cos(_x * 2) * _windSpeed; + }; + _windSource = [20, _windDir + 180 - _x, 0] call fnc_polar2vect; + if (!(lineIntersects [_position, _position 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/weather/functions/fnc_displayWindInfo.sqf b/addons/weather/functions/fnc_displayWindInfo.sqf index 7996503719..e81463f41a 100644 --- a/addons/weather/functions/fnc_displayWindInfo.sqf +++ b/addons/weather/functions/fnc_displayWindInfo.sqf @@ -38,15 +38,14 @@ GVAR(WindInfo) = true; _windIndex = 12; _windColor = [1, 1, 1, 1]; - - // Toogle behaviour depending on ace_advanced_ballistics being used or not - // @todo, check ACE_AB is actually enabled - _windSpeed = if (isClass (configFile >> "CfgPatches" >> "ACE_Advanced_Ballistics")) then { - (eyePos ACE_player) call EFUNC(advanced_ballistics,calculateWindSpeed); + _windSpeed = if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { + // With wind gradient + [eyePos ACE_player, true, true, true] call FUNC(calculateWindSpeed); } else { - vectorMagnitude ACE_wind; + // Without wind gradient + [eyePos ACE_player, false, true, true] call FUNC(calculateWindSpeed); }; - + if (_windSpeed > 0.2) then { _playerDir = getDir ACE_player; _windDir = (ACE_wind select 0) atan2 (ACE_wind select 1);