Package megamek.common.autoResolve.acar
Class SimulationContext
java.lang.Object
megamek.common.autoResolve.acar.SimulationContext
- All Implemented Interfaces:
IGame,PlanetaryConditionsUsing
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected Forcesprotected final ConcurrentHashMap<Integer, InGameObject> protected final ConcurrentHashMap<Integer, Player> protected intFields inherited from interface megamek.common.game.IGame
DEFAULT_BOARD_ID, LOGGER -
Constructor Summary
ConstructorsConstructorDescriptionSimulationContext(SimulationOptions gameOptions, SetupForces setupForces, Board board, PlanetaryConditions planetaryConditions) SimulationContext(SimulationOptions gameOptions, SetupForces setupForces, Board board, PlanetaryConditions planetaryConditions, long seed) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified action to the list of pending EntityActions for this phase and fires a GameNewActionEvent.voidaddActionHandler(ActionHandler handler) voidvoidaddGameListener(GameListener listener) Adds a GameListener to this game.voidAdds the given Player to the game with the given game-unique id.voidaddUnit(InGameObject unit) voidaddUnitToGraveyard(Entity entity) voidapplyDamageToEntityFromUnit(SBFUnit unit, Entity entity, EntityFinalState entityFinalState) clamp(BoardLocation location) voidEmpties the list of pending EntityActions completely.voidClear this round from this list of entities to deployvoidfireGameEvent(GameEvent event) Fires the given GameEvent, sending the event to all GameListener of this game.booleanReturns the pending EntityActions.Returns the list of formations that are in the game's InGameObject list, i.e.getActiveFormations(int playerId) getActiveFormations(Player player) Returns the complete map of boardIds/boards the game uses.intintgetEntity(int id) getFormation(int formationID) Returns the formation of the given ID, if one can be found.intgetLiveDeployedEntitiesOwnedBy(Player player) getNewReport(int messageId) Returns a new ReportEntry with the given report message ID.intintintintgetPhase()getPlayer(int id) getPlayerSkill(int playerId) Deprecated, for removal: This API element is subject to removal in a future version.longgetSeed()intgetSelectedEntityCount(EntitySelector selector) intgetStartingNumberOfUnits(int playerId) getTeams()getTurn()intReturns the current turn index, i.e.booleanhasBoard(int boardId) Returns true if the given bboard ID is an actual board in the game.booleanhasBoard(BoardLocation boardLocation) Returns true if the given boardLocation points to an existing board, i.e.booleanhasBoardLocation(BoardLocation boardLocation) Returns true if the given boardLocation really exists, i.e.booleanhasBoardLocation(Coords coords, int boardId) Returns true if the given coords and boardID really exist, are not null, the board ID is an actual board in the game and the coords are contained in that board.booleanbooleanvoidAdds 1 to the current round value.booleanReturns true when the current game phase should be played, meaning it is played in the current type of game and there are possible actions in it in the present game state.booleanbooleanbooleanisOutOfGame(int id) intvoidreceiveBoard(int boardId, Board board) Sets the given board as the game's board with the given boardId, possibly replacing the former board of the same id.voidreceiveBoards(Map<Integer, Board> boards) Sets the given boards as the game's boards, replacing all previous boards.voidreceivePhase(GamePhase phase) Sets the current game phase to the given phase.voidremoveAction(Action action) Deprecated, for removal: This API element is subject to removal in a future version.voidremoveActionsFor(int id) Removes all pending EntityActions by the InGameObject (Entity, unit) of the given ID from the list of pending actions.voidremoveEntity(Entity entity) voidremoveFormation(Formation formation) voidremoveGameListener(GameListener listener) Removes the specified game listener.voidremovePlayer(int id) Removes the player with the id from the game.voidreplaceUnits(List<InGameObject> units) This is a Client-side method to replace or add units that are sent from the server.voidreset()Resets this game, i.e.voidResets the turn index toAWAITING_FIRST_TURNvoidSets the given board as the game's board with the given boardId, possibly replacing the former board of the same id.voidsetBoardLocation(BoardLocation boardLocation, Formation formation) voidsetCurrentRound(int currentRound) Sets the current game round to the given round number.voidReplaces the game's Forces with the given forces.voidsetFormationAt(Formation formation, BoardLocation position) voidsetLastPhase(GamePhase lastPhase) Sets the previous game phase to the given phase.voidSets the current game phase to the given phase.voidsetPlanetaryConditions(PlanetaryConditions conditions) Sets this game's planetary conditions.voidSets the given Player to the given game-unique id.voidsetPlayerSkillLevel(int playerId, SkillLevel averageSkillLevel) protected voidsetTurnIndex(int turnIndex) Deprecated, for removal: This API element is subject to removal in a future version.voidvoidClears and re-calculates the deployment table, i.e.voidbooleanshouldDeployForRound(int round) booleanCheck to see if we should deploy this roundMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface megamek.common.game.IGame
addScriptedEvent, areConnectedBoards, boardExists, commonEnclosingBoard, connectBoards, getAllEnclosingBoards, getBoard, getBoard, getBoard, getBoard, getEnclosingBoard, getEnclosingBoard, getEntitiesOwnedBy, getEntityFromAllSources, getHex, getHex, getHexOf, getInGameObject, getInGameObjects, getOutOfGameUnit, getTeamByPlayer, getTeamForPlayer, hasBoardLocationOf, hasConnectedBoard, hasEnclosingBoard, hasGroundBoard, hasNonSpaceBoard, hasPlayer, hasSpaceAndAtmosphericBoards, hasSpaceBoard, isOnAtmosphericMap, isOnAtmosphericMap, isOnGroundMap, isOnGroundMap, isOnSpaceMap, isOnSpaceMap, onConnectedBoards, onDirectlyConnectedBoards, onTheSameBoard, shouldSkipCurrentPhase
-
Field Details
-
inGameObjects
-
players
-
teams
-
forces
-
currentRound
protected int currentRound -
turnIndex
protected int turnIndex
-
-
Constructor Details
-
SimulationContext
public SimulationContext(SimulationOptions gameOptions, SetupForces setupForces, Board board, PlanetaryConditions planetaryConditions) -
SimulationContext
public SimulationContext(SimulationOptions gameOptions, SetupForces setupForces, Board board, PlanetaryConditions planetaryConditions, long seed)
-
-
Method Details
-
getOrders
-
addUnit
-
inGameTWEntities
- Returns:
- The TW Units (Entity) currently in the game.
-
deployableInGameObjects
-
getNoOfEntities
public int getNoOfEntities() -
getStartingNumberOfUnits
public int getStartingNumberOfUnits(int playerId) -
getSelectedEntityCount
-
getPlayerSkill
Deprecated, for removal: This API element is subject to removal in a future version. -
getNextEntityId
public int getNextEntityId()- Specified by:
getNextEntityIdin interfaceIGame- Returns:
- The next free ID for InGameObjects (unit/entity/formation/others).
-
getEntity
- Returns:
- The entity with the given id number, if any.
-
addEntity
-
isOutOfGame
public boolean isOutOfGame(int id) -
getTurnsList
- Specified by:
getTurnsListin interfaceIGame- Returns:
- the current list of turns. If you're not the GameManager, don't even think about changing any of the turns.
-
getOptions
- Specified by:
getOptionsin interfaceIGame
-
getPhase
-
addActionHandler
-
getTurn
-
getCurrentTurn
-
hasMoreTurns
public boolean hasMoreTurns()- Specified by:
hasMoreTurnsin interfaceIGame- Returns:
- True when there is at least one more player turn waiting to be played in the current game phase. //TODO this code from Game is surprising; the last available turn should be at size()-1, but apparently this works
-
setTurns
-
setPhase
Description copied from interface:IGameSets the current game phase to the given phase. May perform phase-dependent cleanup. This method is intended for the GameManager. -
setLastPhase
Description copied from interface:IGameSets the previous game phase to the given phase. This method is intended for the GameManager.- Specified by:
setLastPhasein interfaceIGame- Parameters:
lastPhase- The phase to be remembered as the previous phase.
-
receivePhase
Description copied from interface:IGameSets the current game phase to the given phase. May perform phase-dependent cleanup and fire game events. This method is intended for the Client. By default, this method callsIGame.setPhase(GamePhase). When overridden, it'll usually make sense to call super(phase).- Specified by:
receivePhasein interfaceIGame- Parameters:
phase- The new phase
-
isCurrentPhasePlayable
public boolean isCurrentPhasePlayable()Description copied from interface:IGameReturns true when the current game phase should be played, meaning it is played in the current type of game and there are possible actions in it in the present game state. The result may be different in other rounds.- Specified by:
isCurrentPhasePlayablein interfaceIGame- Returns:
- True when the current phase should be skipped entirely in this round
- See Also:
-
setPlayer
Description copied from interface:IGameSets the given Player to the given game-unique id. // TODO : Is this method useful? Why not use addPlayer that also sets single-blind info? -
removePlayer
public void removePlayer(int id) Description copied from interface:IGameRemoves the player with the id from the game.- Specified by:
removePlayerin interfaceIGame- Parameters:
id- The player id
-
setupTeams
public void setupTeams()- Specified by:
setupTeamsin interfaceIGame
-
replaceUnits
Description copied from interface:IGameThis is a Client-side method to replace or add units that are sent from the server. Adds the given units to the list of units or objects in the current game. When a unit's ID is already present the currently assigned unit will be replaced with the given new one.- Specified by:
replaceUnitsin interfaceIGame- Parameters:
units- The units to add or use as a replacement for current units.
-
getGraveyard
- Specified by:
getGraveyardin interfaceIGame- Returns:
- a list of units that are destroyed or otherwise no longer part of the game. These should have a reason for their removal set.
-
getRetreatingUnits
-
getLiveDeployedEntitiesOwnedBy
-
getNewReport
Description copied from interface:IGameReturns a new ReportEntry with the given report message ID. The ReportEntry subclass returned depends on the implementation in the IGame subclass.- Specified by:
getNewReportin interfaceIGame- Parameters:
messageId- The message ID from report-messages.properties- Returns:
- A new report of an appropriate type and message
-
scriptedEvents
- Specified by:
scriptedEventsin interfaceIGame- Returns:
- All scripted events present in this game. Note that these will typically only be present on the Server side and the Clients will only receive the results of those events.
-
gameTimerIsExpired
public boolean gameTimerIsExpired() -
getActionHandlers
-
changeToNextTurn
-
hasEligibleFormation
-
getFormation
Returns the formation of the given ID, if one can be found.- Parameters:
formationID- the ID to look for- Returns:
- The formation or an empty Optional
-
getLastPhase
-
getActiveFormations
Returns the list of formations that are in the game's InGameObject list, i.e. that aren't destroyed or otherwise removed from play.- Returns:
- The currently active formations
-
getActiveDeployedFormations
-
getActiveFormations
-
getActiveFormations
-
addUnitToGraveyard
-
setPlayerSkillLevel
-
getLocalPlayer
-
getForces
-
getPlayer
-
addPlayer
Description copied from interface:IGameAdds the given Player to the game with the given game-unique id. // TODO : Can this be made a default method? -
getPlayersList
- Specified by:
getPlayersListin interfaceIGame- Returns:
- The current players as a list. Implementations should make sure that this list can be safely modified.
-
getNoOfPlayers
public int getNoOfPlayers()- Specified by:
getNoOfPlayersin interfaceIGame- Returns:
- The current number of active players in the game. This includes observers but not ghosts.
-
getTeams
-
getNoOfTeams
public int getNoOfTeams()- Specified by:
getNoOfTeamsin interfaceIGame- Returns:
- The number of teams in the game.
-
getInGameObjects
- Specified by:
getInGameObjectsin interfaceIGame- Returns:
- A list of all InGameObjects of this game. This list is copied and may be safely modified.
-
removeFormation
-
applyDamageToEntityFromUnit
public void applyDamageToEntityFromUnit(SBFUnit unit, Entity entity, EntityFinalState entityFinalState) -
removeEntity
-
addGameListener
Description copied from interface:IGameAdds a GameListener to this game. The GameListener will receive any subsequently fired GameEvents.- Specified by:
addGameListenerin interfaceIGame- Parameters:
listener- The GameListener to add
-
removeGameListener
Description copied from interface:IGameRemoves the specified game listener.- Specified by:
removeGameListenerin interfaceIGame- Parameters:
listener- the game listener.
-
isForceVictory
public boolean isForceVictory()- Specified by:
isForceVictoryin interfaceIGame- Returns:
- Whether there is an active claim for victory.
-
fireGameEvent
Description copied from interface:IGameFires the given GameEvent, sending the event to all GameListener of this game.- Specified by:
fireGameEventin interfaceIGame- Parameters:
event- the game event.
-
receiveBoard
Description copied from interface:IGameSets the given board as the game's board with the given boardId, possibly replacing the former board of the same id. This method is written with the idea that a game might have more than one board. This method is meant as a client-side method and may fire game events.- Specified by:
receiveBoardin interfaceIGame- Parameters:
boardId- (currently ignored) The boardId to assign to that boardboard- The board to use
-
receiveBoards
Description copied from interface:IGameSets the given boards as the game's boards, replacing all previous boards. This method is written with the idea that a game might have more than one board. This method is meant as a client-side method and may fire game events.- Specified by:
receiveBoardsin interfaceIGame- Parameters:
boards- The new boards
-
setBoard
Description copied from interface:IGameSets the given board as the game's board with the given boardId, possibly replacing the former board of the same id. This method is written with the idea that a game might have more than one board. Game's legacy methods of setBoard() and getBoard() use the boardId 0. This method is meant as a server-side method. -
getBoards
Description copied from interface:IGameReturns the complete map of boardIds/boards the game uses. The returned map is an unmodifiable view of the game's map, but not a deep copy, so changes to a board will affect the game. -
getBoardSize
public int getBoardSize() -
getCurrentRound
public int getCurrentRound()- Specified by:
getCurrentRoundin interfaceIGame- Returns:
- The current game round, with 0 typically indicating deployment and 1 the first actual game round.
-
setCurrentRound
public void setCurrentRound(int currentRound) Description copied from interface:IGameSets the current game round to the given round number. SeeIGame.getCurrentRound(). This method can be used in both GameManager and Client.- Specified by:
setCurrentRoundin interfaceIGame- Parameters:
currentRound- The new round number
-
clearActions
public void clearActions()Empties the list of pending EntityActions completely.- See Also:
-
removeActionsFor
public void removeActionsFor(int id) Removes all pending EntityActions by the InGameObject (Entity, unit) of the given ID from the list of pending actions. -
removeAction
Deprecated, for removal: This API element is subject to removal in a future version.Remove the given EntityAction from the list of pending actions. -
getActionsVector
Returns the pending EntityActions. Do not use to modify the actions; Arlith said: I will be angry. >:[ -
addAction
Adds the specified action to the list of pending EntityActions for this phase and fires a GameNewActionEvent. -
setupDeployment
public void setupDeployment()Clears and re-calculates the deployment table, i.e. assembles all units/objects in the game that are un-deployed (that includes returning units or reinforcements) together with the game round that they are supposed to deploy on. This method can be called at any time in the game and will assemble deployment according to the present game state. -
lastDeploymentRound
public int lastDeploymentRound() -
isDeploymentComplete
public boolean isDeploymentComplete() -
shouldDeployThisRound
public boolean shouldDeployThisRound()Check to see if we should deploy this round -
shouldDeployForRound
public boolean shouldDeployForRound(int round) -
clearDeploymentThisRound
public void clearDeploymentThisRound()Clear this round from this list of entities to deploy -
resetTurnIndex
public void resetTurnIndex()Resets the turn index toAWAITING_FIRST_TURN -
getTurnIndex
public int getTurnIndex()Description copied from interface:IGameReturns the current turn index, i.e. the turn that should next be played by the corresponding player.- Specified by:
getTurnIndexin interfaceIGame
-
setForces
Description copied from interface:IGameReplaces the game's Forces with the given forces. -
incrementCurrentRound
public void incrementCurrentRound()Description copied from interface:IGameAdds 1 to the current round value. This method is intended for server use only.- Specified by:
incrementCurrentRoundin interfaceIGame
-
setTurnIndex
Deprecated, for removal: This API element is subject to removal in a future version.Sets the turn index to the given value.- Parameters:
turnIndex- the new turn index
-
hasBoardLocation
Description copied from interface:IGameReturns true if the given boardLocation really exists, i.e. is not null, its board ID is an actual board in the game and its coords are contained in that board. This means that a hex can be found for this boardLocation.- Specified by:
hasBoardLocationin interfaceIGame- Parameters:
boardLocation- The location to test- Returns:
- True when the location exists and is on a board
-
hasBoardLocation
Description copied from interface:IGameReturns true if the given coords and boardID really exist, are not null, the board ID is an actual board in the game and the coords are contained in that board. This means that a hex can be found for these values, and it will not be null (unless the board data is corrupted).- Specified by:
hasBoardLocationin interfaceIGame- Parameters:
coords- The coords to testboardId- The board ID to test- Returns:
- True when the location exists and is on a board
-
hasBoard
Description copied from interface:IGameReturns true if the given boardLocation points to an existing board, i.e. its board ID is an actual board in the game. Does not check the location's coords. -
hasBoard
public boolean hasBoard(int boardId) Description copied from interface:IGameReturns true if the given bboard ID is an actual board in the game. -
setFormationAt
-
setBoardLocation
-
clamp
-
reset
public void reset()Resets this game, i.e. prepares it for a return to the lobby. -
getSeed
public long getSeed() -
getPlanetaryConditions
- Specified by:
getPlanetaryConditionsin interfacePlanetaryConditionsUsing- Returns:
- This game's planetary conditions
-
setPlanetaryConditions
Description copied from interface:PlanetaryConditionsUsingSets this game's planetary conditions.- Specified by:
setPlanetaryConditionsin interfacePlanetaryConditionsUsing- Parameters:
conditions- The new conditions
-