Skip to content

Commit

Permalink
Merge pull request MegaMek#5864 from Sleet01/Tweak_Princess_Gravity_P…
Browse files Browse the repository at this point in the history
…SR_handling

Tweak princess gravity PSR handling
  • Loading branch information
Sleet01 authored Aug 8, 2024
2 parents 197d704 + 8bab678 commit d33a276
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 120 deletions.
84 changes: 42 additions & 42 deletions megamek/src/megamek/client/ui/SharedUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,50 +344,50 @@ private static Object doPSRCheck(MovePath md, boolean stringResult) {
rollTarget = entity.checkBogDown(step, overallMoveType, curHex,
lastPos, curPos, lastElevation, isPavementStep);
checkNag(rollTarget, nagReport, psrList);
}

// Check if used more MPs than Mech/Vehicle would have w/o gravity
if (!i.hasMoreElements() && !firstStep) {
if ((entity instanceof Mech) || (entity instanceof Tank)) {
if ((moveType == EntityMovementType.MOVE_WALK)
|| (moveType == EntityMovementType.MOVE_VTOL_WALK)
|| (moveType == EntityMovementType.MOVE_RUN)
|| (moveType == EntityMovementType.MOVE_VTOL_RUN)
|| (moveType == EntityMovementType.MOVE_SPRINT)
|| (moveType == EntityMovementType.MOVE_VTOL_SPRINT)) {
int limit = entity.getRunningGravityLimit();
if (step.isOnlyPavement() && entity.isEligibleForPavementBonus()) {
limit++;
}
if (step.getMpUsed() > limit) {
rollTarget = entity.checkMovedTooFast(step, overallMoveType);
checkNag(rollTarget, nagReport, psrList);
}
} else if (moveType == EntityMovementType.MOVE_JUMP) {
int origWalkMP = entity.getWalkMP(MPCalculationSetting.NO_GRAVITY);
int gravWalkMP = entity.getWalkMP();
if (step.getMpUsed() > entity.getJumpMP(MPCalculationSetting.NO_GRAVITY)) {
rollTarget = entity.checkMovedTooFast(step, overallMoveType);
checkNag(rollTarget, nagReport, psrList);
} else if ((game.getPlanetaryConditions().getGravity() > 1)
&& ((origWalkMP - gravWalkMP) > 0)) {
rollTarget = entity.getBasePilotingRoll(md.getLastStepMovementType());
entity.addPilotingModifierForTerrain(rollTarget, step);
int gravMod = game.getPlanetaryConditions()
.getGravityPilotPenalty();
if ((gravMod != 0) && !game.getBoard().inSpace()) {
rollTarget.addModifier(gravMod, game
.getPlanetaryConditions().getGravity()
+ "G gravity");
}
rollTarget.append(new PilotingRollData(entity
.getId(), 0, "jumped in high gravity"));
SharedUtility.checkNag(rollTarget, nagReport,
psrList);
}
if (step.getMpUsed() > entity.getSprintMP(MPCalculationSetting.NO_GRAVITY)) {
rollTarget = entity.checkMovedTooFast(step, overallMoveType);
checkNag(rollTarget, nagReport, psrList);
// Check if used more MPs than Mech/Vehicle would have w/o gravity
if (!i.hasMoreElements() && !firstStep) {
if ((entity instanceof Mech) || (entity instanceof Tank)) {
if ((moveType == EntityMovementType.MOVE_WALK)
|| (moveType == EntityMovementType.MOVE_VTOL_WALK)
|| (moveType == EntityMovementType.MOVE_RUN)
|| (moveType == EntityMovementType.MOVE_VTOL_RUN)
|| (moveType == EntityMovementType.MOVE_SPRINT)
|| (moveType == EntityMovementType.MOVE_VTOL_SPRINT)) {
int limit = entity.getRunningGravityLimit();
if (step.isOnlyPavement() && entity.isEligibleForPavementBonus()) {
limit++;
}
if (step.getMpUsed() > limit) {
rollTarget = entity.checkMovedTooFast(step, overallMoveType);
checkNag(rollTarget, nagReport, psrList);
}
} else if (moveType == EntityMovementType.MOVE_JUMP) {
int origWalkMP = entity.getWalkMP(MPCalculationSetting.NO_GRAVITY);
int gravWalkMP = entity.getWalkMP();
if (step.getMpUsed() > entity.getJumpMP(MPCalculationSetting.NO_GRAVITY)) {
rollTarget = entity.checkMovedTooFast(step, overallMoveType);
checkNag(rollTarget, nagReport, psrList);
} else if ((game.getPlanetaryConditions().getGravity() > 1)
&& ((origWalkMP - gravWalkMP) > 0)) {
rollTarget = entity.getBasePilotingRoll(md.getLastStepMovementType());
entity.addPilotingModifierForTerrain(rollTarget, step);
int gravMod = game.getPlanetaryConditions()
.getGravityPilotPenalty();
if ((gravMod != 0) && !game.getBoard().inSpace()) {
rollTarget.addModifier(gravMod, game
.getPlanetaryConditions().getGravity()
+ "G gravity");
}
rollTarget.append(new PilotingRollData(entity
.getId(), 0, "jumped in high gravity"));
SharedUtility.checkNag(rollTarget, nagReport,
psrList);
}
if (step.getMpUsed() > entity.getSprintMP(MPCalculationSetting.NO_GRAVITY)) {
rollTarget = entity.checkMovedTooFast(step, overallMoveType);
checkNag(rollTarget, nagReport, psrList);
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions megamek/src/megamek/common/MovePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,22 @@ public int hashCode() {

// is this move path being done using careful movement?
private boolean careful = true;
private boolean gravityConcern = false;
private final float gravity;

/**
* Generates a new, empty, movement path object.
*/
public MovePath(final Game game, final Entity entity) {
this.setEntity(entity);
this.setGame(game);
// Do we care about gravity when adding steps?
gravity = game.getPlanetaryConditions().getGravity();
gravityConcern = (
(gravity > 1.0F && cachedEntityState.getJumpMPNoGravity() > 0
|| (gravity < 1.0F && cachedEntityState.getRunMP() > cachedEntityState.getRunMPNoGravity()))
&& game.getBoard().onGround() && !entity.isAirborne()
);
}

public Entity getEntity() {
Expand Down Expand Up @@ -380,6 +389,20 @@ protected MovePath addStep(final MoveStep step, boolean compile) {
}
}

// Gravity check: only applies to ground moves by ground units
if (gravityConcern && getMpUsed() != 0) {
int usedMP = getMpUsed();
int runMP = cachedEntityState.getRunMPNoGravity();
int jumpMP = cachedEntityState.getJumpMPNoGravity();
if (gravity < 1.0) {
// Only dangerous if we move too far
step.setDanger(step.isDanger() || (usedMP > runMP || (step.isJumping() && usedMP > jumpMP)));
} else {
// Dangerous if we jump _at all_
step.setDanger(step.isDanger() || (step.isJumping()));
}
}

// if we're an aerospace unit on a ground map and have passed over a hostile unit
// record this fact - it is useful for debugging thus we leave the commented out code here
// but for performance reasons, we don't actually do it.
Expand Down
Loading

0 comments on commit d33a276

Please sign in to comment.