From 229199ba16fc98e43c76fbe1635262e6c3fc0d69 Mon Sep 17 00:00:00 2001 From: BaerMitUmlaut Date: Sat, 11 May 2019 01:23:33 +0200 Subject: [PATCH] Fix rearming for vehicles using magazine wells --- .../functions/fnc_setTurretMagazineAmmo.sqf | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/rearm/functions/fnc_setTurretMagazineAmmo.sqf b/addons/rearm/functions/fnc_setTurretMagazineAmmo.sqf index 984d382e08..c2abe8a132 100644 --- a/addons/rearm/functions/fnc_setTurretMagazineAmmo.sqf +++ b/addons/rearm/functions/fnc_setTurretMagazineAmmo.sqf @@ -30,7 +30,7 @@ private _magLoadedInWeapon = false; private _loadedWeapon = ""; { private _currentlyLoadedMag = (weaponState [_vehicle, _turretPath, _x]) select 3; - + if (_currentlyLoadedMag isEqualTo _magazineClass) exitWith { _magLoadedInWeapon = true; _loadedWeapon = _x; @@ -47,37 +47,36 @@ if (!_magLoadedInWeapon) then { { _vehicle addMagazineTurret [_magazineClass, _turretPath, _x]; } forEach _ammoCounts; - } else { /* Special hack case: * The magazine class was loaded into a weapon. If the weapon has more than one type of * magazine (e.g. AP and HEAT in a cannon), then removing all magazines would trigger the * weapon to load a different magazine type. For example, removing the HEAT shells while HEAT * is loaded makes the cannon switch to AP. - * + * * To prevent that, we must remove all magazines that would fit into the weapon and then add * them back with the magazine-to-be-loaded being the first. */ - private _allowedMagClassesInWeapon = getArray (configFile >> "CfgWeapons" >> _loadedWeapon >> "magazines"); - + private _allowedMagClassesInWeapon = [_loadedWeapon] call CBA_fnc_compatibleMagazines; + /* Current ammo counts of all allowed magazine classes in weapon. * Example: [["8Rnd_82mm_Mo_shells", [8, 8, 2]], ["8Rnd_82mm_Mo_Flare_white", [7]]] */ private _ammoCountsByMagClass = _allowedMagClassesInWeapon apply {[_x, ([_vehicle, _turretPath, _x] call FUNC(getTurretMagazineAmmo))]}; - + // Removing all magazines that fit into the weapon. { _vehicle removeMagazinesTurret [_x, _turretPath]; } forEach _allowedMagClassesInWeapon; - + // Adding the mags of the given class first with updated ammo counts. { _vehicle addMagazineTurret [_magazineClass, _turretPath, _x]; } forEach _ammoCounts; - + // Adding back all other magazines with their original ammo counts. { _x params ["_loopMagClass", "_loopAmmoCounts"]; - + if (!(_loopMagClass isEqualTo _magazineClass)) then { { _vehicle addMagazineTurret [_loopMagClass, _turretPath, _x];