Skip to content

Commit

Permalink
Medical Treatment - Fix IV return (#10563)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkIsGrim authored Dec 18, 2024
1 parent c435be3 commit 1ffddae
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
16 changes: 13 additions & 3 deletions addons/medical/functions/fnc_getIVs.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
* IVs <ARRAY of ARRAY>:
* 0: IV volume remaining, in liters <STRING>
* 1: IV type (blood, saline, plasma, etc) <STRING>
* 2: Body part IV is attached to <STRING>
* 3: IV classname <STRING>
* 2: IV body part <STRING>
* 3: IV treatment classname <STRING>
* 4: IV flow rate coef <NUMBER>
* 5: IV item classname <STRING>
*
* Example:
* player call ace_medical_fnc_getIVs
Expand All @@ -37,7 +38,16 @@ if !(_unit isKindOf "CAManBase") exitWith {
private _ivBags = [];

{
_ivBags pushBack +_x; // manual deep copy so modification doesn't affect unit state
_x params ["_bagVolume", "_bagType", "_bodyPartIndex", "_treatment", "_rateCoef", "_bagItem"]; // gotta convert body part index back to the part

_ivBags pushBack [
_bagVolume,
_bagType,
ALL_BODY_PARTS select _bodyPartIndex,
treatment,
_rateCoef,
_bagItem
];
} forEach (_unit getVariable [QGVAR(ivBags), []]);

_ivBags
4 changes: 2 additions & 2 deletions addons/medical_status/functions/fnc_getBloodVolumeChange.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (!isNil {_unit getVariable QEGVAR(medical,ivBags)}) then {
private _tourniquets = GET_TOURNIQUETS(_unit);

_bloodBags = _bloodBags apply {
_x params ["_bagVolumeRemaining", "_type", "_bodyPart", "_classname", "_rateCoef"];
_x params ["_bagVolumeRemaining", "_type", "_bodyPart", "_treatment", "_rateCoef", "_item"];

if (_tourniquets select _bodyPart == 0) then {
private _bagChange = (_deltaT * EGVAR(medical,ivFlowRate) * IV_CHANGE_PER_SECOND * _rateCoef) min _bagVolumeRemaining; // absolute value of the change in miliLiters
Expand All @@ -37,7 +37,7 @@ if (!isNil {_unit getVariable QEGVAR(medical,ivBags)}) then {
if (_bagVolumeRemaining < 0.01) then {
[]
} else {
[_bagVolumeRemaining, _type, _bodyPart, _classname, _rateCoef]
[_bagVolumeRemaining, _type, _bodyPart, _treatment, _rateCoef, _item]
};
};

Expand Down
8 changes: 4 additions & 4 deletions addons/medical_treatment/functions/fnc_ivBag.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
* 1: Patient <OBJECT>
* 2: Body Part <STRING>
* 3: Treatment <STRING>
* 4: Item User (not used) <OBJECT>
* 4: Item User <OBJECT>
* 5: Used Item <STRING>
*
* Return Value:
* None
*
* Example:
* [player, cursorObject, "RightArm", "BloodIV", objNull, "ACE_bloodIV"] call ace_medical_treatment_fnc_ivBag
* [player, cursorObject, "RightArm", "BloodIV", player, "ACE_bloodIV"] call ace_medical_treatment_fnc_ivBag
*
* Public: No
*/

params ["_medic", "_patient", "_bodyPart", "_classname", "", "_usedItem"];
params ["_medic", "_patient", "_bodyPart", "_classname", "_itemUser", "_usedItem"];

[_patient, _usedItem] call FUNC(addToTriageCard);
[_patient, "activity", LSTRING(Activity_gaveIV), [[_medic, false, true] call EFUNC(common,getName)]] call FUNC(addToLog);

[QGVAR(ivBagLocal), [_patient, _bodyPart, _classname, _medic], _patient] call CBA_fnc_targetEvent;
[QGVAR(ivBagLocal), [_patient, _bodyPart, _classname, _medic, _itemUser, _usedItem], _patient] call CBA_fnc_targetEvent;
20 changes: 8 additions & 12 deletions addons/medical_treatment/functions/fnc_ivBagLocal.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,40 @@
* 1: Body Part <STRING>
* 2: Treatment <STRING>
* 3: Medic <OBJECT>
* 4: Item User <OBJECT>
* 5: Used item <STRING>
*
* Return Value:
* None
*
* Example:
* [player, "RightArm", "BloodIV", player] call ace_medical_treatment_fnc_ivBagLocal
* [player, "RightArm", "BloodIV", player, player, "ACE_BloodIV"] call ace_medical_treatment_fnc_ivBagLocal
*
* Public: No
*/

params ["_patient", "_bodyPart", "_classname", "_medic"];
params ["_patient", "_bodyPart", "_treatment", "_medic", "_itemUser", "_item"];

// Exit if patient has max blood volume
private _bloodVolume = GET_BLOOD_VOLUME(_patient);
if (_bloodVolume >= DEFAULT_BLOOD_VOLUME) exitWith {
// Return the bag if patient is topped up on blood
if (_medic call EFUNC(common,isPlayer)) then {
private _receiver = [_patient, _medic, _medic] select GVAR(allowSharedEquipment);
[_receiver, _classname] call EFUNC(common,addToInventory);
} else {
// If the medic is AI, only return bag if enabled
if (missionNamespace getVariable [QEGVAR(medical_ai,requireItems), 0] > 0) then {
[_medic, _classname] call EFUNC(common,addToInventory);
};
if (_medic call EFUNC(common,isPlayer) || {missionNamespace getVariable [QEGVAR(medical_ai,requireItems), 0] > 0}) then {
[_itemUser, _item] call EFUNC(common,addToInventory);
};
};

private _partIndex = ALL_BODY_PARTS find toLowerANSI _bodyPart;

// Get attributes for the used IV
private _defaultConfig = configFile >> QUOTE(ADDON) >> "IV";
private _ivConfig = _defaultConfig >> _classname;
private _ivConfig = _defaultConfig >> _treatment;

private _volume = GET_NUMBER(_ivConfig >> "volume",getNumber (_defaultConfig >> "volume"));
private _type = GET_STRING(_ivConfig >> "type",getText (_defaultConfig >> "type"));
private _rateCoef = GET_NUMBER(_ivConfig >> "rateCoef",getNumber (_defaultConfig >> "rateCoef"));

// Add IV bag to patient's ivBags array
private _ivBags = _patient getVariable [QEGVAR(medical,ivBags), []];
_ivBags pushBack [_volume, _type, _partIndex, _classname, _rateCoef];
_ivBags pushBack [_volume, _type, _partIndex, _treatment, _rateCoef, _item];
_patient setVariable [QEGVAR(medical,ivBags), _ivBags, true];

0 comments on commit 1ffddae

Please sign in to comment.