Search in sources :

Example 6 with Infantry

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;
}
Also used : TestEntity(megamek.common.verifier.TestEntity) EntityVerifier(megamek.common.verifier.EntityVerifier) TestTank(megamek.common.verifier.TestTank) TestAero(megamek.common.verifier.TestAero) TestBattleArmor(megamek.common.verifier.TestBattleArmor) TestTank(megamek.common.verifier.TestTank) Tank(megamek.common.Tank) Infantry(megamek.common.Infantry) TestInfantry(megamek.common.verifier.TestInfantry) TestMech(megamek.common.verifier.TestMech) TestSupportVehicle(megamek.common.verifier.TestSupportVehicle) TestSmallCraft(megamek.common.verifier.TestSmallCraft) Mech(megamek.common.Mech) TestMech(megamek.common.verifier.TestMech) TripodMech(megamek.common.TripodMech) BipedMech(megamek.common.BipedMech) LandAirMech(megamek.common.LandAirMech) QuadMech(megamek.common.QuadMech) File(java.io.File) Aero(megamek.common.Aero) TestAero(megamek.common.verifier.TestAero) TestInfantry(megamek.common.verifier.TestInfantry)

Example 7 with Infantry

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;
}
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 8 with Infantry

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");
}
Also used : Infantry(megamek.common.Infantry) LocationFullException(megamek.common.LocationFullException)

Aggregations

Infantry (megamek.common.Infantry)8 Aero (megamek.common.Aero)5 Entity (megamek.common.Entity)5 Mech (megamek.common.Mech)5 Tank (megamek.common.Tank)5 BattleArmor (megamek.common.BattleArmor)4 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 File (java.io.File)2 Vector (java.util.Vector)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 FixedWingSupport (megamek.common.FixedWingSupport)2 MechFileParser (megamek.common.MechFileParser)2 SmallCraft (megamek.common.SmallCraft)2 TestInfantry (megamek.common.verifier.TestInfantry)2 Vector (com.sun.java.util.collections.Vector)1 Frame (java.awt.Frame)1 KeyEvent (java.awt.event.KeyEvent)1 Book (java.awt.print.Book)1