mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Use cached data in setting damage and normalization
Takes cached data from getSelectionsToIgnore instead of checking for the conditions in setHitPointDamage and normalizeHitPoints
This commit is contained in:
parent
2c6411fae9
commit
b8e93e2d28
@ -21,47 +21,11 @@ TRACE_2("params",_vehicle, typeOf _vehicle);
|
||||
// Can't execute all commands if the vehicle isn't local, exit if that's so
|
||||
if !(local _vehicle) exitWith {ERROR_1("Vehicle Not Local %1", _vehicle);};
|
||||
|
||||
(getAllHitPointsDamage _vehicle) params [["_allHitPoints", []]];
|
||||
([_vehicle] call FUNC(getSelectionsToIgnore)) params ["", "_dependsIndexMap"];
|
||||
|
||||
private _config = configOf _vehicle >> "HitPoints";
|
||||
|
||||
private _realHitPoints = [];
|
||||
private _dependentHitPoints = [];
|
||||
private _dependentHitPointScripts = [];
|
||||
|
||||
// Find dependent hitpoints
|
||||
// apply normalized damage to all depends hitpoints
|
||||
{
|
||||
if ((_x != "") && {isClass (_config >> _x)} && {!(_x in _realHitPoints)}) then {
|
||||
_realHitPoints pushBack _x;
|
||||
if (!((getText (_config >> _x >> "depends")) in ["", "0"])) then {
|
||||
_dependentHitPoints pushBack _x;
|
||||
_dependentHitPointScripts pushBack compile getText (_config >> _x >> "depends");
|
||||
};
|
||||
};
|
||||
} forEach _allHitPoints;
|
||||
|
||||
TRACE_2("",_realHitPoints,_dependentHitPoints);
|
||||
|
||||
// Don't bother setting variables if no depends on vehicle:
|
||||
if (_dependentHitPoints isEqualTo []) exitWith {};
|
||||
|
||||
|
||||
// Define global variables and save original values
|
||||
private _savedGlobals = [["total", total]];
|
||||
total = damage _vehicle;
|
||||
{
|
||||
_savedGlobals pushBack [_x, missionNamespace getVariable _x];
|
||||
missionNamespace setVariable [_x, _vehicle getHitPointDamage _x];
|
||||
} forEach _realHitPoints;
|
||||
|
||||
// apply normalized damage to all dependand hitpoints
|
||||
{
|
||||
private _damage = call (_dependentHitPointScripts select _forEachIndex);
|
||||
TRACE_2("setting depend hitpoint", _x, _damage);
|
||||
_vehicle setHitPointDamage [_x, _damage];
|
||||
} forEach _dependentHitPoints;
|
||||
|
||||
// Restore global variables
|
||||
{
|
||||
missionNamespace setVariable _x;
|
||||
} forEach _savedGlobals;
|
||||
private _damage = _vehicle getHitIndex _y;
|
||||
TRACE_2("setting depends hitpoint", _x, _damage);
|
||||
_vehicle setHitIndex [_x, _damage];
|
||||
} forEach _dependsIndexMap;
|
||||
|
@ -26,40 +26,36 @@ TRACE_4("params",_vehicle,typeOf _vehicle,_hitPointIndex,_hitPointDamage);
|
||||
if !(local _vehicle) exitWith {ERROR_1("Vehicle Not Local %1", _vehicle);};
|
||||
|
||||
// get all hitpoints and selections and damages
|
||||
(getAllHitPointsDamage _vehicle) params [["_allHitPoints", []], ["_allHitPointsSelections", []], ["_allHitPointDamages", []]];
|
||||
(getAllHitPointsDamage _vehicle) params ["", ["_hitSelections", []], ["_damageValues", []]];
|
||||
|
||||
([_vehicle] call FUNC(getSelectionsToIgnore)) params ["_selectionsToIgnore", "_dependsIndexMap"];
|
||||
|
||||
// exit if the hitpoint is not valid
|
||||
if ((_hitPointIndex < 0) || {_hitPointIndex >= (count _allHitPoints)}) exitWith {ERROR_2("NOT A VALID HITPOINT: %1-%2", _hitPointIndex,_vehicle);};
|
||||
if ((_hitPointIndex < 0) || {_hitPointIndex >= (count _hitSelections)}) exitWith {ERROR_2("NOT A VALID HITPOINT: %1-%2", _hitPointIndex,_vehicle);};
|
||||
|
||||
// save structural damage and sum of hitpoint damages
|
||||
|
||||
private _damageOld = damage _vehicle;
|
||||
|
||||
private _realHitpointCount = 0;
|
||||
private _realHitPointCount = 0;
|
||||
private _hitPointDamageSumOld = 0;
|
||||
private _hitPointDamageRepaired = 0; //positive for repairs : newSum = (oldSum - repaired)
|
||||
{
|
||||
private _selectionName = _allHitPointsSelections select _forEachIndex;
|
||||
//Filter out all the bad hitpoints (HitPoint="" or no selection)
|
||||
if ((!isNil {_vehicle getHit _selectionName}) && {_x != ""}) then {
|
||||
_realHitpointCount = _realHitpointCount + 1;
|
||||
|
||||
if ((((toLower _x) find "glass") == -1) && {(getText (configOf _vehicle >> "HitPoints" >> _x >> "depends")) in ["", "0"]}) then {
|
||||
_hitPointDamageSumOld = _hitPointDamageSumOld + (_allHitPointDamages select _forEachIndex);
|
||||
if (_forEachIndex == _hitPointIndex) then {
|
||||
_hitPointDamageRepaired = (_allHitPointDamages select _forEachIndex) - _hitPointDamage;
|
||||
};
|
||||
if (!(_forEachIndex in _selectionsToIgnore) && isNil{_dependsIndexMap get _forEachIndex}) then {
|
||||
_realHitPointCount = _realHitPointCount + 1;
|
||||
_hitPointDamageSumOld = _hitPointDamageSumOld + (_damageValues select _forEachIndex);
|
||||
if (_forEachIndex == _hitPointIndex) then {
|
||||
_hitPointDamageRepaired = (_damageValues select _forEachIndex) - _hitPointDamage;
|
||||
};
|
||||
};
|
||||
} forEach _allHitPoints;
|
||||
} forEach _hitSelections;
|
||||
|
||||
// calculate new structural damage
|
||||
private _damageNew = (_hitPointDamageSumOld - _hitPointDamageRepaired) / _realHitpointCount;
|
||||
private _damageNew = (_hitPointDamageSumOld - _hitPointDamageRepaired) / _realHitPointCount;
|
||||
|
||||
if (_hitPointDamageSumOld > 0) then {
|
||||
_damageNew = _damageOld * ((_hitPointDamageSumOld - _hitPointDamageRepaired) / _hitPointDamageSumOld);
|
||||
};
|
||||
TRACE_5("structuralDamage",_damageOld,_damageNew,_hitPointDamageRepaired,_hitPointDamageSumOld,_realHitpointCount);
|
||||
TRACE_5("structuralDamage",_damageOld,_damageNew,_hitPointDamageRepaired,_hitPointDamageSumOld,_realHitPointCount);
|
||||
|
||||
// set new structural damage value
|
||||
private _damageDisabled = !isDamageAllowed _vehicle;
|
||||
@ -70,12 +66,12 @@ if (_damageDisabled) then {
|
||||
_vehicle setDamage [_damageNew, _useEffects];
|
||||
|
||||
//Repair the hitpoint in the damages array:
|
||||
_allHitPointDamages set [_hitPointIndex, _hitPointDamage];
|
||||
_damageValues set [_hitPointIndex, _hitPointDamage];
|
||||
|
||||
//Set the new damage for all hitpoints
|
||||
{
|
||||
_vehicle setHitIndex [_forEachIndex, _x, _useEffects];
|
||||
} forEach _allHitPointDamages;
|
||||
} forEach _damageValues;
|
||||
|
||||
// normalize hitpoints
|
||||
[_vehicle] call FUNC(normalizeHitPoints);
|
||||
|
Loading…
Reference in New Issue
Block a user