public Vector<Mounted> getBombs(BigInteger flag) { Vector<Mounted> bombs = new Vector<Mounted>(); for (Mounted bomb : getBombs()) { BombType btype = (BombType) bomb.getType(); if (!bomb.isInoperable() && (bomb.getUsableShotsLeft() > 0) && btype.hasFlag(flag)) { bombs.add(bomb); } } return bombs; } /**
protected void useAmmo() { if (wtype.hasFlag(WeaponType.F_DOUBLE_ONESHOT)) { ArrayList<Mounted> chain = new ArrayList<>(); for (Mounted current = weapon.getLinked(); current != null; current = current.getLinked()) { chain.add(current); } if (!chain.isEmpty()) { chain.sort((m1, m2) -> Integer.compare(m2.getUsableShotsLeft(), m1.getUsableShotsLeft())); weapon.setLinked(chain.get(0)); for (int i = 0; i < chain.size() - 1; i++) { chain.get(i).setLinked(chain.get(i + 1)); } chain.get(chain.size() - 1).setLinked(null); if (weapon.getLinked().getUsableShotsLeft() == 0) { weapon.setFired(true); } } } else if (wtype.hasFlag(WeaponType.F_ONESHOT)) { weapon.setFired(true); } setDone(); }
public int getTotalAmmoOfType(EquipmentType et) { int totalShotsLeft = 0; for (Mounted amounted : getAmmo()) { if ((amounted.getType() == et) && !amounted.isDumping()) { totalShotsLeft += amounted.getUsableShotsLeft(); } } return totalShotsLeft; }
/** * @return The number of points taken up by all mounted bombs or other external stores. */ default int getBombPoints() { int points = 0; for (Mounted bomb : getBombs()) { if (bomb.getUsableShotsLeft() > 0) { points += BombType.getBombCost(((BombType) bomb.getType()).getBombType()); } } return points; }
@Override protected void useAmmo() { checkAmmo(); if (ammo == null) {// Can't happen. w/o legal ammo, the weapon // *shouldn't* fire. System.out.println("Handler can't find any ammo! Oh no!"); } if (ammo.getUsableShotsLeft() <= 0) { ae.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); super.useAmmo(); }
/** * produce an int array of the number of bombs of each type based on the * current bomblist * * @return */ public int[] getBombLoadout() { int[] loadout = new int[BombType.B_NUM]; for (Mounted bomb : getBombs()) { if ((bomb.getUsableShotsLeft() > 0) && (bomb.getType() instanceof BombType)) { int type = ((BombType) bomb.getType()).getBombType(); loadout[type] = loadout[type] + 1; } } return loadout; }
/** * 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); } } } } }
/** * */ protected void checkAmmo(WeaponAttackAction waa, IGame g) { Entity ae = waa.getEntity(g); Mounted weapon = ae.getEquipment(waa.getWeaponId()); Mounted ammo = weapon.getLinked(); if (ammo == null || ammo.getUsableShotsLeft() < 1) { ae.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } }
@Override protected void useAmmo() { getMountedAmmo(); Mounted bayW = bayWAmmo.getLinkedBy(); int shots = (bayW.getCurrentShots() * weapon.getBayWeapons().size()); for (int i = 0; i < shots; i++) { if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else ae.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinked(); } if (null != bayWAmmo) { bayWAmmo.setShotsLeft(bayWAmmo.getBaseShotsLeft() - 1); } } }
public void checkCriticalSlotsForEquipment(Entity entity, Vector<Mounted> unallocated, Vector<Serializable> allocation, Vector<Integer> heatSinks) { for (Mounted m : entity.getEquipment()) { if (m.getLocation() == Entity.LOC_NONE) { if ((m.getType() instanceof AmmoType) && (m.getUsableShotsLeft() <= 1)) { continue; } if ((entity instanceof Aero) && (m.getType().getCriticals(entity) == 0)) { continue; } if (!(m.getType() instanceof MiscType)) { unallocated.addElement(m); continue; } MiscType mt = (MiscType) m.getType(); if (!mt.hasFlag(MiscType.F_HEAT_SINK) && !mt.hasFlag(MiscType.F_DOUBLE_HEAT_SINK) && !mt.hasFlag(MiscType.F_IS_DOUBLE_HEAT_SINK_PROTOTYPE)) { unallocated.addElement(m); continue; } } } }
@Override protected void useAmmo() { checkAmmo(); if (ammo == null) {// Can't happen. w/o legal ammo, the weapon // *shouldn't* fire. System.out.println("Handler can't find any ammo! Oh no!"); } if (ammo.getUsableShotsLeft() <= 0) { ae.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } if (roll >= toHit.getValue()) { ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); if (wtype.hasFlag(WeaponType.F_ONESHOT)) { weapon.setFired(true); } setDone(); } }
/** * */ protected void checkAmmo(WeaponAttackAction waa, IGame g) { Entity ae = waa.getEntity(g); Mounted m = ae.getEquipment(waa.getWeaponId()); for (int wId : m.getBayWeapons()) { Mounted weapon = ae.getEquipment(wId); Mounted ammo = weapon.getLinked(); if (ammo == null || ammo.getUsableShotsLeft() < 1) { ae.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } } }
/** * does this BA have an unjettisoned DWP? * * @return */ public boolean hasDWP() { for (Mounted mounted : getWeaponList()) { if (mounted.isDWPMounted()) { if (mounted.isMissing()) { continue; } else if ((mounted.getLinked() != null) && (mounted.getLinked().getUsableShotsLeft() > 0)) { return true; } else if ((mounted.getLinked() == null) && !mounted.isMissing()) { return true; } } } return false; }
/** * Attempts to reload any empty weapons with the first ammo found */ public void reloadEmptyWeapons() { // try to reload weapons for (Mounted mounted : getTotalWeaponList()) { WeaponType wtype = (WeaponType) mounted.getType(); if (wtype.getAmmoType() != AmmoType.T_NA) { if ((mounted.getLinked() == null) || (mounted.getLinked().getUsableShotsLeft() <= 0) || mounted.getLinked().isDumping()) { loadWeaponWithSameAmmo(mounted); } } } }
@Override protected void useAmmo() { int[] payload = waa.getBombPayload(); if (!ae.isBomber() || (null == payload)) { return; } for (int type = 0; type < payload.length; type++) { for (int i = 0; i < payload[type]; i++) { // find the first mounted bomb of this type and drop it for (Mounted bomb : ae.getBombs()) { if (!bomb.isDestroyed() && (bomb.getUsableShotsLeft() > 0) && (((BombType) bomb.getType()).getBombType() == type)) { bomb.setShotsLeft(0); break; } } } } super.useAmmo(); }
@Override protected void useAmmo() { // call super function if we are in IDF mode, since we don't have streak // there. if (streakInactive()) { super.useAmmo(); return; } checkAmmo(); if (ammo == null) {// Can't happen. w/o legal ammo, the weapon // *shouldn't* fire. System.out.println("Handler can't find any ammo! Oh no!"); } if (ammo.getUsableShotsLeft() <= 0) { ae.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } if (roll >= toHit.getValue()) { ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); if (wtype.hasFlag(WeaponType.F_ONESHOT)) { weapon.setFired(true); } setDone(); } }
/** * 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; }
@Override protected void useAmmo() { setDone(); checkAmmo(); // how many shots are we firing? int nShots = weapon.getCurrentShots(); // do we need to revert to single shot? if (nShots > 1) { int nAvail = ae.getTotalAmmoOfType(ammo.getType()); while (nAvail < nShots) { nShots--; } } // use up ammo for (int i = 0; i < nShots; i++) { if (ammo.getUsableShotsLeft() <= 0) { ae.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); } } }
@Override protected void useAmmo() { final String METHOD_NAME = "useAmmo()"; for (int wId : weapon.getBayWeapons()) { Mounted bayW = ae.getEquipment(wId); // check the currently loaded ammo Mounted bayWAmmo = bayW.getLinked(); if (bayWAmmo == null) {// Can't happen. w/o legal ammo, the weapon // *shouldn't* fire. logDebug(METHOD_NAME, "Handler can't find any ammo! Oh no!"); } int shots = bayW.getCurrentShots(); for (int i = 0; i < shots; i++) { if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else ae.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinked(); } if (null != bayWAmmo) { bayWAmmo.setShotsLeft(bayWAmmo.getBaseShotsLeft() - 1); } } } }
@Override protected void useAmmo() { final String METHOD_NAME = "useAmmo()"; for (int wId : weapon.getBayWeapons()) { Mounted bayW = ae.getEquipment(wId); // check the currently loaded ammo Mounted bayWAmmo = bayW.getLinked(); if (bayWAmmo == null) {// Can't happen. w/o legal ammo, the weapon // *shouldn't* fire. logDebug(METHOD_NAME, "Handler can't find any ammo! Oh no!"); } int shots = bayW.getCurrentShots(); for (int i = 0; i < shots; i++) { if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else ae.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinked(); } if (null != bayWAmmo) { bayWAmmo.setShotsLeft(bayWAmmo.getBaseShotsLeft() - 1); } } } }