diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index 9563752d92..5deaf77ceb 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -12,6 +12,7 @@ PREP(actionPlaceInBodyBag); PREP(actionRemoveTourniquet); PREP(actionLoadUnit); PREP(actionUnloadUnit); +PREP(addDamageToUnit); PREP(addHeartRateAdjustment); PREP(addToInjuredCollection); PREP(addToLog); diff --git a/addons/medical/functions/fnc_addDamageToUnit.sqf b/addons/medical/functions/fnc_addDamageToUnit.sqf new file mode 100644 index 0000000000..78d81821e4 --- /dev/null +++ b/addons/medical/functions/fnc_addDamageToUnit.sqf @@ -0,0 +1,63 @@ +/* + * Author: PabstMirror + * Manually Apply Damage to a unit (can cause lethal damage) + * NOTE: because of caching, this will not have instant effects (~3 frame delay) + * + * Arguments: + * 0: The Unit + * 1: Damage to Add + * 2: Selection ("head", "body", "hand_l", "hand_r", "leg_l", "leg_r") + * 3: Projectile Type + * + * Return Value: + * HandleDamage's return + * + * Example: + * [player, 0.8, "leg_r", "bullet"] call ace_medical_fnc_addDamageToUnit + * [cursorTarget, 1, "body", "stab"] call ace_medical_fnc_addDamageToUnit + * + * Public: Yes + */ +#define DEBUG_MODE_FULL +#define DEBUG_TESTRESULTS +#include "script_component.hpp" + +params [["_unit", objNull, [objNull]], ["_damageToAdd", -1, [0]], ["_selection", "", [""]], ["_typeOfDamage", "", [""]]]; +TRACE_4("params",_unit,_damageToAdd,_selection,_typeOfDamage); + +_selection = toLower _selection; +if ((isNull _unit) || {!local _unit} || {!alive _unit}) exitWith {ACE_LOGERROR_1("addDamageToUnit - badUnit %1", _this); -1}; +if (_damageToAdd < 0) exitWith {ACE_LOGERROR_1("addDamageToUnit - bad damage %1", _this); -1}; +if (!(_selection in GVAR(SELECTIONS))) exitWith {ACE_LOGERROR_1("addDamageToUnit - bad selection %1", _this); -1}; + +//Get the hitpoint and the index +private _hitpoint = [_unit, _selection, true] call ace_medical_fnc_translateSelections; +(getAllHitPointsDamage _unit) params [["_allHitPoints", []]]; +private _hitpointIndex = -1; +{ //case insensitive find + if (_x == _hitpoint) exitWith {_hitpointIndex = _forEachIndex;}; +} forEach _allHitPoints; +if (_hitpointIndex < 0) exitWith {ACE_LOGERROR_1("addDamageToUnit - bad hitpointIndex %1", _this); -1}; + +private _currentDamage = _unit getHitIndex _hitpointIndex; + +#ifdef DEBUG_TESTRESULTS +private _checkAtFrame = diag_frameno + 5; +private _partNumber = [_selection] call FUNC(selectionNameToNumber); +private _startDmg = (_unit getVariable [QGVAR(bodyPartStatus), [0,0,0,0,0,0]]) select _partNumber; +private _debugCode = { + params ["", "_unit", "_startDmg", "_damageToAdd", "_partNumber"]; + private _endDmg = (_unit getVariable [QGVAR(bodyPartStatus), [0,0,0,0,0,0]]) select _partNumber; + if ((!alive _unit) || {_endDmg > _startDmg}) then { + ACE_LOGINFO_6("addDamageToUnit - PASSED - [unit:%1, partNo:%2, addDmg:%3] results:[alive:%4 old:%5 new:%6]", _unit, _partNumber, _damageToAdd, alive _unit, _startDmg, _endDmg); + } else { + ACE_LOGERROR_6("addDamageToUnit - FAILED - [unit:%1, partNo:%2, addDmg:%3] results:[alive:%4 old:%5 new:%6]", _unit, _partNumber, _damageToAdd, alive _unit, _startDmg, _endDmg); + }; +}; +[{diag_frameno > (_this select 0)}, _debugCode, [_checkAtFrame, _unit, _startDmg, _damageToAdd, _partNumber]] call EFUNC(common,waitUntilAndExecute); +#endif + +private _return = [_unit, _selection, (_currentDamage + _damageToAdd), _unit, _typeOfDamage, _hitpointIndex] call FUNC(handleDamage); +TRACE_1("handleDamage called",_return); + +_return diff --git a/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf b/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf index e457e023c6..02da9e9564 100644 --- a/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf +++ b/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf @@ -62,7 +62,7 @@ if (_distance < _backblastRange) then { [_damage * 100] call BIS_fnc_bloodEffect; if (isClass (configFile >> "CfgPatches" >> "ACE_Medical") && {([_firer] call EFUNC(medical,hasMedicalEnabled))}) then { - [_firer, "body", ((_firer getvariable [QEGVAR(medical,bodyPartStatus), [0,0,0,0,0,0]]) select 1) + _damage, _firer, "backblast", 0] call EFUNC(medical,handleDamage); + [_firer, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit); } else { _firer setDamage (damage _firer + _damage); }; diff --git a/addons/overpressure/functions/fnc_overpressureDamage.sqf b/addons/overpressure/functions/fnc_overpressureDamage.sqf index f9c58050e0..b1c8a5c574 100644 --- a/addons/overpressure/functions/fnc_overpressureDamage.sqf +++ b/addons/overpressure/functions/fnc_overpressureDamage.sqf @@ -56,7 +56,7 @@ TRACE_4("Parameters:",_overpressureAngle,_overpressureRange,_overpressureDamage, if (_x == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect}; if (isClass (configFile >> "CfgPatches" >> "ACE_Medical") && {([_x] call EFUNC(medical,hasMedicalEnabled))}) then { - [_x, "body", ((_x getvariable [QEGVAR(medical,bodyPartStatus), [0,0,0,0,0,0]]) select 1) + _damage, _firer, "backblast", 0] call EFUNC(medical,handleDamage); + [_x, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit); } else { _x setDamage (damage _x + _damage); };