2016-12-06 19:42:10 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
|
|
|
* Update the peripheral resistance
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: The Unit <OBJECT>
|
|
|
|
* 1: Time since last update <NUMBER>
|
|
|
|
* 2: Sync value? <BOOL>
|
|
|
|
*
|
|
|
|
* ReturnValue:
|
|
|
|
* nothing
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
params ["_unit", "_deltaT", "_syncValue"];
|
|
|
|
|
|
|
|
private _peripheralResistanceAdjustment = 0;
|
|
|
|
private _adjustment = _unit getVariable [QGVAR(peripheralResistanceAdjustments), []];
|
|
|
|
|
|
|
|
if (!(_adjustment isEqualTo [])) then {
|
|
|
|
{
|
|
|
|
_x params ["_value", "_timeTillMaxEffect", "_maxTimeInSystem", "_timeInSystem"];
|
|
|
|
if (abs _value > 0 && {_maxTimeInSystem > 0}) then {
|
|
|
|
if (_timeInSystem >= _maxTimeInSystem) then {
|
|
|
|
_adjustment set [_forEachIndex, ObjNull];
|
|
|
|
} else {
|
|
|
|
_timeInSystem = _timeInSystem + _deltaT;
|
|
|
|
private _effectRatio = ((_timeInSystem / (1 max _timeTillMaxEffect)) ^ 2) min 1;
|
|
|
|
_peripheralResistanceAdjustment = _peripheralResistanceAdjustment + _value * _effectRatio * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem;
|
|
|
|
_x set [3, _timeInSystem];
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
_adjustment set [_forEachIndex, ObjNull];
|
|
|
|
};
|
|
|
|
} forEach _adjustment;
|
|
|
|
|
|
|
|
_adjustment = _adjustment - [ObjNull];
|
|
|
|
_unit setVariable [QGVAR(peripheralResistanceAdjustments), _adjustment, _syncValue];
|
|
|
|
|
2017-04-22 15:57:32 +00:00
|
|
|
// always sync on last run
|
|
|
|
_unit SetVariable [QGVAR(peripheralResistance), 0 max (100 + _peripheralResistanceAdjustment), _syncValue || {_adjustment isEqualTo []}];
|
2016-12-06 19:42:10 +00:00
|
|
|
};
|