Class CrossBoardAttackHelper

java.lang.Object
megamek.common.board.CrossBoardAttackHelper

public final class CrossBoardAttackHelper extends Object
  • Method Details

    • isCrossBoardAttackPossible

      public static boolean isCrossBoardAttackPossible(Entity attacker, Targetable target, Game game)
      Returns true when the given attacker can possibly attack the given target wherein attacker and target are not on the same board.

      Note: Returns false when attacker and target are on the same board! Also returns false when attacker or target do not have a valid position, i.e. are un-deployed or offboard or transported.

      Note: This method is strict in that when it returns false, no attack is possible. It may however return true when an attack is possible in principle but may still be hindered by some circumstance. In other words, this method checks for general features such as unit types and a connection between the boards of attacker and target but it does not check ammo availability, disallowed multiple targets, firing arcs etc.

      Parameters:
      attacker - The attacking unit
      target - The target unit or object
      game - The game object
      Returns:
      True when an attack is possible in principle (but might still be unavailable), false only when an attack is definitely impossible
    • onGroundMapsWithinOneAtmosphereMap

      public static boolean onGroundMapsWithinOneAtmosphereMap(Game game, Targetable unit1, Targetable unit2)
    • isOrbitToSurface

      public static boolean isOrbitToSurface(Game game, Entity attacker, Targetable target)
      Returns true when an attack of the given attacker on the given target is an orbit-to-surface attack. When true, the attack may still be impossible because of ammo, arc, distance etc. but when false, the attack cannot work as an O2S attack.
      Parameters:
      game - The game
      attacker - The attacking unit for the O2S attack
      target - The target
      Returns:
      True when an attack must be handled as an O2S attack
    • isAirborneToSurface

      public static boolean isAirborneToSurface(Entity attacker, Targetable target, Game game)
      Returns true when an attack of the given attacker on the given target is an airborne-to-surface attack. When true, the attack may still be impossible because of ammo, arc, distance etc. but when false, the attack cannot work as an A2S attack.
      Parameters:
      attacker - The attacking unit for the A2S attack
      target - The target
      game - The game
      Returns:
      True when an attack must be handled as an A2S attack
    • isSurfaceToOrbit

      public static boolean isSurfaceToOrbit(Entity attacker, Targetable target, Game game)
      Returns true when an attack of the given attacker on the given target is a surface-to-orbit attack. When true, the attack may still be impossible because of ammo, arc, distance etc. but when false, the attack cannot work as an S2O attack.
      Parameters:
      attacker - The attacking unit for the S2O attack
      target - The target
      game - The game
      Returns:
      True when an attack must be handled as an S2O attack
    • getCrossBoardGroundMapDistance

      public static int getCrossBoardGroundMapDistance(Entity attacker, Targetable target, Game game)
      Returns the distance between attacker and target provided they are on different ground map sheets. The distance is given in hexes and can be converted to a map sheet distance by dividing by 17 (see WeaponAttackAction.toHitIsImpossible()). The position of attacker or target on their respective boards does not influence the distance, as the result is supposed to be treated as a multiple of "map sheets". The hex distance is measured as the distance in hexes between the ground maps on their atmospheric map multiplied by 17 (Board.DEFAULT_BOARD_HEIGHT). If the ground maps are not on the same atmospheric map but instead two different ones within a common space map, the distance is equal to the hex distance of the atmospheric maps on the space map times 36 * 17 as each space hex measures 18 km and each atmosphere hex 0.5 km. If attacker and target are on the same map or one of them is not on a ground map or their maps are not connected at all (no common space map), this will return Integer.MAX_VALUE.
      Parameters:
      attacker - The attacker
      target - The target (typically a hex)
      game - The game
      Returns:
      The distance between attacker and target measured in hexes
    • isCrossBoardArtyAttack

      public static boolean isCrossBoardArtyAttack(Entity attacker, Targetable target, Game game)
      Returns true when the given attacker and target may generally take part in an artillery attack from one ground board to another ground board. When true, the attack may still be impossible because of ammo, arc, distance etc. but when false, the attack is definitely impossible.

      This method checks for null combatants and if both are on connected but different ground maps

      Parameters:
      attacker - The attacking unit firing an artillery weapon
      target - The target (hex)
      game - The game
      Returns:
      True when a cross board arty attack is possible in principle, false when it is definitely impossible