Package megamek.client.bot
Class BotClient
java.lang.Object
megamek.client.AbstractClient
megamek.client.Client
megamek.client.bot.BotClient
- All Implemented Interfaces:
IClient
- Direct Known Subclasses:
Princess
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class megamek.client.AbstractClient
AbstractClient.ConnectionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BehaviorSettingsThe bot's personality/configuration state.protected BoardClusterTrackerstatic final intprotected booleanFields inherited from class megamek.client.AbstractClient
awaitingSave, bots, connected, connection, connectionListener, connThread, disconnectFlag, host, iconCache, localPlayerNumber, log, name, phaseReport, port, roundReport, unitNameTracker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcacheImgTag(Entity entity) The bot client has no need of image tag caching Let's save ourselves some CPU and memory and not deal with itprotected abstract Vector<BoardLocation> protected abstract voidprotected abstract voidprotected abstract voidCalculate what to do during the INFANTRY_VS_INFANTRY_COMBAT phase.protected abstract MovePathDetermines which entity should be moved next and then calls tocontinueMovementFor(Entity)with that entity.protected abstract PhysicalOptionprotected Vector<EntityAction> calculatePointBlankShot(int firingEntityID, int targetID) protected abstract voidCalculate what to do during the PRE_END_DECLARATIONS phase.protected voidCalculates the pre phase turn.protected voidCalculates the targeting/off board turn This includes firing TAG and non-direct-fire artillery Does nothing in this implementation.voidchangePhase(GamePhase phase) Changes the game phase, and the displays that go along with it.protected abstract voidprotected voidprotected abstract MovePathcontinueMovementFor(Entity entity) protected voidcorrectName(Packet inP) protected booleanLet the bot decide whether to reroll initiative based on report infoprotected voidvoiddoAlertDialog(String title, String message) Pops up a dialog box showing an alertvoidWhich AI implementation this bot is.protected EntityLazy-loaded list of enemy entities that we should consider firing at.protected CoordsgetFirstValidCoords(Entity deployedUnit, List<Coords> possibleDeployCoords) Gets valid and empty starting coords around the specified point.Lazy-loaded list of friendly entities.doublegetMassOfAllInBuilding(Game game, Coords coords, int boardId) getStartingCoordsArray(Entity deployed_ent) int[]Helper function that determines which of this bot's entities are stranded inside immobilized transports.protected abstract voidabstract voidprotected abstract voidprotected voidbooleanisBot()protected booleanCalled to determine whether the game log should be kept.protected voidTakes this bot's turn in the Victory Setup phase.protected intprotected abstract voidprotected abstract voidprotected voidreceiveEntityUpdate(Packet packet) In addition to handling the entity update normally, the bot needs to decide if it should activate its hidden unitsreceiveReport(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 itprotected voidrevealEntities(int movedEntityID) Given an entity that just moved, decide if I should reveal any entities in responseabstract voidsetBehaviorSettings(BehaviorSettings behaviorSettings) Applies the given behavior settings to this bot.voidsetClientGUI(ClientGUI clientGUI) Methods inherited from class megamek.client.Client
canUnloadStranded, changeTurnIndex, deploy, getAvailableMapSizes, getBoard, getBoard, getEntitiesVector, getEntity, getFirstDeployableEntityNum, getFirstEntityNum, getGame, getMapSettings, getMyTurn, getNextDeployableEntityNum, getNextEntityNum, getPrevEntityNum, getSelectedEntities, getSkillGenerator, handleGameSpecificPacket, isMyTurn, moveEntity, receiveAttack, receiveBuildingAdd, receiveBuildingCollapse, receiveBuildingRemove, receiveBuildingUpdate, receiveDeployMinefields, receiveEntities, receiveEntitiesUpdate, receiveEntityRemove, receiveEntityVisibilityIndicator, receiveForcesDelete, receiveForceUpdate, receiveIlluminatedHexes, receivePrincessDishonored, receiveRemoveMinefield, receiveRevealMinefield, receiveSendingMinefields, receiveTurns, receiveUpdateCutHexes, receiveUpdateGroundObjects, receiveUpdateIndustrialElevators, receiveUpdateMinefields, sendActivateHidden, sendAddEntitiesToForce, sendAddEntity, sendAddForce, sendAddSquadron, sendAmmoChange, sendAMSAssignCFRResponse, sendAPDSAssignCFRResponse, sendArtyAutoHitHexes, sendAssignForceFull, sendAttackData, sendBotSettingsToServer, sendBuildingEdit, sendBuildTrain, sendCalledShotChange, sendChangeOwner, sendChangeTeam, sendChargeLevelChange, sendCustomInit, sendDamageEdit, sendDeleteEntities, sendDeleteEntity, sendDeleteForces, sendDeployBridge, sendDeployFortifications, sendDeployGroundObjects, sendDeploymentUnload, sendDeployMinefields, sendDominoCFRResponse, sendEjectionSettingChange, sendEntityWeaponOrderUpdate, sendExplodeBuilding, sendForceParent, sendGameOptions, sendGhostTargetAction, sendHexEdit, sendHiddenPBSCFRResponse, sendInfantryActionDeclaration, sendLoadEntity, sendLoadGame, sendLobbyBoardGenerationRequest, sendMapDimensions, sendMapSettings, sendModeChange, sendMountFacingChange, sendNovaChange, sendPlanetaryConditions, sendPlayerPickedPassThrough, sendPrePhaseData, sendRerollInitiativeRequest, sendResetRoundDeployment, sendSensorChange, sendSinksChange, sendSpecialHexDisplayAppend, sendSpecialHexDisplayDelete, sendSystemModeChange, sendTAGTargetCFRResponse, sendTelemissileTargetCFRResponse, sendTowEntity, sendUnitAbandonmentAnnouncement, sendUnloadStranded, sendUpdateEntity, sendUpdateEntity, sendUpdateForce, sendUpdateForce, sendVariableRangeTargetingModeChange, setSkillGeneratorMethods inherited from class megamek.client.AbstractClient
addCloseClientListener, checkDuplicateNamesDuringAdd, connect, die, disconnected, fireSaveCompleted, flushConn, getBots, getHost, getLocalPlayerNumber, getName, getPort, handleGameIndependentPacket, handlePacket, initGameLog, isAwaitingSave, isConnected, memDump, possiblyWriteToLog, receivePlayerInfo, receiveUnitReplace, send, sendArtilleryRevealPreference, sendChat, sendDone, sendNextPlayer, sendPause, sendPlayerInfo, sendPlayerInfo, sendServerChat, sendUnpause, setAwaitingSave, setLocalPlayerNumber, setName, setSaveCompletionCallback, updateConnectionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface megamek.client.IClient
getBotClient, getInGameObject, getInGameObjects, getLocalPlayer, getPlayer, isLocalBot, playerExists
-
Field Details
-
BOT_TURN_RETRY_COUNT
public static final int BOT_TURN_RETRY_COUNT- See Also:
-
frame
-
rerolledInitiative
protected boolean rerolledInitiative -
behaviorSettings
The bot's personality/configuration state. Held onBotClientbecause 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 nevernull: subclasses normally replace it viasetBehaviorSettings(BehaviorSettings)during construction, but the default preserves the non-null contract thatgetBehaviorSettings()callers rely on even if a subclass does not. -
boardClusterTracker
-
-
Constructor Details
-
BotClient
-
-
Method Details
-
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:
isBotin classAbstractClient
-
initialize
public abstract void initialize() -
processChat
-
initMovement
protected abstract void initMovement() -
initFiring
protected abstract void initFiring() -
calculateMoveTurn
Determines which entity should be moved next and then calls tocontinueMovementFor(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
- Throws:
Exception
-
getBehaviorSettings
- Returns:
- this bot's current behavior settings (personality/configuration state)
-
setBehaviorSettings
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 inbehaviorSettings.- 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
-
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
-
pickTagTarget
-
continueMovementFor
- Parameters:
entity- The entity who is to move.- Returns:
- The calculated move path.
- Throws:
NullPointerException- if entity is NULL.
-
calculateArtyAutoHitHexes
-
checkMorale
protected abstract void checkMorale() -
keepGameLog
protected boolean keepGameLog()Description copied from class:AbstractClientCalled to determine whether the game log should be kept. Default implementation delegates toPreferenceManager.getClientPreferences().- Overrides:
keepGameLogin classAbstractClient- 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
-
getArbitraryEntity
-
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
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
Description copied from class:ClientChanges the game phase, and the displays that go along with it.- Overrides:
changePhasein classClient- Parameters:
phase- the phase switching from.
-
postMovementProcessing
protected abstract void postMovementProcessing() -
getMassOfAllInBuilding
- 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
-
doAlertDialog
Pops up a dialog box showing an alert -
correctName
- Overrides:
correctNamein classAbstractClient
-
setClientGUI
-
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 withClient.sendDeployGroundObjects(java.util.Map<megamek.common.board.Coords, java.util.List<megamek.common.equipment.ICarryable>>). -
deployMinefields
protected void deployMinefields() -
receiveReport
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:
receiveReportin classClient
-
receiveEntityUpdate
In addition to handling the entity update normally, the bot needs to decide if it should activate its hidden units- Overrides:
receiveEntityUpdatein classClient- 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
The bot client has no need of image tag caching Let's save ourselves some CPU and memory and not deal with it- Overrides:
cacheImgTagin classClient
-
getClusterTracker
-