Package net.sf.freecol.server.model
Class ServerGame
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.Game
-
- net.sf.freecol.server.model.ServerGame
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
,TurnTaker
public class ServerGame extends Game implements TurnTaker
The server representation of the game.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.Game
Game.LogoutReason
-
-
Field Summary
Fields Modifier and Type Field Description private long
lastTime
Timestamp of last move, if any.private static java.util.logging.Logger
logger
-
Fields inherited from class net.sf.freecol.common.model.Game
combatModel, currentPlayer, freeColGameObjectListener, freeColGameObjects, map, nextId, players, TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description ServerGame(Specification specification)
Creates a new game model.ServerGame(Specification specification, java.util.Random random)
Creates a new game model.ServerGame(Specification specification, FreeColXMLReader xr)
Initiate a newServerGame
with information from a saved game.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changeAI(Player player, boolean ai)
Change the AI state of a player.ServerPlayer
checkForWinner()
Checks if anybody has won this game.boolean
csAcceptTrade(DiplomaticTrade agreement, Unit unit, Settlement settlement, ChangeSet cs)
Accept a diplomatic trade.void
csNewTurn(java.util.Random random, LogBuilder lb, ChangeSet cs)
Build the updates for a new turn for all the players in this game.void
csNextTurn(ChangeSet cs)
Change to the next turn for this game.private ServerPlayer
csSpanishSuccession(ChangeSet cs, LogBuilder lb, Event event)
Checks for and if necessary performs the War of Spanish Succession changes.boolean
equals(java.lang.Object o)
Player
establishUnknownEnemy()
Establish the unknown enemy player.java.util.List<Player>
getConnectedPlayers(Player... players)
Get a list of connected players, optionally excluding supplied ones.int
getNextId()
Stub for routine only meaningful in the server.int
hashCode()
boolean
isNextPlayerInNewTurn()
Is the next player in a new turn?private void
randomize(java.util.Random random)
Randomize a new game.boolean
sendTo(Player player, ChangeSet cs)
Send a change set to one player.void
sendToAll(ChangeSet cs)
Send a change set to all live players.void
sendToList(java.util.List<Player> players, ChangeSet cs)
Send a change set to a list of players.void
sendToOthers(Player player, ChangeSet cs)
Send a change set to all players, optionally excluding one.private boolean
spanishSuccessionReady(Event event, java.util.List<Player> players, LogBuilder lb)
Is it time for the Spanish Succession settlement?void
updatePlayers(java.util.List<? extends Player> players)
Update the players.-
Methods inherited from class net.sf.freecol.common.model.Game
addFreeColGameObject, addPlayer, addPlayers, allPlayersReadyToLaunch, canAddNewPlayer, changeMap, checkIntegrity, checkOwners, copyIn, findFreeColLocation, getAge, getAllColonies, getAllColoniesList, getClientPlayer, getClientUserName, getCombatModel, getCurrentPlayer, getDifficultyOptionGroup, getFirstPlayer, getFreeColGameObject, getFreeColGameObject, getFreeColGameObjectList, getGameOptions, getInitialActiveUnit, getInitialActiveUnitId, getLiveEuropeanPlayerList, getLiveEuropeanPlayers, getLiveNativePlayerList, getLiveNativePlayers, getLivePlayerList, getLivePlayers, getLocationClass, getMap, getMapGeneratorOptions, getMessageDisplay, getMessageSource, getNationOptions, getNextPlayer, getPlayer, getPlayerByName, getPlayerByNation, getPlayerByNationId, getPlayerList, getPlayers, getSettlementByName, getSpanishSuccession, getSpecification, getStatistics, getTurn, getUnknownEnemy, getUUID, getVacantNation, getVacantNations, getXMLTagName, isInClient, isInRevengeMode, isInServer, newInstance, notifyOwnerChanged, notifyRemoveFreeColGameObject, notifySetFreeColGameObject, preGameUpdate, readAttributes, readChild, readChildren, removeFreeColGameObject, removePlayer, setCombatModel, setCurrentPlayer, setFreeColGameObject, setFreeColGameObjectListener, setGameOptions, setInitialActiveUnitId, setMap, setMapGeneratorOptions, setNationOptions, setSpanishSuccession, setSpecification, setTurn, setUnknownEnemy, sortPlayers, unserialize, update, update, updateLocationRef, updateRef, updateRef, writeAttributes, writeChildren
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeResources, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, intern, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toString, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Constructor Detail
-
ServerGame
public ServerGame(Specification specification)
Creates a new game model. Public for the test suite.- Parameters:
specification
- TheSpecification
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
- TheSpecification
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 newServerGame
with information from a saved game. Called from FreeColServer.readGame when restoring a saved game.- Parameters:
specification
- TheSpecification
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.
-
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
- ThePlayer
s 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
- TheChangeSet
to send.
-
sendToOthers
public void sendToOthers(Player player, ChangeSet cs)
Send a change set to all players, optionally excluding one.- Parameters:
player
- APlayer
to exclude.cs
- TheChangeSet
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 ofPlayer
s to send to.cs
- TheChangeSet
to send.
-
sendTo
public boolean sendTo(Player player, ChangeSet cs)
Send a change set to one player.- Parameters:
player
- ThePlayer
to send to.cs
- TheChangeSet
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 newPlayer
s.
-
changeAI
public void changeAI(Player player, boolean ai)
Change the AI state of a player.- Parameters:
player
- ThePlayer
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
- AChangeSet
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 SuccessionEvent
.players
- A list to fill with the strongest and weakest AIs.lb
- ALogBuilder
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
- AChangeSet
to update.lb
- ALogBuilder
to log to.event
- The Spanish SuccessionEvent
.- 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
- TheDiplomacyTrade
agreement.unit
- TheUnit
that is trading.settlement
- TheSettlement
that is trading.cs
- AChangeSet
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.
-
-