Privates, Headers, Merge 4 PFEH into one

This commit is contained in:
PabstMirror 2016-01-05 01:39:29 -06:00
parent 776f9352fe
commit e2c08d2c26
28 changed files with 254 additions and 184 deletions

View File

@ -1,17 +1,13 @@
class RscTitles class RscTitles {
{ class RscWindIntuitive {
class RscWindIntuitive
{
idd=-1; idd=-1;
onLoad="with uiNameSpace do { RscWindIntuitive = _this select 0 };"; onLoad="with uiNameSpace do { RscWindIntuitive = _this select 0 };";
movingEnable=0; movingEnable=0;
duration=60; duration=60;
fadeIn="false"; fadeIn="false";
fadeOut="false"; fadeOut="false";
class controls class controls {
{ class RscWindIntuitive {
class RscWindIntuitive
{
idc=132948; idc=132948;
type=0; type=0;
style=48; style=48;

View File

@ -40,12 +40,40 @@ GVAR(ACE_rain) = rain;
simulWeatherSync; 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 { if (GVAR(syncRain)) then {
[{
0 setRain GVAR(ACE_rain); 0 setRain GVAR(ACE_rain);
}, 0, []] call CBA_fnc_addPerFrameHandler;
}; };
}, 0, []] call CBA_fnc_addPerFrameHandler;
//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);

View File

@ -9,4 +9,10 @@ GVAR(rain_current_range) = -1+(random 2);
// Wind // Wind
call FUNC(initWind); 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);

View File

@ -1,18 +1,19 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates the air density * Calculates the air density
* *
* Arguments: * Arguments:
* 0: temperature - degrees celcius <NUMBER> * 0: temperature - degrees celsius <NUMBER>
* 1: pressure - hPa <NUMBER> * 1: pressure - hPa <NUMBER>
* 2: relativeHumidity - value between 0.0 and 1.0 <NUMBER> * 2: relativeHumidity - value between 0.0 and 1.0 <NUMBER>
* *
* Return Value: * Return Value:
* density of air - kg * m^(-3) <NUMBER> * density of air - kg * m^(-3) <NUMBER>
* *
* Return value: * Example:
* None * [0, 1020, 0.5] call ace_weather_fnc_calculateAirDensity
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
@ -21,11 +22,10 @@ params ["_temperature", "_pressure", "_relativeHumidity"];
_pressure = _pressure * 100; // hPa to Pa _pressure = _pressure * 100; // hPa to Pa
if (_relativeHumidity > 0) then { if (_relativeHumidity > 0) then {
private ["_pSat", "_vaporPressure", "_partialPressure"];
// Saturation vapor pressure calculated according to: http://wahiduddin.net/calc/density_algorithms.htm // Saturation vapor pressure calculated according to: http://wahiduddin.net/calc/density_algorithms.htm
_pSat = 6.1078 * 10 ^ ((7.5 * _temperature) / (_temperature + 237.3)); private _pSat = 6.1078 * 10 ^ ((7.5 * _temperature) / (_temperature + 237.3));
_vaporPressure = _relativeHumidity * _pSat; private _vaporPressure = _relativeHumidity * _pSat;
_partialPressure = _pressure - _vaporPressure; private _partialPressure = _pressure - _vaporPressure;
(_partialPressure * DRY_AIR_MOLAR_MASS + _vaporPressure * WATER_VAPOR_MOLAR_MASS) / (UNIVERSAL_GAS_CONSTANT * KELVIN(_temperature)) (_partialPressure * DRY_AIR_MOLAR_MASS + _vaporPressure * WATER_VAPOR_MOLAR_MASS) / (UNIVERSAL_GAS_CONSTANT * KELVIN(_temperature))
} else { } else {

View File

@ -1,6 +1,5 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates the barometric pressure based on altitude and weather * Calculates the barometric pressure based on altitude and weather
* *
* Arguments: * Arguments:
@ -9,8 +8,10 @@
* Return Value: * Return Value:
* barometric pressure - hPA <NUMBER> * barometric pressure - hPA <NUMBER>
* *
* Return value: * Example:
* None * 0 call ace_weather_fnc_calculateBarometricPressure
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,6 +1,5 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates density altitude for a given air density * Calculates density altitude for a given air density
* *
* Arguments: * Arguments:
@ -9,8 +8,10 @@
* Return Value: * Return Value:
* density altitude - m <NUMBER> * density altitude - m <NUMBER>
* *
* Return value: * Example:
* None * 1.225 call ace_weather_fnc_calculateDensityAltitude
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,17 +1,18 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates dew point based on temperature and relative humidity * Calculates dew point based on temperature and relative humidity
* *
* Arguments: * Arguments:
* 0: temperature - degrees celcius <NUMBER> * 0: temperature - degrees celsius <NUMBER>
* 2: relativeHumidity - value between 0.0 and 1.0 <NUMBER> * 1: relativeHumidity - value between 0.0 and 1.0 <NUMBER>
* *
* Return Value: * Return Value:
* dew point <NUMBER> * dew point <NUMBER>
* *
* Return value: * Example:
* None * [32, 0.4] call ace_weather_fnc_calculateDewPoint
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
@ -24,7 +25,6 @@ if (_rh == 0) exitWith { CELSIUS(0) };
// Source: https://en.wikipedia.org/wiki/Dew_point // Source: https://en.wikipedia.org/wiki/Dew_point
private ["_gamma"]; private _gamma = ln(_rh) + (__b * _t) / (__c + _t);
_gamma = ln(_rh) + (__b * _t) / (__c + _t);
(__c * _gamma) / (__b - _gamma) (__c * _gamma) / (__b - _gamma)

View File

@ -1,17 +1,18 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates heat index based on temperature and relative humidity * Calculates heat index based on temperature and relative humidity
* *
* Arguments: * Arguments:
* 0: temperature - degrees celcius <NUMBER> * 0: temperature - degrees celsius <NUMBER>
* 1: relativeHumidity - value between 0.0 and 1.0 <NUMBER> * 1: relativeHumidity - value between 0.0 and 1.0 <NUMBER>
* *
* Return Value: * Return Value:
* heat index <NUMBER> * heat index <NUMBER>
* *
* Return value: * Example:
* None * [36, 0.75] call ace_weather_fnc_calculateHeatIndex
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,6 +1,5 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates the terrain roughness length at a given world position * Calculates the terrain roughness length at a given world position
* *
* Arguments: * Arguments:
@ -9,19 +8,20 @@
* Return Value: * Return Value:
* roughness length <NUMBER> * roughness length <NUMBER>
* *
* Example:
* (getPosASL player) call ace_weather_fnc_calculateRoughnessLength
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_roughness_lengths", "_windSource", "_nearBuildings", "_isWater"];
// Source: http://es.ucsc.edu/~jnoble/wind/extrap/index.html // 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]); private _nearBuildings = count (_windSource nearObjects ["Building", 50]);
_isWater = surfaceIsWater _windSource; private _isWater = surfaceIsWater _windSource;
if (_nearBuildings == 0 && _isWater) exitWith { if (_nearBuildings == 0 && _isWater) exitWith {
0.0005 0.0005
@ -31,4 +31,4 @@ if (_nearBuildings >= 10) exitWith {
1.6 1.6
}; };
_roughness_lengths select (2 + (_nearBuildings min 6)) ROUGHNESS_LENGTHS select (2 + (_nearBuildings min 6))

View File

@ -1,16 +1,17 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates the speed of sound for a given temperature * Calculates the speed of sound for a given temperature
* *
* Arguments: * Arguments:
* temperature - degrees celcius <NUMBER> * temperature - degrees celsius <NUMBER>
* *
* Return Value: * Return Value:
* speed of sound - m/s <NUMBER> * speed of sound - m/s <NUMBER>
* *
* Return value: * Example:
* None * 0 call ace_weather_fnc_calculateSpeedOfSound
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,6 +1,5 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates the temperature based on altitude and weather * Calculates the temperature based on altitude and weather
* *
* Arguments: * Arguments:
@ -9,8 +8,10 @@
* Return Value: * Return Value:
* temperature - degrees celsius <NUMBER> * temperature - degrees celsius <NUMBER>
* *
* Return value: * Example:
* None * 500 call ace_weather_fnc_calculateTemperatureAtHeight
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,36 +1,35 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates wet bulb based on temperature and relative humidity * Calculates wet bulb based on temperature and relative humidity
* *
* Arguments: * Arguments:
* 0: temperature - degrees celcius <NUMBER> * 0: temperature - degrees celsius <NUMBER>
* 1: pressure - hPa <NUMBER> * 1: pressure - hPa <NUMBER>
* 2: relativeHumidity - value between 0.0 and 1.0 <NUMBER> * 2: relativeHumidity - value between 0.0 and 1.0 <NUMBER>
* *
* Return Value: * Return Value:
* wet bulb <NUMBER> * wet bulb <NUMBER>
* *
* Return value: * Example:
* None * [0, 1020, 0.5] call ace_weather_fnc_calculateWetBulb
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_es", "_e", "_eDiff", "_eGuessPrev", "_cTempDelta", "_twGuess", "_eguess"];
params ["_temperature", "_pressure", "_relativeHumidity"]; params ["_temperature", "_pressure", "_relativeHumidity"];
// Source: http://cosmoquest.org/forum/showthread.php?155366-Calculating-Wet-Bulb-Temperature-from-RH-amp-Dry-Bulb // 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)); private _es = 6.112 * exp((17.67 * _temperature) / (_temperature + 243.5));
_e = _es * _relativeHumidity; private _e = _es * _relativeHumidity;
_eDiff = _es - _e; private _eDiff = _es - _e;
_eGuessPrev = _es; private _eGuessPrev = _es;
_cTempDelta = 3.3145; private _cTempDelta = 3.3145;
_twGuess = _temperature; private _twGuess = _temperature;
for "_j" from 1 to 50 do { for "_j" from 1 to 50 do {
_twGuess = _twGuess - _cTempDelta; _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))); _eguess = _eguess - (_pressure * (_temperature - _twGuess) * 0.00066 * (1 + (0.00115 * _twGuess)));
_eDiff = _eguess - _e; _eDiff = _eguess - _e;
if (abs(_eDiff) <= 0.001) exitWith {}; if (abs(_eDiff) <= 0.001) exitWith {};

View File

@ -1,15 +1,17 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates wind chill based on temperature and wind speed * Calculates wind chill based on temperature and wind speed
* *
* Arguments: * Arguments:
* 0: temperature - degrees celcius <NUMBER> * 0: temperature - degrees celsius <NUMBER>
* 1: wind speed - m/s <NUMBER> * 1: wind speed - m/s <NUMBER>
* *
* Return Value: * Return Value:
* wind chill <NUMBER> * wind chill <NUMBER>
* *
* Example:
* [0, 10] call ace_weather_fnc_calculateWindChill
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,43 +1,42 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Calculates the true wind speed at a given world position * Calculates the true wind speed at a given world position
* *
* Arguments: * Arguments:
* 0: world position - posASL <POSTION> * 0: world position - posASL <POSTION>
* 1: Account for wind gradient <BOOL> * 1: Account for wind gradient (used in advanced ballistics) <BOOL>
* 2: Account for terrain <BOOL> * 2: Account for terrain <BOOL>
* 3: Account for obstacles <BOOL> * 3: Account for obstacles <BOOL>
* *
* Return Value: * Return Value:
* wind speed - m/s <NUMBER> * wind speed - m/s <NUMBER>
* *
* Example:
* [eyePos ACE_player, true, true, true] call ace_weather_fnc_calculateWindSpeed;
*
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_fnc_polar2vect", "_windSpeed", "_windDir", "_windDirAdjusted", "_height", "_newWindSpeed", "_windSource", "_roughnessLength"];
params ["_position", "_windGradientEnabled", "_terrainEffectEnabled", "_obstacleEffectEnabled"]; params ["_position", "_windGradientEnabled", "_terrainEffectEnabled", "_obstacleEffectEnabled"];
_fnc_polar2vect = { private _fnc_polar2vect = {
private ["_mag2D"]; params ["_mag","_dir","_elev"];
params ["_x", "_y", "_z"]; private _mag2D = _mag * cos(_elev);
_mag2D = _x * cos(_z); [_mag2D * sin(_dir), _mag2D * cos(_dir), _mag * sin(_elev)];
[_mag2D * sin(_y), _mag2D * cos(_y), _x * sin(_z)];
}; };
_windSpeed = vectorMagnitude ACE_wind; private _windSpeed = vectorMagnitude ACE_wind;
_windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); private _windDir = (ACE_wind select 0) atan2 (ACE_wind select 1);
_windDirAdjusted = _windDir + 180; private _windDirAdjusted = _windDir + 180;
// Wind gradient // Wind gradient
if (_windGradientEnabled) then { if (_windGradientEnabled) then {
if (_windSpeed > 0.05) then { if (_windSpeed > 0.05) then {
_height = (ASLToATL _position) select 2; private _height = (ASLToATL _position) select 2;
_height = 0 max _height min 20; _height = 0 max _height min 20;
if (_height < 20) then { if (_height < 20) then {
_roughnessLength = _position call FUNC(calculateRoughnessLength); private _roughnessLength = _position call FUNC(calculateRoughnessLength);
_windSpeed = _windSpeed * abs(ln(_height / _roughnessLength) / ln(20 / _roughnessLength)); _windSpeed = _windSpeed * abs(ln(_height / _roughnessLength) / ln(20 / _roughnessLength));
}; };
}; };
@ -46,9 +45,9 @@ if (_windGradientEnabled) then {
// Terrain effect on wind // Terrain effect on wind
if (_terrainEffectEnabled) then { if (_terrainEffectEnabled) then {
if (_windSpeed > 0.05) 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 { if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith {
_newWindSpeed = cos(_x * 9) * _windSpeed; _newWindSpeed = cos(_x * 9) * _windSpeed;
}; };
@ -60,6 +59,7 @@ if (_terrainEffectEnabled) then {
if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith { if (!(terrainIntersectASL [_position, _position vectorAdd _windSource])) exitWith {
_newWindSpeed = cos(_x * 9) * _windSpeed; _newWindSpeed = cos(_x * 9) * _windSpeed;
}; };
nil
} count [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; } count [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
_windSpeed = _newWindSpeed; _windSpeed = _newWindSpeed;
}; };
@ -68,9 +68,9 @@ if (_terrainEffectEnabled) then {
// Obstacle effect on wind // Obstacle effect on wind
if (_obstacleEffectEnabled) then { if (_obstacleEffectEnabled) then {
if (_windSpeed > 0.05) 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 { if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith {
_newWindSpeed = cos(_x * 2) * _windSpeed; _newWindSpeed = cos(_x * 2) * _windSpeed;
}; };
@ -82,6 +82,7 @@ if (_obstacleEffectEnabled) then {
if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith { if (!(lineIntersects [_position, _position vectorAdd _windSource])) exitWith {
_newWindSpeed = cos(_x * 2) * _windSpeed; _newWindSpeed = cos(_x * 2) * _windSpeed;
}; };
nil
} count [0, 5, 10, 15, 20, 25, 30, 35, 40, 45]; } count [0, 5, 10, 15, 20, 25, 30, 35, 40, 45];
_windSpeed = _newWindSpeed; _windSpeed = _newWindSpeed;
}; };

View File

@ -1,6 +1,5 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Displays a wind info (colored arrow) in the top left corner of the screen * Displays a wind info (colored arrow) in the top left corner of the screen
* *
* Argument: * Argument:
@ -8,6 +7,11 @@
* *
* Return value: * Return value:
* None * None
*
* Example:
* [] call ace_weather_fnc_displayWindInfo
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
@ -28,17 +32,15 @@ EGVAR(advanced_ballistics,Protractor) = false;
GVAR(WindInfo) = true; 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; GVAR(WindInfo) = false;
0 cutText ["", "PLAIN"]; 0 cutText ["", "PLAIN"];
[_this select 1] call CBA_fnc_removePerFrameHandler; [_this select 1] call CBA_fnc_removePerFrameHandler;
}; };
_windIndex = 12; private _windIndex = 12;
_windColor = [1, 1, 1, 1]; private _windColor = [1, 1, 1, 1];
_windSpeed = if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { private _windSpeed = if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then {
// With wind gradient // With wind gradient
[eyePos ACE_player, true, true, true] call FUNC(calculateWindSpeed); [eyePos ACE_player, true, true, true] call FUNC(calculateWindSpeed);
} else { } else {
@ -47,8 +49,8 @@ GVAR(WindInfo) = true;
}; };
if (_windSpeed > 0.2) then { if (_windSpeed > 0.2) then {
_playerDir = (ACE_player call CBA_fnc_headDir) select 0; private _playerDir = (ACE_player call CBA_fnc_headDir) select 0;
_windDir = (ACE_wind select 0) atan2 (ACE_wind select 1); private _windDir = (ACE_wind select 0) atan2 (ACE_wind select 1);
_windIndex = round(((_playerDir - _windDir + 360) % 360) / 30); _windIndex = round(((_playerDir - _windDir + 360) % 360) / 30);
_windIndex = _windIndex % 12; _windIndex = _windIndex % 12;
}; };

View File

@ -1,6 +1,5 @@
/* /*
* Author: Ruthberg, esteldunedain * Author: Ruthberg, esteldunedain
*
* Get the weather data for the current map * Get the weather data for the current map
* *
* Argument: * Argument:
@ -8,6 +7,11 @@
* *
* Return value: * Return value:
* None * None
*
* Example:
* [] call ace_weather_fnc_getMapData
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"

View File

@ -1,6 +1,5 @@
/* /*
* Author: ACE2 Team, Ruthberg * Author: ACE2 Team, Ruthberg
*
* Calculate current wind locally from the data broadcasted by the server * Calculate current wind locally from the data broadcasted by the server
* *
* Argument: * Argument:
@ -8,17 +7,20 @@
* *
* Return value: * Return value:
* Wind <ARRAY> * Wind <ARRAY>
*
* Example:
* [] call ace_weather_fnc_getWind
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_periodPercent", "_periodPosition"];
if (isNil "ACE_WIND_PARAMS") exitWith { [0, 0, 0] }; if (isNil "ACE_WIND_PARAMS") exitWith { [0, 0, 0] };
ACE_WIND_PARAMS params ["_dir", "_dirChange", "_spd", "_spdChange", "_period"]; ACE_WIND_PARAMS params ["_dir", "_dirChange", "_spd", "_spdChange", "_period"];
_periodPosition = (ACE_time - GVAR(wind_period_start_time)) min _period; private _periodPosition = (ACE_time - GVAR(wind_period_start_time)) min _period;
_periodPercent = _periodPosition / _period; private _periodPercent = _periodPosition / _period;
_spd = _spd + _spdChange * _periodPercent; _spd = _spd + _spdChange * _periodPercent;
_dir = _dir + _dirChange * _periodPercent; _dir = _dir + _dirChange * _periodPercent;

View File

@ -10,6 +10,9 @@
* Return Value: * Return Value:
* None <NIL> * None <NIL>
* *
* Example:
* [module, [], true] call ace_weather_fnc_initModuleSettings
*
* Public: No * Public: No
*/ */

View File

@ -1,6 +1,5 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Inits the wind variables on mission start * Inits the wind variables on mission start
* *
* Argument: * Argument:
@ -8,28 +7,32 @@
* *
* Return value: * Return value:
* None * None
*
* Example:
* [] call ace_weather_fnc_initWind
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_sum", "_rand", "_csum", "_index", "_month", "_windDirectionProbabilities"]; private _month = date select 1;
_month = date select 1; private _windDirectionProbabilities = GVAR(WindDirectionProbabilities) select (_month - 1);
_windDirectionProbabilities = GVAR(WindDirectionProbabilities) select (_month - 1);
ACE_wind = [0, 0, 0]; ACE_wind = [0, 0, 0];
GVAR(wind_direction_reference) = random 360; GVAR(wind_direction_reference) = random 360;
_sum = 0; private _sum = 0;
for "_i" from 0 to 7 do { for "_i" from 0 to 7 do {
_sum = _sum + (_windDirectionProbabilities select _i); _sum = _sum + (_windDirectionProbabilities select _i);
}; };
_rand = random _sum; private _rand = random _sum;
_csum = [0, 0, 0, 0, 0, 0, 0, 0]; private _csum = [0, 0, 0, 0, 0, 0, 0, 0];
for "_i" from 0 to 7 do { for "_i" from 0 to 7 do {
for "_j" from 0 to _i do { for "_j" from 0 to _i do {
_csum set [_i, (_csum select _i) + (_windDirectionProbabilities select _j)]; _csum set [_i, (_csum select _i) + (_windDirectionProbabilities select _j)];
}; };
}; };
_index = 0; private _index = 0;
for "_i" from 0 to 7 do { for "_i" from 0 to 7 do {
if (_rand > (_csum select _i)) then { if (_rand > (_csum select _i)) then {
_index = _index + 1; _index = _index + 1;

View File

@ -1,6 +1,5 @@
/* /*
* Author: Ruthberg * Author: Ruthberg
*
* Gather weather parameters and broadcast them to the clients * Gather weather parameters and broadcast them to the clients
* *
* Argument: * Argument:
@ -8,11 +7,14 @@
* *
* Return value: * Return value:
* None * None
*
* Example:
* [] call ace_weather_fnc_serverController
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
if (!GVAR(enableServerController)) exitWith {};
if (GVAR(useACEWeather)) then { if (GVAR(useACEWeather)) then {
// Use location based real world weather data // Use location based real world weather data
[] call FUNC(updateAceWeather); [] call FUNC(updateAceWeather);

View File

@ -1,6 +1,5 @@
/* /*
* Author: ACE2 Team, esteldunedain, ruthberg * Author: ACE2 Team, esteldunedain, ruthberg
*
* Updates the wind and rain evolution on the server. Broadcasts the current and next values to the clients * Updates the wind and rain evolution on the server. Broadcasts the current and next values to the clients
* *
* Argument: * Argument:
@ -8,20 +7,24 @@
* *
* Return value: * Return value:
* None * None
*
* Example:
* [] call ace_weather_fnc_updateAceWeather
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_overcastMultiplier", "_lastRain", "_rainOverCast", "_transitionTime", "_windDirectionVariance", "_windSpeed", "_windSpeedChange", "_windMaxDiff", "_windMinDiff", "_windDirection", "_windDirectionChange", "_ratioMin", "_ratioMax"]; private _overcastMultiplier = 1 max (2* overcast) min 2; // 0 (@ overcast 0), 2 (@ overcast 1)
_overcastMultiplier = 1 max (2* overcast) min 2; // 0 (@ overcast 0), 2 (@ overcast 1)
// Rain simulation // 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_next_period) = ceil((1 + (random 10)) / _overcastMultiplier);
GVAR(rain_period_count) = 0; GVAR(rain_period_count) = 0;
_lastRain = GVAR(current_rain); private _lastRain = GVAR(current_rain);
private _rainOverCast = 0;
if (overcast >= 0.7) then { if (overcast >= 0.7) then {
_rainOverCast = (overcast - 0.7) / 0.3; _rainOverCast = (overcast - 0.7) / 0.3;
@ -40,7 +43,7 @@ if (GVAR(syncRain) && GVAR(rain_period_count) > GVAR(rain_next_period)) then {
GVAR(current_rain) = 0; 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]; ACE_RAIN_PARAMS = [_lastRain, GVAR(current_rain), _transitionTime];
TRACE_4("",_lastRain,_rainOverCast,_transitionTime,overcast); TRACE_4("",_lastRain,_rainOverCast,_transitionTime,overcast);
@ -50,14 +53,14 @@ if (GVAR(syncRain) && GVAR(rain_period_count) > GVAR(rain_next_period)) then {
}; };
// Wind simulation // 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_next_period) = ceil((2 + (random 5)) / _overcastMultiplier);
GVAR(wind_period_count) = 0; GVAR(wind_period_count) = 0;
_windDirectionVariance = (90 - (random 180)) * (overcast ^ 2); private _windDirectionVariance = (90 - (random 180)) * (overcast ^ 2);
_windDirection = (360 + GVAR(wind_direction_reference) + _windDirectionVariance) % 360; private _windDirection = (360 + GVAR(wind_direction_reference) + _windDirectionVariance) % 360;
_windDirectionChange = _windDirection - GVAR(current_wind_direction); private _windDirectionChange = _windDirection - GVAR(current_wind_direction);
if (_windDirectionChange > 180) then { if (_windDirectionChange > 180) then {
_windDirectionChange = _windDirectionChange - 360; _windDirectionChange = _windDirectionChange - 360;
}; };
@ -65,20 +68,20 @@ if (GVAR(syncWind) && GVAR(wind_period_count) > GVAR(wind_next_period)) then {
_windDirectionChange = 360 + _windDirectionChange; _windDirectionChange = 360 + _windDirectionChange;
}; };
_windMaxDiff = GVAR(mean_wind_speed) - GVAR(max_wind_speed); private _windMaxDiff = GVAR(mean_wind_speed) - GVAR(max_wind_speed);
_windMinDiff = GVAR(min_wind_speed) - GVAR(mean_wind_speed); private _windMinDiff = GVAR(min_wind_speed) - GVAR(mean_wind_speed);
_ratioMax = (random 1) ^ 2; private _ratioMax = (random 1) ^ 2;
_ratioMin = (random 1) ^ 2; private _ratioMin = (random 1) ^ 2;
_windSpeed = GVAR(current_wind_speed); private _windSpeed = GVAR(current_wind_speed);
_windSpeedChange = 0; private _windSpeedChange = 0;
if ((random 1) < (0.3 max overcast)) then { if ((random 1) < (0.3 max overcast)) then {
_windSpeed = GVAR(mean_wind_speed) + _windMaxDiff * _ratioMax + _windMinDiff * _ratioMin; _windSpeed = GVAR(mean_wind_speed) + _windMaxDiff * _ratioMax + _windMinDiff * _ratioMin;
_windSpeedChange = _windSpeed - GVAR(current_wind_speed); _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); TRACE_5("dirCur/dirNew/spdCur/spdNew/period",GVAR(current_wind_direction),_windDirection,GVAR(current_wind_speed),_windSpeed,_transitionTime);

View File

@ -1,27 +1,30 @@
/* /*
* Author: ACE2 Team * Author: ACE2 Team
* * Updates GVAR(currentHumidity)
* Updates GVAR(currentHumidity) based on
* *
* Argument: * Argument:
* Nothing * Nothing
* *
* Return value: * Return value:
* Nothing * Nothing
*
* Example:
* [] call ace_weather_fnc_updateHumidity
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_month", "_avgTemperature", "_pS1", "_pS2"]; private _month = date select 1;
_month = date select 1;
GVAR(currentHumidity) = (GVAR(Humidity) select (_month - 1)) / 100; 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; GVAR(currentHumidity) = 1;
} else { } else {
_avgTemperature = ((GVAR(TempDay) select (_month - 1)) + (GVAR(TempNight) select (_month - 1))) / 2; private _avgTemperature = ((GVAR(TempDay) select (_month - 1)) + (GVAR(TempNight) select (_month - 1))) / 2;
_pS1 = 6.112 * exp((17.62 * _avgTemperature) / (243.12 + _avgTemperature)); private _pS1 = 6.112 * exp((17.62 * _avgTemperature) / (243.12 + _avgTemperature));
_PS2 = 6.112 * exp((17.62 * GVAR(currentTemperature)) / (243.12 + GVAR(currentTemperature))); private _PS2 = 6.112 * exp((17.62 * GVAR(currentTemperature)) / (243.12 + GVAR(currentTemperature)));
GVAR(currentHumidity) = GVAR(currentHumidity) * _PS1 / _PS2; GVAR(currentHumidity) = GVAR(currentHumidity) * _PS1 / _PS2;
GVAR(currentHumidity) = GVAR(currentHumidity) + GVAR(humidityShift); GVAR(currentHumidity) = GVAR(currentHumidity) + GVAR(humidityShift);

View File

@ -1,6 +1,5 @@
/* /*
* Author: ACE2 Team, Ruthberg * Author: ACE2 Team, Ruthberg
*
* Updates rain based on ACE_RAIN_PARAMS * Updates rain based on ACE_RAIN_PARAMS
* *
* Argument: * Argument:
@ -8,17 +7,21 @@
* *
* Return value: * Return value:
* Nothing * Nothing
*
* Example:
* [] call ace_weather_fnc_updateRain
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
if (!GVAR(syncRain)) exitWith {};
if (!isNil "ACE_RAIN_PARAMS") then { if (!isNil "ACE_RAIN_PARAMS") then {
ACE_RAIN_PARAMS params ["_oldRain", "_newRain", "_period"]; ACE_RAIN_PARAMS params ["_oldRain", "_newRain", "_period"];
private ["_periodPosition", "_periodPercent"]; private _periodPosition = (ACE_time - GVAR(rain_period_start_time)) min _period;
_periodPosition = (ACE_time - GVAR(rain_period_start_time)) min _period; private _periodPercent = (_periodPosition / _period) min 1;
_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));
}; };

View File

@ -1,6 +1,5 @@
/* /*
* Author: ACE2 Team * Author: ACE2 Team
*
* Updates GVAR(currentTemperature) based on the map data * Updates GVAR(currentTemperature) based on the map data
* *
* Argument: * Argument:
@ -8,14 +7,18 @@
* *
* Return value: * Return value:
* Nothing * Nothing
*
* Example:
* [] call ace_weather_fnc_updateTemperature
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_time", "_month", "_timeRatio"]; private _time = daytime;
_time = daytime; private _month = date select 1;
_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(TempDay) select (_month - 1)) * (1 - _timeRatio) + (GVAR(TempNight) select (_month - 1)) * _timeRatio;
GVAR(currentTemperature) = GVAR(currentTemperature) + GVAR(temperatureShift) - GVAR(badWeatherShift) * overcast; GVAR(currentTemperature) = GVAR(currentTemperature) + GVAR(temperatureShift) - GVAR(badWeatherShift) * overcast;

View File

@ -1,6 +1,5 @@
/* /*
* Author: ACE2 Team, Ruthberg * Author: ACE2 Team, Ruthberg
*
* Updates wind, gusts and waves based on ACE_wind * Updates wind, gusts and waves based on ACE_wind
* *
* Argument: * Argument:
@ -8,19 +7,22 @@
* *
* Return value: * Return value:
* Nothing * Nothing
*
* Example:
* [] call ace_weather_fnc_updateWind
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
if (!GVAR(syncWind)) exitWith { ACE_wind = wind }; if (!GVAR(syncWind)) exitWith { ACE_wind = wind };
private ["_newWaves"];
ACE_wind = [] call FUNC(getWind); ACE_wind = [] call FUNC(getWind);
setWind [ACE_wind select 0, ACE_wind select 1, true]; setWind [ACE_wind select 0, ACE_wind select 1, true];
2 setGusts 0; 2 setGusts 0;
// Set waves: 0 when no wind, 1 when wind >= 16 m/s // 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 { if (abs(_newWaves - waves) > 0.1) then {
1 setWaves _newWaves; 1 setWaves _newWaves;
}; };

View File

@ -1,6 +1,9 @@
#define COMPONENT weather #define COMPONENT weather
#include "\z\ace\addons\main\script_mod.hpp" #include "\z\ace\addons\main\script_mod.hpp"
//#define DEBUG_ENABLED_WEATHER
// #define DEBUG_MODE_FULL
// #define ENABLE_PERFORMANCE_COUNTERS
#ifdef DEBUG_ENABLED_WEATHER #ifdef DEBUG_ENABLED_WEATHER
#define DEBUG_MODE_FULL #define DEBUG_MODE_FULL
#endif #endif