Record Class UnderwaterFire
- Record Components:
blocked- why the shot is impossible, ornullif it can be attemptedunderwaterRanges- the range table to use instead of the weapon's normal one, ornullto keep the normal table; only set when the shot passes through water and is still legal
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 Summary
ConstructorsConstructorDescriptionUnderwaterFire(TargetRollModifier blocked, int[] underwaterRanges) Creates an instance of aUnderwaterFirerecord class. -
Method Summary
Modifier and TypeMethodDescriptionblocked()Returns the value of theblockedrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.final StringtoString()Returns a string representation of this record class.int[]Returns the value of theunderwaterRangesrecord component.
-
Constructor Details
-
UnderwaterFire
Creates an instance of aUnderwaterFirerecord class.- Parameters:
blocked- the value for theblockedrecord componentunderwaterRanges- the value for theunderwaterRangesrecord component
-
-
Method Details
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
blocked
Returns the value of theblockedrecord component.- Returns:
- the value of the
blockedrecord component
-
underwaterRanges
Returns the value of theunderwaterRangesrecord component.- Returns:
- the value of the
underwaterRangesrecord component
-