Class UnitBehavior

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

public class UnitBehavior extends Object
  • Constructor Details

    • UnitBehavior

      public UnitBehavior()
  • Method Details

    • isFleeOrdered

      public static boolean isFleeOrdered(Princess owner)
      Returns whether the bot has a standing order to flee toward an edge, given from the Bot Commands panel or the flee chat command.
      Parameters:
      owner - the bot
      Returns:
      true if every unit of the bot is ordered toward the bot's destination edge
    • isFollowingOrdersOverWithdrawal

      public boolean isFollowingOrdersOverWithdrawal(Entity entity, Princess owner)
      Returns whether a withdrawing unit follows the player's orders instead of heading for its retreat edge.

      A player's direct order outranks the unit's own Forced Withdrawal: a crippled unit sent to a hex or an edge goes there (issue #9038). A gamemaster's order to withdraw still wins over everything, and the bot-wide flee order wins over a route, sending a withdrawing unit toward the ordered edge instead.

      Parameters:
      entity - the unit
      owner - the bot that owns the unit
      Returns:
      true if the unit is withdrawing under the bot's rules but has orders to follow instead
    • getActiveWaypoint

      public Optional<Coords> getActiveWaypoint(Entity entity, Princess owner)
      Returns the waypoint that decides where the unit moves this phase, if a waypoint does. An edge order, a bot-wide flee order and a withdrawal the player has not overridden all send the unit to an edge instead, so they return empty.
      Parameters:
      entity - the unit
      owner - the bot that owns the unit
      Returns:
      the unit's current waypoint when it is following its route, otherwise empty
    • beginRanking

      public void beginRanking(Entity entity, Princess owner)
      Works out a unit's active waypoint once before its moves are ranked, and answers with it until endRanking(): the path ranker asks for it four or five times for every move it scores.
      Parameters:
      entity - the unit about to have its moves ranked
      owner - the bot that owns the unit
    • endRanking

      public void endRanking()
      Ends the waypoint snapshot beginRanking(megamek.common.units.Entity, megamek.client.bot.princess.Princess) took, once the unit's moves are ranked.
    • getBehaviorType

      public UnitBehavior.BehaviorType getBehaviorType(Entity entity, Princess owner)
      Gets (and calculates, if necessary), the behavior type for the given entity.
    • getCachedBehaviorType

      @Nullable public UnitBehavior.BehaviorType getCachedBehaviorType(Entity entity)
      The behavior already worked out for this unit, without working one out if none has been.

      For logging and analysis only. getBehaviorType(megamek.common.units.Entity, megamek.client.bot.princess.Princess) computes and caches on a miss, and what it computes depends on where everything is standing at the time - so asking early, for a unit that has not moved yet, would pin an answer the bot would otherwise have reached later with better information.

      Parameters:
      entity - the unit to look up
      Returns:
      the cached behavior, or null if this unit has not been evaluated this turn
    • overrideBehaviorType

      public void overrideBehaviorType(Entity entity, UnitBehavior.BehaviorType behaviorType)
    • getWaypointForEntity

      public Optional<Coords> getWaypointForEntity(Entity entity)
      Parameters:
      entity - the unit
      Returns:
      the next waypoint of the unit's route, which is stored on the unit, or empty when it has none
    • isDestinationValidForEntity

      public boolean isDestinationValidForEntity(Entity entity, Coords destination, Princess owner)
    • addEntityWaypoint

      public int addEntityWaypoint(Entity entity, List<Coords> waypoints, Princess owner)
      Adds waypoints to the end of the unit's route, dropping any the unit cannot reach. The route is stored on the unit and sent to the server.
      Returns:
      how many of the given waypoints were kept; 0 when none of them can be reached
    • addEntityWaypoint

      @Deprecated(since="0.51.0", forRemoval=true) public boolean addEntityWaypoint(Entity entity, Coords destination, Princess owner)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • removeTailWaypoint

      public void removeTailWaypoint(Entity entity, Princess owner)
      Removes the last waypoint of the unit's route, good for an "undo" behavior.
      Parameters:
      entity - the unit
      owner - the bot that owns the unit
    • setEntityWaypoints

      public int setEntityWaypoints(Entity entity, List<Coords> waypoints, Princess owner)
      Replaces the unit's route with the given waypoints, dropping any the unit cannot reach. The route is stored on the unit and sent to the server.
      Returns:
      how many of the given waypoints were kept; 0 when none of them can be reached, in which case the unit's orders are left as they were
    • clearWaypoints

      public void clearWaypoints(Entity entity, Princess owner)
      Clears all of one unit's orders.
      Parameters:
      entity - the unit
      owner - the bot that owns the unit
    • clearWaypoints

      public void clearWaypoints(Princess owner)
      Clears the orders of every unit of the bot.
      Parameters:
      owner - the bot
    • clear

      public void clear()
      Clears the entity behavior cache, should be done at the start of each movement phase