Skip to content

Commit

Permalink
Merge pull request MegaMek#4820 from MegaMek/aero_maneuver_facing_change
Browse files Browse the repository at this point in the history
Fix Immelman and Split-S maneuvers
  • Loading branch information
HammerGS authored Oct 9, 2023
2 parents 93de159 + 02622eb commit f6676e3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
7 changes: 2 additions & 5 deletions megamek/src/megamek/client/commands/MoveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

import megamek.client.Client;
import megamek.client.ui.swing.MovementDisplay;
import megamek.common.Coords;
import megamek.common.Entity;
import megamek.common.EntityMovementMode;
import megamek.common.MovePath;
import megamek.common.*;
import megamek.common.MovePath.MoveStepType;
import megamek.common.options.OptionsConstants;

Expand Down Expand Up @@ -164,7 +161,7 @@ public String run(String[] args) {
private void currentMove(Coords dest) {
if (dest != null) {
if (gear == GEAR_TURN) {
cmd.rotatePathfinder(cmd.getFinalCoords().direction(dest), false);
cmd.rotatePathfinder(cmd.getFinalCoords().direction(dest), false, ManeuverType.MAN_NONE);
} else if (gear == GEAR_LAND || gear == GEAR_JUMP) {
cmd.findPathTo(dest, MoveStepType.FORWARDS);
} else if (gear == GEAR_BACKUP) {
Expand Down
40 changes: 20 additions & 20 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -987,14 +987,14 @@ private void addStepToMovePath(MoveStepType moveStep, boolean noCost) {
updateMove();
}

private void addStepToMovePath(MoveStepType moveStep, boolean noCost, boolean isManeuver) {
cmd.addStep(moveStep, noCost, isManeuver);
private void addStepToMovePath(MoveStepType moveStep, boolean noCost, boolean isManeuver, int maneuverType) {
cmd.addStep(moveStep, noCost, isManeuver, maneuverType);
updateMove();
}

private void addStepsToMovePath(boolean noCost, boolean isManeuver, MoveStepType ... moveSteps) {
private void addStepsToMovePath(boolean noCost, boolean isManeuver, int maneuverType, MoveStepType ... moveSteps) {
for (MoveStepType moveStep : moveSteps) {
cmd.addStep(moveStep, noCost, isManeuver);
cmd.addStep(moveStep, noCost, isManeuver, maneuverType);
}
updateMove();
}
Expand Down Expand Up @@ -1747,7 +1747,7 @@ private synchronized Entity ce() {
*/
private void currentMove(Coords dest) {
if (shiftheld || (gear == GEAR_TURN)) {
cmd.rotatePathfinder(cmd.getFinalCoords().direction(dest), false);
cmd.rotatePathfinder(cmd.getFinalCoords().direction(dest), false, ManeuverType.MAN_NONE);
} else if ((gear == GEAR_JUMP)
&& (ce().getJumpType() == Mech.JUMP_BOOSTER)) {
// Jumps with mechanical jump boosters are special
Expand Down Expand Up @@ -1836,19 +1836,19 @@ private void currentMove(Coords dest) {
} else if (gear == GEAR_RAM) {
cmd.findPathTo(dest, MoveStepType.FORWARDS);
} else if (gear == GEAR_IMMEL) {
addStepsToMovePath(true, true,
addStepsToMovePath(true, true, ManeuverType.MAN_IMMELMAN,
MoveStepType.UP,
MoveStepType.UP,
MoveStepType.DEC,
MoveStepType.DEC);
cmd.rotatePathfinder(cmd.getFinalCoords().direction(dest), true);
cmd.rotatePathfinder(cmd.getFinalCoords().direction(dest), true, ManeuverType.MAN_IMMELMAN);
gear = GEAR_LAND;
} else if (gear == GEAR_SPLIT_S) {
addStepsToMovePath(true, true,
addStepsToMovePath(true, true, ManeuverType.MAN_SPLIT_S,
MoveStepType.DOWN,
MoveStepType.DOWN,
MoveStepType.ACC);
cmd.rotatePathfinder(cmd.getFinalCoords().direction(dest), true);
cmd.rotatePathfinder(cmd.getFinalCoords().direction(dest), true, ManeuverType.MAN_SPLIT_S);
gear = GEAR_LAND;
}
if (gear == GEAR_LONGEST_WALK || gear == GEAR_LONGEST_RUN) {
Expand Down Expand Up @@ -4244,13 +4244,13 @@ private boolean addManeuver(int type) {
cmd.addManeuver(type);
switch (type) {
case ManeuverType.MAN_HAMMERHEAD:
addStepToMovePath(MoveStepType.YAW, true, true);
addStepToMovePath(MoveStepType.YAW, true, true, type);
return true;
case ManeuverType.MAN_HALF_ROLL:
addStepToMovePath(MoveStepType.ROLL, true, true);
addStepToMovePath(MoveStepType.ROLL, true, true, type);
return true;
case ManeuverType.MAN_BARREL_ROLL:
addStepToMovePath(MoveStepType.DEC, true, true);
addStepToMovePath(MoveStepType.DEC, true, true, type);
return true;
case ManeuverType.MAN_IMMELMAN:
gear = MovementDisplay.GEAR_IMMEL;
Expand All @@ -4269,7 +4269,7 @@ private boolean addManeuver(int type) {
vel = last.getVelocityLeft();
}
while (vel > 0) {
addStepToMovePath(MoveStepType.DEC, true, true);
addStepToMovePath(MoveStepType.DEC, true, true, type);
vel--;
}
addStepToMovePath(MoveStepType.UP);
Expand All @@ -4279,31 +4279,31 @@ private boolean addManeuver(int type) {
// See Total Warfare pg 85
if (clientgui.getClient().getGame().getBoard().getType() == Board.T_GROUND) {
for (int i = 0; i < 8; i++) {
addStepToMovePath(MoveStepType.LATERAL_LEFT, true, true);
addStepToMovePath(MoveStepType.LATERAL_LEFT, true, true, type);
}
for (int i = 0; i < 8; i++) {
addStepToMovePath(MoveStepType.FORWARDS, true, true);
addStepToMovePath(MoveStepType.FORWARDS, true, true, type);
}
} else {
addStepToMovePath(MoveStepType.LATERAL_LEFT, true, true);
addStepToMovePath(MoveStepType.LATERAL_LEFT, true, true, type);
}
return true;
case ManeuverType.MAN_SIDE_SLIP_RIGHT:
// If we are on a ground map, slide slip works slightly differently
// See Total Warfare pg 85
if (clientgui.getClient().getGame().getBoard().getType() == Board.T_GROUND) {
for (int i = 0; i < 8; i++) {
addStepToMovePath(MoveStepType.LATERAL_RIGHT, true, true);
addStepToMovePath(MoveStepType.LATERAL_RIGHT, true, true, type);
}
for (int i = 0; i < 8; i++) {
addStepToMovePath(MoveStepType.FORWARDS, true, true);
addStepToMovePath(MoveStepType.FORWARDS, true, true, type);
}
} else {
addStepToMovePath(MoveStepType.LATERAL_RIGHT, true, true);
addStepToMovePath(MoveStepType.LATERAL_RIGHT, true, true, type);
}
return true;
case ManeuverType.MAN_LOOP:
addStepToMovePath(MoveStepType.LOOP, true, true);
addStepToMovePath(MoveStepType.LOOP, true, true, type);
return true;
default:
return false;
Expand Down
6 changes: 3 additions & 3 deletions megamek/src/megamek/common/ManeuverType.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public static boolean canPerform(int type, int velocity, int altitude,
MovePath tmpMp = mp.clone();
for (int i = 0; i < 8; i++) {
if (type == MAN_SIDE_SLIP_LEFT) {
tmpMp.addStep(MoveStepType.LATERAL_LEFT, true, true);
tmpMp.addStep(MoveStepType.LATERAL_LEFT, true, true, type);
} else {
tmpMp.addStep(MoveStepType.LATERAL_RIGHT, true, true);
tmpMp.addStep(MoveStepType.LATERAL_RIGHT, true, true, type);
}
}
for (int i = 0; i < 8; i++) {
tmpMp.addStep(MoveStepType.FORWARDS, true, true);
tmpMp.addStep(MoveStepType.FORWARDS, true, true, type);
}
return tmpMp.getLastStep().isLegal(tmpMp);
} else {
Expand Down
17 changes: 9 additions & 8 deletions megamek/src/megamek/common/MovePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ public MovePath addStep(final MoveStepType type, final boolean noCost) {
return addStep(new MoveStep(this, type, noCost));
}

public MovePath addStep(final MoveStepType type, final boolean noCost, final boolean isManeuver) {
return addStep(new MoveStep(this, type, noCost, isManeuver));
public MovePath addStep(final MoveStepType type, final boolean noCost, final boolean isManeuver, final int maneuverType) {
return addStep(new MoveStep(this, type, noCost, isManeuver, maneuverType));
}

public MovePath addStep(final MoveStepType type, final Minefield mf) {
Expand Down Expand Up @@ -567,10 +567,10 @@ public void compile(final Game g, final Entity en, boolean clip) {
step = new MoveStep(this, step.getType(), step.getBraceLocation());
} else if (!step.getLaunched().isEmpty()) {
step = new MoveStep(this, step.getType(), step.getLaunched());
} else if (step.isManeuver()) {
step = new MoveStep(this, step.getType(), step.hasNoCost(), step.isManeuver(), step.getManeuverType());
} else if (step.getManeuverType() != ManeuverType.MAN_NONE) {
step = new MoveStep(this, step.getType(), -1, -1, step.getManeuverType());
} else if (step.isManeuver()) {
step = new MoveStep(this, step.getType(), step.hasNoCost(), step.isManeuver());
} else if (step.hasNoCost()) {
step = new MoveStep(this, step.getType(), step.hasNoCost());
} else if (null != step.getMinefield()) {
Expand Down Expand Up @@ -1440,11 +1440,12 @@ private void lazyPathfinder(final Coords dest, final MoveStepType type) {
while (!getFinalCoords().equals(subDest)) {
// adjust facing
rotatePathfinder((getFinalCoords().direction(subDest) + (step == MoveStepType.BACKWARDS ? 3 : 0)) % 6,
false);
false, ManeuverType.MAN_NONE);
// step forwards
addStep(step);
}
rotatePathfinder((getFinalCoords().direction(dest) + (step == MoveStepType.BACKWARDS ? 3 : 0)) % 6, false);
rotatePathfinder((getFinalCoords().direction(dest) + (step == MoveStepType.BACKWARDS ? 3 : 0)) % 6,
false, ManeuverType.MAN_NONE);
if (!dest.equals(getFinalCoords())) {
addStep(type);
}
Expand Down Expand Up @@ -1553,10 +1554,10 @@ protected void copyFields(MovePath copy) {
/**
* Rotate from the current facing to the destination facing.
*/
public void rotatePathfinder(final int destFacing, final boolean isManeuver) {
public void rotatePathfinder(final int destFacing, final boolean isManeuver, int maneuverType) {
while (getFinalFacing() != destFacing) {
final MoveStepType stepType = getDirection(getFinalFacing(), destFacing);
addStep(stepType, isManeuver, isManeuver);
addStep(stepType, isManeuver, isManeuver, maneuverType);
}
}

Expand Down
3 changes: 2 additions & 1 deletion megamek/src/megamek/common/MoveStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,11 @@ public MoveStep(MovePath path, MoveStepType type, boolean noCost) {
}

public MoveStep(MovePath path, MoveStepType type, boolean noCost,
boolean isManeuver) {
boolean isManeuver, int maneuverType) {
this(path, type);
this.noCost = noCost;
maneuver = isManeuver;
this.maneuverType = maneuverType;
}

public MoveStep(MovePath path, MoveStepType type, int recovery,
Expand Down

0 comments on commit f6676e3

Please sign in to comment.