/** * Tries to load the specified weapon with the first available ammo */ public void loadWeapon(Mounted mounted) { for (Mounted mountedAmmo : getAmmo()) { if (loadWeapon(mounted, mountedAmmo)) { break; } } }
@Override public ArrayList<Mounted> getAmmo() { ArrayList<Mounted> allAmmo = new ArrayList<Mounted>(); for (Integer fId : fighters) { Entity fighter = game.getEntity(fId); allAmmo.addAll(fighter.getAmmo()); } return allAmmo; }
private static String formatAmmo(Entity e) { StringBuffer sb = new StringBuffer(1024); for (Mounted ammo : e.getAmmo()) { sb.append(ammo.getName()); sb.append(": ").append(ammo.getBaseShotsLeft()) .append(CommonConstants.NL); } return sb.toString(); }
private String getAmmo() { StringBuffer sAmmo = new StringBuffer(); if (entity.getAmmo().size() < 1) { return ""; } sAmmo.append(String.format("%1$-30s %2$3s %3$5s\n", "Ammo", "Loc", "Shots")); sAmmo.append("----------------------------------------\n"); for (Mounted mounted : entity.getAmmo()) { sAmmo.append(String.format("%1$-30s %2$3s %3$5d\n", mounted.getName(), entity.getLocationAbbr(mounted.getLocation()), mounted.getBaseShotsLeft())); } sAmmo.append("\n"); return sAmmo.toString(); }
/** * Tries to load the specified weapon with the first available ammo of the * same munition type as currently in use. If this fails, use first ammo. */ public void loadWeaponWithSameAmmo(Mounted mounted) { for (Mounted mountedAmmo : getAmmo()) { if (loadWeaponWithSameAmmo(mounted, mountedAmmo)) { return; } } // fall back to use any ammo loadWeapon(mounted); }
public int getTotalAmmoOfType(EquipmentType et) { int totalShotsLeft = 0; for (Mounted amounted : getAmmo()) { if ((amounted.getType() == et) && !amounted.isDumping()) { totalShotsLeft += amounted.getUsableShotsLeft(); } } return totalShotsLeft; }
@Override public StringBuffer printAmmo(StringBuffer buff, int posLoc, int posWeight) { for (Mounted m : getEntity().getAmmo()) { AmmoType mt = (AmmoType) m.getType(); buff.append(StringUtil.makeLength(mt.getName(), 20)); buff.append(" ").append( StringUtil.makeLength(getLocationAbbr(m.getLocation()), getPrintSize() - 5 - 20)) .append(TestEntity.makeWeightString( Math.ceil(mt.getKgPerShot() * m.getBaseShotsLeft()) / 1000.0)).append("\n"); } return buff; }
public StringBuffer printAmmo(StringBuffer buff, int posLoc, int posWeight) { for (Mounted m : getEntity().getAmmo()) { AmmoType mt = (AmmoType) m.getType(); // Don't think this can happen, but ... if (m.getLocation() == Entity.LOC_NONE) { continue; } buff.append(StringUtil.makeLength(mt.getName(), 20)); buff.append(" ").append( StringUtil.makeLength(getLocationAbbr(m.getLocation()), getPrintSize() - 5 - 20)) .append(TestEntity.makeWeightString(mt .getTonnage(getEntity()))).append("\n"); } return buff; }
/** * 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; }
@Override public double getWeightAmmo() { double weight = 0.0; for (Mounted m : getEntity().getAmmo()) { // One Shot Ammo if (m.getLocation() == Entity.LOC_NONE) { continue; } AmmoType mt = (AmmoType) m.getType(); int slots = (int)Math.ceil(m.getBaseShotsLeft() / mt.getShots()); weight += mt.getTonnage(getEntity()) * slots; } return weight; }
private Entity setupGunEmplacement() { Entity testEntity = Mockito.mock(GunEmplacement.class); Mockito.when(testEntity.calculateBattleValue()).thenCallRealMethod(); Mockito.when(testEntity.calculateBattleValue(Mockito.anyBoolean(), Mockito.anyBoolean())).thenCallRealMethod(); Mockito.when(testEntity.getTotalArmor()).thenReturn(100); ArrayList<Mounted> equipment = new ArrayList<Mounted>(2); WeaponType ppcType = Mockito.mock(WeaponType.class); Mockito.when(ppcType.getBV(Mockito.any(Entity.class))).thenReturn(50.0); Mounted ppc = Mockito.mock(Mounted.class); Mockito.when(ppc.getType()).thenReturn(ppcType); Mockito.when(ppc.isDestroyed()).thenReturn(false); equipment.add(ppc); equipment.add(ppc); Mockito.when(testEntity.getEquipment()).thenReturn(equipment); Mockito.when(testEntity.getWeaponList()).thenReturn(equipment); Mockito.when(testEntity.getAmmo()).thenReturn(new ArrayList<Mounted>(0)); return testEntity; }
/** * Worker function that expends ammo from all units belonging to the side specified in this modifier. * @param scenario * @param campaign */ public static void expendAmmo(AtBDynamicScenario scenario, Campaign campaign, ForceAlignment eventRecipient, int ammoExpenditureIntensity) { // now go through all the entities belonging to the recipient currently in the scenario // and remove a random amount of ammo from each bin for(int botIndex = 0; botIndex < scenario.getNumBots(); botIndex++) { BotForce bf = scenario.getBotForce(botIndex); if(bf.getTeam() == ScenarioForceTemplate.TEAM_IDS.get(eventRecipient.ordinal())) { for(Entity en : bf.getEntityList()) { for(Mounted ammoBin : en.getAmmo()) { int remainingShots = Math.max(0, ammoBin.getUsableShotsLeft() - Compute.randomInt(ammoExpenditureIntensity)); ammoBin.setShotsLeft(remainingShots); } } } } }
@Override public double getWeightAmmo() { double weight = 0.0; for (Mounted m : getEntity().getAmmo()) { // One Shot Ammo if (m.getLocation() == Entity.LOC_NONE) { continue; } AmmoType mt = (AmmoType) m.getType(); int slots = (int)Math.ceil(m.getBaseShotsLeft() / mt.getShots()); weight += ceil(mt.getTonnage(getEntity()) * slots, Ceil.HALFTON); } return weight; }
@Override public double getWeightAmmo() { double weight = 0.0; for (Mounted m : getEntity().getAmmo()) { if (!m.isOneShotAmmo()) { AmmoType mt = (AmmoType) m.getType(); weight += ceil(mt.getKgPerShot() * m.getBaseShotsLeft() / 1000, Ceil.KILO); } } return weight; }
for(Mounted ammoBin : weapon.getEntity().getAmmo()) { if((ammoBin.getLocation() != Entity.LOC_NONE) && ((WeaponType) weapon.getType()).getAmmoType() == ((AmmoType) ammoBin.getType()).getAmmoType()) {
public double getWeightAmmo() { double weight = 0.0; for (Mounted m : getEntity().getAmmo()) { // One Shot Ammo if (m.getLocation() == Entity.LOC_NONE) { continue; } // Bombs on ASF don't count! if ((getEntity() instanceof Aero) && (m.getType() instanceof BombType)) { continue; } AmmoType mt = (AmmoType) m.getType(); weight += mt.getTonnage(getEntity()); } return weight; }
/** * Determine how much ammunition (of all munition types) remains which is * compatible with the given ammo. * * @param et - the <code>EquipmentType</code> of the ammo to be found. This * value may be <code>null</code>. * @return the <code>int</code> count of the amount of shots of all * munitions equivalent to the given ammo type. */ public int getTotalMunitionsOfType(@Nullable EquipmentType et) { int totalShotsLeft = 0; // specifically don't count caseless munitions as being of the same type as non-caseless for (Mounted amounted : getAmmo()) { boolean amCaseless = ((AmmoType) amounted.getType()).getMunitionType() == AmmoType.M_CASELESS; boolean etCaseless = (et != null) && ((AmmoType) et).getMunitionType() == AmmoType.M_CASELESS; boolean caselessMismatch = amCaseless != etCaseless; if (amounted.getType().equals(et) && !caselessMismatch && !amounted.isDumping()) { totalShotsLeft += amounted.getUsableShotsLeft(); } } return totalShotsLeft; }
/** * Scans through the ammo on the unit for any inferno rounds. * * @return <code>true</code> if the unit is still loaded with Inferno * rounds. <code>false</code> if no rounds were ever loaded or if * they have all been fired. */ public boolean hasInfernoAmmo() { boolean found = false; // Walk through the unit's ammo, stop when we find a match. for (Mounted amounted : getAmmo()) { AmmoType atype = (AmmoType) amounted.getType(); if (((atype.getAmmoType() == AmmoType.T_SRM) || (atype.getAmmoType() == AmmoType.T_SRM_IMP) || (atype.getAmmoType() == AmmoType.T_MML)) && (atype.getMunitionType() == AmmoType.M_INFERNO) && (amounted.getHittableShotsLeft() > 0)) { found = true; } if ((atype.getAmmoType() == AmmoType.T_IATM) && (atype.getMunitionType() == AmmoType.M_IATM_IIW) && (amounted.getHittableShotsLeft() > 0)) { found = true; } } return found; }