From 846b65864f21f6b09e6803c269da0335268db9b9 Mon Sep 17 00:00:00 2001 From: LorenLuke Date: Thu, 12 Dec 2019 13:31:51 -0800 Subject: [PATCH] Weather - Add a 'check air temperature' action (#6154) --- addons/weather/ACE_Settings.hpp | 19 +---- addons/weather/CfgVehicles.hpp | 13 ++++ addons/weather/UI/temp_ca.paa | Bin 0 -> 22016 bytes addons/weather/XEH_PREP.hpp | 2 + addons/weather/XEH_preInit.sqf | 2 + .../weather/functions/fnc_displayAirTemp.sqf | 72 ++++++++++++++++++ .../functions/fnc_getApproximateAirTemp.sqf | 70 +++++++++++++++++ addons/weather/initSettings.sqf | 39 ++++++++++ addons/weather/stringtable.xml | 6 ++ 9 files changed, 207 insertions(+), 16 deletions(-) create mode 100644 addons/weather/UI/temp_ca.paa create mode 100644 addons/weather/functions/fnc_displayAirTemp.sqf create mode 100644 addons/weather/functions/fnc_getApproximateAirTemp.sqf create mode 100644 addons/weather/initSettings.sqf diff --git a/addons/weather/ACE_Settings.hpp b/addons/weather/ACE_Settings.hpp index e2eb4590b7..2028beac3e 100644 --- a/addons/weather/ACE_Settings.hpp +++ b/addons/weather/ACE_Settings.hpp @@ -1,24 +1,11 @@ class ACE_Settings { class GVAR(enabled) { - category = CSTRING(Module_DisplayName); - displayName = CSTRING(enabled_DisplayName); - description = CSTRING(enabled_Description); - typeName = "BOOL"; - value = 1; + movedToSQF = 1; }; class GVAR(updateInterval) { - category = CSTRING(Module_DisplayName); - displayName = CSTRING(updateInterval_DisplayName); - description = CSTRING(updateInterval_Description); - typeName = "SCALAR"; - value = 60; - sliderSettings[] = {0, 300, 0, 0}; + movedToSQF = 1; }; class GVAR(windSimulation) { - category = CSTRING(Module_DisplayName); - displayName = CSTRING(windSimulation_DisplayName); - description = CSTRING(windSimulation_Description); - typeName = "BOOL"; - value = 1; + movedToSQF = 1; }; }; diff --git a/addons/weather/CfgVehicles.hpp b/addons/weather/CfgVehicles.hpp index cab16183a8..151b756c49 100644 --- a/addons/weather/CfgVehicles.hpp +++ b/addons/weather/CfgVehicles.hpp @@ -1,4 +1,17 @@ class CfgVehicles { + class Man; + class CAManBase: Man { + class ACE_SelfActions { + class ACE_CheckAirTemperature { + displayName = CSTRING(CheckAirTemperature); + condition = QUOTE(GVAR(enabled) && GVAR(showCheckAirTemperature)); + exceptions[] = {"isNotInside", "isNotSitting"}; + statement = QUOTE([ACE_player] call FUNC(getApproximateAirTemp)); + icon = QPATHTOF(UI\temp_ca.paa); + }; + }; + }; + class ACE_Module; class GVAR(ModuleSettings): ACE_Module { scope = 1; diff --git a/addons/weather/UI/temp_ca.paa b/addons/weather/UI/temp_ca.paa new file mode 100644 index 0000000000000000000000000000000000000000..3bbc441e2669ae7533133c0b23715c718fcc3336 GIT binary patch literal 22016 zcmeHP4Qx}_6}~nxU^H;ba05zA+$AQEmnw=s0)9I%QgaR zWqGuf*d)3zByUt}=5%dVT8WK_#iD;W0m4sV1e!K=;x1{$kB164PBJHHo^yB3dwFT} zOcdOQ!L;uxc6|KKJ@=mT-Fx1>=bdW}Ei7DaSy5b#ev)kd4QtqJz=G1irxuG_GzG}5kvw##2DJ@U>)awPg z@|F7XEFi^OO3Rb3;4jyH@vbk$TT07qUn);Z%ayOxmuCSf9#UGKbY=d_wO_pJOYxS{ za@&{6lhShKEA{1BK#GTymM2}A|8ngY@A^`_rL^4krShb-T=`0Uc@~i3A*H3#7lo!j z&v9;=2eDy%sIsW{A#Mg8&O@4!G6OA@C#7#uMfvJ3T0n}2l$Lfyyk4SCSHB5GN>9cQ z0l!;5Kalb(^xd_9h~MqvBl0Ww-(8&I)tZQ>f`7a$oY-;|{1Y3Wc=t}hKi(EjZ21cQ ziH%RZd#B(ZZwn{3d2j*9-B(5g;KS5YhpsZRN*>YTj0TS=WFRm8$Z8bzDMQvR?s&LK1lKWE9T?c?Kb19;VKTQAl@34YTQ4JP!$ z_~}$^PY*@p7hCcS3H;b!B|ljH7(VjFa1Z5bdHjibno4T#dF5~(Ov!VxY) z!2L(v|H}pd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w6KjwUi2UN&pD)vi&w0es{Xd#IX6G;aOCuW8A72J)wbTk zXHV=;>-2)}eeAIxG1B@o$xLuxgnbtxa-Pzq*bL@+ui^~6&EFeM+JKp?3%v$%%U47@ayGJgx3BK!YQlN literal 0 HcmV?d00001 diff --git a/addons/weather/XEH_PREP.hpp b/addons/weather/XEH_PREP.hpp index 48788c0546..5f17905849 100644 --- a/addons/weather/XEH_PREP.hpp +++ b/addons/weather/XEH_PREP.hpp @@ -10,7 +10,9 @@ PREP(calculateTemperatureAtHeight); PREP(calculateWetBulb); PREP(calculateWindChill); PREP(calculateWindSpeed); +PREP(displayAirTemp); PREP(displayWindInfo); +PREP(getApproximateAirTemp); PREP(getMapData); PREP(initModuleSettings); PREP(initWind); diff --git a/addons/weather/XEH_preInit.sqf b/addons/weather/XEH_preInit.sqf index 1b551f133e..438c3e9962 100644 --- a/addons/weather/XEH_preInit.sqf +++ b/addons/weather/XEH_preInit.sqf @@ -7,6 +7,8 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +#include "initSettings.sqf" + // Make sure this data is read before client/server postInit call FUNC(getMapData); diff --git a/addons/weather/functions/fnc_displayAirTemp.sqf b/addons/weather/functions/fnc_displayAirTemp.sqf new file mode 100644 index 0000000000..e32d60a159 --- /dev/null +++ b/addons/weather/functions/fnc_displayAirTemp.sqf @@ -0,0 +1,72 @@ +#include "script_component.hpp" +/* + * Author: LorenLuke + * Displays an abstracted depiction of air temperature to a unit. + * + * Arguments: + * 0: Temperature + * 1: Unit Bias range + * + * Return Value: + * None + * + * Example: + * [15.8] call ace_weather_fnc_displayAirTemp + * + * Public: No + */ + +params ["_apparent_temperature", "_bias"]; +TRACE_2("params",_temperature, _bias); + +_temperature1 = floor(_temperature + (_bias select 0) - (random 2)); +_temperature2 = floor(_temperature + (_bias select 1) + (random 2)); + +private _color1 = [ +// Colors obtained by quartic regression formula of RGB values at corresponding temperatures as marked on advanced_ballistics rangecard + ( (((-0.000238348 * (_temperature1 ^ 4)) - (0.00865642 * (_temperature1 ^ 3)) + (0.794548 * (_temperature1 ^2)) - (0.323314 * _temperature1) +6.78445) min 255) /255) max 0, + ( (((-0.000308515 * (_temperature1 ^ 4)) + (0.000245732 * (_temperature1 ^ 3)) + (0.308531 * (_temperature1 ^2)) - (02.78916 * _temperature1) +164.326) min 255) /255) max 0, + ( (((-0.000107648 * (_temperature1 ^ 4)) + (0.00106365 * (_temperature1 ^ 3)) - (0.0989707 * (_temperature1 ^2)) - (9.66256 * _temperature1) +171.402) min 255) /255) max 0 +]; + +private _text = composeText ["", [format ["%1C", _temperature1],_color1] call EFUNC(common,stringToColoredText)]; +_text = composeText [_text, [" --- ", [1,1,1]] call EFUNC(common,stringToColoredText)]; + +private _color2 = [ +// Colors obtained by quartic regression formula of RGB values at corresponding temperatures as marked on advanced_ballistics rangecard + ( (((-0.000238348 * (_temperature2 ^ 4)) - (0.00865642 * (_temperature2 ^ 3)) + (0.794548 * (_temperature2 ^2)) - (0.323314 * _temperature2) +6.78445) min 255) /255) max 0, + ( (((-0.000308515 * (_temperature2 ^ 4)) + (0.000245732 * (_temperature2 ^ 3)) + (0.308531 * (_temperature2 ^2)) - (02.78916 * _temperature2) +164.326) min 255) /255) max 0, + ( (((-0.000107648 * (_temperature2 ^ 4)) + (0.00106365 * (_temperature2 ^ 3)) - (0.0989707 * (_temperature2 ^2)) - (9.66256 * _temperature2) +171.402) min 255) /255) max 0 +]; + + _text = composeText [_text, [format ["%1C", _temperature2], _color2] call EFUNC(common,stringToColoredText)]; + +[_text, QPATHTOF(UI\temp_ca.paa),_color, ACE_player, 2] call EFUNC(common,displayTextPicture); + +/* +for "_i" from -40 to 40 step 4 do { + _temp_color = _color; + + if (_i == 0) then { + _text = composeText [_text, ["[", _temp_color] call EFUNC(common,stringToColoredText)]; + _text = composeText [_text, ["0", [0.6, 1, 0.6]] call EFUNC(common,stringToColoredText)]; + _text = composeText [_text, ["]", _temp_color] call EFUNC(common,stringToColoredText)]; + } else { + _string = "I"; + }; + + if (abs( _i - _apparent_temperature) < 8.5) then { + _temp_color = [ + // Colors obtained by quartic regression formula of RGB values at corresponding temperatures as marked on advanced_ballistics rangecard + ( (((-0.000238348 * (_i ^ 4)) - (0.00865642 * (_i ^ 3)) + (0.794548 * (_i ^2)) - (0.323314 * _i) +6.78445) min 255) /255) max 0, + ( (((-0.000308515 * (_i ^ 4)) + (0.000245732 * (_i ^ 3)) + (0.308531 * (_i ^2)) - (02.78916 * _i) +164.326) min 255) /255) max 0, + ( (((-0.000107648 * (_i ^ 4)) + (0.00106365 * (_i ^ 3)) - (0.0989707 * (_i ^2)) - (9.66256 * _i) +171.402) min 255) /255) max 0 + ]; + }; + + _text = composeText [_text, [_string, [_temp_color select 0, _temp_color select 1, _temp_color select 2]] call EFUNC(common,stringToColoredText)]; +}; + +_text = composeText [_text, [" +40C", [1,0,0]] call EFUNC(common,stringToColoredText)]; +*/ +[_text, QPATHTOF(UI\temp_ca.paa),[1,1,1], ACE_player, 2] call EFUNC(common,displayTextPicture); diff --git a/addons/weather/functions/fnc_getApproximateAirTemp.sqf b/addons/weather/functions/fnc_getApproximateAirTemp.sqf new file mode 100644 index 0000000000..e9d00570df --- /dev/null +++ b/addons/weather/functions/fnc_getApproximateAirTemp.sqf @@ -0,0 +1,70 @@ +#include "script_component.hpp" +/* + * Author: LorenLuke + * Returns an approximate representation of temperature at a unit's location. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * [ACE_player] call ace_weather_fnc_getApproximateAirTemp + * + * Public: No + */ + +params ["_unit"]; +TRACE_1("params",_unit); + +if (isNil (format ["%1", _unit getVariable "ACE_airTemperatureBias"])) then { + _unit setVariable ["ACE_airTemperatureBias", [-(random(3) + 1), random(3) + 1]]; +}; + +private _temperature = ((getPosASL _unit) select 2) call EFUNC(weather,calculateTemperatureAtHeight); +private _humidity = EGVAR(weather,currentHumidity); +private _heatIndex = [_temperature, _humidity] call EFUNC(weather,calculateHeatIndex); +private _chill = [_temperature, _humidity] call EFUNC(weather,calculateWindChill); + +private _e = 2^(1/(ln 2)); + +/* +// Windchill calc with wind vars; https://en.wikipedia.org/wiki/Wind_chill#Australian_Apparent_Temperature +private _windspeed = [getPosASL _unit, true, true, true] call EFUNC(weather,calculateWindSpeed); +private _water_vapor_pressure = _humidity * 6.105 *(_e ^ ((17.27 * _temperature)/(237.7 + _temperature))) / 100; +private _chill = _temperature + (0.33 * _water_vapor_pressure) - (0.70 * _windspeed) - 400; +*/ + +// sigmoid = f(x) = L / (1 + e^(-k * (x - x_0))); +// L max value, e = euler, k = steepness, + +// L = max value +private _sigmoid_L = 1; + +// x_0 = sigmoid midpoint, aka 50% proportion; 18.5C, ~65F +private _sigmoid_midpoint = 18.5; + +// place +- midpoint with desired proportion +private _sigmoid_valuation = 8.5; + +// desired upper and proportion on sigmoid +private _sigmoid_proportion_at_valuation = 0.95; +private _sigmoid_proportion_at_lower_valuation = 1 - _sigmoid_proportion_at_valuation; + +// k = steepness +private _sigmoid_k = (ln ((_sigmoid_proportion_at_lower_valuation^-1) - 1) ) / _sigmoid_valuation; + +// 5$/95% @ 10C/27C; [5% and 95% values at 50F and ~80F]; +// 5% = 0.05 = 1/20 = f(_midpoint - _valuation) = L / (1 + e^(-k * ((_midpoint - _valuation) - _midpoint) +// (0.05)^-1 = 20 = (L / (1 + e^(-k * (-_valuation))) )^-1 = (1 + e^(-k * -_valuation))/L; +// L = 1;> 20 = (1 + e^(k * valuation)); 20 - 1 = e^(k * valuation); +// 19 = e^(k * 8.5); (log_e 19) = (k * 8.5); (log_e 19)/8.5 = k; + +// retrieve sigmoid proportion at _temperature +private _temperature_sigmoid = _sigmoid_L / (1 + _e^(-_sigmoid_k * (_temperature - _sigmoid_midpoint))); + +// Weighted average between windchill and heat index based on sigmoid levels, plus +- 4deg randomisation +private _apparent_temperature = ((_temperature_sigmoid * _heatIndex) + ((1 - _temperature_sigmoid) * _chill) + random(8) - 4); + +[_apparent_temperature, (_unit getVariable "ACE_airTemperatureBias")] call FUNC(displayAirTemp); diff --git a/addons/weather/initSettings.sqf b/addons/weather/initSettings.sqf new file mode 100644 index 0000000000..6439c32570 --- /dev/null +++ b/addons/weather/initSettings.sqf @@ -0,0 +1,39 @@ +private _category = [format ["ACE %1", LLSTRING(Module_DisplayName)]]; + +[ + QGVAR(enabled), "CHECKBOX", + [LSTRING(enabled_DisplayName), LSTRING(enabled_Description)], + _category, + true, // default value + true, // isGlobal + {[QGVAR(enabled), _this] call EFUNC(common,cbaSettings_settingChanged)}, + true // Needs mission restart +] call CBA_settings_fnc_init; + +[ + QGVAR(updateInterval), "SLIDER", + [LSTRING(updateInterval_DisplayName), LSTRING(updateInterval_Description)], + _category, + [0,300,60,0], // [min, max, default value, trailing decimals (-1 for whole numbers only)] + true, // isGlobal + {[QGVAR(updateInterval), _this] call EFUNC(common,cbaSettings_settingChanged)}, + true // Needs mission restart +] call CBA_settings_fnc_init; + +[ + QGVAR(windSimulation), "CHECKBOX", + [LSTRING(windSimulation_DisplayName), LSTRING(windSimulation_Description)], + _category, + true, // default value + true, // isGlobal + {[QGVAR(windSimulation), _this] call EFUNC(common,cbaSettings_settingChanged)}, + true // Needs mission restart +] call CBA_settings_fnc_init; + +[ + QGVAR(showCheckAirTemperature), "CHECKBOX", + [LSTRING(showCheckAirTemperature_DisplayName)], + _category, + true, // default value + false, // isGlobal +] call CBA_settings_fnc_init; diff --git a/addons/weather/stringtable.xml b/addons/weather/stringtable.xml index 99ec47296a..0e837bc182 100644 --- a/addons/weather/stringtable.xml +++ b/addons/weather/stringtable.xml @@ -152,5 +152,11 @@ Ativar a simulação de vento dos mapas. (sobrepõe vento vanilla) Povoluje simulaci větru založenou na mapě (přepíše původní vítr) + + Check Air Temperature + + + Show Check Air Temperature Action +