use of megamek.common.Mounted 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();
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class StructureTab method turretChanged.
@Override
public void turretChanged(int type, int size) {
getBattleArmor().setModularTurret(type == BAChassisView.TURRET_MODULAR);
if (type == BAChassisView.TURRET_NONE) {
size = 0;
} else {
size = Math.max(1, size);
}
getBattleArmor().setTurretSize(size);
if (size == 0) {
for (Mounted mount : getBattleArmor().getEquipment()) {
if (mount.getBaMountLoc() == BattleArmor.MOUNT_LOC_TURRET) {
mount.setBaMountLoc(BattleArmor.MOUNT_LOC_BODY);
}
}
}
panChassis.setFromEntity(getBattleArmor());
refresh.refreshStatus();
refresh.refreshPreview();
refresh.refreshBuild();
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class BuildTab method autoFillCrits.
private void autoFillCrits() {
for (Mounted mount : buildView.getTableModel().getCrits()) {
for (int location = 0; location < getTank().locations(); location++) {
try {
getTank().addEquipment(mount, location, false);
UnitUtil.changeMountStatus(getTank(), mount, location, Entity.LOC_NONE, false);
break;
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
refresh.refreshAll();
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class EquipmentTab method addEquipment.
private void addEquipment(EquipmentType equip) {
boolean success = false;
Mounted mount = null;
boolean isMisc = equip instanceof MiscType;
if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
if (!UnitUtil.hasTargComp(getTank())) {
mount = UnitUtil.updateTC(getTank(), equip);
success = mount != null;
}
} else {
try {
mount = new Mounted(getTank(), equip);
int loc = Entity.LOC_NONE;
if (isMisc && equip.hasFlag(MiscType.F_MAST_MOUNT)) {
loc = VTOL.LOC_ROTOR;
}
getTank().addEquipment(mount, loc, false);
success = true;
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
if (success) {
equipmentList.addCrit(mount);
}
}
use of megamek.common.Mounted 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++;
}
}
}
Aggregations