Record Class UnderwaterFire

java.lang.Object
java.lang.Record
megamek.client.bot.princess.UnderwaterFire
Record Components:
blocked - why the shot is impossible, or null if it can be attempted
underwaterRanges - the range table to use instead of the weapon's normal one, or null to keep the normal table; only set when the shot passes through water and is still legal

public record UnderwaterFire(TargetRollModifier blocked, int[] underwaterRanges) extends Record
Predicts whether a shot would be blocked or shortened by water, for a shooter and target that are not actually standing where the bot is considering putting them.

The game already enforces the underwater fire rules (TW p.107-109): a submerged weapon can only fire at targets that are also in the water, most weapons cannot fire underwater at all, and the ones that can reach a fraction of their surface range. Compute.getRangeMods(megamek.common.game.Game, megamek.common.units.Entity, megamek.common.equipment.WeaponMounted, megamek.common.equipment.AmmoMounted, megamek.common.units.Targetable) applies all of that - but it reads the shooter's real location status, which the server only sets after a unit actually moves. The bot evaluates thousands of positions a unit is not in, so its damage estimate never saw these rules. The result was that deep water looked like a one-way firing position: the bot priced the protection water gives (the enemy cannot hit a submerged unit) but not the cost (the submerged unit cannot shoot back), and units would sit in a lake all game believing they had their full arsenal.

This class is that missing prediction. isWeaponUnderwater(megamek.common.units.Entity, megamek.client.bot.princess.EntityState, megamek.common.Hex, megamek.common.equipment.WeaponMounted) mirrors how the server assigns wet locations when a unit enters water, applied to the hypothetical position instead of the real one: a Mek standing in depth 1 has only its legs underwater, anything deeper or prone submerges the whole unit unless its top still clears the surface, and a jumping unit stays dry on the turn it lands. check(megamek.common.units.Entity, megamek.client.bot.princess.EntityState, megamek.common.Hex, megamek.common.units.Targetable, megamek.client.bot.princess.EntityState, megamek.common.Hex, megamek.common.equipment.WeaponMounted, megamek.common.equipment.Mounted<?>) then applies the same shot restrictions the server would, in the same order, and hands back the underwater range table when the shot is legal but shortened.

Both directions matter. A submerged shooter overestimating its own guns is what makes water a fake bunker; a dry shooter overestimating its guns against a submerged target is what makes the rest of the force waste turns shooting at that bunker.

  • Constructor Details

    • UnderwaterFire

      public UnderwaterFire(@Nullable TargetRollModifier blocked, @Nullable int[] underwaterRanges)
      Creates an instance of a UnderwaterFire record class.
      Parameters:
      blocked - the value for the blocked record component
      underwaterRanges - the value for the underwaterRanges record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • blocked

      @Nullable public TargetRollModifier blocked()
      Returns the value of the blocked record component.
      Returns:
      the value of the blocked record component
    • underwaterRanges

      @Nullable public int[] underwaterRanges()
      Returns the value of the underwaterRanges record component.
      Returns:
      the value of the underwaterRanges record component