GetVehicleWeapons = { private _result = []; private _getAnyMagazines = { private _weapon = configFile >> "CfgWeapons" >> _this; private _mags = []; { _mags = _mags + getArray ( (if (_x == "this") then { _weapon } else { _weapon >> _x }) >> "magazines" ); } forEach getArray (_weapon >> "muzzles"); _mags; }; private _findRecurse = { private ["_class", "_currentPath"]; private _root = (_this select 0); private _path = +(_this select 1); for "_i" from 0 to count _root -1 do { _class = _root select _i; if (isClass _class) then { _currentPath = _path + [_i]; { _result set [count _result, [_x, _x call _getAnyMagazines, _currentPath, str _class]]; } forEach getArray (_class >> "weapons"); _class = _class >> "turrets"; if (isClass _class) then { [_class, _currentPath] call _findRecurse; }; }; }; }; private _class = ( configFile >> "CfgVehicles" >> ( switch (typeName _this) do { case "STRING" : {_this}; case "OBJECT" : {typeOf _this}; default {nil} } ) >> "turrets" ); [_class, []] call _findRecurse; _result; }; AddVehicleAmmo = { params ["_unit", "_mag", "_path", "_magCount", "_ammoCount"]; _unit removeMagazinesTurret [_mag, _path]; if (_ammoCount > 0) then { _unit addMagazineTurret [_mag, _path, _ammoCount]; }; if (_magCount > 0) then { for "_i" from 1 to _magCount do { _unit addMagazineTurret [_mag, _path]; }; }; }; ["Equipment", "Change Vehicle Loadout", { _unit = [_logic, false] call Ares_fnc_GetUnitUnderCursor; if (isNull _unit) exitWith { [localize "STR_NO_OBJECT_SELECTED"] call Ares_fnc_ShowZeusMessage; playSound "FD_Start_F"; }; _unit = vehicle _unit; if (!(_unit isKindOf "AllVehicles")) exitWith { ["Object is not a vehicle"] call Ares_fnc_ShowZeusMessage; playSound "FD_Start_F"; }; _weaponList = _unit call GetVehicleWeapons; _paths = []; _weapons = []; _magazines = []; _magazineNames = []; { _x params ["_weapon", "_mags", "_path", "_config"]; _weapons pushBack _weapon; _magNames = []; { _magNames pushBack (getText (configFile >> "CfgMagazines" >> _x >> "displayName")); } forEach _mags; _paths pushBack _path; _magazines pushBack _mags; _magazineNames pushBack _magNames; } forEach _weaponList; _properties = ["Loadout", [ ["Choose weapon", _weapons] ]] call Ares_fnc_ShowChooseDialog; if (count _properties == 0) exitWith { ["Loadout editing aborted"] call Ares_fnc_ShowZeusMessage; }; _turretPath = _paths select (_properties select 0); _weaponMags = _magazines select (_properties select 0); _weaponMagNames = _magazineNames select (_properties select 0); _properties = ["Loadout", [ ["Choose magazine", _weaponMagNames] ]] call Ares_fnc_ShowChooseDialog; if (count _properties == 0) exitWith { ["Loadout editing aborted"] call Ares_fnc_ShowZeusMessage; }; _selectedMagazine = _weaponMags select (_properties select 0); _magazineCount = 0; _largestMag = 0; _ammoCount = 0; { _x params ["_class", "_path", "_ammo", "_id", "_creator"]; if (_class == _selectedMagazine) then { if (_ammo > _largestMag) then { _largestMag = _ammo; }; }; } forEach magazinesAllTurrets _unit; { _x params ["_class", "_path", "_ammo", "_id", "_creator"]; if (_class == _selectedMagazine) then { if (_ammo < _largestMag) then { _ammoCount = _ammo; } else { _magazineCount = _magazineCount + 1; }; }; } forEach magazinesAllTurrets _unit; if (_ammoCount == 0 && _magazineCount > 0) then { _ammoCount = _largestMag; _magazineCount = _magazineCount - 1; }; _properties = ["", [ ["Ammo Count", str _ammoCount, str _ammoCount], ["Magazine Count", str _magazineCount, str _magazineCount] ]] call Ares_fnc_ShowChooseDialog; if (count _properties == 0) exitWith { ["Loadout editing aborted"] call Ares_fnc_ShowZeusMessage; }; _newAmmoCount = parseNumber (_properties select 0); _newMagCount = parseNumber (_properties select 1); [_unit, _selectedMagazine, _turretPath, _newMagCount, _newAmmoCount] remoteExecCall ["AddVehicleAmmo", _unit]; }] call Ares_fnc_RegisterCustomModule;