mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Switch to depends hashmap, non-ignored depends
Switched to depends hashmap, removed single-parent depends from ignored, removed now unnecessary multi-part names
This commit is contained in:
parent
d17dbe84ec
commit
8452fe012d
@ -31,7 +31,7 @@ if (_type in _initializedClasses) exitWith {};
|
||||
if (_type == "") exitWith {};
|
||||
|
||||
// get selections to ignore
|
||||
([_vehicle] call FUNC(getSelectionsToIgnore)) params ["_selectionsToIgnore", "_dependsArray"];
|
||||
([_vehicle] call FUNC(getSelectionsToIgnore)) params ["_selectionsToIgnore"];
|
||||
|
||||
// get all hitpoints and selections
|
||||
(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]]; // Since 1.82 these are all lower case
|
||||
@ -156,21 +156,6 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
|
||||
_hitPointsAddedStrings = _trackArray select 1;
|
||||
_hitPointsAddedAmount = _trackArray select 2;
|
||||
|
||||
{
|
||||
// Add names of depends hitpoints to the parent hitpoint
|
||||
if (_hitpoint == (_x select 0)) then {
|
||||
private _dependsHitpoint = (_x select 1);
|
||||
([_dependsHitpoint, "%1", _dependsHitpoint, [_hitPointsAddedNames, _hitPointsAddedStrings, _hitPointsAddedAmount]] call FUNC(getHitPointString)) params ["_dependsText", ""];
|
||||
_text = _text + " / " + _dependsText;
|
||||
};
|
||||
// Add name of parent hitpoint to the depends hitpoint
|
||||
if (_hitpoint == (_x select 1)) then {
|
||||
private _dependsParentHitpoint = (_x select 0);
|
||||
([_dependsParentHitpoint, "%1", _dependsParentHitpoint, [_hitPointsAddedNames, _hitPointsAddedStrings, _hitPointsAddedAmount]] call FUNC(getHitPointString)) params ["_dependsParentText", ""];
|
||||
_text = _dependsParentText + " / " + _text;
|
||||
};
|
||||
} forEach _dependsArray;
|
||||
|
||||
if (_hitpoint in TRACK_HITPOINTS) then {
|
||||
_position = compile format ["private _return = _target selectionPosition ['%1', 'HitPoints']; _return set [1, 0]; _return", _selection];
|
||||
TRACE_4("Adding RepairTrack",_hitpoint,_forEachIndex,_selection,_text);
|
||||
|
@ -26,7 +26,7 @@ private _postRepairDamageMin = [_unit, _action isEqualTo "fullRepair"] call FUNC
|
||||
|
||||
(getAllHitPointsDamage _vehicle) params ["_allHitPoints"];
|
||||
private _hitPointClassname = _allHitPoints select _hitPointIndex;
|
||||
private _initializedDepends = missionNamespace getVariable [QGVAR(dependsHitPointsInitializedClasses), createHashMap];
|
||||
(GETMVAR(GVAR(ignoredAndDependsInitializedClasses), objNull) get typeOf _vehicle) params ["","_dependsIndexMap"];
|
||||
private _repairedHitpoints = [];
|
||||
|
||||
// get current hitpoint damage
|
||||
@ -36,10 +36,24 @@ private _hitPointCurDamage = _vehicle getHitIndex _hitPointIndex;
|
||||
private _hitPointNewDamage = (_hitPointCurDamage - 0.5) max _postRepairDamageMin;
|
||||
|
||||
if (_hitPointNewDamage < _hitPointCurDamage) then {
|
||||
// raise event to set the new hitpoint damage
|
||||
TRACE_3("repairing main point", _vehicle, _hitPointIndex, _hitPointNewDamage);
|
||||
[QGVAR(setVehicleHitPointDamage), [_vehicle, _hitPointIndex, _hitPointNewDamage], _vehicle] call CBA_fnc_targetEvent;
|
||||
_hitPointCurDamage = _hitPointNewDamage;
|
||||
private _parentIndex = _dependsIndexMap get _hitPointIndex;
|
||||
if (isNil "_parentIndex") then {
|
||||
// raise event to set the new hitpoint damage
|
||||
TRACE_3("repairing main point", _vehicle, _hitPointIndex, _hitPointNewDamage);
|
||||
[QGVAR(setVehicleHitPointDamage), [_vehicle, _hitPointIndex, _hitPointNewDamage], _vehicle] call CBA_fnc_targetEvent;
|
||||
_hitPointCurDamage = _hitPointNewDamage;
|
||||
} else {
|
||||
// Fix damagable depends hitpoints with ignored parent (current hitpoint gets normalized)
|
||||
private _parentHitpointCurDamage = _vehicle getHitIndex _parentIndex;
|
||||
private _parentHitpointNewDamage = _parentHitpointCurDamage;
|
||||
if (_parentHitpointCurDamage > _postRepairDamageMin) then {
|
||||
_parentHitpointNewDamage = (_parentHitpointCurDamage - 0.5) max _postRepairDamageMin;
|
||||
};
|
||||
_repairedHitpoints pushBack _parentIndex;
|
||||
TRACE_4("Repairing depends and parent", _vehicle, _hitPointIndex, _parentIndex, _parentHitpointNewDamage);
|
||||
[QGVAR(setVehicleHitPointDamage), [_vehicle, _parentIndex, _parentHitpointNewDamage], _vehicle] call CBA_fnc_targetEvent;
|
||||
_hitPointCurDamage = _parentHitpointNewDamage;
|
||||
};
|
||||
};
|
||||
|
||||
// Get hitpoint groups if available
|
||||
@ -56,12 +70,16 @@ if (isArray _hitpointGroupConfig) then {
|
||||
if (_subHitIndex == -1) then {
|
||||
ERROR_2("Invalid hitpoint %1 in hitpointGroups of %2",_subHitpoint,_vehicle);
|
||||
} else {
|
||||
private _subPointCurDamage = _vehicle getHitIndex _hitPointIndex;
|
||||
private _subPointNewDamage = (_subPointCurDamage - 0.5) max _postRepairDamageMin;
|
||||
if (_subPointNewDamage < _subPointCurDamage) then {
|
||||
TRACE_3("repairing sub point", _vehicle, _subHitIndex, _subPointNewDamage);
|
||||
_repairedHitpoints pushBack _subHitIndex;
|
||||
[QGVAR(setVehicleHitPointDamage), [_vehicle, _subHitIndex, _subPointNewDamage], _vehicle] call CBA_fnc_targetEvent;
|
||||
if (_subHitIndex in _repairedHitpoints) then {
|
||||
TRACE_2("Skipping repair, sub hitpoint already fixed in depends",_subHitIndex,_vehicle);
|
||||
} else {
|
||||
private _subPointCurDamage = _vehicle getHitIndex _hitPointIndex;
|
||||
private _subPointNewDamage = (_subPointCurDamage - 0.5) max _postRepairDamageMin;
|
||||
if (_subPointNewDamage < _subPointCurDamage) then {
|
||||
TRACE_3("repairing sub point", _vehicle, _subHitIndex, _subPointNewDamage);
|
||||
_repairedHitpoints pushBack _subHitIndex;
|
||||
[QGVAR(setVehicleHitPointDamage), [_vehicle, _subHitIndex, _subPointNewDamage], _vehicle] call CBA_fnc_targetEvent;
|
||||
};
|
||||
};
|
||||
};
|
||||
} forEach _subHitArray;
|
||||
@ -69,31 +87,6 @@ if (isArray _hitpointGroupConfig) then {
|
||||
} forEach (getArray _hitpointGroupConfig);
|
||||
};
|
||||
|
||||
// Fix damagable depends hitpoints with ignored parent
|
||||
private _type = typeOf _vehicle;
|
||||
private _vehicleDependsArray = _initializedDepends get _type;
|
||||
{
|
||||
_x params ["_parentHitpoint","_dependsHitpoint"];
|
||||
if (_hitPointClassname == _dependsHitpoint) exitWith {
|
||||
private _dependsIndex = _allHitPoints findIf {_x == _dependsHitpoint};
|
||||
private _parentIndex = _allHitPoints findIf {_x == _parentHitpoint};
|
||||
if (_parentIndex in _repairedHitpoints) then {
|
||||
TRACE_2("Skipping repair, depends parent fixed in hitpoint groups",_parentHitpoint,_vehicle);
|
||||
continue;
|
||||
} else {
|
||||
private _parentHitpointCurDamage = _vehicle getHitIndex _parentIndex;
|
||||
private _parentHitpointNewDamage = (_parentHitpointCurDamage - 0.5) max _postRepairDamageMin;
|
||||
private _dependsHitpointCurDamage = _vehicle getHitIndex _dependsIndex;
|
||||
private _dependsHitpointNewDamage = (_dependsHitpointCurDamage - 0.5) max _postRepairDamageMin;
|
||||
if (_parentHitpointNewDamage < _parentHitpointCurDamage
|
||||
|| _dependsHitpointNewDamage < _dependsHitpointCurDamage) then {
|
||||
TRACE_4("Repairing depends parent", _vehicle, _dependsIndex, _parentIndex, _parentHitpointNewDamage);
|
||||
[QGVAR(setVehicleHitPointDamage), [_vehicle, _parentIndex, _parentHitpointNewDamage], _vehicle] call CBA_fnc_targetEvent;
|
||||
};
|
||||
};
|
||||
};
|
||||
} forEach _vehicleDependsArray;
|
||||
|
||||
// display text message if enabled
|
||||
if (GVAR(DisplayTextOnRepair)) then {
|
||||
// Find localized string
|
||||
|
@ -19,11 +19,10 @@ params ["_vehicle"];
|
||||
|
||||
private _type = typeOf _vehicle;
|
||||
TRACE_2("getSelectionsToIgnore",_vehicle,_type);
|
||||
private _initializedClasses = missionNamespace getVariable [QGVAR(hitPointsToIgnoreInitializedClasses), createHashMap];
|
||||
private _initializedDepends = missionNamespace getVariable [QGVAR(dependsHitPointsInitializedClasses), createHashMap];
|
||||
private _initializedClasses = GETMVAR(GVAR(ignoredAndDependsInitializedClasses), createHashMap);
|
||||
if (_type in _initializedClasses) exitWith {
|
||||
TRACE_2("retrieved chached selections",_vehicle,_type);
|
||||
[_initializedClasses get _type, _initializedDepends get _type];
|
||||
TRACE_2("retrieved cached selections",_vehicle,_type);
|
||||
_initializedClasses get _type;
|
||||
}; //you return different amount of values each time
|
||||
|
||||
private _vehCfg = configOf _vehicle;
|
||||
@ -35,7 +34,7 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
|
||||
([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];
|
||||
|
||||
private _indexesToIgnore = [];
|
||||
private _dependsArray = [];
|
||||
private _dependsIndexMap = createHashMap;
|
||||
private _processedSelections = [];
|
||||
|
||||
{
|
||||
@ -129,17 +128,20 @@ private _processedSelections = [];
|
||||
/*#ifdef DEBUG_MODE_FULL
|
||||
systemChat format ["Skipping depends hitpoint, hitpoint %1, index %2, selection %3", _hitpoint, _forEachIndex, _selection];
|
||||
#endif*/
|
||||
|
||||
private _groupIndex = _hitpointGroups findIf {_x # 0 == _hitpoint};
|
||||
if (_groupIndex != -1) then {
|
||||
ERROR_2("[%1] hitpoint [%2] is both a group-parent and a depends and will be unrepairable",_type,_hitpoint);
|
||||
ERROR_1("group: %1",_hitpointGroups # _groupIndex);
|
||||
};
|
||||
private _parentHitpoint = getText (_vehCfg >> "HitPoints" >> _hitpoint >> "depends");
|
||||
_parentHitpoint = toLower _parentHitpoint;
|
||||
_dependsArray pushBack [_parentHitpoint, _hitpoint];
|
||||
private _parentHitpointIndex = _hitPoints findIf {_x == _parentHitpoint};
|
||||
|
||||
_indexesToIgnore pushBack _forEachIndex;
|
||||
if (_parentHitpointIndex != -1) then {
|
||||
_dependsIndexMap set [_forEachIndex, _parentHitpointIndex];
|
||||
} else { // multiple parents or incorrect parent
|
||||
_indexesToIgnore pushBack _forEachIndex;
|
||||
private _groupIndex = _hitpointGroups findIf {_x # 0 == _hitpoint};
|
||||
if (_groupIndex != -1) then {
|
||||
ERROR_2("[%1] hitpoint [%2] is both a group-parent and an ignored depends and will be unrepairable",_type,_hitpoint);
|
||||
ERROR_1("group: %1",_hitpointGroups # _groupIndex);
|
||||
};
|
||||
};
|
||||
_processedSelections pushBack _selection;
|
||||
continue
|
||||
};
|
||||
@ -157,22 +159,7 @@ private _processedSelections = [];
|
||||
_processedSelections pushBack _selection;
|
||||
} forEach _hitSelections;
|
||||
|
||||
// Remove depends hitpoints with ignored parents from ignore list
|
||||
{
|
||||
_x params ["_parentHitpoint", "_dependsHitpoint"];
|
||||
private _parentIndex = _hitPoints findIf {_parentHitpoint == _x};
|
||||
private _dependsIndex = _hitPoints findIf {_dependsHitpoint == _x};
|
||||
if (_parentIndex in _indexesToIgnore) then {
|
||||
TRACE_2("Removing depends hitpoint from ignored",_dependsHitpoint,_dependsIndex);
|
||||
private _dependsIgnoreArrayIndex = _indexesToIgnore findIf {_dependsIndex == _x};
|
||||
_indexesToIgnore deleteAt _dependsIgnoreArrayIndex;
|
||||
};
|
||||
} forEach _dependsArray;
|
||||
_initializedClasses set [_type, [_indexesToIgnore, _dependsIndexMap]];
|
||||
SETMVAR(GVAR(ignoredAndDependsInitializedClasses), _initializedClasses);
|
||||
|
||||
_initializedClasses set [_type, _indexesToIgnore];
|
||||
missionNamespace setVariable [QGVAR(hitPointsToIgnoreInitializedClasses), _initializedClasses];
|
||||
|
||||
_initializedDepends set [_type, _dependsArray];
|
||||
missionNamespace setVariable [QGVAR(dependsHitPointsInitializedClasses), _initializedDepends];
|
||||
|
||||
[_indexesToIgnore, _dependsArray]
|
||||
[_indexesToIgnore, _dependsIndexMap]
|
||||
|
Loading…
Reference in New Issue
Block a user