2015-02-03 19:09:25 +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>
|
|
|
|
* 4: Projectile <OBJECT/STRING>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Damage To Be Inflicted <NUMBER>
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-01-18 21:16:35 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-22 14:25:10 +00:00
|
|
|
params ["_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 {
|
|
|
|
#ifdef DEBUG_ENABLED_MEDICAL
|
2015-09-02 18:49:17 +00:00
|
|
|
ACE_LOGDEBUG_3("HandleDamage on remote unit! - %1 - %2 - %3", diag_frameno, _unit, isServer);
|
2015-09-02 18:13:51 +00:00
|
|
|
#endif
|
|
|
|
nil
|
|
|
|
};
|
|
|
|
|
|
|
|
private ["_damageReturn", "_typeOfDamage", "_minLethalDamage", "_newDamage", "_typeIndex", "_preventDeath"];
|
2015-02-06 12:47:17 +00:00
|
|
|
|
2015-09-02 18:13:51 +00:00
|
|
|
// bug, assumed fixed, @todo excessive testing, if nothing happens remove
|
|
|
|
/*if (typeName _projectile == "OBJECT") then {
|
2015-02-06 12:47:17 +00:00
|
|
|
_projectile = typeOf _projectile;
|
|
|
|
_this set [4, _projectile];
|
2015-09-02 18:13:51 +00:00
|
|
|
};*/
|
2015-01-18 21:16:35 +00:00
|
|
|
|
2015-09-02 18:13:51 +00:00
|
|
|
#ifdef DEBUG_ENABLED_MEDICAL
|
2015-09-02 18:49:17 +00:00
|
|
|
ACE_LOGDEBUG_3("HandleDamage - %1 - %2 - %3", diag_frameno, _selection, _damage);
|
2015-09-02 18:13:51 +00:00
|
|
|
#endif
|
|
|
|
|
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-09-02 18:13:51 +00:00
|
|
|
// If the damage is being weird, we just tell it to fuck off. Ignore: "hands", "legs", "?"
|
|
|
|
if (_selection != "" && {!(_selection in GVAR(SELECTIONS))}) exitWith {0}; //@todo "neck", "pelvis", "spine1", "spine2", "spine3"
|
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-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-09-02 18:49:17 +00:00
|
|
|
#ifdef DEBUG_ENABLED_MEDICAL
|
|
|
|
ACE_LOGDEBUG_3("HandleDamage damage disabled. - %1 - %2 - %3", diag_frameno, _unit, _selection);
|
|
|
|
#endif
|
2015-04-30 23:38:36 +00:00
|
|
|
};
|
|
|
|
|
2015-09-02 18:49:17 +00:00
|
|
|
//if (true) exitWith {nil};//
|
|
|
|
|
2015-04-30 23:38:36 +00:00
|
|
|
// Get return damage
|
2015-02-06 12:47:17 +00:00
|
|
|
_damageReturn = _damage;
|
2015-08-11 18:58:00 +00:00
|
|
|
|
2015-08-26 08:04:51 +00:00
|
|
|
_newDamage = _this call FUNC(handleDamage_caching);
|
|
|
|
// handleDamage_caching may have modified the projectile string
|
|
|
|
_typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
|
2015-08-11 18:58:00 +00:00
|
|
|
|
2015-08-26 08:04:51 +00:00
|
|
|
_typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
|
2015-08-29 13:29:02 +00:00
|
|
|
_minLethalDamage = if (_typeIndex >= 0) then {
|
|
|
|
GVAR(minLethalDamages) select _typeIndex
|
|
|
|
} else {
|
|
|
|
0.01
|
2015-08-26 08:04:51 +00:00
|
|
|
};
|
2015-02-13 21:55:13 +00:00
|
|
|
|
2015-08-26 08:04:51 +00:00
|
|
|
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _shooter} && {_projectile == ""} && {_selection == ""}) then {
|
|
|
|
if (GVAR(enableVehicleCrashes)) then {
|
|
|
|
_selection = GVAR(SELECTIONS) select (floor(random(count GVAR(SELECTIONS))));
|
2015-04-29 20:54:58 +00:00
|
|
|
};
|
2015-08-26 08:04:51 +00:00
|
|
|
};
|
2015-04-05 13:51:28 +00:00
|
|
|
|
2015-08-26 08:04:51 +00:00
|
|
|
if ((_minLethalDamage <= _newDamage) && {[_unit, [_selection] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
|
|
|
|
if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
|
|
|
|
_damageReturn = 0.9;
|
2015-04-29 20:54:58 +00:00
|
|
|
};
|
2015-08-26 08:04:51 +00:00
|
|
|
if ([_unit] call FUNC(setDead)) then {
|
|
|
|
_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
|
|
|
|
2015-03-05 17:42:08 +00:00
|
|
|
[_unit] call FUNC(addToInjuredCollection);
|
2015-02-07 22:48:24 +00:00
|
|
|
|
2015-05-16 10:11:45 +00:00
|
|
|
if (_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)]) exitWith {
|
|
|
|
if (vehicle _unit != _unit and {damage (vehicle _unit) >= 1}) then {
|
2015-04-30 23:38:36 +00:00
|
|
|
[_unit] call EFUNC(common,unloadPerson);
|
2015-05-16 10:11:45 +00:00
|
|
|
};
|
|
|
|
|
2015-05-18 20:22:57 +00:00
|
|
|
private "_delayedUnconsicous";
|
|
|
|
_delayedUnconsicous = false;
|
2015-05-16 10:11:45 +00:00
|
|
|
if (vehicle _unit != _unit and {damage (vehicle _unit) >= 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 {
|
|
|
|
if (_unit getvariable ["ACE_isUnconscious", false]) exitwith {
|
2015-06-19 21:03:31 +00:00
|
|
|
[_unit] call FUNC(setDead);
|
|
|
|
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);
|
|
|
|
}, [_unit], 0.7, 0] call EFUNC(common,waitAndExec);
|
|
|
|
} else {
|
|
|
|
[{
|
|
|
|
[_this select 0, true] call FUNC(setUnconscious);
|
|
|
|
}, [_unit]] call EFUNC(common,execNextFrame);
|
|
|
|
};
|
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-05-16 10:11:45 +00:00
|
|
|
[_unit] 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-08-22 14:25:10 +00:00
|
|
|
_damageReturn
|