Search in sources :

Example 1 with ITechnology

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

Aggregations

Vector (java.util.Vector)1 EquipmentType (megamek.common.EquipmentType)1 ITechnology (megamek.common.ITechnology)1 Infantry (megamek.common.Infantry)1 Mounted (megamek.common.Mounted)1 TestInfantry (megamek.common.verifier.TestInfantry)1