diff --git a/addons/advanced_ballistics/functions/fnc_handleFired.sqf b/addons/advanced_ballistics/functions/fnc_handleFired.sqf index 5404953bd0..bb0b649da4 100644 --- a/addons/advanced_ballistics/functions/fnc_handleFired.sqf +++ b/addons/advanced_ballistics/functions/fnc_handleFired.sqf @@ -76,7 +76,7 @@ if (GVAR(barrelLengthInfluenceEnabled)) then { }; if (GVAR(ammoTemperatureEnabled)) then { - _temperature = GET_TEMPERATURE_AT_HEIGHT((getPosASL _unit) select 2); + _temperature = ((getPosASL _unit) select 2) call EFUNC(weather,calculateTemperatureAtHeight); _muzzleVelocityShift = [_AmmoCacheEntry select 9, _temperature] call FUNC(calculateAmmoTemperatureVelocityShift); if (_muzzleVelocityShift != 0) then { _bulletVelocity = _bulletVelocity vectorAdd ((vectorNormalized _bulletVelocity) vectorMultiply (_muzzleVelocityShift)); @@ -105,7 +105,7 @@ _barrelTwist = _WeaponCacheEntry select 0; _stabilityFactor = 1.5; if (_caliber > 0 && _bulletLength > 0 && _bulletMass > 0 && _barrelTwist > 0) then { - _temperature = GET_TEMPERATURE_AT_HEIGHT((getPosASL _unit) select 2); + _temperature = ((getPosASL _unit) select 2) call EFUNC(weather,calculateTemperatureAtHeight); _barometricPressure = ((getPosASL _bullet) select 2) call EFUNC(weather,calculateBarometricPressure); _stabilityFactor = [_caliber, _bulletLength, _bulletMass, _barrelTwist, _muzzleVelocity, _temperature, _barometricPressure] call FUNC(calculateStabilityFactor); }; diff --git a/addons/advanced_ballistics/script_component.hpp b/addons/advanced_ballistics/script_component.hpp index 3334bb3207..757330a5d0 100644 --- a/addons/advanced_ballistics/script_component.hpp +++ b/addons/advanced_ballistics/script_component.hpp @@ -21,6 +21,5 @@ #define SPECIFIC_GAS_CONSTANT_DRY_AIR 287.058 #define STD_AIR_DENSITY_ICAO 1.22498 #define STD_AIR_DENSITY_ASM 1.20885 -#define GET_TEMPERATURE_AT_HEIGHT(h) (EGVAR(weather,currentTemperature) - 0.0065 * (h)) #define EXTENSION_REQUIRED_VERSION "1.0" diff --git a/addons/kestrel4500/XEH_postInit.sqf b/addons/kestrel4500/XEH_postInit.sqf index 24a972c326..eb22aa1de2 100644 --- a/addons/kestrel4500/XEH_postInit.sqf +++ b/addons/kestrel4500/XEH_postInit.sqf @@ -22,4 +22,6 @@ GVAR(MeasuredWindSpeed) = 0; GVAR(ImpellerState) = 0; GVAR(Kestrel4500) = false; -GVAR(Overlay) = false; \ No newline at end of file +GVAR(Overlay) = false; + +[] call FUNC(restoreUserData); \ No newline at end of file diff --git a/addons/kestrel4500/XEH_preInit.sqf b/addons/kestrel4500/XEH_preInit.sqf index 4e29b9bdbf..7b36167a16 100644 --- a/addons/kestrel4500/XEH_preInit.sqf +++ b/addons/kestrel4500/XEH_preInit.sqf @@ -9,10 +9,11 @@ PREP(createKestrelDialog); PREP(displayKestrel); PREP(generateOutputData); PREP(measureWindSpeed); +PREP(onCloseDialog); +PREP(onCloseDisplay); +PREP(restoreUserData); +PREP(storeUserData); PREP(updateDisplay); PREP(updateImpellerState); -PREP(onCloseDialog); -PREP(onCloseDisplay); - ADDON = true; diff --git a/addons/kestrel4500/functions/fnc_buttonPressed.sqf b/addons/kestrel4500/functions/fnc_buttonPressed.sqf index f0f9a10db1..1d73f9ac79 100644 --- a/addons/kestrel4500/functions/fnc_buttonPressed.sqf +++ b/addons/kestrel4500/functions/fnc_buttonPressed.sqf @@ -51,3 +51,4 @@ switch (_this) do { }; [] call FUNC(updateDisplay); +[] call FUNC(storeUserData); diff --git a/addons/kestrel4500/functions/fnc_collectData.sqf b/addons/kestrel4500/functions/fnc_collectData.sqf index a812ad0f7c..60bab4b9ec 100644 --- a/addons/kestrel4500/functions/fnc_collectData.sqf +++ b/addons/kestrel4500/functions/fnc_collectData.sqf @@ -14,13 +14,14 @@ */ #include "script_component.hpp" -private ["_playerDir", "_windSpeed", "_crosswind", "_headwind", "_humidity", "_temperature", "_humidity", "_barometricPressure", "_altitude"]; +private ["_playerAltitude", "_playerDir", "_windSpeed", "_crosswind", "_headwind", "_humidity", "_temperature", "_humidity", "_barometricPressure", "_altitude"]; +_playerAltitude = (getPosASL ACE_player) select 2; if (isNil QGVAR(MIN) || isNil QGVAR(MAX)) then { - _temperature = GET_TEMPERATURE_AT_HEIGHT((getPosASL ACE_player) select 2); + _temperature = _playerAltitude call EFUNC(weather,calculateTemperatureAtHeight); _humidity = EGVAR(weather,currentHumidity); - _barometricPressure = ((getPosASL ACE_player) select 2) call EFUNC(weather,calculateBarometricPressure); - _altitude = EGVAR(weather,Altitude) + ((getPosASL ACE_player) select 2); + _barometricPressure = _playerAltitude call EFUNC(weather,calculateBarometricPressure); + _altitude = EGVAR(weather,Altitude) + _playerAltitude; GVAR(MIN) = [0, 0, 0, 0, _temperature, _humidity, _barometricPressure, _altitude]; GVAR(MAX) = [0, 0, 0, 0, _temperature, _humidity, _barometricPressure, _altitude]; }; @@ -42,9 +43,9 @@ if (GVAR(MinAvgMaxMode) == 1) then { // Wind SPD _windSpeed = call FUNC(measureWindSpeed); - GVAR(MIN) set [1, (GVAR(MIN) select 1) min abs(_windSpeed)]; - GVAR(MAX) set [1, abs(_windSpeed) max (GVAR(MAX) select 1)]; - GVAR(TOTAL) set [1, (GVAR(TOTAL) select 1) + abs(_windSpeed)]; + GVAR(MIN) set [1, (GVAR(MIN) select 1) min _windSpeed]; + GVAR(MAX) set [1, _windSpeed max (GVAR(MAX) select 1)]; + GVAR(TOTAL) set [1, (GVAR(TOTAL) select 1) + _windSpeed]; // CROSSWIND _crosswind = 0; @@ -70,7 +71,7 @@ if (GVAR(MinAvgMaxMode) == 1) then { }; // TEMP -_temperature = GET_TEMPERATURE_AT_HEIGHT((getPosASL ACE_player) select 2); +_temperature = _playerAltitude call EFUNC(weather,calculateTemperatureAtHeight); GVAR(MIN) set [4, (GVAR(MIN) select 4) min _temperature]; GVAR(MAX) set [4, _temperature max (GVAR(MAX) select 4)]; GVAR(TOTAL) set [4, (GVAR(TOTAL) select 4) + _temperature]; @@ -82,13 +83,13 @@ GVAR(MAX) set [5, _humidity max (GVAR(MAX) select 5)]; GVAR(TOTAL) set [5, (GVAR(TOTAL) select 5) + _humidity]; // BARO -_barometricPressure = ((getPosASL ACE_player) select 2) call EFUNC(weather,calculateBarometricPressure); +_barometricPressure = _playerAltitude call EFUNC(weather,calculateBarometricPressure); GVAR(MIN) set [6, (GVAR(MIN) select 6) min _barometricPressure]; GVAR(MAX) set [6, _barometricPressure max (GVAR(MAX) select 6)]; GVAR(TOTAL) set [6, (GVAR(TOTAL) select 6) + _barometricPressure]; // ALTITUDE -_altitude = EGVAR(weather,Altitude) + ((getPosASL ACE_player) select 2); +_altitude = EGVAR(weather,Altitude) + _playerAltitude; GVAR(MIN) set [7, (GVAR(MIN) select 7) min _altitude]; GVAR(MAX) set [7, _altitude max (GVAR(MAX) select 7)]; GVAR(TOTAL) set [7, (GVAR(TOTAL) select 7) + _altitude]; \ No newline at end of file diff --git a/addons/kestrel4500/functions/fnc_generateOutputData.sqf b/addons/kestrel4500/functions/fnc_generateOutputData.sqf index 6b139fe72e..1549bbe9cb 100644 --- a/addons/kestrel4500/functions/fnc_generateOutputData.sqf +++ b/addons/kestrel4500/functions/fnc_generateOutputData.sqf @@ -34,10 +34,11 @@ _textInfoLine2 = ""; _windSpeed = call FUNC(measureWindSpeed); _windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); -_temperature = GET_TEMPERATURE_AT_HEIGHT((getPosASL ACE_player) select 2); -_humidity = EGVAR(weather,currentHumidity); - _playerDir = getDir ACE_player; +_playerAltitude = (getPosASL ACE_player) select 2; + +_temperature = _playerAltitude call EFUNC(weather,calculateTemperatureAtHeight); +_humidity = EGVAR(weather,currentHumidity); GVAR(Direction) = 4 * floor(_playerDir / 90); if (_playerDir % 90 > 10) then { GVAR(Direction) = GVAR(Direction) + 1}; @@ -174,7 +175,7 @@ switch (GVAR(Menu)) do { }; case 6: { // BARO if (!GVAR(MinAvgMax)) then { - _textCenterBig = Str(round((((getPosASL ACE_player) select 2) call EFUNC(weather,calculateBarometricPressure)) * 10) / 10); + _textCenterBig = Str(round((_playerAltitude call EFUNC(weather,calculateBarometricPressure)) * 10) / 10); } else { _textCenterLine1Left = "Min"; _textCenterLine2Left = "Avg"; @@ -186,7 +187,7 @@ switch (GVAR(Menu)) do { }; case 7: { // ALTITUDE if (!GVAR(MinAvgMax)) then { - _textCenterBig = Str(round(EGVAR(weather,Altitude) + ((getPosASL ACE_player) select 2))); + _textCenterBig = Str(round(EGVAR(weather,Altitude) + _playerAltitude)); } else { _textCenterLine1Left = "Min"; _textCenterLine2Left = "Avg"; @@ -198,7 +199,7 @@ switch (GVAR(Menu)) do { }; case 8: { // User Screen 1 _textCenterLine1Left = Str(round(_playerDir)); - _textCenterLine2Left = Str(round(EGVAR(weather,Altitude) + ((getPosASL ACE_player) select 2))); + _textCenterLine2Left = Str(round(EGVAR(weather,Altitude) + _playerAltitude)); _textCenterLine3Left = Str(round(abs(_windSpeed) * 10) / 10); _textCenterLine1Right = GVAR(Directions) select GVAR(Direction); _textCenterLine2Right = "m"; @@ -207,7 +208,7 @@ switch (GVAR(Menu)) do { case 9: { // User Screen 2 _textCenterLine1Left = Str(round(_temperature * 10) / 10); _textCenterLine2Left = Str(round(_humidity * 100 * 10) / 10); - _textCenterLine3Left = Str(round((1013.25 * exp(-(EGVAR(weather,Altitude) + ((getPosASL ACE_player) select 2)) / 7990) - 10 * overcast) * 10) / 10); + _textCenterLine3Left = Str(round((_playerAltitude call EFUNC(weather,calculateBarometricPressure)) * 10) / 10); _textCenterLine1Right = "C"; _textCenterLine2Right = "%"; _textCenterLine3Right = "hPA"; diff --git a/addons/kestrel4500/functions/fnc_restoreUserData.sqf b/addons/kestrel4500/functions/fnc_restoreUserData.sqf new file mode 100644 index 0000000000..3cd96d80af --- /dev/null +++ b/addons/kestrel4500/functions/fnc_restoreUserData.sqf @@ -0,0 +1,18 @@ +/* + * Author: Ruthberg + * Reads user data from profileNamespace + * + * Arguments: + * Nothing + * + * Return Value: + * Nothing + * + * Example: + * call ace_kestrel4500_fnc_restore_user_data + * + * Public: No + */ +#include "script_component.hpp" + +GVAR(Menu) = 0 max (profileNamespace getVariable ["ACE_Kestrel4500_menu", 0]) min ((count GVAR(Menus)) - 1); diff --git a/addons/kestrel4500/functions/fnc_storeUserData.sqf b/addons/kestrel4500/functions/fnc_storeUserData.sqf new file mode 100644 index 0000000000..3b7ce9dd4d --- /dev/null +++ b/addons/kestrel4500/functions/fnc_storeUserData.sqf @@ -0,0 +1,18 @@ +/* + * Author: Ruthberg + * Saves user data into profileNamespace + * + * Arguments: + * Nothing + * + * Return Value: + * Nothing + * + * Example: + * call ace_kestrel4500_fnc_store_user_data + * + * Public: No + */ +#include "script_component.hpp" + +profileNamespace setVariable ["ACE_Kestrel4500_menu", GVAR(menu)]; diff --git a/addons/kestrel4500/script_component.hpp b/addons/kestrel4500/script_component.hpp index b8db2edb78..90c338ebeb 100644 --- a/addons/kestrel4500/script_component.hpp +++ b/addons/kestrel4500/script_component.hpp @@ -10,5 +10,3 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" - -#define GET_TEMPERATURE_AT_HEIGHT(h) (EGVAR(weather,currentTemperature) - 0.0065 * (h)) diff --git a/addons/mk6mortar/functions/fnc_handleFired.sqf b/addons/mk6mortar/functions/fnc_handleFired.sqf index e2b440c520..284560b775 100644 --- a/addons/mk6mortar/functions/fnc_handleFired.sqf +++ b/addons/mk6mortar/functions/fnc_handleFired.sqf @@ -42,8 +42,7 @@ if (_bisAirFriction != 0) exitWith {ERROR("Non zero base airFriction");}; //Calculate air density: _altitude = (getPosASL _vehicle) select 2; -#define GET_TEMPERATURE_AT_HEIGHT(h) (EGVAR(weather,currentTemperature) - 0.0065 * (h)) -_temperature = GET_TEMPERATURE_AT_HEIGHT(_altitude); +_temperature = _altitude call EFUNC(weather,calculateTemperatureAtHeight); _pressure = _altitude call EFUNC(weather,calculateBarometricPressure); _relativeHumidity = EGVAR(weather,currentHumidity); _airDensity = [_temperature, _pressure, _relativeHumidity] call EFUNC(weather,calculateAirDensity); diff --git a/addons/weather/XEH_preInit.sqf b/addons/weather/XEH_preInit.sqf index 6e6e008a67..85166ce356 100644 --- a/addons/weather/XEH_preInit.sqf +++ b/addons/weather/XEH_preInit.sqf @@ -6,6 +6,7 @@ ADDON = false; PREP(calculateAirDensity); PREP(calculateBarometricPressure); PREP(calculateRoughnessLength); +PREP(calculateTemperatureAtHeight); PREP(calculateWindSpeed); PREP(displayWindInfo); PREP(getMapData); diff --git a/addons/weather/functions/fnc_calculateBarometricPressure.sqf b/addons/weather/functions/fnc_calculateBarometricPressure.sqf index c65d343c93..1e1d47098c 100644 --- a/addons/weather/functions/fnc_calculateBarometricPressure.sqf +++ b/addons/weather/functions/fnc_calculateBarometricPressure.sqf @@ -14,7 +14,4 @@ */ #include "script_component.hpp" -private ["_altitude"]; -_altitude = _this; - -(1013.25 * exp(-(GVAR(Altitude) + _altitude) / 7990) - 10 * overcast) +(1013.25 * exp(-(GVAR(Altitude) + _this) / 7990) - 10 * overcast) diff --git a/addons/weather/functions/fnc_calculateTemperatureAtHeight.sqf b/addons/weather/functions/fnc_calculateTemperatureAtHeight.sqf new file mode 100644 index 0000000000..dd31dfe05e --- /dev/null +++ b/addons/weather/functions/fnc_calculateTemperatureAtHeight.sqf @@ -0,0 +1,17 @@ +/* + * Author: Ruthberg + * + * Calculates the temperature based on altitude and weather + * + * Arguments: + * 0: height - meters + * + * Return Value: + * 0: temperature - degrees celsius + * + * Return value: + * None + */ +#include "script_component.hpp" + +(GVAR(currentTemperature) - 0.0065 * _this)