ACE3/addons/medical/functions/fnc_addDamageToUnit.sqf

64 lines
2.9 KiB
Plaintext
Raw Normal View History

2015-11-26 15:53:12 +00:00
/*
* 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 <OBJECT>
* 1: Damage to Add <NUMBER>
* 2: Body part ("Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg") <STRING>
2015-11-26 15:53:12 +00:00
* 3: Projectile Type <STRING>
*
* Return Value:
* HandleDamage's return <NUMBER>
*
* Example:
* [player, 0.8, "rightleg", "bullet"] call ace_medical_fnc_addDamageToUnit
2015-11-26 15:53:12 +00:00
* [cursorTarget, 1, "body", "stab"] call ace_medical_fnc_addDamageToUnit
*
* Public: Yes
*/
// #define DEBUG_MODE_FULL
// #define DEBUG_TESTRESULTS
2015-11-26 15:53:12 +00:00
#include "script_component.hpp"
params [["_unit", objNull, [objNull]], ["_damageToAdd", -1, [0]], ["_bodyPart", "", [""]], ["_typeOfDamage", "", [""]]];
TRACE_4("params",_unit,_damageToAdd,_bodyPart,_typeOfDamage);
2015-11-26 15:53:12 +00:00
_bodyPart = toLower _bodyPart;
if (isNull _unit || {!local _unit} || {!alive _unit}) exitWith {ERROR_1("addDamageToUnit - badUnit %1", _this); -1};
2016-08-22 19:06:52 +00:00
if (_damageToAdd < 0) exitWith {ERROR_1("addDamageToUnit - bad damage %1", _this); -1};
if !(_bodyPart in ALL_BODY_PARTS) exitWith {ERROR_1("addDamageToUnit - bad selection %1", _this); -1};
2015-11-26 15:53:12 +00:00
//Get the hitpoint and the index
private _hitpoint = [_unit, _bodyPart, true] call ace_medical_fnc_translateSelections;
2015-11-26 15:53:12 +00:00
(getAllHitPointsDamage _unit) params [["_allHitPoints", []]];
private _hitpointIndex = -1;
{ //case insensitive find
if (_x == _hitpoint) exitWith {_hitpointIndex = _forEachIndex;};
} forEach _allHitPoints;
2016-08-22 19:06:52 +00:00
if (_hitpointIndex < 0) exitWith {ERROR_1("addDamageToUnit - bad hitpointIndex %1", _this); -1};
2015-11-26 15:53:12 +00:00
private _currentDamage = _unit getHitIndex _hitpointIndex;
#ifdef DEBUG_TESTRESULTS
private _checkAtFrame = diag_frameno + 5;
private _partNumber = ALL_BODY_PARTS find _bodyPart;
2015-11-26 15:53:12 +00:00
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 {
2016-08-22 19:06:52 +00:00
INFO_6("addDamageToUnit - PASSED - [unit:%1, partNo:%2, addDmg:%3] results:[alive:%4 old:%5 new:%6]", _unit, _partNumber, _damageToAdd, alive _unit, _startDmg, _endDmg);
2015-11-26 15:53:12 +00:00
} else {
2016-08-22 19:06:52 +00:00
ERROR_6("addDamageToUnit - FAILED - [unit:%1, partNo:%2, addDmg:%3] results:[alive:%4 old:%5 new:%6]", _unit, _partNumber, _damageToAdd, alive _unit, _startDmg, _endDmg);
2015-11-26 15:53:12 +00:00
};
};
[{diag_frameno > (_this select 0)}, _debugCode, [_checkAtFrame, _unit, _startDmg, _damageToAdd, _partNumber]] call CBA_fnc_waitUntilAndExecute;
2015-11-26 15:53:12 +00:00
#endif
2016-12-10 03:27:42 +00:00
private _return = [_unit, _bodyPart, (_currentDamage + _damageToAdd), _unit, _typeOfDamage, _hitpointIndex, objNull] call FUNC(handleDamage); // todo - switch to medical engine
2015-11-26 15:53:12 +00:00
TRACE_1("handleDamage called",_return);
_return