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;
}
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;
}
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);
}
}
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;
}
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;
}
}
}
}
Aggregations