Search in sources :

Example 31 with CriticalSlot

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

the class DropTargetCriticalList method changeArmoring.

private void changeArmoring() {
    CriticalSlot cs = getCrit();
    if (cs != null) {
        if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
            Mounted mount = getMounted();
            mount.setArmored(!cs.isArmored());
            UnitUtil.updateCritsArmoredStatus(getUnit(), mount);
        } else {
            cs.setArmored(!cs.isArmored());
            UnitUtil.updateCritsArmoredStatus(getUnit(), cs, getCritLocation());
        }
    }
    // Check linkings after you remove everything.
    try {
        MechFileParser.postLoadInit(getUnit());
    } catch (EntityLoadingException ele) {
    // do nothing.
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    if (refresh != null) {
        refresh.refreshAll();
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Example 32 with CriticalSlot

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

the class UnitUtil method removeOneShotAmmo.

public static void removeOneShotAmmo(Entity unit) {
    ArrayList<Mounted> ammoList = new ArrayList<Mounted>();
    for (Mounted mount : unit.getAmmo()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            ammoList.add(mount);
        }
    }
    for (Mounted mount : ammoList) {
        int index = unit.getEquipment().indexOf(mount);
        unit.getEquipment().remove(mount);
        unit.getAmmo().remove(mount);
        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;
                }
                if (cs.getIndex() >= index) {
                    cs.setIndex(cs.getIndex() - 1);
                }
            }
        }
    }
}
Also used : Mounted(megamek.common.Mounted) CriticalSlot(megamek.common.CriticalSlot) ArrayList(java.util.ArrayList)

Example 33 with CriticalSlot

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

the class UnitUtil method createSpreadMounts.

/**
 * create a Mounted and corresponding CriticalSlots for the passed in
 * <code>EquipmentType</code> on the passed in <code>Mech</code>
 *
 * @param unit
 * @param equip
 * @return
 */
public static Mounted createSpreadMounts(Mech unit, EquipmentType equip) {
    final String METHOD_NAME = "createSpreadMounts(Mech, EquipmentType)";
    // how many non-spreadable contiguous blocks of crits?
    int blocks = 0;
    boolean isMisc = equip instanceof MiscType;
    blocks = equip.getCriticals(unit);
    List<Integer> locations = new ArrayList<Integer>();
    if (isMisc) {
        if ((equip.hasFlag(MiscType.F_INDUSTRIAL_TSM) || equip.hasFlag(MiscType.F_TSM))) {
            // all crits user placeable
            for (int i = 0; i < equip.getCriticals(unit); i++) {
                locations.add(Entity.LOC_NONE);
            }
        } else if (equip.hasFlag(MiscType.F_ENVIRONMENTAL_SEALING)) {
            // 1 crit in each location
            for (int i = 0; i < unit.locations(); i++) {
                locations.add(i);
            }
        } else if (equip.hasFlag(MiscType.F_STEALTH)) {
            // 2 in arms, legs, side torsos
            locations.add(Mech.LOC_LLEG);
            locations.add(Mech.LOC_RLEG);
            locations.add(Mech.LOC_LARM);
            locations.add(Mech.LOC_RARM);
            locations.add(Mech.LOC_LT);
            locations.add(Mech.LOC_RT);
            blocks = 6;
            // Need to account for the center leg
            if (unit instanceof TripodMech) {
                locations.add(Mech.LOC_CLEG);
                blocks++;
            }
        } else if (equip.hasFlag(MiscType.F_SCM)) {
            // 1 in arms, legs, side torsos
            locations.add(Mech.LOC_LLEG);
            locations.add(Mech.LOC_RLEG);
            locations.add(Mech.LOC_LARM);
            locations.add(Mech.LOC_RARM);
            locations.add(Mech.LOC_LT);
            locations.add(Mech.LOC_RT);
            blocks = 6;
        } else if ((equip.hasFlag(MiscType.F_TRACKS) || equip.hasFlag(MiscType.F_TALON) || equip.hasFlag(MiscType.F_JUMP_BOOSTER))) {
            // 1 block in each leg
            locations.add(Mech.LOC_LLEG);
            locations.add(Mech.LOC_RLEG);
            if (unit instanceof QuadMech) {
                locations.add(Mech.LOC_LARM);
                locations.add(Mech.LOC_RARM);
            }
            blocks = (unit instanceof BipedMech ? 2 : 4);
            // Need to account for the center leg
            if (unit instanceof TripodMech) {
                locations.add(Mech.LOC_CLEG);
                blocks = 3;
            }
        } else if (equip.hasFlag(MiscType.F_PARTIAL_WING)) {
            // one block in each side torso
            locations.add(Mech.LOC_LT);
            locations.add(Mech.LOC_RT);
            blocks = 2;
        } else if ((equip.hasFlag(MiscType.F_VOIDSIG) || equip.hasFlag(MiscType.F_NULLSIG) || equip.hasFlag(MiscType.F_BLUE_SHIELD))) {
            // Need to account for the center leg
            if (unit instanceof TripodMech) {
                blocks++;
            }
            // 1 crit in each location, except the head
            for (int i = Mech.LOC_CT; i < unit.locations(); i++) {
                locations.add(i);
            }
        } else if (equip.hasFlag(MiscType.F_CHAMELEON_SHIELD)) {
            // Need to account for the center leg
            if (unit instanceof TripodMech) {
                blocks++;
            }
            // 1 crit in each location except head and CT
            for (int i = Mech.LOC_RT; i < unit.locations(); i++) {
                locations.add(i);
            }
        }
    }
    boolean firstBlock = true;
    Mounted mount = new Mounted(unit, equip);
    for (; blocks > 0; blocks--) {
        // how many crits per block?
        int crits = UnitUtil.getCritsUsed(unit, equip);
        for (int i = 0; i < crits; i++) {
            try {
                if (firstBlock || (locations.get(0) == Entity.LOC_NONE)) {
                    // create only one mount per equipment, for BV and stuff
                    addMounted(unit, mount, locations.get(0), false);
                    if (firstBlock) {
                        firstBlock = false;
                    }
                    if (locations.get(0) == Entity.LOC_NONE) {
                        // only user-placable spread stuff gets location
                        // none
                        // for those, we need to create a mount for each
                        // crit,
                        // otherwise we can't correctly let the user place
                        // them
                        // luckily, that only affects TSM, so BV works out
                        // correctly
                        mount = new Mounted(unit, equip);
                    }
                } else {
                    CriticalSlot cs = new CriticalSlot(mount);
                    if (!unit.addCritical(locations.get(0), cs)) {
                        UnitUtil.removeCriticals(unit, mount);
                        JOptionPane.showMessageDialog(null, "No room for equipment", mount.getName() + " does not fit into " + unit.getLocationName(locations.get(0)), JOptionPane.INFORMATION_MESSAGE);
                        unit.getMisc().remove(mount);
                        unit.getEquipment().remove(mount);
                        return null;
                    }
                }
            } catch (LocationFullException lfe) {
                getLogger().log(UnitUtil.class, METHOD_NAME, lfe);
                JOptionPane.showMessageDialog(null, lfe.getMessage(), mount.getName() + " does not fit into " + unit.getLocationName(locations.get(0)), JOptionPane.INFORMATION_MESSAGE);
                unit.getMisc().remove(mount);
                unit.getEquipment().remove(mount);
                return null;
            }
        }
        locations.remove(0);
    }
    return mount;
}
Also used : TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) CriticalSlot(megamek.common.CriticalSlot) MiscType(megamek.common.MiscType) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) BipedMech(megamek.common.BipedMech)

Example 34 with CriticalSlot

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

the class UnitUtil method removeClanCase.

public static void removeClanCase(Entity unit) {
    ArrayList<Mounted> caseList = new ArrayList<Mounted>();
    for (Mounted mount : unit.getMisc()) {
        if (mount.getType().getInternalName().equals("CLCASE")) {
            caseList.add(mount);
        }
    }
    for (Mounted mount : caseList) {
        int index = unit.getEquipment().indexOf(mount);
        unit.getEquipment().remove(mount);
        unit.getMisc().remove(mount);
        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;
                }
                if (cs.getIndex() >= index) {
                    cs.setIndex(cs.getIndex() - 1);
                }
            }
        }
    }
}
Also used : Mounted(megamek.common.Mounted) CriticalSlot(megamek.common.CriticalSlot) ArrayList(java.util.ArrayList)

Example 35 with CriticalSlot

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

the class UnitUtil method getShieldDamageCapacity.

public static int getShieldDamageCapacity(Mech mech, int location) {
    final String METHOD_NAME = "getShieldDamageCapacity(Mech, int)";
    for (int slot = 0; slot < mech.getNumberOfCriticals(location); slot++) {
        CriticalSlot cs = mech.getCritical(location, slot);
        if (cs == null) {
            continue;
        }
        if (cs.getType() != CriticalSlot.TYPE_EQUIPMENT) {
            continue;
        }
        Mounted m = cs.getMount();
        if (m == null) {
            getLogger().log(UnitUtil.class, METHOD_NAME, LogLevel.ERROR, "Null Mount index: " + cs.getIndex());
            m = cs.getMount();
        }
        EquipmentType type = m.getType();
        if ((type instanceof MiscType) && ((MiscType) type).isShield()) {
            return m.getBaseDamageCapacity();
        }
    }
    return 0;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType)

Aggregations

CriticalSlot (megamek.common.CriticalSlot)38 Mounted (megamek.common.Mounted)28 EntityLoadingException (megamek.common.loaders.EntityLoadingException)11 BattleArmor (megamek.common.BattleArmor)7 MiscType (megamek.common.MiscType)7 Vector (java.util.Vector)6 TestBattleArmor (megamek.common.verifier.TestBattleArmor)6 WeaponType (megamek.common.WeaponType)5 Font (java.awt.Font)4 ArrayList (java.util.ArrayList)4 EquipmentType (megamek.common.EquipmentType)4 LocationFullException (megamek.common.LocationFullException)4 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 IOException (java.io.IOException)3 AmmoType (megamek.common.AmmoType)3 Dimension (java.awt.Dimension)2 Transferable (java.awt.datatransfer.Transferable)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 InputEvent (java.awt.event.InputEvent)2