if (!AmmoType.isAmmoValid(ammoType, weaponType)) { continue;
/** * Checks to ensure that the given ammo can be used with the given weapon type. Performs the following tests:<br/> * {@code ammo} != null<br/> * {@link Mounted#getType()} instanceof {@link AmmoType}<br/> * {@link Mounted#isAmmoUsable()}<br/> * {@link #isAmmoValid(AmmoType, WeaponType)}. * * @param ammo The ammunition to be tested. * @param weaponType The weapon the ammo is to be used with. * @return TRUE if the ammmo and weapon are compatible. */ public static boolean isAmmoValid(Mounted ammo, WeaponType weaponType) { if (ammo == null) { return false; } if (!(ammo.getType() instanceof AmmoType)) { return false; } return ammo.isAmmoUsable() && isAmmoValid((AmmoType) ammo.getType(), weaponType); }
@Test public void testIsAmmoValid() { // Test ammo that matches weapon. Assert.assertTrue(AmmoType.isAmmoValid(mockAmmoAC5, mockAC5)); Assert.assertTrue(AmmoType.isAmmoValid(mockAmmoSrm4, mockSRM4)); Assert.assertTrue(AmmoType.isAmmoValid(mockAmmoInferno4, mockSRM4)); // Test an empty ammo bin. Assert.assertFalse(AmmoType.isAmmoValid(mockAmmoAC5Empty, mockAC5)); // Test null ammo. Assert.assertFalse(AmmoType.isAmmoValid((Mounted) null, mockAC5)); Assert.assertFalse(AmmoType.isAmmoValid((AmmoType) null, mockAC5)); // Test incompatible ammo. Assert.assertFalse(AmmoType.isAmmoValid(mockAmmoAC5, mockSRM4)); Assert.assertFalse(AmmoType.isAmmoValid(mockAmmoSrm4, mockPPC)); // Test wrong rack size. Assert.assertFalse(AmmoType.isAmmoValid(mockAmmoAC10, mockAC5)); Assert.assertFalse(AmmoType.isAmmoValid(mockAmmoSrm6, mockSRM4)); // Test something that's not ammo. Assert.assertFalse(AmmoType.isAmmoValid(mockNotAmmo, mockAC5)); } }
/** * Worker function that selects the appropriate ammo for the given entity and weapon. * @param shooter * @param currentWeapon * @param game * @return */ private int findAmmo(Entity shooter, Mounted currentWeapon, IGame game) { int ammoEquipmentNum = NO_AMMO; // simply grab the first valid ammo and let 'er rip. for(Mounted ammo : shooter.getAmmo()) { if(!ammo.isAmmoUsable() || !AmmoType.isAmmoValid(ammo, (WeaponType) currentWeapon.getType())) { continue; } ammoEquipmentNum = shooter.getEquipmentNum(ammo); break; // TODO: Attempt to select homing ammo if the target is tagged. // To do so, check ammoType.getMunitionType() == AmmoType.M_HOMING } return ammoEquipmentNum; }
final List<Mounted> validAmmo = new ArrayList<>(); for (final Mounted a : ammo) { if (AmmoType.isAmmoValid(a, weaponType)) { validAmmo.add(a);
for (Mounted ammo : ba.getAmmo()){ if (ammo.isSquadSupportWeapon() && !AmmoType.isAmmoValid(ammo, sswType)){ buff.append(ammo.getName() + " is squad support weapon " + "mounted, but it is not a legal ammo type for " +
&& AmmoType.isAmmoValid(ammo, (WeaponType)weapon.getType())){ weapon.setLinked(ammo); for (Mounted weapon : ent.getWeaponList()){ if (weapon.isDWPMounted() && AmmoType.isAmmoValid(ammo, (WeaponType)weapon.getType())){ weapon.setLinked(ammo);