use of megamek.common.EquipmentType in project megameklab by MegaMek.
the class EquipmentTab method removeHeatSinks.
private void removeHeatSinks() {
int location = 0;
for (; location < equipmentList.getRowCount(); ) {
Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
EquipmentType eq = mount.getType();
if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
try {
equipmentList.removeCrit(location);
} catch (ArrayIndexOutOfBoundsException aioobe) {
return;
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
location++;
}
}
}
use of megamek.common.EquipmentType in project megameklab by MegaMek.
the class EquipmentTab method loadEquipmentTable.
private void loadEquipmentTable() {
for (Mounted mount : getBattleArmor().getWeaponList()) {
if (UnitUtil.isBattleArmorWeapon(mount.getType(), getBattleArmor()) || UnitUtil.isBattleArmorAPWeapon(mount.getType())) {
equipmentList.addCrit(mount);
}
}
for (Mounted mount : getBattleArmor().getAmmo()) {
// Ignore ammo for one-shot launchers
if (mount.getLinkedBy() != null && mount.getLinkedBy().isOneShot()) {
continue;
}
equipmentList.addCrit(mount);
}
List<EquipmentType> spreadAlreadyAdded = new ArrayList<EquipmentType>();
for (Mounted mount : getBattleArmor().getMisc()) {
EquipmentType etype = mount.getType();
if (UnitUtil.isHeatSink(mount) || etype.hasFlag(MiscType.F_JUMP_JET) || etype.hasFlag(MiscType.F_JUMP_BOOSTER) || etype.hasFlag(MiscType.F_TSM) || etype.hasFlag(MiscType.F_INDUSTRIAL_TSM) || (etype.hasFlag(MiscType.F_MASC) && !etype.hasSubType(MiscType.S_SUPERCHARGER)) || UnitUtil.isArmorOrStructure(etype)) {
continue;
}
// if (UnitUtil.isUnitEquipment(mount.getType(), unit) || UnitUtil.isUn) {
if (UnitUtil.isFixedLocationSpreadEquipment(etype) && !spreadAlreadyAdded.contains(etype)) {
equipmentList.addCrit(mount);
// keep track of spreadable equipment here, so it doesn't
// show up multiple times in the table
spreadAlreadyAdded.add(etype);
} else {
equipmentList.addCrit(mount);
}
// }
}
}
use of megamek.common.EquipmentType in project megameklab by MegaMek.
the class EquipmentTab method removeHeatSinks.
private void removeHeatSinks() {
int location = 0;
for (; location < equipmentList.getRowCount(); ) {
Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
EquipmentType eq = mount.getType();
if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
try {
equipmentList.removeCrit(location);
} catch (ArrayIndexOutOfBoundsException aioobe) {
return;
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
location++;
}
}
}
use of megamek.common.EquipmentType 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.EquipmentType 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