2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-09-26 04:36:35 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
2017-08-10 11:32:55 +00:00
|
|
|
* Returns array of required nearby repair objects (wheels/tracks).
|
2015-09-26 04:36:35 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit that does the repairing <OBJECT>
|
2016-01-29 00:19:02 +00:00
|
|
|
* 1: Max range to seach from unit (meters) <NUMBER>
|
2015-09-26 04:36:35 +00:00
|
|
|
* 2: Array of arrays of classnames <ARRAY>
|
2023-11-21 01:43:43 +00:00
|
|
|
* 3: Sort objects by damage <BOOL> (default: false)
|
2015-09-26 04:36:35 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Array of objects, or [] if not all available <ARRAY>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, 5, [["Ace_Track"]]] call ace_repair_fnc_getClaimObjects
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
2023-11-21 01:43:43 +00:00
|
|
|
params ["_unit", "_maxRange", "_objectsToClaim", ["_sortByDamage", false]];
|
|
|
|
TRACE_4("params",_unit,_maxRange,_objectsToClaim,_sortByDamage);
|
2015-09-26 04:36:35 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
private _return = [];
|
2015-09-26 04:36:35 +00:00
|
|
|
|
|
|
|
{
|
2015-11-10 02:11:48 +00:00
|
|
|
private _requiredList = _x; //eg ["ace_track", "ace_track"]
|
2021-10-12 21:09:56 +00:00
|
|
|
private _ableToAquire = []; //will be array of objects
|
2015-09-26 04:36:35 +00:00
|
|
|
{
|
2021-10-12 21:09:56 +00:00
|
|
|
private _nearObjects = _unit nearEntities [_x, _maxRange];
|
2023-11-21 01:43:43 +00:00
|
|
|
if (_sortByDamage && {count _nearObjects > 1}) then {
|
|
|
|
_nearObjects = _nearObjects apply {[damage _x, _x]};
|
|
|
|
_nearObjects sort true;
|
|
|
|
_nearObjects = _nearObjects apply {_x select 1};
|
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
{
|
2021-10-12 21:09:56 +00:00
|
|
|
if (!(_x in _ableToAquire) && {(_x getVariable [QEGVAR(common,owner), objNull]) in [objNull, _unit]}) exitWith { // skip claimed objects
|
|
|
|
_ableToAquire pushBack _x
|
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
} forEach _nearObjects;
|
2021-10-12 21:09:56 +00:00
|
|
|
} forEach _requiredList;
|
2015-09-26 04:36:35 +00:00
|
|
|
TRACE_2("Check required equals available",_requiredList,_ableToAquire);
|
|
|
|
if ((count _ableToAquire) == (count _requiredList)) exitWith {_return = _ableToAquire};
|
2021-10-12 21:09:56 +00:00
|
|
|
} forEach _objectsToClaim;
|
2015-09-26 04:36:35 +00:00
|
|
|
|
|
|
|
_return
|