From cd28c9a944b959906f13ecef4977b429c52473bb Mon Sep 17 00:00:00 2001 From: mazinskihenry <33608576+mazinskihenry@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:20:47 -0800 Subject: [PATCH] Add infectionArray --- .../chemical/functions/fnc_fullHealLocal.sqf | 1 + .../chemical/functions/fnc_gasManagerPFH.sqf | 5 +++-- addons/chemical/functions/fnc_poison.sqf | 12 ++++++++++-- .../vitals/functions/fnc_handlePoisoning.sqf | 19 ++++++++++++++++--- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/addons/chemical/functions/fnc_fullHealLocal.sqf b/addons/chemical/functions/fnc_fullHealLocal.sqf index d9d46d734..5874a2e37 100644 --- a/addons/chemical/functions/fnc_fullHealLocal.sqf +++ b/addons/chemical/functions/fnc_fullHealLocal.sqf @@ -22,3 +22,4 @@ _patient setVariable [QGVAR(gasmask_durability), 10, true]; _patient setVariable [QGVAR(CSGas), 0, true]; _patient setVariable [QGVAR(airPoisoning), false, true]; _patient setVariable [QGVAR(infectionTime), missionNamespace getVariable [QGVAR(infectionTime), 60], true]; +_patient setVariable [QGVAR(infectionArray), [], true]; \ No newline at end of file diff --git a/addons/chemical/functions/fnc_gasManagerPFH.sqf b/addons/chemical/functions/fnc_gasManagerPFH.sqf index f4fb22083..c49c3058b 100644 --- a/addons/chemical/functions/fnc_gasManagerPFH.sqf +++ b/addons/chemical/functions/fnc_gasManagerPFH.sqf @@ -20,6 +20,8 @@ _y params ["_gasLogic", "_radius", "_gasLevel", "_condition", "_conditionArgs", "_isSealable"]; TRACE_2("gasManagerPFH loop",_x,_y); + private _infectedObject = _y; + // Remove when condition is no longer valid if !(_conditionArgs call _condition) then { TRACE_2("condition no longer valid, deleting",_x,_y); @@ -34,7 +36,6 @@ // Poison units (alive or dead) close to the gas source { - // Get the distance of the unit from the center of the sphere (_gasLogic) private _distance = _x distance _gasLogic; @@ -46,7 +47,7 @@ _x setVariable [QGVAR(areaIntensity), _intensity, true]; - [QGVAR(poison), [_x, _gasLevel], _x] call CBA_fnc_targetEvent; + [QGVAR(poison), [_x, _gasLevel, _infectedObject], _x] call CBA_fnc_targetEvent; } forEach nearestObjects [_gasLogic, ["CAManBase"], _radius]; } forEach GVAR(gasSources); diff --git a/addons/chemical/functions/fnc_poison.sqf b/addons/chemical/functions/fnc_poison.sqf index 0c8d549d9..9958334f6 100644 --- a/addons/chemical/functions/fnc_poison.sqf +++ b/addons/chemical/functions/fnc_poison.sqf @@ -15,7 +15,7 @@ * Public: No */ -params ["_unit", "_gasLevel"]; +params ["_unit", "_gasLevel", "_infectedObject"]; // Check if unit is remote (objNull is remote) if (!local _unit) exitWith { @@ -44,6 +44,14 @@ if (_gasLevel == 0) exitWith { }; }; +private _currentInfectionArray = _unit getVariable [QGVAR(infectionArray), []]; + +if ((_currentInfectionArray findIf { _x isEqualTo _infectedObject}) == -1) then { + _currentInfectionArray append [_infectedObject]; +}; + +_unit setVariable [QGVAR(infectionArray), _currentInfectionArray, true]; + //Get max infection time private _infectionTime = missionNamespace getVariable [QGVAR(infectionTime), 60]; @@ -62,4 +70,4 @@ if (_currentInfection != _newTime) then { // Exit if infection reaches 0 if (_newTime <= 0) then { _unit setVariable [QGVAR(airPoisoning), true, true]; -}; +}; \ No newline at end of file diff --git a/addons/vitals/functions/fnc_handlePoisoning.sqf b/addons/vitals/functions/fnc_handlePoisoning.sqf index b8f9e75b8..c150c5eae 100644 --- a/addons/vitals/functions/fnc_handlePoisoning.sqf +++ b/addons/vitals/functions/fnc_handlePoisoning.sqf @@ -24,12 +24,25 @@ private _currentCS = _unit getVariable [QEGVAR(chemical,CSGas), 0]; _unit setVariable [QEGVAR(chemical,CSGas), (_currentCS - (_poisonAdjustment * _deltaT)) max 0, _syncValue]; -if !(_unit getVariable [QEGVAR(chemical,airPoisoning), false]) then { +private _infectionArray = _unit getVariable [QEGVAR(chemical,infectionArray), []]; + +if (count _infectionArray == 0) then { private _currentInfection = _unit getVariable [QEGVAR(chemical,infectionTime), missionNamespace getVariable [QEGVAR(chemical,infectionTime), 60]]; private _updateTime = _currentInfection + (1 * _deltaT); _updateTime = _updateTime min (missionNamespace getVariable [QEGVAR(chemical,infectionTime), 60]); _unit setVariable [QEGVAR(chemical,infectionTime), _updateTime, true]; } else { - _unit setVariable [QEGVAR(chemical,infectionTime), 0, true]; -}; + { + _x params ["_gasLogic", "_radius", "_gasLevel", "_condition", "_conditionArgs", "_isSealable"]; + + // Get the distance of the unit from the center of the sphere (_gasLogic) + private _distance = _unit distance _gasLogic; + + if (_distance > _radius) then { + _infectionArray deleteAt _forEachIndex; + }; + } forEach _infectionArray; + + _unit setVariable [QEGVAR(chemical,infectionArray), _infectionArray, true]; +}; \ No newline at end of file