use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class UnitUtil method replaceMainWeapon.
public static void replaceMainWeapon(Infantry unit, InfantryWeapon weapon, boolean secondary) {
Mounted existingInfantryMount = null;
for (Mounted m : unit.getWeaponList()) {
if ((m.getType() instanceof InfantryWeapon) && (m.getLocation() == Infantry.LOC_INFANTRY)) {
existingInfantryMount = m;
break;
}
}
if (null != existingInfantryMount) {
UnitUtil.removeMounted(unit, existingInfantryMount);
}
if (secondary) {
unit.setSecondaryWeapon(weapon);
} else {
unit.setPrimaryWeapon(weapon);
}
// is TAG, in which case both are added.
if (unit.getSecondaryWeapon() != null && unit.getSecondaryWeapon().hasFlag(WeaponType.F_TAG)) {
try {
unit.addEquipment(unit.getPrimaryWeapon(), Infantry.LOC_INFANTRY);
unit.addEquipment(unit.getSecondaryWeapon(), Infantry.LOC_INFANTRY);
} catch (LocationFullException ex) {
}
} else if ((unit.getSecondaryN() < 2) || (null == unit.getSecondaryWeapon())) {
try {
unit.addEquipment(unit.getPrimaryWeapon(), Infantry.LOC_INFANTRY);
} catch (LocationFullException ex) {
}
} else {
try {
unit.addEquipment(unit.getSecondaryWeapon(), Infantry.LOC_INFANTRY);
} catch (LocationFullException ex) {
}
}
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class EquipmentView method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(ADD_COMMAND)) {
boolean success = false;
Mounted mount = null;
try {
mount = getBattleArmor().addEquipment(equipmentTypes.elementAt(equipmentCombo.getSelectedIndex()), Entity.LOC_NONE, false);
success = mount != null;
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
if (success) {
equipmentList.addCrit(mount);
}
} else if (e.getActionCommand().equals(REMOVE_COMMAND)) {
int startRow = equipmentTable.getSelectedRow();
int count = equipmentTable.getSelectedRowCount();
for (; count > 0; count--) {
if (startRow > -1) {
equipmentList.removeMounted(startRow);
equipmentList.removeCrit(startRow);
}
}
} else if (e.getActionCommand().equals(REMOVEALL_COMMAND)) {
removeAllEquipment();
} else {
return;
}
fireTableRefresh();
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class StructureTab method enhancementChanged.
@Override
public void enhancementChanged(EquipmentType enhancement) {
UnitUtil.removeEnhancements(getMech());
if (null != enhancement) {
if (enhancement.hasFlag(MiscType.F_MASC)) {
Mounted mount = new Mounted(getMech(), enhancement);
try {
getMech().addEquipment(mount, Entity.LOC_NONE, false);
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
} else {
UnitUtil.createSpreadMounts(getMech(), enhancement);
}
}
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
}
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(getMech(), location);
// TODO: move this construction data out of the ui
int crits = 0;
switch(EquipmentType.getArmorType(armor)) {
case EquipmentType.T_ARMOR_STEALTH:
case EquipmentType.T_ARMOR_FERRO_LAMELLOR:
crits = 2;
break;
case EquipmentType.T_ARMOR_HEAVY_FERRO:
crits = 3;
break;
case EquipmentType.T_ARMOR_LIGHT_FERRO:
crits = 1;
break;
case EquipmentType.T_ARMOR_FERRO_FIBROUS:
case EquipmentType.T_ARMOR_REFLECTIVE:
case EquipmentType.T_ARMOR_REACTIVE:
if (armor.isClan()) {
crits = 1;
} else {
crits = 2;
}
break;
}
if (getMech().getEmptyCriticals(location) < crits) {
JOptionPane.showMessageDialog(null, armor.getName() + " does not fit in location " + getMech().getLocationName(location) + ". Resetting to Standard Armor in this location.", "Error", JOptionPane.INFORMATION_MESSAGE);
} else {
getMech().setArmorType(EquipmentType.getArmorType(armor), location);
getMech().setArmorTechLevel(armor.getTechLevel(getTechManager().getGameYear(), armor.isClan()));
for (; crits > 0; crits--) {
try {
getMech().addEquipment(new Mounted(getMech(), armor), location, false);
} catch (LocationFullException ex) {
}
}
}
panArmor.refresh();
panArmorAllocation.setFromEntity(getMech());
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshSummary();
refresh.refreshStatus();
}
use of megamek.common.LocationFullException in project megameklab by MegaMek.
the class StructureTab method jumpChanged.
@Override
public void jumpChanged(int jumpMP, EquipmentType jumpJet) {
// Don't set jumpMP for UMU.
if (null == jumpJet) {
getMech().setOriginalJumpMP(0);
jumpMP = 0;
} else if (jumpJet.hasFlag(MiscType.F_JUMP_JET) || jumpJet.hasFlag(MiscType.F_JUMP_BOOSTER)) {
getMech().setOriginalJumpMP(jumpMP);
} else {
getMech().setOriginalJumpMP(0);
}
List<Mounted> jjs = getMech().getMisc().stream().filter(m -> m.getType() == jumpJet).collect(Collectors.toList());
if (jumpJet.hasFlag(MiscType.F_JUMP_BOOSTER)) {
if (!getMech().hasWorkingMisc(MiscType.F_JUMP_BOOSTER)) {
UnitUtil.createSpreadMounts(getMech(), jumpJet);
}
} else {
while (jjs.size() > jumpMP) {
UnitUtil.removeMounted(getMech(), jjs.remove(jjs.size() - 1));
}
while (jumpMP > jjs.size()) {
try {
UnitUtil.addMounted(getMech(), new Mounted(getMech(), jumpJet), Entity.LOC_NONE, false);
} catch (LocationFullException e) {
// Adding to LOC_NONE
}
jumpMP--;
}
}
panSummary.refresh();
refresh.refreshBuild();
refresh.refreshStatus();
refresh.refreshPreview();
panMovement.setFromEntity(getMech());
}
Aggregations