Class Compute

java.lang.Object
megamek.common.compute.Compute

public class Compute extends Object
The Compute class is designed to provide static methods for 'Meks and other entities moving, firing, etc.
  • Field Details

  • Method Details

    • d6

      public static int d6()
      Wrapper to random#d6()
    • d6

      public static int d6(int dice)
      Wrapper to random#d6(n)
    • d6

      public static int d6(int dice, int keep)
      Wrapper to random#d6(n)
    • rollD6

      public static Roll rollD6(int dice)
      Wrapper to random#d6(n)
    • rollD6

      public static Roll rollD6(int dice, int keep)
      Wrapper to random#d6(n)
    • individualDice

      public static List<Integer> individualDice(int number, int faces)
      Input is in format "ndf", so this can handle 2d6 or 3d10
      Parameters:
      number - the number of dice to roll
      faces - the number of faces on those dice
      Returns:
      an Integer list of every dice roll, with index 0 containing the summed result
    • individualRolls

      public static List<Integer> individualRolls(int count, int number, int faces)
      Input is in format "c ndf", so that this can handle 10 rolls of 3d6
      Parameters:
      count - the count of sets of dice to roll
      number - the number of dice to roll per set
      faces - the number of faces per die
      Returns:
      an Integer list of every summed dice roll, with index 0 containing the summed result
    • getHighestTwoIntegers

      public static int getHighestTwoIntegers(int... values)
      Returns the sum of the highest two values from the provided list of integer values.

      This method efficiently computes the top two results without sorting, making it suitable for rules that require selecting the best two dice out of several rolled, such as natural aptitude-empowered skill checks.

      Edge cases are handled gracefully:

      • If no values are provided, the result is 0.
      • If only one value is provided, that value is returned.
      • If two or more values are provided, the sum of the highest two is returned.
      Parameters:
      values - one or more integers
      Returns:
      the sum of the highest two values (clamped within Integer Min/Max), or a fallback value for edge cases
      Since:
      0.50.10
    • randomInt

      public static int randomInt(int maxValue)
      Generates a number between 0 and max value exclusive (this means maxValue-1). e.g. randomInt(3) will generate 0, 1, or 2.
    • randomIntInclusive

      public static int randomIntInclusive(int maxValue)
      Generates a number between 0 and max value inclusive (this means maxValue). e.g. randomInt(3) will generate 0, 1, 2 or 3.
    • randomRealIntInclusive

      public static int randomRealIntInclusive(int maxValue)
      Generates a number between 1 and max value inclusive (this means maxValue). e.g. randomInt(3) will generate 1, 2 or 3.
    • randomFloat

      public static float randomFloat()
      Wrapper to random#randomFloat()
    • randomListElement

      public static <T> T randomListElement(List<T> list)
      Selects a random element from a list
      Type Parameters:
      T - The list type
      Parameters:
      list - The list of items to select from
      Returns:
      An element in the list
      Throws:
      IllegalArgumentException - when the given list is empty
    • setRNG

      public static void setRNG(int type)
      Sets the RNG to the desired type
    • setRNG

      public static void setRNG(MMRandom random)
      Sets the RNG to the specific instance.
      Parameters:
      random - A non-null instance of MMRandom to use for all random number generation.
    • oddsAbove

      public static double oddsAbove(int n)
      Returns the odds that a certain number or above will be rolled on 2d6.
    • oddsAbove

      public static double oddsAbove(int n, boolean dropLowest)
      Returns the odds that a certain number or above will be rolled on 2d6, or on 3d6 drop the lowest if the flag is set.
      Parameters:
      dropLowest - Flag that determines whether 2d6 or 3d6 drop the lowest is used
    • oddsAsDisplayPercent

      public static double oddsAsDisplayPercent(double odds)
      Rounds odds from oddsAbove(int, boolean) down to one decimal place for display. Rounding down means a roll that can still fail never shows as 100%. For example, a target number of 3 rolled with Natural Aptitude is 99.54%, which shows as 99.5% rather than 100%.

      One decimal place, not two, because the 2d6 odds are stored to one decimal place: 8 or more is stored as 41.6, so two places would show a false 41.60.

      Parameters:
      odds - the odds of success, from 0 to 100
      Returns:
      the odds rounded down to one decimal place
    • stackingViolation

      public static Entity stackingViolation(Game game, int enteringId, Coords coords, boolean climbMode)
      Returns an entity if the specified entity would cause a stacking violation entering a hex, or returns null if it would not. The returned entity is the entity causing the violation.

      The position and elevation for the stacking violation are derived from the Entity represented by the passed Entity ID. By default, ignores hidden units.

      Parameters:
      game - The Game instance
      enteringId - The gameId of the moving Entity
      coords - The hex being entered
      climbMode - The moving Entity's climb mode at the point it enters the destination hex
      Returns:
      Entity instance that is causing the violation
    • stackingViolation

      public static Entity stackingViolation(Game game, Entity entering, Coords dest, Entity transport, boolean climbMode, boolean ignoreHidden)
      When compiling an unloading step, both the transporter and the unloaded unit probably occupy some other position on the board.

      The position and elevation for the stacking violation are derived from the passed Entity.

      Parameters:
      game - The Game instance
      entering - The Entity entering the hex
      dest - The hex being entered
      transport - Represents the unit transporting entering, which may affect stacking, can be null
      climbMode - The moving Entity's climb mode at the point it enters the destination hex
      ignoreHidden - true by default.
      Returns:
      Entity instance that is causing the violation
    • stackingViolation

      public static Entity stackingViolation(Game game, Entity entering, int elevation, Coords dest, Entity transport, boolean climbMode, boolean ignoreHidden)
      Returns an entity if the specified entity would cause a stacking violation entering a hex, or returns null if it would not. The returned entity is the entity causing the violation.

      The position is derived from the passed Entity, while the elevation is derived from the passed Entity parameter.

      Parameters:
      game - The Game instance
      entering - The Entity entering the hex
      elevation - The elevation of the moving Entity
      dest - The hex being entered
      transport - Represents the unit transporting entering, which may affect stacking, can be null
      climbMode - The moving Entity's climb mode at the point it enters the destination hex
      ignoreHidden - true by default.
      Returns:
      Entity instance that is causing the violation
    • stackingViolation

      public static Entity stackingViolation(Game game, Entity entering, Coords origPosition, int elevation, Coords dest, Entity transport, boolean climbMode, boolean ignoreHidden)
      Used by Princess / bots for checking deployment positions.
      Parameters:
      game - The Game instance
      entering - The Entity entering the hex
      origPosition - The coords of the hex the moving Entity is leaving
      elevation - The elevation of the moving Entity
      dest - The hex being entered
      transport - Represents the unit transporting entering, which may affect stacking, can be null
      climbMode - The moving Entity's climb mode at the point it enters the destination hex
      ignoreHidden - true by default.
      Returns:
      Entity instance that is causing the violation
    • stackingViolation

      public static Entity stackingViolation(Game game, Entity entering, int elevation, Coords dest, int destBoardId, Entity transport, boolean climbMode, boolean ignoreHidden)
      Board-aware check used when compiling movepaths
      Parameters:
      game - The Game instance
      entering - The Entity entering the hex
      elevation - The elevation of the moving Entity
      dest - The hex being entered
      destBoardId - Allows setting a different board for checking destination hex
      transport - Represents the unit transporting entering, which may affect stacking, can be null
      climbMode - The moving Entity's climb mode at the point it enters the destination hex
      ignoreHidden - true by default.
      Returns:
      Entity instance that is causing the violation
    • stackingViolation

      public static Entity stackingViolation(Game game, Entity entering, Coords origPosition, int elevation, Coords dest, int destBoardId, Entity transport, boolean climbMode, boolean ignoreHidden)
      Returns an entity if the specified entity would cause a stacking violation entering a hex, or returns null if it would not. The returned entity is the entity causing the violation.

      The position and elevation is derived from the passed Entity parameter.

      Parameters:
      game - The Game instance
      entering - The Entity entering the hex
      origPosition - The coords of the hex the moving Entity is leaving
      elevation - The elevation of the moving Entity
      dest - The hex being entered
      destBoardId - Allows setting a different board for checking destination hex
      transport - Represents the unit transporting entering, which may affect stacking, can be null
      climbMode - The moving Entity's climb mode at the point it enters the destination hex
      ignoreHidden - true by default.
      Returns:
      Entity instance that is causing the violation
    • isEnemyIn

      public static boolean isEnemyIn(Game game, Entity entity, Coords coords, boolean onlyMeks, boolean ignoreInfantry, int enLowEl, boolean ignoreHidden)
      Returns true if there is any unit that is an enemy of the specified unit in the specified hex. This is only called for stacking purposes, and so does not return true if the enemy unit is currently making a DFA.
    • isPilotingSkillNeeded

      public static boolean isPilotingSkillNeeded(Game game, int entityId, Coords src, Coords dest, EntityMovementType movementType, boolean isTurning, boolean prevStepIsOnPavement, int srcElevation, int destElevation, MoveStep moveStep)
      Returns:
      true if a piloting skill roll is needed to traverse the terrain
    • isValidDisplacement

      public static boolean isValidDisplacement(Game game, int entityId, Coords src, int direction)
      Can the defending unit be displaced from the source to the destination?
    • isValidDisplacement

      public static boolean isValidDisplacement(Game game, int entityId, Coords src, Coords dest)
      Can the defending unit be displaced from the source to the destination?
    • getValidDisplacement

      public static Coords getValidDisplacement(Game game, int entityId, Coords src, int direction)
      Gets a valid displacement, from the hexes around src, as close to the original direction as is possible.
      Returns:
      valid displacement coords, or null if none
    • getPreferredDisplacement

      public static Coords getPreferredDisplacement(Game game, int entityId, Coords src, int direction)
      Gets a preferred displacement. Right now this picks the surrounding hex with the same elevation as original hex, if not available it picks the highest elevation that is a valid displacement. This will preferably not displace into friendly units
      Returns:
      valid displacement coords, or null if none
    • getMissedChargeDisplacement

      public static Coords getMissedChargeDisplacement(Game game, int entityId, Coords src, int direction)
      Gets a hex to displace a missed charge to. Picks left or right, first preferring higher hexes, then randomly, or returns the base hex if they're impassible.
    • findSpotter

      public static Entity findSpotter(Game game, Entity attacker, Targetable target)
      Finds the best spotter for the attacker. The best spotter is the one with the lowest attack modifiers, of course. LOS modifiers and movement are considered.
    • isTargetTagged

      public static boolean isTargetTagged(Targetable target, Game game)
      Worker function to determine if the target has been tagged.
      Parameters:
      target - The non-entity target to check
      game - The current Game
      Returns:
      Whether the given entity or other targetable is tagged.
    • isTargetTagged

      public static boolean isTargetTagged(Entity attacker, Targetable target, Game game)
      Worker function to determine if the target has been tagged by the specific attacker.
      Parameters:
      attacker - The attacker.
      target - The non-entity target to check
      game - The current Game
      Returns:
      Whether the given entity or other targetable is tagged by the specific attacker.
    • getImmobileMod

      public static ToHitData getImmobileMod(Targetable target)
    • getImmobileMod

      @Nullable public static ToHitData getImmobileMod(Targetable target, int aimingAt, AimingMode aimingMode)
      Gets the ToHitData associated with firing at an immobile target. Returns null if target isn't.

      Note: all Ranged attack calls *must* go through *.addImmobileMod() or we may get illegal -4 mods. Currently this is the case; all other attack types go through the above simplified method.

      Parameters:
      target - The target being considered for firing
      aimingAt - The location of the unit being aimed at
      aimingMode - The aiming mode
      Returns:
      The relevant ToHitData
    • getRangeMods

      public static ToHitData getRangeMods(Game game, Entity attackingEntity, WeaponMounted weapon, AmmoMounted ammo, Targetable target)
      Determines the to-hit modifier due to range for an attack with the specified parameters. Includes minimum range, infantry 0-range mods, and target stealth mods. Accounts for friendly C3 units.
      Returns:
      the modifiers
    • getRangeMods

      public static ToHitData getRangeMods(Game game, Entity attackingEntity, WeaponMounted weapon, AmmoMounted ammo, Targetable target, @Nullable List<ECMInfo> allECMInfo)
      Determines the to-hit modifier due to range for an attack with the specified parameters. Includes minimum range, infantry 0-range mods, and target stealth mods. Accounts for friendly C3 units.

      For a C3-equipped attacker, the C3 spotter search needs ECM information for every game entity, which is expensive to compute. Callers that evaluate many attacks in a row (bots, to-hit previews) should compute that list once via ComputeECM.computeAllEntitiesECMInfo(List) and pass it in.

      Parameters:
      allECMInfo - Precomputed ECM information for all game entities, or null to compute it on demand
      Returns:
      the modifiers
    • getInfantryRangeMods

      public static ToHitData getInfantryRangeMods(int distance, InfantryWeapon primaryWeapon, InfantryWeapon secondaryWeapon, @Nullable InfantryWeapon disposableWeapon, boolean underwater)
      Calculate the range modifiers for a conventional infantry attack.
      Parameters:
      distance - - range to target
      primaryWeapon - - the weapon used to calculate range -- secondaryWeapon if 2/squad, otherwise primary
      secondaryWeapon - - the secondaryWeapon weapon, if any. Range zero penalties apply even if primary is used for range
      underwater - - underwater range is half, rounded down
      Returns:
      - all modifiers for range
    • effectiveWeaponDistance

      public static int effectiveWeaponDistance(Game game, Entity weaponEntity, WeaponMounted weapon, Targetable target)
      Calculates effective distance from a weapon's firing position to a target, accounting for altitude differences and same-building elevation modifiers. This is used for entities with multiple firing positions like BuildingEntity.
      Parameters:
      game - The current game
      weaponEntity - The entity with the weapon
      weapon - The weapon being fired
      target - The target being attacked
      Returns:
      The effective distance from the weapon's firing position to the target
    • effectiveDistance

      public static int effectiveDistance(Game game, Entity attacker, @Nullable Targetable target)
    • effectiveDistance

      public static int effectiveDistance(Game game, Entity attacker, @Nullable Targetable target, boolean useGroundDistance)
      Finds the effective distance between an attacker and a target. Includes the distance bonus if the attacker and target are in the same building and on different levels. Also takes account of altitude differences
      Returns:
      the effective distance
    • getClosestFlightPath

      @Nullable public static Coords getClosestFlightPath(int attackerId, Coords aPos, Entity targetEntity)
      Parameters:
      aPos - the attacker's position
      targetEntity - the target entity
      Returns:
      the closest position along targetEntity's flight path to aPos. In the case of multiple equidistance positions, the first one is picked unless targetEntity's playerPickedPassThrough position is non-null.
    • getClosestFlightPathFacing

      public static int getClosestFlightPathFacing(int attackerId, Coords aPos, Entity targetEntity)
    • getClosestToFlightPath

      @Nullable public static Coords getClosestToFlightPath(Entity flyingEntity, Coords targetPosition)
      Parameters:
      flyingEntity - the flyer
      targetPosition - target
      Returns:
      the closest position along flyingEntity's flight path to targetPosition. In the case of multiple equidistance positions, the first one is picked.
    • exposed_findC3Spotter

      @Deprecated public static Entity exposed_findC3Spotter(Game game, Entity attacker, Targetable target)
      Deprecated.
      WOR: Need this function to find out where my nova stuff doesn't work. Delete it if nova works but remember to alter the /nova debug server command.
    • findTAGSpotter

      public static Entity findTAGSpotter(Game game, Entity attacker, Targetable target, boolean stopAtFirst)
      Function that attempts to find one TAG spotter, or the best TAG spotter,
      Parameters:
      attacker - should be an artillery unit
      target - (if null, do not return a spotter!)
      stopAtFirst - if we only want to know that there is one, not which is best
      Returns:
      The Spotter.
    • getProneMods

      public static ToHitData getProneMods(Game game, Entity attacker, int weaponId)
      Gets the modifiers, if any, that the mek receives from being prone.
      Returns:
      any applicable modifiers due to being prone
    • getDamageWeaponMods

      public static ToHitData getDamageWeaponMods(Entity attacker, Mounted<?> weapon)
      Adds any damage modifiers from arm critical hits or sensor damage.
      Returns:
      Any applicable damage modifiers
    • getSecondaryTargetMod

      public static ToHitData getSecondaryTargetMod(Game game, Entity attacker, Targetable target)
      Determines if the current target is a secondary target, and if so, returns the appropriate modifier.
      Returns:
      The secondary target modifier.
    • getAccidentalFallFromAboveDamageFor

      public static int getAccidentalFallFromAboveDamageFor(Entity entity, int fallElevation)
      Damage that a mek does with an accidental fall from above.
    • getAttackerMovementModifier

      public static ToHitData getAttackerMovementModifier(Game game, int entityId)
      Modifier to attacks due to attacker movement
    • getAttackerMovementModifier

      public static ToHitData getAttackerMovementModifier(Game game, int entityId, EntityMovementType movement)
      Modifier to attacks due to attacker movement
    • getSpotterMovementModifier

      public static ToHitData getSpotterMovementModifier(Game game, int entityId)
      Modifier to attacks due to spotter movement
    • getSpotterMovementModifier

      public static ToHitData getSpotterMovementModifier(Game game, int entityId, EntityMovementType movement)
      Modifier to attacks due to spotter movement
    • modifyPhysicalBTHForAdvantages

      public static void modifyPhysicalBTHForAdvantages(Entity attacker, Entity target, ToHitData toHit, Game game)
      Modifier to physical attack BTH due to pilot advantages
    • maxTargetMovementModifier

      public static int maxTargetMovementModifier(@Nullable Game game)
      The highest target movement modifier a ground unit can earn in this game: the top of the movement table, +6 or +7 under the MaxTech movement modifiers option, plus the +1 for jumping or being airborne. A gamemaster's change is held to this ceiling.
      Parameters:
      game - the game whose options decide the table, or null for the standard table
      Returns:
      the ceiling of the target movement modifier
    • getTargetMovementModifier

      public static ToHitData getTargetMovementModifier(Game game, int entityId)
      Modifier to attacks due to target movement, with any gamemaster change for the round applied on top and the total held between no modifier and maxTargetMovementModifier(Game). Aerospace targets take no movement modifier here and so take no gamemaster change either.
      Parameters:
      game - current game
      entityId - targetId
      Returns:
      toHitData for the target's movement modifiers
      See Also:
    • minGamemasterTargetModifier

      public static int minGamemasterTargetModifier(Game game, int entityId)
      The largest reduction a gamemaster's target movement modifier change can make on this unit this round: the earned modifier taken back down to the floor getTargetMovementModifier(Game, int) holds the total to. A unit that earned +2 by moving can be reduced by 2; one that earned nothing, or the -1 for standing still, cannot be reduced at all. The damage editor uses this as the bottom of its Target Modifier control, so every reduction it offers applies in full.
      Parameters:
      game - current game
      entityId - targetId
      Returns:
      the lowest delta that still changes the modifier, zero or negative
    • getEarnedTargetMovementModifier

      public static ToHitData getEarnedTargetMovementModifier(Game game, int entityId)
      Modifier to attacks due to target movement, as the unit earned it by moving this round, before any gamemaster change. The damage editor shows this beside its Target Modifier control, so a gamemaster can see what a reduction has to work with: a unit that earned nothing cannot be taken below nothing.
      Parameters:
      game - current game
      entityId - targetId
      Returns:
      toHitData for the target's movement modifiers
    • getTargetMovementModifier

      public static ToHitData getTargetMovementModifier(int distance, boolean jumped, boolean airborneNonAerospace, Game game)
      Target movement modifier for the specified distance
      Parameters:
      distance - how many hexes did the target unit move?
      jumped - did the target unit jump?
      airborneNonAerospace - was the target an airborne, non-aerospace unit?
      game - current game
      Returns:
      toHitData for the target's movement modifiers
      See Also:
    • getAttackerTerrainModifier

      public static ToHitData getAttackerTerrainModifier(Game game, int entityId)
      Modifier to attacks due to attacker terrain
    • getTargetTerrainModifier

      public static ToHitData getTargetTerrainModifier(Game game, Targetable target)
      Modifier to attacks due to target terrain TODO:um....should VTOLs get modifiers for smoke, etc.
    • getTargetTerrainModifier

      public static ToHitData getTargetTerrainModifier(Game game, Targetable target, int eiStatus)
    • getTargetTerrainModifier

      public static ToHitData getTargetTerrainModifier(Game game, Targetable target, int eiStatus, boolean attackerInSameBuilding)
    • getTargetTerrainModifier

      public static ToHitData getTargetTerrainModifier(Game game, Targetable targetable, int eiStatus, boolean attackerInSameBuilding, boolean underwaterWeapon)
    • getStrafingTerrainModifier

      public static ToHitData getStrafingTerrainModifier(Game game, int eiStatus, Hex hex)
    • getTargetTotalHP

      public static int getTargetTotalHP(Game game, Targetable target)
      Calculates the current theoretical damage absorbable (armor+structure, etc.) by the given target. Used as a measure of the potential durability of the target under fire.
    • getHighestExpectedDamage

      public static WeaponAttackAction getHighestExpectedDamage(Game g, List<WeaponAttackAction> vAttacks, boolean assumeHit)
      Returns the weapon attack out of a list that has the highest expected damage
    • getSecondHighestExpectedDamage

      public static WeaponAttackAction getSecondHighestExpectedDamage(Game g, List<WeaponAttackAction> vAttacks, boolean assumeHit)
      Returns the weapon attack out of a list that has the second highest expected damage used for engaging multiple salvos
    • getExpectedDamage

      public static float getExpectedDamage(Game g, WeaponAttackAction waa, boolean assumeHit)
      Determines the expected damage to a weapon attack, based on to-hit, salvo sizes, etc.
    • getExpectedDamage

      public static float getExpectedDamage(Game game, WeaponAttackAction weaponAttackAction, boolean assumeHit, List<ECMInfo> allECMInfo)
      Determines the expected damage to a weapon attack, based on to-hit, salvo sizes, etc.
    • getAmmoAdjDamage

      @Deprecated(since="0.51.0", forRemoval=true) public static double getAmmoAdjDamage(Game game, WeaponAttackAction weaponAttackAction)
      Deprecated, for removal: This API element is subject to removal in a future version.
      If the unit is carrying multiple types of ammo for the specified weapon, cycle through them and choose the type best suited to engage the specified target Value returned is expected damage Note that some ammo types, such as infernos, do no damage or have special properties and so the damage is an estimation of effectiveness
    • spinUpCannon

      @Deprecated public static int spinUpCannon(Game game, WeaponAttackAction attackAction)
      Deprecated.
      If this is an ultra or rotary cannon, lets see about 'spinning it up' for extra damage
      Returns:
      the int ID of weapon mode
    • spinUpCannon

      public static int spinUpCannon(Game game, WeaponAttackAction attackAction, int spinupThreshold)
      Determine if autocannon should fire more than one round. Includes standard ACs if the game option for rapid-fire-mode is enabled.
      Parameters:
      game - The current game
      attackAction - Attack action with weapon attack properties
      spinupThreshold - Maximum to-hit number to consider for rapid fire
      Returns:
      the int ID of weapon mode, which is also the number of mode changes from single shot
    • isThroughFrontHex

      public static boolean isThroughFrontHex(Coords src, Entity t)
      Returns true if the line between source Coords and target goes through the hex in front of the attacker
    • firingArcFromVGLFacing

      public static int firingArcFromVGLFacing(int facing)
      Converts the facing of a vehicular grenade launcher to the corresponding firing arc.
      Parameters:
      facing - The VGL facing returned by Mounted.getFacing()
      Returns:
      The firing arc
    • inVisualRange

      public static boolean inVisualRange(Game game, Entity ae, Targetable target)
      checks to see whether the target is within visual range of the entity, but not necessarily LoS
    • inVisualRange

      public static boolean inVisualRange(Game game, LosEffects los, Entity attackingEntity, Targetable target)
      Determine whether the attacking entity is within visual range of the target. This requires line of sight effects to determine if there are certain intervening obstructions, like smoke, that can reduce visual range. Since repeated LoSEffects computations can be expensive, it is possible to pass in the LosEffects, since they are commonly already computed when this method is called.
      Parameters:
      game - The current Game
    • isAnySensorContact

      @Deprecated(since="0.51.0", forRemoval=true) public static boolean isAnySensorContact(Game game, int targetId)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Checks to see if an entity has already been detected by anyone Used for sensor return icons on board
      Parameters:
      game - The current Game
      targetId - - the ID# of the target entity we're looking for
    • hasSensorContact

      public static boolean hasSensorContact(Entity detector, int targetId)
      Checks to see if target entity has already appeared on detector's sensors Used with Naval C3 to determine if detector can fire weapons at @target
      Parameters:
      detector - - the entity making a sensor scan
      targetId - - the entity id of the scan target
    • hasAnyFiringSolution

      public static boolean hasAnyFiringSolution(Game game, int targetId)
      Checks to see if an entity is in anyone's firing solutions list Used for visibility
      Parameters:
      game - The current Game
      targetId - - the ID # of the target we're firing at
    • updateFiringSolutions

      public static void updateFiringSolutions(Game game, Entity detector)
      Updates an entity's firingSolutions, removing any objects that no longer meet criteria for being tracked as targets. Also, if the detecting entity no longer meets criteria for having firing solutions, empty the list. We wouldn't want a dead ship to be providing NC3 data, now would we...
    • updateSensorContacts

      public static void updateSensorContacts(Game game, Entity detector)
      Updates an entity's sensorContacts, removing any objects that no longer meet criteria for being tracked. Also, if the detecting entity no longer meets criteria for having sensor contacts, empty the list. We wouldn't want a dead ship to be providing sensor data, now would we...
    • calcFiringSolution

      public static boolean calcFiringSolution(Game game, Entity ae, Targetable target)
      If the game is in space, "visual range" represents a firing solution as defined in SO starting on p117 Also, in most cases each target must be detected with sensors before it can be seen, so we need to make sensor rolls for detection. This should only be used if TacOps sensor rules are in use. This requires line of sight effects to determine if there are certain intervening obstructions, like sensor shadows, asteroids and that sort of thing, that can reduce visual range. Since repeated LoSEffects computations can be expensive, it is possible to pass in the LosEffects, since they are commonly already computed when this method is called.
      Parameters:
      game - The current Game
      ae - the entity making a sensor scan
      target - the entity we're trying to spot
    • calcFutureTargetFiringSolution

      @Deprecated(since="0.51.0", forRemoval=true) public static boolean calcFutureTargetFiringSolution(Game game, Entity attacker, Targetable target, Coords futureTargetPosition)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • calcSensorContact

      public static boolean calcSensorContact(Game game, Entity ae, Targetable target)
      Determines whether we have an "object" detection as defined in SO's Advanced Sensors rules starting on p117
      Parameters:
      game - The current Game
      ae - the entity making a sensor scan
      target - the entity we're trying to spot
    • getVisualRange

      public static int getVisualRange(Game game, Entity ae, LosEffects los, boolean targetIlluminated)
      Returns:
      visual range in hexes along a specific line of sight
    • getMaxVisualRange

      public static int getMaxVisualRange(Entity entity, boolean targetIlluminated)
      Returns:
      visual range in hexes given current planetary conditions and no los obstruction
    • inSensorRange

      public static boolean inSensorRange(Game game, Entity ae, Targetable target, List<ECMInfo> allECMInfo)
      Checks to see whether the target is within sensor range (but not necessarily LoS or visual range)
      Parameters:
      allECMInfo - A collection of ECMInfo for all entities, this value can be null, and it will be computed when it's needed, however passing in the pre-computed collection is much faster
    • inSensorRange

      public static boolean inSensorRange(Game game, LosEffects los, Entity ae, Targetable target, List<ECMInfo> allECMInfo)
    • canSee

      public static boolean canSee(Game game, Entity ae, Targetable target)
      Checks to see if the target is visible to the unit, always considering sensors.
    • canSee

      public static boolean canSee(Game game, Entity ae, Targetable target, boolean useSensors, LosEffects los, List<ECMInfo> allECMInfo)
      Checks to see if the target is visible to the unit, if the sensor flag is true then sensors are checked as well.
    • getSensorRangeBracket

      public static int getSensorRangeBracket(Entity ae, Targetable target, List<ECMInfo> allECMInfo)
      gets the sensor range bracket when detecting a particular type of target. target may be null here, which gives you the bracket without target entity modifiers
      Parameters:
      allECMInfo - A collection of ECMInfo for all entities, this value can be null, and it will be computed when it's needed, however passing in the pre-computed collection is much faster
    • getSensorBracket

      public static int getSensorBracket(int check)
      returns the brackets for sensor checks
    • getSensorRangeByBracket

      public static int getSensorRangeByBracket(Game game, Entity ae, @Nullable Targetable target, @Nullable LosEffects los)
      gets the size of the sensor range bracket when detecting a particular type of target. target may be null here, which gives you the range without target entity modifiers
    • getADARangeModifier

      public static int getADARangeModifier(int distance)
    • getSensorRanges

      @Nullable public static Compute.SensorRangeHelper getSensorRanges(Game game, Entity e)
      returns the current sensing ranges of the active sensor
    • shouldMoveBackHex

      public static int shouldMoveBackHex(Entity e1, Entity e2)
      Compares the initiative of two aerospace units in the same hex to determine attack angle. The attack angle is computed as if the unit with the higher initiative were in its previous hex.
      Parameters:
      e1 - The first Entity to compare
      e2 - The second Entity to compare
      Returns:
      < 0 if the first unit has a higher initiative, > 0 if the second is higher, or 0 if one of the units is not an aerospace unit, does not have a valid position, or the two units are not in the same hex.
    • missilesHit

      public static int missilesHit(int missiles)
      Maintain backwards compatibility.
      Parameters:
      missiles - - the int number of missiles in the pack.
    • missilesHit

      public static int missilesHit(int missiles, int nMod)
      Maintain backwards compatability.
    • missilesHit

      public static int missilesHit(int missiles, int nMod, boolean hotLoaded)
      Maintain backwards compatability.
    • missilesHit

      public static int missilesHit(int missiles, int nMod, boolean hotLoaded, boolean streak, boolean advancedAMS)
      Roll the number of missiles (or whatever) on the missile hit table, with the specified mod to the roll.
      Parameters:
      missiles - - the int number of missiles in the pack.
      nMod - - the int modifier to the roll for number of missiles that hit.
      hotLoaded - - roll 3d6 take worst 2
      streak - - force a roll of 11 on the cluster table
      advancedAMS - - the roll can now go below 2, indicating no damage
    • calculateClusterHitTableAmount

      public static int calculateClusterHitTableAmount(int roll, int rackSize)
    • getMetalInPath

      public static int getMetalInPath(Entity ae, Coords a, Coords b)
      Check for ferrous metal content in terrain on path from a to b return the total content.
    • getGhostTargetNumber

      public static int getGhostTargetNumber(Entity ae, Coords a, Coords b)
      Check for ECM bubbles in Ghost Target mode along the path from a to b and return the highest target roll. -1 if no Ghost Targets
    • getSpaceBombBaseToHit

      public static ToHitData getSpaceBombBaseToHit(Entity attacker, Entity defender, Game game)
      Get the base to-hit number of a space bomb attack by the given attacker upon the given defender
      Parameters:
      attacker - - the Entity conducting the leg attack.
      defender - - the Entity being attacked.
      Returns:
      The base ToHitData of the attack.
    • getLegAttackBaseToHit

      public static ToHitData getLegAttackBaseToHit(Entity attacker, Entity defender, Game game)
      Get the base to-hit number of a Leg Attack by the given attacker upon the given defender
      Parameters:
      attacker - - the Entity conducting the leg attack.
      defender - - the Entity being attacked.
      Returns:
      The base ToHitData of the attack.
    • getSwarmMekBaseToHit

      public static ToHitData getSwarmMekBaseToHit(Entity attacker, Entity defender, Game game)
      Get the base to-hit number of a Swarm Mek by the given attacker upon the given defender.
      Parameters:
      attacker - - the Entity swarming.
      defender - - the Entity being swarmed.
      Returns:
      The base ToHitData of the mek.
    • canPhysicalTarget

      public static boolean canPhysicalTarget(Game game, int entityId, Targetable target)
    • canMoveOnPavement

      public static boolean canMoveOnPavement(Hex srcHex, Hex destHex, MoveStep moveStep)
      Can movement between the two coordinates be on pavement (which includes roads and bridges)? If so it will override prohibited terrain, it may change movement costs, and it may lead to skids.
      Parameters:
      srcHex - the Hex being left.
      destHex - the Hex being entered.
      moveStep - the MoveStep being performed.
      Returns:
      true if movement between srcHex and destHex can be on pavement; false otherwise.
    • canMoveOnPavement

      public static boolean canMoveOnPavement(Game game, Coords src, Coords dest, MoveStep moveStep)
      Can movement between the two coordinates be on pavement (which includes roads and bridges)? If so it will override prohibited terrain, it may change movement costs, and it may lead to skids.
      Parameters:
      game - The current Game
      src - the Coords being left.
      dest - the Coords being entered.
      moveStep - the MoveStep being performed.
      Returns:
      true if movement between src and dest can be on pavement; false otherwise.
    • isInSameBuilding

      public static boolean isInSameBuilding(Game game, Entity attacker, Targetable target)
      Determines whether the attacker and the target are in the same building.
      Returns:
      true if the target can and does occupy the same building, false otherwise.
    • isInBuilding

      public static boolean isInBuilding(@Nullable Game game, @Nullable Entity entity)
      Determine if the given unit is inside a building at the given coordinates.
      Parameters:
      game - The current Game. This value may be null.
      entity - the Entity to be checked. This value may be null.
      Returns:
      true if the entity is inside the building at those coordinates. false if there is no building at those coordinates or if the entity is on the roof or in the air above the building, or if any input argument is null
    • isInBuilding

      public static boolean isInBuilding(@Nullable Game game, @Nullable Entity entity, @Nullable Coords coords)
      Determine if the given unit is inside a building at the given coordinates.
      Parameters:
      game - The current Game. This value may be null.
      entity - the Entity to be checked. This value may be null.
      coords - the Coords of the building hex. This value may be null.
      Returns:
      true if the entity is inside the building at those coordinates. false if there is no building at those coordinates or if the entity is on the roof or in the air above the building, or if any input argument is null
    • isInBuilding

      public static boolean isInBuilding(@Nullable Game game, int elevation, @Nullable Coords coords, int boardId)
      Returns true when the given place is inside a building, false when the location is not on a board, has no building or the elevation is below the basement or on or above the building. Note that it is safe to pass in any values for elevation, coords and board ID.
      Parameters:
      game - The game (not null)
      elevation - The elevation to test
      coords - The coords of the location
      boardId - The board ID of the location
      Returns:
      True if the given place is inside a building
    • scatterDiveBombs

      public static Coords scatterDiveBombs(Coords coords, int moF)
      Scatter from hex according to dive-bombing rules (based on MoF), TW pg 246. The scatter can happen in any direction.
      Parameters:
      coords - The Coords to scatter from
      moF - The margin of failure, which determines scatter distance
      Returns:
      the Coords scattered to and distance (moF)
    • scatterAltitudeBombs

      public static Coords scatterAltitudeBombs(Coords coords, int facing, int moF)
      Scatter from hex according to altitude bombing rules (based on MoF), TW pg 246. The scatter only happens in the "front" three facings.
      Parameters:
      coords - The Coords to scatter from
      facing - Direction we were going at the time the bomb was dropped
      moF - How badly we failed
      Returns:
      the Coords scattered to and distance (moF)
    • scatterDirectArty

      public static Coords scatterDirectArty(Coords coords, int moF)
      scatter from hex according to direct fire artillery rules (based on MoF)
      Parameters:
      coords - The Coords to scatter from
      moF - The margin of failure, which determines scatter distance
      Returns:
      the Coords scattered to
    • scatter

      public static Coords scatter(Coords coords, int margin)
      Scatters from a hex in a random direction, rolling 1d6 to pick one of the six straight-line directions.
      Parameters:
      coords - the Coords to scatter from
      margin - the scatter distance in hexes; its magnitude is used, so a negative value (such as a negative margin of failure) scatters the same distance as its positive counterpart. Callers may also pass a fixed distance unrelated to a margin of failure.
      Returns:
      the Coords scattered to
    • scatterAssaultDrop

      public static Coords scatterAssaultDrop(Coords coords, int margin)
      scatter from hex according to atmospheric drop rules d6 for direction, 1d6 per point of MOF
      Parameters:
      coords - The Coords to scatter from
      margin - the int margin of failure
      Returns:
      the Coords scattered to
    • getSwarmMissileTarget

      @Nullable public static Entity getSwarmMissileTarget(Game game, int aeId, Coords coords, int weaponId)
      Gets a new target for a flight of swarm missiles that was just shot at an entity and has missiles left
      Parameters:
      game - The current Game
      aeId - The attacking Entity
      weaponId - The int ID of the launcher used to fire this volley
      Returns:
      the new target Entity. May return null if no new target available
    • getFinalPosition

      @Nullable public static Coords getFinalPosition(Coords currentPosition, int... v)
    • changeVectors

      public static int[] changeVectors(int[] v, int facing)
      method to change a set of active vectors for a one-point thrust expenditure in the giving facing
    • sameVectors

      public static boolean sameVectors(int[] v1, int[] v2)
      compare two vectors and determine if they are the same
    • getNetVelocity

      public static int getNetVelocity(Coords src, Entity te, int attackerVelocity, int targetVelocity)
      Get the net velocity of two aerospace for ramming attacks
    • directBlowBADamage

      public static int directBlowBADamage(double damage, int damageType, BattleArmor target)
      Returns how much damage a weapon will do against a BattleArmor target if the BattleArmor vs BattleArmor rules on TO pg 109 are in effect.
      Parameters:
      damage - Original weapon damage
      damageType - The damage type for BA vs BA damage
      target - The target, used for ensuring the target BA isn't fire-resistant
    • getDamageTypeString

      public static String getDamageTypeString(int damageType, int burstMultiplier)
      Used to get a human-readable string that represents the passed damage type.
      Parameters:
      damageType - The damageType constant
      burstMultiplier - The multiplier for burst damage, used by machine gun arrays against conventional infantry
      Returns:
      A string representation of the damage type
    • directBlowInfantryDamage

      public static int directBlowInfantryDamage(double damage, int mos, int damageType, boolean isNonInfantryAgainstMechanized, boolean isAttackThruBuilding)
    • directBlowInfantryDamage

      public static int directBlowInfantryDamage(double damage, int mos, int damageType, boolean isNonInfantryAgainstMechanized, boolean isAttackThruBuilding, int attackerId, Vector<Report> vReport)
      Method replicates the Non-Conventional Damage against Infantry damage table as well as shifting for direct blows. also adjust for non-infantry damaging mechanized infantry
    • computeTotalDamage

      public static int computeTotalDamage(List<WeaponMounted> weaponList)
      Returns:
      the maximum damage that a set of weapons can generate.
    • computeTotalDamage

      public static int computeTotalDamage(WeaponMounted weapon)
      Returns:
      the maximum damage that a weapon can generate.
    • directBlowInfantryDamage

      public static int directBlowInfantryDamage(double damage, int mos, int damageType, boolean isNonInfantryAgainstMechanized, boolean isAttackThruBuilding, int attackerId, Vector<Report> vReport, int mgaSize)
      Method replicates the Non-Conventional Damage against Infantry damage table as well as shifting for direct blows. also adjust for non-infantry damaging mechanized infantry. No mods for Plasma weapons.
      Parameters:
      damage - The base amount of damage
      mos - The margin of success
      damageType - The damage class of the weapon, used to adjust damage against infantry
      isNonInfantryAgainstMechanized - Whether this is a non-infantry attack against mechanized infantry
      isAttackThruBuilding - Whether the attack involves attacker and target both within the same building
      attackerId - The entity id of the attacking unit
      vReport - The report messages vector
      mgaSize - For machine gun array attacks, the number of linked weapons. For other weapons this should be 1.
      Returns:
      The adjusted damage
    • dialDownDamage

      public static int dialDownDamage(Mounted<?> weapon, WeaponType weaponType)
      Method computes how much damage a dial down weapon has done
      Returns:
      new damage
    • dialDownDamage

      public static int dialDownDamage(Mounted<?> weapon, WeaponType weaponType, int range)
      Method computes how much damage a dial down weapon has done
      Returns:
      new damage
    • dialDownHeat

      public static int dialDownHeat(Mounted<?> weapon, WeaponType weaponType)
      Method computes how much heat a dial down weapon generates
      Returns:
      Heat, minimum of 1;
    • dialDownHeat

      public static int dialDownHeat(Mounted<?> weapon, WeaponType weaponType, int range)
      Method computes how much heat a dial down weapon generates
      Returns:
      Heat, minimum of 1;
    • getAdjacentEntitiesAlongAttack

      public static ArrayList<Entity> getAdjacentEntitiesAlongAttack(Coords aPos, Coords tPos, Game game)
      Parameters:
      aPos - - attacking entity
      tPos - - targeted entity
      Returns:
      a vector of all the entities that are adjacent to the targeted entity and would fall along the angle of attack
    • isInUrbanEnvironment

      public static boolean isInUrbanEnvironment(Game game, Coords unitPOS)
    • isAirToGround

      public static boolean isAirToGround(Entity attacker, Targetable target)
      Returns true when an attack of the attacker against the target is considered an A2G attack, see TW p.242-247. This includes strafing, striking and bombing. Attacks on Hex targets and Entity targets can be A2G attacks. Artillery attacks, even from an airborne aero unit, do not count as A2G attacks. Attacks from spaceborne aerospace do not count as A2G attacks (they may count as O2G attacks). Also note that flying ground units such as VTOLs and WiGEs count as ground targets and so attacks against them may count as A2G attacks.
      Parameters:
      attacker - The assumed attacker
      target - The assumed target
      Returns:
      True if the attack would be considered an A2G attack
    • isAirToAir

      public static boolean isAirToAir(Game game, Entity attacker, Targetable target)
      Returns true when an attack of the given units would be an A2A attack. Checks for null units and if both units are airborne, Entity.isAirborne(). Also checks if they're either on the same map or on connected maps (atmosphere/ground or ground/ground within one atmosphere map).
      Parameters:
      game - The game
      attacker - The attacking unit
      target - The target
      Returns:
      True when the supposed attack would be an A2A attack
    • isGroundToAir

      public static boolean isGroundToAir(Entity attacker, Targetable target)
    • isGroundToGround

      public static boolean isGroundToGround(Entity attacker, Targetable target)
    • roundsUntilReturn

      public static int roundsUntilReturn(Game game, Entity en)
      This is a homebrew function partially drawn from pg. 40-1 of AT2R that allows units that flee the field for any reason to return after a certain number of rounds It can potentially be expanded to include other conditions
      Returns:
      number of rounds until return (-1 if never)
    • inDeadZone

      public static boolean inDeadZone(Game game, Entity ae, Targetable target)
    • getAcceptableUnloadPositions

      public static List<Coords> getAcceptableUnloadPositions(List<Coords> candidates, int boardId, Entity unitToUnload, Game game, int elev)
    • isAcceptableUnloadPosition

      public static boolean isAcceptableUnloadPosition(Coords position, int boardId, Entity unitToUnload, Game game, int elev)
    • getMountableUnits

      public static List<Entity> getMountableUnits(Entity entity, Coords pos, int boardId, int elev, Game game)
      Returns a list of all adjacent units that can load the given Entity.
      Parameters:
      entity - The entity to load
      pos - The coordinates of the hex to load from
      boardId - The board ID of the hex to load from
      elev - The absolute elevation of the unit at the point of loading (surface of the hex + elevation over the surface)
      game - The game
      Returns:
      All adjacent units that can transport the Entity
    • allowAimedShotWith

      public static boolean allowAimedShotWith(WeaponMounted weapon, AimingMode aimingMode)
    • getAeroCrewNeeds

      public static int getAeroCrewNeeds(Entity entity)
    • getSVBaseCrewNeeds

      public static int getSVBaseCrewNeeds(Entity entity)
      Calculates the base crew requirements for support vehicles.
      Parameters:
      entity - The support vehicle
      Returns:
      The minimum base crew
    • getTotalGunnerNeeds

      public static int getTotalGunnerNeeds(Entity entity)
      Returns the number of required gunners for an entity.
      Parameters:
      entity - The entity
      Returns:
      The number of required gunners
    • getAdditionalNonGunner

      public static int getAdditionalNonGunner(Entity entity)
      Calculates the number of additional non-gunner crew members required by vehicles and advanced aerospace vessels due to specific miscellaneous equipment mounts or special unit features.

      Crew additions are based on the tonnage or equipment size of certain mounted systems, such as:

      • Communications equipment (F_COMMUNICATIONS): +1 crew per ton of equipment
      • Field Kitchens (F_FIELD_KITCHEN): +3 crew per mount
      • Mobile Field Bases (F_MOBILE_FIELD_BASE): +5 crew per mount
      • MASH units (F_MASH): +5 crew per size unit

      For tanks, any additional crew seats (via getExtraCrewSeats()) are added.

      If the unit has a drone operating system it requires 0 additional crew. For super-heavy meks, this always returns 1 (to represent the Tactical Officer).

      Parameters:
      entity - The unit for which to calculate the additional crew requirements
      Returns:
      The number of additional non-gunner crew required for the given unit
    • getCommunicationsCrew

      public static int getCommunicationsCrew(Entity entity)
    • getDoctorCrew

      public static int getDoctorCrew(Entity entity)
    • getMedicCrew

      public static int getMedicCrew(Entity entity)
    • getCombatTechCrew

      public static int getCombatTechCrew(Entity entity)
    • getAstechCrew

      public static int getAstechCrew(Entity entity)
    • getFullCrewSize

      public static int getFullCrewSize(Entity entity)
    • getTotalDriverNeeds

      public static int getTotalDriverNeeds(Entity entity)
    • useSpheroidAtmosphere

      public static boolean useSpheroidAtmosphere(Game game, Entity en)
      Should we treat this entity, in its current state, as if it is a spheroid unit flying in atmosphere?
    • indirectAttackImpossible

      public static boolean indirectAttackImpossible(Game game, Entity ae, Targetable target, WeaponType weaponType, Mounted<?> weapon)
      Worker function that checks if an indirect attack is impossible for the given passed-in arguments
    • isFlakAttack

      public static boolean isFlakAttack(Entity attacker, Entity target)
    • isFlakToHitTarget

      public static boolean isFlakToHitTarget(Entity attacker, Entity target)
      Returns whether a flak weapon (LB-X cluster, flak ammo, HAG and the like) gets its to-hit bonus against the target. TW p.114 (errata v12.0): flak applies "against a unit that presently has an Altitude or Elevation, or that expended any VTOL or WiGE MP or Thrust Points that turn (even if it landed at the end of that Movement Phase)". A VTOL or WiGE that flew and then landed is therefore still a flak target for the rest of the turn.

      This is the to-hit check only. Artillery flak, which bursts at the target's height, keeps using isFlakAttack(Entity, Entity).

      Parameters:
      attacker - the attacking unit
      target - the unit being attacked
      Returns:
      true if a flak weapon gets its to-hit bonus against the target
    • turnsTilHit

      public static int turnsTilHit(int distance)
    • turnsTilBOMHit

      public static int turnsTilBOMHit(Game game, Entity ae, Targetable target, int velocity)
      Get turns for an indirect or off-board round to hit with its current velocity
      Parameters:
      ae - Attacker
      target - Target hex/entity
      velocity - speed of round, default 50 according to WeaponAttackAction
    • calculateArtilleryLead

      public static Coords calculateArtilleryLead(Game game, Entity ae, Targetable target, boolean homing)
      Parameters:
      homing - to determine if we need the homing lead or some other value.
      Returns:
      Coordinates to aim at to hit this target while it's on the move (we think).
    • calculateArtilleryLead

      public static Coords calculateArtilleryLead(Coords targetPoint, int direction, int leadAmount)
      Returns:
      Coordinates to target given this lead and direction
    • canPointBlankShot

      public static boolean canPointBlankShot(Entity attacker, Entity target)
      Lightweight helper to determine if a given unit can take a Pointblank shot on another
      Parameters:
      attacker - Prospective Pointblank Shot shooter
      target - Prospective Pointblank Shot target
      Returns:
      boolean true if shot can be taken legally; false otherwise
    • revealsHiddenUnitForPointblankShot

      public static boolean revealsHiddenUnitForPointblankShot(Entity mover, int distance, boolean overflight)
      Whether a moving enemy reveals a hidden unit in a way that lets it take a point-blank shot (TW p.260).

      A hidden unit revealed by enemy movement may immediately make the shot, and the rule allows the target to "continue its move after the attack" when it has MP left. That is only possible part way through a move, so a ground unit reveals as it passes rather than only when it stops. Requiring the mover to stop meant walking past a hidden unit did nothing at all.

      An airborne aerospace mover is different: it reveals what it flies over, so the range depends on whether it carries an Active Probe.

      A VTOL or WiGE flying over a hex does not reveal a unit hidden in that hex (TW errata v12.0, p.260, Airborne Units). It still reveals a unit it passes next to, and one in the hex where it ends its move, as a ground unit would.

      Parameters:
      mover - the unit that is moving
      distance - hexes between the mover's current step and the hidden unit
      overflight - true when this step is a VTOL or WiGE flying over the hex without ending its move there; see isNonAerospaceOverflight(Entity, MoveStep, boolean)
      Returns:
      true if the hidden unit is revealed and may take its shot
    • isNonAerospaceOverflight

      public static boolean isNonAerospaceOverflight(Entity mover, MoveStep step, boolean endStep)
      Whether a step is a non-aerospace airborne unit flying over a hex: a unit using VTOL or WiGE movement (VTOLs, WiGEs, LAMs in AirMek mode, powered flight infantry) that is above the terrain of the step's hex and does not end its move there. Such a unit does not reveal units hidden in the hexes it flies over (TW errata v12.0, p.260, Airborne Units).
      Parameters:
      mover - the unit that is moving
      step - the step being taken
      endStep - true when this is the last step of the move
      Returns:
      true if the step flies over its hex
    • canDetectHidden

      public static boolean canDetectHidden(Entity detector, int distance, boolean endStep)
      Lightweight helper for some step evaluation. No side effects.
      Parameters:
      detector - Entity that will detect a hidden unit
      distance - int Distance from detector to hidden entity
      endStep - boolean whether this detection is occurring at the last step of a move path
      Returns:
      true if detector can detect a unit in this situation
    • allEnemiesOutsideBlast

      public static boolean allEnemiesOutsideBlast(Targetable target, Entity attacker, AmmoType ammoType, boolean artillery, boolean flak, boolean asfFlak, Game game)
    • enemiesInsideBlast

      public static Set<Entity> enemiesInsideBlast(Targetable target, Entity attacker, AmmoType ammoType, boolean artillery, boolean flak, boolean asfFlak, Game game)
    • log2

      public static int log2(int number) throws IllegalArgumentException
      Fast log2 implementation; throws if number ≤ 0
      Parameters:
      number - positive int to get the log2 of
      Returns:
      int approximate log2 of number; functionally (Math.floor(log10(10)/log10(2))
      Throws:
      IllegalArgumentException
    • getLoadableCoords

      public static ArrayList<Coords> getLoadableCoords(Entity carrier, Coords position, int boardId)
      Helper to get the coordinates from which a unit can load other units. Not in Entity to avoid bloat. May need extension for different map types but unlikely.
      Parameters:
      carrier - Entity that will be doing the loading
      position - Coords of hex to use as the center of the carrier; may not match carrier's current position value.
      boardId - For future use, e.g. low-altitude or multi-board maps
      Returns:
      ArrayList of Coords that the carrier entity can legally load units from