Change clean up privates in handleDamage code

This commit is contained in:
Glowbal 2016-06-13 11:05:21 +02:00
parent 8e59993d7a
commit 792dbcd009
3 changed files with 35 additions and 40 deletions

View File

@ -26,8 +26,6 @@ if !(local _unit) exitWith {
nil
};
private ["_damageReturn", "_typeOfDamage", "_minLethalDamage", "_newDamage", "_typeIndex", "_preventDeath"];
// bug, assumed fixed, @todo excessive testing, if nothing happens remove
if (_projectile isEqualType objNull) then {
_projectile = typeOf _projectile;
@ -62,16 +60,16 @@ if !(_unit getVariable [QGVAR(allowDamage), true]) exitWith {
};
// Get return damage
_damageReturn = _damage;
private _damageReturn = _damage;
_newDamage = _this call FUNC(handleDamage_caching);
private _newDamage = _this call FUNC(handleDamage_caching);
// handleDamage_caching may have modified the projectile string
_typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
private _typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
TRACE_3("ACE_DEBUG: HandleDamage caching new damage",_selection,_newDamage,_unit);
_typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
_minLethalDamage = if (_typeIndex >= 0) then {
private _typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
private _minLethalDamage = if (_typeIndex >= 0) then {
GVAR(minLethalDamages) select _typeIndex
} else {
0.01

View File

@ -17,13 +17,12 @@
*/
#include "script_component.hpp"
private ["_hitSelections", "_hitPoints", "_impactVelocity", "_newDamage", "_cache_hitpoints", "_cache_projectiles", "_cache_params", "_cache_damages"];
params ["_unit", "_selectionName", "_damage", "_source", "_projectile", "_hitPointIndex"];
_hitSelections = GVAR(SELECTIONS);
private _hitSelections = GVAR(SELECTIONS);
// Calculate change in damage - use getHitIndex because selection is translated (hitdiaphragm->body)
_newDamage = _damage - (damage _unit);
private _newDamage = _damage - (damage _unit);
if (_hitPointIndex >= 0) then {_newDamage = _damage - (_unit getHitIndex _hitPointIndex)};
TRACE_7("ACE_DEBUG: HandleDamage_Caching Called",_unit, _selectionName, _damage, _source, _projectile,_hitPointIndex,_newDamage);
@ -40,7 +39,7 @@ if ((_vehicle != _unit) && {!(_vehicle isKindOf "StaticWeapon")} && {_source in
};
// Handle falling damage
_impactVelocity = (velocity _unit) select 2;
private _impactVelocity = (velocity _unit) select 2;
if (_impactVelocity < -5 && {_vehicle == _unit}) then {
TRACE_1("Starting isFalling", time);
_unit setVariable [QGVAR(isFalling), true];
@ -51,6 +50,7 @@ if (_impactVelocity < -5 && {_vehicle == _unit}) then {
_unit setVariable [QGVAR(isFalling), false];
};
};
if (_unit getVariable [QGVAR(isFalling), false]) then {
if !(_selectionName in ["", "leg_l", "leg_r"]) then {
if (_selectionName == "body") then {
@ -86,11 +86,10 @@ if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) t
if (GVAR(level) < 2 || {!([_unit] call FUNC(hasMedicalEnabled))}) then {
[_unit] call FUNC(handleDamage_basic);
} else {
_cache_params = _unit getVariable [QGVAR(cachedHandleDamageParams), []];
_cache_damages = _unit getVariable QGVAR(cachedDamages);
private _cache_params = _unit getVariable [QGVAR(cachedHandleDamageParams), []];
private _cache_damages = _unit getVariable QGVAR(cachedDamages);
{
_params = _x + [_cache_damages select _forEachIndex];
_params call FUNC(handleDamage_advanced);
(_x + [_cache_damages select _forEachIndex]) call FUNC(handleDamage_advanced);
} forEach _cache_params;
[_unit] call FUNC(handleDamage_advancedSetDamage);
};
@ -106,24 +105,23 @@ if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) t
// Caching of the damage events
if (_selectionName != "") then {
_cache_projectiles = _unit getVariable QGVAR(cachedProjectiles);
private ["_index","_otherDamage"];
_index = _cache_projectiles find _projectile;
private _cache_projectiles = _unit getVariable QGVAR(cachedProjectiles);
private _index = _cache_projectiles find _projectile;
// Check if the current projectile has already been handled once
if (_index >= 0 && {_projectile != "falling"}) exitWith {
_cache_damages = _unit getVariable QGVAR(cachedDamages);
// Find the previous damage this projectile has done
_otherDamage = (_cache_damages select _index);
private _cache_damages = _unit getVariable QGVAR(cachedDamages);
private _otherDamage = (_cache_damages select _index); // Find the previous damage this projectile has done
// Take the highest damage of the two
if (_newDamage > _otherDamage) then {
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
private _cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
private _cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
private ["_hitPoint", "_restore"];
// Restore the damage before the previous damage was processed
_hitPoint = _cache_hitpoints select _index;
_restore = ((_unit getHitIndex _hitPoint) - _otherDamage) max 0;
private _hitPoint = _cache_hitpoints select _index;
private _restore = ((_unit getHitIndex _hitPoint) - _otherDamage) max 0;
_unit setHitIndex [_hitPoint, _restore];
_cache_hitpoints set [_index, _hitPointIndex];
@ -137,9 +135,9 @@ if (_selectionName != "") then {
};
};
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
_cache_damages = _unit getVariable QGVAR(cachedDamages);
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
private _cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
private _cache_damages = _unit getVariable QGVAR(cachedDamages);
private _cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
// This is an unhandled projectile
_cache_projectiles pushBack _projectile;

View File

@ -17,27 +17,26 @@
#include "script_component.hpp"
private ["_bodyPartn", "_injuryTypeInfo", "_allInjuriesForDamageType", "_allPossibleInjuries", "_highestPossibleDamage", "_highestPossibleSpot", "_minDamage", "_openWounds", "_woundID", "_toAddInjury", "_painToAdd", "_bloodLoss", "_bodyPartNToAdd", "_classType", "_damageLevels", "_foundIndex", "_i", "_injury", "_maxDamage", "_pain", "_painLevel", "_selections", "_toAddClassID", "_woundsCreated"];
params ["_unit", "_selectionName", "_damage", "_typeOfProjectile", "_typeOfDamage"];
TRACE_6("ACE_DEBUG: HandleDamage Called",_unit, _selectionName, _damage, _shooter, _typeOfProjectile,_typeOfDamage);
// Administration for open wounds and ids
_openWounds = _unit getVariable[QGVAR(openWounds), []];
_woundID = _unit getVariable[QGVAR(lastUniqueWoundID), 1];
private _openWounds = _unit getVariable[QGVAR(openWounds), []];
private _woundID = _unit getVariable[QGVAR(lastUniqueWoundID), 1];
_extensionOutput = "ace_medical" callExtension format ["HandleDamageWounds,%1,%2,%3,%4", _selectionName, _damage, _typeOfDamage, _woundID];
private _extensionOutput = "ace_medical" callExtension format ["HandleDamageWounds,%1,%2,%3,%4", _selectionName, _damage, _typeOfDamage, _woundID];
_painToAdd = 0;
_woundsCreated = [];
private _painToAdd = 0;
private _woundsCreated = [];
call compile _extensionOutput;
{
_x params ["", "_toAddClassID", "_bodyPartNToAdd"];
_foundIndex = -1;
_toAddClassID = _x select 1;
_bodyPartNToAdd = _x select 2;
{
_x params ["", "_compareId", "_comparyBodyPartN"];
// Check if we have an id of the given class on the given bodypart already
if (_x select 1 == _toAddClassID && {_x select 2 == _bodyPartNToAdd}) exitWith {
if (_compareId == _toAddClassID && {_comparyBodyPartN2 == _bodyPartNToAdd}) exitWith {
_foundIndex = _forEachIndex;
};
} forEach _openWounds;
@ -47,7 +46,7 @@ call compile _extensionOutput;
_openWounds pushBack _x;
} else {
// We already have one of these, so we are just going to increase the number that we have of it with a new one.
_injury = _openWounds select _foundIndex;
private _injury = _openWounds select _foundIndex;
_injury set [3, (_injury select 3) + 1];
};
} forEach _woundsCreated;
@ -59,6 +58,6 @@ if (count _woundsCreated > 0) then {
_unit setVariable [QGVAR(lastUniqueWoundID), _woundID, true];
};
_painLevel = _unit getVariable [QGVAR(pain), 0];
private _painLevel = _unit getVariable [QGVAR(pain), 0];
_unit setVariable [QGVAR(pain), _painLevel + _painToAdd];
TRACE_6("ACE_DEBUG: HandleDamage_WoundsOLD",_unit, _painLevel, _painToAdd, _unit getVariable QGVAR(pain), _unit getVariable QGVAR(openWounds),_woundsCreated);