use of megamek.common.Infantry in project megameklab by MegaMek.
the class UnitUtil method getEntityVerifier.
/**
* Returns a TestEntity instance for the supplied Entity.
*
* @param unit
* @return
*/
public static TestEntity getEntityVerifier(Entity unit) {
EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
TestEntity testEntity = null;
if (unit.hasETypeFlag(Entity.ETYPE_MECH)) {
testEntity = new TestMech((Mech) unit, entityVerifier.mechOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_SUPPORT_TANK)) {
testEntity = new TestSupportVehicle((Tank) unit, entityVerifier.tankOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_TANK)) {
testEntity = new TestTank((Tank) unit, entityVerifier.tankOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
testEntity = new TestSmallCraft((SmallCraft) unit, entityVerifier.aeroOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_AERO)) {
testEntity = new TestAero((Aero) unit, entityVerifier.aeroOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_BATTLEARMOR)) {
testEntity = new TestBattleArmor((BattleArmor) unit, entityVerifier.baOption, null);
} else if (unit.hasETypeFlag(Entity.ETYPE_INFANTRY)) {
testEntity = new TestInfantry((Infantry) unit, entityVerifier.infOption, null);
}
return testEntity;
}
use of megamek.common.Infantry 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.Infantry in project megameklab by MegaMek.
the class MainUI method createNewUnit.
@Override
public void createNewUnit(long entityType, boolean isPrimitive, boolean isIndustrial, Entity oldEntity) {
setEntity(new Infantry());
getEntity().setYear(3145);
getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
getEntity().setArmorTechLevel(TechConstants.T_IS_TW_NON_BOX);
((Infantry) getEntity()).setSquadN(4);
((Infantry) getEntity()).setSquadSize(7);
((Infantry) getEntity()).setPrimaryWeapon((InfantryWeapon) EquipmentType.get("InfantryAssaultRifle"));
try {
getEntity().addEquipment(EquipmentType.get("InfantryAssaultRifle"), Infantry.LOC_INFANTRY);
} catch (LocationFullException ex) {
}
getEntity().autoSetInternal();
getEntity().setChassis("New");
getEntity().setModel("Infantry");
}
Aggregations