Skip to content

Commit

Permalink
Repair - Use object with lowest damage for changing wheels/tracks (#9648
Browse files Browse the repository at this point in the history
)

sort claimObject by damage
  • Loading branch information
LinkIsGrim authored Nov 21, 2023
1 parent ac9044f commit 99ccf31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions addons/repair/functions/fnc_getClaimObjects.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* 0: Unit that does the repairing <OBJECT>
* 1: Max range to seach from unit (meters) <NUMBER>
* 2: Array of arrays of classnames <ARRAY>
* 3: Sort objects by damage <BOOL> (default: false)
*
* Return Value:
* Array of objects, or [] if not all available <ARRAY>
Expand All @@ -17,8 +18,8 @@
* Public: Yes
*/

params ["_unit", "_maxRange", "_objectsToClaim"];
TRACE_3("params",_unit,_maxRange,_objectsToClaim);
params ["_unit", "_maxRange", "_objectsToClaim", ["_sortByDamage", false]];
TRACE_4("params",_unit,_maxRange,_objectsToClaim,_sortByDamage);

private _return = [];

Expand All @@ -27,6 +28,11 @@ private _return = [];
private _ableToAquire = []; //will be array of objects
{
private _nearObjects = _unit nearEntities [_x, _maxRange];
if (_sortByDamage && {count _nearObjects > 1}) then {
_nearObjects = _nearObjects apply {[damage _x, _x]};
_nearObjects sort true;
_nearObjects = _nearObjects apply {_x select 1};
};
{
if (!(_x in _ableToAquire) && {(_x getVariable [QEGVAR(common,owner), objNull]) in [objNull, _unit]}) exitWith { // skip claimed objects
_ableToAquire pushBack _x
Expand Down
2 changes: 1 addition & 1 deletion addons/repair/functions/fnc_repair.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if (!("All" in _repairLocations)) then {
private _requiredObjects = getArray (_config >> "claimObjects");
private _claimObjectsAvailable = [];
if (_requiredObjects isNotEqualTo []) then {
_claimObjectsAvailable = [_caller, 5, _requiredObjects] call FUNC(getClaimObjects);
_claimObjectsAvailable = [_caller, 5, _requiredObjects, true] call FUNC(getClaimObjects);
if (_claimObjectsAvailable isEqualTo []) then {
TRACE_2("Missing Required Objects",_requiredObjects,_claimObjectsAvailable);
_return = false
Expand Down

0 comments on commit 99ccf31

Please sign in to comment.