ACE3/addons/csw/functions/fnc_getNearbySources.sqf

54 lines
1.6 KiB
Plaintext
Raw Normal View History

2023-12-18 16:47:01 +00:00
#include "..\script_component.hpp"
2023-07-01 17:33:42 +00:00
/*
* Author: LinkIsGrim
2023-12-18 16:47:01 +00:00
* Gets available ammo sources for loading a CSW.
2023-07-01 17:33:42 +00:00
*
* Arguments:
2023-07-13 11:51:26 +00:00
* 0: Unit or vehicle attempting to load <OBJECT>
* 1: Skip vehicle sources <BOOL> (default: false)
* 2: Include CSW crew <BOOL> (default: false)
2023-07-01 17:33:42 +00:00
*
* Return Value:
* Ammo sources <ARRAY of OBJECT>
*
* Example:
* [player] call ace_csw_fnc_getNearbySources
*
* Public: No
*/
2023-12-18 16:47:01 +00:00
2023-07-13 11:51:26 +00:00
[_this, {
params ["_unit", ["_skipVehicles", false], ["_includeCrew", false]];
2023-12-18 16:47:01 +00:00
private _nearSupplies = (_unit nearSupplies DISTANCE_SEARCH_RADIUS) select {
2023-07-01 17:33:42 +00:00
isNull (group _x) ||
{!(_x call EFUNC(common,isPlayer)) && {[side group _unit, side group _x] call BIS_fnc_sideIsFriendly}}
2023-07-01 17:33:42 +00:00
};
2023-07-13 11:51:26 +00:00
if (_includeCrew) then {
_nearSupplies append (crew _unit);
};
if (_skipVehicles) then {
_nearSupplies = _nearSupplies select {
private _source = _x;
(["Ship", "Car", "Air", "Tank"] findIf {_source isKindOf _x}) == -1
};
};
_nearSupplies pushBackUnique _unit;
2023-07-01 17:33:42 +00:00
{
if (_x isKindOf "CAManBase") then {
_nearSupplies append [uniformContainer _x, vestContainer _x, backpackContainer _x];
continue;
};
{
_x params ["", "_container"];
_nearSupplies pushBack _container;
} forEach (everyContainer _x);
} forEach _nearSupplies;
_nearSupplies select {!(_x isKindOf "CAManBase")} // return
2023-07-13 11:51:26 +00:00
}, _this select 0, QGVAR(nearbySourcesCache), NEARBY_SOURCES_CACHE_EXPIRY, QGVAR(clearNearbySourcesCache)] call EFUNC(common,cachedCall);