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;
}
Aggregations