Search in sources :

Example 21 with EquipmentType

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

the class UnitUtil method checkEquipmentByTechLevel.

public static boolean checkEquipmentByTechLevel(Entity unit, ITechManager techManager) {
    Vector<Mounted> toRemove = new Vector<Mounted>();
    ITechnology acTA = Entity.getArmoredComponentTechAdvancement();
    boolean dirty = false;
    for (Mounted m : unit.getEquipment()) {
        if (m.isArmored() && !techManager.isLegal(acTA)) {
            m.setArmored(false);
            updateCritsArmoredStatus(unit, m);
            dirty = true;
        }
        EquipmentType etype = m.getType();
        if (UnitUtil.isArmorOrStructure(etype) || UnitUtil.isHeatSink(etype) || UnitUtil.isJumpJet(etype)) {
            continue;
        }
        if (etype.hasFlag(MiscType.F_TSM) || etype.hasFlag(MiscType.F_INDUSTRIAL_TSM) || (etype.hasFlag(MiscType.F_MASC) && !etype.hasSubType(MiscType.S_SUPERCHARGER)) || etype.hasFlag(MiscType.F_SCM)) {
            continue;
        }
        if (!techManager.isLegal(etype)) {
            toRemove.add(m);
        }
    }
    dirty |= toRemove.size() > 0;
    for (Mounted m : toRemove) {
        UnitUtil.removeMounted(unit, m);
    }
    if (unit instanceof Infantry) {
        Infantry pbi = (Infantry) unit;
        if ((null != pbi.getPrimaryWeapon()) && techManager.isLegal(pbi.getPrimaryWeapon())) {
            dirty = true;
            UnitUtil.replaceMainWeapon((Infantry) unit, (InfantryWeapon) EquipmentType.get("Infantry Auto Rifle"), false);
        }
        if ((null != pbi.getSecondaryWeapon()) && !techManager.isLegal(pbi.getSecondaryWeapon())) {
            dirty = true;
            UnitUtil.replaceMainWeapon((Infantry) unit, null, true);
        }
    }
    return dirty;
}
Also used : Infantry(megamek.common.Infantry) TestInfantry(megamek.common.verifier.TestInfantry) ITechnology(megamek.common.ITechnology) Mounted(megamek.common.Mounted) Vector(java.util.Vector) EquipmentType(megamek.common.EquipmentType)

Example 22 with EquipmentType

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

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

the class BAProtoArmorView method refresh.

public void refresh() {
    EquipmentType prev = (EquipmentType) cbArmorType.getSelectedItem();
    cbArmorType.removeActionListener(this);
    cbArmorType.removeAllItems();
    BigInteger flag = BigInteger.valueOf(0);
    if ((etype & Entity.ETYPE_BATTLEARMOR) != 0) {
        flag = MiscType.F_BA_EQUIPMENT;
    } else if ((etype & Entity.ETYPE_PROTOMECH) != 0) {
        flag = MiscType.F_PROTOMECH_EQUIPMENT;
    }
    for (int at = 0; at < EquipmentType.armorNames.length; at++) {
        String name = EquipmentType.getArmorTypeName(at, techManager.useClanTechBase());
        EquipmentType eq = EquipmentType.get(name);
        if ((null != eq) && eq.hasFlag(flag) && techManager.isLegal(eq)) {
            cbArmorType.addItem(eq);
        }
        if (techManager.useMixedTech()) {
            name = EquipmentType.getArmorTypeName(at, !techManager.useClanTechBase());
            EquipmentType eq2 = EquipmentType.get(name);
            if ((null != eq2) && (eq != eq2) && eq2.hasFlag(flag) && techManager.isLegal(eq2)) {
                cbArmorType.addItem(eq2);
            }
        }
    }
    cbArmorType.setSelectedItem(prev);
    cbArmorType.addActionListener(this);
    if ((cbArmorType.getSelectedIndex() < 0) && (cbArmorType.getModel().getSize() > 0)) {
        cbArmorType.setSelectedIndex(0);
    }
    cbArmorType.showTechBase(techManager.useMixedTech());
}
Also used : BigInteger(java.math.BigInteger) EquipmentType(megamek.common.EquipmentType)

Example 24 with EquipmentType

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

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

the class MVFArmorView method refresh.

public void refresh() {
    EquipmentType prev = (EquipmentType) cbArmorType.getSelectedItem();
    cbArmorType.removeActionListener(this);
    cbArmorType.removeAllItems();
    List<EquipmentType> allArmors = TestEntity.legalArmorsFor(etype, industrial, movementMode, techManager);
    allArmors.forEach(eq -> cbArmorType.addItem(eq));
    if (((etype & (Entity.ETYPE_SMALL_CRAFT | Entity.ETYPE_JUMPSHIP)) == 0) && techManager.isLegal(Entity.getPatchworkArmorAdvancement())) {
        cbArmorType.addItem(null);
    }
    if (null == prev) {
        cbArmorType.setSelectedIndex(cbArmorType.getModel().getSize() - 1);
    } else {
        cbArmorType.setSelectedItem(prev);
    }
    cbArmorType.addActionListener(this);
    if ((null != prev) && (cbArmorType.getSelectedIndex() < 0)) {
        cbArmorType.setSelectedIndex(0);
    }
    cbArmorType.showTechBase(techManager.useMixedTech());
}
Also used : EquipmentType(megamek.common.EquipmentType)

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