Fixed advanced medical handleDamage chain. Now supports killing units.

This commit is contained in:
Glowbal 2015-02-28 19:22:46 +01:00
parent f1445a4c45
commit 451f8b6d0b
5 changed files with 129 additions and 13 deletions

View File

@ -10,6 +10,7 @@ PREP(handleDamage_basic);
PREP(handleDamage_fractures);
PREP(handleDamage_internalInjuries);
PREP(handleDamage_caching);
PREP(handleDamage_advancedSetDamage);
PREP(init);
PREP(selectionNameToNumber);
PREP(handleDamage_wounds);
@ -67,6 +68,7 @@ PREP(isMedic);
PREP(isInMedicalFacility);
PREP(isMedicalVehicle);
PREP(canAccessMedicalEquipment);
PREP(determineIfFatal);
GVAR(injuredUnitCollection) = [];
call FUNC(parseConfigForInjuries);

View File

@ -0,0 +1,42 @@
/**
* fn_determineIfFatal.sqf
* @Descr: N/A
* @Author: Glowbal
*
* @Arguments: []
* @Return:
* @PublicAPI: false
*/
#include "script_component.hpp"
private ["_unit","_part","_damageThreshold", "_withDamage"];
_unit = _this select 0;
_part = _this select 1;
_withDamage = if (count _this > 2) then { _this select 2} else {0};
if (!alive _unit) exitwith {true};
if ((vehicle _unit != _unit) && {!alive (vehicle _unit)}) exitwith { true };
// Find the correct Damage threshold for unit.
_damageThreshold = [1,1,1];
if (isPlayer _unit) then {
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_Players), GVAR(damageThreshold_Players), GVAR(damageThreshold_Players) * 1.7]];
} else {
_damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_AI), GVAR(damageThreshold_AI), GVAR(damageThreshold_AI) * 1.7]];
};
_damageBodyPart = ((_unit getvariable [QGVAR(bodyPartStatus),[0,0,0,0,0,0]]) select _part) + _withDamage;
// Check if damage to body part is higher as damage head
if (_part == 0) exitwith {
(_damageBodyPart >= (_damageThreshold select 0) && {(random(1) > 0.2)});
};
// Check if damage to body part is higher as damage torso
if (_part == 1) exitwith {
(_damageBodyPart >= (_damageThreshold select 1) && {(random(1) > 0.2)});
};
// Check if damage to body part is higher as damage limbs
(_damageBodyPart >= (_damageThreshold select 2) && {(random(1) > 0.95)});

View File

@ -1,5 +1,5 @@
/*
* Author: KoffeinFlummi
* Author: KoffeinFlummi, Glowbal
* Main HandleDamage EH function.
*
* Arguments:
@ -26,7 +26,7 @@ _projectile = _this select 4;
if !(local _unit) exitWith {nil};
if !([_unit] call FUNC(hasMedicalEnabled)) exitwith {};
if !([_unit] call FUNC(hasMedicalEnabled)) exitwith {systemChat format["Has no medical enabled: %1", _unit];};
if (typeName _projectile == "OBJECT") then {
_projectile = typeOf _projectile;
@ -49,9 +49,19 @@ if (_damageReturn < 0.01) exitWith {0};
if (GVAR(level) >= 1) then {
[_unit, _selectionName, _damage, _source, _projectile, _damageReturn] call FUNC(handleDamage_caching);
// TODO check if this should would have killed the unit..
if (_damageReturn > 0.9) then {
_damageReturn = 0.9;
_hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"];
_newDamage = _damage - (damage _unit);
if (_selectionName in _hitSelections) then {
_newDamage = _damage - (_unit getHitPointDamage (_hitPoints select (_hitSelections find _selectionName)));
};
if ([_unit, [_selectionName] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)) then {
if ([_unit] call FUNC(setDead)) then {
_damageReturn = 1;
};
} else {
_damageReturn = 0.89;
};
};
};

View File

@ -19,33 +19,39 @@
#include "script_component.hpp"
private ["_unit","_selectionName","_amountOfDamage","_sourceOfDamage","_typeOfProjectile","_typeOfDamage"];
private ["_unit","_selectionName","_amountOfDamage","_sourceOfDamage","_typeOfProjectile","_typeOfDamage", "_part", "_damageBodyParts", "_newDamage", "_hitPoints"];
_unit = _this select 0;
_selectionName = _this select 1;
_amountOfDamage = _this select 2;
_sourceOfDamage = _this select 3;
_typeOfProjectile = _this select 4;
_returnDamage = _this select 5;
_typeOfDamage = [_typeOfProjectile] call FUNC(getTypeOfDamage);
_part = [_selectionName] call FUNC(selectionNameToNumber);
_hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"];
// Sorting out the damage
_damageBodyParts = _unit getvariable [QGVAR(bodyPartStatus), [0,0,0,0,0,0]];
_newDamage = _amountOfDamage - (_unit getHitPointDamage (_hitPoints select _part));
_damageBodyParts set [_part, (_damageBodyParts select _part) + _newDamage];
_unit setvariable [QGVAR(bodyPartStatus), _damageBodyParts, true];
[_unit] call FUNC(handleDamage_advancedSetDamage);
// TODO parse for new damage
// TODO parse for kill injuries
[_unit, _selectionName, _amountOfDamage, _typeOfProjectile, _typeOfDamage] call FUNC(handleDamage_wounds);
[_unit, _selectionName, _newDamage, _typeOfProjectile, _typeOfDamage] call FUNC(handleDamage_wounds);
if (GVAR(enableAirway)) then {
[_unit,_selectionName,_amountOfDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_airway);
[_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_airway);
};
if (GVAR(enableFractures)) then {
[_unit,_selectionName,_amountOfDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_fractures);
[_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_fractures);
};
if (GVAR(enableInternalBleeding)) then {
[_unit,_selectionName,_amountOfDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_internalInjuries);
[_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_internalInjuries);
};
if (alive _unit && {!(_unit getvariable ["ACE_isUnconscious", false])}) then {
[_unit, _amountOfDamage] call FUNC(reactionToDamage);
[_unit, _newDamage] call FUNC(reactionToDamage);
};
_returnDamage;

View File

@ -0,0 +1,56 @@
/*
* Author: Glowbal
* Sets the hitpoint damage for au nit to the correct values
*
* Arguments:
* 0: Unit for which the hitpoint damage will be sorted out <OBJECT>
*
* Return Value:
* nil
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_bodyStatus", "_headDamage", "_torsoDamage", "_handsDamage", "_legsDamage"];
_unit = _this select 0;
if (!local _unit) exitwith {
// execute only local
};
_bodyStatus = _unit getvariable [QGVAR(bodyPartStatus),[0,0,0,0,0,0]];
// ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"]
_headDamage = _bodyStatus select 0;
if (_headDamage > 0.95) then {
_unit setHitPointDamage ["hitHead", 0.95];
} else {
_unit setHitPointDamage ["hitHead", _headDamage];
};
_torsoDamage = _bodyStatus select 1;
if (_torsoDamage > 0.95) then {
_unit setHitPointDamage ["hitBody", 0.95];
} else {
_unit setHitPointDamage ["hitBody", _torsoDamage];
};
_handsDamage = (_bodyStatus select 2) + (_bodyStatus select 3);
if (_handsDamage > 0.95) then {
_unit setHitPointDamage ["hitHands", 0.95];
} else {
_unit setHitPointDamage ["hitHands", _handsDamage];
};
_legsDamage = (_bodyStatus select 4) + (_bodyStatus select 5);
if (_legsDamage > 0.95) then {
_unit setHitPointDamage ["hitLegs", 0.95];
} else {
_unit setHitPointDamage ["hitLegs", _legsDamage];
};
if ({_x > 0} count _bodyStatus == 0) then {
_unit setDamage 0;
};