Search in sources :

Example 1 with Engine

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

the class CVChassisView 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 clanFlag = 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) == clanFlag)) {
                cbEngine.setSelectedIndex(i);
                return;
            }
        }
    }
}
Also used : Engine(megamek.common.Engine)

Example 2 with Engine

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

the class FighterChassisView 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.getModel().getSize() > 0)) {
        cbEngine.setSelectedIndex(0);
    }
}
Also used : Engine(megamek.common.Engine)

Example 3 with Engine

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

the class MekChassisView method getAvailableEngines.

public List<Engine> getAvailableEngines() {
    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;
    int[] engineTypes = ENGINE_TYPES;
    if (isPrimitive() || isIndustrial()) {
        engineTypes = INDUSTRIAL_ENGINE_TYPES;
    } else if (getBaseTypeIndex() == BASE_TYPE_LAM) {
        engineTypes = LAM_ENGINE_TYPES;
    }
    // Non-superheavies can use non-fusion engines under experimental rules
    boolean allowNonFusion = isPrimitive() || (!isSuperheavy() && techManager.getTechLevel().compareTo(SimpleTechLevel.EXPERIMENTAL) >= 0);
    for (int i : engineTypes) {
        Engine e = new Engine(getEngineRating(), i, flags);
        if (e.engineValid && (e.isFusion() || allowNonFusion) && 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() || allowNonFusion) && techManager.isLegal(e)) {
                retVal.add(e);
            }
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Engine(megamek.common.Engine)

Example 4 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) {
    int cockpit = Mech.COCKPIT_STANDARD;
    int at = EquipmentType.T_ARMOR_STANDARD;
    int st = EquipmentType.T_STRUCTURE_STANDARD;
    if (isPrimitive && isIndustrial) {
        cockpit = Mech.COCKPIT_PRIMITIVE_INDUSTRIAL;
        at = EquipmentType.T_ARMOR_PRIMITIVE;
        st = EquipmentType.T_STRUCTURE_INDUSTRIAL;
    } else if (isPrimitive) {
        cockpit = Mech.COCKPIT_PRIMITIVE;
        at = EquipmentType.T_ARMOR_PRIMITIVE;
    } else if (isIndustrial) {
        cockpit = Mech.COCKPIT_INDUSTRIAL;
        at = EquipmentType.T_ARMOR_INDUSTRIAL;
        st = EquipmentType.T_STRUCTURE_INDUSTRIAL;
    }
    if (entityType == Entity.ETYPE_TRIPOD_MECH) {
        setEntity(new TripodMech(Mech.GYRO_STANDARD, Mech.COCKPIT_TRIPOD));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    } else if (entityType == Entity.ETYPE_QUAD_MECH) {
        setEntity(new QuadMech(Mech.GYRO_STANDARD, cockpit));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    } else if (entityType == Entity.ETYPE_LAND_AIR_MECH) {
        setEntity(new LandAirMech(Mech.GYRO_STANDARD, Mech.COCKPIT_STANDARD, LandAirMech.LAM_STANDARD));
        getEntity().setTechLevel(TechConstants.T_IS_ADVANCED);
        getEntity().setManualBV(-1);
    } else if (entityType == Entity.ETYPE_QUADVEE) {
        setEntity(new QuadVee(Mech.GYRO_STANDARD, QuadVee.MOTIVE_TRACK));
        getEntity().setTechLevel(TechConstants.T_CLAN_ADVANCED);
        UnitUtil.createSpreadMounts((Mech) getEntity(), EquipmentType.get("Tracks"));
        getEntity().setManualBV(-1);
    } else {
        // type == 0
        setEntity(new BipedMech(Mech.GYRO_STANDARD, cockpit));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    }
    Mech mech = (Mech) getEntity();
    getEntity().setWeight(25);
    if (entityType == Entity.ETYPE_LAND_AIR_MECH) {
        mech.setEngine(new Engine(75, Engine.NORMAL_ENGINE, 0));
        UnitUtil.updateJumpJets(((Mech) getEntity()), 3, Mech.JUMP_STANDARD);
    } else {
        mech.setEngine(new Engine(25, Engine.NORMAL_ENGINE, 0));
    }
    getEntity().setArmorType(at);
    getEntity().setArmorTechLevel(getEntity().getTechLevel());
    getEntity().setStructureType(st);
    mech.addGyro();
    mech.addEngineCrits();
    if (isPrimitive) {
        mech.addPrimitiveCockpit();
    } else if (isIndustrial) {
        mech.addIndustrialCockpit();
    } else if (Entity.ETYPE_QUADVEE == entityType) {
        mech.addQuadVeeCockpit();
    } else {
        mech.addCockpit();
    }
    UnitUtil.updateHeatSinks(mech, 10, "Single");
    getEntity().autoSetInternal();
    for (int loc = 0; loc < getEntity().locations(); loc++) {
        mech.initializeArmor(0, loc);
        mech.initializeRearArmor(0, loc);
    }
    if (null == oldEntity) {
        mech.setChassis("New");
        mech.setModel("Mek");
        mech.setYear(3145);
    } else {
        mech.setChassis(oldEntity.getChassis());
        mech.setModel(oldEntity.getModel());
        mech.setYear(Math.max(oldEntity.getYear(), mech.getConstructionTechAdvancement().getIntroductionDate()));
        mech.setSource(oldEntity.getSource());
        mech.setManualBV(oldEntity.getManualBV());
        SimpleTechLevel lvl = SimpleTechLevel.max(mech.getStaticTechLevel(), SimpleTechLevel.convertCompoundToSimple(oldEntity.getTechLevel()));
        mech.setTechLevel(lvl.getCompoundTechLevel(oldEntity.isClan()));
        mech.setMixedTech(oldEntity.isMixedTech());
    }
}
Also used : TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) SimpleTechLevel(megamek.common.SimpleTechLevel) BipedMech(megamek.common.BipedMech) Mech(megamek.common.Mech) LandAirMech(megamek.common.LandAirMech) TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) QuadVee(megamek.common.QuadVee) BipedMech(megamek.common.BipedMech) Engine(megamek.common.Engine) LandAirMech(megamek.common.LandAirMech)

Example 5 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;
    if (getMech().isPrimitive()) {
        rating = (int) Math.ceil((rating * 1.2) / 5.0) * 5;
    }
    int oldRating = getMech().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 if ((tonnage <= 100) && !hasCTSpace(engine, getMech().getGyroType(), getMech().getCockpitType())) {
            JOptionPane.showMessageDialog(this, "There is not enough space in the center torso for the required engine.", "Bad Engine", JOptionPane.ERROR_MESSAGE);
            panChassis.setEngineRating(oldRating);
            return false;
        } else {
            engine.setBaseChassisHeatSinks(getMech().getEngine().getBaseChassisHeatSinks(getMech().hasCompactHeatSinks()));
            getMech().setEngine(engine);
            UnitUtil.updateAutoSinks(getMech(), getMech().hasCompactHeatSinks());
        }
    }
    return true;
}
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