ACE3/addons/csw/functions/fnc_getAvailableAmmo.sqf

63 lines
1.7 KiB
Plaintext
Raw Normal View History

2023-12-18 16:47:01 +00:00
#include "..\script_component.hpp"
2023-07-13 11:51:26 +00:00
/*
* Author: LinkIsGrim
2023-12-18 16:47:01 +00:00
* Gets available ammo for a CSW.
2023-07-13 11:51:26 +00:00
*
* Arguments:
* 0: CSW <OBJECT>
* 1: Only loaded magazines <BOOL> (default: false)
* 2: Skip ammo from vehicles <BOOL> (default: true)
* 3: Include CSW crew <BOOL> (default: true)
*
* Return Value:
2023-12-22 22:03:33 +00:00
* Available Ammo <HASHMAP>
2023-07-13 11:51:26 +00:00
* Magazine classname <STRING>
* Total Ammo <NUMBER>
*
* Example:
* [cursorObject] call ace_csw_fnc_getAvailableAmmo
*
* Public: Yes
*/
2023-12-18 16:47:01 +00:00
2023-07-13 11:51:26 +00:00
params [["_vehicle", objNull, [objNull]], ["_onlyLoaded", false, [false]], ["_skipVehicles", true, [true]], ["_includeCrew", true, [true]]];
if (isNull _vehicle) exitWith {createHashMap};
private _availableMagazines = createHashMap;
private _fnc_addAmmo = {
params ["_magazine", "_ammo"];
if !(_magazine in _availableMagazines) then {
_availableMagazines set [_magazine, _ammo];
} else {
_availableMagazines set [_magazine, (_availableMagazines get _magazine) + _ammo];
};
};
{
_x params ["_xMag", "", "_xAmmo"];
2023-07-16 18:43:43 +00:00
if (_xAmmo <= 0) then {continue};
2023-07-13 11:51:26 +00:00
private _carryMag = _xMag call FUNC(getCarryMagazine);
if (_carryMag isEqualTo "") then {continue};
[_carryMag, _xAmmo] call _fnc_addAmmo
} forEach (magazinesAllTurrets _vehicle);
if (_onlyLoaded) exitWith {_availableMagazines};
[QGVAR(clearNearbySourcesCache), []] call CBA_fnc_localEvent;
private _sources = [_vehicle, _skipVehicles, _includeCrew] call FUNC(getNearbySources);
if (_sources isEqualTo []) exitWith {_availableMagazines};
{
private _source = _x;
{
_x call _fnc_addAmmo
} forEach ([_source, _vehicle] call FUNC(getSourceCompatibleMagazines));
} forEach _sources;
_availableMagazines // return