2017-06-08 13:31:51 +00:00
|
|
|
/*
|
2015-09-02 18:13:51 +00:00
|
|
|
* Author: KoffeinFlummi, Glowbal, commy2
|
2015-02-03 19:09:25 +00:00
|
|
|
* Main HandleDamage EH function.
|
2015-01-18 21:16:35 +00:00
|
|
|
*
|
2015-02-03 19:09:25 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: Unit That Was Hit <OBJECT>
|
|
|
|
* 1: Name Of Hit Selection <STRING>
|
|
|
|
* 2: Amount Of Damage <NUMBER>
|
|
|
|
* 3: Shooter <OBJECT>
|
2017-06-08 13:31:51 +00:00
|
|
|
* 4: Projectile <OBJECT, STRING>
|
2015-11-21 17:11:13 +00:00
|
|
|
* 5: HitPointIndex (-1 for structural) <NUMBER>
|
2016-09-05 20:27:00 +00:00
|
|
|
* 6: Shooter <OBJECT>
|
2015-02-03 19:09:25 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Damage To Be Inflicted <NUMBER>
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [bob, "leg", 2, kevin, "bullet", -1, kevin] call ACE_medical_fnc_handleDamage
|
|
|
|
*
|
2015-02-03 19:09:25 +00:00
|
|
|
* Public: No
|
2015-01-18 21:16:35 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2017-02-02 19:03:13 +00:00
|
|
|
_this = _this select [0, 7];
|
2015-11-04 20:36:26 +00:00
|
|
|
params ["_unit", "_selection", "_damage", "_shooter", "_projectile", "_hitPointIndex"];
|
2015-09-04 14:46:35 +00:00
|
|
|
TRACE_5("ACE_DEBUG: HandleDamage Called",_unit, _selection, _damage, _shooter, _projectile);
|
2015-01-20 17:57:33 +00:00
|
|
|
|
2015-09-02 18:13:51 +00:00
|
|
|
// bug, apparently can fire for remote units in special cases
|
|
|
|
if !(local _unit) exitWith {
|
2015-09-04 14:46:35 +00:00
|
|
|
TRACE_2("ACE_DEBUG: HandleDamage on remote unit!",_unit, isServer);
|
2015-09-02 18:13:51 +00:00
|
|
|
nil
|
|
|
|
};
|
|
|
|
|
|
|
|
// bug, assumed fixed, @todo excessive testing, if nothing happens remove
|
2015-11-20 17:40:31 +00:00
|
|
|
if (_projectile isEqualType objNull) then {
|
2015-02-06 12:47:17 +00:00
|
|
|
_projectile = typeOf _projectile;
|
|
|
|
_this set [4, _projectile];
|
2015-09-05 09:25:56 +00:00
|
|
|
};
|
2015-01-18 21:16:35 +00:00
|
|
|
|
2015-09-06 09:49:08 +00:00
|
|
|
TRACE_3("ACE_DEBUG: HandleDamage",_selection,_damage,_unit);
|
2015-09-02 18:13:51 +00:00
|
|
|
|
2015-09-02 18:49:17 +00:00
|
|
|
// If damage is in dummy hitpoints, "hands" and "legs", don't change anything
|
|
|
|
if (_selection == "hands") exitWith {_unit getHit "hands"};
|
|
|
|
if (_selection == "legs") exitWith {_unit getHit "legs"};
|
2015-11-21 17:11:13 +00:00
|
|
|
if (_selection == "arms") exitWith {_unit getHit "arms"};
|
2015-09-02 18:49:17 +00:00
|
|
|
|
2015-11-01 15:35:25 +00:00
|
|
|
// Deal with the new hitpoint and selection names introduced with Arma v1.50 and later.
|
|
|
|
// This will convert new selection names into selection names that the medical system understands
|
|
|
|
// TODO This should be cleaned up when we revisit the medical system at a later stage
|
|
|
|
// and instead we should deal with the new hitpoints directly
|
2015-11-04 20:36:26 +00:00
|
|
|
_selection = [_unit, _selection, _hitPointIndex] call FUNC(translateSelections);
|
2015-11-01 15:35:25 +00:00
|
|
|
_this set [1, _selection]; // ensure that the parameters are set correctly
|
|
|
|
|
2015-11-21 17:11:13 +00:00
|
|
|
// If the damage is being weird, we just tell it to fuck off. Ignore: "hands", "legs", "arms"
|
|
|
|
if (_selection != "" && {!(_selection in GVAR(SELECTIONS))}) exitWith {0};
|
2015-02-06 12:47:17 +00:00
|
|
|
|
2015-04-30 23:38:36 +00:00
|
|
|
// Exit if we disable damage temporarily
|
2015-08-26 08:04:51 +00:00
|
|
|
if !(_unit getVariable [QGVAR(allowDamage), true]) exitWith {
|
2015-09-06 09:49:08 +00:00
|
|
|
TRACE_3("ACE_DEBUG: HandleDamage damage disabled.",_selection,damage _unit,_unit);
|
2015-09-02 18:13:51 +00:00
|
|
|
if (_selection == "") then {
|
2015-08-29 13:29:02 +00:00
|
|
|
damage _unit
|
2015-09-02 18:13:51 +00:00
|
|
|
} else {
|
|
|
|
_unit getHit _selection
|
2015-08-26 08:04:51 +00:00
|
|
|
};
|
2015-04-30 23:38:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Get return damage
|
2016-06-13 09:05:21 +00:00
|
|
|
private _damageReturn = _damage;
|
2015-08-11 18:58:00 +00:00
|
|
|
|
2016-06-13 09:05:21 +00:00
|
|
|
private _newDamage = _this call FUNC(handleDamage_caching);
|
2015-08-26 08:04:51 +00:00
|
|
|
// handleDamage_caching may have modified the projectile string
|
2016-06-13 09:05:21 +00:00
|
|
|
private _typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
|
2015-08-11 18:58:00 +00:00
|
|
|
|
2015-09-06 09:49:08 +00:00
|
|
|
TRACE_3("ACE_DEBUG: HandleDamage caching new damage",_selection,_newDamage,_unit);
|
|
|
|
|
2016-06-13 09:05:21 +00:00
|
|
|
private _typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
|
|
|
|
private _minLethalDamage = if (_typeIndex >= 0) then {
|
2015-08-29 13:29:02 +00:00
|
|
|
GVAR(minLethalDamages) select _typeIndex
|
|
|
|
} else {
|
|
|
|
0.01
|
2015-08-26 08:04:51 +00:00
|
|
|
};
|
2015-02-13 21:55:13 +00:00
|
|
|
|
2016-02-26 21:58:49 +00:00
|
|
|
if (!isNull _shooter) then {
|
|
|
|
_unit setvariable [QGVAR(lastDamageSource), _shooter, false];
|
|
|
|
};
|
|
|
|
|
2016-02-15 23:11:04 +00:00
|
|
|
private _vehicle = vehicle _unit;
|
2016-02-16 04:23:04 +00:00
|
|
|
private _effectiveSelectionName = _selection;
|
2016-02-15 23:11:04 +00:00
|
|
|
if ((_vehicle != _unit) && {!(_vehicle isKindOf "StaticWeapon")} && {_shooter in [objNull, driver _vehicle, _vehicle]} && {_projectile == ""} && {_selection == ""}) then {
|
2015-08-26 08:04:51 +00:00
|
|
|
if (GVAR(enableVehicleCrashes)) then {
|
2016-02-16 04:23:04 +00:00
|
|
|
_effectiveSelectionName = _this select 1; //pull random selection from HDC
|
2015-04-29 20:54:58 +00:00
|
|
|
};
|
2015-08-26 08:04:51 +00:00
|
|
|
};
|
2015-04-05 13:51:28 +00:00
|
|
|
|
2016-02-16 04:23:04 +00:00
|
|
|
if ((_minLethalDamage <= _newDamage) && {[_unit, [_effectiveSelectionName] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
|
2015-08-26 08:04:51 +00:00
|
|
|
if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
|
|
|
|
_damageReturn = 0.9;
|
2015-04-29 20:54:58 +00:00
|
|
|
};
|
2015-11-21 17:11:13 +00:00
|
|
|
if ([_unit, false, true] call FUNC(setDead)) then {
|
2015-08-26 08:04:51 +00:00
|
|
|
_damageReturn = 1;
|
2015-04-29 20:54:58 +00:00
|
|
|
} else {
|
|
|
|
_damageReturn = _damageReturn min 0.89;
|
|
|
|
};
|
2015-08-26 08:04:51 +00:00
|
|
|
} else {
|
|
|
|
_damageReturn = _damageReturn min 0.89;
|
2015-01-18 21:16:35 +00:00
|
|
|
};
|
2015-08-26 08:04:51 +00:00
|
|
|
|
2016-02-28 23:12:56 +00:00
|
|
|
// Start the loop that tracks the unit vitals
|
|
|
|
[_unit] call FUNC(addVitalLoop);
|
2015-02-07 22:48:24 +00:00
|
|
|
|
2015-05-16 10:11:45 +00:00
|
|
|
if (_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)]) exitWith {
|
2016-02-16 04:23:04 +00:00
|
|
|
private _delayedUnconsicous = false;
|
|
|
|
if (_vehicle != _unit and {damage _vehicle >= 1}) then {
|
2015-04-30 23:38:36 +00:00
|
|
|
[_unit] call EFUNC(common,unloadPerson);
|
2015-05-18 20:22:57 +00:00
|
|
|
_delayedUnconsicous = true;
|
2015-05-16 10:11:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (_damageReturn >= 0.9 && {_selection in ["", "head", "body"]}) exitWith {
|
2015-11-30 16:53:57 +00:00
|
|
|
if (_unit getVariable ["ACE_isUnconscious", false]) exitwith {
|
2015-11-21 17:11:13 +00:00
|
|
|
[_unit, false, true] call FUNC(setDead);
|
2015-06-19 21:03:31 +00:00
|
|
|
0.89;
|
2015-04-29 20:54:58 +00:00
|
|
|
};
|
2015-05-18 20:22:57 +00:00
|
|
|
if (_delayedUnconsicous) then {
|
|
|
|
[{
|
|
|
|
[_this select 0, true] call FUNC(setUnconscious);
|
2016-05-22 13:27:24 +00:00
|
|
|
}, [_unit], 0.7] call CBA_fnc_waitAndExecute;
|
2015-05-18 20:22:57 +00:00
|
|
|
} else {
|
|
|
|
[{
|
|
|
|
[_this select 0, true] call FUNC(setUnconscious);
|
2016-05-22 13:27:24 +00:00
|
|
|
}, [_unit]] call CBA_fnc_execNextFrame;
|
2015-05-18 20:22:57 +00:00
|
|
|
};
|
2015-06-19 21:03:31 +00:00
|
|
|
0.89;
|
2015-04-29 20:54:58 +00:00
|
|
|
};
|
2015-07-30 16:21:24 +00:00
|
|
|
_damageReturn min 0.89;
|
2015-05-16 10:11:45 +00:00
|
|
|
};
|
2015-04-29 20:54:58 +00:00
|
|
|
|
2015-05-16 10:11:45 +00:00
|
|
|
if (((_unit getVariable [QGVAR(enableRevive), GVAR(enableRevive)]) > 0) && {_damageReturn >= 0.9} && {_selection in ["", "head", "body"]}) exitWith {
|
|
|
|
if (vehicle _unit != _unit and {damage (vehicle _unit) >= 1}) then {
|
|
|
|
[_unit] call EFUNC(common,unloadPerson);
|
2015-02-10 12:33:40 +00:00
|
|
|
};
|
2015-11-21 17:11:13 +00:00
|
|
|
[_unit, false, true] call FUNC(setDead);
|
2015-06-19 21:03:31 +00:00
|
|
|
0.89;
|
2015-01-18 21:16:35 +00:00
|
|
|
};
|
2015-02-07 22:48:24 +00:00
|
|
|
|
2015-09-06 09:49:08 +00:00
|
|
|
TRACE_3("ACE_DEBUG: HandleDamage damage return",_selection,_damageReturn,_unit);
|
|
|
|
|
2015-08-22 14:25:10 +00:00
|
|
|
_damageReturn
|