From 0313e7b322858802831d35c7ed3922b8bc7b406f Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Tue, 19 Jan 2016 17:03:47 -0300 Subject: [PATCH] Divide the weapon state variable into two: a temp variable, and a time variable. Only broadcast the temp part and only approximately --- addons/overheating/functions/fnc_firedEH.sqf | 7 +++---- .../functions/fnc_swapBarrelCallback.sqf | 5 ++++- .../functions/fnc_updateTemperature.sqf | 17 ++++++++++------- addons/overheating/script_component.hpp | 1 + 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/addons/overheating/functions/fnc_firedEH.sqf b/addons/overheating/functions/fnc_firedEH.sqf index aedb20e62b..1641553ac8 100644 --- a/addons/overheating/functions/fnc_firedEH.sqf +++ b/addons/overheating/functions/fnc_firedEH.sqf @@ -36,11 +36,10 @@ if (_unit == ACE_player) then { }; // Get current temperature from the unit variable -private _variableName = format [QGVAR(%1), _weapon]; -(_unit getVariable [_variableName, [0, 0]]) params ["_temperature"]; +private _temperature = _unit getVariable [format [QGVAR(%1_temp), _weapon], 0] private _scaledTemperature = linearConversion [0, 1000, _temperature, 0, 1, true]; -TRACE_3("",_variableName,_temperature,_scaledTemperature); +TRACE_2("",_temperature,_scaledTemperature); //Get weapon data from cache: private _weaponData = GVAR(weaponInfoCache) getVariable _weapon; @@ -76,7 +75,7 @@ if (GVAR(overheatingDispersion)) then { //Dispersion: 0 mils @ 0°C, 0.5 mils @ 333°C, 2.2 mils @ 666°C, 5 mils at 1000°C _dispersion = _dispersion * 0.28125 * (_scaledTemperature^2); - + _slowdownFactor = _slowdownFactor * linearConversion [0.666, 1, _scaledTemperature, 0, -0.1, true]; // Get the pseudo random values for dispersion from the remaining ammo count diff --git a/addons/overheating/functions/fnc_swapBarrelCallback.sqf b/addons/overheating/functions/fnc_swapBarrelCallback.sqf index 1f6fdb8b59..287968fc00 100644 --- a/addons/overheating/functions/fnc_swapBarrelCallback.sqf +++ b/addons/overheating/functions/fnc_swapBarrelCallback.sqf @@ -22,4 +22,7 @@ TRACE_2("params",_player,_weapon); // don't consume the barrel, but rotate through them. [localize LSTRING(SwappedBarrel), QUOTE(PATHTOF(UI\spare_barrel_ca.paa))] call EFUNC(common,displayTextPicture); -_player setVariable [format [QGVAR(%1), _weapon], [0, 0], false]; +// Publish the temperature variable +_unit setVariable [format [QGVAR(%1_temp), 0, true]; +// Store the update time +_unit setVariable [format [QGVAR(%1_time), ACE_time]; diff --git a/addons/overheating/functions/fnc_updateTemperature.sqf b/addons/overheating/functions/fnc_updateTemperature.sqf index c7d64790ed..89d5975024 100644 --- a/addons/overheating/functions/fnc_updateTemperature.sqf +++ b/addons/overheating/functions/fnc_updateTemperature.sqf @@ -20,11 +20,12 @@ params ["_unit", "_weapon", "_heatIncrement"]; TRACE_3("params",_unit,_weapon,_heatIncrement); -// each weapon has it's own variable. Can't store the temperature in the weapon since they are not objects unfortunately. -private _variableName = format [QGVAR(%1), _weapon]; - // get old values -(_unit getVariable [_variableName, [0, 0]]) params ["_temperature", "_time"]; +// each weapon has it's own variable. Can't store the temperature in the weapon since they are not objects unfortunately. +private _tempVarName = format [QGVAR(%1_temp), _weapon]; +private _timeVarName = format [QGVAR(%1_time), _weapon]; +private _temperature = _unit getVariable [_tempVarName, 0]; +private _lastTime = _unit getVariable [_timeVarName, 0]; private _barrelMass = 0.50 * (getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "mass") / 22.0) max 1.0; @@ -71,13 +72,15 @@ _fnc_cooling = { }; // Calculate cooling -_temperature = [_temperature, _barrelMass, ACE_time - _time] call _fnc_cooling; +_temperature = [_temperature, _barrelMass, ACE_time - _lastTime] call _fnc_cooling; TRACE_1("cooledTo",_temperature); // Calculate heating // Steel Heat Capacity = 466 J/(Kg.K) _temperature = _temperature + _heatIncrement / (_barrelMass * 466); -// Publish the variable -[_unit, _variableName, [_temperature, ACE_time], 2.0] call EFUNC(common,setVariablePublic); +// Publish the temperature variable +[_unit, _tempVarName, _temperature, TEMP_TOLERANCE] call EFUNC(common,setApproximateVariablePublic); +// Store the update time locally +_unit setVariable [_timeVarName, ACE_time]; _temperature diff --git a/addons/overheating/script_component.hpp b/addons/overheating/script_component.hpp index dee897e0c0..47ea541c1a 100644 --- a/addons/overheating/script_component.hpp +++ b/addons/overheating/script_component.hpp @@ -14,6 +14,7 @@ #include "\z\ace\addons\main\script_macros.hpp" +#define TEMP_TOLERANCE 50 #ifdef DEBUG_MODE_FULL #define TRACE_PROJECTILE_INFO(BULLET) _vdir = vectorNormalized velocity BULLET; _dir = (_vdir select 0) atan2 (_vdir select 1); _up = asin (_vdir select 2); _mv = vectorMagnitude velocity BULLET; TRACE_3("adjusted projectile",_dir,_up,_mv);