From 73d3869a046fc736ea9d5b533b085004a4c6279e Mon Sep 17 00:00:00 2001 From: Thomas Kooi Date: Sun, 25 Jan 2015 14:00:51 +0100 Subject: [PATCH] Minor improvements made to handleDamage functions --- .../functions/fnc_cacheHandleDamageCall.sqf | 10 +++--- .../functions/fnc_determineIfFatal.sqf | 4 +-- addons/medical/functions/fnc_onDamage.sqf | 17 +++++++--- .../fnc_onInjury_assignOpenWounds.sqf | 34 +++++++++++-------- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/addons/medical/functions/fnc_cacheHandleDamageCall.sqf b/addons/medical/functions/fnc_cacheHandleDamageCall.sqf index 09469ec275..b692c2e871 100644 --- a/addons/medical/functions/fnc_cacheHandleDamageCall.sqf +++ b/addons/medical/functions/fnc_cacheHandleDamageCall.sqf @@ -11,7 +11,7 @@ #include "script_component.hpp" -private ["_unit", "_selectionName","_damage"]; +private ["_unit", "_selectionName","_damage", "_source","_projectile","_hitSelections","_hitPoints","_newDamage","_cache_hitpoints","_cache_projectiles","_cache_params","_cache_damages"]; _unit = _this select 0; _selectionName = _this select 1; _damage = _this select 2; @@ -47,11 +47,12 @@ if (_unit getVariable [QGVAR(isFalling), false]) then { // Finished with the current frame, reset variables // Note: sometimes handleDamage spans over 2 or even 3 frames. -if (diag_frameno > (_unit getVariable [QGVAR(frameNo), -3]) + 2) then { - _unit setVariable [QGVAR(frameNo), diag_frameno]; +if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) then { + _unit setVariable [QGVAR(frameNo_damageCaching), diag_frameno]; // handle the cached damages 3 frames later [{ + private ["_args","_unit","_frameNo"]; _args = _this select 0; _unit = _args select 0; _frameNo = _args select 1; @@ -87,7 +88,7 @@ if (_selectionName != "") then { // Check if the current projectile has already been handled once if (_projectile in _cache_projectiles) then { - + private ["_index","_otherDamage"]; // if it has been handled, find the index in the cache _index = _cache_projectiles find _projectile; @@ -98,6 +99,7 @@ if (_selectionName != "") then { if (_otherDamage > _newDamage) then { _newDamage = 0; } else { + private ["_hitPoint", "_restore"]; // Restore the damage before the previous damage was processed _hitPoint = _cache_hitpoints select _index; _restore = ((_unit getHitPointDamage _hitPoint) - _otherDamage) max 0; diff --git a/addons/medical/functions/fnc_determineIfFatal.sqf b/addons/medical/functions/fnc_determineIfFatal.sqf index a9f5597f11..b14822efeb 100644 --- a/addons/medical/functions/fnc_determineIfFatal.sqf +++ b/addons/medical/functions/fnc_determineIfFatal.sqf @@ -21,9 +21,9 @@ 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)]]; + _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)]]; + _damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_AI), GVAR(damageThreshold_AI), GVAR(damageThreshold_AI) * 1.7]]; }; _damageBodyPart = ([_unit,QGVAR(bodyPartStatus),[0,0,0,0,0,0]] call EFUNC(common,getDefinedVariable)) select _part; diff --git a/addons/medical/functions/fnc_onDamage.sqf b/addons/medical/functions/fnc_onDamage.sqf index 31bee43595..e12392004b 100644 --- a/addons/medical/functions/fnc_onDamage.sqf +++ b/addons/medical/functions/fnc_onDamage.sqf @@ -42,8 +42,8 @@ if !(_selectionName in ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"]) e [_unit, _selectionName, _damage, _source, _projectile] call FUNC(cacheHandledamageCall); // Checking if we should return full damage or not -if (_damage > 0.95) then { - _damage = 0.95; +if (_damage > 0.975) then { + _damage = 0.975; }; // Check if a unit would die from this hit @@ -53,12 +53,21 @@ if (alive _unit && (vehicle _unit == _unit) && {alive (vehicle _unit)}) then { // 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)]]; + _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)]]; + _damageThreshold =_unit getvariable[QGVAR(unitDamageThreshold), [GVAR(damageThreshold_AI), GVAR(damageThreshold_AI), GVAR(damageThreshold_AI) * 1.7]]; }; _damageBodyPart = ([_unit,QGVAR(bodyPartStatus),[0,0,0,0,0,0]] call EFUNC(common,getDefinedVariable)) select _bodyPartn; + _hitSelections = ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"]; + _hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"]; + + // Calculate change in damage. + _newDamage = _damage - (damage _unit); + if (_selectionName in _hitSelections) then { + _newDamage = _damage - (_unit getHitPointDamage (_hitPoints select (_hitSelections find _selectionName))); + }; + // Check if damage to body part is higher as damage head if (_bodyPartn == 0) exitwith { if (_damageBodyPart >= ((_damageThreshold select 0) + _newDamage) && {(random(1) > 0.2)}) then { diff --git a/addons/medical/functions/fnc_onInjury_assignOpenWounds.sqf b/addons/medical/functions/fnc_onInjury_assignOpenWounds.sqf index 5f3171fb70..f03f4c7abe 100644 --- a/addons/medical/functions/fnc_onInjury_assignOpenWounds.sqf +++ b/addons/medical/functions/fnc_onInjury_assignOpenWounds.sqf @@ -9,56 +9,60 @@ */ #include "script_component.hpp" +#define ADD_INJURY(BODYPART,TYPE,AMOUNT) _selection = _openWounds select BODYPART; \ + _newAmount = (_selection select TYPE) + AMOUNT; \ + _selection set [ TYPE, _newAmount]; \ + _openWounds set [BODYPART , _selection]; -private ["_unit", "_amountOfDamage", "_typeOfInjury", "_bodyPartn"]; + +private ["_unit", "_amountOfDamage", "_typeOfInjury", "_bodyPartn", "_openWounds","_newAmount","_selection"]; _unit = _this select 0; _amountOfDamage = _this select 1; _typeOfInjury = _this select 2; _bodyPartn = _this select 3; if (_amountOfDamage > 0.05) exitwith { + _openWounds = [_unit,QGVAR(openWounds)] call EFUNC(common,getDefinedVariable); switch (toLower _typeOfInjury) do { case "bullet": { - [_unit, _bodyPartn, round(random(2)), 1, false] call FUNC(addOpenWounds); + ADD_INJURY(_bodyPartn, round(random(2)), 1); }; case "grenade": { - [_unit, _bodyPartn, round(random(2)), 1] call FUNC(addOpenWounds); + ADD_INJURY(_bodyPartn, round(random(2)), 1); for "_i" from 0 to round(random(3)) /* step +1 */ do { - [_unit, round(random(6)), round(random(2)), 1, false] call FUNC(addOpenWounds); + ADD_INJURY(round(random(6)), round(random(2)), 1); }; }; case "explosive": { - [_unit, _bodyPartn, round(random(2)), 1] call FUNC(addOpenWounds); + ADD_INJURY(_bodyPartn, round(random(2)), 1); for "_i" from 0 to round(random(4)) /* step +1 */ do { - [_unit, round(random(6)), round(random(2)), 1, false] call FUNC(addOpenWounds); + ADD_INJURY(round(random(6)), round(random(2)), 1); }; }; case "shell": { - [_unit, _bodyPartn, round(random(2)), 1] call FUNC(addOpenWounds); + ADD_INJURY(_bodyPartn, round(random(2)), 1); for "_i" from 0 to round(random(5)) /* step +1 */ do { - [_unit, round(random(6)), round(random(2)), 1, false] call FUNC(addOpenWounds); + ADD_INJURY(round(random(6)), round(random(2)), 1); }; }; case "backblast": { if (random(1)>=0.5) then{ - [_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds); + ADD_INJURY(_bodyPartn, round(random(2)), 1); }; }; case "unknown": { - [_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds); + ADD_INJURY(_bodyPartn, round(random(1)), 1); }; case "vehiclecrash": { if (random(1)>=0.5) then{ - [_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds); + ADD_INJURY(_bodyPartn, round(random(1)), 1); }; }; default { - [_unit, _bodyPartn, round(random(1)), 1, false] call FUNC(addOpenWounds); + ADD_INJURY(_bodyPartn, round(random(1)), 1); }; }; - - // one more call to broadcast the new injuries - [_unit, _bodyPartn, 0, 0, true] call FUNC(addOpenWounds); + [_unit, QGVAR(openWounds),_openWounds] call EFUNC(common,setDefinedVariable); true; };