Divide the weapon state variable into two: a temp variable, and a time variable. Only broadcast the temp part and only approximately

This commit is contained in:
esteldunedain 2016-01-19 17:03:47 -03:00
parent 782934c4b2
commit 0313e7b322
4 changed files with 18 additions and 12 deletions

View File

@ -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

View File

@ -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];

View File

@ -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

View File

@ -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);