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

Update Princess hazard calcs and settings #5857

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4477,8 +4477,8 @@ BotConfigDialog.fallShameSliderMin=Highway Menace
BotConfigDialog.fallShameSliderMax=Never takes a risk.
BotConfigDialog.fallShameSliderTitle=Piloting Caution
BotConfigDialog.fallShameToolTip=<EM>Piloting Caution:</EM> How much do I want to avoid failed Piloting Rolls?
BotConfigDialog.braverySliderMin=I fear nothing!
BotConfigDialog.braverySliderMax=Run Away!
BotConfigDialog.braverySliderMax=I fear nothing!
BotConfigDialog.braverySliderMin=Run Away!
BotConfigDialog.braverySliderTitle=Bravery
BotConfigDialog.braveryTooltip=<EM>Bravery:</EM> How worried about enemy damage am I?
BotConfigDialog.targetsLabel=Strategic Targets
Expand Down
72 changes: 72 additions & 0 deletions megamek/src/megamek/client/bot/princess/BasicPathRanker.java
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ private double checkHexForHazards(Hex hex, Entity movingUnit, boolean endHex, Mo
Terrains.BUILDING,
Terrains.BRIDGE,
Terrains.BLACK_ICE,
Terrains.SNOW,
Terrains.SWAMP,
Terrains.MUD,
Terrains.TUNDRA));
Expand Down Expand Up @@ -854,6 +855,12 @@ private double checkHexForHazards(Hex hex, Entity movingUnit, boolean endHex, Mo
case Terrains.BLACK_ICE:
hazardValue += calcIceHazard(movingUnit, hex, step, movePath, jumpLanding, logMsg);
break;
case Terrains.SNOW:
hazardValue += calcSnowHazard(hex, endHex, movingUnit, logMsg);
break;
case Terrains.RUBBLE:
hazardValue += calcRubbleHazard(hex, endHex, movingUnit, jumpLanding, step, logMsg);
break;
case Terrains.SWAMP:
hazardValue += calcSwampHazard(hex, endHex, movingUnit, jumpLanding, step, logMsg);
break;
Expand Down Expand Up @@ -1317,6 +1324,35 @@ private double calcBogDownFactor(String name, boolean endHex, boolean jumpLandin
return factor;
}

private double calcSnowHazard(Hex hex, boolean endHex, Entity movingUnit, StringBuilder logMsg) {
logMsg.append("\n\tCalculating Deep Snow hazard: ");

// Hover units are above the surface.
if (EntityMovementMode.HOVER == movingUnit.getMovementMode()
|| EntityMovementMode.WIGE == movingUnit.getMovementMode()) {
logMsg.append("Hovering above Snow (0).");
return 0;
}

if (hex.terrainLevel(Terrains.SNOW) > 1) {
// PSR checks _to bog down_ and _escape bogged down_ are at (mod - 1); all others are at a +1 mod
int psrMod = 0;
// Infantry use 4+ check instead of Pilot / Driving skill
int pilotSkill = (movingUnit.isInfantry()) ? 4 : movingUnit.getCrew().getPiloting();
double hazard;

// Base hazard is arbitrarily set to 10
hazard = 10 * calcBogDownFactor(
"Deep Snow", endHex, false, pilotSkill, psrMod, logMsg);

logMsg.append("\nBase hazard value: ").append(LOG_DECIMAL.format(hazard));
return Math.round(hazard);
}

// Thin snow poses no hazard; MP malus accounted for elsewhere.
return 0;
}

private double calcSwampHazard(Hex hex, boolean endHex, Entity movingUnit,
boolean jumpLanding, MoveStep step,
StringBuilder logMsg) {
Expand Down Expand Up @@ -1410,6 +1446,42 @@ private double calcTundraHazard(boolean endHex, boolean jumpLanding, Entity movi
return Math.round(hazard);
}

private double calcRubbleHazard(Hex hex, boolean endHex, Entity movingUnit,
boolean jumpLanding, MoveStep step,
StringBuilder logMsg) {

logMsg.append("\n\tCalculating Rubble hazard: ");

// Hover units are above the surface.
if (EntityMovementMode.HOVER == movingUnit.getMovementMode()
|| EntityMovementMode.WIGE == movingUnit.getMovementMode()) {
logMsg.append("Hovering above Rubble (0).");
return 0;
}

double hazard = 0;

boolean caresAboutRubble = (
(!jumpLanding || endHex)
&& (hex.terrainLevel(Terrains.RUBBLE) > 0) && (hex.terrainLevel(Terrains.PAVEMENT) == Terrain.LEVEL_NONE)
&& movingUnit.canFall()
);

if (caresAboutRubble) {
// PSR checks are at +0 for Rubble levels up to 6, Ultra, which is +1
int psrMod = (hex.terrainLevel(Terrains.RUBBLE) < 6) ? 0 : 1;
if (movingUnit.hasAbility(OptionsConstants.PILOT_TM_MOUNTAINEER)) {
psrMod -= 1;
}
int pilotSkill = movingUnit.getCrew().getPiloting();

// The only hazard is the +1 to PSRs, which are difficult to quantify
hazard = calcBogDownFactor(
"Rubble", endHex, jumpLanding, pilotSkill, psrMod, false, logMsg);
}
logMsg.append("\nBase hazard value: ").append(LOG_DECIMAL.format(hazard));
return Math.round(hazard);
}
/**
* Simple data structure that holds a separate firing and physical damage number.
*
Expand Down
7 changes: 7 additions & 0 deletions megamek/src/megamek/client/ui/dialogs/BotConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import org.apache.logging.log4j.LogManager;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
Expand Down Expand Up @@ -439,7 +441,11 @@ private boolean isChangedPreset() {

private JPanel buildSlider(JSlider thisSlider, String minMsgProperty,
String maxMsgProperty, String toolTip, String title) {
TitledBorder border = BorderFactory.createTitledBorder(title);
border.setTitlePosition(TitledBorder.TOP);
border.setTitleJustification(TitledBorder.CENTER);
var result = new TipPanel();
result.setBorder(border);
result.setLayout(new BoxLayout(result, BoxLayout.PAGE_AXIS));
result.setToolTipText(toolTip);
thisSlider.setToolTipText(toolTip);
Expand All @@ -455,6 +461,7 @@ private JPanel buildSlider(JSlider thisSlider, String minMsgProperty,

result.add(panLabels);
result.add(thisSlider);
result.revalidate();
return result;
}

Expand Down
8 changes: 5 additions & 3 deletions megamek/src/megamek/common/Compute.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,17 +566,19 @@ public static boolean isPilotingSkillNeeded(Game game, int entityId,
Coords src, Coords dest, EntityMovementType movementType,
boolean isTurning, boolean prevStepIsOnPavement, int srcElevation,
int destElevation, MoveStep moveStep) {
// It's possible to get a real ID for an entity we've forgotten (Double Blind, for instance).
final Entity entity = game.getEntity(entityId);
if (entity == null) {
throw new IllegalArgumentException("Entity invalid. ID " + entityId);
}

final Hex srcHex = game.getBoard().getHex(src);
final Hex destHex = game.getBoard().getHex(dest);
final boolean isInfantry = (entity instanceof Infantry);
int delta_alt = (destElevation + destHex.getLevel())
- (srcElevation + srcHex.getLevel());

// arguments valid?
if (entity == null) {
throw new IllegalArgumentException("Entity invalid. ID " + entityId);
}
if (src.distance(dest) > 1) {
throw new IllegalArgumentException("Coordinates must be adjacent.");
}
Expand Down
Loading