Medical - Fix addDamageToUnit (#7247)

This commit is contained in:
PabstMirror 2019-10-20 16:48:26 -05:00 committed by GitHub
parent c37783de0b
commit f9d181c72e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 12 deletions

View File

@ -2,7 +2,6 @@
/* /*
* Author: PabstMirror * Author: PabstMirror
* Manually Apply Damage to a unit (can cause lethal damage) * Manually Apply Damage to a unit (can cause lethal damage)
* NOTE: because of caching, this will not have instant effects (~3 frame delay)
* *
* Arguments: * Arguments:
* 0: The Unit <OBJECT> * 0: The Unit <OBJECT>
@ -10,6 +9,7 @@
* 2: Body part ("Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg") <STRING> * 2: Body part ("Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg") <STRING>
* 3: Projectile Type <STRING> * 3: Projectile Type <STRING>
* 4: Source <OBJECT> * 4: Source <OBJECT>
* 5: Non-directional damage source array (Optional) <ARRAY>
* *
* Return Value: * Return Value:
* Successful <BOOL> * Successful <BOOL>
@ -22,12 +22,12 @@
*/ */
// #define DEBUG_TESTRESULTS // #define DEBUG_TESTRESULTS
params [["_unit", objNull, [objNull]], ["_damageToAdd", -1, [0]], ["_bodyPart", "", [""]], ["_typeOfDamage", "", [""]], ["_instigator", objNull, [objNull]]]; params [["_unit", objNull, [objNull]], ["_damageToAdd", -1, [0]], ["_bodyPart", "", [""]], ["_typeOfDamage", "", [""]], ["_instigator", objNull, [objNull]], ["_damageSelectionArray", [], [[]]]];
TRACE_5("addDamageToUnit",_unit,_damageToAdd,_bodyPart,_typeOfDamage,_instigator); TRACE_6("addDamageToUnit",_unit,_damageToAdd,_bodyPart,_typeOfDamage,_instigator,_damageSelectionArray);
_bodyPart = toLower _bodyPart; _bodyPart = toLower _bodyPart;
private _bodyPartIndex = ALL_BODY_PARTS find _bodyPart; private _bodyPartIndex = ALL_BODY_PARTS find _bodyPart;
if (_bodyPartIndex < 0) then { _bodyPartIndex = ALL_SELECTIONS find _bodyPart; }; // 2nd attempt with selection names ("hand_l", "hand_r", "leg_l", "leg_r") if (_bodyPartIndex < 0) then { _bodyPartIndex = ALL_SELECTIONS find _bodyPart; }; // 2nd attempt with selection names ("hand_l", "hand_r", "leg_l", "leg_r")
if (_bodyPartIndex < 0) exitWith {ERROR_1("addDamageToUnit - bad selection %1", _this); false}; if (_bodyPartIndex < 0) exitWith {ERROR_1("addDamageToUnit - bad selection %1", _this); false};
if (isNull _unit || {!local _unit} || {!alive _unit}) exitWith {ERROR_2("addDamageToUnit - badUnit %1 [local %2]", _this, local _unit); false}; if (isNull _unit || {!local _unit} || {!alive _unit}) exitWith {ERROR_2("addDamageToUnit - badUnit %1 [local %2]", _this, local _unit); false};
if (_damageToAdd < 0) exitWith {ERROR_1("addDamageToUnit - bad damage %1", _this); false}; if (_damageToAdd < 0) exitWith {ERROR_1("addDamageToUnit - bad damage %1", _this); false};
@ -35,20 +35,24 @@ if (_damageToAdd < 0) exitWith {ERROR_1("addDamageToUnit - bad damage %1", _this
// Extension is case sensitive and expects this format (different from ALL_BODY_PARTS) // Extension is case sensitive and expects this format (different from ALL_BODY_PARTS)
_bodyPart = ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"] select _bodyPartIndex; _bodyPart = ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"] select _bodyPartIndex;
if (_damageSelectionArray isEqualTo []) then { // this will only be used if damage type is not location specific
_damageSelectionArray = [HITPOINT_INDEX_HEAD, 1, HITPOINT_INDEX_BODY, 1, HITPOINT_INDEX_LARM, 1, HITPOINT_INDEX_RARM, 1, HITPOINT_INDEX_LLEG, 1, HITPOINT_INDEX_RLEG, 1];
};
if (!isNull _instigator) then { if (!isNull _instigator) then {
_unit setVariable [QEGVAR(medical,lastDamageSource), _instigator]; _unit setVariable [QEGVAR(medical,lastDamageSource), _instigator];
_unit setVariable [QEGVAR(medical,lastInstigator), _instigator]; _unit setVariable [QEGVAR(medical,lastInstigator), _instigator];
}; };
#ifdef DEBUG_TESTRESULTS #ifdef DEBUG_TESTRESULTS
private _startDmg = +(_unit getVariable [QEGVAR(medical,bodyPartDamage), [-1]]); private _startDmg = +(_unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]]);
private _startPain = GET_PAIN(_unit); private _startPain = GET_PAIN(_unit);
#endif #endif
[QEGVAR(medical,woundReceived), [_unit, _bodyPart, _damageToAdd, _instigator, _typeOfDamage]] call CBA_fnc_localEvent; [QEGVAR(medical,woundReceived), [_unit, _bodyPart, _damageToAdd, _instigator, _typeOfDamage, _damageSelectionArray]] call CBA_fnc_localEvent;
#ifdef DEBUG_TESTRESULTS #ifdef DEBUG_TESTRESULTS
private _endDmg = _unit getVariable [QEGVAR(medical,bodyPartDamage), [-1]]; private _endDmg = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]];
private _endPain = GET_PAIN(_unit); private _endPain = GET_PAIN(_unit);
private _typeOfDamageAdj = _typeOfDamage call EFUNC(medical_damage,getTypeOfDamage); private _typeOfDamageAdj = _typeOfDamage call EFUNC(medical_damage,getTypeOfDamage);
private _config = configFile >> "ACE_Medical_Injuries" >> "damageTypes" >> _typeOfDamageAdj; private _config = configFile >> "ACE_Medical_Injuries" >> "damageTypes" >> _typeOfDamageAdj;

View File

@ -118,10 +118,10 @@ if (_hitPoint isEqualTo "ace_hdbracket") exitWith {
*/ */
if (_shooter == _unit && {(velocity _unit select 2) < -2}) then { if (_shooter == _unit && {(velocity _unit select 2) < -2}) then {
_ammo = "#falling"; // non-selectionSpecific so only _damageSelectionArray matters _ammo = "#falling"; // non-selectionSpecific so only _damageSelectionArray matters
_damageSelectionArray = [4, 1, 5, 1]; // selectRandom ["RightLeg", "LeftLeg"]; _damageSelectionArray = [HITPOINT_INDEX_RLEG, 1, HITPOINT_INDEX_LLEG, 1];
TRACE_5("Fall",_unit,_shooter,_instigator,_damage,_receivedDamage); TRACE_5("Fall",_unit,_shooter,_instigator,_damage,_receivedDamage);
} else { } else {
_damageSelectionArray = [2, 1, 3, 1, 4, 1, 5, 1]; // selectRandom ["RightArm", "LeftArm", "RightLeg", "LeftLeg"]; _damageSelectionArray = [HITPOINT_INDEX_RARM, 1, HITPOINT_INDEX_LARM, 1, HITPOINT_INDEX_LLEG, 1, HITPOINT_INDEX_RLEG, 1];
TRACE_5("Collision",_unit,_shooter,_instigator,_damage,_receivedDamage); TRACE_5("Collision",_unit,_shooter,_instigator,_damage,_receivedDamage);
}; };
@ -138,7 +138,7 @@ if (_hitPoint isEqualTo "ace_hdbracket") exitWith {
}; };
} else { } else {
// Anything else is almost guaranteed to be fire damage // Anything else is almost guaranteed to be fire damage
_damageSelectionArray = [1, 1, 4, 1, 5, 1]; // selectRandom ["Body", "LeftLeg", "RightLeg"]; _damageSelectionArray = [HITPOINT_INDEX_BODY, 1, HITPOINT_INDEX_LLEG, 1, HITPOINT_INDEX_RLEG, 1];;
_ammo = "#unknown"; // non-selectionSpecific so only _damageSelectionArray matters _ammo = "#unknown"; // non-selectionSpecific so only _damageSelectionArray matters
// Fire damage can occur as lots of minor damage events // Fire damage can occur as lots of minor damage events

View File

@ -52,7 +52,7 @@ if (_distance < _backblastRange) then {
[_damage * 100] call BIS_fnc_bloodEffect; [_damage * 100] call BIS_fnc_bloodEffect;
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then {
[_unit, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit); [_unit, _damage, "body", "backblast", _unit] call EFUNC(medical,addDamageToUnit);
} else { } else {
TRACE_1("",isDamageAllowed _unit); TRACE_1("",isDamageAllowed _unit);
if (!isDamageAllowed _unit) exitWith {}; // Skip damage if not allowed if (!isDamageAllowed _unit) exitWith {}; // Skip damage if not allowed

View File

@ -57,7 +57,7 @@ TRACE_3("cache",_overpressureAngle,_overpressureRange,_overpressureDamage);
if (_x == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect}; if (_x == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect};
if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then {
[_x, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit); [_x, _damage, "body", "backblast", _firer] call EFUNC(medical,addDamageToUnit);
} else { } else {
TRACE_1("",isDamageAllowed _x); TRACE_1("",isDamageAllowed _x);
if (!isDamageAllowed _x) exitWith {}; // Skip damage if not allowed if (!isDamageAllowed _x) exitWith {}; // Skip damage if not allowed