get compatible missiles fnc

This commit is contained in:
commy2 2015-03-18 21:33:00 +01:00
parent 40eed0e12f
commit 43defaee06
3 changed files with 32 additions and 23 deletions

View File

@ -3,6 +3,7 @@
ADDON = false;
PREP(canLoad);
PREP(getLoadableMissiles);
PREP(load);
PREP(reloadLauncher);

View File

@ -4,7 +4,7 @@
* Check of the unit can reload the launcher of target unit.
*
* Argument:
* 0: Unit to to the reload (Object)
* 0: Unit to do the reloading (Object)
* 1: Unit eqipped with launcher (Object)
*
* Return value:
@ -30,27 +30,7 @@ if (_weapon == "" || {currentWeapon _target != _weapon}) exitWith {false};
if (currentMagazine _target != "") exitWith {false};
// check if the launcher is compatible
private "_config";
_config = configFile >> "CfgWeapons" >> _weapon;
if (getNumber (_config >> QGVAR(enabled)) == 0) exitWith {false};
// get magazine of reloader
private "_magazines";
_magazines = magazines _unit;
{
_magazines deleteAt (_magazines find _x);
} forEach secondaryWeaponMagazine _unit;
if (getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled)) == 0) exitWith {false};
// check if the reloader has a magazine compatible with targets launcher
private "_hasMagazine";
_hasMagazine = false;
{
if (_x in _magazines) exitWith {
_hasMagazine = true;
};
} forEach getArray (_config >> "magazines");
_hasMagazine
count ([_unit, _weapon] call FUNC(getLoadableMissiles)) > 0

View File

@ -0,0 +1,28 @@
/*
* Author: commy2
*
* Return all magazine types from reloaders inventory that are compatible with given weapon.
*
* Argument:
* 0: Unit to to the reload (Object)
* 1: A launcher (String)
*
* Return value:
* Reloable magazines (Array)
*/
#include "script_component.hpp"
private ["_unit", "_weapon"];
_unit = _this select 0;
_weapon = _this select 1;
// get available magazines of reloader, Note: "magazines" does not include currently loaded magazines
private "_magazines";
_magazines = magazines _unit;
// case sensitvity
_magazines = [_magazines, {toLower _this}] call EFUNC(common,map);
// get reloaders magazine types compatible with targets launcher. No duplicates.
[getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"), {toLower _this in _magazines}] call EFUNC(common,filter)