Search in sources :

Example 26 with AmmoType

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

the class ImageHelper method printVehicleAmmo.

public static void printVehicleAmmo(Entity vehicle, Graphics2D g2d, float yoffset, float xoffset) {
    float pointY = 341 + yoffset;
    float pointX = 22 + xoffset;
    HashMap<String, Integer> ammoHash = new HashMap<String, Integer>();
    g2d.setFont(UnitUtil.deriveFont(7.0f));
    for (Mounted ammo : vehicle.getAmmo()) {
        // don't print one shot ammo
        if (ammo.getLocation() == Entity.LOC_NONE) {
            continue;
        }
        AmmoType aType = (AmmoType) ammo.getType();
        String shortName = aType.getShortName().replace("Ammo", "");
        shortName = shortName.replace('(', '.').replace(')', '.').replace(".Clan.", "");
        shortName = shortName.replace("-capable", "");
        shortName += " ";
        if ((aType.getAmmoType() == AmmoType.T_AC) || (aType.getAmmoType() == AmmoType.T_MML) || (aType.getAmmoType() == AmmoType.T_SRM) || (aType.getAmmoType() == AmmoType.T_SRM_STREAK) || (aType.getAmmoType() == AmmoType.T_SRM_TORPEDO) || (aType.getAmmoType() == AmmoType.T_LRM) || (aType.getAmmoType() == AmmoType.T_LRM_STREAK) || (aType.getAmmoType() == AmmoType.T_LRM_TORPEDO) || (aType.getAmmoType() == AmmoType.T_MML) || (aType.getAmmoType() == AmmoType.T_AC) || (aType.getAmmoType() == AmmoType.T_AC_LBX) || (aType.getAmmoType() == AmmoType.T_AC_LBX_THB) || (aType.getAmmoType() == AmmoType.T_AC_ROTARY) || (aType.getAmmoType() == AmmoType.T_AC_ULTRA) || (aType.getAmmoType() == AmmoType.T_AC_ULTRA_THB) || (aType.getAmmoType() == AmmoType.T_MRM) || (aType.getAmmoType() == AmmoType.T_MRM_STREAK) || (aType.getAmmoType() == AmmoType.T_ATM) || (aType.getAmmoType() == AmmoType.T_HAG) || (aType.getAmmoType() == AmmoType.T_EXLRM)) {
            // shortName = shortName.replaceFirst(" ", " " +
            // aType.getRackSize() + " ");
            shortName = shortName.replaceFirst("  Artemis", " Artemis");
        }
        shortName = shortName.trim();
        if (ammoHash.containsKey(shortName)) {
            int currentAmmo = ammoHash.get(shortName);
            currentAmmo += ammo.getUsableShotsLeft();
            ammoHash.put(shortName, currentAmmo);
        } else {
            int currentAmmo = ammo.getUsableShotsLeft();
            ammoHash.put(shortName, currentAmmo);
        }
    }
    for (Mounted misc : vehicle.getMisc()) {
        if (misc.getType().hasFlag(MiscType.F_SENSOR_DISPENSER)) {
            if (ammoHash.get("Remote Sensors") == null) {
                ammoHash.put("Remote Sensors", misc.getUsableShotsLeft());
            } else {
                ammoHash.put("Remote Sensors", misc.getUsableShotsLeft() + ammoHash.get("Remote Sensors"));
            }
        }
    }
    if (ammoHash.keySet().size() == 0) {
        return;
    }
    StringBuffer sb = new StringBuffer("Ammo: ");
    int linecount = 0;
    for (String ammo : ammoHash.keySet()) {
        sb.append("(");
        sb.append(ammo);
        sb.append(") ");
        sb.append(ammoHash.get(ammo));
        sb.append(", ");
    }
    double stringLength = ImageHelper.getStringWidth(g2d, sb.toString(), g2d.getFont());
    linecount = (int) Math.floor(stringLength / 160);
    sb.setLength(0);
    sb.append("Ammo: ");
    if (vehicle.hasWorkingMisc(MiscType.F_CASE, -1) || vehicle.isClan()) {
        sb = new StringBuffer("Ammo (CASE): ");
    }
    g2d.drawString(sb.toString(), pointX, pointY - ((linecount) * ImageHelper.getStringHeight(g2d, sb.toString(), g2d.getFont())));
    pointX += ImageHelper.getStringWidth(g2d, sb.toString(), g2d.getFont());
    sb = new StringBuffer();
    int linesprinted = 0;
    int currentStringLength = 0;
    for (String ammo : ammoHash.keySet()) {
        currentStringLength = sb.length();
        sb.append("(");
        sb.append(ammo);
        sb.append(") ");
        sb.append(ammoHash.get(ammo));
        sb.append(", ");
        if ((ImageHelper.getStringWidth(g2d, sb.toString(), g2d.getFont()) > 160) && (linesprinted < linecount)) {
            sb.setLength(sb.length() - ((sb.length() - currentStringLength) + 2));
            g2d.drawString(sb.toString(), pointX, pointY - ((linecount - linesprinted) * ImageHelper.getStringHeight(g2d, sb.toString(), g2d.getFont())));
            linesprinted++;
            sb.setLength(0);
            sb.append("(");
            sb.append(ammo);
            sb.append(") ");
            sb.append(ammoHash.get(ammo));
            sb.append(", ");
        }
    }
    if (sb.length() > 0) {
        sb.setLength(sb.length() - 2);
        g2d.drawString(sb.toString(), pointX, pointY - ((linecount - linesprinted) * ImageHelper.getStringHeight(g2d, sb.toString(), g2d.getFont())));
        pointY += ImageHelper.getStringHeight(g2d, sb.toString(), g2d.getFont());
    }
}
Also used : AmmoType(megamek.common.AmmoType) HashMap(java.util.HashMap) Mounted(megamek.common.Mounted)

Example 27 with AmmoType

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

the class ImageHelperAero method printAeroWeaponsNEquipment.

public static void printAeroWeaponsNEquipment(Aero aero, Graphics2D g2d) {
    int pointShift = 0;
    if ((aero instanceof SmallCraft) && aero.isSpheroid()) {
        pointShift = 11;
    }
    int qtyPoint = 30;
    int typePoint = 42;
    int locPoint = 112 + pointShift;
    int heatPoint = 130 + pointShift;
    int shtPoint = 147 + pointShift;
    int medPoint = 170 + pointShift;
    int longPoint = 190 + pointShift;
    int erPoint = 210 + pointShift;
    float linePoint = 204f;
    float maxHeight = 97.0f;
    float lineFeed = 6.7f;
    boolean newLineNeeded = false;
    ArrayList<Hashtable<String, EquipmentInfo>> equipmentLocations = new ArrayList<Hashtable<String, EquipmentInfo>>(aero.locations());
    for (int pos = 0; pos <= aero.locations(); pos++) {
        equipmentLocations.add(pos, new Hashtable<String, EquipmentInfo>());
    }
    for (Mounted eq : aero.getEquipment()) {
        if ((eq.isWeaponGroup() || (eq.getType() instanceof AmmoType)) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(eq.getType())) {
            continue;
        }
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(eq.getLocation());
        String equipmentName = eq.getName();
        if (eq.isRearMounted()) {
            equipmentName += "(R)";
        }
        if (eqHash.containsKey(equipmentName)) {
            EquipmentInfo eqi = eqHash.get(equipmentName);
            if (eq.getType().getTechLevel(aero.getTechLevelYear()) != eqi.techLevel) {
                eqi = new EquipmentInfo(aero, eq);
            } else {
                eqi.count++;
            }
            eqHash.put(equipmentName, eqi);
        } else {
            EquipmentInfo eqi = new EquipmentInfo(aero, eq);
            eqHash.put(equipmentName, eqi);
        }
    }
    if (aero.getTroopCarryingSpace() > 0) {
        maxHeight -= lineFeed;
    }
    if (aero.hasWorkingMisc(MiscType.F_CHASSIS_MODIFICATION)) {
        maxHeight -= lineFeed;
    }
    if (aero.getCockpitType() != Aero.COCKPIT_STANDARD) {
        maxHeight -= lineFeed;
    }
    for (@SuppressWarnings("unused") Bay bay : aero.getTransportBays()) {
        maxHeight -= lineFeed;
    }
    if (aero.getAmmo().size() > 0) {
        maxHeight -= lineFeed;
    }
    g2d.setFont(UnitUtil.deriveFont(false, 7.0f));
    Font font = ImageHelperAero.getAeroWeaponsNEquipmentFont(g2d, false, maxHeight, equipmentLocations, 7.0f);
    g2d.setFont(font);
    float stringHeight = ImageHelper.getStringHeight(g2d, "H", font);
    lineFeed = stringHeight;
    for (int pos = Aero.LOC_NOSE; pos <= aero.locations(); pos++) {
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(pos);
        if (eqHash.size() < 1) {
            continue;
        }
        ArrayList<EquipmentInfo> equipmentList = new ArrayList<EquipmentInfo>();
        for (EquipmentInfo eqi : eqHash.values()) {
            equipmentList.add(eqi);
        }
        Collections.sort(equipmentList, StringUtils.equipmentInfoComparator());
        for (EquipmentInfo eqi : equipmentList) {
            newLineNeeded = false;
            g2d.setFont(font);
            g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
            String name = eqi.name.trim() + " " + eqi.damage.trim();
            if (eqi.c3Level == EquipmentInfo.C3I) {
                ImageHelper.printC3iName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3EM) {
                ImageHelper.printC3EmName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3S) {
                ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3M) {
                ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3SB) {
                ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3MB) {
                ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
                ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.isMashCore) {
                ImageHelper.printMashCore(g2d, typePoint, linePoint, font, false, aero);
            } else if (eqi.isDroneControl) {
                ImageHelper.printDroneControl(g2d, typePoint, linePoint, font, false, aero);
            } else {
                if (ImageHelper.getStringWidth(g2d, name, font) > 65) {
                    // g2d.setFont(UnitUtil.getNewFont(g2d, eqi.name.trim(),
                    // false, 65, font.getSize2D()));
                    g2d.drawString(eqi.name.trim(), typePoint, linePoint);
                    linePoint += lineFeed;
                    g2d.drawString(eqi.damage.trim(), typePoint, linePoint);
                } else {
                    g2d.drawString(name, typePoint, linePoint);
                }
            }
            g2d.setFont(font);
            String location = ImageHelperAero.getLocationAbbrs(pos);
            if ((aero instanceof SmallCraft) && (aero.getMovementMode() == EntityMovementMode.SPHEROID)) {
                location = ImageHelperAero.getLocationAbbrsSmallCraft(pos);
            }
            g2d.drawString(location, locPoint, linePoint);
            ImageHelper.printCenterString(g2d, Integer.toString(eqi.heat), font, heatPoint, linePoint);
            if (eqi.isMML) {
                linePoint += lineFeed;
                g2d.drawString("SRM Ammo", typePoint, linePoint);
                g2d.drawString(Integer.toString(eqi.shtRange * 2), shtPoint, (int) linePoint);
                g2d.drawString("\u2014", medPoint, linePoint);
                g2d.drawString("\u2014", longPoint, linePoint);
                g2d.drawString("\u2014", erPoint, linePoint);
                // g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
                // g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
                // g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 6, (int) linePoint - 2);
                linePoint += lineFeed;
                g2d.drawString("LRM Ammo", typePoint, linePoint);
                g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, (int) linePoint);
                g2d.drawString(Integer.toString(eqi.medRange), medPoint, (int) linePoint);
                g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
                g2d.drawString("\u2014", erPoint, linePoint);
            // g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 6, (int) linePoint - 2);
            } else if (eqi.shtRange > 0) {
                g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, (int) linePoint);
            } else {
                g2d.drawString("\u2014", shtPoint, linePoint);
            // g2d.drawLine(shtPoint, (int) linePoint - 2, shtPoint + 6, (int) linePoint - 2);
            }
            if ((eqi.medRange > 0) && !eqi.isMML) {
                g2d.drawString(Integer.toString(eqi.medRange), medPoint, (int) linePoint);
            } else if (!eqi.isMML) {
                g2d.drawString("\u2014", medPoint, linePoint);
            // g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
            }
            if ((eqi.longRange > 0) && !eqi.isMML) {
                g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
            } else if (!eqi.isMML) {
                g2d.drawString("\u2014", longPoint, linePoint);
            // g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
            }
            if ((eqi.erRange > 0) && !eqi.isMML) {
                g2d.drawString(Integer.toString(eqi.erRange), erPoint, (int) linePoint);
            } else if (!eqi.isMML) {
                g2d.drawString("\u2014", erPoint, linePoint);
            // g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 6, (int) linePoint - 2);
            }
            if (eqi.hasArtemis) {
                g2d.drawString("w/Artemis IV FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            } else if (eqi.hasArtemisV) {
                g2d.drawString("w/Artemis V FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            } else if (eqi.hasApollo) {
                g2d.drawString("w/Apollo FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            }
            linePoint += lineFeed;
            if (newLineNeeded) {
                linePoint += lineFeed;
            }
        }
    }
    if (aero.getCockpitType() != Aero.COCKPIT_STANDARD) {
        g2d.drawString(aero.getCockpitTypeString(), 22, linePoint);
        linePoint += lineFeed;
    }
    if (aero instanceof FixedWingSupport) {
        ImageHelperAero.printFixedWingSupportCargoChassisMod((FixedWingSupport) aero, g2d, (int) linePoint);
    } else {
        ImageHelperAero.printCargo(aero, g2d, (int) linePoint);
    }
    ImageHelper.printVehicleAmmo(aero, g2d, -20, 8);
    ImageHelperAero.printAeroFuel(aero, g2d, 8);
}
Also used : FixedWingSupport(megamek.common.FixedWingSupport) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Font(java.awt.Font) SmallCraft(megamek.common.SmallCraft) AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) Bay(megamek.common.Bay)

Example 28 with AmmoType

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

the class BuildView method loadEquipmentTable.

private void loadEquipmentTable() {
    equipmentList.removeAllCrits();
    masterEquipmentList.clear();
    engineHeatSinkCount = UnitUtil.getCriticalFreeHeatSinks(getMech(), getMech().hasCompactHeatSinks());
    for (Mounted mount : getMech().getMisc()) {
        if ((mount.getLocation() == Entity.LOC_NONE) && !isEngineHeatSink(mount) && !(mount.getType().getCriticals(getMech()) == 0)) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getMech().getWeaponList()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getMech().getAmmo()) {
        if ((mount.getLocation() == Entity.LOC_NONE) && ((mount.getUsableShotsLeft() > 1) || (((AmmoType) mount.getType()).getAmmoType() == AmmoType.T_COOLANT_POD))) {
            masterEquipmentList.add(mount);
        }
    }
    Collections.sort(masterEquipmentList, StringUtils.mountedComparator());
    // HeatSinks first
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isHeatSink(masterEquipmentList.get(pos))) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // 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.isArmor(masterEquipmentList.get(pos).getType()) && !UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // structure
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isStructure(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 that is not TSM
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (!UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // TSM
    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)

Example 29 with AmmoType

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

the class BuildView method mousePressed.

public void mousePressed(MouseEvent e) {
    // locations, but only if those locations are make sense
    if (e.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem item;
        final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
        final Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
        final String[] locNames = BattleArmor.MOUNT_LOC_NAMES;
        // A list of the valid locations we can add the selected eq to
        ArrayList<Integer> validLocs = new ArrayList<Integer>();
        int numLocs = BattleArmor.MOUNT_NUM_LOCS;
        for (int loc = 0; loc < numLocs; loc++) {
            if (TestBattleArmor.isMountLegal(getBattleArmor(), eq, loc)) {
                validLocs.add(loc);
            }
        }
        if (eq.getLocation() == BattleArmor.LOC_SQUAD && !(eq.getType() instanceof InfantryWeapon)) {
            // Add a menu item for each potential location
            for (Integer location : validLocs) {
                if (UnitUtil.isValidLocation(getBattleArmor(), eq.getType(), location)) {
                    item = new JMenuItem("Add to " + locNames[location]);
                    final int loc = location;
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            mountEquipmentInLocation(loc, selectedRow);
                        }
                    });
                    popup.add(item);
                }
            }
            if (!UnitUtil.isArmor(eq.getType()) && !eq.isSquadSupportWeapon()) {
                item = new JMenuItem("Make individual weapon");
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setLocation(BattleArmor.LOC_TROOPER_1);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        } else {
            if (!UnitUtil.isArmor(eq.getType()) && !(eq.getType() instanceof InfantryWeapon) && !((eq.getType() instanceof WeaponType) && (eq.getType().hasFlag(WeaponType.F_TASER) || ((WeaponType) eq.getType()).getAmmoType() == AmmoType.T_NARC))) {
                item = new JMenuItem("Make squad weapon");
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setLocation(BattleArmor.LOC_SQUAD);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Allow number of shots selection
        if ((getBattleArmor() instanceof BattleArmor) && eq.getType() instanceof AmmoType) {
            AmmoType at = (AmmoType) eq.getType();
            int maxNumShots = 4;
            int stepSize = 1;
            if (at.getAmmoType() == AmmoType.T_BA_TUBE) {
                maxNumShots = 8;
                stepSize = 2;
            }
            for (int i = at.getShots(); i <= maxNumShots; i += stepSize) {
                if (i == eq.getBaseShotsLeft()) {
                    continue;
                }
                item = new JMenuItem("Set Shots: " + i);
                final int shots = i;
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setShotsLeft(shots);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Allow making this a squad support weapon
        if ((eq.getType() instanceof WeaponType) && !eq.isSquadSupportWeapon() && !eq.getType().hasFlag(WeaponType.F_INFANTRY) && eq.getLocation() == BattleArmor.LOC_SQUAD && getBattleArmor().getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
            item = new JMenuItem("Mount as squad support weapon");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    eq.setSquadSupportWeapon(true);
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        // Adding ammo as a squad support mount is slightly different
        if ((eq.getType() instanceof AmmoType) && !eq.getType().hasFlag(WeaponType.F_MISSILE) && !eq.isSquadSupportWeapon() && eq.getLocation() == BattleArmor.LOC_SQUAD && getBattleArmor().getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
            boolean enabled = false;
            for (Mounted weapon : getBattleArmor().getWeaponList()) {
                WeaponType wtype = (WeaponType) weapon.getType();
                if (weapon.isSquadSupportWeapon() && AmmoType.isAmmoValid(eq, wtype)) {
                    enabled = true;
                }
            }
            item = new JMenuItem("Mount as squad support weapon");
            item.setEnabled(enabled);
            item.setToolTipText("Ammo can only be squad mounted along " + "with a weapon that uses it");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    eq.setSquadSupportWeapon(true);
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        // Allow removing squad support weapon
        if (eq.isSquadSupportWeapon()) {
            item = new JMenuItem("Remove squad support weapon mount");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    eq.setSquadSupportWeapon(false);
                    // squad support weapon
                    for (Mounted ammo : getBattleArmor().getAmmo()) {
                        ammo.setSquadSupportWeapon(false);
                    }
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        // See if we should allow linking this to a DWP
        if (getBattleArmor().hasWorkingMisc(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.getType().hasFlag(WeaponType.F_MISSILE) && !(eq.getType() instanceof AmmoType) && !eq.isDWPMounted() && (getBattleArmor()).canMountDWP()) {
            for (Mounted m : getBattleArmor().getMisc()) {
                // If this isn't a DWP or it's a full DWP, skip
                if (!m.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) || m.getLinked() != null) {
                    continue;
                }
                String locName;
                if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
                    locName = "None";
                } else {
                    locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
                }
                item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
                final Mounted dwp = m;
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setLinked(dwp);
                        dwp.setLinked(eq);
                        eq.setDWPMounted(true);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Should we allow mounting Ammo in a DWP?
        if ((eq.getType() instanceof AmmoType) && getBattleArmor().hasWorkingMisc(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.isDWPMounted() && (getBattleArmor()).canMountDWP()) {
            for (final Mounted m : getBattleArmor().getMisc()) {
                // If this isn't a DWP, skip
                if (!m.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK)) {
                    continue;
                }
                // We only want to enable the menu item if the DWP has a
                // mounted weapon and we clicked on a valid ammo type
                boolean enabled = false;
                if (m.getLinked() != null) {
                    EquipmentType etype = m.getLinked().getType();
                    if (etype instanceof WeaponType) {
                        WeaponType wtype = (WeaponType) etype;
                        if (AmmoType.isAmmoValid(eq, wtype)) {
                            enabled = true;
                        }
                    }
                }
                String locName;
                if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
                    locName = "None";
                } else {
                    locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
                }
                item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
                item.setToolTipText("Ammo can only be mounted in a DWP " + "with a valid weapon.");
                item.setEnabled(enabled);
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        m.getLinked().setLinked(eq);
                        eq.setDWPMounted(true);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Right-clicked on a DWP that has an attached weapon
        if (eq.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && eq.getLinked() != null) {
            item = new JMenuItem("Remove attached weapon");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    Mounted attached = eq.getLinked();
                    attached.setDWPMounted(false);
                    eq.setLinked(null);
                    eq.setLinkedBy(null);
                    attached.setLinked(null);
                    attached.setLinkedBy(null);
                    // Remove any attached ammo
                    for (Mounted ammo : getBattleArmor().getAmmo()) {
                        if (attached.equals(ammo.getLinkedBy())) {
                            ammo.setDWPMounted(false);
                            ammo.setLinked(null);
                            ammo.setLinkedBy(null);
                        }
                    }
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        // See if we should allow linking this to an AP Mount
        if (getBattleArmor().hasWorkingMisc(MiscType.F_AP_MOUNT) && eq.getType().hasFlag(WeaponType.F_INFANTRY) && !eq.isAPMMounted()) {
            for (Mounted m : getBattleArmor().getMisc()) {
                // If this isn't an AP Mount or it's a full AP Mount, skip
                if (!m.getType().hasFlag(MiscType.F_AP_MOUNT) || m.getLinked() != null) {
                    continue;
                }
                // regardless of the number of gloves
                if (m.getType().hasFlag(MiscType.F_ARMORED_GLOVE)) {
                    boolean hasUsedGlove = false;
                    for (Mounted m2 : getBattleArmor().getMisc()) {
                        if (m2.getType().hasFlag(MiscType.F_ARMORED_GLOVE) && (m2.getLinked() != null)) {
                            hasUsedGlove = true;
                        }
                    }
                    if (hasUsedGlove) {
                        continue;
                    }
                }
                // Only armored gloves can carry infantry support weapons
                if (!m.getType().hasFlag(MiscType.F_ARMORED_GLOVE) && eq.getType().hasFlag(WeaponType.F_INF_SUPPORT)) {
                    continue;
                }
                String locName;
                if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
                    locName = "None";
                } else {
                    locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
                }
                item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
                final Mounted apm = m;
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setLinked(apm);
                        apm.setLinked(eq);
                        eq.setAPMMounted(true);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Right-clicked on a AP Mount that has an attached weapon
        if (eq.getType().hasFlag(MiscType.F_AP_MOUNT) && eq.getLinked() != null) {
            item = new JMenuItem("Remove attached weapon");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    Mounted attached = eq.getLinked();
                    attached.setAPMMounted(false);
                    eq.setLinked(null);
                    eq.setLinkedBy(null);
                    attached.setLinked(null);
                    attached.setLinkedBy(null);
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        popup.show(this, e.getX(), e.getY());
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) EquipmentType(megamek.common.EquipmentType) JPopupMenu(javax.swing.JPopupMenu) AmmoType(megamek.common.AmmoType) ActionListener(java.awt.event.ActionListener) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) JMenuItem(javax.swing.JMenuItem) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Example 30 with AmmoType

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

the class BuildView method loadEquipmentTable.

private void loadEquipmentTable() {
    equipmentList.removeAllCrits();
    masterEquipmentList.clear();
    for (Mounted mount : getTank().getMisc()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getTank().getWeaponList()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getTank().getAmmo()) {
        int ammoType = ((AmmoType) mount.getType()).getAmmoType();
        if ((mount.getLocation() == Entity.LOC_NONE) && (mount.getUsableShotsLeft() > 1 || ammoType == AmmoType.T_CRUISE_MISSILE)) {
            masterEquipmentList.add(mount);
        }
    }
    Collections.sort(masterEquipmentList, StringUtils.mountedComparator());
    // HeatSinks first
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isHeatSink(masterEquipmentList.get(pos))) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // 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.isArmor(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // structure
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if ((masterEquipmentList.get(pos).getType() instanceof MiscType) && masterEquipmentList.get(pos).getType().hasFlag(MiscType.F_ENDO_STEEL)) {
            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)

Aggregations

AmmoType (megamek.common.AmmoType)34 Mounted (megamek.common.Mounted)32 ArrayList (java.util.ArrayList)15 MiscType (megamek.common.MiscType)15 WeaponType (megamek.common.WeaponType)15 Vector (java.util.Vector)13 Font (java.awt.Font)9 EquipmentType (megamek.common.EquipmentType)8 LocationFullException (megamek.common.LocationFullException)7 BattleArmor (megamek.common.BattleArmor)6 Weapon (megamek.common.weapons.Weapon)6 Dimension (java.awt.Dimension)5 JMenuItem (javax.swing.JMenuItem)5 JPopupMenu (javax.swing.JPopupMenu)5 InfantryWeapon (megamek.common.weapons.infantry.InfantryWeapon)5 PPCWeapon (megamek.common.weapons.ppc.PPCWeapon)5 MouseEvent (java.awt.event.MouseEvent)4 MouseListener (java.awt.event.MouseListener)4 HashMap (java.util.HashMap)4 Hashtable (java.util.Hashtable)4