2015-12-16 19:22:18 +00:00
/*
* Author: Grey
* Checks whether magazine can be loaded into static weapon
*
* Arguments:
* 0: static <OBJECT>
* 1: unit <OBJECT>
2015-12-19 11:10:12 +00:00
* 2: magazine class to check; if not given having any compatible magazine returns true <STRING> (default: "")
2015-12-16 19:22:18 +00:00
*
* Return Value:
* canLoadMagazine <BOOL>
*
* Example:
2015-12-16 22:47:14 +00:00
* [_target,_player,"ACE_1Rnd_82mm_Mo_HE"] call ace_mk6mortar_fnc_canLoadMagazine
2015-12-16 19:22:18 +00:00
*
* Public: Yes
*/
#include "script_component.hpp"
2015-12-16 22:47:14 +00:00
params ["_static","_unit",["_magazineClassOptional","",[""]]];
2015-12-16 19:22:18 +00:00
2015-12-19 11:10:12 +00:00
if !(alive _static && GVAR(useAmmoHandling)) exitWith {false};
2018-05-30 21:45:31 +00:00
if (_static getVariable [QGVAR(inUse), false]) exitWith {false};
2015-12-16 19:22:18 +00:00
2017-10-10 14:39:59 +00:00
private _canLoadMagazine = false;
private _hasCompatibleMagazine = false;
2015-12-16 19:22:18 +00:00
2017-10-10 14:39:59 +00:00
private _currentMagazine = (magazinesAllTurrets _static) select 1;
private _weapon = (_static weaponsTurret [0]) select 0;
2015-12-16 19:22:18 +00:00
2017-10-10 14:39:59 +00:00
private _listOfMagNames = getArray(configFile >> "cfgWeapons" >> _weapon >> "magazines");
private _count = 0;
2015-12-16 19:22:18 +00:00
//If function is called with an optional string then check if player has that magzine otherwise check all magazines of the player to see if they are compatible with the static weapon
if (_magazineClassOptional != "") then {
2015-12-19 11:10:12 +00:00
if ([_unit,_magazineClassOptional] call EFUNC(common,hasMagazine)) then {
2015-12-16 19:22:18 +00:00
_hasCompatibleMagazine = true;
};
2015-12-19 11:10:12 +00:00
} else {
2015-12-16 19:22:18 +00:00
{
2015-12-17 08:13:23 +00:00
if ([_unit,_x] call EFUNC(common,hasMagazine)) exitWith {_hasCompatibleMagazine = true};
2015-12-16 19:22:18 +00:00
} forEach _listOfMagNames;
};
//If static weapon has a magazine then find the ammo count
2015-12-19 11:10:12 +00:00
if (count (_static magazinesTurret [0]) > 0) then {
2015-12-16 19:22:18 +00:00
_count = _currentMagazine select 2;
};
//If the static weapon doesn't have a magzine or a magazine with no bullets, the player has a compatible magazine and the static weapon has a barrel then you can load a magazine
2018-05-30 21:45:31 +00:00
if ((count (_static magazinesTurret [0]) == 0 || _count == 0) && _hasCompatibleMagazine) then {
2015-12-16 19:22:18 +00:00
_canLoadMagazine = true;
};
_canLoadMagazine