Search in sources :

Example 26 with MiscType

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

the class UnitUtil method getShieldDamageCapacity.

public static int getShieldDamageCapacity(Mech mech, int location) {
    final String METHOD_NAME = "getShieldDamageCapacity(Mech, int)";
    for (int slot = 0; slot < mech.getNumberOfCriticals(location); slot++) {
        CriticalSlot cs = mech.getCritical(location, slot);
        if (cs == null) {
            continue;
        }
        if (cs.getType() != CriticalSlot.TYPE_EQUIPMENT) {
            continue;
        }
        Mounted m = cs.getMount();
        if (m == null) {
            getLogger().log(UnitUtil.class, METHOD_NAME, LogLevel.ERROR, "Null Mount index: " + cs.getIndex());
            m = cs.getMount();
        }
        EquipmentType type = m.getType();
        if ((type instanceof MiscType) && ((MiscType) type).isShield()) {
            return m.getBaseDamageCapacity();
        }
    }
    return 0;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType)

Example 27 with MiscType

use of megamek.common.MiscType 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 28 with MiscType

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

the class EquipmentTab method addEquipment.

private void addEquipment(EquipmentType equip) {
    boolean success = false;
    Mounted mount = null;
    boolean isMisc = equip instanceof MiscType;
    if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
        if (!UnitUtil.hasTargComp(getMech())) {
            mount = UnitUtil.updateTC(getMech(), equip);
            success = mount != null;
        }
    } else if (isMisc && UnitUtil.isFixedLocationSpreadEquipment(equip)) {
        mount = UnitUtil.createSpreadMounts(getMech(), equip);
        success = mount != null;
    } else {
        try {
            mount = new Mounted(getMech(), equip);
            getMech().addEquipment(mount, Entity.LOC_NONE, false);
            success = true;
        } catch (LocationFullException lfe) {
        // this can't happen, we add to Entity.LOC_NONE
        }
    }
    if (success) {
        equipmentList.addCrit(mount);
    }
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType)

Example 29 with MiscType

use of megamek.common.MiscType 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 30 with MiscType

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

the class BuildView method jMenuLoadComponent_actionPerformed.

private void jMenuLoadComponent_actionPerformed(int location, int selectedRow) {
    Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
    if (eq.getType().isSpreadable() || eq.isSplitable()) {
        if (!(eq.getType() instanceof MiscType) || !eq.getType().hasFlag(MiscType.F_TARGCOMP)) {
            jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, 1, selectedRow);
        } else {
            // Targetting computer is flagged as spreadable so the slots will be added one at a time when loaded,
            // since we don't have a way of indicating the number of slots until we know all the weapons. But
            // it's not really splittable, so we need to put add all the slots at once.
            jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, eq.getType().getCriticals(getMech()), selectedRow);
        }
        return;
    }
    try {
        if ((eq.getType() instanceof WeaponType) && eq.getType().hasFlag(WeaponType.F_VGL)) {
            String[] facings;
            if (location == Mech.LOC_LT) {
                facings = new String[4];
                facings[0] = "Front";
                facings[1] = "Front-Left";
                facings[2] = "Rear-Left";
                facings[3] = "Rear";
            } else if (location == Mech.LOC_RT) {
                facings = new String[4];
                facings[0] = "Front";
                facings[1] = "Front-Right";
                facings[2] = "Rear-Right";
                facings[3] = "Rear";
            } else if (location == Mech.LOC_CT) {
                facings = new String[2];
                facings[0] = "Front";
                facings[1] = "Rear";
            } else {
                JOptionPane.showMessageDialog(this, "VGL must be placed in torso location!", "Invalid location", JOptionPane.WARNING_MESSAGE);
                return;
            }
            String facing = (String) JOptionPane.showInputDialog(this, "Please choose the facing of the VGL", "Choose Facing", JOptionPane.QUESTION_MESSAGE, null, facings, facings[0]);
            if (facing == null) {
                return;
            }
            UnitUtil.addMounted(getMech(), eq, location, false);
            if (facing.equals("Front-Left")) {
                eq.setFacing(5);
            } else if (facing.equals("Front-Right")) {
                eq.setFacing(1);
            } else if (facing.equals("Rear-Right")) {
                eq.setFacing(2);
            } else if (facing.equals("Rear-Left")) {
                eq.setFacing(4);
            } else if (facing.equals("Rear")) {
                eq.setFacing(3);
                UnitUtil.changeMountStatus(getMech(), eq, location, -1, true);
            }
        } else {
            UnitUtil.addMounted(getMech(), eq, location, false);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    UnitUtil.changeMountStatus(getMech(), eq, location, -1, false);
    // go back up to grandparent build tab and fire a full refresh.
    ((BuildTab) getParent().getParent()).refreshAll();
}
Also used : BuildTab(megameklab.com.ui.Mek.tabs.BuildTab) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) WeaponType(megamek.common.WeaponType)

Aggregations

MiscType (megamek.common.MiscType)37 Mounted (megamek.common.Mounted)33 AmmoType (megamek.common.AmmoType)14 EquipmentType (megamek.common.EquipmentType)13 LocationFullException (megamek.common.LocationFullException)12 WeaponType (megamek.common.WeaponType)11 Vector (java.util.Vector)9 CriticalSlot (megamek.common.CriticalSlot)7 ArrayList (java.util.ArrayList)6 Weapon (megamek.common.weapons.Weapon)6 PPCWeapon (megamek.common.weapons.ppc.PPCWeapon)5 JMenuItem (javax.swing.JMenuItem)4 JPopupMenu (javax.swing.JPopupMenu)4 BattleArmor (megamek.common.BattleArmor)4 Entity (megamek.common.Entity)4 Dimension (java.awt.Dimension)3 ActionEvent (java.awt.event.ActionEvent)3 MouseEvent (java.awt.event.MouseEvent)3 MouseListener (java.awt.event.MouseListener)3 List (java.util.List)3