Skip to content

Commit

Permalink
Merge pull request #6379 from kuronekochomusuke/issue_6368
Browse files Browse the repository at this point in the history
allow princess to flee at end of movement
  • Loading branch information
Sleet01 authored Jan 9, 2025
2 parents 284e2e4 + 32394fc commit 5a9fd64
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
8 changes: 8 additions & 0 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,14 @@ private MovePath performPathPostProcessing(MovePath path, double expectedDamage)
retVal = SharedUtility.moveAero(retVal, null);
}

// allow fleeing at end of movement if is falling back and can flee from position
if ((isFallingBack(path.getEntity()))
&& (path.getLastStep() != null)
&& (getGame().canFleeFrom(path.getEntity(), path.getLastStep().getPosition()))
&& (path.getMpUsed() < path.getMaxMP())) {
path.addStep(MoveStepType.FLEE);
}

return retVal;
}

Expand Down
14 changes: 3 additions & 11 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -975,20 +975,12 @@ private void updateMove(boolean redrawMovement) {
}

private void updateFleeButton() {
int maxMP = maxMP(ce(), gear);

boolean hasLastStep = (cmd != null) && (cmd.getLastStep() != null);
boolean fleeStart = ce().canFlee(ce().getPosition());
boolean jumpMoveRemaining = hasLastStep
&& cmd.getLastStep().isJumping()
&& (cmd.getMpUsed() < ce().getJumpMP());
boolean runMoveRemaining = hasLastStep
&& !cmd.getLastStep().isJumping()
&& (cmd.getMpUsed() < maxMP);
boolean moveRemaining = jumpMoveRemaining || runMoveRemaining;
boolean fleeStart = !hasLastStep &&
ce().canFlee(ce().getPosition());
boolean fleeEnd = hasLastStep
&& (cmd.getMpUsed() < cmd.getMaxMP())
&& (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL)
&& moveRemaining
&& clientgui.getClient().getGame().canFleeFrom(ce(), cmd.getLastStep().getPosition());

setFleeEnabled(fleeStart || fleeEnd);
Expand Down
24 changes: 24 additions & 0 deletions megamek/src/megamek/common/MovePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -2003,4 +2003,28 @@ public MovePath calculateDestructionAwarePath(Coords dest) {

return finPath;
}

/**
*
* @return maximum movement based on the current movement type
* include sprint if available
*/
public int getMaxMP() {
int maxMP;

if (contains(MoveStepType.START_JUMP) || contains(MoveStepType.DFA)) {
maxMP = getEntity().getJumpMP();
} else if (contains(MoveStepType.BACKWARDS)) {
maxMP = getEntity().getWalkMP();
} else {
if ((getLastStep() != null) &&
getLastStep().canUseSprint(game)) {
maxMP = getEntity().getSprintMP();
} else {
maxMP = getEntity().getRunMP();
}
}

return maxMP;
}
}

0 comments on commit 5a9fd64

Please sign in to comment.