Search in sources :

Example 31 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class UnitUtil method removeHeatSinks.

/**
 * Removes the specified number of heat sinks from the mek Heat sinks are
 * removed first fwith LOC_NONE above the free crit limit then they are
 * removed with a location, and lastly they are removed below the free crit
 * limit
 *
 * @param unit
 */
public static void removeHeatSinks(Mech unit, int number) {
    final String METHOD_NAME = "removeHeatSinks(Mech, int)";
    Vector<Mounted> toRemove = new Vector<Mounted>();
    int base = UnitUtil.getCriticalFreeHeatSinks(unit, unit.hasCompactHeatSinks());
    boolean splitCompact = false;
    if (unit.hasCompactHeatSinks()) {
        // first check to see if there is a single compact heat sink outside
        // of
        // the engine and remove this first if so
        Mounted mount = UnitUtil.getSingleCompactHeatSink(unit);
        if ((null != mount) && (number > 0)) {
            UnitUtil.removeMounted(unit, mount);
            number--;
        }
        // compact
        if ((number % 2) == 1) {
            splitCompact = true;
            number--;
        }
    }
    Vector<Mounted> unassigned = new Vector<Mounted>();
    Vector<Mounted> assigned = new Vector<Mounted>();
    Vector<Mounted> free = new Vector<Mounted>();
    for (Mounted m : unit.getMisc()) {
        if (UnitUtil.isHeatSink(m)) {
            if (m.getLocation() == Entity.LOC_NONE) {
                if (base > 0) {
                    free.add(m);
                    base--;
                } else {
                    unassigned.add(m);
                }
            } else {
                assigned.add(m);
            }
        }
    }
    toRemove.addAll(unassigned);
    toRemove.addAll(assigned);
    toRemove.addAll(free);
    if (unit.hasCompactHeatSinks()) {
        // need to do some number magic here. The unassigned and assigned
        // slots
        // should each contain two heat sinks, but if we dip into the free
        // then we
        // are looking at one heat sink.
        int numberDouble = Math.min(number / 2, unassigned.size() + assigned.size());
        int numberSingle = Math.max(0, number - (2 * numberDouble));
        number = numberDouble + numberSingle;
    }
    number = Math.min(number, toRemove.size());
    for (int i = 0; i < number; i++) {
        Mounted eq = toRemove.get(i);
        UnitUtil.removeMounted(unit, eq);
    }
    if (splitCompact) {
        Mounted eq = toRemove.get(number);
        int loc = eq.getLocation();
        // remove singleCompact mount and replace with a double
        UnitUtil.removeMounted(unit, eq);
        if (!eq.getType().hasFlag(MiscType.F_HEAT_SINK)) {
            try {
                UnitUtil.addMounted(unit, new Mounted(unit, EquipmentType.get("IS1 Compact Heat Sink")), loc, false);
            } catch (Exception ex) {
                getLogger().log(UnitUtil.class, METHOD_NAME, ex);
            }
        }
    }
}
Also used : Mounted(megamek.common.Mounted) Vector(java.util.Vector) LocationFullException(megamek.common.LocationFullException)

Example 32 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class UnitUtil method countUnallocatedCriticals.

public static int countUnallocatedCriticals(Mech unit) {
    int nCrits = 0;
    int engineHeatSinkCount = UnitUtil.getCriticalFreeHeatSinks(unit, unit.hasCompactHeatSinks());
    for (Mounted mount : unit.getMisc()) {
        if (UnitUtil.isHeatSink(mount) && (mount.getLocation() == Entity.LOC_NONE)) {
            if (engineHeatSinkCount > 0) {
                engineHeatSinkCount--;
                continue;
            }
        }
        if ((mount.getLocation() == Entity.LOC_NONE)) {
            nCrits += UnitUtil.getCritsUsed(unit, mount.getType());
        }
    }
    for (Mounted mount : unit.getWeaponList()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            nCrits += UnitUtil.getCritsUsed(unit, mount.getType());
        }
    }
    for (Mounted mount : unit.getAmmo()) {
        if ((mount.getLocation() == Entity.LOC_NONE) && ((mount.getUsableShotsLeft() > 1) || (((AmmoType) mount.getType()).getAmmoType() == AmmoType.T_COOLANT_POD))) {
            nCrits += UnitUtil.getCritsUsed(unit, mount.getType());
        }
    }
    return nCrits;
}
Also used : Mounted(megamek.common.Mounted)

Example 33 with Mounted

use of megamek.common.Mounted 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);
                }
            }
        }
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) ArrayList(java.util.ArrayList)

Example 34 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class UnitUtil method resetCriticalsAndMounts.

/**
 * Reset all the Crits and Mounts on the Unit.
 *
 * @param unit
 */
public static void resetCriticalsAndMounts(Mech unit) {
    for (int location = Mech.LOC_HEAD; 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_EQUIPMENT)) {
                cs = null;
                unit.setCritical(location, slot, cs);
            }
        }
    }
    for (Mounted mount : unit.getEquipment()) {
        mount.setLocation(Entity.LOC_NONE, false);
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted)

Example 35 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class WeaponListCellRenderer 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);
    EquipmentType eq = EquipmentType.get(value.toString());
    if (eq == null) {
        return label;
    }
    label.setText(UnitUtil.getCritName(unit, eq));
    label.setName(value.toString());
    label.setToolTipText(UnitUtil.getToolTipInfo(unit, new Mounted(unit, eq)));
    return label;
}
Also used : Mounted(megamek.common.Mounted) JLabel(javax.swing.JLabel) EquipmentType(megamek.common.EquipmentType)

Aggregations

Mounted (megamek.common.Mounted)131 MiscType (megamek.common.MiscType)38 LocationFullException (megamek.common.LocationFullException)34 AmmoType (megamek.common.AmmoType)32 CriticalSlot (megamek.common.CriticalSlot)31 EquipmentType (megamek.common.EquipmentType)27 ArrayList (java.util.ArrayList)25 WeaponType (megamek.common.WeaponType)25 Vector (java.util.Vector)21 EntityLoadingException (megamek.common.loaders.EntityLoadingException)17 Font (java.awt.Font)14 BattleArmor (megamek.common.BattleArmor)11 JMenuItem (javax.swing.JMenuItem)9 JPopupMenu (javax.swing.JPopupMenu)9 Entity (megamek.common.Entity)9 TestBattleArmor (megamek.common.verifier.TestBattleArmor)9 Dimension (java.awt.Dimension)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)7 List (java.util.List)6