From afa153aa8c4031f286dca2a731713ab69946857a Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 22 Sep 2024 14:36:19 +0200 Subject: [PATCH] fix wige deployment options --- .../common/AllowedDeploymentHelper.java | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/megamek/src/megamek/common/AllowedDeploymentHelper.java b/megamek/src/megamek/common/AllowedDeploymentHelper.java index 368c6854de..c9b6f1d188 100644 --- a/megamek/src/megamek/common/AllowedDeploymentHelper.java +++ b/megamek/src/megamek/common/AllowedDeploymentHelper.java @@ -49,10 +49,32 @@ public List findAllowedElevations() { } result.removeIf(o -> entity.isLocationProhibited(coords, o.elevation())); result.removeIf(o -> Compute.stackingViolation(game, entity, o.elevation(), coords, null, entity.climbMode()) != null); + + if (entity.getMovementMode().isWiGE()) { + addAirborneWigeOptions(result); + } + Collections.sort(result); return result; } + /** + * Adds airborne elevations where the WiGE could deploy landed. + * + * @param result The current options where the WiGE is landed + */ + private void addAirborneWigeOptions(List result) { + // WiGE may also deploy flying wherever they can be grounded + List wigeOptions = new ArrayList<>(); + for (ElevationOption currentOption : result) { + if (!hasElevationOption(result, currentOption.elevation() + 1)) { + // If an elevation already exists, it is probably a bridge; at that elevation, the WiGE is landed + wigeOptions.add(new ElevationOption(currentOption.elevation() + 1, ELEVATION)); + } + } + result.addAll(wigeOptions); + } + private List allowedAeroAltitudes() { List result = new ArrayList<>(); if (board.onGround()) { @@ -78,14 +100,6 @@ private List allowedGroundElevations() { if (!hasZeroElevationOption(result)) { result.addAll(allowedZeroElevation()); } - if (entity.getMovementMode().isWiGE()) { - // WiGE may also deploy flying wherever they can be grounded - List wigeOptions = new ArrayList<>(); - for (ElevationOption currentOption : result) { - wigeOptions.add(new ElevationOption(currentOption.elevation() + 1, ELEVATION)); - } - result.addAll(wigeOptions); - } // Bridges block deployment for units of more than 1 level height if they intersect; height() == 0 is 1 level if (hex.containsTerrain(Terrains.BRIDGE) && (entity.height() > 0)) { @@ -160,8 +174,18 @@ private List findAllowedVTOLElevations() { return result; } + /** + * @return True if the given options contain at least one with elevation 0. + */ private boolean hasZeroElevationOption(List options) { - return options.stream().anyMatch(o -> o.elevation() == 0); + return hasElevationOption(options, 0); + } + + /** + * @return True if the given options contain at least one of the given elevation. + */ + private boolean hasElevationOption(List options, int elevation) { + return options.stream().anyMatch(o -> o.elevation() == elevation); } private List findAllowedElevationsWithBuildings() {