net.sf.freecol.server.model
Class ServerPlayer

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
          extended by net.sf.freecol.common.model.Player
              extended by net.sf.freecol.server.model.ServerPlayer
All Implemented Interfaces:
Nameable, Named, ServerModelObject

public class ServerPlayer
extends Player
implements ServerModelObject

A Player with additional (server specific) information. That is: pointers to this player's Connection and Socket


Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.Player
Player.ActivePredicate, Player.GoingToPredicate, Player.PlayerType, Player.Stance, Player.UnitIterator, Player.UnitPredicate
 
Field Summary
 
Fields inherited from class net.sf.freecol.common.model.Player
playerComparator, SCORE_INDEPENDENCE_DECLARED, SCORE_INDEPENDENCE_GRANTED, SCORE_SETTLEMENT_DESTROYED, UNKNOWN_ENEMY
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
ServerPlayer(Game game, java.lang.String name, boolean admin, boolean ai, java.net.Socket socket, Connection connection, Nation nation)
          Creates a new ServerPlayer.
ServerPlayer(Game game, java.lang.String name, boolean admin, java.net.Socket socket, Connection connection)
          Creates a new ServerPlayer.
ServerPlayer(javax.xml.stream.XMLStreamReader in)
           
 
Method Summary
 ModelMessage cashInTreasureTrain(Unit unit)
          Cash in a treasure train.
 void claimLand(Tile tile, Settlement settlement, int price)
          Claim the given land.
 java.util.List<FreeColObject> declareIndependence(java.lang.String nationName, java.lang.String countryName)
          Declare independence.
 Connection getConnection()
          Gets the connection of this player.
 int getRemainingEmigrants()
           
static java.lang.String getServerAdditionXMLElementTagName()
          Returns the tag name of the root element representing this object.
 java.net.Socket getSocket()
          Gets the socket of this player.
 java.util.List<ModelMessage> giveIndependence(ServerPlayer REFplayer)
          Gives independence to this player.
 boolean hasExplored(Tile tile)
          Checks if this Player has explored the given Tile.
 boolean isConnected()
          Checks if this player is currently connected to the server.
 void readFromServerAdditionElement(javax.xml.stream.XMLStreamReader in)
           
 void resetExploredTiles(Map map)
          Resets this player's explored tiles.
 void revealMap()
          (DEBUG ONLY) Makes the entire map visible.
 void setConnected(boolean connected)
          Sets the "connected"-status of this player.
 void setConnection(Connection connection)
          Sets the connection of this player.
 void setExplored(Tile tile)
          Sets the given tile to be explored by this player and updates the player's information about the tile.
 void setExplored(Unit unit)
          Sets the tiles within the given Unit's line of sight to be explored by this player.
 void setRemainingEmigrants(int emigrants)
           
 void toServerAdditionElement(javax.xml.stream.XMLStreamWriter out)
           
 java.lang.String toString()
          Returns the name of this player.
 void updateID()
          Sets the ID of the super class to be serverID.
 
Methods inherited from class net.sf.freecol.common.model.Player
addFather, addModelMessage, addSettlement, canBuildColonies, canHaveFoundingFathers, canMoveToEurope, canRecruitUnits, canSee, canTrade, canTrade, canTrade, canTrade, changeRelationWithPlayer, checkEmigrate, checkForDeath, clearModelMessages, divertModelMessages, endTurn, equals, generateRecruitable, generateRecruitablesList, getArrears, getArrears, getColonies, getColoniesPopulation, getColony, getColonyValue, getColor, getCurrentFather, getDead, getDefaultRegionName, getDefaultSettlementName, getDifficulty, getDominionsAtWar, getEntryLocation, getEurope, getEuropeName, getFatherCount, getFeatureContainer, getGold, getHistory, getImmigration, getImmigrationRequired, getIncomeAfterTaxes, getIncomeBeforeTaxes, getIndependentNationName, getIndex, getIndianSettlement, getIndianSettlements, getLandPrice, getLiberty, getLibertyProductionNextTurn, getMarket, getMarketName, getModelMessages, getMonarch, getMostValuableGoods, getName, getNation, getNationID, getNationType, getNewLandName, getNewModelMessages, getNextActiveUnit, getNextGoingToUnit, getNumberOfKingLandUnits, getNumberOfSettlements, getOutpostValue, getPlayerType, getRecruitPrice, getREFPlayer, getRemainingFoundingFatherCost, getRepairLocation, getRulerName, getSales, getScore, getSettlement, getSettlements, getSoL, getStance, getStanceAsString, getTax, getTension, getTotalFoundingFatherCost, getTradeRoutes, getUnit, getUnitIterator, getUnits, getXMLElementTagName, hasAbility, hasBeenAttackedByPrivateers, hasContacted, hasFather, hasManOfWar, hasNextActiveUnit, hasNextGoingToUnit, hasSettlement, hasTraded, incrementImmigration, incrementLiberty, invalidateCanSeeTiles, isAdmin, isAI, isAtWar, isDead, isEuropean, isIndian, isNewLandNamed, isReady, isREF, modifyGold, modifyIncomeAfterTaxes, modifyIncomeBeforeTaxes, modifySales, modifyScore, modifyTension, modifyTension, newTurn, reduceImmigration, reinitialiseMarket, removeModelMessages, removeSettlement, removeUnit, resetArrears, resetArrears, resetCanSeeTiles, resetTradeRouteCounts, setAI, setArrears, setArrears, setAttackedByPrivateers, setColor, setContacted, setCurrentFather, setDead, setEntryLocation, setFeatureContainer, setGold, setHistory, setImmigration, setImmigrationRequired, setIndependentNationName, setMonarch, setName, setNation, setNationType, setNewLandName, setNumberOfSettlements, setPlayerType, setReady, setScore, setStance, setTax, setTension, setTradeRoutes, setUnit, surrenderTo, updateImmigrationRequired
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addToRemoveElement, dispose, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, setGame, setId, toSavedXML, toXML, updateFreeColGameObject
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAttribute, hasListeners, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerPlayer

public ServerPlayer(Game game,
                    java.lang.String name,
                    boolean admin,
                    java.net.Socket socket,
                    Connection connection)
Creates a new ServerPlayer.

Parameters:
game - The Game this object belongs to.
name - The player name.
admin - Whether the player is the game administrator or not.
socket - The socket to the player's client.
connection - The Connection for the above mentioned socket.

ServerPlayer

public ServerPlayer(Game game,
                    java.lang.String name,
                    boolean admin,
                    boolean ai,
                    java.net.Socket socket,
                    Connection connection,
                    Nation nation)
Creates a new ServerPlayer.

Parameters:
game - The Game this object belongs to.
name - The player name.
admin - Whether the player is the game administrator or not.
ai - Whether this is an AI player.
socket - The socket to the player's client.
connection - The Connection for the above mentioned socket.
nation - The nation of the Player.

ServerPlayer

public ServerPlayer(javax.xml.stream.XMLStreamReader in)
             throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException
Method Detail

isConnected

public boolean isConnected()
Checks if this player is currently connected to the server.

Returns:
true if this player is currently connected to the server and false otherwise.

setConnected

public void setConnected(boolean connected)
Sets the "connected"-status of this player.

Parameters:
connected - Should be true if this player is currently connected to the server and false otherwise.
See Also:
isConnected()

getRemainingEmigrants

public int getRemainingEmigrants()

setRemainingEmigrants

public void setRemainingEmigrants(int emigrants)

claimLand

public void claimLand(Tile tile,
                      Settlement settlement,
                      int price)
Claim the given land.

Parameters:
tile - The Tile to claim.
settlement - The Settlement that will own the tile, if any.
price - The price to pay for the land, which must agree with the owner valuation, unless negative which denotes stealing.

declareIndependence

public java.util.List<FreeColObject> declareIndependence(java.lang.String nationName,
                                                         java.lang.String countryName)
Declare independence.

Parameters:
nationName - The new name for the independent nation.
countryName - The new name for its residents.

giveIndependence

public java.util.List<ModelMessage> giveIndependence(ServerPlayer REFplayer)
Gives independence to this player.


cashInTreasureTrain

public ModelMessage cashInTreasureTrain(Unit unit)
Cash in a treasure train.

Parameters:
unit - The treasure train Unit to cash in.

resetExploredTiles

public void resetExploredTiles(Map map)
Resets this player's explored tiles. This is done by setting all the tiles within a Units line of sight visible. The other tiles are made unvisible.

Parameters:
map - The Map to reset the explored tiles on.
See Also:
hasExplored(net.sf.freecol.common.model.Tile)

hasExplored

public boolean hasExplored(Tile tile)
Checks if this Player has explored the given Tile.

Overrides:
hasExplored in class Player
Parameters:
tile - The Tile.
Returns:
true if the Tile has been explored and false otherwise.

setExplored

public void setExplored(Tile tile)
Sets the given tile to be explored by this player and updates the player's information about the tile.

Overrides:
setExplored in class Player
Parameters:
tile - The Tile to set explored.
See Also:
Tile.updatePlayerExploredTile(Player)

setExplored

public void setExplored(Unit unit)
Sets the tiles within the given Unit's line of sight to be explored by this player.

Overrides:
setExplored in class Player
Parameters:
unit - The Unit.
See Also:
setExplored(Tile), hasExplored(net.sf.freecol.common.model.Tile)

revealMap

public void revealMap()
(DEBUG ONLY) Makes the entire map visible.


getSocket

public java.net.Socket getSocket()
Gets the socket of this player.

Returns:
The Socket.

getConnection

public Connection getConnection()
Gets the connection of this player.

Returns:
The Connection.

setConnection

public void setConnection(Connection connection)
Sets the connection of this player.

Parameters:
connection - The Connection.

toServerAdditionElement

public void toServerAdditionElement(javax.xml.stream.XMLStreamWriter out)
                             throws javax.xml.stream.XMLStreamException
Specified by:
toServerAdditionElement in interface ServerModelObject
Throws:
javax.xml.stream.XMLStreamException

updateID

public void updateID()
Sets the ID of the super class to be serverID.

Overrides:
updateID in class FreeColGameObject

readFromServerAdditionElement

public void readFromServerAdditionElement(javax.xml.stream.XMLStreamReader in)
                                   throws javax.xml.stream.XMLStreamException
Specified by:
readFromServerAdditionElement in interface ServerModelObject
Throws:
javax.xml.stream.XMLStreamException

getServerAdditionXMLElementTagName

public static java.lang.String getServerAdditionXMLElementTagName()
Returns the tag name of the root element representing this object.

Returns:
the tag name.

toString

public java.lang.String toString()
Description copied from class: Player
Returns the name of this player.

Overrides:
toString in class Player
Returns:
The name of this player.