/** * Set the number of shots in the mount. * * @param shots * the <code>int</code> number of shots for the mount. */ void setShotsLeft(int shots) { m_mounted.setShotsLeft(shots); } }
public void loadBinSingle() { int shots = Math.min(getAmountAvailable(), Math.min(shotsNeeded, ((AmmoType) type).getShots())); if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted && mounted.getType() instanceof AmmoType) { mounted.setShotsLeft(mounted.getBaseShotsLeft() + shots); } } changeAmountAvailable(-1 * shots, (AmmoType)type); shotsNeeded -= shots; }
@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(); }
public void unloadSingle() { int shots = Math.min(getCurrentShots(), ((AmmoType) type).getShots()); AmmoType curType = (AmmoType)type; if (null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted && mounted.getType() instanceof AmmoType) { shots = Math.min(mounted.getBaseShotsLeft(), shots); mounted.setShotsLeft(mounted.getBaseShotsLeft() - shots); curType = (AmmoType)mounted.getType(); } } shotsNeeded += shots; if(shots > 0) { changeAmountAvailable(shots, curType); } }
/** * 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 addEquipment(Mounted mounted, int loc, boolean rearMounted, int nAmmo) throws LocationFullException { if ((mounted.getType() instanceof AmmoType) && (nAmmo > 1)) { mounted.setByShot(true); mounted.setShotsLeft(nAmmo); mounted.setOriginalShots(nAmmo); double tonnage = Math.max(1, nAmmo / ((AmmoType) mounted.getType()).getShots()) * ((AmmoType) mounted.getType()).getTonnage(this); mounted.setAmmoCapacity(tonnage); } addEquipment(mounted, loc, rearMounted); }
@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); } } }
@Override public void updateConditionFromPart() { if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted) { mounted.setHit(false); mounted.setDestroyed(false); mounted.setRepairable(true); unit.repairSystem(CriticalSlot.TYPE_EQUIPMENT, equipmentNum); mounted.setShotsLeft(getFullShots() - shotsNeeded); } } }
@Override public void loadBin() { int shots = Math.min(getAmountAvailable(), shotsNeeded); int shotsPerTrooper = shots / getNumTroopers(); shots = shotsPerTrooper * getNumTroopers(); if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted) { if(mounted.getType().equals(type) && ((AmmoType)mounted.getType()).getMunitionType() == getMunitionType()) { //just a simple reload mounted.setShotsLeft(mounted.getBaseShotsLeft() + shotsPerTrooper); } else { //loading a new type of ammo unload(); mounted.changeAmmoType((AmmoType)type); mounted.setShotsLeft(shotsPerTrooper); } } } changeAmountAvailable(-1 * shots, (AmmoType)type); shotsNeeded -= shots; }
@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(); } }
@Override public void updateConditionFromPart() { if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted) { mounted.setHit(false); mounted.setDestroyed(false); mounted.setRepairable(true); unit.repairSystem(CriticalSlot.TYPE_EQUIPMENT, equipmentNum); mounted.setShotsLeft(getFullShots() - shotsNeeded/getNumTroopers()); } } }
public void loadBin() { int shots = Math.min(getAmountAvailable(), getShotsNeeded()); if (null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if (null != mounted) { EquipmentType mType = mounted.getType(); if (mType instanceof AmmoType) { if (!ammoTypeChanged()) { //just a simple reload mounted.setShotsLeft(mounted.getBaseShotsLeft() + shots); } else { //loading a new type of ammo unload(); mounted.changeAmmoType((AmmoType)type); mounted.setShotsLeft(shots); } changeAmountAvailable(-1 * shots, (AmmoType)type); shotsNeeded -= shots; } else { MekHQ.getLogger().log(AmmoBin.class, "loadBin", LogLevel.WARNING, mType.getName() + " is not valid equipment for " + getName() + " to restock ammo on unit " + unit.getName()); } } } }
@Override public void updateConditionFromEntity(boolean checkForDestruction) { if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted) { capacity = mounted.getAmmoCapacity(); type = mounted.getType(); if(mounted.isMissing() || mounted.isDestroyed()) { mounted.setShotsLeft(0); return; } shotsNeeded = getFullShots() - mounted.getBaseShotsLeft(); } } }
@Override public void updateConditionFromEntity(boolean checkForDestruction) { if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted) { if(mounted.isMissing() || mounted.isDestroyed()) { mounted.setShotsLeft(0); remove(false); return; } if (type == mounted.getType()) { shotsNeeded = getFullShots() - mounted.getBaseShotsLeft(); } } } }
@Override public void unload() { int shots = 0; AmmoType curType = (AmmoType)type; if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted) { shots = mounted.getBaseShotsLeft() * getNumTroopers(); mounted.setShotsLeft(0); curType = (AmmoType)mounted.getType(); } } shotsNeeded = getFullShots() * getNumTroopers(); if(shots > 0) { changeAmountAvailable(shots, curType); } }
@Override public void updateConditionFromPart() { if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted) { mounted.setHit(false); mounted.setDestroyed(false); mounted.setRepairable(true); mounted.changeAmmoType((AmmoType) type); unit.repairSystem(CriticalSlot.TYPE_EQUIPMENT, equipmentNum); mounted.setShotsLeft(getFullShots() - shotsNeeded); mounted.setAmmoCapacity(capacity); } } }
public void unload() { //FIXME: the following won't work for proto and Dropper bins if they //are not attached to a unit. Currently the only place AmmoBins are loaded //off of units is for refits, which neither of those units can do, but we //may want to think about not having refits load ammo bins but rather reserve //some AmmoStorage instead if we implement customization of these units int shots = getFullShots() - shotsNeeded; AmmoType curType = (AmmoType)type; if(null != unit) { Mounted mounted = unit.getEntity().getEquipment(equipmentNum); if(null != mounted && mounted.getType() instanceof AmmoType) { shots = mounted.getBaseShotsLeft(); mounted.setShotsLeft(0); curType = (AmmoType)mounted.getType(); } } shotsNeeded = getFullShots(); if(shots > 0) { changeAmountAvailable(shots, curType); } }
@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(); } }
@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); } } }