ACE3/addons/medical_vitals/functions/fnc_updatePainSuppress.sqf

54 lines
1.9 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
/*
* Author: Glowbal
* Update the pain suppression
*
* Arguments:
* 0: The Unit <OBJECT>
* 1: Time since last update <NUMBER>
* 2: Sync value? <BOOL>
*
2018-05-08 08:17:47 +00:00
* Return Value:
* None
*
* Public: No
*/
params ["_unit", "_deltaT", "_syncValue"];
private _painSupressAdjustment = 0;
2018-05-23 09:52:47 +00:00
private _adjustments = _unit getVariable [VAR_PAIN_SUPP_ADJ, []];
2018-05-23 09:52:47 +00:00
if !(_adjustments isEqualTo []) then {
{
_x params ["_value", "_timeTillMaxEffect", "_maxTimeInSystem", "_timeInSystem"];
2018-05-23 09:52:47 +00:00
if (_value != 0 && {_maxTimeInSystem > 0}) then {
if (_timeInSystem >= _maxTimeInSystem) then {
2018-05-23 09:52:47 +00:00
_adjustments set [_forEachIndex, nil];
} else {
_timeInSystem = _timeInSystem + _deltaT;
private _effectRatio = ((_timeInSystem / (1 max _timeTillMaxEffect)) ^ 2) min 1;
_painSupressAdjustment = _painSupressAdjustment + _value * _effectRatio * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem;
_x set [3, _timeInSystem];
};
} else {
2018-05-23 09:52:47 +00:00
_adjustments set [_forEachIndex, nil];
};
2018-05-23 09:52:47 +00:00
} forEach _adjustments;
2018-05-23 09:52:47 +00:00
_unit setVariable [VAR_PAIN_SUPP_ADJ, _adjustments - [nil], (_syncValue || {_adjustments isEqualTo []})]; // always sync on last run
2018-05-08 08:17:47 +00:00
_unit setVariable [VAR_PAIN_SUPP, 0 max _painSupressAdjustment, _syncValue];
};
// Handle continuous pain reduction
private _pain = GET_PAIN(_unit);
2018-05-08 09:16:12 +00:00
_unit setVariable [QEGVAR(medical_status,pain), 0 max (_pain - _deltaT / PAIN_FADE_TIME), _syncValue];
// Handles simple medication
if (isNil QEGVAR(medical_treatment,advancedMedication) || {!EGVAR(medical_treatment,advancedMedication)}) then {
private _painSupress = _unit getVariable [VAR_PAIN_SUPP, 0];
_painSupress = _painSupress - _deltaT / PAIN_SUPPRESSION_FADE_TIME;
_unit setVariable [VAR_PAIN_SUPP, 0 max _painSupress, _syncValue];
};