Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair - Fix adding actions for hitpoints with the same name #9430

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/repair/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PREP(fullRepairProgress);
PREP(getClaimObjects);
PREP(getFullRepairTime);
PREP(getHitPointString);
PREP(getHitPointsToIgnore);
PREP(getSelectionsToIgnore);
PREP(getPatchWheelTime);
PREP(getPostRepairDamage);
PREP(getRepairItems);
Expand Down
26 changes: 9 additions & 17 deletions addons/repair/functions/fnc_addRepairActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ TRACE_2("addRepairActions", _vehicle,_type);
private _initializedClasses = GETMVAR(GVAR(initializedClasses),[]);
if (_type in _initializedClasses) exitWith {};

// get hitPoints to ignore
private _hitPointsToIgnore = [_vehicle] call FUNC(getHitPointsToIgnore);
// get selections to ignore
private _selectionsToIgnore = _vehicle call FUNC(getSelectionsToIgnore);

// get all hitpoints and selections
(getAllHitPointsDamage _vehicle) params [["_hitPoints", []], ["_hitSelections", []]]; // Since 1.82 these are all lower case
Expand All @@ -41,7 +41,6 @@ private _hitPointsToIgnore = [_vehicle] call FUNC(getHitPointsToIgnore);
private _hitPointsAddedNames = [];
private _hitPointsAddedStrings = [];
private _hitPointsAddedAmount = [];
private _processedSelections = [];
private _icon = ["a3\ui_f\data\igui\cfg\actions\repair_ca.paa", "#FFFFFF"];

private _vehCfg = configOf _vehicle;
Expand All @@ -53,10 +52,14 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
{
private _selection = _x;
private _hitpoint = toLower (_hitPoints select _forEachIndex);
if (_selection in _wheelHitSelections) then {
// Wheels should always be unique
if (_selection in _processedSelections) exitWith {TRACE_3("Duplicate Wheel",_hitpoint,_forEachIndex,_selection);};

// Skip ignored selections
if (_forEachIndex in _selectionsToIgnore) then {
TRACE_3("Skipping ignored hitpoint",_hitpoint,_forEachIndex,_selection);
continue
};

if (_selection in _wheelHitSelections) then {
private _position = compile format ["_target selectionPosition ['%1', 'HitPoints', 'AveragePoint'];", _selection];

TRACE_3("Adding Wheel Actions",_hitpoint,_forEachIndex,_selection);
Expand Down Expand Up @@ -90,14 +93,7 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
private _statement = {[_this select 1, _this select 0, _this select 2 select 0, "PatchWheel"] call DFUNC(repair)};
private _action = [_name, _text, _patchIcon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction);
[_type, 0, [_root], _action] call EFUNC(interact_menu,addActionToClass);

_processedSelections pushBack _selection;
} else {
// Skip ignored hitpoints
if (_hitpoint in _hitPointsToIgnore) exitWith {
TRACE_3("Skipping ignored hitpoint",_hitpoint,_forEachIndex,_selection);
};

// Some hitpoints do not have a selection but do have an armorComponent value (seems to mainly be RHS)
// Ref https://community.bistudio.com/wiki/Arma_3_Damage_Enhancement
// this code won't support identically named hitpoints (e.g. commander turret: Duplicate HitPoint name 'HitTurret')
Expand Down Expand Up @@ -156,8 +152,6 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
_hitPointsAddedAmount = _trackArray select 2;

if (_hitpoint in TRACK_HITPOINTS) then {
// Tracks should always be unique
if (_selection in _processedSelections) exitWith {TRACE_3("Duplicate Track",_hitpoint,_forEachIndex,_selection);};
_position = compile format ["private _return = _target selectionPosition ['%1', 'HitPoints']; _return set [1, 0]; _return", _selection];
TRACE_4("Adding RepairTrack",_hitpoint,_forEachIndex,_selection,_text);
private _condition = {[_this select 1, _this select 0, _this select 2 select 0, "RepairTrack"] call DFUNC(canRepair)};
Expand All @@ -176,8 +170,6 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
[_type, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
};
};

_processedSelections pushBack _selection;
};
} forEach _hitSelections;

Expand Down
5 changes: 2 additions & 3 deletions addons/repair/functions/fnc_fullRepairProgress.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ if (_totalTime - _elapsedTime > ([_engineer, _vehicle] call FUNC(getFullRepairTi
private _allHitPointsDamage = getAllHitPointsDamage _vehicle;
_allHitPointsDamage params ["_hitPoints", "", "_damageValues"];

private _hitPointsToIgnore = [_vehicle] call FUNC(getHitPointsToIgnore);
private _selectionsToIgnore = _vehicle call FUNC(getSelectionsToIgnore);

private _firstDamagedIndex = {
private _hitPoint = _hitPoints select _forEachIndex;
if (_x > 0 && {!(_hitPoint in _hitPointsToIgnore)}) exitWith {_forEachIndex};
if (_x > 0 && {!(_forEachIndex in _selectionsToIgnore)}) exitWith {_forEachIndex};
-1
} forEach _damageValues;

Expand Down
5 changes: 2 additions & 3 deletions addons/repair/functions/fnc_getFullRepairTime.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ params ["_engineer", "_vehicle"];
private _allHitPointsDamage = getAllHitPointsDamage _vehicle;
_allHitPointsDamage params ["_hitPoints", "", "_damageValues"];

private _hitPointsToIgnore = [_vehicle] call FUNC(getHitPointsToIgnore);
private _selectionsToIgnore = _vehicle call FUNC(getSelectionsToIgnore);

private _repairsNeeded = 0;
private _doExtraRepair = false;
{
if (_x <= 0) then {continue}; // skip hitpoints that don't need repairs
private _hitPoint = _hitPoints select _forEachIndex;
if (_hitPoint in _hitPointsToIgnore) then { // only add extra repair for ignore hitpoints if they're damaged
if (_forEachIndex in _selectionsToIgnore) then { // only add extra repair for ignore hitpoints if they're damaged
_doExtraRepair = true;
continue
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
* HitPoints to ignore <ARRAY>
*
* Example:
* [vehicle] call ace_repair_fnc_getHitpointsToIgnore
* [vehicle] call ace_repair_fnc_getSelectionsToIgnore
*
* Public: No
*/

params ["_vehicle"];

private _type = typeOf _vehicle;
TRACE_2("getHitPointsToIgnore",_vehicle,_type);
TRACE_2("getSelectionsToIgnore",_vehicle,_type);
private _initializedClasses = missionNamespace getVariable [QGVAR(hitPointsToIgnoreInitializedClasses), createHashMap];
if (_type in _initializedClasses) exitWith {_initializedClasses get _type};

Expand All @@ -30,7 +30,7 @@ private _turretPaths = ((fullCrew [_vehicle, "gunner", true]) + (fullCrew [_vehi
// get hitpoints of wheels with their selections
([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitSelections"];

private _hitPointsToIgnore = [""]; // always ignore empty hitpoints
private _indexesToIgnore = [];
private _processedSelections = [];

{
Expand All @@ -39,6 +39,7 @@ private _processedSelections = [];
private _isWheelOrTrack = _selection in _wheelHitSelections || {_hitpoint in _wheelHitPoints} || {_hitpoint in TRACK_HITPOINTS};

if (_hitpoint isEqualTo "") then { // skip empty hitpoint
_indexesToIgnore pushBack _forEachIndex;
continue
};

Expand All @@ -47,7 +48,7 @@ private _processedSelections = [];
/*#ifdef DEBUG_MODE_FULL
systemChat format ["Skipping duplicate wheel, hitpoint %1, index %2, selection %3", _hitpoint, _forEachIndex, _selection];
#endif*/
_hitPointsToIgnore pushBackUnique _hitpoint;
_indexesToIgnore pushBack _forEachIndex;
_processedSelections pushBack _selection;
continue
};
Expand All @@ -57,7 +58,7 @@ private _processedSelections = [];
/*#ifdef DEBUG_MODE_FULL
systemChat format ["Skipping glass, hitpoint %1, index %2, selection %3", _hitpoint, _forEachIndex, _selection];
#endif*/
_hitPointsToIgnore pushBackUnique _hitpoint;
_indexesToIgnore pushBack _forEachIndex;
_processedSelections pushBack _selection;
continue
};
Expand All @@ -67,7 +68,7 @@ private _processedSelections = [];
/*#ifdef DEBUG_MODE_FULL
systemChat format ["Skipping ERA/SLAT, hitpoint %1, index %2, selection %3", _hitpoint, _forEachIndex, _selection];
#endif*/
_hitPointsToIgnore pushBackUnique _hitpoint;
_indexesToIgnore pushBack _forEachIndex;
_processedSelections pushBack _selection;
continue
};
Expand All @@ -79,16 +80,29 @@ private _processedSelections = [];
private _hitpointsCfg = "configName _x == _hitpoint" configClasses _turretHitpointCfg;
if (_hitpointsCfg isNotEqualTo []) exitWith {
TRACE_2("turret hitpoint configFound",_hitpoint,_x);
_hitpointsCfg = _hitpointsCfg # 0;
// only do turret hitpoints and stuff linked to visuals
if ((_hitpoint in ["hitturret", "hitgun"]) || {(getNumber (_hitpointsCfg # 0 >> "isGun")) == 1} || {(getNumber (_hitpointsCfg # 0 >> "isTurret")) == 1} || {(getText (_hitpointsCfg # 0 >> "visual")) != ""}) then {
_armorComponent = getText (_hitpointsCfg # 0 >> "armorComponent");
if (
(_hitpoint in ["hitturret", "hitgun"]) ||
{(getNumber (_hitpointsCfg >> "isGun")) == 1} ||
{(getNumber (_hitpointsCfg >> "isTurret")) == 1} ||
{(getText (_hitpointsCfg >> "visual")) != ""}
) then {
_armorComponent = getText (_hitpointsCfg >> "armorComponent");
};
};
} forEach _turretPaths;
if (_armorComponent == "") then {
private _hitpointsCfg = "configName _x == _hitpoint" configClasses (_vehCfg >> "HitPoints");
if (_hitpointsCfg isNotEqualTo [] && {(getText (_hitpointsCfg # 0 >> "visual")) != ""}) then {
_armorComponent = getText (_hitpointsCfg # 0 >> "armorComponent");
if (_hitpointsCfg isNotEqualTo []) then {
_hitpointsCfg = _hitpointsCfg # 0;
if (
(getNumber (_hitpointsCfg >> "isGun")) == 1 ||
{(getNumber (_hitpointsCfg >> "isTurret")) == 1} ||
{(getText (_hitpointsCfg >> "visual")) != ""}
) then {
_armorComponent = getText (_hitpointsCfg >> "armorComponent");
};
};
};
};
Expand All @@ -98,7 +112,7 @@ private _processedSelections = [];
/*#ifdef DEBUG_MODE_FULL
systemChat format ["Skipping no selection OR armor component, hitpoint %1, index %2, selection %3", _hitpoint, _forEachIndex, _selection];
#endif*/
_hitPointsToIgnore pushBackUnique _hitpoint;
_indexesToIgnore pushBack _forEachIndex;
_processedSelections pushBack _selection;
continue
};
Expand All @@ -115,7 +129,7 @@ private _processedSelections = [];
ERROR_1("group: %1",_hitpointGroups # _groupIndex);
};

_hitPointsToIgnore pushBackUnique _hitpoint;
_indexesToIgnore pushBack _forEachIndex;
_processedSelections pushBack _selection;
continue
};
Expand All @@ -125,15 +139,15 @@ private _processedSelections = [];
/*#ifdef DEBUG_MODE_FULL
systemChat format ["Skipping child hitpoint, hitpoint %1, index %2, selection %3", _hitpoint, _forEachIndex, _selection];
#endif*/
_hitPointsToIgnore pushBackUnique _hitpoint;
_indexesToIgnore pushBack _forEachIndex;
_processedSelections pushBack _selection;
continue
};

_processedSelections pushBack _selection;
} forEach _hitSelections;

_initializedClasses set [_type, _hitPointsToIgnore];
_initializedClasses set [_type, _indexesToIgnore];
missionNamespace setVariable [QGVAR(hitPointsToIgnoreInitializedClasses), _initializedClasses];

_hitPointsToIgnore
_indexesToIgnore