Added GVAR(HITPOINTS) and GVAR(SELECTIONS) variables

No longer have to recreate the selection and hitpoint arrays every time
This commit is contained in:
Glowbal 2015-04-11 22:30:52 +02:00
parent c69f71ba71
commit e8d2a00994
3 changed files with 35 additions and 26 deletions

View File

@ -102,4 +102,7 @@ GVAR(IVBags) = [];
call FUNC(parseConfigForInjuries);
GVAR(HITPOINTS) = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"];
GVAR(SELECTIONS) = ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"];
ADDON = true;

View File

@ -17,7 +17,7 @@
#include "script_component.hpp"
private ["_unit", "_selection", "_damage", "_shooter", "_projectile", "_damageReturn", "_hitPoints", "_typeOfDamage"];
private ["_unit", "_selection", "_damage", "_shooter", "_projectile", "_damageReturn", "_typeOfDamage"];
_unit = _this select 0;
_selection = _this select 1;
_damage = _this select 2;
@ -32,8 +32,7 @@ if (typeName _projectile == "OBJECT") then {
};
// If the damage is being weird, we just tell it to fuck off.
_hitSelections = ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"];
if !(_selection in (_hitSelections + [""])) exitWith {0};
if !(_selection in (GVAR(SELECTIONS) + [""])) exitWith {0};
_damageReturn = _damage;
if (GVAR(level) < 2) then {
@ -46,8 +45,7 @@ if (GVAR(level) >= 2) then {
// lets use basic for the time being..
_damageReturn = _this call FUNC(handleDamage_basic);
};
[_unit, _selection, _damage, _source, _projectile] call FUNC(handleDamage_caching);
_newDamage = _this call FUNC(handleDamage_caching);
if (_damageReturn > 0.9) then {
@ -59,12 +57,6 @@ if (GVAR(level) >= 2) then {
_minLethalDamage = GVAR(minLethalDamages) select _typeIndex;
};
_hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"];
_newDamage = _damage - (damage _unit);
if (_selection in _hitSelections) then {
_newDamage = _damage - (_unit getHitPointDamage (_hitPoints select (_hitSelections find _selection)));
};
if ((_minLethalDamage <= _newDamage) && {[_unit, [_selection] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)} && {_selection in ["", "head", "body"]}) then {
if ([_unit] call FUNC(setDead)) then {
_damageReturn = 1;

View File

@ -25,8 +25,8 @@ _damage = _this select 2;
_source = _this select 3;
_projectile = _this select 4;
_hitSelections = ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"];
_hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"];
_hitSelections = GVAR(SELECTIONS);
_hitPoints = GVAR(HITPOINTS);
// Calculate change in damage.
_newDamage = _damage - (damage _unit);
@ -34,6 +34,8 @@ if (_selectionName in _hitSelections) then {
_newDamage = _damage - (_unit getHitPointDamage (_hitPoints select (_hitSelections find _selectionName)));
};
//_damage = _damage + _newDamage;
// Check for vehicle crash
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _source} && {_projectile == ""} && {_selectionName == ""}) then {
if (missionNamespace getvariable [QGVAR(allowVehicleCrashDamage), true]) then {
@ -60,13 +62,15 @@ if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) t
// handle the cached damages 3 frames later
[{
private "_args";
private ["_args", "_params"];
_args = _this select 0;
if (diag_frameno > (_args select 1) + 2) then {
_cache_params = (_args select 0) getVariable [QGVAR(cachedHandleDamageParams), []];
_cache_damages = (_args select 0) getVariable QGVAR(cachedDamages);
{
_x call FUNC(handleDamage_advanced);
_params = _x + [_cache_damages select _foreachIndex];
_params call FUNC(handleDamage_advanced);
}foreach _cache_params;
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
@ -78,23 +82,22 @@ if (diag_frameno > (_unit getVariable [QGVAR(frameNo_damageCaching), -3]) + 2) t
_unit setVariable [QGVAR(cachedHandleDamageParams), []];
};
// Make sure there's only one damaged selection per projectile per frame.
_cache_projectiles = _unit getVariable QGVAR(cachedProjectiles);
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
_cache_damages = _unit getVariable QGVAR(cachedDamages);
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
// Caching of the damage events
if (_selectionName != "") then {
_cache_projectiles = _unit getVariable QGVAR(cachedProjectiles);
private ["_index","_otherDamage"];
_index = _cache_projectiles find _projectile;
// Check if the current projectile has already been handled once
if (_index >= 0) exitwith {
_cache_damages = _unit getVariable QGVAR(cachedDamages);
// Find the previous damage this projectile has done
_otherDamage = (_cache_damages select _index);
// Take the highest damage of the two
if (_newDamage > _otherDamage) then {
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
private ["_hitPoint", "_restore"];
// Restore the damage before the previous damage was processed
_hitPoint = _cache_hitpoints select _index;
@ -104,18 +107,29 @@ if (_selectionName != "") then {
_cache_hitpoints set [_index, (_hitPoints select (_hitSelections find _selectionName))];
_cache_damages set [_index, _newDamage];
_cache_params set[_index, _this];
_unit setVariable [QGVAR(cachedProjectiles), _cache_projectiles];
_unit setVariable [QGVAR(cachedHitPoints), _cache_hitpoints];
_unit setVariable [QGVAR(cachedDamages), _cache_damages];
_unit setVariable [QGVAR(cachedHandleDamageParams), _cache_params];
};
};
_cache_hitpoints = _unit getVariable QGVAR(cachedHitPoints);
_cache_damages = _unit getVariable QGVAR(cachedDamages);
_cache_params = _unit getVariable QGVAR(cachedHandleDamageParams);
// This is an unhandled projectile
_cache_projectiles pushBack _projectile;
_cache_hitpoints pushBack (_hitPoints select (_hitSelections find _selectionName));
_cache_damages pushBack _newDamage;
_cache_params pushBack _this;
// Store the new cached values
_unit setVariable [QGVAR(cachedProjectiles), _cache_projectiles];
_unit setVariable [QGVAR(cachedHitPoints), _cache_hitpoints];
_unit setVariable [QGVAR(cachedDamages), _cache_damages];
_unit setVariable [QGVAR(cachedHandleDamageParams), _cache_params];
};
// Store the new cached values
_unit setVariable [QGVAR(cachedProjectiles), _cache_projectiles];
_unit setVariable [QGVAR(cachedHitPoints), _cache_hitpoints];
_unit setVariable [QGVAR(cachedDamages), _cache_damages];
_unit setVariable [QGVAR(cachedHandleDamageParams), _cache_params];
_newDamage;