Search in sources :

Example 36 with Mounted

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

the class BuildView method loadEquipmentTable.

private void loadEquipmentTable() {
    equipmentList.removeAllCrits();
    masterEquipmentList.clear();
    for (Mounted mount : getBattleArmor().getMisc()) {
        if ((mount.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE && !mount.getType().hasFlag(MiscType.F_BA_MANIPULATOR) && !mount.getName().contains("BA Standard"))) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getBattleArmor().getWeaponList()) {
        // Don't display weapons mounted in a detachable weapon pack
        if (mount.isDWPMounted() || mount.isAPMMounted()) {
            continue;
        }
        if ((mount.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) && (UnitUtil.isBattleArmorWeapon(mount.getType(), getBattleArmor()) || UnitUtil.isBattleArmorAPWeapon(mount.getType()))) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getBattleArmor().getAmmo()) {
        // Ignore ammo for one-shot launchers
        if (mount.getLinkedBy() != null && mount.getLinkedBy().isOneShot()) {
            continue;
        }
        // Ignore DWP-mounted ammo
        if (mount.isDWPMounted()) {
            continue;
        }
        if (mount.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
            masterEquipmentList.add(mount);
        }
    }
    Collections.sort(masterEquipmentList, StringUtils.mountedComparator());
    // Jump Jets
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isJumpJet(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // weapons and ammo
    Vector<Mounted> weaponsNAmmoList = new Vector<Mounted>(10, 1);
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if ((masterEquipmentList.get(pos).getType() instanceof Weapon) || (masterEquipmentList.get(pos).getType() instanceof AmmoType)) {
            weaponsNAmmoList.add(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    Collections.sort(weaponsNAmmoList, StringUtils.mountedComparator());
    for (Mounted mount : weaponsNAmmoList) {
        equipmentList.addCrit(mount);
    }
    // Equipment
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if ((masterEquipmentList.get(pos).getType() instanceof MiscType) && !UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // armor
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isArmor(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // everything else
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        equipmentList.addCrit(masterEquipmentList.get(pos));
    }
}
Also used : AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) Vector(java.util.Vector) Weapon(megamek.common.weapons.Weapon) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon)

Example 37 with Mounted

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

the class BuildView method mountEquipmentInLocation.

/**
 * When the user right-clicks on the equipment table, a context menu is
 * generated that his menu items for each possible location that is clicked.
 * When the location is clicked, this is the method that adds the selected
 * equipment to the desired location.
 *
 * @param location
 * @param selectedRow
 */
private void mountEquipmentInLocation(int location, int selectedRow) {
    Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
    try {
        eq.setBaMountLoc(location);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    UnitUtil.changeMountStatus(getBattleArmor(), eq, BattleArmor.LOC_SQUAD, -1, false);
    // go back up to grandparent build tab and fire a full refresh.
    ((BuildTab) getParent().getParent()).refreshAll();
}
Also used : BuildTab(megameklab.com.ui.BattleArmor.tabs.BuildTab) Mounted(megamek.common.Mounted)

Example 38 with Mounted

use of megamek.common.Mounted 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 39 with Mounted

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

the class EquipmentView method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ADD_COMMAND)) {
        boolean success = false;
        Mounted mount = null;
        try {
            mount = getBattleArmor().addEquipment(equipmentTypes.elementAt(equipmentCombo.getSelectedIndex()), Entity.LOC_NONE, false);
            success = mount != null;
        } catch (LocationFullException lfe) {
        // this can't happen, we add to Entity.LOC_NONE
        }
        if (success) {
            equipmentList.addCrit(mount);
        }
    } else if (e.getActionCommand().equals(REMOVE_COMMAND)) {
        int startRow = equipmentTable.getSelectedRow();
        int count = equipmentTable.getSelectedRowCount();
        for (; count > 0; count--) {
            if (startRow > -1) {
                equipmentList.removeMounted(startRow);
                equipmentList.removeCrit(startRow);
            }
        }
    } else if (e.getActionCommand().equals(REMOVEALL_COMMAND)) {
        removeAllEquipment();
    } else {
        return;
    }
    fireTableRefresh();
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Example 40 with Mounted

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

the class StatusBar method calculateTotalHeat.

public double calculateTotalHeat() {
    double heat = 0;
    for (Mounted mounted : getSmallCraft().getWeaponList()) {
        WeaponType wtype = (WeaponType) mounted.getType();
        double weaponHeat = wtype.getHeat();
        // only count non-damaged equipment
        if (mounted.isMissing() || mounted.isHit() || mounted.isDestroyed() || mounted.isBreached()) {
            continue;
        }
        // one shot weapons count 1/4
        if ((wtype.getAmmoType() == AmmoType.T_ROCKET_LAUNCHER) || wtype.hasFlag(WeaponType.F_ONESHOT)) {
            weaponHeat *= 0.25;
        }
        // double heat for ultras
        if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) {
            weaponHeat *= 2;
        }
        // Six times heat for RAC
        if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) {
            weaponHeat *= 6;
        }
        // half heat for streaks
        if ((wtype.getAmmoType() == AmmoType.T_SRM_STREAK) || (wtype.getAmmoType() == AmmoType.T_MRM_STREAK) || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) {
            weaponHeat *= 0.5;
        }
        heat += weaponHeat;
    }
    return heat;
}
Also used : Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType)

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