From 0364975c128c2a170f7b0ffc7eb069d56eb95744 Mon Sep 17 00:00:00 2001 From: ulteq Date: Mon, 1 Jun 2015 16:09:35 +0200 Subject: [PATCH] Implemented Density Altitude calculation --- addons/kestrel4500/XEH_postInit.sqf | 6 +++--- .../kestrel4500/functions/fnc_collectData.sqf | 7 +++++-- .../functions/fnc_generateOutputData.sqf | 20 ++++++++++++++++--- addons/weather/XEH_preInit.sqf | 1 + .../fnc_calculateDensityAltitude.sqf | 19 ++++++++++++++++++ 5 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 addons/weather/functions/fnc_calculateDensityAltitude.sqf diff --git a/addons/kestrel4500/XEH_postInit.sqf b/addons/kestrel4500/XEH_postInit.sqf index 98136cbd0b..f22fc2228f 100644 --- a/addons/kestrel4500/XEH_postInit.sqf +++ b/addons/kestrel4500/XEH_postInit.sqf @@ -2,10 +2,10 @@ #include "initKeybinds.sqf" -GVAR(Menus) = ["Date", "Direction", "Wind SPD m/s", "CROSSWIND m/s", "HEADWIND m/s", "TEMP °C", "CHILL °C", "HUMIDITY %", "HEAT INDEX °C", "DEW POINT °C", "WET BULB °C", "BARO hPA", "ALTITUDE m", "User Screen 1", "User Screen 2"]; +GVAR(Menus) = ["Date", "Direction", "Wind SPD m/s", "CROSSWIND m/s", "HEADWIND m/s", "TEMP °C", "CHILL °C", "HUMIDITY %", "HEAT INDEX °C", "DEW POINT °C", "WET BULB °C", "BARO hPA", "ALTITUDE m", "DENS ALT m", "User Screen 1", "User Screen 2"]; -GVAR(TOTAL) = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -GVAR(ENTRIES) = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +GVAR(TOTAL) = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +GVAR(ENTRIES) = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; GVAR(MinAvgMax) = false; GVAR(MinAvgMaxMode) = 0; diff --git a/addons/kestrel4500/functions/fnc_collectData.sqf b/addons/kestrel4500/functions/fnc_collectData.sqf index 41f372d416..1998666d52 100644 --- a/addons/kestrel4500/functions/fnc_collectData.sqf +++ b/addons/kestrel4500/functions/fnc_collectData.sqf @@ -14,13 +14,15 @@ */ #include "script_component.hpp" -private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_altitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_fnc_updateMemory", "_windSpeed", "_crosswind", "_headwind"]; +private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_altitude", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_fnc_updateMemory", "_windSpeed", "_crosswind", "_headwind"]; _playerDir = getDir ACE_player; _playerAltitude = (getPosASL ACE_player) select 2; _temperature = _playerAltitude call EFUNC(weather,calculateTemperatureAtHeight); _humidity = EGVAR(weather,currentHumidity); _barometricPressure = _playerAltitude call EFUNC(weather,calculateBarometricPressure); _altitude = EGVAR(weather,Altitude) + _playerAltitude; +_airDensity = [_temperature, _barometricPressure, _humidity] call EFUNC(weather,calculateAirDensity); +_densityAltitude = _airDensity call EFUNC(weather,calculateDensityAltitude); _chill = [_temperature, _humidity] call EFUNC(weather,calculateWindChill); _heatIndex = [_temperature, _humidity] call EFUNC(weather,calculateHeatIndex); _dewPoint = [_temperature, _humidity] call EFUNC(weather,calculateDewPoint); @@ -33,7 +35,7 @@ if (isNil QGVAR(MIN) || isNil QGVAR(MAX)) then { { GVAR(ENTRIES) set [_x, (GVAR(ENTRIES) select _x) + 1]; -} forEach [1, 5, 6, 7, 8, 9, 10, 11, 12]; +} forEach [1, 5, 6, 7, 8, 9, 10, 11, 12, 13]; _fnc_updateMemory = { PARAMS_2(_slot,_value); @@ -86,3 +88,4 @@ if (GVAR(MinAvgMaxMode) == 1) then { [10, _wetBulb] call _fnc_updateMemory; [11, _barometricPressure] call _fnc_updateMemory; [12, _altitude] call _fnc_updateMemory; +[13, _densityAltitude] call _fnc_updateMemory; diff --git a/addons/kestrel4500/functions/fnc_generateOutputData.sqf b/addons/kestrel4500/functions/fnc_generateOutputData.sqf index fc7b94b711..fce359de6f 100644 --- a/addons/kestrel4500/functions/fnc_generateOutputData.sqf +++ b/addons/kestrel4500/functions/fnc_generateOutputData.sqf @@ -16,7 +16,7 @@ if (ACE_diagTime - GVAR(headingSetDisplayTimer) < 0.8) exitWith {["", "", " Heading Set", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]}; -private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_fnc_dayOfWeek", "_dayString", "_monthString", "_windSpeed", "_windDir", "_textTop", "_textCenterBig", "_textCenter", "_textCenterLine1Left", "_textCenterLine2Left", "_textCenterLine3Left", "_textCenterLine1Right", "_textCenterLine2Right", "_textCenterLine3Right", "_textInfoLine1", "_textInfoLine2", "_textBottomBig", "_textCenterLine1", "_textCenterLine2", "_textCenterLine3", "_textCenterLine4", "_textCenterLine5", "_textCenterLine6"]; +private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_fnc_dayOfWeek", "_dayString", "_monthString", "_windSpeed", "_windDir", "_textTop", "_textCenterBig", "_textCenter", "_textCenterLine1Left", "_textCenterLine2Left", "_textCenterLine3Left", "_textCenterLine1Right", "_textCenterLine2Right", "_textCenterLine3Right", "_textInfoLine1", "_textInfoLine2", "_textBottomBig", "_textCenterLine1", "_textCenterLine2", "_textCenterLine3", "_textCenterLine4", "_textCenterLine5", "_textCenterLine6"]; [] call FUNC(collectData); @@ -52,6 +52,8 @@ _playerAltitude = (getPosASL ACE_player) select 2; _temperature = _playerAltitude call EFUNC(weather,calculateTemperatureAtHeight); _humidity = EGVAR(weather,currentHumidity); _barometricPressure = _playerAltitude call EFUNC(weather,calculateBarometricPressure); +_airDensity = [_temperature, _barometricPressure, _humidity] call EFUNC(weather,calculateAirDensity); +_densityAltitude = _airDensity call EFUNC(weather,calculateDensityAltitude); _chill = [_temperature, _humidity] call EFUNC(weather,calculateWindChill); _heatIndex = [_temperature, _humidity] call EFUNC(weather,calculateHeatIndex); _dewPoint = [_temperature, _humidity] call EFUNC(weather,calculateDewPoint); @@ -284,7 +286,19 @@ if (GVAR(referenceHeadingMenu) == 0) then { _textCenterLine3Right = Str(round(GVAR(Max) select 12)); }; }; - case 13: { // User Screen 1 + case 13: { // DENSITY ALTITUDE + if (!GVAR(MinAvgMax)) then { + _textCenterBig = Str(round(_densityAltitude)); + } else { + _textCenterLine1Left = "Min"; + _textCenterLine2Left = "Avg"; + _textCenterLine3Left = "Max"; + _textCenterLine1Right = Str(round(GVAR(Min) select 13)); + _textCenterLine2Right = Str(round((GVAR(Total) select 13) / (GVAR(Entries) select 13))); + _textCenterLine3Right = Str(round(GVAR(Max) select 13)); + }; + }; + case 14: { // User Screen 1 _textCenterLine1Left = Str(round(_playerDir)); _textCenterLine2Left = Str(round(EGVAR(weather,Altitude) + _playerAltitude)); _textCenterLine3Left = Str(round(abs(_windSpeed) * 10) / 10); @@ -292,7 +306,7 @@ if (GVAR(referenceHeadingMenu) == 0) then { _textCenterLine2Right = "m"; _textCenterLine3Right = "m/s"; }; - case 14: { // User Screen 2 + case 15: { // User Screen 2 _textCenterLine1Left = Str(round(_temperature * 10) / 10); _textCenterLine2Left = Str(round(_humidity * 100 * 10) / 10); _textCenterLine3Left = Str(round((_playerAltitude call EFUNC(weather,calculateBarometricPressure)) * 10) / 10); diff --git a/addons/weather/XEH_preInit.sqf b/addons/weather/XEH_preInit.sqf index 177b58ec82..eb5291334a 100644 --- a/addons/weather/XEH_preInit.sqf +++ b/addons/weather/XEH_preInit.sqf @@ -5,6 +5,7 @@ ADDON = false; PREP(calculateAirDensity); PREP(calculateBarometricPressure); +PREP(calculateDensityAltitude); PREP(calculateDewPoint); PREP(calculateHeatIndex); PREP(calculateRoughnessLength); diff --git a/addons/weather/functions/fnc_calculateDensityAltitude.sqf b/addons/weather/functions/fnc_calculateDensityAltitude.sqf new file mode 100644 index 0000000000..97889e2499 --- /dev/null +++ b/addons/weather/functions/fnc_calculateDensityAltitude.sqf @@ -0,0 +1,19 @@ +/* + * Author: Ruthberg + * + * Calculates density altitude for a given air density + * + * Arguments: + * density of air - kg * m^(-3) + * + * Return Value: + * density altitude - m + * + * Return value: + * None + */ +#include "script_component.hpp" + +// Source: http://wahiduddin.net/calc/density_altitude.htm + +((44.3308 - 42.2665 * _this ^ 0.2349692456) * 1000)