Skip to content

Commit

Permalink
Add hazard calculation for Deep Snow
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleet01 committed Aug 5, 2024
1 parent cce83da commit 1f05489
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 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,9 @@ 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.SWAMP:
hazardValue += calcSwampHazard(hex, endHex, movingUnit, jumpLanding, step, logMsg);
break;
Expand Down Expand Up @@ -1317,6 +1321,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

0 comments on commit 1f05489

Please sign in to comment.