Search in sources :

Example 11 with Engine

use of megamek.common.Engine in project megameklab by MegaMek.

the class FighterChassisView method getAvailableEngines.

public List<Engine> getAvailableEngines() {
    if (isPrimitive()) {
        return Collections.singletonList(new Engine(getEngineRating(), Engine.NORMAL_ENGINE, 0));
    }
    List<Engine> retVal = new ArrayList<>();
    boolean isMixed = techManager.useMixedTech();
    int flags = 0;
    if (techManager.useClanTechBase()) {
        flags |= Engine.CLAN_ENGINE;
    }
    if (getEngineRating() > 400) {
        flags |= Engine.LARGE_ENGINE;
    }
    int altFlags = flags ^ Engine.CLAN_ENGINE;
    // Non-superheavies can use non-fusion engines under experimental rules
    for (int i : ENGINE_TYPES) {
        Engine e = new Engine(getEngineRating(), i, flags);
        if (e.engineValid && (e.isFusion() || conventional) && techManager.isLegal(e)) {
            retVal.add(e);
        }
        // Only add the opposite tech base if the engine is different.
        if (isMixed && e.getSideTorsoCriticalSlots().length > 0) {
            e = new Engine(getEngineRating(), i, altFlags);
            if (e.engineValid && (e.isFusion() || conventional) && techManager.isLegal(e)) {
                retVal.add(e);
            }
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Engine(megamek.common.Engine)

Example 12 with Engine

use of megamek.common.Engine in project megameklab by MegaMek.

the class MekChassisView method setEngine.

/**
 * Select the first engine in the list that matches engine type and flags,
 * ignoring any flags other than Clan.
 */
public void setEngine(Engine engine) {
    if (null != engine) {
        int type = engine.getEngineType();
        int flags = engine.getFlags() & Engine.CLAN_ENGINE;
        for (int i = 0; i < cbEngine.getModel().getSize(); i++) {
            final Engine e = cbEngine.getItemAt(i);
            if ((e.getEngineType() == type) && ((e.getFlags() & Engine.CLAN_ENGINE) == flags)) {
                cbEngine.setSelectedIndex(i);
                return;
            }
        }
    }
}
Also used : Engine(megamek.common.Engine)

Example 13 with Engine

use of megamek.common.Engine in project megameklab by MegaMek.

the class MekChassisView method refreshEngine.

private void refreshEngine() {
    cbEngine.removeActionListener(this);
    Engine prevEngine = (Engine) cbEngine.getSelectedItem();
    cbEngine.removeAllItems();
    for (Engine e : getAvailableEngines()) {
        cbEngine.addItem(e);
    }
    setEngine(prevEngine);
    cbEngine.addActionListener(this);
    if (cbEngine.getSelectedIndex() < 0) {
        cbEngine.setSelectedIndex(0);
    }
}
Also used : Engine(megamek.common.Engine)

Example 14 with Engine

use of megamek.common.Engine in project megameklab by MegaMek.

the class MekChassisView method getEngine.

public Engine getEngine() {
    Engine e = (Engine) cbEngine.getSelectedItem();
    if (null == e) {
        return null;
    }
    // Clan and large flags are specific to the engine. the superheavy flag depends on the mech
    // and may have changed since the last refresh.
    int flags = e.getFlags() & (Engine.CLAN_ENGINE | Engine.LARGE_ENGINE);
    if (isSuperheavy()) {
        flags |= Engine.SUPERHEAVY_ENGINE;
    }
    return new Engine(getEngineRating(), e.getEngineType(), flags);
}
Also used : Engine(megamek.common.Engine)

Example 15 with Engine

use of megamek.common.Engine in project megameklab by MegaMek.

the class MainUI method createNewUnit.

@Override
public void createNewUnit(long entityType, boolean isPrimitive, boolean isIndustrial, Entity oldEntity) {
    if (entityType == Entity.ETYPE_VTOL) {
        setEntity(new VTOL());
        getEntity().setTechLevel(TechConstants.T_INTRO_BOXSET);
        getEntity().setWeight(20);
        getEntity().setMovementMode(EntityMovementMode.VTOL);
    } else {
        if (entityType == Entity.ETYPE_SUPER_HEAVY_TANK) {
            setEntity(new SuperHeavyTank());
            getEntity().setTechLevel(TechConstants.T_IS_ADVANCED);
            getEntity().setWeight(51);
        } else {
            setEntity(new Tank());
            getEntity().setTechLevel(TechConstants.T_INTRO_BOXSET);
            getEntity().setWeight(20);
        }
        getEntity().setMovementMode(EntityMovementMode.HOVER);
    }
    Tank tank = (Tank) getEntity();
    tank.setYear(3145);
    tank.setEngine(new Engine(Math.max(10, (int) getEntity().getWeight() - tank.getSuspensionFactor()), Engine.NORMAL_ENGINE, Engine.TANK_ENGINE));
    tank.autoSetInternal();
    for (int loc = 0; loc < getEntity().locations(); loc++) {
        tank.initializeArmor(0, loc);
    }
    getEntity().setArmorType(EquipmentType.T_ARMOR_STANDARD);
    getEntity().setArmorTechLevel(TechConstants.T_INTRO_BOXSET);
    getEntity().setStructureType(EquipmentType.T_STRUCTURE_STANDARD);
    tank.setHasNoDualTurret(true);
    if (Entity.ETYPE_VTOL == entityType) {
        tank.setHasNoTurret(true);
    }
    if (null == oldEntity) {
        tank.setChassis("New");
        tank.setModel("Tank");
        tank.setYear(3145);
    } else {
        tank.setChassis(oldEntity.getChassis());
        tank.setModel(oldEntity.getModel());
        tank.setYear(Math.max(oldEntity.getYear(), tank.getConstructionTechAdvancement().getIntroductionDate()));
        tank.setSource(oldEntity.getSource());
        tank.setManualBV(oldEntity.getManualBV());
        SimpleTechLevel lvl = SimpleTechLevel.max(tank.getStaticTechLevel(), SimpleTechLevel.convertCompoundToSimple(oldEntity.getTechLevel()));
        tank.setTechLevel(lvl.getCompoundTechLevel(oldEntity.isClan()));
        tank.setMixedTech(oldEntity.isMixedTech());
        tank.setMovementMode(oldEntity.getMovementMode());
    }
    tank.setOriginalWalkMP((tank.getEngine().getRating() + tank.getSuspensionFactor()) / (int) tank.getWeight());
}
Also used : SimpleTechLevel(megamek.common.SimpleTechLevel) VTOL(megamek.common.VTOL) SuperHeavyTank(megamek.common.SuperHeavyTank) SuperHeavyTank(megamek.common.SuperHeavyTank) Tank(megamek.common.Tank) Engine(megamek.common.Engine)

Aggregations

Engine (megamek.common.Engine)17 ArrayList (java.util.ArrayList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 SimpleTechLevel (megamek.common.SimpleTechLevel)3 Aero (megamek.common.Aero)1 BipedMech (megamek.common.BipedMech)1 ConvFighter (megamek.common.ConvFighter)1 LandAirMech (megamek.common.LandAirMech)1 Mech (megamek.common.Mech)1 QuadMech (megamek.common.QuadMech)1 QuadVee (megamek.common.QuadVee)1 SuperHeavyTank (megamek.common.SuperHeavyTank)1 Tank (megamek.common.Tank)1 TripodMech (megamek.common.TripodMech)1 VTOL (megamek.common.VTOL)1