use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class DropTargetCriticalList method getMounted.
public Mounted getMounted() {
// so they are handled specially
if (getUnit() instanceof BattleArmor) {
// The names for this list should be of the form <eq>:<slot>:<eqId>
String[] split = ((String) this.getSelectedValue()).split(":");
if (split.length > 2) {
int eqId = Integer.parseInt(split[2]);
return getUnit().getEquipment(eqId);
}
return null;
}
CriticalSlot crit = getCrit();
Mounted mount = null;
try {
if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
return crit.getMount();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return mount;
}
use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class UnitUtil method compactCriticals.
public static void compactCriticals(Entity unit, int loc) {
int firstEmpty = -1;
for (int slot = 0; slot < unit.getNumberOfCriticals(loc); slot++) {
CriticalSlot cs = unit.getCritical(loc, slot);
if ((cs == null) && (firstEmpty == -1)) {
firstEmpty = slot;
}
if ((firstEmpty != -1) && (cs != null)) {
// move this to the first empty slot
unit.setCritical(loc, firstEmpty, cs);
// mark the old slot empty
unit.setCritical(loc, slot, null);
// restart just after the moved slot's new location
slot = firstEmpty;
firstEmpty = -1;
}
}
}
use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class UnitUtil method expandUnitMounts.
/**
* Expands crits that are a single mount by have multiple spreadable crits
* Such as TSM, Endo Steel, Reactive armor.
*
* @param unit
*/
public static void expandUnitMounts(Mech unit) {
for (int location = 0; location <= Mech.LOC_LLEG; location++) {
for (int slot = 0; slot < unit.getNumberOfCriticals(location); slot++) {
CriticalSlot cs = unit.getCritical(location, slot);
if ((cs == null) || (cs.getType() == CriticalSlot.TYPE_SYSTEM)) {
continue;
}
Mounted mount = cs.getMount();
if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType()) && (UnitUtil.isTSM(mount.getType()) || UnitUtil.isArmorOrStructure(mount.getType()))) {
Mounted newMount = new Mounted(unit, mount.getType());
newMount.setLocation(location, mount.isRearMounted());
newMount.setArmored(mount.isArmored());
cs.setMount(newMount);
cs.setArmored(mount.isArmored());
unit.getEquipment().remove(mount);
unit.getMisc().remove(mount);
unit.getEquipment().add(newMount);
unit.getMisc().add(newMount);
}
}
}
}
use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class UnitUtil method compactCriticals.
private static void compactCriticals(Mech mech, int loc) {
if (loc == Mech.LOC_HEAD) {
// which will mess up parsing if compacted.
return;
}
int firstEmpty = -1;
for (int slot = 0; slot < mech.getNumberOfCriticals(loc); slot++) {
CriticalSlot cs = mech.getCritical(loc, slot);
if ((cs == null) && (firstEmpty == -1)) {
firstEmpty = slot;
}
if ((firstEmpty != -1) && (cs != null)) {
// move this to the first empty slot
mech.setCritical(loc, firstEmpty, cs);
// mark the old slot empty
mech.setCritical(loc, slot, null);
// restart just after the moved slot's new location
slot = firstEmpty;
firstEmpty = -1;
}
}
}
use of megamek.common.CriticalSlot in project megameklab by MegaMek.
the class CritListCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean hasFocus) {
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, hasFocus);
this.list = list;
setPreferredSize(new Dimension(110, 15));
setMaximumSize(new Dimension(110, 15));
setMinimumSize(new Dimension(110, 15));
String[] split = ((String) value).split(":");
label.setText(split[0]);
CriticalSlot cs;
if (split.length > 2) {
int eqId = Integer.parseInt(split[2]);
cs = new CriticalSlot(unit.getEquipment(eqId));
} else if (split.length > 1) {
cs = getCrit(Integer.parseInt(split[1]));
} else if (((String) value).equals("-Empty-")) {
cs = null;
} else {
cs = getCrit(index);
}
if (cs != null) {
if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
if (useColor) {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_SYSTEMS));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_SYSTEMS));
}
if (cs.isArmored()) {
label.setText(label.getText() + " (A)");
}
} else if (cs.getMount() != null) {
Mounted mount = cs.getMount();
if (useColor) {
if (mount.getType() instanceof WeaponType) {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_WEAPONS));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_WEAPONS));
} else if (mount.getType() instanceof AmmoType) {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_AMMO));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_AMMO));
} else {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_EQUIPMENT));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_EQUIPMENT));
}
}
String name = UnitUtil.getCritName(unit, mount.getType());
if (mount.isRearMounted()) {
name += " (R)";
}
if (mount.isArmored()) {
name += " (A)";
}
if (mount.isMechTurretMounted()) {
name += " (T)";
}
if (mount.isSponsonTurretMounted()) {
name += " (ST)";
}
if (mount.isPintleTurretMounted()) {
name += " (PT)";
}
if (mount.isDWPMounted()) {
name += " (DWP)";
}
if (unit.isOmni() && !mount.getType().isOmniFixedOnly()) {
if (mount.isOmniPodMounted()) {
name += " (Pod)";
} else {
name += " (Fixed)";
label.setFont(label.getFont().deriveFont(Font.ITALIC));
}
}
if ((mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) || mount.getType().hasFlag(MiscType.F_AP_MOUNT)) && mount.getLinked() != null) {
name += " (attached " + mount.getLinked().getName() + ")";
}
// many shots are in this Critical
if ((unit instanceof BattleArmor) && (mount.getType() instanceof AmmoType)) {
name += " (" + mount.getBaseShotsLeft() + ")";
}
String toolTipText = UnitUtil.getToolTipInfo(unit, mount);
if (cs.getMount2() != null) {
mount = cs.getMount2();
name += " | " + UnitUtil.getCritName(unit, mount.getType());
}
label.setText(name);
label.setToolTipText(toolTipText);
}
} else if (useColor) {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_EMPTY));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_EMPTY));
}
int loc = getCritLocation();
if ((cs != null) && UnitUtil.isLastCrit(unit, cs, index, loc) && UnitUtil.isPreviousCritEmpty(unit, cs, index, loc)) {
label.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.black));
} else if ((cs != null) && UnitUtil.isLastCrit(unit, cs, index, loc)) {
label.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black));
} else if ((cs != null) && UnitUtil.isPreviousCritEmpty(unit, cs, index, loc)) {
label.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.black));
}
return label;
}
Aggregations