Skip to content

Commit

Permalink
Switch to try/catch and reducing logging of off-board minefield lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleet01 committed Jan 13, 2025
1 parent ee3d31b commit 3533e20
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions megamek/src/megamek/server/totalwarfare/TWGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7122,19 +7122,20 @@ private boolean enterMinefield(Entity entity, Coords c, int curElev, boolean isO
continue;
}

// Safety check; can't operate on minefields that don't officially exist
if (game.getBoard().getHex(mf.getCoords()) == null) {
logger.warn("Minefield not found on board: " + mf.toString());
continue;
}

// if we are in the water, then the sea mine will only blow up if at
// the right depth
if (game.getBoard().getHex(mf.getCoords()).containsTerrain(Terrains.WATER)) {
if ((Math.abs(curElev) != mf.getDepth())
try {
// if we are in the water, then the sea mine will only blow up if at
// the right depth
if (game.getBoard().contains(mf.getCoords()) &&
game.getBoard().getHex(mf.getCoords()).containsTerrain(Terrains.WATER)
) {
if ((Math.abs(curElev) != mf.getDepth())
&& (Math.abs(curElev + entity.getHeight()) != mf.getDepth())) {
continue;
continue;
}
}
} catch (NullPointerException _ignored) {
logger.warn("Minefield not found on board: " + mf.toString());
continue;
}

// Check for mine-sweeping. Vibramines handled elsewhere
Expand Down Expand Up @@ -7602,22 +7603,29 @@ boolean checkVibrabombs(Entity entity, Coords coords, boolean displaced, Coords
while (e.hasMoreElements()) {
Minefield mf = e.nextElement();

// Safety check; can't operate on minefields that don't officially exist
if (game.getBoard().getHex(mf.getCoords()) == null) {
logger.warn("Minefield not found on board: " + mf.toString());
continue;
}
try {
// Safety check; can't operate on minefields that don't officially exist
if (game.getBoard().getHex(mf.getCoords()) == null) {
logger.warn("Minefield not found on board: " + mf.toString());
continue;
}

// Bug 954272: Mines shouldn't work underwater, and BMRr says
// Vibrabombs are mines
if (game.getBoard().getHex(mf.getCoords()).containsTerrain(Terrains.WATER)
// Bug 954272: Mines shouldn't work underwater, and BMRr says
// Vibrabombs are mines
if (game.getBoard().contains(mf.getCoords()) &&
game.getBoard().getHex(mf.getCoords()).containsTerrain(Terrains.WATER)
&& !game.getBoard().getHex(mf.getCoords()).containsTerrain(Terrains.PAVEMENT)
&& !game.getBoard().getHex(mf.getCoords()).containsTerrain(Terrains.ICE)) {
continue;
}
continue;
}

// Mek weighing 10 tons or less can't set off the bomb
if (mass <= (mf.getSetting() - 10)) {
continue;
}

// Mek weighing 10 tons or less can't set off the bomb
if (mass <= (mf.getSetting() - 10)) {
} catch (NullPointerException _ignored) {
logger.warn("Minefield not found on board: " + mf.toString());
continue;
}

Expand Down

0 comments on commit 3533e20

Please sign in to comment.