Repair - Use object with lowest damage for changing wheels/tracks (#9648)

sort claimObject by damage
This commit is contained in:
Grim 2023-11-20 22:43:43 -03:00 committed by GitHub
parent ac9044f2d6
commit 99ccf31807
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -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>
@ -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 = [];
@ -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

View File

@ -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