From e2c08d2c26fe09440f4a396006dba3200c1f4d84 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 5 Jan 2016 01:39:29 -0600 Subject: [PATCH] Privates, Headers, Merge 4 PFEH into one --- addons/weather/CfgVehicles.hpp | 2 +- addons/weather/CfgWorlds.hpp | 2 +- addons/weather/RscTitles.hpp | 14 ++-- addons/weather/XEH_postInit.sqf | 42 ++++++++-- addons/weather/XEH_postServerInit.sqf | 8 +- .../functions/fnc_calculateAirDensity.sqf | 16 ++-- .../fnc_calculateBarometricPressure.sqf | 7 +- .../fnc_calculateDensityAltitude.sqf | 7 +- .../functions/fnc_calculateDewPoint.sqf | 14 ++-- .../functions/fnc_calculateHeatIndex.sqf | 9 +- .../fnc_calculateRoughnessLength.sqf | 16 ++-- .../functions/fnc_calculateSpeedOfSound.sqf | 9 +- .../fnc_calculateTemperatureAtHeight.sqf | 7 +- .../functions/fnc_calculateWetBulb.sqf | 25 +++--- .../functions/fnc_calculateWindChill.sqf | 6 +- .../functions/fnc_calculateWindSpeed.sqf | 37 +++++---- .../weather/functions/fnc_displayWindInfo.sqf | 20 +++-- addons/weather/functions/fnc_getMapData.sqf | 8 +- addons/weather/functions/fnc_getWind.sqf | 12 +-- .../functions/fnc_initModuleSettings.sqf | 3 + addons/weather/functions/fnc_initWind.sqf | 19 +++-- .../functions/fnc_serverController.sqf | 8 +- .../functions/fnc_updateAceWeather.sqf | 83 ++++++++++--------- .../weather/functions/fnc_updateHumidity.sqf | 19 +++-- addons/weather/functions/fnc_updateRain.sqf | 17 ++-- .../functions/fnc_updateTemperature.sqf | 13 +-- addons/weather/functions/fnc_updateWind.sqf | 10 ++- addons/weather/script_component.hpp | 5 +- 28 files changed, 254 insertions(+), 184 deletions(-) diff --git a/addons/weather/CfgVehicles.hpp b/addons/weather/CfgVehicles.hpp index f37a62449a..f98a1e50f5 100644 --- a/addons/weather/CfgVehicles.hpp +++ b/addons/weather/CfgVehicles.hpp @@ -53,4 +53,4 @@ class CfgVehicles { description = CSTRING(Module_Description); }; }; -}; \ No newline at end of file +}; diff --git a/addons/weather/CfgWorlds.hpp b/addons/weather/CfgWorlds.hpp index 1391468fd9..dd0a616272 100644 --- a/addons/weather/CfgWorlds.hpp +++ b/addons/weather/CfgWorlds.hpp @@ -48,4 +48,4 @@ class CfgWorlds { {0.08, 0.38, 0.06, 0.04, 0.19, 0.03, 0.02, 0.02}, // November {0.06, 0.37, 0.05, 0.03, 0.18, 0.04, 0.02, 0.02}};// December }; -}; \ No newline at end of file +}; diff --git a/addons/weather/RscTitles.hpp b/addons/weather/RscTitles.hpp index aedebdabfc..d89c8d0671 100644 --- a/addons/weather/RscTitles.hpp +++ b/addons/weather/RscTitles.hpp @@ -1,17 +1,13 @@ -class RscTitles -{ - class RscWindIntuitive - { +class RscTitles { + class RscWindIntuitive { idd=-1; onLoad="with uiNameSpace do { RscWindIntuitive = _this select 0 };"; movingEnable=0; duration=60; fadeIn="false"; fadeOut="false"; - class controls - { - class RscWindIntuitive - { + class controls { + class RscWindIntuitive { idc=132948; type=0; style=48; @@ -28,4 +24,4 @@ class RscTitles }; }; }; -}; \ No newline at end of file +}; diff --git a/addons/weather/XEH_postInit.sqf b/addons/weather/XEH_postInit.sqf index c6f779358f..f5ef929ff2 100644 --- a/addons/weather/XEH_postInit.sqf +++ b/addons/weather/XEH_postInit.sqf @@ -40,12 +40,40 @@ GVAR(ACE_rain) = rain; simulWeatherSync; -[FUNC(updateTemperature), 20, []] call CBA_fnc_addPerFrameHandler; -[FUNC(updateHumidity), 20, []] call CBA_fnc_addPerFrameHandler; -[FUNC(updateWind), 1, []] call CBA_fnc_addPerFrameHandler; -[FUNC(updateRain), 2, []] call CBA_fnc_addPerFrameHandler; -[{ + + + +["SettingsInitialized",{ + TRACE_1("SettingsInitialized",GVAR(syncRain)); + + //Create a 1 sec delay PFEH to update rain every frame: if (GVAR(syncRain)) then { - 0 setRain GVAR(ACE_rain); + [{ + 0 setRain GVAR(ACE_rain); + }, 0, []] call CBA_fnc_addPerFrameHandler; }; -}, 0, []] call CBA_fnc_addPerFrameHandler; \ No newline at end of file + + //Create a 1 sec delay PFEH to update wind/rain/temp/humidity + + //If we don't sync rain, set next time to infinity + GVAR(nextUpdateRain) = if (GVAR(syncRain)) then {0} else {1e99}; + GVAR(nextUpdateTempAndHumidity) = 0; + [{ + BEGIN_COUNTER(weatherPFEH); + + [] call FUNC(updateWind); //Every 1 second + + if (ACE_time > GVAR(nextUpdateRain)) then { + [] call FUNC(updateRain); //Every 2 seconds + GVAR(nextUpdateRain) = 2 + ACE_time; + }; + if (ACE_time > GVAR(nextUpdateTempAndHumidity)) then { + [] call FUNC(updateTemperature); //Every 20 seconds + [] call FUNC(updateHumidity); //Every 20 seconds + GVAR(nextUpdateTempAndHumidity) = 20 + ACE_time; + }; + + END_COUNTER(weatherPFEH); + }, 1, []] call CBA_fnc_addPerFrameHandler; + +}] call EFUNC(common,addEventHandler); diff --git a/addons/weather/XEH_postServerInit.sqf b/addons/weather/XEH_postServerInit.sqf index aa733afa5d..f7b830b11d 100644 --- a/addons/weather/XEH_postServerInit.sqf +++ b/addons/weather/XEH_postServerInit.sqf @@ -9,4 +9,10 @@ GVAR(rain_current_range) = -1+(random 2); // Wind call FUNC(initWind); -[FUNC(serverController), GVAR(serverUpdateInterval)] call CBA_fnc_addPerFrameHandler; +["SettingsInitialized", { + TRACE_2("SettingsInitialized",GVAR(enableServerController),GVAR(serverUpdateInterval)); + + if (GVAR(enableServerController)) then { + [FUNC(serverController), GVAR(serverUpdateInterval)] call CBA_fnc_addPerFrameHandler; + }; +}] call EFUNC(common,addEventHandler); diff --git a/addons/weather/functions/fnc_calculateAirDensity.sqf b/addons/weather/functions/fnc_calculateAirDensity.sqf index f3de65f99d..bda8410ddd 100644 --- a/addons/weather/functions/fnc_calculateAirDensity.sqf +++ b/addons/weather/functions/fnc_calculateAirDensity.sqf @@ -1,18 +1,19 @@ /* * Author: Ruthberg - * * Calculates the air density * * Arguments: - * 0: temperature - degrees celcius + * 0: temperature - degrees celsius * 1: pressure - hPa * 2: relativeHumidity - value between 0.0 and 1.0 * * Return Value: * density of air - kg * m^(-3) * - * Return value: - * None + * Example: + * [0, 1020, 0.5] call ace_weather_fnc_calculateAirDensity + * + * Public: No */ #include "script_component.hpp" @@ -21,11 +22,10 @@ params ["_temperature", "_pressure", "_relativeHumidity"]; _pressure = _pressure * 100; // hPa to Pa if (_relativeHumidity > 0) then { - private ["_pSat", "_vaporPressure", "_partialPressure"]; // Saturation vapor pressure calculated according to: http://wahiduddin.net/calc/density_algorithms.htm - _pSat = 6.1078 * 10 ^ ((7.5 * _temperature) / (_temperature + 237.3)); - _vaporPressure = _relativeHumidity * _pSat; - _partialPressure = _pressure - _vaporPressure; + private _pSat = 6.1078 * 10 ^ ((7.5 * _temperature) / (_temperature + 237.3)); + private _vaporPressure = _relativeHumidity * _pSat; + private _partialPressure = _pressure - _vaporPressure; (_partialPressure * DRY_AIR_MOLAR_MASS + _vaporPressure * WATER_VAPOR_MOLAR_MASS) / (UNIVERSAL_GAS_CONSTANT * KELVIN(_temperature)) } else { diff --git a/addons/weather/functions/fnc_calculateBarometricPressure.sqf b/addons/weather/functions/fnc_calculateBarometricPressure.sqf index 134a741127..29b8fa7877 100644 --- a/addons/weather/functions/fnc_calculateBarometricPressure.sqf +++ b/addons/weather/functions/fnc_calculateBarometricPressure.sqf @@ -1,6 +1,5 @@ /* * Author: Ruthberg - * * Calculates the barometric pressure based on altitude and weather * * Arguments: @@ -9,8 +8,10 @@ * Return Value: * barometric pressure - hPA * - * Return value: - * None + * Example: + * 0 call ace_weather_fnc_calculateBarometricPressure + * + * Public: No */ #include "script_component.hpp" diff --git a/addons/weather/functions/fnc_calculateDensityAltitude.sqf b/addons/weather/functions/fnc_calculateDensityAltitude.sqf index 97889e2499..8dea9849b1 100644 --- a/addons/weather/functions/fnc_calculateDensityAltitude.sqf +++ b/addons/weather/functions/fnc_calculateDensityAltitude.sqf @@ -1,6 +1,5 @@ /* * Author: Ruthberg - * * Calculates density altitude for a given air density * * Arguments: @@ -9,8 +8,10 @@ * Return Value: * density altitude - m * - * Return value: - * None + * Example: + * 1.225 call ace_weather_fnc_calculateDensityAltitude + * + * Public: No */ #include "script_component.hpp" diff --git a/addons/weather/functions/fnc_calculateDewPoint.sqf b/addons/weather/functions/fnc_calculateDewPoint.sqf index cbfc606054..81db9565dc 100644 --- a/addons/weather/functions/fnc_calculateDewPoint.sqf +++ b/addons/weather/functions/fnc_calculateDewPoint.sqf @@ -1,17 +1,18 @@ /* * Author: Ruthberg - * * Calculates dew point based on temperature and relative humidity * * Arguments: - * 0: temperature - degrees celcius - * 2: relativeHumidity - value between 0.0 and 1.0 + * 0: temperature - degrees celsius + * 1: relativeHumidity - value between 0.0 and 1.0 * * Return Value: * dew point * - * Return value: - * None + * Example: + * [32, 0.4] call ace_weather_fnc_calculateDewPoint + * + * Public: No */ #include "script_component.hpp" @@ -24,7 +25,6 @@ if (_rh == 0) exitWith { CELSIUS(0) }; // Source: https://en.wikipedia.org/wiki/Dew_point -private ["_gamma"]; -_gamma = ln(_rh) + (__b * _t) / (__c + _t); +private _gamma = ln(_rh) + (__b * _t) / (__c + _t); (__c * _gamma) / (__b - _gamma) diff --git a/addons/weather/functions/fnc_calculateHeatIndex.sqf b/addons/weather/functions/fnc_calculateHeatIndex.sqf index 057c13d7ad..a4626128de 100644 --- a/addons/weather/functions/fnc_calculateHeatIndex.sqf +++ b/addons/weather/functions/fnc_calculateHeatIndex.sqf @@ -1,17 +1,18 @@ /* * Author: Ruthberg - * * Calculates heat index based on temperature and relative humidity * * Arguments: - * 0: temperature - degrees celcius + * 0: temperature - degrees celsius * 1: relativeHumidity - value between 0.0 and 1.0 * * Return Value: * heat index * - * Return value: - * None + * Example: + * [36, 0.75] call ace_weather_fnc_calculateHeatIndex + * + * Public: No */ #include "script_component.hpp" diff --git a/addons/weather/functions/fnc_calculateRoughnessLength.sqf b/addons/weather/functions/fnc_calculateRoughnessLength.sqf index 4fd0d18fb3..423f3fc3d6 100644 --- a/addons/weather/functions/fnc_calculateRoughnessLength.sqf +++ b/addons/weather/functions/fnc_calculateRoughnessLength.sqf @@ -1,6 +1,5 @@ /* * Author: Ruthberg - * * Calculates the terrain roughness length at a given world position * * Arguments: @@ -9,19 +8,20 @@ * Return Value: * roughness length * + * Example: + * (getPosASL player) call ace_weather_fnc_calculateRoughnessLength + * * Public: No */ #include "script_component.hpp" -private ["_roughness_lengths", "_windSource", "_nearBuildings", "_isWater"]; - // Source: http://es.ucsc.edu/~jnoble/wind/extrap/index.html -_roughness_lengths = [0.0002, 0.0005, 0.0024, 0.03, 0.055, 0.1, 0.2, 0.4, 0.8, 1.6]; +#define ROUGHNESS_LENGTHS [0.0002, 0.0005, 0.0024, 0.03, 0.055, 0.1, 0.2, 0.4, 0.8, 1.6] -_windSource = _this vectorDiff ((vectorNormalized ACE_wind) vectorMultiply 25); +private _windSource = _this vectorDiff ((vectorNormalized ACE_wind) vectorMultiply 25); -_nearBuildings = count (_windSource nearObjects ["Building", 50]); -_isWater = surfaceIsWater _windSource; +private _nearBuildings = count (_windSource nearObjects ["Building", 50]); +private _isWater = surfaceIsWater _windSource; if (_nearBuildings == 0 && _isWater) exitWith { 0.0005 @@ -31,4 +31,4 @@ if (_nearBuildings >= 10) exitWith { 1.6 }; -_roughness_lengths select (2 + (_nearBuildings min 6)) +ROUGHNESS_LENGTHS select (2 + (_nearBuildings min 6)) diff --git a/addons/weather/functions/fnc_calculateSpeedOfSound.sqf b/addons/weather/functions/fnc_calculateSpeedOfSound.sqf index 322ba75ac5..f645ba2368 100644 --- a/addons/weather/functions/fnc_calculateSpeedOfSound.sqf +++ b/addons/weather/functions/fnc_calculateSpeedOfSound.sqf @@ -1,16 +1,17 @@ /* * Author: Ruthberg - * * Calculates the speed of sound for a given temperature * * Arguments: - * temperature - degrees celcius + * temperature - degrees celsius * * Return Value: * speed of sound - m/s * - * Return value: - * None + * Example: + * 0 call ace_weather_fnc_calculateSpeedOfSound + * + * Public: No */ #include "script_component.hpp" diff --git a/addons/weather/functions/fnc_calculateTemperatureAtHeight.sqf b/addons/weather/functions/fnc_calculateTemperatureAtHeight.sqf index 5e02795d59..e33b8213eb 100644 --- a/addons/weather/functions/fnc_calculateTemperatureAtHeight.sqf +++ b/addons/weather/functions/fnc_calculateTemperatureAtHeight.sqf @@ -1,6 +1,5 @@ /* * Author: Ruthberg - * * Calculates the temperature based on altitude and weather * * Arguments: @@ -9,8 +8,10 @@ * Return Value: * temperature - degrees celsius * - * Return value: - * None + * Example: + * 500 call ace_weather_fnc_calculateTemperatureAtHeight + * + * Public: No */ #include "script_component.hpp" diff --git a/addons/weather/functions/fnc_calculateWetBulb.sqf b/addons/weather/functions/fnc_calculateWetBulb.sqf index 94e96cd11b..a8a58b0dc3 100644 --- a/addons/weather/functions/fnc_calculateWetBulb.sqf +++ b/addons/weather/functions/fnc_calculateWetBulb.sqf @@ -1,36 +1,35 @@ /* * Author: Ruthberg - * * Calculates wet bulb based on temperature and relative humidity * * Arguments: - * 0: temperature - degrees celcius + * 0: temperature - degrees celsius * 1: pressure - hPa * 2: relativeHumidity - value between 0.0 and 1.0 * * Return Value: * wet bulb * - * Return value: - * None + * Example: + * [0, 1020, 0.5] call ace_weather_fnc_calculateWetBulb + * + * Public: No */ #include "script_component.hpp" -private ["_es", "_e", "_eDiff", "_eGuessPrev", "_cTempDelta", "_twGuess", "_eguess"]; - params ["_temperature", "_pressure", "_relativeHumidity"]; // Source: http://cosmoquest.org/forum/showthread.php?155366-Calculating-Wet-Bulb-Temperature-from-RH-amp-Dry-Bulb -_es = 6.112 * exp((17.67 * _temperature) / (_temperature + 243.5)); -_e = _es * _relativeHumidity; -_eDiff = _es - _e; -_eGuessPrev = _es; -_cTempDelta = 3.3145; -_twGuess = _temperature; +private _es = 6.112 * exp((17.67 * _temperature) / (_temperature + 243.5)); +private _e = _es * _relativeHumidity; +private _eDiff = _es - _e; +private _eGuessPrev = _es; +private _cTempDelta = 3.3145; +private _twGuess = _temperature; for "_j" from 1 to 50 do { _twGuess = _twGuess - _cTempDelta; - _eguess = 6.112 * exp((17.67 * _twGuess) / (_twGuess + 243.5)); + private _eguess = 6.112 * exp((17.67 * _twGuess) / (_twGuess + 243.5)); _eguess = _eguess - (_pressure * (_temperature - _twGuess) * 0.00066 * (1 + (0.00115 * _twGuess))); _eDiff = _eguess - _e; if (abs(_eDiff) <= 0.001) exitWith {}; diff --git a/addons/weather/functions/fnc_calculateWindChill.sqf b/addons/weather/functions/fnc_calculateWindChill.sqf index ee3a20283b..0e17d53377 100644 --- a/addons/weather/functions/fnc_calculateWindChill.sqf +++ b/addons/weather/functions/fnc_calculateWindChill.sqf @@ -1,15 +1,17 @@ /* * Author: Ruthberg - * * Calculates wind chill based on temperature and wind speed * * Arguments: - * 0: temperature - degrees celcius + * 0: temperature - degrees celsius * 1: wind speed - m/s * * Return Value: * wind chill * + * Example: + * [0, 10] call ace_weather_fnc_calculateWindChill + * * Public: No */ #include "script_component.hpp" diff --git a/addons/weather/functions/fnc_calculateWindSpeed.sqf b/addons/weather/functions/fnc_calculateWindSpeed.sqf index 87c6c49d42..206bc1d298 100644 --- a/addons/weather/functions/fnc_calculateWindSpeed.sqf +++ b/addons/weather/functions/fnc_calculateWindSpeed.sqf @@ -1,43 +1,42 @@ /* * Author: Ruthberg - * * Calculates the true wind speed at a given world position * * Arguments: * 0: world position - posASL - * 1: Account for wind gradient + * 1: Account for wind gradient (used in advanced ballistics) * 2: Account for terrain * 3: Account for obstacles * * Return Value: * wind speed - m/s * + * Example: + * [eyePos ACE_player, true, true, true] call ace_weather_fnc_calculateWindSpeed; + * * Public: No */ #include "script_component.hpp" -private ["_fnc_polar2vect", "_windSpeed", "_windDir", "_windDirAdjusted", "_height", "_newWindSpeed", "_windSource", "_roughnessLength"]; - params ["_position", "_windGradientEnabled", "_terrainEffectEnabled", "_obstacleEffectEnabled"]; -_fnc_polar2vect = { - private ["_mag2D"]; - params ["_x", "_y", "_z"]; - _mag2D = _x * cos(_z); - [_mag2D * sin(_y), _mag2D * cos(_y), _x * sin(_z)]; +private _fnc_polar2vect = { + params ["_mag","_dir","_elev"]; + private _mag2D = _mag * cos(_elev); + [_mag2D * sin(_dir), _mag2D * cos(_dir), _mag * sin(_elev)]; }; -_windSpeed = vectorMagnitude ACE_wind; -_windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); -_windDirAdjusted = _windDir + 180; +private _windSpeed = vectorMagnitude ACE_wind; +private _windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); +private _windDirAdjusted = _windDir + 180; // Wind gradient if (_windGradientEnabled) then { if (_windSpeed > 0.05) then { - _height = (ASLToATL _position) select 2; + private _height = (ASLToATL _position) select 2; _height = 0 max _height min 20; if (_height < 20) then { - _roughnessLength = _position call FUNC(calculateRoughnessLength); + private _roughnessLength = _position call FUNC(calculateRoughnessLength); _windSpeed = _windSpeed * abs(ln(_height / _roughnessLength) / ln(20 / _roughnessLength)); }; }; @@ -46,9 +45,9 @@ if (_windGradientEnabled) then { // Terrain effect on wind if (_terrainEffectEnabled) then { if (_windSpeed > 0.05) then { - _newWindSpeed = 0; + private _newWindSpeed = 0; { - _windSource = [100, _windDirAdjusted, _x] call _fnc_polar2vect; + private _windSource = [100, _windDirAdjusted, _x] call _fnc_polar2vect; if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith { _newWindSpeed = cos(_x * 9) * _windSpeed; }; @@ -60,6 +59,7 @@ if (_terrainEffectEnabled) then { if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith { _newWindSpeed = cos(_x * 9) * _windSpeed; }; + nil } count [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; _windSpeed = _newWindSpeed; }; @@ -68,9 +68,9 @@ if (_terrainEffectEnabled) then { // Obstacle effect on wind if (_obstacleEffectEnabled) then { if (_windSpeed > 0.05) then { - _newWindSpeed = 0; + private _newWindSpeed = 0; { - _windSource = [20, _windDirAdjusted, _x] call _fnc_polar2vect; + private _windSource = [20, _windDirAdjusted, _x] call _fnc_polar2vect; if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith { _newWindSpeed = cos(_x * 2) * _windSpeed; }; @@ -82,6 +82,7 @@ if (_obstacleEffectEnabled) then { if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith { _newWindSpeed = cos(_x * 2) * _windSpeed; }; + nil } count [0, 5, 10, 15, 20, 25, 30, 35, 40, 45]; _windSpeed = _newWindSpeed; }; diff --git a/addons/weather/functions/fnc_displayWindInfo.sqf b/addons/weather/functions/fnc_displayWindInfo.sqf index 98d9026c1c..3e084c7aa5 100644 --- a/addons/weather/functions/fnc_displayWindInfo.sqf +++ b/addons/weather/functions/fnc_displayWindInfo.sqf @@ -1,6 +1,5 @@ /* * Author: Ruthberg - * * Displays a wind info (colored arrow) in the top left corner of the screen * * Argument: @@ -8,6 +7,11 @@ * * Return value: * None + * + * Example: + * [] call ace_weather_fnc_displayWindInfo + * + * Public: No */ #include "script_component.hpp" @@ -28,17 +32,15 @@ EGVAR(advanced_ballistics,Protractor) = false; GVAR(WindInfo) = true; [{ - private ["_windSpeed", "_windDir", "_playerDir", "_windIndex", "_windColor"]; - - if !(GVAR(WindInfo) && !(underwater ACE_player) && vehicle ACE_player == ACE_player) exitWith { + if ((!GVAR(WindInfo)) || {underwater ACE_player} || {vehicle ACE_player != ACE_player}) exitWith { GVAR(WindInfo) = false; 0 cutText ["", "PLAIN"]; [_this select 1] call CBA_fnc_removePerFrameHandler; }; - _windIndex = 12; - _windColor = [1, 1, 1, 1]; - _windSpeed = if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { + private _windIndex = 12; + private _windColor = [1, 1, 1, 1]; + private _windSpeed = if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { // With wind gradient [eyePos ACE_player, true, true, true] call FUNC(calculateWindSpeed); } else { @@ -47,8 +49,8 @@ GVAR(WindInfo) = true; }; if (_windSpeed > 0.2) then { - _playerDir = (ACE_player call CBA_fnc_headDir) select 0; - _windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); + private _playerDir = (ACE_player call CBA_fnc_headDir) select 0; + private _windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); _windIndex = round(((_playerDir - _windDir + 360) % 360) / 30); _windIndex = _windIndex % 12; }; diff --git a/addons/weather/functions/fnc_getMapData.sqf b/addons/weather/functions/fnc_getMapData.sqf index 2e39f80764..b344ad2bdf 100644 --- a/addons/weather/functions/fnc_getMapData.sqf +++ b/addons/weather/functions/fnc_getMapData.sqf @@ -1,6 +1,5 @@ /* * Author: Ruthberg, esteldunedain - * * Get the weather data for the current map * * Argument: @@ -8,6 +7,11 @@ * * Return value: * None + * + * Example: + * [] call ace_weather_fnc_getMapData + * + * Public: No */ #include "script_component.hpp" @@ -207,4 +211,4 @@ GVAR(TempNight) = [-4, -3, 0, 4, 9, 12, 14, 14, 10, 6, 2, -2]; GVAR(Humidity) = [82, 80, 78, 70, 71, 72, 70, 73, 78, 80, 83, 82]; GVAR(currentTemperature) = 20; -GVAR(currentHumidity) = 0.5; \ No newline at end of file +GVAR(currentHumidity) = 0.5; diff --git a/addons/weather/functions/fnc_getWind.sqf b/addons/weather/functions/fnc_getWind.sqf index 7e133896a6..d087dc2498 100644 --- a/addons/weather/functions/fnc_getWind.sqf +++ b/addons/weather/functions/fnc_getWind.sqf @@ -1,6 +1,5 @@ /* * Author: ACE2 Team, Ruthberg - * * Calculate current wind locally from the data broadcasted by the server * * Argument: @@ -8,17 +7,20 @@ * * Return value: * Wind + * + * Example: + * [] call ace_weather_fnc_getWind + * + * Public: No */ #include "script_component.hpp" -private ["_periodPercent", "_periodPosition"]; - if (isNil "ACE_WIND_PARAMS") exitWith { [0, 0, 0] }; ACE_WIND_PARAMS params ["_dir", "_dirChange", "_spd", "_spdChange", "_period"]; -_periodPosition = (ACE_time - GVAR(wind_period_start_time)) min _period; -_periodPercent = _periodPosition / _period; +private _periodPosition = (ACE_time - GVAR(wind_period_start_time)) min _period; +private _periodPercent = _periodPosition / _period; _spd = _spd + _spdChange * _periodPercent; _dir = _dir + _dirChange * _periodPercent; diff --git a/addons/weather/functions/fnc_initModuleSettings.sqf b/addons/weather/functions/fnc_initModuleSettings.sqf index 034612ab58..f1e9c1d6fc 100644 --- a/addons/weather/functions/fnc_initModuleSettings.sqf +++ b/addons/weather/functions/fnc_initModuleSettings.sqf @@ -10,6 +10,9 @@ * Return Value: * None * + * Example: + * [module, [], true] call ace_weather_fnc_initModuleSettings + * * Public: No */ diff --git a/addons/weather/functions/fnc_initWind.sqf b/addons/weather/functions/fnc_initWind.sqf index 10b22efa2a..4c88f59f95 100644 --- a/addons/weather/functions/fnc_initWind.sqf +++ b/addons/weather/functions/fnc_initWind.sqf @@ -1,6 +1,5 @@ /* * Author: Ruthberg - * * Inits the wind variables on mission start * * Argument: @@ -8,28 +7,32 @@ * * Return value: * None + * + * Example: + * [] call ace_weather_fnc_initWind + * + * Public: No */ #include "script_component.hpp" -private ["_sum", "_rand", "_csum", "_index", "_month", "_windDirectionProbabilities"]; -_month = date select 1; -_windDirectionProbabilities = GVAR(WindDirectionProbabilities) select (_month - 1); +private _month = date select 1; +private _windDirectionProbabilities = GVAR(WindDirectionProbabilities) select (_month - 1); ACE_wind = [0, 0, 0]; GVAR(wind_direction_reference) = random 360; -_sum = 0; +private _sum = 0; for "_i" from 0 to 7 do { _sum = _sum + (_windDirectionProbabilities select _i); }; -_rand = random _sum; -_csum = [0, 0, 0, 0, 0, 0, 0, 0]; +private _rand = random _sum; +private _csum = [0, 0, 0, 0, 0, 0, 0, 0]; for "_i" from 0 to 7 do { for "_j" from 0 to _i do { _csum set [_i, (_csum select _i) + (_windDirectionProbabilities select _j)]; }; }; -_index = 0; +private _index = 0; for "_i" from 0 to 7 do { if (_rand > (_csum select _i)) then { _index = _index + 1; diff --git a/addons/weather/functions/fnc_serverController.sqf b/addons/weather/functions/fnc_serverController.sqf index 2cbdeb581e..4ac859751b 100644 --- a/addons/weather/functions/fnc_serverController.sqf +++ b/addons/weather/functions/fnc_serverController.sqf @@ -1,6 +1,5 @@ /* * Author: Ruthberg - * * Gather weather parameters and broadcast them to the clients * * Argument: @@ -8,11 +7,14 @@ * * Return value: * None + * + * Example: + * [] call ace_weather_fnc_serverController + * + * Public: No */ #include "script_component.hpp" -if (!GVAR(enableServerController)) exitWith {}; - if (GVAR(useACEWeather)) then { // Use location based real world weather data [] call FUNC(updateAceWeather); diff --git a/addons/weather/functions/fnc_updateAceWeather.sqf b/addons/weather/functions/fnc_updateAceWeather.sqf index 029e1eb89b..2eb264d91b 100644 --- a/addons/weather/functions/fnc_updateAceWeather.sqf +++ b/addons/weather/functions/fnc_updateAceWeather.sqf @@ -1,6 +1,5 @@ /* * Author: ACE2 Team, esteldunedain, ruthberg - * * Updates the wind and rain evolution on the server. Broadcasts the current and next values to the clients * * Argument: @@ -8,40 +7,44 @@ * * Return value: * None + * + * Example: + * [] call ace_weather_fnc_updateAceWeather + * + * Public: No */ #include "script_component.hpp" -private ["_overcastMultiplier", "_lastRain", "_rainOverCast", "_transitionTime", "_windDirectionVariance", "_windSpeed", "_windSpeedChange", "_windMaxDiff", "_windMinDiff", "_windDirection", "_windDirectionChange", "_ratioMin", "_ratioMax"]; - -_overcastMultiplier = 1 max (2* overcast) min 2; // 0 (@ overcast 0), 2 (@ overcast 1) +private _overcastMultiplier = 1 max (2* overcast) min 2; // 0 (@ overcast 0), 2 (@ overcast 1) // Rain simulation -if (GVAR(syncRain) && GVAR(rain_period_count) > GVAR(rain_next_period)) then { +if (GVAR(syncRain) && {GVAR(rain_period_count) > GVAR(rain_next_period)}) then { GVAR(rain_next_period) = ceil((1 + (random 10)) / _overcastMultiplier); GVAR(rain_period_count) = 0; - - _lastRain = GVAR(current_rain); - + + private _lastRain = GVAR(current_rain); + private _rainOverCast = 0; + if (overcast >= 0.7) then { _rainOverCast = (overcast - 0.7) / 0.3; if (GVAR(current_rain) == 0) then { // Initialize rain with a random strength depending on the current overcast value GVAR(current_rain) = -0.25 + (random 0.75) + (random 0.5) * _rainOverCast; }; - + GVAR(current_rain) = GVAR(current_rain) + GVAR(current_rain) * ((_rainOverCast * _overcastMultiplier) / 8) * GVAR(rain_current_range); GVAR(current_rain) = 0 max GVAR(current_rain) min 1; - + GVAR(rain_current_range) = -1 + (random 2); } else { _rainOverCast = 1; - + GVAR(current_rain) = 0; }; - - _transitionTime = 1 + (_rainOverCast * 5) + (random (_rainOverCast * 20)); - + + private _transitionTime = 1 + (_rainOverCast * 5) + (random (_rainOverCast * 20)); + ACE_RAIN_PARAMS = [_lastRain, GVAR(current_rain), _transitionTime]; TRACE_4("",_lastRain,_rainOverCast,_transitionTime,overcast); @@ -50,47 +53,47 @@ if (GVAR(syncRain) && GVAR(rain_period_count) > GVAR(rain_next_period)) then { }; // Wind simulation -if (GVAR(syncWind) && GVAR(wind_period_count) > GVAR(wind_next_period)) then { - +if (GVAR(syncWind) && {GVAR(wind_period_count) > GVAR(wind_next_period)}) then { + GVAR(wind_next_period) = ceil((2 + (random 5)) / _overcastMultiplier); GVAR(wind_period_count) = 0; - - _windDirectionVariance = (90 - (random 180)) * (overcast ^ 2); - _windDirection = (360 + GVAR(wind_direction_reference) + _windDirectionVariance) % 360; - _windDirectionChange = _windDirection - GVAR(current_wind_direction); + + private _windDirectionVariance = (90 - (random 180)) * (overcast ^ 2); + private _windDirection = (360 + GVAR(wind_direction_reference) + _windDirectionVariance) % 360; + private _windDirectionChange = _windDirection - GVAR(current_wind_direction); if (_windDirectionChange > 180) then { _windDirectionChange = _windDirectionChange - 360; }; if (_windDirectionChange < -180) then { _windDirectionChange = 360 + _windDirectionChange; }; - - _windMaxDiff = GVAR(mean_wind_speed) - GVAR(max_wind_speed); - _windMinDiff = GVAR(min_wind_speed) - GVAR(mean_wind_speed); - - _ratioMax = (random 1) ^ 2; - _ratioMin = (random 1) ^ 2; - - _windSpeed = GVAR(current_wind_speed); - _windSpeedChange = 0; + + private _windMaxDiff = GVAR(mean_wind_speed) - GVAR(max_wind_speed); + private _windMinDiff = GVAR(min_wind_speed) - GVAR(mean_wind_speed); + + private _ratioMax = (random 1) ^ 2; + private _ratioMin = (random 1) ^ 2; + + private _windSpeed = GVAR(current_wind_speed); + private _windSpeedChange = 0; if ((random 1) < (0.3 max overcast)) then { _windSpeed = GVAR(mean_wind_speed) + _windMaxDiff * _ratioMax + _windMinDiff * _ratioMin; _windSpeedChange = _windSpeed - GVAR(current_wind_speed); }; - - _transitionTime = GVAR(wind_next_period) * GVAR(serverUpdateInterval); - + + private _transitionTime = GVAR(wind_next_period) * GVAR(serverUpdateInterval); + TRACE_5("dirCur/dirNew/spdCur/spdNew/period",GVAR(current_wind_direction),_windDirection,GVAR(current_wind_speed),_windSpeed,_transitionTime); - + ACE_WIND_PARAMS = [GVAR(current_wind_direction), - _windDirectionChange, - GVAR(current_wind_speed), - _windSpeedChange, - _transitionTime]; - + _windDirectionChange, + GVAR(current_wind_speed), + _windSpeedChange, + _transitionTime]; + GVAR(current_wind_direction) = _windDirection; GVAR(current_wind_speed) = _windSpeed; - + GVAR(wind_period_start_time) = ACE_time; publicVariable "ACE_WIND_PARAMS"; }; @@ -102,4 +105,4 @@ if (GVAR(syncMisc)) then { }; GVAR(rain_period_count) = GVAR(rain_period_count) + 1; -GVAR(wind_period_count) = GVAR(wind_period_count) + 1; \ No newline at end of file +GVAR(wind_period_count) = GVAR(wind_period_count) + 1; diff --git a/addons/weather/functions/fnc_updateHumidity.sqf b/addons/weather/functions/fnc_updateHumidity.sqf index df6e64df5d..3ea28d6a44 100644 --- a/addons/weather/functions/fnc_updateHumidity.sqf +++ b/addons/weather/functions/fnc_updateHumidity.sqf @@ -1,27 +1,30 @@ /* * Author: ACE2 Team - * - * Updates GVAR(currentHumidity) based on + * Updates GVAR(currentHumidity) * * Argument: * Nothing * * Return value: * Nothing + * + * Example: + * [] call ace_weather_fnc_updateHumidity + * + * Public: No */ #include "script_component.hpp" -private ["_month", "_avgTemperature", "_pS1", "_pS2"]; -_month = date select 1; +private _month = date select 1; GVAR(currentHumidity) = (GVAR(Humidity) select (_month - 1)) / 100; -if (rain > 0 && overcast > 0.7) then { +if ((rain > 0) && {overcast > 0.7}) then { GVAR(currentHumidity) = 1; } else { - _avgTemperature = ((GVAR(TempDay) select (_month - 1)) + (GVAR(TempNight) select (_month - 1))) / 2; - _pS1 = 6.112 * exp((17.62 * _avgTemperature) / (243.12 + _avgTemperature)); - _PS2 = 6.112 * exp((17.62 * GVAR(currentTemperature)) / (243.12 + GVAR(currentTemperature))); + private _avgTemperature = ((GVAR(TempDay) select (_month - 1)) + (GVAR(TempNight) select (_month - 1))) / 2; + private _pS1 = 6.112 * exp((17.62 * _avgTemperature) / (243.12 + _avgTemperature)); + private _PS2 = 6.112 * exp((17.62 * GVAR(currentTemperature)) / (243.12 + GVAR(currentTemperature))); GVAR(currentHumidity) = GVAR(currentHumidity) * _PS1 / _PS2; GVAR(currentHumidity) = GVAR(currentHumidity) + GVAR(humidityShift); diff --git a/addons/weather/functions/fnc_updateRain.sqf b/addons/weather/functions/fnc_updateRain.sqf index 6c4c829747..8fa18500e8 100644 --- a/addons/weather/functions/fnc_updateRain.sqf +++ b/addons/weather/functions/fnc_updateRain.sqf @@ -1,6 +1,5 @@ /* * Author: ACE2 Team, Ruthberg - * * Updates rain based on ACE_RAIN_PARAMS * * Argument: @@ -8,17 +7,21 @@ * * Return value: * Nothing + * + * Example: + * [] call ace_weather_fnc_updateRain + * + * Public: No */ #include "script_component.hpp" -if (!GVAR(syncRain)) exitWith {}; - if (!isNil "ACE_RAIN_PARAMS") then { ACE_RAIN_PARAMS params ["_oldRain", "_newRain", "_period"]; - private ["_periodPosition", "_periodPercent"]; - _periodPosition = (ACE_time - GVAR(rain_period_start_time)) min _period; - _periodPercent = (_periodPosition / _period) min 1; + private _periodPosition = (ACE_time - GVAR(rain_period_start_time)) min _period; + private _periodPercent = (_periodPosition / _period) min 1; - GVAR(ACE_Rain) = (_oldRain + (_newRain - _oldRain) * _periodPercent); + GVAR(ACE_Rain) = linearConversion [GVAR(rain_period_start_time), (GVAR(rain_period_start_time) + _period), ACE_time, _oldRain, _newRain]; + + TRACE_3("Update Rain",rain,ACE_RAIN_PARAMS,GVAR(ACE_Rain)); }; diff --git a/addons/weather/functions/fnc_updateTemperature.sqf b/addons/weather/functions/fnc_updateTemperature.sqf index 82f126e33f..9ff11859f4 100644 --- a/addons/weather/functions/fnc_updateTemperature.sqf +++ b/addons/weather/functions/fnc_updateTemperature.sqf @@ -1,6 +1,5 @@ /* * Author: ACE2 Team - * * Updates GVAR(currentTemperature) based on the map data * * Argument: @@ -8,14 +7,18 @@ * * Return value: * Nothing + * + * Example: + * [] call ace_weather_fnc_updateTemperature + * + * Public: No */ #include "script_component.hpp" -private ["_time", "_month", "_timeRatio"]; -_time = daytime; -_month = date select 1; +private _time = daytime; +private _month = date select 1; -_timeRatio = abs(_time - 12) / 12; +private _timeRatio = abs(_time - 12) / 12; GVAR(currentTemperature) = (GVAR(TempDay) select (_month - 1)) * (1 - _timeRatio) + (GVAR(TempNight) select (_month - 1)) * _timeRatio; GVAR(currentTemperature) = GVAR(currentTemperature) + GVAR(temperatureShift) - GVAR(badWeatherShift) * overcast; diff --git a/addons/weather/functions/fnc_updateWind.sqf b/addons/weather/functions/fnc_updateWind.sqf index b362458fdb..75724e3674 100644 --- a/addons/weather/functions/fnc_updateWind.sqf +++ b/addons/weather/functions/fnc_updateWind.sqf @@ -1,6 +1,5 @@ /* * Author: ACE2 Team, Ruthberg - * * Updates wind, gusts and waves based on ACE_wind * * Argument: @@ -8,19 +7,22 @@ * * Return value: * Nothing + * + * Example: + * [] call ace_weather_fnc_updateWind + * + * Public: No */ #include "script_component.hpp" if (!GVAR(syncWind)) exitWith { ACE_wind = wind }; -private ["_newWaves"]; - ACE_wind = [] call FUNC(getWind); setWind [ACE_wind select 0, ACE_wind select 1, true]; 2 setGusts 0; // Set waves: 0 when no wind, 1 when wind >= 16 m/s -_newWaves = ((vectorMagnitude ACE_wind) / 16.0) min 1.0; +private _newWaves = ((vectorMagnitude ACE_wind) / 16.0) min 1.0; if (abs(_newWaves - waves) > 0.1) then { 1 setWaves _newWaves; }; diff --git a/addons/weather/script_component.hpp b/addons/weather/script_component.hpp index 2a6aeb0393..c2df236d53 100644 --- a/addons/weather/script_component.hpp +++ b/addons/weather/script_component.hpp @@ -1,6 +1,9 @@ #define COMPONENT weather #include "\z\ace\addons\main\script_mod.hpp" -//#define DEBUG_ENABLED_WEATHER + +// #define DEBUG_MODE_FULL +// #define ENABLE_PERFORMANCE_COUNTERS + #ifdef DEBUG_ENABLED_WEATHER #define DEBUG_MODE_FULL #endif