Skip to content

Commit

Permalink
fix wige deployment options
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Sep 22, 2024
1 parent 5b011f9 commit afa153a
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions megamek/src/megamek/common/AllowedDeploymentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,32 @@ public List<ElevationOption> 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<ElevationOption> result) {
// WiGE may also deploy flying wherever they can be grounded
List<ElevationOption> 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<ElevationOption> allowedAeroAltitudes() {
List<ElevationOption> result = new ArrayList<>();
if (board.onGround()) {
Expand All @@ -78,14 +100,6 @@ private List<ElevationOption> allowedGroundElevations() {
if (!hasZeroElevationOption(result)) {
result.addAll(allowedZeroElevation());
}
if (entity.getMovementMode().isWiGE()) {
// WiGE may also deploy flying wherever they can be grounded
List<ElevationOption> 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)) {
Expand Down Expand Up @@ -160,8 +174,18 @@ private List<ElevationOption> findAllowedVTOLElevations() {
return result;
}

/**
* @return True if the given options contain at least one with elevation 0.
*/
private boolean hasZeroElevationOption(List<ElevationOption> 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<ElevationOption> options, int elevation) {
return options.stream().anyMatch(o -> o.elevation() == elevation);
}

private List<ElevationOption> findAllowedElevationsWithBuildings() {
Expand Down

0 comments on commit afa153a

Please sign in to comment.