Search in sources :

Example 1 with CriticalSuit

use of megameklab.com.ui.BattleArmor.CriticalSuit 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 2 with CriticalSuit

use of megameklab.com.ui.BattleArmor.CriticalSuit in project megameklab by MegaMek.

the class BuildTab method autoFillCrits.

private void autoFillCrits() {
    // BattleArmor doesn't track crits implicitly, so they need to be
    // tracked explicitly
    CriticalSuit crits = new CriticalSuit(getBattleArmor());
    for (Mounted mount : buildView.getTableModel().getCrits()) {
        for (int location = BattleArmor.MOUNT_LOC_BODY; location < BattleArmor.MOUNT_NUM_LOCS; location++) {
            if (!UnitUtil.isValidLocation(getBattleArmor(), mount.getType(), location)) {
                continue;
            }
            // Don't assign change equipment that's already placed
            if (mount.getBaMountLoc() != BattleArmor.MOUNT_LOC_NONE) {
                continue;
            }
            if (crits.canAddMounted(location, mount)) {
                mount.setBaMountLoc(location);
                // Just added for record keeping
                crits.addMounted(location, mount);
                break;
            }
        }
    }
    refresh.refreshAll();
}
Also used : Mounted(megamek.common.Mounted) CriticalSuit(megameklab.com.ui.BattleArmor.CriticalSuit)

Aggregations

Mounted (megamek.common.Mounted)2 CriticalSuit (megameklab.com.ui.BattleArmor.CriticalSuit)2 Font (java.awt.Font)1 File (java.io.File)1 Vector (java.util.Vector)1 CriticalSlot (megamek.common.CriticalSlot)1 WeaponType (megamek.common.WeaponType)1 MtfFile (megamek.common.loaders.MtfFile)1 EntityVerifier (megamek.common.verifier.EntityVerifier)1 TestBattleArmor (megamek.common.verifier.TestBattleArmor)1 InfantryWeapon (megamek.common.weapons.infantry.InfantryWeapon)1