use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class EquipmentTab method addEquipment.
private void addEquipment(EquipmentType equip) {
Mounted mount = null;
boolean isMisc = equip instanceof MiscType;
if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
if (!UnitUtil.hasTargComp(getAero())) {
mount = UnitUtil.updateTC(getAero(), equip);
if (null != mount) {
equipmentList.addCrit(mount);
}
}
} else {
int count = (Integer) spnAddCount.getValue();
if (getAero().usesWeaponBays() && (equip instanceof AmmoType)) {
Mounted aMount = UnitUtil.findUnallocatedAmmo(getAero(), equip);
if (null != aMount) {
aMount.setShotsLeft(aMount.getUsableShotsLeft() + ((AmmoType) equip).getShots() * count);
return;
} else {
mount = new Mounted(getAero(), equip);
mount.setShotsLeft(((AmmoType) equip).getShots() * count);
try {
getAero().addEquipment(mount, Entity.LOC_NONE, false);
equipmentList.addCrit(mount);
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
} else {
try {
for (int i = 0; i < count; i++) {
mount = new Mounted(getAero(), equip);
getAero().addEquipment(mount, Entity.LOC_NONE, false);
equipmentList.addCrit(mount);
}
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
}
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class StructureTab method patchworkChanged.
@Override
public void patchworkChanged(int location, EquipmentType armor) {
UnitUtil.resetArmor(getAero(), location);
// TODO: move this construction data out of the ui
int crits = 0;
switch(EquipmentType.getArmorType(armor)) {
case EquipmentType.T_ARMOR_STEALTH_VEHICLE:
case EquipmentType.T_ARMOR_LIGHT_ALUM:
case EquipmentType.T_ARMOR_ALUM:
case EquipmentType.T_ARMOR_FERRO_ALUM_PROTO:
case EquipmentType.T_ARMOR_FERRO_LAMELLOR:
case EquipmentType.T_ARMOR_REFLECTIVE:
case EquipmentType.T_ARMOR_REACTIVE:
crits = 1;
break;
case EquipmentType.T_ARMOR_HEAVY_ALUM:
crits = 2;
break;
}
if (getAero().getEmptyCriticals(location) < crits) {
JOptionPane.showMessageDialog(null, armor.getName() + " does not fit in location " + getAero().getLocationName(location) + ". Resetting to Standard Armor in this location.", "Error", JOptionPane.INFORMATION_MESSAGE);
} else {
getAero().setArmorType(EquipmentType.getArmorType(armor), location);
getAero().setArmorTechLevel(armor.getTechLevel(getTechManager().getGameYear(), armor.isClan()));
for (; crits > 0; crits--) {
try {
getAero().addEquipment(new Mounted(getAero(), armor), location, false);
} catch (LocationFullException ex) {
}
}
}
panArmor.refresh();
panArmorAllocation.setFromEntity(getAero());
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshSummary();
refresh.refreshStatus();
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class EquipmentTab method addEquipment.
private void addEquipment(EquipmentType equip) {
Mounted mount = null;
boolean isMisc = equip instanceof MiscType;
boolean multiMount = UnitUtil.isBAMultiMount(equip);
if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
if (!UnitUtil.hasTargComp(getBattleArmor())) {
mount = UnitUtil.updateTC(getBattleArmor(), equip);
if (mount != null) {
equipmentList.addCrit(mount);
}
}
} else {
try {
if (multiMount) {
for (int t = 1; t <= getBattleArmor().getTroopers(); t++) {
mount = new Mounted(getBattleArmor(), equip);
mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
getBattleArmor().addEquipment(mount, t, false);
equipmentList.addCrit(mount);
}
} else {
mount = new Mounted(getBattleArmor(), equip);
mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
getBattleArmor().addEquipment(mount, BattleArmor.LOC_SQUAD, false);
equipmentList.addCrit(mount);
}
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class StructureTab method enhancementChanged.
@Override
public void enhancementChanged(EquipmentType eq, boolean selected) {
if (selected) {
try {
int loc = BattleArmor.MOUNT_LOC_BODY;
if (eq.hasFlag(MiscType.F_MASC)) {
loc = BattleArmor.MOUNT_LOC_NONE;
}
int numTimesToAdd = 1;
// for each critical
if (eq.isSpreadable()) {
numTimesToAdd = eq.getCriticals(getBattleArmor());
}
for (int i = 0; i < numTimesToAdd; i++) {
Mounted newMount = new Mounted(getBattleArmor(), eq);
newMount.setBaMountLoc(loc);
getBattleArmor().addEquipment(newMount, BattleArmor.LOC_SQUAD, false);
}
} catch (LocationFullException exc) {
// Shouldn't happen with BA
exc.printStackTrace();
}
} else {
List<Mounted> mounts = getBattleArmor().getMisc().stream().filter(m -> m.getType().equals(eq)).collect(Collectors.toList());
for (Mounted mount : mounts) {
UnitUtil.removeMounted(getBattleArmor(), mount);
}
}
panMovement.setFromEntity(getBattleArmor());
refresh.refreshSummary();
refresh.refreshBuild();
refresh.refreshPreview();
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class StructureTab method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
removeAllListeners();
if (e.getSource() instanceof JComboBox) {
@SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) e.getSource();
if (combo.equals(leftManipSelect)) {
// If the BA already had a manipulator here, we'll need to
// remove it
Mounted leftManip = getBattleArmor().getLeftManipulator();
BAManipulator manipType;
if (leftManip != null) {
UnitUtil.removeMounted(getBattleArmor(), leftManip);
manipType = BAManipulator.getManipulator(leftManip.getType().getInternalName());
// remove the paired manipulator
if (manipType.pairMounted) {
Mounted rightManip = getBattleArmor().getRightManipulator();
if (rightManip != null) {
UnitUtil.removeMounted(getBattleArmor(), rightManip);
rightManipSelect.setSelectedIndex(0);
}
}
}
// If we selected something other than "None", mount it
if (leftManipSelect.getSelectedIndex() != 0) {
String manipName = (String) leftManipSelect.getSelectedItem();
manipType = BAManipulator.getManipulator(manipName);
EquipmentType et = EquipmentType.get(manipType.internalName);
leftManip = new Mounted(getBattleArmor(), et);
leftManip.setBaMountLoc(BattleArmor.MOUNT_LOC_LARM);
try {
// Add the manipulator
getBattleArmor().addEquipment(leftManip, BattleArmor.LOC_SQUAD, false);
// Check to see if we need to add its mate
manipType = BAManipulator.getManipulator(leftManip.getType().getInternalName());
// remove the paired manipulator
if (manipType.pairMounted) {
Mounted rightManip = new Mounted(getBattleArmor(), et);
rightManip.setBaMountLoc(BattleArmor.MOUNT_LOC_RARM);
getBattleArmor().addEquipment(rightManip, BattleArmor.LOC_SQUAD, false);
}
} catch (LocationFullException ex) {
// This shouldn't happen
ex.printStackTrace();
}
}
} else if (combo.equals(rightManipSelect)) {
// If the BA already had a manipulator here, we'll need to
// remove it
Mounted rightManip = getBattleArmor().getRightManipulator();
BAManipulator manipType;
if (rightManip != null) {
UnitUtil.removeMounted(getBattleArmor(), rightManip);
manipType = BAManipulator.getManipulator(rightManip.getType().getInternalName());
// remove the paired manipulator
if (manipType.pairMounted) {
Mounted leftManip = getBattleArmor().getLeftManipulator();
if (leftManip != null) {
UnitUtil.removeMounted(getBattleArmor(), leftManip);
leftManipSelect.setSelectedIndex(0);
}
}
}
// If we selected something other than "None", mount it
if (rightManipSelect.getSelectedIndex() != 0) {
String manipName = (String) rightManipSelect.getSelectedItem();
manipType = BAManipulator.getManipulator(manipName);
EquipmentType et = EquipmentType.get(manipType.internalName);
rightManip = new Mounted(getBattleArmor(), et);
rightManip.setBaMountLoc(BattleArmor.MOUNT_LOC_RARM);
try {
// Add the manipulator
getBattleArmor().addEquipment(rightManip, BattleArmor.LOC_SQUAD, false);
// Check to see if we need to add its mate
manipType = BAManipulator.getManipulator(rightManip.getType().getInternalName());
// remove the paired manipulator
if (manipType.pairMounted) {
Mounted leftManip = new Mounted(getBattleArmor(), et);
leftManip.setBaMountLoc(BattleArmor.MOUNT_LOC_LARM);
getBattleArmor().addEquipment(leftManip, BattleArmor.LOC_SQUAD, false);
}
} catch (LocationFullException ex) {
// This shouldn't happen
ex.printStackTrace();
}
}
}
}
refresh.refreshAll();
}
Aggregations