Class BotClient

All Implemented Interfaces:
IClient
Direct Known Subclasses:
Princess

public abstract class BotClient extends Client
  • Field Details

    • BOT_TURN_RETRY_COUNT

      public static final int BOT_TURN_RETRY_COUNT
      See Also:
    • frame

      public JFrame frame
    • rerolledInitiative

      protected boolean rerolledInitiative
    • behaviorSettings

      protected BehaviorSettings behaviorSettings
      The bot's personality/configuration state. Held on BotClient because it is generic bot-personality state (sliders, targeting, retreat edges) shared by every bot implementation, not specific to any one AI. Initialized to a default so it is never null: subclasses normally replace it via setBehaviorSettings(BehaviorSettings) during construction, but the default preserves the non-null contract that getBehaviorSettings() callers rely on even if a subclass does not.
    • boardClusterTracker

      protected BoardClusterTracker boardClusterTracker
  • Constructor Details

    • BotClient

      public BotClient(String playerName, String host, int port)
  • Method Details

    • getAIType

      public AIType getAIType()
      Which AI implementation this bot is. Reported to the server alongside the bot's settings so a savegame remembers what kind of bot held each seat, and shown by the bot config dialog so it tells the truth about a running bot instead of assuming Princess. Subclasses that are their own AI type override this.
      Returns:
      this bot's AIType
    • isBot

      public boolean isBot()
      Overrides:
      isBot in class AbstractClient
    • initialize

      public abstract void initialize()
    • processChat

      protected abstract void processChat(GamePlayerChatEvent ge)
    • initMovement

      protected abstract void initMovement()
    • initFiring

      protected abstract void initFiring()
    • calculateMoveTurn

      protected abstract MovePath calculateMoveTurn()
      Determines which entity should be moved next and then calls to continueMovementFor(Entity) with that entity.
      Returns:
      The calculated move path.
      Throws:
      NullPointerException - if no entity can be found to move.
    • calculateFiringTurn

      protected abstract void calculateFiringTurn()
    • calculateDeployment

      protected abstract void calculateDeployment() throws Exception
      Throws:
      Exception
    • getBehaviorSettings

      public BehaviorSettings getBehaviorSettings()
      Returns:
      this bot's current behavior settings (personality/configuration state)
    • setBehaviorSettings

      public abstract void setBehaviorSettings(BehaviorSettings behaviorSettings)
      Applies the given behavior settings to this bot. Implementations decide how the settings take effect (for example, re-initializing scorers or notifying the server) and are responsible for storing them in behaviorSettings.
      Parameters:
      behaviorSettings - the new behavior settings to apply
    • initTargeting

      protected void initTargeting()
    • calculateTargetingOffBoardTurn

      protected void calculateTargetingOffBoardTurn()
      Calculates the targeting/off board turn This includes firing TAG and non-direct-fire artillery Does nothing in this implementation.
    • calculatePrePhaseTurn

      protected void calculatePrePhaseTurn()
      Calculates the pre phase turn. In Standard ghost target mode during PRE_FIRING, assigns ghost targets for any qualifying equipment. Otherwise just ends the turn.
    • calculatePhysicalTurn

      @Nullable protected abstract PhysicalOption calculatePhysicalTurn()
    • calculatePreEndDeclarationsTurn

      protected abstract void calculatePreEndDeclarationsTurn()
      Calculate what to do during the PRE_END_DECLARATIONS phase. This phase allows infantry to initiate building/vessel combat.
    • calculateInfantryVsInfantryCombatTurn

      protected abstract void calculateInfantryVsInfantryCombatTurn()
      Calculate what to do during the INFANTRY_VS_INFANTRY_COMBAT phase. This phase allows infantry to reinforce or withdraw from building/vessel combat.
    • calculatePointBlankShot

      protected Vector<EntityAction> calculatePointBlankShot(int firingEntityID, int targetID)
    • pickTagTarget

      protected int pickTagTarget(GameCFREvent evt)
    • continueMovementFor

      protected abstract MovePath continueMovementFor(Entity entity)
      Calculates the full MovePath for the given Entity.
      Parameters:
      entity - The entity who is to move.
      Returns:
      The calculated move path.
      Throws:
      NullPointerException - if entity is NULL.
    • calculateArtyAutoHitHexes

      protected abstract Vector<BoardLocation> calculateArtyAutoHitHexes()
    • checkMorale

      protected abstract void checkMorale()
    • keepGameLog

      protected boolean keepGameLog()
      Description copied from class: AbstractClient
      Called to determine whether the game log should be kept. Default implementation delegates to PreferenceManager.getClientPreferences().
      Overrides:
      keepGameLog in class AbstractClient
      Returns:
      True/False if the game log is to be kept.
    • getStrandedEntities

      public int[] getStrandedEntities()
      Helper function that determines which of this bot's entities are stranded inside immobilized transports.
      Returns:
      Array of entity IDs.
    • getEntitiesOwned

      public List<Entity> getEntitiesOwned()
    • getArbitraryEntity

      protected Entity getArbitraryEntity()
    • getEnemyEntities

      public List<Entity> getEnemyEntities()
      Lazy-loaded list of enemy entities that we should consider firing at. Only good for the current entity turn calculation, as this list can change between individual entity turns.
    • getFriendEntities

      public List<Entity> getFriendEntities()
      Lazy-loaded list of friendly entities. Only good for the current entity turn calculation, as this list can change between individual entity turns.
    • connectOwnTrains

      protected void connectOwnTrains()
    • changePhase

      public void changePhase(GamePhase phase)
      Description copied from class: Client
      Changes the game phase, and the displays that go along with it.
      Overrides:
      changePhase in class Client
      Parameters:
      phase - the phase switching from.
    • postMovementProcessing

      protected abstract void postMovementProcessing()
    • getMassOfAllInBuilding

      public double getMassOfAllInBuilding(Game game, Coords coords, int boardId)
      Returns:
      The total weight of all units in or on the building or bridge (but not fuel tank) at the given map location. If the given position doesn't exist, returns 0. Only units weighing on the building count, not those flying above it.
    • getFirstValidCoords

      @Nullable protected Coords getFirstValidCoords(Entity deployedUnit, List<Coords> possibleDeployCoords)
      Gets valid and empty starting coords around the specified point. This method iterates through the list of Coords and returns the first Coords that does not have a stacking violation.
    • getStartingCoordsArray

      protected List<Coords> getStartingCoordsArray(Entity deployed_ent)
    • doAlertDialog

      public void doAlertDialog(String title, String message)
      Pops up a dialog box showing an alert
    • correctName

      protected void correctName(Packet inP)
      Overrides:
      correctName in class AbstractClient
    • setClientGUI

      public void setClientGUI(ClientGUI clientGUI)
    • endOfTurnProcessing

      public void endOfTurnProcessing()
    • performVictorySetupTurn

      protected void performVictorySetupTurn()
      Takes this bot's turn in the Victory Setup phase. The default sends the game's ground objects back unchanged, which ends the turn without placing anything: control points assigned to this bot before the game began (by MekHQ, a scenario file, or in the lobby) are already on the board when this phase runs, so a bot has nothing it must do here. Bot implementations that want to choose or adjust their own control points (Princess, CASPAR) override this, edit the ground objects, and send the result - the send is the turn action that ends the bot's turn, so every override MUST end with Client.sendDeployGroundObjects(java.util.Map<megamek.common.board.Coords, java.util.List<megamek.common.equipment.ICarryable>>).
    • deployMinefields

      protected void deployMinefields()
    • receiveReport

      public String receiveReport(List<Report> reports)
      The bot client doesn't really need a text report Let's save ourselves a little processing time and not deal with any of it
      Overrides:
      receiveReport in class Client
    • receiveEntityUpdate

      protected void receiveEntityUpdate(Packet packet) throws InvalidPacketDataException
      In addition to handling the entity update normally, the bot needs to decide if it should activate its hidden units
      Overrides:
      receiveEntityUpdate in class Client
      Throws:
      InvalidPacketDataException
    • revealEntities

      protected void revealEntities(int movedEntityID)
      Given an entity that just moved, decide if I should reveal any entities in response
    • decideToRerollInitiative

      protected boolean decideToRerollInitiative()
      Let the bot decide whether to reroll initiative based on report info
      Returns:
      true if Tactical Genius A) is available, B) hasn't been used already, and C) would improve our initiative vs enemy players; otherwise return false.
    • cacheImgTag

      protected void cacheImgTag(Entity entity)
      The bot client has no need of image tag caching Let's save ourselves some CPU and memory and not deal with it
      Overrides:
      cacheImgTag in class Client
    • getClusterTracker

      public BoardClusterTracker getClusterTracker()