Search in sources :

Example 6 with Engine

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

the class StructureTab method recalculateEngineRating.

/**
 * Calculates required engine rating for speed and tonnage and updates engine if possible.
 * @return true if the new engine is legal for rating, space, and tech level
 */
private boolean recalculateEngineRating(int walkMP, double tonnage) {
    int rating = TestAero.calculateEngineRating(getAero(), (int) tonnage, walkMP);
    int oldRating = getAero().getEngine().getRating();
    if (oldRating != rating) {
        panChassis.setEngineRating(rating);
        Engine engine = panChassis.getEngine();
        if (!engine.engineValid || !panInfo.isLegal(engine)) {
            JOptionPane.showMessageDialog(this, String.format("The required engine rating of %d exceeds the maximum.", rating), "Bad Engine", JOptionPane.ERROR_MESSAGE);
            panChassis.setEngineRating(oldRating);
            return false;
        }
    }
    return true;
}
Also used : Engine(megamek.common.Engine)

Example 7 with Engine

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

the class StructureTab method recalculateEngineRating.

/**
 * Calculates required engine rating for speed and tonnage and updates engine if possible.
 * @return true if the new engine is legal for rating, space, and tech level
 */
private boolean recalculateEngineRating(int walkMP, double tonnage) {
    int rating = walkMP * (int) tonnage - Tank.getSuspensionFactor(panChassis.getMovementMode(), tonnage);
    if (rating < 10) {
        rating = 10;
    }
    int oldRating = getTank().getEngine().getRating();
    if (oldRating != rating) {
        panChassis.setEngineRating(rating);
        Engine engine = panChassis.getEngine();
        if (!engine.engineValid || !panBasicInfo.isLegal(engine)) {
            JOptionPane.showMessageDialog(this, String.format("The required engine rating of %d exceeds the maximum.", rating), "Bad Engine", JOptionPane.ERROR_MESSAGE);
            panChassis.setEngineRating(oldRating);
            return false;
        } else {
            engine.setBaseChassisHeatSinks(-1);
            getTank().setEngine(engine);
        }
    }
    return true;
}
Also used : Engine(megamek.common.Engine)

Example 8 with Engine

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

the class CVChassisView 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 9 with Engine

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

the class CVChassisView method getAvailableEngines.

public List<Engine> getAvailableEngines() {
    List<Engine> retVal = new ArrayList<>();
    boolean isMixed = techManager.useMixedTech();
    int flags = Engine.TANK_ENGINE;
    if (techManager.useClanTechBase()) {
        flags |= Engine.CLAN_ENGINE;
    }
    if (getEngineRating() > 400) {
        flags |= Engine.LARGE_ENGINE;
    }
    int altFlags = flags ^ Engine.CLAN_ENGINE;
    int[] engineTypes = ENGINE_TYPES;
    for (int i : engineTypes) {
        Engine e = new Engine(getEngineRating(), i, flags);
        if (e.engineValid && techManager.isLegal(e)) {
            retVal.add(e);
        }
        // (i.e. different slot requirement)
        if (isMixed && e.getSideTorsoCriticalSlots().length > 0) {
            e = new Engine(getEngineRating(), i, altFlags);
            if (e.engineValid && techManager.isLegal(e)) {
                retVal.add(e);
            }
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Engine(megamek.common.Engine)

Example 10 with Engine

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

the class FighterChassisView method setEngine.

/**
 * Select the first engine in the list that matches engine type and flags, disregarding the large engine flag.
 */
public void setEngine(Engine engine) {
    if (null != engine) {
        int type = engine.getEngineType();
        int flags = engine.getFlags() & ~Engine.LARGE_ENGINE;
        for (int i = 0; i < cbEngine.getModel().getSize(); i++) {
            final Engine e = cbEngine.getItemAt(i);
            if ((e.getEngineType() == type) && ((e.getFlags() & ~Engine.LARGE_ENGINE) == flags)) {
                cbEngine.setSelectedIndex(i);
                return;
            }
        }
    }
}
Also used : 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