Search in sources :

Example 21 with CriticalSlot

use of megamek.common.CriticalSlot 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 22 with CriticalSlot

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

the class CriticalView method refresh.

public void refresh() {
    critSuit = new CriticalSuit(getBattleArmor());
    leftPanel.removeAll();
    rightPanel.removeAll();
    bodyPanel.removeAll();
    turretPanel.removeAll();
    int[] numAPWeapons = new int[BattleArmor.MOUNT_NUM_LOCS];
    int[] numAMWeapons = new int[BattleArmor.MOUNT_NUM_LOCS];
    for (Mounted m : getBattleArmor().getEquipment()) {
        if (m.getLocation() == BattleArmor.LOC_SQUAD || m.getLocation() == trooper) {
            critSuit.addMounted(m.getBaMountLoc(), m);
            // Weapons mounted in a quad turret count against the body limits
            int useLoc = m.getBaMountLoc();
            if (useLoc == BattleArmor.MOUNT_LOC_TURRET) {
                useLoc = BattleArmor.MOUNT_LOC_BODY;
            }
            if (useLoc != BattleArmor.MOUNT_LOC_NONE) {
                if ((m.getType() instanceof WeaponType) && !(m.getType() instanceof InfantryWeapon)) {
                    numAMWeapons[useLoc]++;
                }
                if (m.getType().hasFlag(MiscType.F_AP_MOUNT)) {
                    numAPWeapons[useLoc]++;
                }
            }
        }
    }
    synchronized (getBattleArmor()) {
        for (int location = 0; location < critSuit.locations(); location++) {
            Vector<String> critNames = new Vector<String>(1, 1);
            for (int slot = 0; slot < critSuit.getNumCriticals(location); slot++) {
                CriticalSlot cs = critSuit.getCritical(location, slot);
                if (cs == null) {
                    if (showEmpty) {
                        critNames.add(MtfFile.EMPTY);
                    }
                    continue;
                } else if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
                    // BattleArmor shouldn't have system type crits
                    continue;
                } else if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
                    try {
                        Mounted m = cs.getMount();
                        // Critical didn't get removed. Remove it now.
                        if (m == null) {
                            if (showEmpty) {
                                critNames.add(MtfFile.EMPTY);
                            }
                            continue;
                        }
                        StringBuffer critName = new StringBuffer(m.getName());
                        critName.append(":" + slot + ":" + getBattleArmor().getEquipmentNum(m));
                        critNames.add(critName.toString());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            DropTargetCriticalList<String> criticalSlotList = null;
            criticalSlotList = new DropTargetCriticalList<String>(critNames, eSource, refresh, showEmpty);
            criticalSlotList.setAlignmentX(JLabel.CENTER_ALIGNMENT);
            criticalSlotList.setVisibleRowCount(critNames.size());
            criticalSlotList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            criticalSlotList.setFont(new Font("Arial", Font.PLAIN, 10));
            criticalSlotList.setName(location + ":" + trooper);
            criticalSlotList.setBorder(BorderFactory.createEtchedBorder(Color.WHITE.brighter(), Color.BLACK.darker()));
            switch(location) {
                case BattleArmor.MOUNT_LOC_LARM:
                    leftPanel.add(criticalSlotList);
                    break;
                case BattleArmor.MOUNT_LOC_RARM:
                    rightPanel.add(criticalSlotList);
                    break;
                case BattleArmor.MOUNT_LOC_BODY:
                    bodyPanel.add(criticalSlotList);
                    break;
                case BattleArmor.MOUNT_LOC_TURRET:
                    turretPanel.add(criticalSlotList);
                    break;
            }
        }
        String[] amTxt = new String[BattleArmor.MOUNT_NUM_LOCS];
        String[] apTxt = new String[BattleArmor.MOUNT_NUM_LOCS];
        for (int loc = 0; loc < BattleArmor.MOUNT_NUM_LOCS; loc++) {
            amTxt[loc] = "AM Wpn: " + numAMWeapons[loc] + "/" + getBattleArmor().getNumAllowedAntiMechWeapons(loc);
            apTxt[loc] = "AP Wpn: " + numAPWeapons[loc] + "/" + getBattleArmor().getNumAllowedAntiPersonnelWeapons(loc, trooper);
            if (numAMWeapons[loc] > getBattleArmor().getNumAllowedAntiMechWeapons(loc)) {
                amTxt[loc] = "<html><font color='C00000'>" + amTxt[loc] + "</font></html>";
            }
            if (numAPWeapons[loc] > getBattleArmor().getNumAllowedAntiMechWeapons(loc)) {
                apTxt[loc] = "<html><font color='C00000'>" + apTxt[loc] + "</font></html>";
            }
        }
        leftPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_LARM], lblSz));
        leftPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_LARM], lblSz));
        rightPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_RARM], lblSz));
        rightPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_RARM], lblSz));
        bodyPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_BODY], lblSz));
        bodyPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_BODY], lblSz));
        // Hide the arm panels if we are a quad
        if (getBattleArmor().getChassisType() == BattleArmor.CHASSIS_TYPE_QUAD) {
            leftPanel.setVisible(false);
            rightPanel.setVisible(false);
            turretPanel.setVisible(getBattleArmor().getTurretCapacity() > 0);
        } else {
            leftPanel.setVisible(true);
            rightPanel.setVisible(true);
            turretPanel.setVisible(false);
        }
        EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
        TestBattleArmor testBA = new TestBattleArmor(getBattleArmor(), entityVerifier.baOption, null);
        String weightTxt = "Weight: " + String.format("%1$.3f", testBA.calculateWeight(trooper)) + "/" + getBattleArmor().getTrooperWeight();
        if (testBA.calculateWeight(trooper) > getBattleArmor().getTrooperWeight()) {
            weightTxt = "<html><font color='C00000'>" + weightTxt + "</font></html>";
        }
        weightLabel.setText(weightTxt);
        leftPanel.add(Box.createVerticalStrut(8));
        rightPanel.add(Box.createVerticalStrut(8));
        bodyPanel.add(Box.createVerticalStrut(8));
        turretPanel.add(Box.createVerticalStrut(8));
        leftPanel.invalidate();
        leftPanel.invalidate();
        rightPanel.invalidate();
        turretPanel.invalidate();
        bodyPanel.repaint();
        leftPanel.repaint();
        rightPanel.repaint();
        turretPanel.repaint();
    }
}
Also used : EntityVerifier(megamek.common.verifier.EntityVerifier) CriticalSlot(megamek.common.CriticalSlot) TestBattleArmor(megamek.common.verifier.TestBattleArmor) Font(java.awt.Font) Mounted(megamek.common.Mounted) CriticalSuit(megameklab.com.ui.BattleArmor.CriticalSuit) WeaponType(megamek.common.WeaponType) Vector(java.util.Vector) MtfFile(megamek.common.loaders.MtfFile) File(java.io.File) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon)

Example 23 with CriticalSlot

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

the class StructureTab method resetSystemCrits.

private void resetSystemCrits() {
    getMech().clearCockpitCrits();
    getMech().clearGyroCrits();
    getMech().clearEngineCrits();
    removeSystemCrits(LandAirMech.LAM_LANDING_GEAR, Mech.LOC_CT);
    int[] ctEngine = getMech().getEngine().getCenterTorsoCriticalSlots(getMech().getGyroType());
    int lastEngine = ctEngine[ctEngine.length - 1];
    for (int slot = 0; slot <= lastEngine; slot++) {
        clearCrit(Mech.LOC_CT, slot);
    }
    for (int slot : getMech().getEngine().getSideTorsoCriticalSlots()) {
        clearCrit(Mech.LOC_RT, slot);
        clearCrit(Mech.LOC_LT, slot);
    }
    getMech().addEngineCrits();
    switch(getMech().getGyroType()) {
        case Mech.GYRO_COMPACT:
            clearCritsForGyro(2);
            getMech().addCompactGyro();
            break;
        case Mech.GYRO_HEAVY_DUTY:
            clearCritsForGyro(4);
            getMech().addHeavyDutyGyro();
            break;
        case Mech.GYRO_XL:
            clearCritsForGyro(6);
            getMech().addXLGyro();
            break;
        case Mech.GYRO_NONE:
            UnitUtil.compactCriticals(getMech(), Mech.LOC_CT);
            break;
        default:
            clearCritsForGyro(4);
            getMech().addGyro();
    }
    switch(getMech().getCockpitType()) {
        case Mech.COCKPIT_COMMAND_CONSOLE:
            clearCritsForCockpit(false, true);
            getMech().addCommandConsole();
            break;
        case Mech.COCKPIT_DUAL:
            clearCritsForCockpit(false, true);
            getMech().addDualCockpit();
            break;
        case Mech.COCKPIT_SMALL:
            clearCritsForCockpit(true, false);
            getMech().addSmallCockpit();
            break;
        case Mech.COCKPIT_INTERFACE:
            clearCritsForCockpit(false, true);
            getMech().addInterfaceCockpit();
            break;
        case Mech.COCKPIT_TORSO_MOUNTED:
        case Mech.COCKPIT_VRRP:
            if (lastEngine + 2 < getMech().getNumberOfCriticals(Mech.LOC_CT)) {
                clearCrit(Mech.LOC_CT, lastEngine + 1);
                clearCrit(Mech.LOC_CT, lastEngine + 2);
            }
            clearCrit(Mech.LOC_HEAD, 0);
            clearCrit(Mech.LOC_HEAD, 1);
            if (getMech().getEmptyCriticals(Mech.LOC_LT) < 1) {
                for (int i = 0; i < getMech().getNumberOfCriticals(Mech.LOC_LT); i++) {
                    if (getMech().getCritical(Mech.LOC_LT, i) != null && getMech().getCritical(Mech.LOC_LT, i).getType() == CriticalSlot.TYPE_EQUIPMENT) {
                        clearCrit(Mech.LOC_LT, i);
                        break;
                    }
                }
            }
            if (getMech().getEmptyCriticals(Mech.LOC_RT) < 1) {
                for (int i = 0; i < getMech().getNumberOfCriticals(Mech.LOC_RT); i++) {
                    if (getMech().getCritical(Mech.LOC_RT, i) != null && getMech().getCritical(Mech.LOC_RT, i).getType() == CriticalSlot.TYPE_EQUIPMENT) {
                        clearCrit(Mech.LOC_RT, i);
                        break;
                    }
                }
            }
            getMech().addTorsoMountedCockpit(getMech().getCockpitType() == Mech.COCKPIT_VRRP);
            break;
        case Mech.COCKPIT_INDUSTRIAL:
            clearCritsForCockpit(false, false);
            getMech().addIndustrialCockpit();
            getMech().setArmorType(EquipmentType.T_ARMOR_INDUSTRIAL);
            break;
        case Mech.COCKPIT_PRIMITIVE:
            clearCritsForCockpit(false, false);
            getMech().addPrimitiveCockpit();
            getMech().setArmorType(EquipmentType.T_ARMOR_PRIMITIVE);
            break;
        case Mech.COCKPIT_PRIMITIVE_INDUSTRIAL:
            clearCritsForCockpit(false, false);
            getMech().addIndustrialPrimitiveCockpit();
            getMech().setArmorType(EquipmentType.T_ARMOR_COMMERCIAL);
            break;
        default:
            clearCritsForCockpit(false, false);
            getMech().addCockpit();
    }
    // For LAMs we want to put the landing gear in the first available slot after the engine and gyro.
    if (getMech().hasETypeFlag(Entity.ETYPE_LAND_AIR_MECH)) {
        int lgSlot = 10;
        for (int i = 0; i < getMech().getNumberOfCriticals(Mech.LOC_CT); i++) {
            final CriticalSlot slot = getMech().getCritical(Mech.LOC_CT, i);
            if ((null == slot) || (slot.getType() == CriticalSlot.TYPE_EQUIPMENT) || ((slot.getIndex() != Mech.SYSTEM_ENGINE) && (slot.getIndex() != Mech.SYSTEM_GYRO))) {
                lgSlot = i;
                break;
            }
        }
        CriticalSlot crit = new CriticalSlot(CriticalSlot.TYPE_SYSTEM, LandAirMech.LAM_LANDING_GEAR);
        getMech().removeCriticals(Mech.LOC_CT, crit);
        clearCrit(Mech.LOC_CT, lgSlot);
        getMech().setCritical(Mech.LOC_CT, lgSlot, crit);
    }
    refresh.refreshBuild();
}
Also used : CriticalSlot(megamek.common.CriticalSlot)

Example 24 with CriticalSlot

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

the class StructureTab method clearCrit.

/**
 * Removes equipment placed in the given critical slot to clear the space for a system critical
 */
private void clearCrit(int loc, int slotNum) {
    final CriticalSlot crit = getMech().getCritical(loc, slotNum);
    Mounted mounted = null;
    if (crit != null && crit.getType() == CriticalSlot.TYPE_EQUIPMENT) {
        mounted = crit.getMount();
    }
    if (mounted == null) {
        return;
    }
    UnitUtil.removeCriticals(getMech(), mounted);
    if (crit.getMount2() != null) {
        UnitUtil.removeCriticals(getMech(), crit.getMount2());
    }
    // Check linkings after you remove everything.
    try {
        MechFileParser.postLoadInit(getMech());
    } catch (EntityLoadingException ele) {
    // do nothing.
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
        UnitUtil.changeMountStatus(getMech(), mounted, Entity.LOC_NONE, Entity.LOC_NONE, false);
        if (crit.getMount2() != null) {
            UnitUtil.changeMountStatus(getMech(), crit.getMount2(), Entity.LOC_NONE, Entity.LOC_NONE, false);
        }
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) LocationFullException(megamek.common.LocationFullException) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Example 25 with CriticalSlot

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

the class CriticalSuit method addMounted.

public void addMounted(int loc, Mounted m) {
    // Don't mount unmounted equipment
    if (loc == BattleArmor.MOUNT_LOC_NONE) {
        return;
    }
    // AP Weapons that are mounted in an AP Mount don't take up slots
    if (m.isAPMMounted() && m.getLinkedBy() != null && m.getLinkedBy().getType().hasFlag(MiscType.F_AP_MOUNT)) {
        return;
    }
    // as they get a special slot added for them
    if (m.getType().hasFlag(MiscType.F_BA_MANIPULATOR)) {
        int slot = crits[loc].length - 1;
        crits[loc][slot] = new CriticalSlot(m);
    }
    int critsToAdd;
    if (m.getType().isSpreadable()) {
        critsToAdd = 1;
    } else {
        critsToAdd = m.getType().getCriticals(ba);
    }
    if (critsToAdd == 0) {
        return;
    }
    for (int slot = 0; slot < getNumCriticals(loc); slot++) {
        if (crits[loc][slot] == null) {
            crits[loc][slot] = new CriticalSlot(m);
            critsToAdd--;
            if (critsToAdd <= 0) {
                break;
            }
        }
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot)

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