use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class BayWeaponCriticalTree method addToNewBay.
/**
* Adds a new bay of the appropriate type to the unit and adds the equipment to the bay.
*
* @param bayType The type of bay to be added.
* @param eq The equipment to be added.
*/
public void addToNewBay(EquipmentType bayType, Mounted eq) {
try {
Mounted bay = eSource.getEntity().addEquipment(bayType, location, facing == AFT);
BayNode bayNode = new BayNode(bay);
model.insertNodeInto(bayNode, (MutableTreeNode) model.getRoot(), ((TreeNode) model.getRoot()).getChildCount());
bayNode.setParent((MutableTreeNode) model.getRoot());
if (isRootVisible()) {
expandRow(0);
setRootVisible(false);
}
addToBay(bay, eq);
} catch (LocationFullException ex) {
// should not happen
}
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class BayWeaponCriticalTree method addAmmoToBay.
public void addAmmoToBay(Mounted bay, Mounted eq, int shots) {
AmmoType at = (AmmoType) eq.getType();
eq.setShotsLeft(eq.getBaseShotsLeft() - shots);
if (eq.getBaseShotsLeft() <= 0) {
UnitUtil.removeMounted(eSource.getEntity(), eq);
}
Optional<Mounted> addMount = bay.getBayAmmo().stream().map(n -> eSource.getEntity().getEquipment(n)).filter(m -> m.getType() == at).findFirst();
if (addMount.isPresent()) {
addMount.get().setShotsLeft(addMount.get().getBaseShotsLeft() + shots);
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
} else {
try {
Mounted m = eSource.getEntity().addEquipment(at, bay.getLocation());
m.setShotsLeft(shots);
addToBay(bay, m);
} catch (LocationFullException e) {
}
}
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class BayWeaponCriticalTree method removeAmmo.
/**
* Moves one or more shots of ammo from this location to unallocated. This should not be used if
* there is only one slot of ammo left in the location;
* use {@link #removeEquipment(EquipmentNode) removeEquipment}
* instead.
*
* @param ammo The allocated ammo to remove.
* @param shots The number of shots to remove.
*/
private void removeAmmo(final Mounted ammo, int shots) {
AmmoType at = (AmmoType) ammo.getType();
ammo.setShotsLeft(ammo.getBaseShotsLeft() - shots);
Mounted unallocated = UnitUtil.findUnallocatedAmmo(eSource.getEntity(), at);
for (Mounted m : eSource.getEntity().getAmmo()) {
if ((m.getLocation() == Entity.LOC_NONE) && (m.getType() == at)) {
unallocated = m;
break;
}
}
if (null != unallocated) {
unallocated.setShotsLeft(ammo.getBaseShotsLeft() + shots);
} else {
unallocated = new Mounted(eSource.getEntity(), at);
unallocated.setShotsLeft(shots);
try {
eSource.getEntity().addEquipment(unallocated, Entity.LOC_NONE, false);
} catch (LocationFullException e) {
}
}
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
}
Aggregations