use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class DropTargetCriticalList method getCrit.
private CriticalSlot getCrit() {
int slot = getSelectedIndex();
int location = getCritLocation();
CriticalSlot crit = null;
if ((slot >= 0) && (slot < getUnit().getNumberOfCriticals(location))) {
crit = getUnit().getCritical(location, slot);
}
return crit;
}
use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class DropTargetCriticalList method mousePressed.
public void mousePressed(MouseEvent e) {
if (buildView) {
if (e.getButton() == MouseEvent.BUTTON2) {
setSelectedIndex(locationToIndex(e.getPoint()));
removeCrit();
} else if (e.getButton() == MouseEvent.BUTTON3) {
setSelectedIndex(locationToIndex(e.getPoint()));
if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
removeCrit();
return;
}
int location = getCritLocation();
JPopupMenu popup = new JPopupMenu();
CriticalSlot cs = getCrit();
Mounted mount = getMounted();
if ((e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
changeWeaponFacing(!mount.isRearMounted());
return;
}
if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
changeOmniMounting(!mount.isOmniPodMounted());
return;
}
if (mount != null) {
popup.setAutoscrolls(true);
JMenuItem info;
if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType())) {
info = new JMenuItem("Remove " + mount.getName());
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeCrit();
}
});
popup.add(info);
}
info = new JMenuItem("Delete " + mount.getName());
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeMount();
}
});
popup.add(info);
if ((mount.getType() instanceof WeaponType) && getUnit().hasWorkingMisc(MiscType.F_SPONSON_TURRET) && ((mount.getLocation() == Tank.LOC_LEFT) || (mount.getLocation() == Tank.LOC_RIGHT))) {
if (!mount.isSponsonTurretMounted()) {
info = new JMenuItem("Mount " + mount.getName() + " in Sponson Turret");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeSponsonTurretMount(true);
}
});
popup.add(info);
} else {
info = new JMenuItem("Remove " + mount.getName() + " from Sponson Turret");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeSponsonTurretMount(false);
}
});
popup.add(info);
}
}
if ((mount.getType() instanceof WeaponType) && getUnit().hasWorkingMisc(MiscType.F_PINTLE_TURRET, mount.getLocation())) {
if (!mount.isPintleTurretMounted()) {
info = new JMenuItem("Mount " + mount.getName() + " in Pintle Turret");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changePintleTurretMount(true);
}
});
popup.add(info);
} else {
info = new JMenuItem("Remove " + mount.getName() + " from Pintle Turret");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changePintleTurretMount(false);
}
});
popup.add(info);
}
}
if (getUnit().isOmni() && !mount.getType().isOmniFixedOnly()) {
if (mount.isOmniPodMounted()) {
info = new JMenuItem("Change to fixed mount");
info.addActionListener(ev -> changeOmniMounting(false));
popup.add(info);
} else if (UnitUtil.canPodMount(getUnit(), mount)) {
info = new JMenuItem("Change to pod mount");
info.addActionListener(ev -> changeOmniMounting(true));
popup.add(info);
}
}
}
if (UnitUtil.isArmorable(cs) && ((UnitUtil.getUnitTechType(getUnit()) == UnitUtil.TECH_EXPERIMENTAL) || (UnitUtil.getUnitTechType(getUnit()) == UnitUtil.TECH_UNOFFICAL))) {
popup.addSeparator();
if (cs.isArmored()) {
JMenuItem info = new JMenuItem("Remove Armoring");
info.setActionCommand(Integer.toString(location));
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeArmoring();
}
});
popup.add(info);
} else {
JMenuItem info = new JMenuItem("Add Armoring");
info.setActionCommand(Integer.toString(location));
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeArmoring();
}
});
popup.add(info);
}
}
if (popup.getComponentCount() > 0) {
popup.show(this, e.getX(), e.getY());
}
}
}
}
use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class UnitUtil method removeCriticals.
/**
* Sets the corresponding critical slots to null for the Mounted object.
*
* @param unit
* @param eq
*/
public static void removeCriticals(Entity unit, Mounted eq) {
if (eq.getLocation() == Entity.LOC_NONE) {
return;
}
for (int loc = 0; loc < unit.locations(); loc++) {
for (int slot = 0; slot < unit.getNumberOfCriticals(loc); slot++) {
CriticalSlot cs = unit.getCritical(loc, slot);
if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
if (cs.getMount().equals(eq)) {
// remove first one, and replace it with the second
if (cs.getMount2() != null) {
cs.setMount(cs.getMount2());
cs.setMount2(null);
} else {
// If it's the only Mounted, clear the slot
cs = null;
unit.setCritical(loc, slot, cs);
}
} else if ((cs.getMount2() != null) && cs.getMount2().equals(eq)) {
cs.setMount2(null);
}
}
}
}
}
use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class UnitUtil method removeISorArmorCrits.
/**
* remove all CriticalSlots on the passed unit that are internal structure or
* armor
*
* @param unit
* the Entity
* @param internalStructure
* true to remove IS, false to remove armor
*/
public static void removeISorArmorCrits(Entity unit, boolean internalStructure) {
ArrayList<String> mountList = new ArrayList<String>();
if (internalStructure) {
for (String struc : EquipmentType.structureNames) {
mountList.add("IS " + struc);
mountList.add("Clan " + struc);
}
} else {
for (String armor : EquipmentType.armorNames) {
mountList.add("IS " + armor);
mountList.add("Clan " + armor);
}
}
for (int location = Mech.LOC_HEAD; location < unit.locations(); location++) {
for (int slot = 0; slot < unit.getNumberOfCriticals(location); slot++) {
CriticalSlot crit = unit.getCritical(location, slot);
if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
Mounted mount = crit.getMount();
if ((mount != null) && (mount.getType() instanceof MiscType) && mountList.contains(mount.getType().getInternalName())) {
crit = null;
unit.setCritical(location, slot, crit);
}
}
}
}
}
use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class UnitUtil method resetArmor.
/**
* Remove all mounts for the current armor type from a single location on the passed unit
* and sets the armor type in that location to standard.
*
* @param unit The <code>Entity</code>
* @param loc The location from which to remove the armor mounts.
*/
public static void resetArmor(Entity unit, int loc) {
String name = EquipmentType.getArmorTypeName(unit.getArmorType(loc), TechConstants.isClan(unit.getArmorTechLevel(loc)));
EquipmentType eq = EquipmentType.get(name);
if (null != eq) {
for (int slot = 0; slot < unit.getNumberOfCriticals(loc); slot++) {
final CriticalSlot crit = unit.getCritical(loc, slot);
if ((null != crit) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT) && (null != crit.getMount()) && crit.getMount().getType().equals(eq)) {
unit.getMisc().remove(crit.getMount());
unit.setCritical(loc, slot, null);
}
}
}
unit.setArmorType(EquipmentType.T_ARMOR_STANDARD, loc);
unit.setArmorTechLevel(TechConstants.T_INTRO_BOXSET, loc);
}
Aggregations