Class SBFGame

java.lang.Object
megamek.common.game.AbstractGame
megamek.common.strategicBattleSystems.SBFGame
All Implemented Interfaces:
IGame, PlanetaryConditionsUsing, SBFRuleOptionsUser

public final class SBFGame extends AbstractGame implements PlanetaryConditionsUsing, SBFRuleOptionsUser
This is an SBF game's game object that holds all game information. As of 2024, this is under construction.
  • Constructor Details

    • SBFGame

      public SBFGame()
  • Method Details

    • getTurn

      @Nullable public SBFTurn getTurn()
      Specified by:
      getTurn in interface IGame
    • getOptions

      public SBFRuleOptions getOptions()
      Description copied from interface: SBFRuleOptionsUser
      This method must be implemented to provide access to the SBF options used in the present game so that the convenience methods of this interface work correctly.
      Specified by:
      getOptions in interface IGame
      Specified by:
      getOptions in interface SBFRuleOptionsUser
      Returns:
      the SBFRuleOptions used by the present SBF game
    • getPhase

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

      public GamePhase getLastPhase()
    • 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
    • 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
    • isForceVictory

      public boolean isForceVictory()
      Specified by:
      isForceVictory in interface IGame
      Returns:
      Whether there is an active claim for victory.
    • 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
      Overrides:
      addPlayer in class AbstractGame
      Parameters:
      id - The game-unique id of this player
      player - The Player object
    • 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.
    • getPlanetaryConditions

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

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

      public void addUnit(InGameObject unit)
    • receiveUnit

      public void receiveUnit(InGameObject unit)
      Adds or overwrites the received unit in the game's unit list.
      Parameters:
      unit - The new or changed unit
    • 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.
    • addReports

      public void addReports(List<SBFReportEntry> reports)
      Adds the given reports this game's reports.
      Parameters:
      reports - the new reports to add
    • 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
    • getGameReport

      public SBFFullGameReport getGameReport()
    • replaceAllReports

      public void replaceAllReports(Map<Integer,List<SBFReportEntry>> newReports)
      Replaces this game's entire reports with the given reports.
      Parameters:
      newReports - The new reports to keep as this game's reports
    • setTurns

      public void setTurns(List<SBFTurn> newTurns)
      Sets the current list of turns to the given one, replacing any currently present turns.
      Parameters:
      newTurns - The new list of turns to use
    • getTurnsList

      public List<SBFTurn> getTurnsList()
      Returns the current list of turns. The returned list is unmodifiable but not a deep copy. If you're not the SBFGameManager, don't even think about changing any of the turns.
      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.
    • 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.
    • setUnitList

      public void setUnitList(List<InGameObject> units)
    • setGraveyard

      public void setGraveyard(List<InGameObject> graveyard)
    • visibilityHelper

      public SBFVisibilityHelper visibilityHelper()
    • isVisible

      public boolean isVisible(int viewingPlayer, int formationID)
    • getFullyVisibleUnits

      public List<InGameObject> getFullyVisibleUnits(Player viewingPlayer)
    • getVisibility

      public SBFVisibilityStatus getVisibility(Player player, int unitId)
    • changeToNextTurn

      public SBFTurn changeToNextTurn()
      Advances the turn index and returns the then-current turn.
      Returns:
      The current turn (after advancing the turn index)
    • hasEligibleFormation

      public boolean hasEligibleFormation(SBFFormationTurn turn)
    • getActiveFormations

      public List<SBFFormation> 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
    • getActiveFormationsAt

      public List<SBFFormation> getActiveFormationsAt(BoardLocation location)
      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
    • isHostileActiveFormationAt

      public boolean isHostileActiveFormationAt(BoardLocation location, SBFFormation formation)
    • areHostile

      public boolean areHostile(SBFFormation formation, Player player)
    • getNextEligibleFormation

      public Optional<SBFFormation> getNextEligibleFormation()
      Returns:
      the first formation in the list of formations that is alive and eligible for the current game phase.
    • getPreviousEligibleFormation

      @Deprecated(since="0.51.0", forRemoval=true) public Optional<SBFFormation> getPreviousEligibleFormation()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      the preceding formation in the list of formations that is alive and eligible for the current game phase.
    • getNextEligibleFormation

      public Optional<SBFFormation> getNextEligibleFormation(int currentFormationID)
      Returns:
      the next in the list of formations that is alive and eligible for the current game phase, counting from the given current formation id. If no matching formation can be found for the given id, returns the first eligible formation in the list of formations that is alive and eligible.
    • getPreviousEligibleFormation

      public Optional<SBFFormation> getPreviousEligibleFormation(int currentFormationID)
      Returns:
      the previous in the list of formations that is alive and eligible for the current game phase, counting from the given current formation id. If no matching formation can be found for the given id, returns the last eligible formation from the list of formations that is alive and eligible.
    • getFormation

      public Optional<SBFFormation> 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
    • 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
    • getPlayerFor

      public Optional<Player> getPlayerFor(SBFTurn turn)
      Returns the Player that has to act in the given turn. The result should rarely be empty.
      Parameters:
      turn - The SBFTurn to check
      Returns:
      The Player whose turn it is
    • setTurnIndex

      public void setTurnIndex(int turnIndex, int prevPlayerId)
      Sets the current turn index
      Parameters:
      turnIndex - The new turn index.
      prevPlayerId - The ID of the player who triggered the turn index change.
    • onSameBoard

      public boolean onSameBoard(SBFFormation unit1, SBFFormation unit2)
    • forget

      public void forget(int unitId)
    • addActionHandler

      public void addActionHandler(SBFActionHandler handler)
    • removeActionHandler

      @Deprecated(since="0.51.0", forRemoval=true) public void removeActionHandler(SBFActionHandler handler)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getActionHandlers

      public List<SBFActionHandler> getActionHandlers()
      Returns:
      The currently active action handlers.