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

Fixes #5053 Update Aero movement envelope when accelerating or decelerating. #5054

Merged
merged 3 commits into from
Jan 17, 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
48 changes: 46 additions & 2 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ public boolean shouldPerformAction() {
@Override
public void performAction() {
removeLastStep();
computeMovementEnvelope(ce());
if (ce() instanceof Aero) {
computeAeroMovementEnvelope(ce());
} else {
computeMovementEnvelope(ce());
}
}
});

Expand All @@ -492,7 +496,11 @@ public boolean shouldPerformAction() {
@Override
public void performAction() {
removeIllegalSteps();
computeMovementEnvelope(ce());
if (ce() instanceof Aero) {
computeAeroMovementEnvelope(ce());
} else {
computeMovementEnvelope(ce());
}
}
});

Expand Down Expand Up @@ -4542,6 +4550,40 @@ public void computeMovementEnvelope(Entity suggestion) {
.getRunMP(), en.getJumpMP(), mvMode);
}

/**
* Computes possible moves for entities of Aero units. This is similar to the
* `computeMovementEnvelope()` method; however, it uses the `MovePath`
* final velocity to temporarily set units velocity to draw the move envelope.
* This method always sets the original entity velocity back to it's orginial.
*
* @param entity - Suggested entity to use to compute Aero move envelope.
* @return - This method will do nothing if the Entity passed in is null or
* is not an Aero based unity.
*/
private void computeAeroMovementEnvelope(Entity entity) {
if ((entity == null) || !(entity instanceof Aero) || (cmd == null)) {
return;
}

// Increment the entity's delta-v then compute the movement envelope.
Aero ae = (Aero)entity;
int currentVelocity = ae.getCurrentVelocity();
ae.setCurrentVelocity(cmd.getFinalVelocity());

// Refresh the new velocity envelope on the map.
try {
computeMovementEnvelope(ae);
} catch (Exception e) {
LogManager.getLogger().error("An error occured trying to compute the move envelope for an Aero.");
} finally {
// Reset the bird's velocity back to original velocity no-matter-what. It will be updated when
// the 'move' button is clicked and the move is processed.
ae.setCurrentVelocity(currentVelocity);
}

return;
}

public void computeModifierEnvelope() {
if (ce() == null) {
return;
Expand Down Expand Up @@ -5061,8 +5103,10 @@ public synchronized void actionPerformed(ActionEvent ev) {
addStepToMovePath(MoveStepType.DECN);
} else if (actionCmd.equals(MoveCommand.MOVE_ACC.getCmd())) {
addStepToMovePath(MoveStepType.ACC);
computeAeroMovementEnvelope(ce);
} else if (actionCmd.equals(MoveCommand.MOVE_DEC.getCmd())) {
addStepToMovePath(MoveStepType.DEC);
computeAeroMovementEnvelope(ce);
} else if (actionCmd.equals(MoveCommand.MOVE_EVADE.getCmd())) {
addStepToMovePath(MoveStepType.EVADE);
} else if (actionCmd.equals(MoveCommand.MOVE_BOOTLEGGER.getCmd())) {
Expand Down
Loading