diff --git a/megamek/src/megamek/common/Hex.java b/megamek/src/megamek/common/Hex.java index 1d2a1b66b7..c8e1722315 100644 --- a/megamek/src/megamek/common/Hex.java +++ b/megamek/src/megamek/common/Hex.java @@ -575,21 +575,34 @@ public boolean isIgnitable() { || containsTerrain(Terrains.FIELDS) || containsTerrain(Terrains.INDUSTRIAL)); } + /** + * Returns true if the hex is valid for takeoff - either clear, has pavement, or a road + * @return + */ public boolean isClearForTakeoff() { - for (final Integer i : terrains.keySet()) { - if (containsTerrain(i) && (i != Terrains.PAVEMENT) && (i != Terrains.ROAD) && (i != Terrains.FLUFF) - && (i != Terrains.ARMS) && (i != Terrains.LEGS) && (i != Terrains.SNOW) && (i != Terrains.MUD) - && (i != Terrains.SMOKE) && (i != Terrains.METAL_CONTENT)) { - return false; - } + if (hasPavementOrRoad()) { + return true; } - return true; + return getBaseTerrainType() == 0; } public boolean isClearForLanding() { return !containsTerrain(Terrains.IMPASSABLE); } + /** + * Returns the "Base Terrain" for the hex, or 0 if it is clear + * @return + */ + public int getBaseTerrainType() { + for (int terrain : terrains.keySet()) { + if (Terrains.isBaseTerrain(terrain)) { + return terrain; + } + } + return 0; + } + public int getFireTurn() { return fireTurn; } diff --git a/megamek/src/megamek/common/IAero.java b/megamek/src/megamek/common/IAero.java index 4017a25995..5042a547d3 100644 --- a/megamek/src/megamek/common/IAero.java +++ b/megamek/src/megamek/common/IAero.java @@ -515,19 +515,18 @@ default PilotingRollData checkLanding(EntityMovementType moveType, int velocity, boolean clear = false; for (Coords pos : landingPositions) { Hex hex = ((Entity) this).getGame().getBoard().getHex(pos); - if ((hex == null) || hex.hasPavement()) { + if ((hex == null) || hex.hasPavementOrRoad()) { continue; } - if (hex.isClearHex()) { + if (hex.getBaseTerrainType() == 0) { clear = true; - } else { - for (int terrain : hex.getTerrainTypes()) { - if ((terrain == Terrains.WATER) && hex.containsTerrain(Terrains.ICE)) { - continue; - } - if (Terrains.landingModifier(terrain, hex.terrainLevel(terrain)) > 0) { - terrains.add(List.of(terrain, hex.terrainLevel(terrain))); - } + } + for (int terrain : hex.getTerrainTypes()) { + if ((terrain == Terrains.WATER) && hex.containsTerrain(Terrains.ICE)) { + continue; + } + if (Terrains.landingModifier(terrain, hex.terrainLevel(terrain)) > 0) { + terrains.add(List.of(terrain, hex.terrainLevel(terrain))); } } } diff --git a/megamek/src/megamek/common/Terrains.java b/megamek/src/megamek/common/Terrains.java index d9bc84c459..7bd9a80ab2 100644 --- a/megamek/src/megamek/common/Terrains.java +++ b/megamek/src/megamek/common/Terrains.java @@ -559,4 +559,17 @@ public static int landingModifier(int terrainType, int terrainLevel) { return 0; } } + + + /** + * Returns true if the terrain is a base terrain type, excluding "Clear" + * @param terrainType + * @return + */ + public static boolean isBaseTerrain(int terrainType){ + return terrainType == WOODS || terrainType == WATER || terrainType == ROUGH + || terrainType == RUBBLE || terrainType == JUNGLE || terrainType == SAND + || terrainType == TUNDRA || terrainType == MAGMA || terrainType == FIELDS + || terrainType == INDUSTRIAL || terrainType == SPACE || terrainType == BUILDING; + } }