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 longlastTimeTimestamp of last move, if any.private static java.util.logging.Loggerlogger-
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 newServerGamewith information from a saved game.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchangeAI(Player player, boolean ai)Change the AI state of a player.ServerPlayercheckForWinner()Checks if anybody has won this game.booleancsAcceptTrade(DiplomaticTrade agreement, Unit unit, Settlement settlement, ChangeSet cs)Accept a diplomatic trade.voidcsNewTurn(java.util.Random random, LogBuilder lb, ChangeSet cs)Build the updates for a new turn for all the players in this game.voidcsNextTurn(ChangeSet cs)Change to the next turn for this game.private ServerPlayercsSpanishSuccession(ChangeSet cs, LogBuilder lb, Event event)Checks for and if necessary performs the War of Spanish Succession changes.booleanequals(java.lang.Object o)PlayerestablishUnknownEnemy()Establish the unknown enemy player.java.util.List<Player>getConnectedPlayers(Player... players)Get a list of connected players, optionally excluding supplied ones.intgetNextId()Stub for routine only meaningful in the server.inthashCode()booleanisNextPlayerInNewTurn()Is the next player in a new turn?private voidrandomize(java.util.Random random)Randomize a new game.booleansendTo(Player player, ChangeSet cs)Send a change set to one player.voidsendToAll(ChangeSet cs)Send a change set to all live players.voidsendToList(java.util.List<Player> players, ChangeSet cs)Send a change set to a list of players.voidsendToOthers(Player player, ChangeSet cs)Send a change set to all players, optionally excluding one.private booleanspanishSuccessionReady(Event event, java.util.List<Player> players, LogBuilder lb)Is it time for the Spanish Succession settlement?voidupdatePlayers(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- TheSpecificationto 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- TheSpecificationto use in this game.random- A pseudo-random number source.
-
ServerGame
public ServerGame(Specification specification, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Initiate a newServerGamewith information from a saved game. Called from FreeColServer.readGame when restoring a saved game.- Parameters:
specification- TheSpecificationto 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- ThePlayers 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- TheChangeSetto send.
-
sendToOthers
public void sendToOthers(Player player, ChangeSet cs)
Send a change set to all players, optionally excluding one.- Parameters:
player- APlayerto exclude.cs- TheChangeSetencapsulating 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 ofPlayers to send to.cs- TheChangeSetto send.
-
sendTo
public boolean sendTo(Player player, ChangeSet cs)
Send a change set to one player.- Parameters:
player- ThePlayerto send to.cs- TheChangeSetto 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 newPlayers.
-
changeAI
public void changeAI(Player player, boolean ai)
Change the AI state of a player.- Parameters:
player- ThePlayerto 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
ServerPlayerwho 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- AChangeSetto 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- ALogBuilderto 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- AChangeSetto update.lb- ALogBuilderto log to.event- The Spanish SuccessionEvent.- Returns:
- The
ServerPlayerthat 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- TheDiplomacyTradeagreement.unit- TheUnitthat is trading.settlement- TheSettlementthat is trading.cs- AChangeSetto 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.
-
-