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 4830 wige jumps to bottom of water hex #4835

Merged
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
28 changes: 14 additions & 14 deletions megamek/src/megamek/client/ui/SharedUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static Object getAeroSpecificPSRList(MovePath md, boolean stringResult)
// iterate through steps
for (final Enumeration<MoveStep> i = md.getSteps(); i.hasMoreElements();) {
final MoveStep step = i.nextElement();

// stop for illegal movement
if (step.getMovementType(md.isEndStep(step)) == EntityMovementType.MOVE_ILLEGAL) {
break;
Expand Down Expand Up @@ -103,15 +103,15 @@ private static Object getAeroSpecificPSRList(MovePath md, boolean stringResult)
step.getVelocity(), curPos, curFacing, false);
checkNag(rollTarget, nagReport, psrList);
}

if (step.getType() == MoveStepType.VLAND) {
rollTarget = ((IAero) entity).checkLanding(moveType,
step.getVelocity(), curPos, curFacing, true);
checkNag(rollTarget, nagReport, psrList);
}

// Check for Ejecting
if (step.getType() == MoveStepType.EJECT
if (step.getType() == MoveStepType.EJECT
&& (entity.isFighter())) {
rollTarget = GameManager.getEjectModifiers(game, entity, 0, false);
checkNag(rollTarget, nagReport, psrList);
Expand Down Expand Up @@ -150,7 +150,7 @@ private static Object getAeroSpecificPSRList(MovePath md, boolean stringResult)
}
return psrList;
}

/**
* Checks to see if piloting skill rolls are needed for the currently
* selected movement. This code is basically a simplified version of
Expand Down Expand Up @@ -387,10 +387,10 @@ private static Object doPSRCheck(MovePath md, boolean stringResult) {
}
}
}

// Sheer Cliffs, TO p.39
// Roads over cliffs cancel the cliff effects for units that move on roads
boolean vehicleAffectedByCliff = entity instanceof Tank
boolean vehicleAffectedByCliff = entity instanceof Tank
&& !entity.isAirborneVTOLorWIGE();
boolean quadveeVehMode = entity instanceof QuadVee
&& entity.getConversionMode() == QuadVee.CONV_MODE_VEHICLE;
Expand All @@ -399,12 +399,12 @@ private static Object doPSRCheck(MovePath md, boolean stringResult) {
&& !entity.isAero();
// Cliffs should only exist towards 1 or 2 level drops, check just to make sure
// Everything that does not have a 1 or 2 level drop shouldn't be handled as a cliff
int stepHeight = curElevation + curHex.getLevel()
int stepHeight = curElevation + curHex.getLevel()
- (lastElevation + prevHex.getLevel());
boolean isUpCliff = !lastPos.equals(curPos)
boolean isUpCliff = !lastPos.equals(curPos)
&& curHex.hasCliffTopTowards(prevHex)
&& (stepHeight == 1 || stepHeight == 2);
boolean isDownCliff = !lastPos.equals(curPos)
boolean isDownCliff = !lastPos.equals(curPos)
&& prevHex.hasCliffTopTowards(curHex)
&& (stepHeight == -1 || stepHeight == -2);

Expand Down Expand Up @@ -492,13 +492,13 @@ private static Object doPSRCheck(MovePath md, boolean stringResult) {
checkNag(rollTarget, nagReport, psrList);
}
}

if (step.isTurning()) {
rollTarget = entity.checkTurnModeFailure(overallMoveType,
prevStep == null? 0 : prevStep.getNStraight(), md.getMpUsed(), curPos);
checkNag(rollTarget, nagReport, psrList);
}

if (step.getType() == MoveStepType.BOOTLEGGER) {
rollTarget = entity.getBasePilotingRoll(overallMoveType);
entity.addPilotingModifierForTerrain(rollTarget);
Expand Down Expand Up @@ -531,7 +531,7 @@ private static Object doPSRCheck(MovePath md, boolean stringResult) {

rollTarget = entity.checkUsingOverdrive(overallMoveType);
checkNag(rollTarget, nagReport, psrList);

rollTarget = entity.checkGunningIt(overallMoveType);
checkNag(rollTarget, nagReport, psrList);

Expand All @@ -557,7 +557,7 @@ private static Object doPSRCheck(MovePath md, boolean stringResult) {
nagReport.append(Messages.getString("MovementDisplay.IceLanding"));
}
} else if (!(prevStep.climbMode() && hex.containsTerrain(Terrains.BRIDGE))) {
if (!entity.getMovementMode().isHover()) {
if (!entity.getMovementMode().isHoverOrWiGE()) {
rollTarget = entity.checkWaterMove(waterLevel, overallMoveType);
checkNag(rollTarget, nagReport, psrList);
}
Expand Down Expand Up @@ -822,7 +822,7 @@ private static MovePath addSteps(MovePath md, Client client) {
for (Entity ent : game.getEntitiesVector(left)) {
leftTonnage += ent.getWeight();
}

double rightTonnage = 0;
for (Entity ent : game.getEntitiesVector(right)) {
rightTonnage += ent.getWeight();
Expand Down
14 changes: 9 additions & 5 deletions megamek/src/megamek/common/MovePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ public boolean willCrushBuildings() {

/**
* Airborne WiGEs that move less than five hexes (four for glider protomech) in a movement phase must
* land unless it has taken off in the same phase or it is a LAM or glider ProtoMech that is using hover
* land unless it has taken off in the same phase, jumped, or it is a LAM or glider ProtoMech that is using hover
* movement.
*
* @param includeMovePathHexes Whether to include the hexes plotted in this MovePath in the total distance
Expand All @@ -1640,6 +1640,10 @@ public boolean automaticWiGELanding(boolean includeMovePathHexes) {
return getEntity().isAirborneVTOLorWIGE();
}
}
// A WiGE that jumped A) has to have been flying and B) cannot land this turn.
if (isJumping()) {
return false;
}
// If movement has been interrupted (such as by a sideslip) and remaining movement points have
// been spent, this MovePath only contains the hexes moved after the interruption. The hexes already
// moved this turn are in delta_distance. WHen the server checks at the end of movement, delta_distance
Expand Down Expand Up @@ -1854,23 +1858,23 @@ public boolean nextForwardStepOffBoard() {
}

/**
* Worker function that counts the number of steps of the given type
* Worker function that counts the number of steps of the given type
* at the end of the given path before another step type occurs.
*/
public int getEndStepCount(MoveStepType stepType) {
int stepCount = 0;

for (int index = getStepVector().size() - 1; index >= 0; index--) {
if (getStepVector().get(index).getType() == stepType) {
stepCount++;
} else {
break;
}
}

return stepCount;
}

/**
* Debugging method that calculates a destruction-aware move path to the destination coordinates
*/
Expand Down
28 changes: 22 additions & 6 deletions megamek/src/megamek/common/MoveStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,21 @@ private void compileMove(final Game game, final Entity entity,
.getBoard().getHex(entity.getPosition()).getLevel()) - hex.getLevel();
int building = hex.terrainLevel(Terrains.BLDG_ELEV);
int depth = -hex.depth(true);
// need to adjust depth for potential ice over water
if ((hex.containsTerrain(Terrains.ICE) && hex
.containsTerrain(Terrains.WATER))
|| (entity.getMovementMode() == EntityMovementMode.HOVER)) {
depth = 0;

// Set depth to 0 (surface level) in several cases:
// 1. Jumping onto ice-covered water hex,
// 2. Jumping onto water with Hover move mode,
// 3. Jumping onto water with WiGE move mode
if (hex.containsTerrain(Terrains.WATER)) {
if (
hex.containsTerrain(Terrains.ICE) ||
entity.getMovementMode() == EntityMovementMode.HOVER ||
entity.getMovementMode() == EntityMovementMode.WIGE
) {
depth = 0;
}
}

// grounded DropShips are treated as level 10 buildings for purposes
// of jumping over
boolean grdDropship = false;
Expand All @@ -582,7 +591,14 @@ private void compileMove(final Game game, final Entity entity,
// infantry can jump into a building
setElevation(Math.max(depth, Math.min(building, maxElevation)));
} else {
setElevation(Math.max(depth, building));
int subDepth = Math.max(depth, building);
// Put jumping Hover or WiGE at their elevation above the substrate level,
// or they get implicitly landed (which affects their movement next turn)
if (entity.getMovementMode().isHoverOrWiGE()) {
setElevation(elevation + subDepth);
} else {
setElevation(subDepth);
}
}
if (climbMode()
&& (maxElevation >= hex.terrainLevel(Terrains.BRIDGE_ELEV))) {
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/server/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8747,7 +8747,7 @@ else if ((step.getElevation() + entity.height()) == 0) {
}
}
} else if (!(prevStep.climbMode() && curHex.containsTerrain(Terrains.BRIDGE))
&& !(entity.getMovementMode() == EntityMovementMode.HOVER)) {
&& !(entity.getMovementMode().isHoverOrWiGE())) {
rollTarget = entity.checkWaterMove(waterLevel, overallMoveType);
if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {
// For falling elevation, Entity must not on hex surface
Expand Down