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

Fix wige deployment options #6031

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
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