Class ServerGame

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • lastTime

        private long lastTime
        Timestamp of last move, if any. Do not serialize.
    • Constructor Detail

      • ServerGame

        public ServerGame​(Specification specification)
        Creates a new game model. Public for the test suite.
        Parameters:
        specification - The Specification to use in this game.
      • ServerGame

        public ServerGame​(Specification specification,
                          java.util.Random random)
        Creates a new game model. Called from the FreeColServer constructor to create a completely new game.
        Parameters:
        specification - The Specification to use in this game.
        random - A pseudo-random number source.
      • ServerGame

        public ServerGame​(Specification specification,
                          FreeColXMLReader xr)
                   throws javax.xml.stream.XMLStreamException
        Initiate a new ServerGame with information from a saved game. Called from FreeColServer.readGame when restoring a saved game.
        Parameters:
        specification - The Specification to use in this game.
        xr - The input stream containing the XML.
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurred during parsing.
    • Method Detail

      • getNextId

        public int getNextId()
        Stub for routine only meaningful in the server.
        Overrides:
        getNextId in class Game
        Returns:
        Nothing.
      • getConnectedPlayers

        public java.util.List<Player> getConnectedPlayers​(Player... players)
        Get a list of connected players, optionally excluding supplied ones. Do *not* restrict this only to live players, dead players still need to be communicated with (e.g. to tell them they are dead, or to revive them).
        Parameters:
        players - The Players to exclude.
        Returns:
        A list of all connected players, with exclusions.
      • sendToAll

        public void sendToAll​(ChangeSet cs)
        Send a change set to all live players.
        Parameters:
        cs - The ChangeSet to send.
      • sendToOthers

        public void sendToOthers​(Player player,
                                 ChangeSet cs)
        Send a change set to all players, optionally excluding one.
        Parameters:
        player - A Player to exclude.
        cs - The ChangeSet encapsulating the update.
      • sendToList

        public void sendToList​(java.util.List<Player> players,
                               ChangeSet cs)
        Send a change set to a list of players.
        Parameters:
        players - The list of Players to send to.
        cs - The ChangeSet to send.
      • sendTo

        public boolean sendTo​(Player player,
                              ChangeSet cs)
        Send a change set to one player.
        Parameters:
        player - The Player to send to.
        cs - The ChangeSet to send.
        Returns:
        True if the change was sent.
      • establishUnknownEnemy

        public final Player establishUnknownEnemy()
        Establish the unknown enemy player.
        Returns:
        The new unknown enemy Player.
      • updatePlayers

        public void updatePlayers​(java.util.List<? extends Player> players)
        Update the players.
        Parameters:
        players - A list of new Players.
      • changeAI

        public void changeAI​(Player player,
                             boolean ai)
        Change the AI state of a player.
        Parameters:
        player - The Player to change.
        ai - The new AI state.
      • randomize

        private final void randomize​(java.util.Random random)
        Randomize a new game.
        Parameters:
        random - A pseudo-random number source.
      • checkForWinner

        public ServerPlayer checkForWinner()
        Checks if anybody has won this game.
        Returns:
        The ServerPlayer who has won the game or null if none.
      • isNextPlayerInNewTurn

        public boolean isNextPlayerInNewTurn()
        Is the next player in a new turn?
        Returns:
        True if the next turn is due.
      • csNextTurn

        public void csNextTurn​(ChangeSet cs)
        Change to the next turn for this game.
        Parameters:
        cs - A ChangeSet to update.
      • spanishSuccessionReady

        private boolean spanishSuccessionReady​(Event event,
                                               java.util.List<Player> players,
                                               LogBuilder lb)
        Is it time for the Spanish Succession settlement?
        Parameters:
        event - The Spanish Succession Event.
        players - A list to fill with the strongest and weakest AIs.
        lb - A LogBuilder to log to.
        Returns:
        True if the Spanish Succession can proceed.
      • csSpanishSuccession

        private ServerPlayer csSpanishSuccession​(ChangeSet cs,
                                                 LogBuilder lb,
                                                 Event event)
        Checks for and if necessary performs the War of Spanish Succession changes. Visibility changes for the winner, loser is killed/irrelevant.
        Parameters:
        cs - A ChangeSet to update.
        lb - A LogBuilder to log to.
        event - The Spanish Succession Event.
        Returns:
        The ServerPlayer that is eliminated if any, or null if none found.
      • csAcceptTrade

        public boolean csAcceptTrade​(DiplomaticTrade agreement,
                                     Unit unit,
                                     Settlement settlement,
                                     ChangeSet cs)
        Accept a diplomatic trade. Handles the transfers of TradeItems. Note that first contact contexts may not necessarily have a settlement, but this is ok because first contact trade can only include stance and gold trade items.
        Parameters:
        agreement - The DiplomacyTrade agreement.
        unit - The Unit that is trading.
        settlement - The Settlement that is trading.
        cs - A ChangeSet to update.
        Returns:
        True if the trade was completed successfully.
      • csNewTurn

        public void csNewTurn​(java.util.Random random,
                              LogBuilder lb,
                              ChangeSet cs)
        Build the updates for a new turn for all the players in this game.
        Specified by:
        csNewTurn in interface TurnTaker
        Parameters:
        random - A Random number source.
        lb - A LogBuilder to log to.
        cs - A ChangeSet to update.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class Game
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Game