Skip to content

Commit

Permalink
Merge pull request #933 from NickAragua/fully_amphibious_water_travel…
Browse files Browse the repository at this point in the history
…_fix

Fully amphibious water travel fix
  • Loading branch information
Dylan-M authored Mar 13, 2018
2 parents 4df25f2 + 5960613 commit bfbf7f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
11 changes: 7 additions & 4 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1849,10 +1849,13 @@ public int calcElevation(IHex current, IHex next, int assumedElevation,
retVal += current.surface();
retVal -= next.surface();
} else {
// if we're a hovercraft, surface ship, WIGE or a "fully amphibious" vehicle, we go on the water surface
// without adjusting elevation
if ((getMovementMode() != EntityMovementMode.HOVER)
&& (getMovementMode() != EntityMovementMode.NAVAL)
&& (getMovementMode() != EntityMovementMode.HYDROFOIL)
&& (getMovementMode() != EntityMovementMode.WIGE)) {
&& (getMovementMode() != EntityMovementMode.WIGE)
&& !hasWorkingMisc(MiscType.F_FULLY_AMPHIBIOUS)) {
int prevWaterLevel = 0;
if (current.containsTerrain(Terrains.WATER)) {
prevWaterLevel = current.terrainLevel(Terrains.WATER);
Expand Down Expand Up @@ -2186,9 +2189,9 @@ && getMovementMode() == EntityMovementMode.INF_UMU) {
} else {
// regular ground units
if (hex.containsTerrain(Terrains.ICE)
|| ((getMovementMode() == EntityMovementMode.HOVER) && hex
.containsTerrain(Terrains.WATER))) {
// surface of ice is OK, surface of water is OK for hovers
|| (((getMovementMode() == EntityMovementMode.HOVER) || hasWorkingMisc(MiscType.F_FULLY_AMPHIBIOUS)) &&
hex.containsTerrain(Terrains.WATER))) {
// surface of ice is OK, surface of water is OK for hovers and "fully amphibious" units
if (assumedAlt == hex.surface()) {
return true;
}
Expand Down
15 changes: 12 additions & 3 deletions megamek/src/megamek/common/MoveStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ private void compileMove(final IGame game, final Entity entity,
&& (entity.getMovementMode() != EntityMovementMode.INF_UMU)
&& (entity.getMovementMode() != EntityMovementMode.SUBMARINE)
&& (entity.getMovementMode() != EntityMovementMode.VTOL)
&& (entity.getMovementMode() != EntityMovementMode.WIGE)) {
&& (entity.getMovementMode() != EntityMovementMode.WIGE)
&& !entity.hasWorkingMisc(MiscType.F_FULLY_AMPHIBIOUS)) {
setRunProhibited(true);
}
if (entity.getMovedBackwards()
Expand Down Expand Up @@ -2846,6 +2847,8 @@ protected void calcMovementCostFor(IGame game, MoveStep prevStep) {
&& ((Infantry) getEntity()).isMechanized();
final boolean isProto = getEntity() instanceof Protomech;
final boolean isMech = getEntity() instanceof Mech;
final boolean isAmphibious = getEntity().hasWorkingMisc(MiscType.F_FULLY_AMPHIBIOUS) ||
getEntity().hasWorkingMisc(MiscType.F_LIMITED_AMPHIBIOUS);
int nSrcEl = srcHex.getLevel() + prevEl;
int nDestEl = destHex.getLevel() + elevation;

Expand Down Expand Up @@ -2915,6 +2918,11 @@ && getClearance() == 0) {
mp += destHex.movementCost(getEntity());
}

// if this is an amphibious unit crossing water, increment movement cost by 1
if(isAmphibious && !destHex.containsTerrain(Terrains.ICE) && (destHex.terrainLevel(Terrains.WATER) > 0)) {
mp++;
}

// non-hovers, non-navals and non-VTOLs check for water depth and
// are affected by swamp
if ((moveMode != EntityMovementMode.HOVER)
Expand All @@ -2929,9 +2937,9 @@ && getClearance() == 0) {
// no additional cost when moving on surface of ice.
if (!destHex.containsTerrain(Terrains.ICE)
|| (nDestEl < destHex.surface())) {
if (destHex.terrainLevel(Terrains.WATER) == 1) {
if ((destHex.terrainLevel(Terrains.WATER) == 1) && !isAmphibious) {
mp++;
} else if (destHex.terrainLevel(Terrains.WATER) > 1) {
} else if ((destHex.terrainLevel(Terrains.WATER) > 1) && !isAmphibious) {
if (getEntity().getCrew().getOptions().booleanOption(OptionsConstants.PILOT_TM_FROGMAN)
&& ((entity instanceof Mech) || (entity instanceof Protomech))) {
mp += 2;
Expand Down Expand Up @@ -3297,6 +3305,7 @@ && isThisStepBackwards()
&& (nMove != EntityMovementMode.INF_UMU)
&& (nMove != EntityMovementMode.VTOL)
&& (nMove != EntityMovementMode.WIGE)
&& !entity.hasWorkingMisc(MiscType.F_FULLY_AMPHIBIOUS)
&& (destHex.terrainLevel(Terrains.WATER) > 0)
&& !(destHex.containsTerrain(Terrains.ICE) && (elevation >= 0))
&& !dest.equals(entity.getPosition())
Expand Down
3 changes: 2 additions & 1 deletion megamek/src/megamek/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -32687,7 +32687,8 @@ public boolean checkForCollapse(Building bldg,
if ((entity.getMovementMode() == EntityMovementMode.HYDROFOIL)
|| (entity.getMovementMode() == EntityMovementMode.NAVAL)
|| (entity.getMovementMode() == EntityMovementMode.SUBMARINE)
|| (entity.getMovementMode() == EntityMovementMode.INF_UMU)) {
|| (entity.getMovementMode() == EntityMovementMode.INF_UMU)
|| entity.hasWorkingMisc(MiscType.F_FULLY_AMPHIBIOUS)) {
continue; // under the bridge even at same level
}

Expand Down

0 comments on commit bfbf7f4

Please sign in to comment.