Package net.sf.freecol.common.model
Class Game
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.Game
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
- Direct Known Subclasses:
ServerGame
public class Game extends FreeColGameObject
The main component of the game model.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classGame.FcgoStateState for the FCGO iterator, out here because it has to be static.static classGame.LogoutReasonReasons for logging out.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCIBOLA_TAGprivate static java.lang.StringCLIENT_USER_NAME_TAGprivate java.lang.StringclientUserNameThe client player name, null in the server.protected CombatModelcombatModelThe combat model this game uses.private static java.lang.StringCURRENT_PLAYER_TAGprotected PlayercurrentPlayerThe player whose turn it is.protected FreeColGameObjectListenerfreeColGameObjectListenerA FreeColGameObjectListener to watch the objects in the game.protected java.util.HashMap<java.lang.String,java.lang.ref.WeakReference<FreeColGameObject>>freeColGameObjectsReferences to all objects created in this game.private static java.lang.StringINITIAL_ACTIVE_UNIT_IDprivate java.lang.StringinitialActiveUnitIdInitial active unit identifier.private static java.util.Map<java.lang.String,java.lang.Class<? extends FreeColGameObject>>locationClassesMap of class name to class for the location classes, to speed up game loading.private static java.util.logging.Loggerloggerprotected MapmapThe map of the New World.private NationOptionsnationOptionsThe current nation options.private static java.lang.StringNEXT_ID_TAGprotected intnextIdThe next available identifier that can be given to a newFreeColGameObject.protected java.util.List<Player>playersAll the players in the game.private static intREMOVE_GC_THRESHOLDThe number of removed FCGOs that should trigger a cache clean.private intremoveCountThe number of FCGOs removed since last cache clean.private static java.util.Map<java.lang.Class<? extends FreeColObject>,java.lang.Class<? extends FreeColObject>>serverClassesMap of all classes with corresponding server classes.private static java.lang.StringSPANISH_SUCCESSION_TAGprivate booleanspanishSuccessionWhether the War of Spanish Succession has already taken place.private SpecificationspecificationThe Specification this game uses.static java.lang.StringTAGprivate TurnturnThe current turn.private static java.lang.StringTURN_TAGprivate PlayerunknownEnemyA virtual player to use for enemy privateers.private java.util.UUIDuuidGame UUID, persistent in savegame filesprivate static java.lang.StringUUID_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 Modifier Constructor Description Game()Root constructor for games.Game(Game game, FreeColXMLReader xr)Creates a newGameinstance from a stream.protectedGame(Specification specification)Constructor used by the ServerGame constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFreeColGameObject(java.lang.String id, FreeColGameObject fcgo)Add a newFreeColGameObjectwith a given identifier.voidaddPlayer(Player player)Adds the specified player to the game.voidaddPlayers(java.util.List<Player> players)Add a list of players to this game.booleanallPlayersReadyToLaunch()Checks if all players are ready to launch.booleancanAddNewPlayer()Can a new player be added to this game?voidchangeMap(Map newMap)Change the map in this game, fixing player destinations.Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)Checks the integrity of this game object.voidcheckOwners(Ownable o, Player oldOwner)Maintain the player containers for certain ownables.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.booleanequals(java.lang.Object o)LocationfindFreeColLocation(java.lang.String id)Convenience wrapper to find a location (which is an interface, precluding using the typed version of getFreeColGameObject()) by identifier.intgetAge()Get the age for the current turn.java.util.stream.Stream<Colony>getAllColonies(Player player)Get all the colonies in the game.java.util.List<Colony>getAllColoniesList(Player player)Get a list of all the colonies in the game.PlayergetClientPlayer()Get the client player this thread is operating for.java.lang.StringgetClientUserName()Get the client user name.CombatModelgetCombatModel()Get the combat model in this game.PlayergetCurrentPlayer()Gets the current player.OptionGroupgetDifficultyOptionGroup()Get the difficulty level of this game.PlayergetFirstPlayer()Get the first player in this game.FreeColGameObjectgetFreeColGameObject(java.lang.String id)Gets theFreeColGameObjectwith the given identifier.<T extends FreeColGameObject>
TgetFreeColGameObject(java.lang.String id, java.lang.Class<T> returnClass)Gets theFreeColGameObjectwith the specified identifier and class.private java.util.Iterator<FreeColGameObject>getFreeColGameObjectIterator()Gets anIteratorover every registeredFreeColGameObject.java.util.List<FreeColGameObject>getFreeColGameObjectList()Get a list of all theFreeColGameObjects.OptionGroupgetGameOptions()Gets the game options associated with this game.UnitgetInitialActiveUnit()Get the initial active unit.java.lang.StringgetInitialActiveUnitId()Get the identifier for the initial active unit.java.util.List<Player>getLiveEuropeanPlayerList(Player... exclude)Get a list of the live European players in this game.java.util.stream.Stream<Player>getLiveEuropeanPlayers(Player... exclude)Get a stream of the live European players in this game.java.util.List<Player>getLiveNativePlayerList(Player... exclude)Get a list of the live native players in this game.java.util.stream.Stream<Player>getLiveNativePlayers(Player... exclude)Get a stream of the live native players in this game.java.util.List<Player>getLivePlayerList(Player... exclude)Get a list of the live players in the game, optionally excluding supplied ones.java.util.stream.Stream<Player>getLivePlayers(Player... exclude)Get a stream of the live players in the game, optionally excluding supplied ones.static java.lang.Class<? extends FreeColGameObject>getLocationClass(java.lang.String id)Get a location class from an identifier.MapgetMap()Gets the map that is being used in this game.OptionGroupgetMapGeneratorOptions()Gets the map generator options associated with this game.FreeColObjectgetMessageDisplay(ModelMessage message)Helper function to get the object to display with a message in this game.FreeColGameObjectgetMessageSource(ModelMessage message)Helper function to get the source object of a message in this game.NationOptionsgetNationOptions()Get the current nation options.intgetNextId()Stub for routine only meaningful in the server.PlayergetNextPlayer()Gets the next current player.PlayergetPlayer(java.util.function.Predicate<? super Player> predicate)Get a particular player in the game by a predicate.private PlayergetPlayerAfter(Player beforePlayer)Gets the live player after the given player.PlayergetPlayerByName(java.lang.String name)Gets a player specified by a name.PlayergetPlayerByNation(Nation nation)Get aPlayeridentified by its nation.PlayergetPlayerByNationId(java.lang.String nationId)Get aPlayeridentified by its nation identifier.protected java.util.List<Player>getPlayerList(java.util.function.Predicate<? super Player> predicate)Get players in the game.java.util.stream.Stream<Player>getPlayers(java.util.function.Predicate<? super Player> predicate)Get players in the game.SettlementgetSettlementByName(java.lang.String name)Finds a settlement by name.booleangetSpanishSuccession()Has the Spanish Succession event occured?SpecificationgetSpecification()Get the specification.java.util.Map<java.lang.String,java.lang.String>getStatistics()Gets the statistics of this game.TurngetTurn()Gets the current turn in this game.PlayergetUnknownEnemy()Gets the unknown enemy player, which is used for privateers.java.util.UUIDgetUUID()Gets the unique identifier for this game.NationgetVacantNation()Find an available (i.e.java.util.List<Nation>getVacantNations()Get the currently available nations.java.lang.StringgetXMLTagName()Get the serialization tag for this object.inthashCode()booleanisInClient()Are we executing in a client?booleanisInRevengeMode()Is this game in revenge mode?booleanisInServer()Are we executing in the server?static <T extends FreeColObject>
TnewInstance(Game game, java.lang.Class<T> returnClass, boolean server)Instantiate an uninitialized FreeColGameObject within a game.voidnotifyOwnerChanged(FreeColGameObject source, Player oldOwner, Player newOwner)Notify a listener (if any) of that a game object has changed owner.voidnotifyRemoveFreeColGameObject(java.lang.String id)Notify a listener (if any) of that a game object has gone.voidnotifySetFreeColGameObject(java.lang.String id, FreeColGameObject fcgo)Notify a listener (if any) of a new game object.booleanpreGameUpdate(Game game)Special update handler for the pre-game update.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.voidremoveFreeColGameObject(java.lang.String id, java.lang.String reason)Removes theFreeColGameObjectwith the specified identifier.booleanremovePlayer(Player player)Removes the specified player from the game.voidsetCombatModel(CombatModel newCombatModel)Set the game combat model.voidsetCurrentPlayer(Player newCurrentPlayer)Sets the current player.voidsetFreeColGameObject(java.lang.String id, FreeColGameObject fcgo)Set the mapping between object identifier and object.voidsetFreeColGameObjectListener(FreeColGameObjectListener fcgol)Sets theFreeColGameObjectListenerattached to this game.voidsetGameOptions(OptionGroup go)Sets the game options associated with this game.voidsetInitialActiveUnitId(java.lang.String initialActiveUnitId)Set the identifier for the initial active unit.MapsetMap(Map newMap)Sets the game map.voidsetMapGeneratorOptions(OptionGroup mgo)Sets the map generator options associated with this game.voidsetNationOptions(NationOptions newNationOptions)Set the current nation options.private voidsetPlayers(java.util.List<Player> players)Set the players in the game.voidsetSpanishSuccession(boolean spanishSuccession)Set the Spanish Succession value.voidsetSpecification(Specification specification)Sets the specification for this object.voidsetTurn(Turn newTurn)Sets the current turn in this game.voidsetUnknownEnemy(Player player)Sets the unknown enemy player.voidsortPlayers(java.util.Comparator<Player> comparator)Sort the players list.<T extends FreeColObject>
Tunserialize(java.lang.String xml, java.lang.Class<T> returnClass)Unserialize from XML to a FreeColObject in this game.<T extends FreeColGameObject>
java.util.List<T>update(java.util.Collection<T> other, boolean create)Convenience wrapper to update severalFreeColGameObjects.<T extends FreeColGameObject>
Tupdate(T other, boolean create)Update aFreeColGameObjectfrom another.private <T extends FreeColGameObject>
Tupdate(T other, java.lang.Class<T> returnClass, boolean create)Update aFreeColGameObjectfrom another, optionally allowing missing objects to be created.LocationupdateLocationRef(Location loc)Update aLocationfrom a reference to it in an update.<T extends FreeColGameObject>
java.util.List<T>updateRef(java.util.Collection<T> other)Update severalFreeColGameObjects from a list of references to it in an update.<T extends FreeColGameObject>
TupdateRef(T other)Update aFreeColGameObjectfrom a reference to it in an update.private <T extends FreeColGameObject>
TupdateRef(T other, java.lang.Class<T> returnClass)Update aFreeColGameObjectfrom a reference to it in an update.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(FreeColXMLWriter xw)Write the children of this object to a stream.-
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
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
serverClasses
private static final java.util.Map<java.lang.Class<? extends FreeColObject>,java.lang.Class<? extends FreeColObject>> serverClasses
Map of all classes with corresponding server classes.
-
locationClasses
private static final java.util.Map<java.lang.String,java.lang.Class<? extends FreeColGameObject>> locationClasses
Map of class name to class for the location classes, to speed up game loading.
-
specification
private Specification specification
The Specification this game uses.
-
nextId
protected int nextId
The next available identifier that can be given to a newFreeColGameObject.
-
uuid
private java.util.UUID uuid
Game UUID, persistent in savegame files
-
clientUserName
private java.lang.String clientUserName
The client player name, null in the server.
-
players
protected final java.util.List<Player> players
All the players in the game.
-
unknownEnemy
private Player unknownEnemy
A virtual player to use for enemy privateers.
-
map
protected Map map
The map of the New World.
-
nationOptions
private NationOptions nationOptions
The current nation options. Mainly used to see if a player nation is available.
-
currentPlayer
protected Player currentPlayer
The player whose turn it is.
-
turn
private Turn turn
The current turn.
-
spanishSuccession
private boolean spanishSuccession
Whether the War of Spanish Succession has already taken place.
-
initialActiveUnitId
private java.lang.String initialActiveUnitId
Initial active unit identifier.
-
freeColGameObjects
protected final java.util.HashMap<java.lang.String,java.lang.ref.WeakReference<FreeColGameObject>> freeColGameObjects
References to all objects created in this game. Serialization is not needed directly as these must be completely within { players, unknownEnemy, map } which are directly serialized.
-
combatModel
protected CombatModel combatModel
The combat model this game uses. At the moment, the only combat model available is the SimpleCombatModel, which strives to implement the combat model of the original game. However, it is anticipated that other, more complex combat models will be implemented in future. As soon as that happens, we will also have to make the combat model selectable.
-
REMOVE_GC_THRESHOLD
private static final int REMOVE_GC_THRESHOLD
The number of removed FCGOs that should trigger a cache clean.- See Also:
- Constant Field Values
-
removeCount
private int removeCount
The number of FCGOs removed since last cache clean.
-
freeColGameObjectListener
protected FreeColGameObjectListener freeColGameObjectListener
A FreeColGameObjectListener to watch the objects in the game. Usually this is the AIMain instance. FIXME: is this better done with a property change listener?
-
CIBOLA_TAG
private static final java.lang.String CIBOLA_TAG
- See Also:
- Constant Field Values
-
CLIENT_USER_NAME_TAG
private static final java.lang.String CLIENT_USER_NAME_TAG
- See Also:
- Constant Field Values
-
CURRENT_PLAYER_TAG
private static final java.lang.String CURRENT_PLAYER_TAG
- See Also:
- Constant Field Values
-
INITIAL_ACTIVE_UNIT_ID
private static final java.lang.String INITIAL_ACTIVE_UNIT_ID
- See Also:
- Constant Field Values
-
NEXT_ID_TAG
private static final java.lang.String NEXT_ID_TAG
- See Also:
- Constant Field Values
-
SPANISH_SUCCESSION_TAG
private static final java.lang.String SPANISH_SUCCESSION_TAG
- See Also:
- Constant Field Values
-
TURN_TAG
private static final java.lang.String TURN_TAG
- See Also:
- Constant Field Values
-
UUID_TAG
private static final java.lang.String UUID_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Game
public Game()
Root constructor for games. Game.newInstance uses this so it must be public.
-
Game
protected Game(Specification specification)
Constructor used by the ServerGame constructor.- Parameters:
specification- TheSpecificationfor this game.
-
Game
public Game(Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newGameinstance from a stream.- Parameters:
game- A baseGame(not used here, this is a very special case).xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if an error occurs
-
-
Method Detail
-
preGameUpdate
public boolean preGameUpdate(Game game)
Special update handler for the pre-game update. When starting a new game the server sends an update that contains the game map. This must be synchronized so that the client does not race ahead and launch into the game before the update completes. We used to check integrity here, but 1) the server has already done that and 2) the unexplored Tiles have no type which makes a lot of integrity failures.- Parameters:
game- The update for thisGame.- Returns:
- True if the update succeeds.
-
newInstance
public static <T extends FreeColObject> T newInstance(Game game, java.lang.Class<T> returnClass, boolean server)
Instantiate an uninitialized FreeColGameObject within a game.- Type Parameters:
T- The actual return type.- Parameters:
game- TheGameto instantiate in.returnClass- The requiredFreeColObjectclass.server- Create a server object if possible.- Returns:
- The new uninitialized object, or null on error.
-
getDifficultyOptionGroup
public final OptionGroup getDifficultyOptionGroup()
Get the difficulty level of this game.- Returns:
- An
OptionGroupcontaining the difficulty settings.
-
getGameOptions
public OptionGroup getGameOptions()
Gets the game options associated with this game.- Returns:
- An
OptionGroupcontaining the game options.
-
setGameOptions
public void setGameOptions(OptionGroup go)
Sets the game options associated with this game.- Parameters:
go- AnOptionGroupcontaining the game options.
-
getMapGeneratorOptions
public OptionGroup getMapGeneratorOptions()
Gets the map generator options associated with this game.- Returns:
- An
OptionGroupcontaining the map generator options.
-
setMapGeneratorOptions
public void setMapGeneratorOptions(OptionGroup mgo)
Sets the map generator options associated with this game.- Parameters:
mgo- AnOptionGroupcontaining the map generator options.
-
getNextId
public int getNextId()
Stub for routine only meaningful in the server.- Returns:
- Nothing.
-
getFreeColGameObject
public FreeColGameObject getFreeColGameObject(java.lang.String id)
Gets theFreeColGameObjectwith the given identifier.- Parameters:
id- The object identifier.- Returns:
- The game object, or null if not found.
-
getFreeColGameObject
public <T extends FreeColGameObject> T getFreeColGameObject(java.lang.String id, java.lang.Class<T> returnClass)
Gets theFreeColGameObjectwith the specified identifier and class.- Type Parameters:
T- The actual return type.- Parameters:
id- The object identifier.returnClass- The expected class of the object.- Returns:
- The game object, or null if not found.
-
setFreeColGameObject
public void setFreeColGameObject(java.lang.String id, FreeColGameObject fcgo)Set the mapping between object identifier and object.- Parameters:
id- The object identifier.fcgo- TheFreeColGameObjectto add to thisGame.
-
addFreeColGameObject
public void addFreeColGameObject(java.lang.String id, FreeColGameObject fcgo)Add a newFreeColGameObjectwith a given identifier.- Parameters:
id- The object identifier.fcgo- TheFreeColGameObjectto add to thisGame.
-
removeFreeColGameObject
public void removeFreeColGameObject(java.lang.String id, java.lang.String reason)Removes theFreeColGameObjectwith the specified identifier.- Parameters:
id- The object identifier.reason- A reason to remove the object.- Throws:
java.lang.IllegalArgumentException- If the identifier is null or empty.
-
update
public <T extends FreeColGameObject> T update(T other, boolean create)
Update aFreeColGameObjectfrom another.- Type Parameters:
T- The type of object to update.- Parameters:
other- The other object.create- If true, create the object if it is missing.- Returns:
- The resulting object after update.
-
update
private <T extends FreeColGameObject> T update(T other, java.lang.Class<T> returnClass, boolean create)
Update aFreeColGameObjectfrom another, optionally allowing missing objects to be created.- Type Parameters:
T- The type of object to update.- Parameters:
other- The other object.returnClass- The expected class of the object.create- If true, create missing objects.- Returns:
- The resulting object after update.
-
update
public <T extends FreeColGameObject> java.util.List<T> update(java.util.Collection<T> other, boolean create)
Convenience wrapper to update severalFreeColGameObjects.- Type Parameters:
T- The type of object to update.- Parameters:
other- The collection of objects to update.create- If true, create missing objects.- Returns:
- The resulting list of updated objects.
-
updateRef
public <T extends FreeColGameObject> T updateRef(T other)
Update aFreeColGameObjectfrom a reference to it in an update.- Type Parameters:
T- The type of object to update.- Parameters:
other- The other object.- Returns:
- The resulting object after update.
-
updateRef
private <T extends FreeColGameObject> T updateRef(T other, java.lang.Class<T> returnClass)
Update aFreeColGameObjectfrom a reference to it in an update.- Type Parameters:
T- The type of object to update.- Parameters:
other- The other object.returnClass- The expected class of the object.- Returns:
- The resulting object after update.
-
updateRef
public <T extends FreeColGameObject> java.util.List<T> updateRef(java.util.Collection<T> other)
Update severalFreeColGameObjects from a list of references to it in an update.- Type Parameters:
T- The type of object to update.- Parameters:
other- The other object.- Returns:
- The resulting object after update.
-
updateLocationRef
public Location updateLocationRef(Location loc)
Update aLocationfrom a reference to it in an update.- Parameters:
loc- TheLocation.- Returns:
- The resulting location after update.
-
findFreeColLocation
public Location findFreeColLocation(java.lang.String id)
Convenience wrapper to find a location (which is an interface, precluding using the typed version of getFreeColGameObject()) by identifier. Use this routine when the object should already be present in the game.- Parameters:
id- The object identifier.- Returns:
- The
Locationif any.
-
getFreeColGameObjectIterator
private java.util.Iterator<FreeColGameObject> getFreeColGameObjectIterator()
Gets anIteratorover every registeredFreeColGameObject. ThisIteratorshould be iterated once in a while since it cleans theFreeColGameObjectcache. Very few routines call this any more, so there is a thresholded call in removeFreeColGameObject to ensure the cache is still cleaned. Reconsider this if the situation changes. Lock freeColGameObjects when using this.- Returns:
- An
Iteratorcontaining every registeredFreeColGameObject.
-
getFreeColGameObjectList
public java.util.List<FreeColGameObject> getFreeColGameObjectList()
Get a list of all theFreeColGameObjects.- Returns:
- A suitable list.
-
getUUID
public java.util.UUID getUUID()
Gets the unique identifier for this game. A game UUID persists in save game files.- Returns:
- The game
UUID.
-
getPlayerList
protected java.util.List<Player> getPlayerList(java.util.function.Predicate<? super Player> predicate)
Get players in the game.- Parameters:
predicate- APredicateto select suitable players with.- Returns:
- A list of
Players.
-
getPlayers
public java.util.stream.Stream<Player> getPlayers(java.util.function.Predicate<? super Player> predicate)
Get players in the game.- Parameters:
predicate- APredicateto select suitable players with.- Returns:
- The stream of
Players.
-
getPlayer
public Player getPlayer(java.util.function.Predicate<? super Player> predicate)
Get a particular player in the game by a predicate.- Parameters:
predicate- APredicateto select suitable players with.- Returns:
- The
Playerfound or null if not present.
-
setPlayers
private void setPlayers(java.util.List<Player> players)
Set the players in the game.- Parameters:
players- The newPlayers to add.
-
getPlayerAfter
private Player getPlayerAfter(Player beforePlayer)
Gets the live player after the given player.- Parameters:
beforePlayer- ThePlayerbefore thePlayerto be returned.- Returns:
- The
Playerafter thebeforePlayerin the list which determines the order each player becomes the current player. - See Also:
getNextPlayer()
-
addPlayer
public void addPlayer(Player player)
Adds the specified player to the game.- Parameters:
player- ThePlayerto add.
-
removePlayer
public boolean removePlayer(Player player)
Removes the specified player from the game. We do not really remove the full FCGO from the game, just from the active players list.- Parameters:
player- ThePlayerto remove.- Returns:
- True if the player was removed.
-
getFirstPlayer
public Player getFirstPlayer()
Get the first player in this game.- Returns:
- The first player, or null if none present.
-
sortPlayers
public void sortPlayers(java.util.Comparator<Player> comparator)
Sort the players list.- Parameters:
comparator- TheComparatorto sort with.
-
getPlayerByName
public Player getPlayerByName(java.lang.String name)
Gets a player specified by a name.- Parameters:
name- The name identifying thePlayer.- Returns:
- The
Playeror null if none found.
-
getPlayerByNation
public Player getPlayerByNation(Nation nation)
Get aPlayeridentified by its nation.- Parameters:
nation- TheNationto search for.- Returns:
- The
Playerof the given nation, or null if not found.
-
getPlayerByNationId
public Player getPlayerByNationId(java.lang.String nationId)
Get aPlayeridentified by its nation identifier.- Parameters:
nationId- The nation identifier to search for.- Returns:
- The
Playerof the given nation, or null if not found.
-
getLivePlayerList
public java.util.List<Player> getLivePlayerList(Player... exclude)
Get a list of the live players in the game, optionally excluding supplied ones.- Parameters:
exclude- ThePlayers to exclude.- Returns:
- A list of live
Players, without the excluded ones.
-
getLivePlayers
public java.util.stream.Stream<Player> getLivePlayers(Player... exclude)
Get a stream of the live players in the game, optionally excluding supplied ones.- Parameters:
exclude- ThePlayers to exclude.- Returns:
- A stream of live
Players, without the excluded ones.
-
getLiveEuropeanPlayerList
public java.util.List<Player> getLiveEuropeanPlayerList(Player... exclude)
Get a list of the live European players in this game.- Parameters:
exclude-Players to exclude.- Returns:
- A list of live European
Players in this game, without the excluded ones.
-
getLiveEuropeanPlayers
public java.util.stream.Stream<Player> getLiveEuropeanPlayers(Player... exclude)
Get a stream of the live European players in this game.- Parameters:
exclude-Players to exclude.- Returns:
- A stream of live European
Players in this game, without the excluded ones.
-
getLiveNativePlayerList
public java.util.List<Player> getLiveNativePlayerList(Player... exclude)
Get a list of the live native players in this game.- Parameters:
exclude-Players to exclude.- Returns:
- A list of live native
Players in this game.
-
getLiveNativePlayers
public java.util.stream.Stream<Player> getLiveNativePlayers(Player... exclude)
Get a stream of the live native players in this game.- Parameters:
exclude-Players to exclude.- Returns:
- A stream of live native
Players in this game.
-
getNextPlayer
public Player getNextPlayer()
Gets the next current player.- Returns:
- The
Playerwhose turn follows the current player.
-
addPlayers
public void addPlayers(java.util.List<Player> players)
Add a list of players to this game. Called from the pre and in-game controllers when players change. ATM we never remove players, even dead ones. Must tolerate player being both present and not present.- Parameters:
players- The list ofplayersto add.
-
getUnknownEnemy
public Player getUnknownEnemy()
Gets the unknown enemy player, which is used for privateers.- Returns:
- The unknown enemy
Player.
-
setUnknownEnemy
public void setUnknownEnemy(Player player)
Sets the unknown enemy player.- Parameters:
player- ThePlayerto serve as the unknown enemy.
-
getClientUserName
public java.lang.String getClientUserName()
Get the client user name.- Returns:
- The client user name.
-
isInClient
public boolean isInClient()
Are we executing in a client?- Returns:
- True in a client.
-
isInServer
public boolean isInServer()
Are we executing in the server?- Returns:
- True in the server.
-
getClientPlayer
public Player getClientPlayer()
Get the client player this thread is operating for. If in the server there will be none.- Returns:
- The client
Player.
-
isInRevengeMode
public boolean isInRevengeMode()
Is this game in revenge mode?- Returns:
- True if an undead player is present.
-
getCurrentPlayer
public Player getCurrentPlayer()
Gets the current player.- Returns:
- The current player.
-
setCurrentPlayer
public void setCurrentPlayer(Player newCurrentPlayer)
Sets the current player.- Parameters:
newCurrentPlayer- The new currentPlayer.
-
getMap
public Map getMap()
Gets the map that is being used in this game.- Returns:
- The game
Map.
-
setMap
public Map setMap(Map newMap)
Sets the game map.- Parameters:
newMap- The newMapto use.- Returns:
- The old
Map.
-
changeMap
public void changeMap(Map newMap)
Change the map in this game, fixing player destinations.- Parameters:
newMap- The newMapto use.
-
getNationOptions
public final NationOptions getNationOptions()
Get the current nation options.- Returns:
- The current
NationOptions.
-
setNationOptions
public final void setNationOptions(NationOptions newNationOptions)
Set the current nation options. Public for the test suite.- Parameters:
newNationOptions- The newNationOptionsvalue.
-
getVacantNation
public Nation getVacantNation()
Find an available (i.e. vacant) nation.- Returns:
- A vacant
Nationor null if none found.
-
getVacantNations
public final java.util.List<Nation> getVacantNations()
Get the currently available nations.- Returns:
- A list of available
Nations.
-
canAddNewPlayer
public boolean canAddNewPlayer()
Can a new player be added to this game?- Returns:
- True if a new player can be added.
-
getTurn
public Turn getTurn()
Gets the current turn in this game.- Returns:
- The current
Turn.
-
setTurn
public void setTurn(Turn newTurn)
Sets the current turn in this game.- Parameters:
newTurn- The newTurnto set.
-
getAge
public int getAge()
Get the age for the current turn.- Returns:
- The age (0-2).
-
getCombatModel
public final CombatModel getCombatModel()
Get the combat model in this game.- Returns:
- The
CombatModel.
-
setCombatModel
public final void setCombatModel(CombatModel newCombatModel)
Set the game combat model.- Parameters:
newCombatModel- The newCombatModelvalue.
-
getSpanishSuccession
public final boolean getSpanishSuccession()
Has the Spanish Succession event occured?- Returns:
- True if the Spanish Succession has occurred.
-
setSpanishSuccession
public final void setSpanishSuccession(boolean spanishSuccession)
Set the Spanish Succession value.- Parameters:
spanishSuccession- The new Spanish Succession value.
-
getInitialActiveUnitId
public java.lang.String getInitialActiveUnitId()
Get the identifier for the initial active unit.- Returns:
- The active unit identifier, if any.
-
getInitialActiveUnit
public Unit getInitialActiveUnit()
Get the initial active unit.- Returns:
- The initial active
Unitor null if none.
-
setInitialActiveUnitId
public void setInitialActiveUnitId(java.lang.String initialActiveUnitId)
Set the identifier for the initial active unit.- Parameters:
initialActiveUnitId- The identifier for the current active unit.
-
setFreeColGameObjectListener
public void setFreeColGameObjectListener(FreeColGameObjectListener fcgol)
Sets theFreeColGameObjectListenerattached to this game.- Parameters:
fcgol- The newFreeColGameObjectListener.
-
notifySetFreeColGameObject
public void notifySetFreeColGameObject(java.lang.String id, FreeColGameObject fcgo)Notify a listener (if any) of a new game object.- Parameters:
id- The object identifier.fcgo- The newFreeColGameObject.
-
notifyRemoveFreeColGameObject
public void notifyRemoveFreeColGameObject(java.lang.String id)
Notify a listener (if any) of that a game object has gone.- Parameters:
id- The object identifier.
-
notifyOwnerChanged
public void notifyOwnerChanged(FreeColGameObject source, Player oldOwner, Player newOwner)
Notify a listener (if any) of that a game object has changed owner.- Parameters:
source- TheFreeColGameObjectthat changed owner.oldOwner- The old owningPlayer.newOwner- The new owningPlayer.
-
checkOwners
public void checkOwners(Ownable o, Player oldOwner)
Maintain the player containers for certain ownables. Mainly useful in the client, informing the player that it has gained or lost an ownable.- Parameters:
o- TheOwnablethat may have changed.oldOwner- The previous (possible unchanged) owningPlayer.
-
allPlayersReadyToLaunch
public boolean allPlayersReadyToLaunch()
Checks if all players are ready to launch.- Returns:
- True if all players are ready to launch.
-
getAllColonies
public java.util.stream.Stream<Colony> getAllColonies(Player player)
Get all the colonies in the game.- Parameters:
player- An optionalPlayerto omit.- Returns:
- A stream of all the
Colonys in the game.
-
getAllColoniesList
public java.util.List<Colony> getAllColoniesList(Player player)
Get a list of all the colonies in the game.- Parameters:
player- An optionalPlayerto omit.- Returns:
- A list of all the
Colonys in the game.
-
getSettlementByName
public Settlement getSettlementByName(java.lang.String name)
Finds a settlement by name.- Parameters:
name- The name of theSettlement.- Returns:
- The
Settlementfound, ornullif there is no knownSettlementwith the specified name (the settlement might not be visible to a client).
-
getMessageSource
public FreeColGameObject getMessageSource(ModelMessage message)
Helper function to get the source object of a message in this game.- Parameters:
message- TheModelMessageto find the object in.- Returns:
- The source object.
-
getMessageDisplay
public FreeColObject getMessageDisplay(ModelMessage message)
Helper function to get the object to display with a message in this game.- Parameters:
message- TheModelMessageto find the object in.- Returns:
- An object to display.
-
getStatistics
public java.util.Map<java.lang.String,java.lang.String> getStatistics()
Gets the statistics of this game.- Returns:
- A
Mapof the statistics.
-
getLocationClass
public static java.lang.Class<? extends FreeColGameObject> getLocationClass(java.lang.String id)
Get a location class from an identifier.- Parameters:
id- The identifier to dissect.- Returns:
- The location class.
-
unserialize
public <T extends FreeColObject> T unserialize(java.lang.String xml, java.lang.Class<T> returnClass) throws javax.xml.stream.XMLStreamException
Unserialize from XML to a FreeColObject in this game.- Type Parameters:
T- The actual return type.- Parameters:
xml- The xml serialized version of an object.returnClass- The expected object class.- Returns:
- The unserialized object.
- Throws:
javax.xml.stream.XMLStreamException- if there are any problems reading from the stream.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Overrides:
checkIntegrityin classFreeColGameObject- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto log to.- Returns:
- A suitable
IntegrityType.
-
getSpecification
public Specification getSpecification()
Get the specification.- Overrides:
getSpecificationin classFreeColGameObject- Returns:
- The
Specificationused by this object.
-
setSpecification
public final void setSpecification(Specification specification)
Sets the specification for this object.- Overrides:
setSpecificationin classFreeColGameObject- Parameters:
specification- TheSpecificationto use.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classFreeColGameObject- Type Parameters:
T- TheFreeColObjectsubclass of the object to copy in.- Parameters:
other- The other object.- Returns:
- True if the copy in is succesful.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildrenin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributesin classFreeColGameObject- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildrenin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
readChild
protected void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChildin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classFreeColGameObject
-
hashCode
public int hashCode()
- Overrides:
hashCodein classFreeColGameObject
-
-