mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Move to a function and comments the function that tracks the effects of medications over time. Use waitAndExecute instead of a pfh for better performance.
This commit is contained in:
parent
21d4939abb
commit
0e82cdfe82
@ -57,6 +57,7 @@ PREP(isMedic);
|
||||
PREP(isMedicalVehicle);
|
||||
PREP(isInStableCondition);
|
||||
PREP(itemCheck);
|
||||
PREP(medicationEffectLoop);
|
||||
PREP(modifyMedicalAction);
|
||||
PREP(onMedicationUsage);
|
||||
PREP(onWoundUpdateRequest);
|
||||
|
42
addons/medical/functions/fnc_medicationEffectLoop.sqf
Normal file
42
addons/medical/functions/fnc_medicationEffectLoop.sqf
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: Glowbal, esteldunedain
|
||||
* Medication effect loop for an injection.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
* 1: Name of the Variable that is affected <STRING>
|
||||
* 2: Proportion of the effect applied <NUMBER>
|
||||
* 3: Rate at which the effect is applied <NUMBER>
|
||||
* 4: Viscosity adjustment rate <NUMBER>
|
||||
* 5: Pain reduction rate <NUMBER>
|
||||
*
|
||||
* ReturnValue:
|
||||
* None
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_unit", "_variableName", "_amountDecreased","_decreaseRate", "_viscosityAdjustmentRate", "_painReduceRate"];
|
||||
|
||||
// If the unit died the loop is finished
|
||||
if (!alive _unit) exitWith {};
|
||||
|
||||
// If locality changed finish the local loop
|
||||
if (!local _unit) exitWith {};
|
||||
|
||||
// Apply medicinal effect
|
||||
private _usedMeds = (_unit getVariable [_variableName, 0]) - _decreaseRate;
|
||||
_unit setVariable [_variableName, _usedMeds];
|
||||
|
||||
// Restore the viscosity while the medication is leaving the system
|
||||
_unit setVariable [QGVAR(peripheralResistance), ((_unit getVariable [QGVAR(peripheralResistance), 100]) - _viscosityAdjustmentRate) max 0];
|
||||
_unit setVariable [QGVAR(painSuppress), ((_unit getVariable [QGVAR(painSuppress), 0]) - _painReduceRate) max 0];
|
||||
|
||||
// Exit if the medication has finished it's effect
|
||||
_amountDecreased = _amountDecreased + _decreaseRate;
|
||||
if (_amountDecreased >= 1 || (_usedMeds <= 0) || !alive _unit) exitWith {};
|
||||
|
||||
// Schedule the loop to be executed again 1 sec later
|
||||
[DFUNC(medicationEffectLoop), [_unit, _variableName, _amountDecreased, _decreaseRate, _viscosityAdjustmentRate, _painReduceRate], 1] call EFUNC(common,waitAndExecute);
|
@ -77,22 +77,5 @@ if (_hasOverDosed > 0 && GVAR(enableOverdosing)) then {
|
||||
_decreaseAmount = 1 / _timeInSystem;
|
||||
_viscosityAdjustment = _viscosityChange / _timeInSystem;
|
||||
|
||||
[{
|
||||
params ["_args", "_idPFH"];
|
||||
_args params ["_target", "_timeInSystem", "_variable", "_amountDecreased","_decreaseAmount", "_viscosityAdjustment", "_painReduce"];
|
||||
private "_usedMeds";
|
||||
_usedMeds = _target getVariable [_variable, 0];
|
||||
_usedMeds = _usedMeds - _decreaseAmount;
|
||||
_target setVariable [_variable, _usedMeds];
|
||||
|
||||
_amountDecreased = _amountDecreased + _decreaseAmount;
|
||||
|
||||
// Restoring the viscosity while the medication is leaving the system
|
||||
_target setVariable [QGVAR(peripheralResistance), ((_target getVariable [QGVAR(peripheralResistance), 100]) - _viscosityAdjustment) max 0];
|
||||
_target setVariable [QGVAR(painSuppress), ((_target getVariable [QGVAR(painSuppress), 0]) - _painReduce) max 0];
|
||||
|
||||
if (_amountDecreased >= 1 || (_usedMeds <= 0) || !alive _target) then {
|
||||
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
||||
};
|
||||
_args set [3, _amountDecreased];
|
||||
}, 1, [_target, _timeInSystem, _variable, 0, _decreaseAmount, _viscosityAdjustment, _painReduce / _timeInSystem] ] call CBA_fnc_addPerFrameHandler;
|
||||
// Run the loop that computes the effect of the medication over time
|
||||
[_target, _timeInSystem, _variable, 0, _decreaseAmount, _viscosityAdjustment, _painReduce / _timeInSystem] call FUNC(medicationEffectLoop);
|
||||
|
Loading…
Reference in New Issue
Block a user