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