From e754c89c7336d510f89dcd8f89ed3e9a26dbe7b4 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sun, 7 Feb 2016 13:18:19 +0100 Subject: [PATCH] Remove non functional event driven handleDamage --- addons/medical/XEH_init.sqf | 3 +- addons/medical/XEH_postInit.sqf | 5 - addons/medical/XEH_preInit.sqf | 5 - .../medical/functions/fnc_handleDamageNew.sqf | 186 ------------------ .../functions/fnc_handleDrowningDamage.sqf | 21 -- .../functions/fnc_handleFallDamage.sqf | 63 ------ .../functions/fnc_handleSelectionDamage.sqf | 71 ------- 7 files changed, 1 insertion(+), 353 deletions(-) delete mode 100644 addons/medical/functions/fnc_handleDamageNew.sqf delete mode 100644 addons/medical/functions/fnc_handleDrowningDamage.sqf delete mode 100644 addons/medical/functions/fnc_handleFallDamage.sqf delete mode 100644 addons/medical/functions/fnc_handleSelectionDamage.sqf diff --git a/addons/medical/XEH_init.sqf b/addons/medical/XEH_init.sqf index 8b2b0ae1cd..acdd50ce82 100644 --- a/addons/medical/XEH_init.sqf +++ b/addons/medical/XEH_init.sqf @@ -2,8 +2,7 @@ params ["_unit"]; -//_unit addEventHandler ["HandleDamage", {_this call FUNC(handleDamage)}]; -_unit addEventHandler ["HandleDamage", {_this call FUNC(handleDamageNew)}]; +_unit addEventHandler ["HandleDamage", {_this call FUNC(handleDamage)}]; if (local _unit) then { if (!EGVAR(common,settingsInitFinished)) exitWith { diff --git a/addons/medical/XEH_postInit.sqf b/addons/medical/XEH_postInit.sqf index 26c12f6ddf..7345c2a54e 100644 --- a/addons/medical/XEH_postInit.sqf +++ b/addons/medical/XEH_postInit.sqf @@ -2,11 +2,6 @@ #include "script_component.hpp" -["medical_selectionDamage", {_this call FUNC(handleSelectionDamage)}] call EFUNC(common,addEventhandler); -["medical_fallDamage", {_this call FUNC(handleFallDamage)}] call EFUNC(common,addEventhandler); -["medical_drowningDamage", {_this call FUNC(handleDrowningDamage)}] call EFUNC(common,addEventhandler); -["medical_collisionDamage", {_this call FUNC(handleCollisionDamage)}] call EFUNC(common,addEventhandler); - GVAR(heartBeatSounds_Fast) = ["ACE_heartbeat_fast_1", "ACE_heartbeat_fast_2", "ACE_heartbeat_fast_3"]; GVAR(heartBeatSounds_Normal) = ["ACE_heartbeat_norm_1", "ACE_heartbeat_norm_2"]; GVAR(heartBeatSounds_Slow) = ["ACE_heartbeat_slow_1", "ACE_heartbeat_slow_2"]; diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index a12ebf05ea..e8d6f0372d 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -42,11 +42,6 @@ PREP(handleDamage_fractures); PREP(handleDamage_internalInjuries); PREP(handleDamage_wounds); PREP(handleDamage_woundsOld); -PREP(handleDamageNew); -PREP(handleSelectionDamage); -PREP(handleFallDamage); -PREP(handleCollisionDamage); -PREP(handleDrowningDamage); PREP(handleUnitVitals); PREP(handleKilled); PREP(handleLocal); diff --git a/addons/medical/functions/fnc_handleDamageNew.sqf b/addons/medical/functions/fnc_handleDamageNew.sqf deleted file mode 100644 index 63278c6751..0000000000 --- a/addons/medical/functions/fnc_handleDamageNew.sqf +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Author: KoffeinFlummi, Glowbal, commy2 - * Main HandleDamage EH function. - * - * Arguments: - * 0: Unit That Was Hit - * 1: Name Of Hit Selection - * 2: Amount Of Damage - * 3: Shooter - * 4: Projectile - * - * Return Value: - * Damage To Be Inflicted - * - * Public: No - */ -#include "script_component.hpp" - -params ["_unit", "_selection", "_damage", "_shooter", "_projectile"]; -TRACE_5("ACE_DEBUG: HandleDamage Called",_unit,_selection,_damage,_shooter,_projectile); - -// bug, apparently can fire for remote units in special cases -if !(local _unit) exitWith { - TRACE_2("ACE_DEBUG: HandleDamage on remote unit!",_unit,isServer); - nil -}; - -// bug, assumed fixed, @todo excessive testing, if nothing happens remove -if (typeName _projectile == "OBJECT") then { - TRACE_3("ACE_DEBUG: HandleDamage found projectile instead of classname of ammo!",_unit,_projectile,typeOf _projectile); - _projectile = typeOf _projectile; - _this set [4, _projectile]; -}; - -// Exit now we disable damage, replaces "allowDamage false" -if !(_unit getVariable [QGVAR(allowDamage), true]) exitWith { - TRACE_2("ACE_DEBUG: HandleDamage damage disabled.",_selection,_unit); - if (_selection == "") then { - damage _unit - } else { - _unit getHit _selection - }; -}; - -// 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"}; -if (_selection == "arms") exitWith {_unit getHit "arms"}; - -// 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 -_selection = [_unit, _selection, _hitPointIndex] call FUNC(translateSelections); - -diag_log text str _selection; -diag_log text str _damage; - -// systemChat format["_selection %1 _damage %2", _selection, _damage]; - -private ["_damageReturn", "_newDamage", "_index"]; - -// apply damage scripted -if (_selection == "") then { - _damageReturn = _damage; - _newDamage = _damage - damage _unit; - - _index = -1; - - private "_cachedStructuralDamage"; - _cachedStructuralDamage = _unit getVariable [QGVAR(cachedStructuralDamageNew), 0]; - - // handle damage always tries to start and end with the same structural damage call. Use that to find and set the final damage. discard everything the game discards too. - // this correctly handles: bullets, explosions, fire - if (_damage == _cachedStructuralDamage) then { - private _cachedNewHitpointDamages = _unit getVariable [QGVAR(cachedNewHitpointDamages), [0,0,0,0,0,0]]; - private _cachedNewHitpointProjectiles = _unit getVariable [QGVAR(cachedNewHitpointProjectiles), ["", "", "", "", "", ""]]; - - // this is the only point damage actually counts. all additional vitality functions should use these values. - { - if (_x > 0) then { - ["medical_selectionDamage", [_unit, GVAR(Selections) select _forEachIndex, _x, _cachedNewHitpointProjectiles select _forEachIndex]] call EFUNC(common,localEvent); - }; - } forEach _cachedNewHitpointDamages; - } else { - scopeName "findDamageSource"; - - // check for fall damage. this triggers twice, but seems to happen on the same frame. shouldn't fall twice in a few frames anyway. tested at 7FPS on local host MP - if (animationState _unit select [0,4] == "afal") then { - private "_cachedLastFallDamageFrame"; - _cachedLastFallDamageFrame = _unit getVariable [QGVAR(cachedLastFallDamageFrame), -1]; - - if (diag_frameno != _cachedLastFallDamageFrame) then { - ["medical_fallDamage", [_unit, _newDamage]] call EFUNC(common,localEvent); - _unit setVariable [QGVAR(cachedLastFallDamageFrame), diag_frameno]; - }; - - _damageReturn = damage _unit; - breakOut "findDamageSource"; - }; - - // check for drowning damage. Pretty relyable damage output. triggers only once. - if (getOxygenRemaining _unit < 0.5) then { - // typical drowning damage - if (_newDamage == 0.005) then { - ["medical_drowningDamage", [_unit, _newDamage]] call EFUNC(common,localEvent); - _damageReturn = damage _unit - 0.005; // engine applies damage before hd call. subtract again here. - breakOut "findDamageSource"; - }; - - // suffocated under water might use atypical new damage (mostly 1.005) - if (getOxygenRemaining _unit == 0) then { - ["medical_drowningDamage", [_unit, _newDamage min 1]] call EFUNC(common,localEvent); - _damageReturn = damage _unit; // you will die regardless of hd return value - breakOut "findDamageSource"; - }; - }; - - // check for misc. damage. Probably collision. - if (_projectile == "" && _newDamage > 0) then { - private "_cachedLastCollisionDamageFrame"; - _cachedLastCollisionDamageFrame = _unit getVariable [QGVAR(cachedLastFallDamageFrame), -1]; - - // collision only happens once. engine ignores all further calls on that frame as well - if (_cachedLastCollisionDamageFrame != diag_frameno) then { - _unit setVariable [QGVAR(cachedLastFallDamageFrame), diag_frameno]; - _unit setVariable [QGVAR(cachedLastCollisionDamage), 0]; - - ["medical_collisionDamage", [_unit, _newDamage max (_unit getVariable [QGVAR(cachedLastCollisionDamage), 0])]] call EFUNC(common,localEvent); - - _damageReturn = damage _unit - _newDamage; - breakOut "findDamageSource"; - }; - _damageReturn = damage _unit; - }; - }; - - // reset everything, get ready for the next bullet - _unit setVariable [QGVAR(cachedNewHitpointDamages), [0,0,0,0,0,0]]; - _unit setVariable [QGVAR(cachedNewHitpointProjectiles), ["", "", "", "", "", ""]]; - _unit setVariable [QGVAR(cachedStructuralDamageNew), _damage]; - -} else { - // selections are done scripted. return same value to change nothing. - _damageReturn = _unit getHit _selection; - _newDamage = _damage - _damageReturn; // _damageReturn because it saves one getHit call - - _index = GVAR(SELECTIONS) find _selection; - - // a selection we care for was hit. now save the new damage to apply it by a later structural damage call - if (_index != -1) then { - private _cachedNewHitpointDamages = _unit getVariable [QGVAR(cachedNewHitpointDamages), [0,0,0,0,0,0]]; - private _cachedNewHitpointProjectiles = _unit getVariable [QGVAR(cachedNewHitpointProjectiles), ["", "", "", "", "", ""]]; - - // prevents multiple selections from being hit by one bullet due to hitpoint radius system - { - // ignore this damage if it's a secondary selection (minor damage) - if (_x > _newDamage) exitWith { - _newDamage = 0; - }; - - // overwrite minor damage in secondary selections - if (_x > 0) then { - _cachedNewHitpointDamages set [_forEachIndex, 0]; - _cachedNewHitpointProjectiles set [_forEachIndex, ""]; - }; - } forEach _cachedNewHitpointDamages; - - if (_cachedNewHitpointDamages select _index < _newDamage) then { - // apply these by the next matching hd call with selection "". If that one is not matching, this gets discarded - _cachedNewHitpointDamages set [_index, _newDamage]; - _cachedNewHitpointProjectiles set [_index, _projectile]; - } else { - diag_log format["PREVENTED OVERWRITE: %1", [_newDamage, _projectile, _selection]]; - }; - _unit setVariable [QGVAR(cachedNewHitpointDamages), _cachedNewHitpointDamages]; - _unit setVariable [QGVAR(cachedNewHitpointProjectiles), _cachedNewHitpointProjectiles]; - }; - - // use this to detect collision damage. - if (_projectile == "") then { - _unit setVariable [QGVAR(cachedLastCollisionDamage), _newDamage max (_unit getVariable [QGVAR(cachedLastCollisionDamage), 0])]; - }; -}; - -_damageReturn diff --git a/addons/medical/functions/fnc_handleDrowningDamage.sqf b/addons/medical/functions/fnc_handleDrowningDamage.sqf deleted file mode 100644 index 1116d07762..0000000000 --- a/addons/medical/functions/fnc_handleDrowningDamage.sqf +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Author: Glowbal - * Handle drowning damage to unit - * - * Arguments: - * 0: Unit for which the hitpoint damage will be sorted out - * 1: new damage - * - * Return Value: - * None - * - * Public: No - */ - -#include "script_component.hpp" - -params ["_unit", "_newDamage"]; - -// At the moment we will just not do anything -// We reserve this until a later stage -// A unit will automatically die once oxygen has ran out anyway diff --git a/addons/medical/functions/fnc_handleFallDamage.sqf b/addons/medical/functions/fnc_handleFallDamage.sqf deleted file mode 100644 index 3161364f98..0000000000 --- a/addons/medical/functions/fnc_handleFallDamage.sqf +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Author: Glowbal - * Handle fall damage to unit - * - * Arguments: - * 0: Unit for which the hitpoint damage will be sorted out - * 1: new damage - * - * Return Value: - * None - * - * Public: No - */ - -#include "script_component.hpp" - -params ["_unit", "_newDamage"]; - -private _part = ["leg_l"] call FUNC(selectionNameToNumber); -private _part2 = ["leg_r"] call FUNC(selectionNameToNumber); - -// Store the new damage values in our damageBodyParts store -private _damageBodyParts = _unit getVariable [QGVAR(bodyPartStatus), [0,0,0,0,0,0]]; -_damageBodyParts set [_part, (_damageBodyParts select _part) + _newDamage]; -_damageBodyParts set [_part2, (_damageBodyParts select _part2) + _newDamage]; -_unit setVariable [QGVAR(bodyPartStatus), _damageBodyParts]; - -// our unconscious calculation for selection damages -if (alive _unit && {!(_unit getVariable ["ACE_isUnconscious", false])}) then { - // If it reaches this, we can assume that the hit did not kill this unit, as this function is called some time after the damage has been passed. - if ([_unit, _part, _newDamage * 1.3] call FUNC(determineIfFatal)) then { - [_unit, true, 0.5+random(10)] call FUNC(setUnconscious); - } else { - if ([_unit, _part2, _newDamage * 1.3] call FUNC(determineIfFatal)) then { - [_unit, true, 0.5+random(10)] call FUNC(setUnconscious); - }; - }; -}; - -if (GVAR(level) > 1) then { // advanced medical is enabled - [_unit, "leg_l", _newDamage, "", "falling"] call FUNC(handleDamage_assignWounds); // cover both left and right legs - [_unit, "leg_r", _newDamage, "", "falling"] call FUNC(handleDamage_assignWounds); -} else { - // New pain values - _pain = _unit getVariable [QGVAR(pain), 0]; - _pain = _pain + (_newDamage / 4) * (1 - (_unit getVariable [QGVAR(morphine), 0])); - _unit setVariable [QGVAR(pain), _pain min 1, true]; -}; - -// Store the hitpoint values so blood ends up on the unit textures -_unit setVariable [QGVAR(bodyPartStatus), _damageBodyParts, true]; -TRACE_2("ACE_DEBUG: HandleSelectionDamage Broadcast value here", _unit, _unit getVariable QGVAR(bodyPartStatus)); - -EXPLODE_6_PVT(_damageBodyParts,_headDamage,_torsoDamage,_handsDamageR,_handsDamageL,_legsDamageR,_legsDamageL); -_unit setHitPointDamage ["hitHead", _headDamage min 0.95]; -_unit setHitPointDamage ["hitBody", _torsoDamage min 0.95]; -_unit setHitPointDamage ["hitHands", (_handsDamageR + _handsDamageL) min 0.95]; -_unit setHitPointDamage ["hitLegs", (_legsDamageR + _legsDamageL) min 0.95]; - -{ - private _hitPointName = [_unit, _x, true] call FUNC(translateSelections); - _unit setHitPointDamage [_hitPointName, (_damageBodyParts select _foreachIndex) min 0.95]; -}foreach GVAR(SELECTIONS); diff --git a/addons/medical/functions/fnc_handleSelectionDamage.sqf b/addons/medical/functions/fnc_handleSelectionDamage.sqf deleted file mode 100644 index a72f973c79..0000000000 --- a/addons/medical/functions/fnc_handleSelectionDamage.sqf +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Author: Glowbal, Commy2 & KoffeinFlummi - * Sets the hitpoint damage for an unit to the correct values - * - * Arguments: - * 0: Unit for which the hitpoint damage will be sorted out - * 1: Selection name - * 2: new damage - * 3: projectile - * - * Return Value: - * None - * - * Public: No - */ - -#include "script_component.hpp" - -params ["_unit", "_selection", "_newDamage", "_projectile"]; - -private _part = [_selection] call FUNC(selectionNameToNumber); -if (_part < 0) exitwith {systemchat format["Selection name part is below 0"]}; - -// Store the new damage values in our damageBodyParts store -private _damageBodyParts = _unit getVariable [QGVAR(bodyPartStatus), [0,0,0,0,0,0]]; -_damageBodyParts set [_part, (_damageBodyParts select _part) + _newDamage]; -_unit setVariable [QGVAR(bodyPartStatus), _damageBodyParts]; - -// our unconscious calculation for selection damages -if (alive _unit && {!(_unit getVariable ["ACE_isUnconscious", false])}) then { - // If it reaches this, we can assume that the hit did not kill this unit, as this function is called some time after the damage has been passed. - if ([_unit, _part, if (_part > 1) then {_newDamage * 1.3} else {_newDamage * 2}] call FUNC(determineIfFatal)) then { - [_unit, true, 0.5+random(10)] call FUNC(setUnconscious); - }; -}; - -if (GVAR(level) > 1) then { // advanced medical is enabled - _typeOfDamage = [_projectile] call FUNC(getTypeOfDamage); // Get the exact type of damage - [_unit, _selection, _newDamage, _projectile, _typeOfDamage] call FUNC(handleDamage_assignWounds); - - // TODO Disabled until implemented fully - //if (GVAR(enableAirway)) then { - // [_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_airway); - //}; - //if (GVAR(enableFractures)) then { - // [_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_fractures); - //}; - //if (GVAR(enableInternalBleeding)) then { - // [_unit,_selectionName,_newDamage,_sourceOfDamage, _typeOfDamage] call FUNC(handleDamage_internalInjuries); - //}; -} else { - // New pain values - _pain = _unit getVariable [QGVAR(pain), 0]; - _pain = _pain + (_newDamage / 4) * (1 - (_unit getVariable [QGVAR(morphine), 0])); - _unit setVariable [QGVAR(pain), _pain min 1, true]; -}; - -// Store the hitpoint values so blood ends up on the unit textures -_unit setVariable [QGVAR(bodyPartStatus), _damageBodyParts, true]; -TRACE_2("ACE_DEBUG: HandleSelectionDamage Broadcast value here", _unit, _unit getVariable QGVAR(bodyPartStatus)); - -EXPLODE_6_PVT(_damageBodyParts,_headDamage,_torsoDamage,_handsDamageR,_handsDamageL,_legsDamageR,_legsDamageL); -_unit setHitPointDamage ["hitHead", _headDamage min 0.95]; -_unit setHitPointDamage ["hitBody", _torsoDamage min 0.95]; -_unit setHitPointDamage ["hitHands", (_handsDamageR + _handsDamageL) min 0.95]; -_unit setHitPointDamage ["hitLegs", (_legsDamageR + _legsDamageL) min 0.95]; - -{ - private _hitPointName = [_unit, _x, true] call FUNC(translateSelections); - _unit setHitPointDamage [_hitPointName, (_damageBodyParts select _foreachIndex) min 0.95]; -}foreach GVAR(SELECTIONS);