Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue MegaMek 3360: Fixed takeoff logic and preventing smoke-assisted landings #6302

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading