Class SimulationContext

java.lang.Object
megamek.common.autoResolve.acar.SimulationContext
All Implemented Interfaces:
IGame, PlanetaryConditionsUsing

public class SimulationContext extends Object implements IGame, PlanetaryConditionsUsing
  • Field Details

  • Constructor Details

  • Method Details

    • getOrders

      public Orders getOrders()
    • addUnit

      public void addUnit(InGameObject unit)
    • inGameTWEntities

      public List<Entity> inGameTWEntities()
      Returns:
      The TW Units (Entity) currently in the game.
    • deployableInGameObjects

      public List<Deployable> deployableInGameObjects()
    • getNoOfEntities

      public int getNoOfEntities()
    • getStartingNumberOfUnits

      public int getStartingNumberOfUnits(int playerId)
    • getSelectedEntityCount

      public int getSelectedEntityCount(EntitySelector selector)
    • getPlayerSkill

      @Deprecated(since="0.51.0", forRemoval=true) public SkillLevel getPlayerSkill(int playerId)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getNextEntityId

      public int getNextEntityId()
      Specified by:
      getNextEntityId in interface IGame
      Returns:
      The next free ID for InGameObjects (unit/entity/formation/others).
    • getEntity

      public Optional<Entity> getEntity(int id)
      Returns:
      The entity with the given id number, if any.
    • addEntity

      public void addEntity(Entity entity)
    • isOutOfGame

      public boolean isOutOfGame(int id)
    • getTurnsList

      public List<AcTurn> getTurnsList()
      Specified by:
      getTurnsList in interface IGame
      Returns:
      the current list of turns. If you're not the GameManager, don't even think about changing any of the turns.
    • getOptions

      public SimulationOptions getOptions()
      Specified by:
      getOptions in interface IGame
    • getPhase

      public GamePhase getPhase()
      Specified by:
      getPhase in interface IGame
      Returns:
      The current phase of this game.
    • addActionHandler

      public void addActionHandler(ActionHandler handler)
    • getTurn

      public AcTurn getTurn()
      Specified by:
      getTurn in interface IGame
    • getCurrentTurn

      public Optional<AcTurn> getCurrentTurn()
    • hasMoreTurns

      public boolean hasMoreTurns()
      Specified by:
      hasMoreTurns in interface IGame
      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

      public void setTurns(List<AcTurn> turns)
    • setPhase

      public void setPhase(GamePhase phase)
      Description copied from interface: IGame
      Sets the current game phase to the given phase. May perform phase-dependent cleanup. This method is intended for the GameManager.
      Specified by:
      setPhase in interface IGame
      Parameters:
      phase - The new phase
    • setLastPhase

      public void setLastPhase(GamePhase lastPhase)
      Description copied from interface: IGame
      Sets the previous game phase to the given phase. This method is intended for the GameManager.
      Specified by:
      setLastPhase in interface IGame
      Parameters:
      lastPhase - The phase to be remembered as the previous phase.
    • receivePhase

      public void receivePhase(GamePhase phase)
      Description copied from interface: IGame
      Sets 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 calls IGame.setPhase(GamePhase). When overridden, it'll usually make sense to call super(phase).
      Specified by:
      receivePhase in interface IGame
      Parameters:
      phase - The new phase
    • isCurrentPhasePlayable

      public boolean isCurrentPhasePlayable()
      Description copied from interface: IGame
      Returns 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:
      isCurrentPhasePlayable in interface IGame
      Returns:
      True when the current phase should be skipped entirely in this round
      See Also:
    • setPlayer

      public void setPlayer(int id, Player player)
      Description copied from interface: IGame
      Sets the given Player to the given game-unique id. // TODO : Is this method useful? Why not use addPlayer that also sets single-blind info?
      Specified by:
      setPlayer in interface IGame
      Parameters:
      id - The game-unique id of this player
      player - The Player object
    • removePlayer

      public void removePlayer(int id)
      Description copied from interface: IGame
      Removes the player with the id from the game.
      Specified by:
      removePlayer in interface IGame
      Parameters:
      id - The player id
    • setupTeams

      public void setupTeams()
      Specified by:
      setupTeams in interface IGame
    • replaceUnits

      public void replaceUnits(List<InGameObject> units)
      Description copied from interface: IGame
      This 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:
      replaceUnits in interface IGame
      Parameters:
      units - The units to add or use as a replacement for current units.
    • getGraveyard

      public List<InGameObject> getGraveyard()
      Specified by:
      getGraveyard in interface IGame
      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

      public List<Entity> getRetreatingUnits()
    • getLiveDeployedEntitiesOwnedBy

      public int getLiveDeployedEntitiesOwnedBy(Player player)
    • getNewReport

      public ReportEntry getNewReport(int messageId)
      Description copied from interface: IGame
      Returns a new ReportEntry with the given report message ID. The ReportEntry subclass returned depends on the implementation in the IGame subclass.
      Specified by:
      getNewReport in interface IGame
      Parameters:
      messageId - The message ID from report-messages.properties
      Returns:
      A new report of an appropriate type and message
    • scriptedEvents

      public List<TriggeredEvent> scriptedEvents()
      Specified by:
      scriptedEvents in interface IGame
      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

      public List<ActionHandler> getActionHandlers()
    • changeToNextTurn

      public Optional<AcTurn> changeToNextTurn()
    • hasEligibleFormation

      public boolean hasEligibleFormation(FormationTurn turn)
    • getFormation

      public Optional<Formation> getFormation(int formationID)
      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

      public GamePhase getLastPhase()
    • getActiveFormations

      public List<Formation> 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

      public List<Formation> getActiveDeployedFormations()
    • getActiveFormations

      public List<Formation> getActiveFormations(Player player)
    • getActiveFormations

      public List<Formation> getActiveFormations(int playerId)
    • addUnitToGraveyard

      public void addUnitToGraveyard(Entity entity)
    • setPlayerSkillLevel

      public void setPlayerSkillLevel(int playerId, SkillLevel averageSkillLevel)
    • getLocalPlayer

      public Player getLocalPlayer()
    • getForces

      public Forces getForces()
      Specified by:
      getForces in interface IGame
      Returns:
      The Forces present in this game. Can be empty, but not null.
    • getPlayer

      public Player getPlayer(int id)
      Specified by:
      getPlayer in interface IGame
      Parameters:
      id - a player id
      Returns:
      the individual player assigned the id parameter.
    • addPlayer

      public void addPlayer(int id, Player player)
      Description copied from interface: IGame
      Adds the given Player to the game with the given game-unique id. // TODO : Can this be made a default method?
      Specified by:
      addPlayer in interface IGame
      Parameters:
      id - The game-unique id of this player
      player - The Player object
    • getPlayersList

      public List<Player> getPlayersList()
      Specified by:
      getPlayersList in interface IGame
      Returns:
      The current players as a list. Implementations should make sure that this list can be safely modified.
    • getNoOfPlayers

      public int getNoOfPlayers()
      Specified by:
      getNoOfPlayers in interface IGame
      Returns:
      The current number of active players in the game. This includes observers but not ghosts.
    • getTeams

      public List<Team> getTeams()
      Specified by:
      getTeams in interface IGame
      Returns:
      The teams in the game. Implementations should make sure that this list can be safely modified.
    • getNoOfTeams

      public int getNoOfTeams()
      Specified by:
      getNoOfTeams in interface IGame
      Returns:
      The number of teams in the game.
    • getInGameObjects

      public List<InGameObject> getInGameObjects()
      Specified by:
      getInGameObjects in interface IGame
      Returns:
      A list of all InGameObjects of this game. This list is copied and may be safely modified.
    • removeFormation

      public void removeFormation(Formation formation)
    • applyDamageToEntityFromUnit

      public void applyDamageToEntityFromUnit(SBFUnit unit, Entity entity, EntityFinalState entityFinalState)
    • removeEntity

      public void removeEntity(Entity entity)
    • addGameListener

      public void addGameListener(GameListener listener)
      Description copied from interface: IGame
      Adds a GameListener to this game. The GameListener will receive any subsequently fired GameEvents.
      Specified by:
      addGameListener in interface IGame
      Parameters:
      listener - The GameListener to add
    • removeGameListener

      public void removeGameListener(GameListener listener)
      Description copied from interface: IGame
      Removes the specified game listener.
      Specified by:
      removeGameListener in interface IGame
      Parameters:
      listener - the game listener.
    • isForceVictory

      public boolean isForceVictory()
      Specified by:
      isForceVictory in interface IGame
      Returns:
      Whether there is an active claim for victory.
    • fireGameEvent

      public void fireGameEvent(GameEvent event)
      Description copied from interface: IGame
      Fires the given GameEvent, sending the event to all GameListener of this game.
      Specified by:
      fireGameEvent in interface IGame
      Parameters:
      event - the game event.
    • receiveBoard

      public void receiveBoard(int boardId, Board board)
      Description copied from interface: IGame
      Sets 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:
      receiveBoard in interface IGame
      Parameters:
      boardId - (currently ignored) The boardId to assign to that board
      board - The board to use
    • receiveBoards

      public void receiveBoards(Map<Integer,Board> boards)
      Description copied from interface: IGame
      Sets 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:
      receiveBoards in interface IGame
      Parameters:
      boards - The new boards
    • setBoard

      public void setBoard(int boardId, Board board)
      Description copied from interface: IGame
      Sets 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.
      Specified by:
      setBoard in interface IGame
      Parameters:
      boardId - (currently ignored) The boardId to assign to that board
      board - The board to use
    • getBoards

      public Map<Integer,Board> getBoards()
      Description copied from interface: IGame
      Returns 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.
      Specified by:
      getBoards in interface IGame
      Returns:
      The game's boards and their IDs
    • getBoardSize

      public int getBoardSize()
    • getCurrentRound

      public int getCurrentRound()
      Specified by:
      getCurrentRound in interface IGame
      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: IGame
      Sets the current game round to the given round number. See IGame.getCurrentRound(). This method can be used in both GameManager and Client.
      Specified by:
      setCurrentRound in interface IGame
      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(since="0.51.0", forRemoval=true) public void removeAction(Action action)
      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

      public List<Action> getActionsVector()
      Returns the pending EntityActions. Do not use to modify the actions; Arlith said: I will be angry. >:[
    • addAction

      public void addAction(Action action)
      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 to AWAITING_FIRST_TURN
    • getTurnIndex

      public int getTurnIndex()
      Description copied from interface: IGame
      Returns the current turn index, i.e. the turn that should next be played by the corresponding player.
      Specified by:
      getTurnIndex in interface IGame
    • setForces

      public void setForces(Forces fs)
      Description copied from interface: IGame
      Replaces the game's Forces with the given forces.
      Specified by:
      setForces in interface IGame
      Parameters:
      fs - The new Forces object to use
    • incrementCurrentRound

      public void incrementCurrentRound()
      Description copied from interface: IGame
      Adds 1 to the current round value. This method is intended for server use only.
      Specified by:
      incrementCurrentRound in interface IGame
    • setTurnIndex

      @Deprecated(since="0.51.0", forRemoval=true) protected void setTurnIndex(int turnIndex)
      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

      public boolean hasBoardLocation(@Nullable BoardLocation boardLocation)
      Description copied from interface: IGame
      Returns 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:
      hasBoardLocation in interface IGame
      Parameters:
      boardLocation - The location to test
      Returns:
      True when the location exists and is on a board
    • hasBoardLocation

      public boolean hasBoardLocation(Coords coords, int boardId)
      Description copied from interface: IGame
      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. 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:
      hasBoardLocation in interface IGame
      Parameters:
      coords - The coords to test
      boardId - The board ID to test
      Returns:
      True when the location exists and is on a board
    • hasBoard

      public boolean hasBoard(@Nullable BoardLocation boardLocation)
      Description copied from interface: IGame
      Returns 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.
      Specified by:
      hasBoard in interface IGame
      Parameters:
      boardLocation - The location to test
      Returns:
      True when the location is not null and its board exists
    • hasBoard

      public boolean hasBoard(int boardId)
      Description copied from interface: IGame
      Returns true if the given bboard ID is an actual board in the game.
      Specified by:
      hasBoard in interface IGame
      Parameters:
      boardId - The board ID to test
      Returns:
      True when the board exists
    • setFormationAt

      public void setFormationAt(Formation formation, BoardLocation position)
    • setBoardLocation

      public void setBoardLocation(BoardLocation boardLocation, Formation formation)
    • clamp

      public BoardLocation clamp(BoardLocation location)
    • reset

      public void reset()
      Resets this game, i.e. prepares it for a return to the lobby.
    • getSeed

      public long getSeed()
    • getPlanetaryConditions

      public PlanetaryConditions getPlanetaryConditions()
      Specified by:
      getPlanetaryConditions in interface PlanetaryConditionsUsing
      Returns:
      This game's planetary conditions
    • setPlanetaryConditions

      public void setPlanetaryConditions(PlanetaryConditions conditions)
      Description copied from interface: PlanetaryConditionsUsing
      Sets this game's planetary conditions.
      Specified by:
      setPlanetaryConditions in interface PlanetaryConditionsUsing
      Parameters:
      conditions - The new conditions