2019-06-08 04:47:39 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
/*
|
2023-07-01 15:39:42 +00:00
|
|
|
* Author: PabstMirror, LinkIsGrim
|
|
|
|
* Gets nearby magazines that can be loaded in the static weapon
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Vehicle <OBJECT>
|
|
|
|
* 1: Player <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Mags <ARRAY>
|
2022-03-07 18:29:19 +00:00
|
|
|
* [Carry Magazine <STRING>, Turret Path <ARRAY>, Load Info <NUMBER>, Magazine Source <OBJECT>]
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [cursorObject, player] call ace_csw_fnc_reload_getLoadableMagazines
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_vehicle", "_player"];
|
|
|
|
|
2022-03-07 18:29:19 +00:00
|
|
|
private _magGroupsConfig = configFile >> QGVAR(groups); // so we don't solve in loop every time
|
|
|
|
private _availableMagazines = createHashMap; // slower than array, still needed for setting source of magazine
|
2019-06-08 04:47:39 +00:00
|
|
|
|
2022-03-07 18:29:19 +00:00
|
|
|
// filter enemy & player units while allowing pulling from friendly AI, crates, etc
|
2023-07-01 15:39:42 +00:00
|
|
|
private _nearSupplies = (_vehicle nearSupplies 5) select {
|
2022-03-07 18:29:19 +00:00
|
|
|
isNull (group _x) ||
|
|
|
|
{!([_x] call EFUNC(common,isPlayer)) && {[side group _player, side group _x] call BIS_fnc_sideIsFriendly}}
|
2023-07-01 15:39:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// add caller to nearSupplies since players will get filtered out
|
|
|
|
_nearSupplies pushBack _player;
|
|
|
|
|
|
|
|
// send the mag source with the highest ammo
|
|
|
|
private _bestMagAmmo = createHashMap;
|
2022-03-07 18:29:19 +00:00
|
|
|
|
2019-06-08 04:47:39 +00:00
|
|
|
{
|
2023-07-01 15:39:42 +00:00
|
|
|
if (_x isKindOf "CAManBase") then {
|
|
|
|
// unit inventory needs to be added manually
|
|
|
|
_nearSupplies append [uniformContainer _x, vestContainer _x, backpackContainer _x];
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
private _xSource = _x;
|
|
|
|
private _cswMags = (magazinesAmmoCargo _xSource) select {isClass (_magGroupsConfig >> _x select 0)};
|
|
|
|
|
|
|
|
// add containers inside containers
|
2022-03-07 18:29:19 +00:00
|
|
|
{
|
|
|
|
_x params ["_classname", "_container"];
|
|
|
|
_nearSupplies pushBack _container;
|
|
|
|
} forEach (everyContainer _x);
|
|
|
|
|
|
|
|
{
|
2023-07-01 15:39:42 +00:00
|
|
|
_x params ["_classname", "_ammo"];
|
|
|
|
if (_ammo > (_bestMagAmmo getOrDefault [_classname, 0])) then {
|
|
|
|
_bestMagAmmo set [_classname, _ammo];
|
|
|
|
_availableMagazines set [_classname, _xSource];
|
|
|
|
};
|
|
|
|
} forEach _cswMags;
|
2022-03-07 18:29:19 +00:00
|
|
|
} forEach _nearSupplies;
|
2019-06-08 04:47:39 +00:00
|
|
|
|
2022-03-07 18:29:19 +00:00
|
|
|
if (_availableMagazines isEqualTo createHashMap) exitWith { [] }; // fast exit if no available mags
|
2019-06-08 04:47:39 +00:00
|
|
|
|
|
|
|
private _loadInfo = [];
|
|
|
|
private _return = [];
|
|
|
|
// Go through turrets and find weapons that we could reload
|
|
|
|
{
|
|
|
|
private _turretPath = _x;
|
|
|
|
{
|
|
|
|
private _weapon = _x;
|
|
|
|
{
|
2022-03-07 18:29:19 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING ["_x", "_y"];
|
2019-06-08 04:47:39 +00:00
|
|
|
private _carryMag = _x;
|
2022-03-07 18:29:19 +00:00
|
|
|
private _magSource = _y;
|
|
|
|
private _carryGroup = _magGroupsConfig >> _carryMag;
|
2019-06-08 04:47:39 +00:00
|
|
|
{
|
2022-03-07 18:29:19 +00:00
|
|
|
if (
|
|
|
|
((getNumber (_carryGroup >> _x)) == 1) &&
|
|
|
|
{_loadInfo = [_vehicle, _turretPath, _carryMag, _magSource] call FUNC(reload_canLoadMagazine); _loadInfo select 0}
|
|
|
|
) exitWith {
|
2023-07-01 15:39:42 +00:00
|
|
|
_return pushBack [_carryMag, _turretPath, _loadInfo, _magSource, _player];
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
2023-07-01 15:39:42 +00:00
|
|
|
} forEach (compatibleMagazines _weapon);
|
2022-03-07 18:29:19 +00:00
|
|
|
} forEach _availableMagazines;
|
2019-06-08 04:47:39 +00:00
|
|
|
} forEach (_vehicle weaponsTurret _turretPath);
|
|
|
|
} forEach (allTurrets _vehicle);
|
|
|
|
// Note: these nested forEach's looks terrible, but most only have one element
|
|
|
|
|
|
|
|
_return
|