ACE3/addons/medical/functions/fnc_treatmentAdvanced_bandageLocal.sqf

106 lines
4.4 KiB
Plaintext
Raw Normal View History

/*
* Author: Glowbal
* Handles the bandage of a patient.
*
* Arguments:
* 0: The patient <OBJECT>
* 1: Treatment classname <STRING>
*
*
* Return Value:
* Succesful treatment started <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
2015-08-22 17:47:23 +00:00
private ["_openWounds", "_config", "_effectiveness","_mostEffectiveInjury", "_mostEffectiveSpot", "_woundEffectivenss", "_mostEffectiveInjury", "_impact", "_exit", "_classID", "_effectivenessFound", "_className", "_hitPoints", "_hitSelections", "_point", "_woundTreatmentConfig"];
params ["_target", "_bandage", "_selectionName", ["_specificClass", -1]];
// Ensure it is a valid bodypart
_part = [_selectionName] call FUNC(selectionNameToNumber);
2015-08-22 17:47:23 +00:00
if (_part < 0) exitwith {false};
// Get the open wounds for this unit
_openWounds = _target getvariable [QGVAR(openWounds), []];
2015-08-22 17:47:23 +00:00
if (count _openWounds == 0) exitwith {false}; // nothing to do here!
// Get the default effectiveness for the used bandage
_config = (ConfigFile >> "ACE_Medical_Advanced" >> "Treatment" >> "Bandaging");
_effectiveness = getNumber (_config >> "effectiveness");
if (isClass (_config >> _bandage)) then {
_config = (_config >> _bandage);
if (isNumber (_config >> "effectiveness")) then { _effectiveness = getNumber (_config >> "effectiveness");};
};
// Figure out which injury for this bodypart is the best choice to bandage
_mostEffectiveSpot = 0;
2015-03-09 21:23:37 +00:00
_effectivenessFound = -1;
_mostEffectiveInjury = _openWounds select 0;
_exit = false;
{
2015-08-26 08:04:51 +00:00
_x params ["", "_classID", "_partX"];
2015-09-05 10:59:09 +00:00
TRACE_2("OPENWOUND: ", _target, _x);
// Only parse injuries that are for the selected bodypart.
2015-08-22 17:47:23 +00:00
if (_partX == _part) then {
_woundEffectivenss = _effectiveness;
2015-03-03 22:26:54 +00:00
// Select the classname from the wound classname storage
_className = GVAR(woundClassNames) select _classID;
// Check if this wound type has attributes specified for the used bandage
if (isClass (_config >> _className)) then {
// Collect the effectiveness from the used bandage for this wound type
2015-03-03 22:26:54 +00:00
_woundTreatmentConfig = (_config >> _className);
if (isNumber (_woundTreatmentConfig >> "effectiveness")) then {
_woundEffectivenss = getNumber (_woundTreatmentConfig >> "effectiveness");
};
};
2015-09-05 10:59:09 +00:00
TRACE_2("Wound classes: ", _specificClass, _classID);
if (_specificClass == _classID) exitwith {
_effectivenessFound = _woundEffectivenss;
_mostEffectiveSpot = _foreachIndex;
_mostEffectiveInjury = _x;
_exit = true;
};
// Check if this is the currently most effective found.
if (_woundEffectivenss * ((_x select 4) * (_x select 3)) > _effectivenessFound * ((_mostEffectiveInjury select 4) * (_mostEffectiveInjury select 3))) then {
_effectivenessFound = _woundEffectivenss;
_mostEffectiveSpot = _foreachIndex;
_mostEffectiveInjury = _x;
};
};
if (_exit) exitwith {};
2015-08-22 17:47:23 +00:00
} foreach _openWounds;
2015-03-09 21:23:37 +00:00
if (_effectivenessFound == -1) exitwith {}; // Seems everything is patched up on this body part already..
// TODO refactor this part
// Find the impact this bandage has and reduce the amount this injury is present
_impact = if ((_mostEffectiveInjury select 3) >= _effectivenessFound) then {_effectivenessFound} else { (_mostEffectiveInjury select 3) };
_mostEffectiveInjury set [ 3, ((_mostEffectiveInjury select 3) - _impact) max 0];
_openWounds set [_mostEffectiveSpot, _mostEffectiveInjury];
_target setvariable [QGVAR(openWounds), _openWounds, !USE_WOUND_EVENT_SYNC];
if (USE_WOUND_EVENT_SYNC) then {
["medical_propagateWound", [_target, _mostEffectiveInjury]] call EFUNC(common,globalEvent);
};
// Handle the reopening of bandaged wounds
if (_impact > 0 && {GVAR(enableAdvancedWounds)}) then {
2015-04-20 20:00:11 +00:00
[_target, _impact, _part, _mostEffectiveSpot, _mostEffectiveInjury, _bandage] call FUNC(handleBandageOpening);
};
// If all wounds have been bandaged, we will reset all damage to 0, so the unit is not showing any blood on the model anymore.
2015-08-29 20:51:42 +00:00
if (GVAR(healHitPointAfterAdvBandage) && {{(_x select 2) == _part && {((_x select 4) * (_x select 3)) > 0}}count _openWounds == 0}) then {
_hitSelections = ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"];
_hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"];
_point = _hitPoints select (_hitSelections find _selectionName);
2015-08-29 20:44:52 +00:00
_target setHitPointDamage [_point, 0];
};
true;