Search in sources :

Example 31 with EquipmentType

use of megamek.common.EquipmentType 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 32 with EquipmentType

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

the class StructureTab method refresh.

public void refresh() {
    panBasicInfo.setFromEntity(getInfantry());
    panPlatoonType.setFromEntity(getInfantry());
    panWeapons.setFromEntity(getInfantry());
    removeAllListeners();
    EquipmentType armor = getInfantry().getArmorKit();
    if (null != armor) {
        txtArmor.setText(armor.getName());
    } else {
        String desc = getInfantry().getArmorDesc();
        if (desc.equals("1.0")) {
            txtArmor.setText("None");
        } else {
            txtArmor.setText(desc);
        }
    }
    updateSpecializations();
    StringJoiner sj = new StringJoiner("<br/>");
    for (Enumeration<IOption> e = getInfantry().getCrew().getOptions(PilotOptions.MD_ADVANTAGES); e.hasMoreElements(); ) {
        final IOption opt = e.nextElement();
        if (getInfantry().getCrew().getOptions().booleanOption(opt.getName())) {
            sj.add(opt.getDisplayableName());
        }
    }
    if (sj.length() > 0) {
        txtAugmentations.setText(sj.toString());
    } else {
        txtAugmentations.setText("None");
    }
    weaponView.refresh();
    fieldGunView.refresh();
    armorView.refresh();
    specializationView.refresh();
    augmentationView.refresh();
    enableTabs();
    addAllListeners();
}
Also used : IOption(megamek.common.options.IOption) EquipmentType(megamek.common.EquipmentType) StringJoiner(java.util.StringJoiner)

Example 33 with EquipmentType

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

the class ArmorView method actionPerformed.

public void actionPerformed(ActionEvent arg0) {
    removeAllListeners();
    if (arg0.getSource().equals(btnSetArmor)) {
        int view = masterEquipmentTable.getSelectedRow();
        if (view < 0) {
            // selection got filtered away
            return;
        }
        int selected = masterEquipmentTable.convertRowIndexToModel(view);
        EquipmentType equip = masterEquipmentList.getType(selected);
        if (equip.hasFlag(MiscType.F_ARMOR_KIT)) {
            getInfantry().setArmorKit(equip);
            rbtnCustom.setEnabled(false);
        }
    } else if (arg0.getSource().equals(btnRemoveArmor)) {
        getInfantry().setArmorKit(null);
        getInfantry().setDamageDivisor(1.0);
        getInfantry().setArmorEncumbering(false);
        getInfantry().setSpaceSuit(false);
        getInfantry().setDEST(false);
        getInfantry().setSneakCamo(false);
        getInfantry().setSneakIR(false);
        getInfantry().setSneakECM(false);
        rbtnCustom.setEnabled(true);
    }
    if (arg0.getSource().equals(chEncumber)) {
        getInfantry().setArmorEncumbering(chEncumber.isSelected());
    } else if (arg0.getSource().equals(chSpaceSuit)) {
        getInfantry().setSpaceSuit(chSpaceSuit.isSelected());
    } else if (arg0.getSource().equals(chDEST)) {
        getInfantry().setDEST(chDEST.isSelected());
    } else if (arg0.getSource().equals(chSneakCamo)) {
        getInfantry().setSneakCamo(chSneakCamo.isSelected());
    } else if (arg0.getSource().equals(chSneakIR)) {
        getInfantry().setSneakIR(chSneakIR.isSelected());
    } else if (arg0.getSource().equals(chSneakECM)) {
        getInfantry().setSneakECM(chSneakECM.isSelected());
    }
    addAllListeners();
    if (refresh != null) {
        refresh.refreshStructure();
        refresh.refreshStatus();
        refresh.refreshPreview();
    }
}
Also used : EquipmentType(megamek.common.EquipmentType)

Example 34 with EquipmentType

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

the class FieldGunView method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(btnSetGun)) {
        int view = masterEquipmentTable.getSelectedRow();
        if (view < 0) {
            // selection got filtered away
            return;
        }
        int selected = masterEquipmentTable.convertRowIndexToModel(view);
        EquipmentType equip = masterEquipmentList.getType(selected);
        int num;
        if (equip instanceof ArtilleryWeapon || equip instanceof ArtilleryCannonWeapon) {
            num = 1;
        } else {
            int crewReq = Math.max(2, (int) Math.ceil(equip.getTonnage(getInfantry())));
            num = getInfantry().getShootingStrength() / crewReq;
        }
        UnitUtil.replaceFieldGun(getInfantry(), (WeaponType) equip, num);
    } else if (e.getSource().equals(btnRemoveGun)) {
        UnitUtil.replaceFieldGun(getInfantry(), null, 0);
    } else {
        return;
    }
    refresh.refreshAll();
}
Also used : ArtilleryWeapon(megamek.common.weapons.artillery.ArtilleryWeapon) ArtilleryCannonWeapon(megamek.common.weapons.artillery.ArtilleryCannonWeapon) EquipmentType(megamek.common.EquipmentType)

Example 35 with EquipmentType

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

the class WeaponView method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ADDP_COMMAND) || e.getActionCommand().equals(ADDS_COMMAND)) {
        boolean isSecondary = e.getActionCommand().equals(ADDS_COMMAND);
        int view = masterEquipmentTable.getSelectedRow();
        if (view < 0) {
            // selection got filtered away
            return;
        }
        int selected = masterEquipmentTable.convertRowIndexToModel(view);
        EquipmentType equip = masterEquipmentList.getType(selected);
        if (equip instanceof InfantryWeapon) {
            UnitUtil.replaceMainWeapon(getInfantry(), (InfantryWeapon) equip, isSecondary);
            if (equip.hasFlag(WeaponType.F_TAG)) {
                getInfantry().setSpecializations(getInfantry().getSpecializations() | Infantry.TAG_TROOPS);
                getInfantry().setSecondaryN(2);
            } else if (getInfantry().getSecondaryN() == 0) {
                getInfantry().setSecondaryN(1);
            }
        }
    } else {
        return;
    }
    refresh.refreshAll();
}
Also used : EquipmentType(megamek.common.EquipmentType) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon)

Aggregations

EquipmentType (megamek.common.EquipmentType)49 Mounted (megamek.common.Mounted)24 MiscType (megamek.common.MiscType)14 LocationFullException (megamek.common.LocationFullException)10 ArrayList (java.util.ArrayList)8 JLabel (javax.swing.JLabel)6 AmmoType (megamek.common.AmmoType)6 CriticalSlot (megamek.common.CriticalSlot)6 WeaponType (megamek.common.WeaponType)5 Dimension (java.awt.Dimension)4 List (java.util.List)4 Vector (java.util.Vector)4 BattleArmor (megamek.common.BattleArmor)4 Mech (megamek.common.Mech)4 EntitySource (megameklab.com.ui.EntitySource)4 RefreshListener (megameklab.com.util.RefreshListener)4 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3 ActionEvent (java.awt.event.ActionEvent)3 StringJoiner (java.util.StringJoiner)3