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 0000000000..3bbc441e26 Binary files /dev/null and b/addons/weather/UI/temp_ca.paa differ 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 +