2018-07-30 09:22:14 +00:00
|
|
|
#include "script_component.hpp"
|
2016-07-15 10:23:47 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
2019-06-03 15:31:46 +00:00
|
|
|
* Local callback for bandaging a patient's open wounds.
|
2016-07-15 10:23:47 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2019-06-03 15:31:46 +00:00
|
|
|
* 0: Patient <OBJECT>
|
|
|
|
* 1: Body Part <STRING>
|
|
|
|
* 2: Treatment <STRING>
|
2016-07-15 10:23:47 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2019-06-03 15:31:46 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, "Head", "FieldDressing"] call ace_medical_treatment_fnc_bandageLocal
|
2016-07-15 10:23:47 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2019-06-03 15:31:46 +00:00
|
|
|
params ["_patient", "_bodyPart", "_bandage"];
|
2019-10-08 15:45:09 +00:00
|
|
|
TRACE_3("bandageLocal",_patient,_bodyPart,_bandage);
|
2023-06-24 05:11:56 +00:00
|
|
|
_bodyPart = toLower _bodyPart;
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2019-06-22 18:36:27 +00:00
|
|
|
private _openWounds = GET_OPEN_WOUNDS(_patient);
|
2023-06-24 05:11:56 +00:00
|
|
|
private _woundsOnPart = _openWounds getOrDefault [_bodyPart, []];
|
|
|
|
if (_woundsOnPart isEqualTo []) exitWith {};
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2023-09-10 06:06:15 +00:00
|
|
|
// Figure out which injuries for this bodypart are the best choice to bandage
|
|
|
|
private _targetWounds = [_patient, _bandage, _bodyPart, GVAR(bandageEffectiveness)] call FUNC(findMostEffectiveWounds);
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2018-07-25 08:35:04 +00:00
|
|
|
// Everything is patched up on this body part already
|
2023-09-10 06:06:15 +00:00
|
|
|
if (count _targetWounds == 0) exitWith {};
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2023-09-10 06:06:15 +00:00
|
|
|
private _treatedDamage = 0;
|
|
|
|
private _clearConditionCache = false;
|
|
|
|
|
|
|
|
{
|
|
|
|
private _wound = _x;
|
|
|
|
_wound params ["_classID", "_amountOf", "_bleeding", "_damage"];
|
|
|
|
_y params ["_effectiveness", "_woundIndex", "_impact"];
|
|
|
|
|
|
|
|
// clear condition cache if we stopped all bleeding for this injury
|
|
|
|
if (!_clearConditionCache) then {
|
|
|
|
_clearConditionCache = (_effectiveness >= _amountOf);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Reduce the amount this injury is present
|
|
|
|
(_woundsOnPart select _woundIndex) set [1, _amountOf - _impact];
|
|
|
|
|
|
|
|
// Store treated damage for clearing trauma
|
|
|
|
_treatedDamage = _treatedDamage + (_impact * _damage);
|
|
|
|
|
|
|
|
// Handle reopening bandaged wounds
|
|
|
|
if (_impact > 0 && {GVAR(advancedBandages) == 2}) then {
|
|
|
|
[_patient, _impact, _bodyPart, _woundIndex, _wound, _bandage] call FUNC(handleBandageOpening);
|
|
|
|
};
|
|
|
|
} forEach _targetWounds;
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2019-06-22 18:36:27 +00:00
|
|
|
_patient setVariable [VAR_OPEN_WOUNDS, _openWounds, true];
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2019-06-03 15:31:46 +00:00
|
|
|
[_patient] call EFUNC(medical_status,updateWoundBloodLoss);
|
2019-04-27 19:12:11 +00:00
|
|
|
|
2019-05-12 04:13:59 +00:00
|
|
|
// Check if we fixed limping from this treatment
|
2023-06-24 05:11:56 +00:00
|
|
|
if (
|
|
|
|
EGVAR(medical,limping) == 1
|
2023-09-10 06:06:15 +00:00
|
|
|
&& {_clearConditionCache}
|
|
|
|
&& {_bodyPart in ["leftleg", "rightleg"]}
|
2023-06-24 05:11:56 +00:00
|
|
|
&& {_patient getVariable [QEGVAR(medical,isLimping), false]}
|
|
|
|
) then {
|
2019-06-03 15:31:46 +00:00
|
|
|
[_patient] call EFUNC(medical_engine,updateDamageEffects);
|
2019-05-12 04:13:59 +00:00
|
|
|
};
|
|
|
|
|
2021-10-12 08:08:10 +00:00
|
|
|
if (GVAR(clearTrauma) == 2) then {
|
2023-06-24 05:11:56 +00:00
|
|
|
TRACE_2("clearTrauma - clearing trauma after bandage",_bodyPart,_openWounds);
|
|
|
|
private _partIndex = ALL_BODY_PARTS find _bodyPart;
|
2021-10-12 08:08:10 +00:00
|
|
|
private _bodyPartDamage = _patient getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]];
|
2023-09-10 06:06:15 +00:00
|
|
|
private _newDam = (_bodyPartDamage select _partIndex) - _treatedDamage;
|
2023-06-24 05:11:56 +00:00
|
|
|
|
|
|
|
// Prevent obscenely small damage from lack of floating precision
|
|
|
|
if (_newDam < 0.05) then {
|
2019-10-08 15:45:09 +00:00
|
|
|
_bodyPartDamage set [_partIndex, 0];
|
2021-10-12 08:08:10 +00:00
|
|
|
} else {
|
|
|
|
_bodyPartDamage set [_partIndex, _newDam];
|
|
|
|
};
|
|
|
|
_patient setVariable [QEGVAR(medical,bodyPartDamage), _bodyPartDamage, true];
|
2023-09-10 06:06:15 +00:00
|
|
|
TRACE_2("clearTrauma - healed damage",_partIndex,_treatedDamage);
|
2019-10-08 15:45:09 +00:00
|
|
|
|
2023-06-24 05:11:56 +00:00
|
|
|
switch (_bodyPart) do {
|
|
|
|
case "head": { [_patient, true, false, false, false] call EFUNC(medical_engine,updateBodyPartVisuals); };
|
|
|
|
case "body": { [_patient, false, true, false, false] call EFUNC(medical_engine,updateBodyPartVisuals); };
|
|
|
|
case "leftarm";
|
|
|
|
case "rightarm": { [_patient, false, false, true, false] call EFUNC(medical_engine,updateBodyPartVisuals); };
|
2021-10-12 08:08:10 +00:00
|
|
|
default { [_patient, false, false, false, true] call EFUNC(medical_engine,updateBodyPartVisuals); };
|
2019-10-08 15:45:09 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-06-24 05:11:56 +00:00
|
|
|
// Reset treatment condition cache for nearby players if we stopped all bleeding
|
2023-09-10 06:06:15 +00:00
|
|
|
if (_clearConditionCache) then {
|
2019-12-12 16:25:21 +00:00
|
|
|
private _nearPlayers = (_patient nearEntities ["CAManBase", 6]) select {_x call EFUNC(common,isPlayer)};
|
|
|
|
TRACE_1("clearConditionCaches: bandage",_nearPlayers);
|
|
|
|
[QEGVAR(interact_menu,clearConditionCaches), [], _nearPlayers] call CBA_fnc_targetEvent;
|
|
|
|
};
|