Class FormationSide

java.lang.Object
megamek.client.bot.princess.FormationSide

public final class FormationSide extends Object
Decides which friendly units are on the mover's side of a water obstacle, so a force split by a river forms up with the units it can actually reach.

A formation's centre is the mean position of the force. When a river runs between the two halves of that force, the mean lands in the water - a hex no unit can stand in, measured on a river crossing as 18% of the distinct centre positions in a run. Every unit is then held to a point in the middle of the river, which is the one place the formation cannot be.

The rule here is deliberately narrow: a friend counts toward the formation only if the straight line to it does not cross deep water. Units form up with their own bank, the far bank forms up with itself, and as units cross, the near group shrinks and the far group grows until the force is whole again on the far side. That is how a force actually crosses a river - it assembles on the far bank - rather than trying to hold one shape across an obstacle it can only pass a few units at a time.

Depth matters. Only water deep enough to force a unit to wade separates a formation (SEPARATING_DEPTH). A shallow ford costs movement but does not break a force in two, and treating every puddle as a barrier would fragment formations on wet maps for no reason.

See Also:
  • Method Details

    • sameSide

      public static boolean sameSide(@Nullable Board board, @Nullable Coords from, @Nullable Coords to)
      Whether two positions are on the same side of any water obstacle deep enough to split a formation.
      Parameters:
      board - the board both positions are on
      from - the mover's position
      to - the friend's position
      Returns:
      true when the straight line between them crosses no separating water, and so the two can form up together
    • sameSide

      public static boolean sameSide(@Nullable Board board, @Nullable Coords from, @Nullable Coords to, int minimumDepth)
      Whether two positions are on the same side of any water of at least the given depth.
      Parameters:
      board - the board both positions are on
      from - the mover's position
      to - the other position
      minimumDepth - the shallowest water that counts as a divide, in levels
      Returns:
      true when the straight line between them crosses no such water
    • isForceSplit

      public static boolean isForceSplit(@Nullable Board board, @Nullable Coords from, List<Coords> positions)
      Whether any separating water lies between the mover and the given friends at all.

      Lets a caller skip the per-friend filtering entirely on the overwhelmingly common case of a dry map, where the answer is always the whole force.

      Parameters:
      board - the board the force is on
      from - the mover's position
      positions - the friends' positions
      Returns:
      true when at least one friend is cut off from the mover by water