Class FireControl

java.lang.Object
megamek.client.bot.princess.FireControl
Direct Known Subclasses:
AerospaceFireControl, InfantryFireControl, MultiTargetFireControl

public class FireControl extends Object
FireControl selects which weapons a unit wants to fire and at whom Pay attention to the difference between "guess" and "get". Guess will be much faster, but inaccurate
  • Field Details

    • DAMAGE_UTILITY

      protected static final double DAMAGE_UTILITY
      See Also:
    • CRITICAL_UTILITY

      protected static final double CRITICAL_UTILITY
      See Also:
    • KILL_UTILITY

      protected static final double KILL_UTILITY
      See Also:
    • OVERHEAT_DISUTILITY

      protected static final double OVERHEAT_DISUTILITY
      See Also:
    • OVERHEAT_DISUTILITY_AERO

      protected static final double OVERHEAT_DISUTILITY_AERO
      See Also:
    • TSM_DESIRED_HEAT

      protected static final int TSM_DESIRED_HEAT
      See Also:
    • TSM_HEAT_CEILING

      protected static final int TSM_HEAT_CEILING
      See Also:
    • TSM_ACTIVATION_UTILITY

      protected static final double TSM_ACTIVATION_UTILITY
      See Also:
    • EJECTED_PILOT_DISUTILITY

      protected static final double EJECTED_PILOT_DISUTILITY
      See Also:
    • CIVILIAN_TARGET_DISUTILITY

      protected static final double CIVILIAN_TARGET_DISUTILITY
      See Also:
    • TARGET_HP_FRACTION_DEALT_UTILITY

      protected static final double TARGET_HP_FRACTION_DEALT_UTILITY
      See Also:
    • owner

      protected final Princess owner
  • Constructor Details

    • FireControl

      public FireControl(Princess owningPrincess)
      Constructor
      Parameters:
      owningPrincess - The Princess bot that utilizes this class for computing firing solutions.
  • Method Details

    • getAttackerMovementModifier

      @StaticWrapper protected ToHitData getAttackerMovementModifier(Game game, int shooterId, EntityMovementType shooterMoveType)
      Returns the movement modifier calculated by Compute.getAttackerMovementModifier(Game, int, EntityMovementType).
      Parameters:
      game - The current Game
      shooterId - The ID of the unit doing the shooting.
      shooterMoveType - The EntityMovementType of the unit doing the shooting.
      Returns:
      The attacker movement modifier as a ToHitData object.
    • getTargetMovementModifier

      @StaticWrapper protected ToHitData getTargetMovementModifier(int hexesMoved, boolean jumping, boolean airborneNonAerospace, Game game)
      Returns the movement modifier calculated by Compute.getTargetMovementModifier(int, boolean, boolean, Game)
      Parameters:
      hexesMoved - The number of hexes the target unit moved.
      jumping - Set TRUE if the target jumped.
      airborneNonAerospace - Set TRUE if the target is a VTOL or other airborne, non-aerospace unit.
      game - The current Game
      Returns:
      The target movement modifier as a ToHitData object.
    • isInArc

      @StaticWrapper protected boolean isInArc(Coords shooterPosition, int shooterFacing, Coords targetPosition, int weaponArc)
      Parameters:
      shooterPosition - The current Coords of the shooter.
      shooterFacing - The shooter's current facing.
      targetPosition - The current Coords of the target.
      weaponArc - The arc of the weapon being fired.
      Returns:
      TRUE if the target falls within the weapon's firing arc.
    • guessDistance

      protected int guessDistance(Entity shooter, EntityState shooterState, Targetable target, EntityState targetState, Game game)
      The range this guessed shot is resolved at, from a hypothetical shooter pose.

      Its own method so that CASPAR's aerospace gunnery can replace it without reproducing the rest of the to-hit guess. The stock behaviour is unchanged.

      Parameters:
      shooter - the unit doing the shooting
      shooterState - the pose the shooter would be firing from
      target - the unit being fired on
      targetState - the pose the target would be in
      game - the current game
      Returns:
      the range to look up on the weapon's range brackets
    • calcStrategicBuildingTargetUtility

      protected double calcStrategicBuildingTargetUtility(Targetable target, double expectedDamage)
    • calcPriorityUnitTargetUtility

      protected double calcPriorityUnitTargetUtility(Targetable target)
    • calcCivilianTargetDisutility

      protected double calcCivilianTargetDisutility(Targetable target)
    • calcCommandUtility

      protected double calcCommandUtility(Targetable target)
    • isCommander

      protected boolean isCommander(Entity entity)
    • isSubCommander

      protected boolean isSubCommander(Entity entity)
    • calcTargetPotentialDamageMultiplier

      protected double calcTargetPotentialDamageMultiplier(Targetable target)
      Calculates the logarithmic scaling factor for target damage potential in the utility equation, using the target's potential damage, the weight value TARGET_POTENTIAL_DAMAGE_UTILITY, and Princess's self-preservation value. This is mostly here to not clutter up the utility calculation method with all this extra math.
    • getDiveBombPlan

      protected FiringPlan getDiveBombPlan(Entity shooter, MovePath flightPath, Targetable target, Game game, boolean passedOverTarget, boolean guess)
      Creates a firing plan that fires dive bombs, dropping all bombs on the given target
      Parameters:
      shooter - The unit doing the shooting.
      target - The unit being fired on.
      game - The current Game
      passedOverTarget - Set TRUE to automatically assume the target will be under the flight path rather than going through the full calculation.
      guess - Whether we're just thinking about this firing plan or about to
      Returns:
      The FiringPlan containing all bombs on target, if the shooter is capable of dropping bombs.
    • calcHeatTolerance

      protected int calcHeatTolerance(Entity entity, @Nullable Boolean isAero)
    • calcHeatTolerance

      protected int calcHeatTolerance(Entity entity, @Nullable Boolean isAero, int predictedMovementHeat)
      Calculates how much weapon heat this unit is willing to generate before overheating becomes a disutility. The tolerance is lowered by every source of heat the engine will add this turn on top of the unit's current, already-resolved heat: heat already committed this turn (movement heat sits in Entity.heatBuildup once the unit has moved), the projected heat of a move still being evaluated (predictedMovementHeat), and predicted environmental heat from planetary temperature (see predictEnvironmentalHeat(Entity)). Extreme cold raises the tolerance, modelling the free cooling the engine grants below -30 C.
      Parameters:
      entity - the unit that would be firing
      isAero - true if the shooter is an Aero (stiffer overheat penalty), or null to derive it from entity
      predictedMovementHeat - heat the unit would gain from a move currently being evaluated but not yet committed (0 during the firing phase, where committed movement heat is already in Entity.heatBuildup)
      Returns:
      the overheat tolerance, or Entity.DOES_NOT_TRACK_HEAT for units that ignore heat
    • guessBestFiringPlanUnderHeat

      protected FiringPlan guessBestFiringPlanUnderHeat(Entity shooter, @Nullable EntityState shooterState, Targetable target, @Nullable EntityState targetState, int maxHeat, Game game)
      Guesses the 'best' firing plan under a certain heat No twisting is done
      Parameters:
      shooter - The unit doing the shooting.
      shooterState - The current state of the shooting unit.
      target - The unit being shot at.
      targetState - The current state of the target unit.
      maxHeat - How much heat we're willing to tolerate.
      game - The current Game
      Returns:
      the 'best' firing plan under a certain heat.
    • applyTsmHeatIncentive

      protected void applyTsmHeatIncentive(Entity shooter, FiringPlan firingPlan)
      Adds a utility bonus for a Mek carrying heat-activated standard Triple-Strength Myomer when a firing plan would bring its projected end-of-turn heat up to the TSM_DESIRED_HEAT activation threshold. TSM grants +2 walk MP and double physical damage, so a TSM Mek wants to run hot; this nudges it to fire enough to switch TSM on. The reward peaks at the threshold and tapers to zero at TSM_HEAT_CEILING, so the Mek stays as close to the threshold as it can rather than riding up into shutdown territory; heat past the ceiling gets no reward and the overheat disutility pulls it back. A plan that adds no weapon heat earns nothing, so a Mek already hot from passive sources is not nudged toward not firing. No effect on non-TSM Meks or on prototype/industrial TSM, which do not use the heat threshold.
      Parameters:
      shooter - the unit doing the shooting
      firingPlan - the plan whose utility is adjusted in place
    • firingActivatesTsm

      protected boolean firingActivatesTsm(Entity shooter, FiringPlan firingPlan)
      Reports whether firing this plan is what switches a heat-activated standard Triple-Strength Myomer on this turn: the shooter's projected end-of-turn heat reaches TSM_DESIRED_HEAT with the plan's heat but would fall short of it without. This lets callers keep an otherwise trivial heat-building shot instead of discarding it (for example, in favour of spotting for indirect fire). Returns false for non-TSM Meks, prototype/industrial TSM, and Meks already at or above the activation threshold on their own (which do not need the shot to stay active).
      Parameters:
      shooter - the unit doing the shooting
      firingPlan - the firing plan under consideration
      Returns:
      true if firing the plan activates standard TSM this turn, otherwise false
    • entityCanIndirectFireMissile

      public boolean entityCanIndirectFireMissile(FireControlState fireControlState, Entity shooter)
      Determines if the given entity can use indirect fire as in LRMs.
    • getSpotAction

      public SpotAction getSpotAction(FiringPlan plan, Entity spotter, FireControlState fireControlState)
      Determines if the given entity (potentially employing a given firing plan) can/should spot. If yes, then return a spot action.
    • getTargetableEnemyEntities

      protected List<Targetable> getTargetableEnemyEntities(Entity shooter, Game game, FireControlState fireControlState)
      Gets all the entities that are potential targets
      Parameters:
      shooter - The unit doing the shooting.
      game - The current Game
      Returns:
      A list of potential targets.
    • getMaxDamageAtRange

      public static double getMaxDamageAtRange(Entity shooter, int range, boolean useExtremeRange, boolean useLOSRange)
      Calculates the maximum damage a unit can do at a given range. Chance to hit is not a factor.
      Parameters:
      shooter - The firing unit.
      range - The range to be checked.
      useExtremeRange - Is the extreme range optional rule in effect?
      Returns:
      The most damage done at that range.
    • correctFacing

      public static int correctFacing(int facing)
      makes sure facing falls between 0 and 5 This function likely already exists somewhere else
      Parameters:
      facing - The facing to be corrected.
      Returns:
      The properly adjusted facing.
    • getValidFacingChanges

      public static List<Integer> getValidFacingChanges(Entity shooter)
    • getUnjamWeaponPlan

      public Vector<EntityAction> getUnjamWeaponPlan(Entity shooter)
      This function evaluates whether or not a unit should spend its time unjamming weapons instead of firing, and returns the appropriate firing plan if that's the case.
      Parameters:
      shooter - Entity being considered.
      Returns:
      Unjam action plan, if we conclude that we should spend time unjamming weapons.
    • getFindClubAction

      @Nullable public FindClubAction getFindClubAction(Entity shooter)
      Return a "Find Club" action, if the unit in question can find a club.
    • getSearchLightAction

      public SearchlightAttackAction getSearchLightAction(Entity shooter, FiringPlan plan)
      Given a firing plan, calculate the best target to light up with a searchlight
    • effectivelyAmmoless

      protected static boolean effectivelyAmmoless(WeaponType weaponType)
      Parameters:
      weaponType - that uses ammo that is not tracked, or not actually ammo
      Returns:
      true if weaponType doesn't actually track ammo