2016-07-15 10:23:47 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
|
|
|
* Handles the bandage of a patient.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: The patient <OBJECT>
|
2016-10-07 02:21:01 +00:00
|
|
|
* 1: Treatment class name <STRING>
|
2016-10-05 22:54:57 +00:00
|
|
|
* 2: Body part <STRING>
|
2016-07-15 10:23:47 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Succesful treatment started <BOOL>
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2016-10-05 22:54:57 +00:00
|
|
|
params ["_target", "_bandage", "_bodyPart", ["_specificClass", -1]];
|
2016-07-15 10:23:47 +00:00
|
|
|
|
|
|
|
// Ensure it is a valid bodypart
|
2016-10-05 22:54:57 +00:00
|
|
|
private _partIndex = ALL_BODY_PARTS find toLower _bodyPart;
|
|
|
|
if (_partIndex < 0) exitWith {false};
|
2016-07-15 10:23:47 +00:00
|
|
|
|
|
|
|
// Get the open wounds for this unit
|
|
|
|
private _openWounds = _target getVariable [QEGVAR(medical,openWounds), []];
|
|
|
|
if (count _openWounds == 0) exitWith {false}; // nothing to do here!
|
|
|
|
|
|
|
|
// Get the default effectiveness for the used bandage
|
2016-10-05 22:54:57 +00:00
|
|
|
private _config = configFile >> "ace_medical_treatment" >> "Bandaging";
|
2016-07-15 10:23:47 +00:00
|
|
|
private _effectiveness = getNumber (_config >> "effectiveness");
|
2016-10-05 22:54:57 +00:00
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
if (isClass (_config >> _bandage)) then {
|
|
|
|
_config = (_config >> _bandage);
|
2016-10-05 22:54:57 +00:00
|
|
|
|
|
|
|
if (isNumber (_config >> "effectiveness")) then {
|
|
|
|
_effectiveness = getNumber (_config >> "effectiveness");
|
|
|
|
};
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Figure out which injury for this bodypart is the best choice to bandage
|
|
|
|
// TODO also use up the remainder on left over injuries
|
|
|
|
private _mostEffectiveSpot = 0;
|
|
|
|
private _effectivenessFound = -1;
|
|
|
|
private _mostEffectiveInjury = _openWounds select 0;
|
|
|
|
private _exit = false;
|
2016-10-05 22:54:57 +00:00
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
{
|
2016-10-05 22:54:57 +00:00
|
|
|
_x params ["", "_classID", "_partIndexN"];
|
2016-07-15 10:23:47 +00:00
|
|
|
TRACE_2("OPENWOUND: ", _target, _x);
|
2016-10-05 22:54:57 +00:00
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
// Only parse injuries that are for the selected bodypart.
|
2016-10-05 22:54:57 +00:00
|
|
|
if (_partIndexN == _partIndex) then {
|
2016-07-15 10:23:47 +00:00
|
|
|
private _woundEffectiveness = _effectiveness;
|
|
|
|
|
|
|
|
// Select the classname from the wound classname storage
|
2016-09-27 09:05:38 +00:00
|
|
|
private _className = EGVAR(medical_damage,woundClassNames) select _classID;
|
2016-07-15 10:23:47 +00:00
|
|
|
|
|
|
|
// 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
|
2016-10-05 22:54:57 +00:00
|
|
|
private _woundTreatmentConfig = _config >> _className;
|
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
if (isNumber (_woundTreatmentConfig >> "effectiveness")) then {
|
|
|
|
_woundEffectiveness = getNumber (_woundTreatmentConfig >> "effectiveness");
|
|
|
|
};
|
|
|
|
} else {
|
2016-08-03 18:14:12 +00:00
|
|
|
//Basic medical bandage just has a base level config (same effectivenes for all wound types)
|
2016-10-13 00:05:14 +00:00
|
|
|
if (_bandage != "BasicBandage") then {
|
2016-08-22 19:06:52 +00:00
|
|
|
WARNING_2("No config for wound type [%1] config base [%2]", _className, _config);
|
2016-08-03 18:14:12 +00:00
|
|
|
};
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TRACE_2("Wound classes: ", _specificClass, _classID);
|
|
|
|
if (_specificClass == _classID) exitWith {
|
|
|
|
_effectivenessFound = _woundEffectiveness;
|
|
|
|
_mostEffectiveSpot = _forEachIndex;
|
|
|
|
_mostEffectiveInjury = _x;
|
|
|
|
_exit = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check if this is the currently most effective found.
|
|
|
|
if (_woundEffectiveness * ((_x select 4) * (_x select 3)) > _effectivenessFound * ((_mostEffectiveInjury select 4) * (_mostEffectiveInjury select 3))) then {
|
|
|
|
_effectivenessFound = _woundEffectiveness;
|
|
|
|
_mostEffectiveSpot = _forEachIndex;
|
|
|
|
_mostEffectiveInjury = _x;
|
|
|
|
};
|
|
|
|
};
|
2016-10-05 22:54:57 +00:00
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
if (_exit) exitWith {};
|
|
|
|
} forEach _openWounds;
|
|
|
|
|
|
|
|
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
|
2016-10-05 22:54:57 +00:00
|
|
|
private _impact = if (_mostEffectiveInjury select 3 >= _effectivenessFound) then {_effectivenessFound} else { _mostEffectiveInjury select 3 };
|
|
|
|
_mostEffectiveInjury set [3, ((_mostEffectiveInjury select 3) - _impact) max 0];
|
2016-07-15 10:23:47 +00:00
|
|
|
_openWounds set [_mostEffectiveSpot, _mostEffectiveInjury];
|
|
|
|
|
|
|
|
_target setVariable [QEGVAR(medical,openWounds), _openWounds, true];
|
|
|
|
|
2016-10-07 02:21:01 +00:00
|
|
|
[_target, _bodyPart] call EFUNC(medical_engine,updateBodyPartVisuals);
|
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
// Handle the reopening of bandaged wounds
|
|
|
|
if (_impact > 0 && {EGVAR(medical,level) >= 2} && {EGVAR(medical,enableAdvancedWounds)}) then {
|
2016-10-05 22:54:57 +00:00
|
|
|
[_target, _impact, _partIndex, _mostEffectiveSpot, _mostEffectiveInjury, _bandage] call FUNC(handleBandageOpening);
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// If all wounds to a body part have been bandaged, reset damage to that body part to zero
|
|
|
|
// so that the body part functions normally and blood is removed from the uniform.
|
|
|
|
// Arma combines left and right arms into a single body part (HitHands), same with left and right legs (HitLegs).
|
|
|
|
// Arms are actually hands.
|
|
|
|
if (EGVAR(medical,healHitPointAfterAdvBandage) || {EGVAR(medical,level) < 2}) then {
|
|
|
|
// Get the list of the wounds the target is currently suffering from.
|
|
|
|
private _currentWounds = _target getVariable [QEGVAR(medical,openWounds), []];
|
|
|
|
|
|
|
|
// Tally of unbandaged wounds to each body part.
|
|
|
|
private _headWounds = 0;
|
|
|
|
private _bodyWounds = 0;
|
2016-08-07 18:58:09 +00:00
|
|
|
private _leftArmWounds = 0;
|
|
|
|
private _leftLegWounds = 0;
|
|
|
|
private _rightArmWounds = 0;
|
|
|
|
private _rightLegWounds = 0;
|
2016-07-15 10:23:47 +00:00
|
|
|
|
|
|
|
// Loop through all current wounds and add up the number of unbandaged wounds on each body part.
|
|
|
|
{
|
2016-10-05 22:54:57 +00:00
|
|
|
_x params ["", "", "_partIndex", "_numOpenWounds", "_bloodLoss"];
|
2016-07-15 10:23:47 +00:00
|
|
|
|
|
|
|
// Use switch/case for early termination if wounded limb is found before all six are checked.
|
|
|
|
// Number of wounds multiplied by blood loss will return zero for a fully
|
|
|
|
// bandaged body part, not incrementing the wound counter; or it will return
|
|
|
|
// some other number which will increment the wound counter.
|
2016-10-05 22:54:57 +00:00
|
|
|
switch (_partIndex) do {
|
2016-07-15 10:23:47 +00:00
|
|
|
// Head
|
|
|
|
case 0: {
|
|
|
|
_headWounds = _headWounds + (_numOpenWounds * _bloodLoss);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Body
|
|
|
|
case 1: {
|
|
|
|
_bodyWounds = _bodyWounds + (_numOpenWounds * _bloodLoss);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Left Arm
|
|
|
|
case 2: {
|
2016-08-07 18:58:09 +00:00
|
|
|
_leftArmWounds = _leftArmWounds + (_numOpenWounds * _bloodLoss);
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Right Arm
|
|
|
|
case 3: {
|
2016-08-07 18:58:09 +00:00
|
|
|
_rightArmWounds = _rightArmWounds + (_numOpenWounds * _bloodLoss);
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Left Leg
|
|
|
|
case 4: {
|
2016-08-07 18:58:09 +00:00
|
|
|
_leftLegWounds = _leftLegWounds + (_numOpenWounds * _bloodLoss);
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Right Leg
|
|
|
|
case 5: {
|
2016-08-07 18:58:09 +00:00
|
|
|
_rightLegWounds = _rightLegWounds + (_numOpenWounds * _bloodLoss);
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach _currentWounds;
|
|
|
|
|
2016-10-05 22:54:57 +00:00
|
|
|
// ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"]
|
2016-08-09 17:14:30 +00:00
|
|
|
private _bodyStatus = _target getVariable [QEGVAR(medical,bodyPartStatus), [0,0,0,0,0,0]];
|
2016-08-07 18:58:09 +00:00
|
|
|
|
2016-07-15 10:23:47 +00:00
|
|
|
// Any body part that has no wounds is healed to full health
|
|
|
|
if (_headWounds == 0) then {
|
2016-08-07 18:58:09 +00:00
|
|
|
_bodyStatus set [0, 0];
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
if (_bodyWounds == 0) then {
|
2016-08-07 18:58:09 +00:00
|
|
|
_bodyStatus set [1, 0];
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
2016-08-07 18:58:09 +00:00
|
|
|
if (_leftArmWounds == 0) then {
|
|
|
|
_bodyStatus set [2, 0];
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
2016-08-07 18:58:09 +00:00
|
|
|
if (_rightArmWounds == 0) then {
|
|
|
|
_bodyStatus set [3, 0];
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
2016-08-07 18:58:09 +00:00
|
|
|
if (_leftLegWounds == 0) then {
|
|
|
|
_bodyStatus set [4, 0];
|
|
|
|
};
|
|
|
|
if (_rightLegWounds == 0) then {
|
|
|
|
_bodyStatus set [5, 0];
|
|
|
|
};
|
|
|
|
|
2016-08-09 17:14:30 +00:00
|
|
|
_target setVariable [QEGVAR(medical,bodyPartStatus), _bodyStatus, true];
|
2016-08-07 18:58:09 +00:00
|
|
|
|
2016-10-07 02:21:01 +00:00
|
|
|
//[_target] call EFUNC(medical_damage,setDamage);
|
2016-07-15 10:23:47 +00:00
|
|
|
};
|
|
|
|
|
2016-10-05 22:54:57 +00:00
|
|
|
true
|