Search in sources :

Example 16 with BattleArmor

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

the class BAProtoArmorView method setFromEntity.

public void setFromEntity(Entity en) {
    etype = en.getEntityType();
    refresh();
    cbArmorType.removeActionListener(this);
    spnArmorPoints.removeChangeListener(this);
    String name = EquipmentType.getArmorTypeName(en.getArmorType(0), TechConstants.isClan(en.getArmorTechLevel(0)));
    EquipmentType eq = EquipmentType.get(name);
    cbArmorType.setSelectedItem(eq);
    if (en.hasETypeFlag(Entity.ETYPE_BATTLEARMOR)) {
        spnArmorPointsModel.setValue(Math.min(((BattleArmor) en).getMaximumArmorPoints(), en.getOArmor(BattleArmor.LOC_TROOPER_1)));
        spnArmorPointsModel.setMaximum(((BattleArmor) en).getMaximumArmorPoints());
    } else {
        spnArmorPointsModel.setValue(en.getTotalOArmor());
    }
    cbArmorType.addActionListener(this);
    spnArmorPoints.addChangeListener(this);
}
Also used : EquipmentType(megamek.common.EquipmentType) BattleArmor(megamek.common.BattleArmor)

Example 17 with BattleArmor

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

the class EquipmentTableModel method getValueAt.

public Object getValueAt(int row, int col) {
    EquipmentType type;
    WeaponType wtype = null;
    AmmoType atype = null;
    MiscType mtype = null;
    if (data.isEmpty()) {
        return "";
    } else {
        type = data.get(row);
    }
    if (type instanceof WeaponType) {
        wtype = (WeaponType) type;
    }
    if (type instanceof AmmoType) {
        atype = (AmmoType) type;
    }
    if (type instanceof MiscType) {
        mtype = (MiscType) type;
    }
    DecimalFormat formatter = new DecimalFormat();
    if (col == COL_NAME) {
        return UnitUtil.trimInfantryWeaponNames(type.getName());
    } else if (col == COL_DAMAGE) {
        if (null != wtype) {
            return getDamageString(wtype, entity instanceof Aero);
        } else {
            return "-";
        }
    } else if (col == COL_DIVISOR) {
        if (mtype != null && mtype.hasFlag(MiscType.F_ARMOR_KIT)) {
            if ((mtype.getSubType() & MiscType.S_ENCUMBERING) == 0) {
                return String.valueOf(mtype.getDamageDivisor());
            } else {
                return mtype.getDamageDivisor() + "E";
            }
        } else {
            return "-";
        }
    } else if (col == COL_SPECIAL) {
        String special = "";
        if (type instanceof InfantryWeapon) {
            if (type.hasFlag(WeaponType.F_INF_POINT_BLANK)) {
                special += "(P)";
            }
            if (type.hasFlag(WeaponType.F_INF_AA)) {
                special += "A";
            }
            if (type.hasFlag(WeaponType.F_INF_BURST)) {
                special += "B";
            }
            if (type.hasFlag(WeaponType.F_INF_NONPENETRATING)) {
                special += "N";
            }
            if (type.hasFlag(WeaponType.F_PLASMA) || type.hasFlag(WeaponType.F_INCENDIARY_NEEDLES) || type.hasFlag(WeaponType.F_INFERNO)) {
                special += "F";
            }
        }
        if (type.hasFlag(MiscType.F_ARMOR_KIT)) {
            if ((type.getSubType() & MiscType.S_DEST) != 0) {
                special += "DEST ";
            }
            if ((type.getSubType() & MiscType.S_SNEAK_CAMO) != 0) {
                special += "Camo ";
            }
            if ((type.getSubType() & MiscType.S_SNEAK_IR) != 0) {
                special += "IR ";
            }
            if ((type.getSubType() & MiscType.S_SNEAK_ECM) != 0) {
                special += "ECM ";
            }
            if ((type.getSubType() & MiscType.S_SPACE_SUIT) != 0) {
                special += "SPC ";
            }
        }
        return special;
    } else if (col == COL_CREW) {
        String special = "";
        if (type instanceof InfantryWeapon) {
            special += Integer.toString(((InfantryWeapon) type).getCrew());
            if (type.hasFlag(WeaponType.F_INF_ENCUMBER)) {
                special += "E";
            }
        } else if (type instanceof WeaponType) {
            // Field gun crew size
            special += Math.max(2, (int) Math.ceil(type.getTonnage(entity)));
        }
        return special;
    } else if (col == COL_HEAT) {
        if (null != wtype) {
            if (entity instanceof Aero) {
                return Integer.toString(wtype.getHeat() * Mounted.getNumShots(wtype, null, true));
            } else {
                return Integer.toString(wtype.getHeat());
            }
        } else {
            return "-";
        }
    } else if (col == COL_SHOTS) {
        if (null != atype) {
            return Integer.toString(atype.getShots());
        } else {
            return "-";
        }
    } else if (col == COL_RANGE) {
        if (null != wtype) {
            if (entity instanceof Aero) {
                switch(wtype.maxRange) {
                    case RangeType.RANGE_SHORT:
                        return "Short";
                    case RangeType.RANGE_MEDIUM:
                        return "Medium";
                    case RangeType.RANGE_LONG:
                        return "Long";
                    case RangeType.RANGE_EXTREME:
                        return "Extreme";
                }
                ;
            }
            if (wtype instanceof InfantryWeapon) {
                return ((InfantryWeapon) wtype).getInfantryRange() + "";
            }
            return wtype.getShortRange() + "/" + wtype.getMediumRange() + "/" + wtype.getLongRange();
        } else {
            return "-";
        }
    } else if (col == COL_MRANGE) {
        if (null != wtype) {
            if (entity instanceof Aero) {
                return "-";
            }
            int minRange = wtype.getMinimumRange();
            if (minRange < 0) {
                minRange = 0;
            }
            return Integer.toString(minRange);
        } else {
            return "-";
        }
    } else if (col == COL_TON) {
        if ((entity instanceof BattleArmor) && (atype != null)) {
            return (atype.getKgPerShot() * atype.getShots()) / 1000;
        } else {
            return type.getTonnage(entity);
        }
    } else if (col == COL_CRIT) {
        if (entity instanceof Tank) {
            return type.getTankslots(entity);
        }
        return type.getCriticals(entity);
    } else if (col == COL_TRATING) {
        return type.getFullRatingName(entity.isClan());
    } else if (col == COL_COST) {
        return formatter.format(type.getCost(entity, false, Entity.LOC_NONE));
    } else if (col == COL_BV) {
        return type.getBV(entity);
    } else if (col == COL_DPROTOTYPE) {
        return entity.isMixedTech() ? type.getTechAdvancement().getPrototypeDateName() : type.getTechAdvancement().getPrototypeDateName(entity.isClan());
    } else if (col == COL_DPRODUCTION) {
        return entity.isMixedTech() ? type.getTechAdvancement().getProductionDateName() : type.getTechAdvancement().getProductionDateName(entity.isClan());
    } else if (col == COL_DCOMMON) {
        return entity.isMixedTech() ? type.getTechAdvancement().getCommonDateName() : type.getTechAdvancement().getCommonDateName(entity.isClan());
    } else if (col == COL_DEXTINCT) {
        return entity.isMixedTech() ? type.getTechAdvancement().getExtinctionDateName() : type.getTechAdvancement().getExtinctionDateName(entity.isClan());
    } else if (col == COL_DREINTRO) {
        return entity.isMixedTech() ? type.getTechAdvancement().getReintroductionDateName() : type.getTechAdvancement().getReintroductionDateName(entity.isClan());
    } else if (col == COL_TLEVEL) {
        if ((null != techManager) && CConfig.getBooleanParam(CConfig.TECH_PROGRESSION)) {
            return type.getSimpleLevel(techManager.getGameYear(), techManager.useClanTechBase(), techManager.getTechFaction()).toString();
        } else {
            return type.getStaticTechLevel().toString();
        }
    } else if (col == COL_TECH) {
        switch(type.getTechBase()) {
            case TechAdvancement.TECH_BASE_ALL:
                return "All";
            case TechAdvancement.TECH_BASE_IS:
                return "IS";
            case TechAdvancement.TECH_BASE_CLAN:
                return "Clan";
        }
    } else if (col == COL_REF) {
        return type.getRulesRefs();
    }
    return "?";
}
Also used : AmmoType(megamek.common.AmmoType) WeaponType(megamek.common.WeaponType) MiscType(megamek.common.MiscType) DecimalFormat(java.text.DecimalFormat) EquipmentType(megamek.common.EquipmentType) Tank(megamek.common.Tank) Aero(megamek.common.Aero) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon) BattleArmor(megamek.common.BattleArmor)

Example 18 with BattleArmor

use of megamek.common.BattleArmor 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)

Aggregations

BattleArmor (megamek.common.BattleArmor)18 Mounted (megamek.common.Mounted)9 Aero (megamek.common.Aero)8 CriticalSlot (megamek.common.CriticalSlot)8 TestBattleArmor (megamek.common.verifier.TestBattleArmor)8 Mech (megamek.common.Mech)7 Tank (megamek.common.Tank)7 AmmoType (megamek.common.AmmoType)6 Entity (megamek.common.Entity)6 WeaponType (megamek.common.WeaponType)6 Infantry (megamek.common.Infantry)5 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 EquipmentType (megamek.common.EquipmentType)4 MiscType (megamek.common.MiscType)4 SmallCraft (megamek.common.SmallCraft)4 EntityLoadingException (megamek.common.loaders.EntityLoadingException)4 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 File (java.io.File)3 Vector (java.util.Vector)3