mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
add getAvailableAmmo
This commit is contained in:
parent
17156d5480
commit
078857b5a9
@ -20,6 +20,7 @@ PREP(canGetIn);
|
||||
PREP(getIn);
|
||||
|
||||
PREP(compatibleMagazines);
|
||||
PREP(getAvailableAmmo);
|
||||
PREP(getCarryMagazine);
|
||||
PREP(getNearbySources);
|
||||
PREP(getSourceCompatibleMagazines);
|
||||
|
59
addons/csw/functions/fnc_getAvailableAmmo.sqf
Normal file
59
addons/csw/functions/fnc_getAvailableAmmo.sqf
Normal file
@ -0,0 +1,59 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: LinkIsGrim
|
||||
* Gets available ammo for a CSW
|
||||
*
|
||||
* 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:
|
||||
* Available Ammo <HashMap>
|
||||
* Magazine classname <STRING>
|
||||
* Total Ammo <NUMBER>
|
||||
*
|
||||
* Example:
|
||||
* [cursorObject] call ace_csw_fnc_getAvailableAmmo
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
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"];
|
||||
|
||||
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
|
@ -4,7 +4,9 @@
|
||||
* Gets available ammo sources for loading a CSW
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit attempting to load <OBJECT>
|
||||
* 0: Unit or vehicle attempting to load <OBJECT>
|
||||
* 1: Skip vehicle sources <BOOL> (default: false)
|
||||
* 2: Include CSW crew <BOOL> (default: false)
|
||||
*
|
||||
* Return Value:
|
||||
* Ammo sources <ARRAY of OBJECT>
|
||||
@ -14,16 +16,25 @@
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
params ["_unit"];
|
||||
|
||||
[_unit, {
|
||||
params ["_unit"];
|
||||
[_this, {
|
||||
params ["_unit", ["_skipVehicles", false], ["_includeCrew", false]];
|
||||
private _nearSupplies = (_unit nearSupplies 5) select {
|
||||
isNull (group _x) ||
|
||||
{!([_x] call EFUNC(common,isPlayer)) && {[side group _unit, side group _x] call BIS_fnc_sideIsFriendly}}
|
||||
};
|
||||
|
||||
_nearSupplies pushBack _unit;
|
||||
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;
|
||||
{
|
||||
if (_x isKindOf "CAManBase") then {
|
||||
_nearSupplies append [uniformContainer _x, vestContainer _x, backpackContainer _x];
|
||||
@ -37,4 +48,4 @@ params ["_unit"];
|
||||
} forEach _nearSupplies;
|
||||
|
||||
_nearSupplies select {!(_x isKindOf "CAManBase")} // return
|
||||
}, _unit, QGVAR(nearbySourcesCache), NEARBY_SOURCES_CACHE_EXPIRY, QGVAR(clearNearbySourcesCache)] call EFUNC(common,cachedCall);
|
||||
}, _this select 0, QGVAR(nearbySourcesCache), NEARBY_SOURCES_CACHE_EXPIRY, QGVAR(clearNearbySourcesCache)] call EFUNC(common,cachedCall);
|
||||
|
Loading…
Reference in New Issue
Block a user