2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-07-15 10:23:47 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
|
|
|
* Handles the bandage of a patient.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: The target <OBJECT>
|
|
|
|
* 1: The impact <NUMBER>
|
2023-06-24 05:11:56 +00:00
|
|
|
* 2: Body part <STRING>
|
2016-07-15 10:23:47 +00:00
|
|
|
* 3: Injury index <NUMBER>
|
|
|
|
* 4: Injury <ARRAY>
|
|
|
|
* 5: Used Bandage type <STRING>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_target", "_impact", "_part", "_injuryIndex", "_injury", "_bandage"];
|
2019-04-27 19:12:11 +00:00
|
|
|
TRACE_6("handleBandageOpening",_target,_impact,_part,_injuryIndex,_injury,_bandage);
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2023-06-24 05:11:56 +00:00
|
|
|
_injury params ["_classID"];
|
2019-04-27 19:12:11 +00:00
|
|
|
|
2019-05-12 04:13:59 +00:00
|
|
|
private _className = EGVAR(medical_damage,woundClassNamesComplex) select _classID;
|
2018-07-29 21:43:14 +00:00
|
|
|
private _reopeningChance = DEFAULT_BANDAGE_REOPENING_CHANCE;
|
|
|
|
private _reopeningMinDelay = DEFAULT_BANDAGE_REOPENING_MIN_DELAY;
|
|
|
|
private _reopeningMaxDelay = DEFAULT_BANDAGE_REOPENING_MAX_DELAY;
|
2016-07-15 10:23:47 +00:00
|
|
|
|
|
|
|
// Get the default values for the used bandage
|
2016-10-20 11:38:26 +00:00
|
|
|
private _config = configFile >> QUOTE(ADDON) >> "Bandaging";
|
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
if (isClass (_config >> _bandage)) then {
|
2016-10-20 11:38:26 +00:00
|
|
|
_config = _config >> _bandage;
|
2016-07-15 10:23:47 +00:00
|
|
|
_reopeningChance = getNumber (_config >> "reopeningChance");
|
|
|
|
_reopeningMinDelay = getNumber (_config >> "reopeningMinDelay");
|
|
|
|
_reopeningMaxDelay = getNumber (_config >> "reopeningMaxDelay") max _reopeningMinDelay;
|
|
|
|
} else {
|
2016-08-22 19:06:52 +00:00
|
|
|
WARNING_2("No config for bandage [%1] config base [%2]", _bandage, _config);
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (isClass (_config >> _className)) then {
|
2016-10-20 11:38:26 +00:00
|
|
|
private _woundTreatmentConfig = _config >> _className;
|
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
if (isNumber (_woundTreatmentConfig >> "reopeningChance")) then {
|
|
|
|
_reopeningChance = getNumber (_woundTreatmentConfig >> "reopeningChance");
|
|
|
|
};
|
2016-10-20 11:38:26 +00:00
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
if (isNumber (_woundTreatmentConfig >> "reopeningMinDelay")) then {
|
|
|
|
_reopeningMinDelay = getNumber (_woundTreatmentConfig >> "reopeningMinDelay");
|
|
|
|
};
|
2016-10-20 11:38:26 +00:00
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
if (isNumber (_woundTreatmentConfig >> "reopeningMaxDelay")) then {
|
|
|
|
_reopeningMaxDelay = getNumber (_woundTreatmentConfig >> "reopeningMaxDelay") max _reopeningMinDelay;
|
|
|
|
};
|
|
|
|
} else {
|
2016-08-22 19:06:52 +00:00
|
|
|
WARNING_2("No config for wound type [%1] config base [%2]", _className, _config);
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
TRACE_5("configs",_bandage,_className,_reopeningChance,_reopeningMinDelay,_reopeningMaxDelay);
|
|
|
|
|
2019-06-22 18:36:27 +00:00
|
|
|
private _bandagedWounds = GET_BANDAGED_WOUNDS(_target);
|
2016-07-15 10:23:47 +00:00
|
|
|
private _exist = false;
|
|
|
|
{
|
2023-06-24 05:11:56 +00:00
|
|
|
_x params ["_id", "_amountOf"];
|
|
|
|
if (_id == _classID) exitWith {
|
|
|
|
_x set [1, _amountOf + _impact];
|
|
|
|
TRACE_2("adding to existing bandagedWound",_id,_part);
|
2016-07-15 10:23:47 +00:00
|
|
|
_exist = true;
|
|
|
|
};
|
2023-06-24 05:11:56 +00:00
|
|
|
} forEach (_bandagedWounds getOrDefault [_part, []]);
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2016-12-10 15:36:36 +00:00
|
|
|
if (!_exist) then {
|
2023-06-24 05:11:56 +00:00
|
|
|
TRACE_2("adding new bandagedWound",_classID,_part);
|
2016-12-10 15:36:36 +00:00
|
|
|
private _bandagedInjury = +_injury;
|
2023-06-24 05:11:56 +00:00
|
|
|
_bandagedInjury set [1, _impact];
|
|
|
|
(_bandagedWounds getOrDefault [_part, [], true]) pushBack _bandagedInjury;
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
2019-06-22 18:36:27 +00:00
|
|
|
_target setVariable [VAR_BANDAGED_WOUNDS, _bandagedWounds, true];
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2019-04-27 19:12:11 +00:00
|
|
|
// _reopeningChance = 1;
|
|
|
|
// _reopeningMinDelay = 5;
|
|
|
|
// _reopeningMaxDelay = 6;
|
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
TRACE_1("",_reopeningChance);
|
|
|
|
// Check if we are ever going to reopen this
|
2020-06-13 20:52:30 +00:00
|
|
|
if (random 1 <= _reopeningChance * GVAR(woundReopenChance)) then {
|
2016-10-20 11:38:26 +00:00
|
|
|
private _delay = _reopeningMinDelay + random (_reopeningMaxDelay - _reopeningMinDelay);
|
2016-07-15 10:23:47 +00:00
|
|
|
TRACE_1("Will open",_delay);
|
|
|
|
[{
|
|
|
|
params ["_target", "_impact", "_part", "_injuryIndex", "_injury"];
|
2019-04-27 19:12:11 +00:00
|
|
|
TRACE_5("reopen delay finished",_target,_impact,_part,_injuryIndex,_injury);
|
2016-07-15 10:23:47 +00:00
|
|
|
|
2019-06-22 18:36:27 +00:00
|
|
|
private _openWounds = GET_OPEN_WOUNDS(_target);
|
2023-06-24 05:11:56 +00:00
|
|
|
private _woundsOnPart = _openWounds getOrDefault [_part, []];
|
|
|
|
if (count _woundsOnPart - 1 < _injuryIndex) exitWith { TRACE_2("index bounds",_injuryIndex,count _woundsOnPart); };
|
2019-04-27 19:12:11 +00:00
|
|
|
|
2023-06-24 05:11:56 +00:00
|
|
|
_injury params ["_classID"];
|
2016-12-10 15:36:36 +00:00
|
|
|
|
2023-06-24 05:11:56 +00:00
|
|
|
private _selectedInjury = _woundsOnPart select _injuryIndex;
|
|
|
|
_selectedInjury params ["_selClassID", "_selAmmount"];
|
|
|
|
if (_selClassID == _classID) then { // matching the IDs
|
2019-06-22 18:36:27 +00:00
|
|
|
private _bandagedWounds = GET_BANDAGED_WOUNDS(_target);
|
2016-12-10 15:36:36 +00:00
|
|
|
private _exist = false;
|
|
|
|
{
|
2023-06-24 05:11:56 +00:00
|
|
|
_x params ["_id", "_amountOf"];
|
|
|
|
if (_id == _classID) exitWith {
|
2019-05-12 04:13:59 +00:00
|
|
|
TRACE_2("bandagedWound exists",_id,_classID);
|
2023-06-24 05:11:56 +00:00
|
|
|
_x set [1, 0 max (_amountOf - _impact)];
|
2016-12-10 15:36:36 +00:00
|
|
|
_exist = true;
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
2023-06-24 05:11:56 +00:00
|
|
|
} forEach (_bandagedWounds getOrDefault [_part, []]);
|
2016-12-10 15:36:36 +00:00
|
|
|
|
|
|
|
if (_exist) then {
|
|
|
|
TRACE_2("Reopening Wound",_bandagedWounds,_openWounds);
|
2023-06-24 05:11:56 +00:00
|
|
|
_selectedInjury set [1, _selAmmount + _impact];
|
2019-06-22 18:36:27 +00:00
|
|
|
_target setVariable [VAR_BANDAGED_WOUNDS, _bandagedWounds, true];
|
|
|
|
_target setVariable [VAR_OPEN_WOUNDS, _openWounds, true];
|
2019-04-27 19:12:11 +00:00
|
|
|
|
|
|
|
[_target] call EFUNC(medical_status,updateWoundBloodLoss);
|
2019-05-12 04:13:59 +00:00
|
|
|
|
2023-06-24 05:11:56 +00:00
|
|
|
private _partIndex = ALL_BODY_PARTS find _part;
|
|
|
|
|
2021-10-12 08:08:10 +00:00
|
|
|
// Re-add trauma and damage visuals
|
|
|
|
if (GVAR(clearTrauma) == 2) then {
|
|
|
|
private _injuryDamage = (_selectedInjury select 4) * _impact;
|
|
|
|
private _bodyPartDamage = _target getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]];
|
2023-06-24 05:11:56 +00:00
|
|
|
private _newDam = (_bodyPartDamage select _partIndex) + _injuryDamage;
|
|
|
|
_bodyPartDamage set [_partIndex, _newDam];
|
2021-10-12 08:08:10 +00:00
|
|
|
|
|
|
|
_target setVariable [QEGVAR(medical,bodyPartDamage), _bodyPartDamage, true];
|
|
|
|
|
2023-06-24 05:11:56 +00:00
|
|
|
switch (_partIndex) do {
|
2021-10-12 08:08:10 +00:00
|
|
|
case 0: { [_target, true, false, false, false] call EFUNC(medical_engine,updateBodyPartVisuals); };
|
|
|
|
case 1: { [_target, false, true, false, false] call EFUNC(medical_engine,updateBodyPartVisuals); };
|
|
|
|
case 2;
|
|
|
|
case 3: { [_target, false, false, true, false] call EFUNC(medical_engine,updateBodyPartVisuals); };
|
|
|
|
default { [_target, false, false, false, true] call EFUNC(medical_engine,updateBodyPartVisuals); };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-05-12 04:13:59 +00:00
|
|
|
// Check if we gained limping from this wound re-opening
|
2023-06-24 05:11:56 +00:00
|
|
|
if ((EGVAR(medical,limping) == 1) && {_partIndex > 3}) then {
|
2019-05-12 04:13:59 +00:00
|
|
|
[_target] call EFUNC(medical_engine,updateDamageEffects);
|
|
|
|
};
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
2019-04-27 19:12:11 +00:00
|
|
|
} else {
|
2023-06-24 05:11:56 +00:00
|
|
|
TRACE_3("no match",_selectedInjury,_classID,_part);
|
2016-12-10 15:36:36 +00:00
|
|
|
};
|
2016-07-15 10:23:47 +00:00
|
|
|
}, [_target, _impact, _part, _injuryIndex, +_injury], _delay] call CBA_fnc_waitAndExecute;
|
|
|
|
};
|