Skip to content

Commit

Permalink
Issue MegaMek 3360: Fixed takeoff logic and preventing smoke-assisted…
Browse files Browse the repository at this point in the history
… landings
  • Loading branch information
psikomonkie committed Dec 21, 2024
1 parent 8ad58dc commit 4319dc7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
27 changes: 20 additions & 7 deletions megamek/src/megamek/common/Hex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 9 additions & 10 deletions megamek/src/megamek/common/IAero.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions megamek/src/megamek/common/Terrains.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 4319dc7

Please sign in to comment.