net.sf.freecol.common.model
Class Player

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
All Implemented Interfaces:
Nameable
Direct Known Subclasses:
ServerPlayer

public class Player
extends FreeColGameObject
implements Nameable

Represents a player. The player can be either a human player or an AI-player. In addition to storing the name, nation e.t.c. of the player, it also stores various defaults for the player. One example of this is the entry location.


Nested Class Summary
 class Player.ActivePredicate
          A predicate for determining active units.
 class Player.GoingToPredicate
          A predicate for determining units going somewhere.
static class Player.NoClaimReason
          A variety of reasons why a tile can not be claimed, either to found a settlement or just to be used by one, including the double negative NONE == "no reason" case.
static class Player.PlayerType
          The type of player.
static class Player.Stance
          Constants for describing the stance towards a player.
 class Player.UnitIterator
          An Iterator of Units that can be made active.
 class Player.UnitPredicate
          A predicate that can be applied to a unit.
 
Field Summary
protected  boolean admin
          Is this player an admin?
protected  boolean ai
          True if this is an AI player.
protected  java.util.Set<FoundingFather> allFathers
          The founding fathers in this Player's congress.
static java.lang.String ASSIGN_SETTLEMENT_NAME
           
protected  boolean attackedByPrivateers
          True if player has been attacked by privateers.
private  java.lang.Object canSeeLock
           
private  boolean[][] canSeeTiles
           
protected  java.lang.String capitalName
           
protected  FoundingFather currentFather
          Current founding father being recruited.
protected  boolean dead
          Is this player dead?
protected  Location entryLocation
           
protected  Europe europe
          The European port/location for this player.
protected  FeatureContainer featureContainer
           
private static java.lang.String FOUNDING_FATHER_TAG
          The XML tag name for the set of founding fathers.
protected  int gold
          The amount of gold this player owns.
static int GOLD_NOT_ACCOUNTED
           
protected  HighSeas highSeas
          The HighSeas is a Location that enables Units to travel between the New World and one or several European Ports.
protected  java.util.List<HistoryEvent> history
          The history events occuring with this player.
protected  int immigration
          The number of immigration points.
protected  int immigrationRequired
           
protected  java.lang.String independentNationName
          The name of this player as an independent nation.
protected  java.util.HashMap<java.lang.String,LastSale> lastSales
          The last-sale data.
protected  int liberty
          The number of liberty points.
private static java.util.logging.Logger logger
           
protected  Market market
          The market for Europe.
private  int maximumFoodConsumption
           
protected  java.util.List<ModelMessage> modelMessages
          Model messages for this player.
protected  Monarch monarch
          The monarch for this player.
protected  java.lang.String name
          The name of this player.
protected  java.util.HashMap<java.lang.String,java.lang.Integer> nameIndex
          Indices of largest used region name by type.
protected  java.lang.String nationID
          The nation ID of this player, e.g.
protected  NationType nationType
          The NationType of this player.
protected  java.lang.String newLandName
          The name this player uses for the New World.
private  Player.UnitIterator nextActiveUnitIterator
           
private  Player.UnitIterator nextGoingToUnitIterator
           
private static java.lang.String OFFERED_FATHER_TAG
          The XML tag name for the set of offered founding fathers.
protected  java.util.List<FoundingFather> offeredFathers
          The offered founding fathers.
protected  int oldSoL
          SoL from last turn.
static java.util.Comparator<Player> playerComparator
           
protected  Player.PlayerType playerType
           
protected  boolean ready
           
protected  int score
          The current score of this player.
static int SCORE_SETTLEMENT_DESTROYED
           
protected  java.lang.String settlementFallback
           
protected  java.util.List<java.lang.String> settlementNames
          A cache of settlement names, a capital for natives, and a fallback settlement name prefix.
protected  java.util.List<Settlement> settlements
          The Settlements this player owns.
protected  java.util.Map<java.lang.String,Player.Stance> stance
          Stores the stance towards the other players.
private static java.lang.String STANCE_TAG
          The XML tag name for the stance array.
protected  int tax
          The current tax rate for this player.
protected  java.util.Map<Player,Tension> tension
          Only used by AI - stores the tension levels, 0-1000 with 1000 maximum hostility.
private static java.lang.String TENSION_TAG
          The XML tag name for the tension array.
protected  java.util.List<TradeRoute> tradeRoutes
          Trade routes of this player.
protected  java.util.Map<java.lang.String,Unit> units
          The Units this player owns.
static java.lang.String UNKNOWN_ENEMY
          The name of the unknown enemy.
 
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
UNITS_TAG_NAME
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
protected Player()
          Constructor for ServerPlayer.
protected Player(Game game)
          Constructor for ServerPlayer.
  Player(Game game, org.w3c.dom.Element e)
          Initiates a new Player from an Element and registers this Player at the specified game.
  Player(Game game, java.lang.String id)
          Initiates a new Player with the given ID.
  Player(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new Player from an Element and registers this Player at the specified game.
 
Method Summary
 void addFather(FoundingFather father)
          Add a founding father to the congress.
 void addHistory(HistoryEvent event)
          Add a HistoryEvent to this player.
 void addModelMessage(ModelMessage modelMessage)
          Adds a ModelMessage for this player.
 void addSettlement(Settlement settlement)
          Adds a given settlement to this player's list of settlements.
 boolean atWarWith(Player player)
          Is this player at war with the specified one.
 boolean canAcquireForImprovement(Tile tile)
          Can a tile be acquired from its owners and used for an improvement? Slightly weakens canClaimForImprovement to allow for purchase and/or stealing.
 boolean canBuildColonies()
          Checks if this Player can build colonies.
 boolean canClaimForImprovement(Tile tile)
          Can the ownership of this tile be claimed for the purposes of making an improvement.
 boolean canClaimForSettlement(Tile tile)
          Checks if a tile can be claimed for use by a settlement.
 Player.NoClaimReason canClaimForSettlementReason(Tile tile)
          The test for whether a tile can be freely claimed by a player settlement (freely => not by purchase or stealing).
private  boolean canClaimFreeCenterTile(Tile tile)
          Is this tile claimable for a colony center tile under the special provisions of the model.option.buildOnNativeLand option.
 boolean canClaimToFoundSettlement(Tile tile)
          Can a tile be claimed to found a settlement on?
 Player.NoClaimReason canClaimToFoundSettlementReason(Tile tile)
          Can a tile be claimed to found a settlement on? Almost the same as canClaimForSettlement but there is an extra requirement that the tile be of a settleable type, and some relaxations that allow free center tile acquisition
 boolean canHaveFoundingFathers()
          Checks if this Player can get founding fathers.
 boolean canMoveToEurope()
          Checks if this Player can move units to Europe.
 boolean canOwnTile(Tile tile)
          Can a tile be owned by this player?
private  Player.NoClaimReason canOwnTileReason(Tile tile)
          Can a tile be owned by this player? This is a test of basic practicality and does not consider the full complexity of tile ownership issues.
 boolean canRecruitUnits()
          Checks if this Player can recruit units by producing immigration.
 boolean canSee(Tile tile)
          Checks if this Player can see the given Tile.
 boolean canTrade(Goods goods)
          Returns true if type of goods can be traded in Europe.
 boolean canTrade(Goods goods, Market.Access access)
          Returns true if type of goods can be traded at specified place
 boolean canTrade(GoodsType type)
          Returns true if type of goods can be traded in Europe.
 boolean canTrade(GoodsType type, Market.Access access)
          Returns true if type of goods can be traded at specified place.
 boolean checkEmigrate()
          Checks to see whether or not a colonist can emigrate, and does so if possible.
 boolean checkGold(int amount)
          Checks if the player has enough gold to make a purchase.
 void clearModelMessages()
          Removes all the model messages for this player.
 void clearOfferedFathers()
          Clear the set of offered fathers.
 void divertModelMessages(FreeColGameObject source, FreeColGameObject newSource)
          Sometimes an event causes the source (and display) fields in an accumulated model message to become invalid (e.g.
 boolean equals(Player o)
          Checks if the given Player equals this object.
 int getArrears(Goods goods)
          Returns the arrears due for a type of goods.
 int getArrears(GoodsType type)
          Returns the arrears due for a type of goods.
 boolean getAttackedByPrivateers()
          Returns whether this player has been attacked by privateers.
 java.lang.String getCapitalName()
          Gets the name of this players capital.
 java.util.List<Colony> getColonies()
          Gets a fresh list of all colonies this player owns.
 int getColoniesPopulation()
          Returns the sum of units currently working in the colonies of this player.
 Colony getColony(java.lang.String name)
          Returns the Colony with the given name.
 int getColonyValue(Tile t)
          Gets the value of building a Colony on the given tile.
 FoundingFather getCurrentFather()
          Gets the founding father this player is working towards.
 boolean getDead()
          Get the player death state.
 java.lang.String getDisplayName()
          Gets the name to display for this player.
 Location getEntryLocation()
          Gets the default Location where the units arriving from Europe will be put.
 Europe getEurope()
          Returns the europe object that this player has.
 java.lang.String getEuropeNameKey()
          Describe getEuropeName method here.
 int getFatherCount()
          Returns the number of founding fathers in this players congress.
 java.util.Set<FoundingFather> getFathers()
          Returns the founding fathers in this player's congress.
 FeatureContainer getFeatureContainer()
          Get the FeatureContainer value.
 int getGold()
          Returns the amount of gold that this player has.
 HighSeas getHighSeas()
          Get the HighSeas value.
 java.util.List<HistoryEvent> getHistory()
          Get the History value.
 int getImmigration()
          Gets the number of immigration this player possess.
 int getImmigrationRequired()
          Gets the number of immigration required to cause a new colonist to emigrate.
 int getIncomeAfterTaxes(GoodsType goodsType)
          Returns the current incomeAfterTaxes.
 int getIncomeBeforeTaxes(GoodsType goodsType)
          Returns the current incomeBeforeTaxes.
 java.lang.String getIndependentNationName()
          Get the IndependentNationName value.
 IndianSettlement getIndianSettlement(java.lang.String name)
          Returns the IndianSettlement with the given name.
 java.util.List<IndianSettlement> getIndianSettlements()
          Returns a list of all IndianSettlements this player owns.
 java.util.List<IndianSettlement> getIndianSettlementsWithMission(Player other)
          Returns a list of all IndianSettlements this player owns that have missions, optionally owned by a specific player.
 int getLandPrice(Tile tile)
          Returns the price of the given land.
 LastSale getLastSale(Location where, GoodsType what)
          Gets the current sales data for a location and goods type.
 java.lang.String getLastSaleString(Location where, GoodsType what)
          Gets the last sale price for a location and goods type as a string.
 int getLiberty()
          Gets the current amount of liberty this Player has.
 int getLibertyProductionNextTurn()
          Returns how many total liberty will be produced if no colonies are lost and nothing unexpected happens.
 Market getMarket()
          Returns this Player's Market.
 StringTemplate getMarketName()
          What is the name of the player's market? Following a declaration of independence we are assumed to trade broadly with any European market rather than a specific port.
 int getMaximumFoodConsumption()
          Returns the maximum food consumption of any unit types available to this player.
 java.util.List<ModelMessage> getModelMessages()
          Returns all ModelMessages for this player.
 java.util.Set<Modifier> getModifierSet(java.lang.String id)
          Get the modifier set for a given id from the feature container.
 java.util.Set<Modifier> getModifierSet(java.lang.String id, FreeColGameObjectType type)
          Get the modifier set for a given id and type from the feature container.
 Monarch getMonarch()
          Returns the monarch object this player has.
 Goods getMostValuableGoods()
          Returns the most valuable goods available in one of the player's colonies for the purposes of choosing a threat-to-boycott.
 java.lang.String getName()
          Returns the name of this player.
 int getNameIndex(java.lang.String key)
          Gets the name index for a given key.
 java.lang.String getNameKey()
           
 Nation getNation()
          Return this Player's nation.
 java.lang.String getNationID()
          Return the ID of this Player's nation.
 StringTemplate getNationName()
          Returns the nation of this player as a String.
 java.lang.String getNationNameKey()
          Gets a nation name suitable for use in message IDs.
 NationType getNationType()
          Returns the nation type of this player.
 java.lang.String getNewLandName()
          Gets the name this player has chosen for the new land.
 java.util.List<ModelMessage> getNewModelMessages()
          Returns all new ModelMessages for this player.
 Unit getNextActiveUnit()
          Gets a new active unit.
 Unit getNextGoingToUnit()
          Gets a new going_to unit.
 int getNumberOfKingLandUnits()
          Gets the number of King's land units.
 int getNumberOfSettlements()
          Get the number of settlements.
 java.util.List<FoundingFather> getOfferedFathers()
          Gets the set of offered fathers for this player.
 int getOutpostValue(Tile t)
          Calculates the value of an outpost-type colony at this tile.
 Player.PlayerType getPlayerType()
          Returns the type of this player.
 int getPrice(AbstractUnit au)
          Gets the price to this player for a proposed unit.
 java.util.List<Player> getRebels()
          Gets a list of the players in rebellion against this (REF) player.
 int getRecruitPrice()
          Gets the price for a recruit in europe.
 Player getREFPlayer()
          Gets the Player controlling the "Royal Expeditionary Force" for this player.
 int getRemainingFoundingFatherCost()
          Gets the number of liberty points needed to recruit the next founding father.
 java.lang.String getRulerNameKey()
          Get the RulerName value.
 int getSales(GoodsType goodsType)
          Returns the current sales.
 int getScore()
          Returns the current score of the player.
 Settlement getSettlement(java.lang.String name)
          Find a Settlement by name.
 java.lang.String getSettlementName()
          Gets a settlement name suitable for this player.
 java.util.List<Settlement> getSettlements()
          Returns a list of all Settlements this player owns.
 int getSoL()
          Gets the total percentage of rebels in all this player's colonies.
 java.util.List<Colony> getSortedColonies(java.util.Comparator<Colony> c)
          Returns a sorted list of all Colonies this player owns.
 Player.Stance getStance(Player player)
          Returns the stance towards a given player.
 int getTax()
          Returns the current tax.
 Tension getTension(Player player)
          Gets the hostility this player has against the given player.
 int getTotalFoundingFatherCost()
          Returns how many liberty points in total are needed to earn the Founding Father we are trying to recruit.
 java.util.List<TradeRoute> getTradeRoutes()
          Get the TradeRoutes value.
 Unit getUnit(java.lang.String id)
          Get the Unit value.
 java.util.Iterator<Unit> getUnitIterator()
          Gets an Iterator containing all the units this player owns.
 java.util.List<Unit> getUnits()
           
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean hasAbility(java.lang.String ability)
          Does a player have a particular ability.
 boolean hasContacted(Player player)
          Returns whether this player has met with the Player if the given nation.
 boolean hasContactedEuropeans()
          Returns whether this player has met with any Europeans at all.
 boolean hasContactedIndians()
          Returns whether this player has met with any natives at all.
 boolean hasExplored(Tile tile)
          Checks if this Player has explored the given Tile.
 boolean hasFather(FoundingFather someFather)
          Determines whether this player has a certain Founding father.
 boolean hasManOfWar()
          Checks if this player has a single Man-of-War.
 boolean hasNextActiveUnit()
          Checks if a new active unit can be made active.
 boolean hasNextGoingToUnit()
          Checks if a new active unit can be made active.
 boolean hasSettlement(Settlement s)
          Checks if this player owns the given Settlement.
 boolean hasTraded(GoodsType goodsType)
          Has a type of goods been traded?
 boolean hasVisited(IndianSettlement settlement)
          Has a player visited a native settlement? This is needed by the native report and settlement popup to clarify whether the skill at the settlement is null because it has been depleted, or because we just have not found out what it is yet.
private  boolean hasZeroSettlements()
          The second and third cases of buildOnNative land need to test if the player has no settlements yet.
 void incrementImmigration(int amount)
           
 void incrementLiberty(int amount)
          Adds to the current amount of liberty this player has.
 void initializeHighSeas()
          Initialize the highSeas.
 void installSettlementNames(java.util.List<java.lang.String> names, java.util.Random random)
          Installs suitable settlement names (and the capital if native) into the player name cache.
 void invalidateCanSeeTiles()
          Forces an update of the canSeeTiles.
 boolean isAdmin()
          Checks if this player is an admin.
 boolean isAI()
          Determines whether this player is an AI player.
 boolean isAtWar()
          Checks whether this player is at war with any other player.
 boolean isDead()
          Checks if this player is dead.
 boolean isEuropean()
          Checks if this player is european.
 boolean isIndian()
          Checks if this player is indian.
 boolean isNewLandNamed()
          Returns true if the player already selected a new name for the discovered land.
 boolean isReady()
          Checks if this Player is ready to start the game.
 boolean isREF()
          Checks if this player is a "royal expeditionary force.
 boolean isUndead()
          Checks if this player is undead.
 boolean isUnknownEnemy()
          Is this player the unknown enemy?
 boolean isWorkForREF()
          Checks if this player has work to do if it is a REF-player.
private  boolean[][] makeCanSeeTiles(Map map)
          Builds a canSeeTiles array.
static void makeContact(Player player1, Player player2)
          Set this player as having made initial contact with another player.
 int modifyGold(int amount)
          Modifies the amount of gold that this player has.
 void modifyIncomeAfterTaxes(GoodsType goodsType, int amount)
          Modifies the current incomeAfterTaxes.
 void modifyIncomeBeforeTaxes(GoodsType goodsType, int amount)
          Modifies the current incomeBeforeTaxes.
 void modifySales(GoodsType goodsType, int amount)
          Modifies the current sales.
 void modifyScore(int value)
          Modifies the score of the player by the given value.
 java.util.List<FreeColGameObject> modifyTension(Player player, int addToTension)
          Modifies the hostility against the given player.
 java.util.List<FreeColGameObject> modifyTension(Player player, int addToTension, Settlement origin)
          Modifies the hostility against the given player.
 boolean owns(Ownable ownable)
           
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
protected  void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
          Partial reader for players, so that simple updates to fields such as gold can be brief.
protected  boolean recalculateBellsBonus()
          Recalculate bells bonus when tax changes.
 void reduceImmigration()
          Sets the number of immigration this player possess.
 void reinitialiseMarket()
          Resets this Player's Market.
 void removeModelMessages()
          Removes all undisplayed model messages for this player.
 void removeSettlement(Settlement settlement)
          Removes the given settlement from this player's list of settlements.
 void removeTension(Player player)
          Removes all tension with respect to a given player.
 void removeUnit(Unit oldUnit)
          Remove Unit.
private  boolean resetCanSeeTiles()
          Resets this player's "can see"-tiles.
 void resetIterators()
          Reset the player iterators ready for a new turn.
 void saveSale(LastSale sale)
          Saves a LastSale record.
 void setAI(boolean ai)
          Sets whether this player is an AI player.
 void setAttackedByPrivateers(boolean attacked)
          Sets whether this player has been attacked by privateers.
 void setCurrentFather(FoundingFather someFather)
          Sets this players liberty bell production to work towards recruiting father to its congress.
 void setDead(boolean dead)
          Sets this player to be dead or not.
 void setEntryLocation(Location entryLocation)
          Sets the Location where the units arriving from Europe will be put as a default.
 void setEurope(Europe europe)
          Set the europe object for a 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 setFeatureContainer(FeatureContainer newFeatureContainer)
          Set the FeatureContainer value.
 void setGold(int newGold)
          Set the amount of gold that this player has.
 void setImmigration(int immigration)
          Sets the number of immigration this player possess.
 void setImmigrationRequired(int immigrationRequired)
          Sets the number of immigration required to cause a new colonist to emigrate.
 void setIndependentNationName(java.lang.String newIndependentNationName)
          Set the IndependentNationName value.
 void setLiberty(int liberty)
          Sets the current amount of liberty this player has.
 void setMonarch(Monarch monarch)
          Sets the monarch object this player has.
 void setName(java.lang.String newName)
          Set the Name value.
 void setNameIndex(java.lang.String key, int value)
          Gets the name index for a given key.
 void setNation(Nation newNation)
          Sets the nation for this player.
 void setNationType(NationType newNationType)
          Sets the nation type of this player.
 void setNewLandName(java.lang.String newLandName)
          Sets the name this player uses for the new land.
 boolean setNextActiveUnit(Unit unit)
          Sets a new active unit.
 void setOfferedFathers(java.util.List<FoundingFather> fathers)
          Sets the set of offered fathers.
 void setPlayerType(Player.PlayerType type)
          Sets the player type.
 void setReady(boolean ready)
          Sets this Player to be ready/not ready for starting the game.
 void setScore(int newScore)
          Set the current score of the player.
 boolean setStance(Player player, Player.Stance newStance)
          Sets the stance towards a given player to one of WAR, CEASE_FIRE, PEACE and ALLIANCE.
 void setTax(int amount)
          Sets the current tax
 void setTension(Player player, Tension newTension)
          Sets the hostility against the given player.
 void setTradeRoutes(java.util.List<TradeRoute> newTradeRoutes)
          Set the players trade routes.
 void setUnit(Unit newUnit)
          Set the Unit value.
 java.lang.String toString()
          Returns the name of this player.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
protected  void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out, java.lang.String[] fields)
          Partial writer for players, so that simple updates to fields such as gold can be brief.
 void updateImmigrationRequired()
          Updates the amount of immigration needed to emigrate a Unit from Europe.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
           
protected  void writeChildren(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
           
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeList, equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

GOLD_NOT_ACCOUNTED

public static final int GOLD_NOT_ACCOUNTED
See Also:
Constant Field Values

SCORE_SETTLEMENT_DESTROYED

public static final int SCORE_SETTLEMENT_DESTROYED
See Also:
Constant Field Values

ASSIGN_SETTLEMENT_NAME

public static final java.lang.String ASSIGN_SETTLEMENT_NAME
See Also:
Constant Field Values

FOUNDING_FATHER_TAG

private static final java.lang.String FOUNDING_FATHER_TAG
The XML tag name for the set of founding fathers.

See Also:
Constant Field Values

OFFERED_FATHER_TAG

private static final java.lang.String OFFERED_FATHER_TAG
The XML tag name for the set of offered founding fathers.

See Also:
Constant Field Values

STANCE_TAG

private static final java.lang.String STANCE_TAG
The XML tag name for the stance array.

See Also:
Constant Field Values

TENSION_TAG

private static final java.lang.String TENSION_TAG
The XML tag name for the tension array.

See Also:
Constant Field Values

UNKNOWN_ENEMY

public static final java.lang.String UNKNOWN_ENEMY
The name of the unknown enemy.

See Also:
Constant Field Values

tension

protected java.util.Map<Player,Tension> tension
Only used by AI - stores the tension levels, 0-1000 with 1000 maximum hostility.


stance

protected java.util.Map<java.lang.String,Player.Stance> stance
Stores the stance towards the other players. One of: WAR, CEASE_FIRE, PEACE and ALLIANCE.


name

protected java.lang.String name
The name of this player. This defaults to the user name in case of a human player and the rulerName of the NationType in case of an AI player.


independentNationName

protected java.lang.String independentNationName
The name of this player as an independent nation.


nationType

protected NationType nationType
The NationType of this player.


nationID

protected java.lang.String nationID
The nation ID of this player, e.g. "model.nation.dutch".


newLandName

protected java.lang.String newLandName
The name this player uses for the New World.


admin

protected boolean admin
Is this player an admin?


score

protected int score
The current score of this player.


gold

protected int gold
The amount of gold this player owns.


immigration

protected int immigration
The number of immigration points. Immigration points are an abstract game concept. They are generated by but are not identical to crosses.


liberty

protected int liberty
The number of liberty points. Liberty points are an abstract game concept. They are generated by but are not identical to bells.


market

protected Market market
The market for Europe.


europe

protected Europe europe
The European port/location for this player.


monarch

protected Monarch monarch
The monarch for this player.


ready

protected boolean ready

ai

protected boolean ai
True if this is an AI player.


attackedByPrivateers

protected boolean attackedByPrivateers
True if player has been attacked by privateers.


oldSoL

protected int oldSoL
SoL from last turn.


dead

protected boolean dead
Is this player dead?


allFathers

protected final java.util.Set<FoundingFather> allFathers
The founding fathers in this Player's congress.


currentFather

protected FoundingFather currentFather
Current founding father being recruited.


offeredFathers

protected final java.util.List<FoundingFather> offeredFathers
The offered founding fathers.


tax

protected int tax
The current tax rate for this player.


playerType

protected Player.PlayerType playerType

immigrationRequired

protected int immigrationRequired

entryLocation

protected Location entryLocation

units

protected final java.util.Map<java.lang.String,Unit> units
The Units this player owns.


settlements

protected final java.util.List<Settlement> settlements
The Settlements this player owns.


tradeRoutes

protected final java.util.List<TradeRoute> tradeRoutes
Trade routes of this player.


modelMessages

protected final java.util.List<ModelMessage> modelMessages
Model messages for this player.


history

protected final java.util.List<HistoryEvent> history
The history events occuring with this player.


lastSales

protected java.util.HashMap<java.lang.String,LastSale> lastSales
The last-sale data.


nameIndex

protected final java.util.HashMap<java.lang.String,java.lang.Integer> nameIndex
Indices of largest used region name by type.


canSeeTiles

private boolean[][] canSeeTiles

canSeeLock

private final java.lang.Object canSeeLock

featureContainer

protected FeatureContainer featureContainer

maximumFoodConsumption

private int maximumFoodConsumption

nextActiveUnitIterator

private final Player.UnitIterator nextActiveUnitIterator

nextGoingToUnitIterator

private final Player.UnitIterator nextGoingToUnitIterator

highSeas

protected HighSeas highSeas
The HighSeas is a Location that enables Units to travel between the New World and one or several European Ports.


settlementNames

protected java.util.List<java.lang.String> settlementNames
A cache of settlement names, a capital for natives, and a fallback settlement name prefix. Does not need to be serialized.


capitalName

protected java.lang.String capitalName

settlementFallback

protected java.lang.String settlementFallback

playerComparator

public static final java.util.Comparator<Player> playerComparator
Constructor Detail

Player

protected Player()
Constructor for ServerPlayer.


Player

protected Player(Game game)
Constructor for ServerPlayer.


Player

public Player(Game game,
              javax.xml.stream.XMLStreamReader in)
       throws javax.xml.stream.XMLStreamException
Initiates a new Player from an Element and registers this Player at the specified game.

Parameters:
game - The Game this object belongs to.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

Player

public Player(Game game,
              org.w3c.dom.Element e)
Initiates a new Player from an Element and registers this Player at the specified game.

Parameters:
game - The Game this object belongs to.
e - An XML-element that will be used to initialize this object.

Player

public Player(Game game,
              java.lang.String id)
Initiates a new Player with the given ID. The object should later be initialized by calling either FreeColGameObject.readFromXML(XMLStreamReader) or FreeColObject.readFromXMLElement(Element).

Parameters:
game - The Game in which this object belong.
id - The unique identifier for this object.
Method Detail

getFeatureContainer

public final FeatureContainer getFeatureContainer()
Get the FeatureContainer value.

Returns:
a FeatureContainer value

setFeatureContainer

public final void setFeatureContainer(FeatureContainer newFeatureContainer)
Set the FeatureContainer value.

Parameters:
newFeatureContainer - The new FeatureContainer value.

getModifierSet

public java.util.Set<Modifier> getModifierSet(java.lang.String id)
Get the modifier set for a given id from the feature container.

Parameters:
id - The id to look up.
Returns:
The modifier set.

getModifierSet

public java.util.Set<Modifier> getModifierSet(java.lang.String id,
                                              FreeColGameObjectType type)
Get the modifier set for a given id and type from the feature container.

Parameters:
id - The id to look up.
type - The associated type.
Returns:
The modifier set.

hasAbility

public boolean hasAbility(java.lang.String ability)
Does a player have a particular ability.

Overrides:
hasAbility in class FreeColObject
Parameters:
ability - The ability to test.
Returns:
True if the player has the ability.

addModelMessage

public void addModelMessage(ModelMessage modelMessage)
Adds a ModelMessage for this player.

Parameters:
modelMessage - The ModelMessage.

getModelMessages

public java.util.List<ModelMessage> getModelMessages()
Returns all ModelMessages for this player.

Returns:
all ModelMessages for this player.

getNewModelMessages

public java.util.List<ModelMessage> getNewModelMessages()
Returns all new ModelMessages for this player.

Returns:
all new ModelMessages for this player.

removeModelMessages

public void removeModelMessages()
Removes all undisplayed model messages for this player.


clearModelMessages

public void clearModelMessages()
Removes all the model messages for this player.


divertModelMessages

public void divertModelMessages(FreeColGameObject source,
                                FreeColGameObject newSource)
Sometimes an event causes the source (and display) fields in an accumulated model message to become invalid (e.g. Europe disappears on independence). This routine is for cleaning up such cases.

Parameters:
source - the source field that has become invalid
newSource - a new source field to replace the old with, or if null then remove the message

getMaximumFoodConsumption

public int getMaximumFoodConsumption()
Returns the maximum food consumption of any unit types available to this player.

Returns:
an int value

getScore

public int getScore()
Returns the current score of the player.

Returns:
an int value

setScore

public void setScore(int newScore)
Set the current score of the player.

Parameters:
newScore - The new score.

modifyScore

public void modifyScore(int value)
Modifies the score of the player by the given value.

Parameters:
value - an int value

getMarket

public Market getMarket()
Returns this Player's Market.

Returns:
This Player's Market.

reinitialiseMarket

public void reinitialiseMarket()
Resets this Player's Market.


getMarketName

public StringTemplate getMarketName()
What is the name of the player's market? Following a declaration of independence we are assumed to trade broadly with any European market rather than a specific port.

Returns:
A name for the player's market.

hasSettlement

public boolean hasSettlement(Settlement s)
Checks if this player owns the given Settlement.

Parameters:
s - The Settlement.
Returns:
true if this Player owns the given Settlement.

addSettlement

public void addSettlement(Settlement settlement)
Adds a given settlement to this player's list of settlements.

Parameters:
settlement - The Settlement to add.

removeSettlement

public void removeSettlement(Settlement settlement)
Removes the given settlement from this player's list of settlements.

Parameters:
settlement - The Settlement to remove.

owns

public boolean owns(Ownable ownable)

getSettlements

public java.util.List<Settlement> getSettlements()
Returns a list of all Settlements this player owns.

Returns:
The settlements this player owns.

getNumberOfSettlements

public int getNumberOfSettlements()
Get the number of settlements.

Returns:
The number of settlements this player has.

getColonies

public java.util.List<Colony> getColonies()
Gets a fresh list of all colonies this player owns.

Returns:
A fresh list of the colonies this player owns.

getSortedColonies

public java.util.List<Colony> getSortedColonies(java.util.Comparator<Colony> c)
Returns a sorted list of all Colonies this player owns.

Parameters:
c - A comparator to operate on the colony list.
Returns:
A fresh list of the colonies this player owns.

getColoniesPopulation

public int getColoniesPopulation()
Returns the sum of units currently working in the colonies of this player.

Returns:
Sum of units currently working in the colonies.

getColony

public Colony getColony(java.lang.String name)
Returns the Colony with the given name.

Parameters:
name - The name of the Colony.
Returns:
The Colony or null if this player does not have a Colony with the specified name.

getIndianSettlements

public java.util.List<IndianSettlement> getIndianSettlements()
Returns a list of all IndianSettlements this player owns.

Returns:
The indian settlements this player owns.

getIndianSettlement

public IndianSettlement getIndianSettlement(java.lang.String name)
Returns the IndianSettlement with the given name.

Parameters:
name - The name of the IndianSettlement.
Returns:
The IndianSettlement or null if this player does not have a IndianSettlement with the specified name.

getIndianSettlementsWithMission

public java.util.List<IndianSettlement> getIndianSettlementsWithMission(Player other)
Returns a list of all IndianSettlements this player owns that have missions, optionally owned by a specific player.

Parameters:
other - If non-null, collect only missions established by this Player
Returns:
The settlements this player owns with the specified mission type.

getSettlement

public Settlement getSettlement(java.lang.String name)
Find a Settlement by name.

Parameters:
name - The name of the Settlement.
Returns:
The Settlement, or null if not found.

installSettlementNames

public void installSettlementNames(java.util.List<java.lang.String> names,
                                   java.util.Random random)
Installs suitable settlement names (and the capital if native) into the player name cache.

Parameters:
names - A list of settlement names with the fallback prefix first.
random - A Random number source.

getCapitalName

public java.lang.String getCapitalName()
Gets the name of this players capital. Only meaningful to natives.

Returns:
The name of this players capital.

getSettlementName

public java.lang.String getSettlementName()
Gets a settlement name suitable for this player.

Returns:
A new settlement name.

getPlayerType

public Player.PlayerType getPlayerType()
Returns the type of this player.

Returns:
The player type.

setPlayerType

public void setPlayerType(Player.PlayerType type)
Sets the player type.

Parameters:
type - The new player type.
See Also:
getPlayerType()

isEuropean

public boolean isEuropean()
Checks if this player is european. This includes the "Royal Expeditionay Force".

Returns:
true if this player is european and false otherwise.

isIndian

public boolean isIndian()
Checks if this player is indian. This method returns the opposite of isEuropean().

Returns:
true if this player is indian and false otherwise.

isUndead

public boolean isUndead()
Checks if this player is undead.

Returns:
True if this player is undead.

isREF

public boolean isREF()
Checks if this player is a "royal expeditionary force.

Returns:
true is the given nation is a royal expeditionary force and false otherwise.

isAI

public boolean isAI()
Determines whether this player is an AI player.

Returns:
Whether this player is an AI player.

setAI

public void setAI(boolean ai)
Sets whether this player is an AI player.

Parameters:
ai - true if this Player is controlled by the computer.

isAdmin

public boolean isAdmin()
Checks if this player is an admin.

Returns:
true if the player is an admin and false otherwise.

isDead

public boolean isDead()
Checks if this player is dead. A Player dies when it loses the game.

Returns:
true if this Player is dead.

getDead

public boolean getDead()
Get the player death state. This is indeed identical to isDead(), but is needed for partial updates to complement the setDead() function.

Returns:
True if this Player is dead.

setDead

public void setDead(boolean dead)
Sets this player to be dead or not.

Parameters:
dead - Should be set to true when this Player dies.
See Also:
isDead()

isAtWar

public boolean isAtWar()
Checks whether this player is at war with any other player.

Returns:
true if this player is at war with any other.

isWorkForREF

public boolean isWorkForREF()
Checks if this player has work to do if it is a REF-player.

Returns:
True if any of our units are located in the new world or a nation is in rebellion against us.

getRebels

public java.util.List<Player> getRebels()
Gets a list of the players in rebellion against this (REF) player.

Returns:
A list of nations in rebellion against us.

canOwnTile

public boolean canOwnTile(Tile tile)
Can a tile be owned by this player?

Parameters:
tile - The Tile to consider.
Returns:
True if the tile can be owned by this player.

canOwnTileReason

private Player.NoClaimReason canOwnTileReason(Tile tile)
Can a tile be owned by this player? This is a test of basic practicality and does not consider the full complexity of tile ownership issues.

Parameters:
tile - The Tile to consider.
Returns:
The reason why/not the tile can be owned by this player.

canClaimForSettlement

public boolean canClaimForSettlement(Tile tile)
Checks if a tile can be claimed for use by a settlement.

Parameters:
tile - The Tile to try to claim.
Returns:
True if the tile can be claimed to found a settlement.

canClaimForSettlementReason

public Player.NoClaimReason canClaimForSettlementReason(Tile tile)
The test for whether a tile can be freely claimed by a player settlement (freely => not by purchase or stealing). The rule for the center tile is different, see below. The tile must be ownable by this player, settlement-free, and either not currently owned, owned by this player and not by another settlement that is using the tile, or owned by someone else who does not want anything for it. Got that?

Parameters:
tile - The Tile to try to claim.
Returns:
The reason why/not the tile can be claimed.

canClaimToFoundSettlement

public boolean canClaimToFoundSettlement(Tile tile)
Can a tile be claimed to found a settlement on?

Parameters:
tile - The Tile to try to claim.
Returns:
True if the tile can be claimed to found a settlement.

canClaimToFoundSettlementReason

public Player.NoClaimReason canClaimToFoundSettlementReason(Tile tile)
Can a tile be claimed to found a settlement on? Almost the same as canClaimForSettlement but there is an extra requirement that the tile be of a settleable type, and some relaxations that allow free center tile acquisition

Parameters:
tile - The Tile to try to claim.
Returns:
The reason why/not the tile can be claimed.

canClaimFreeCenterTile

private boolean canClaimFreeCenterTile(Tile tile)
Is this tile claimable for a colony center tile under the special provisions of the model.option.buildOnNativeLand option.

Parameters:
tile - The Tile to try to claim.
Returns:
True if the tile can be claimed.

hasZeroSettlements

private boolean hasZeroSettlements()
The second and third cases of buildOnNative land need to test if the player has no settlements yet. We can not just check that the number of settlement is zero because by the time the settlement is being placed and we are collecting the tiles to claim, the settlement already exists and thus there will already be one settlement--- so we have to check if that one settlement is on the map yet.

Returns:
True if the player has no settlements (on the map) yet.

canClaimForImprovement

public boolean canClaimForImprovement(Tile tile)
Can the ownership of this tile be claimed for the purposes of making an improvement. Quick test that does not handle the curly case of tile transfer between colonies, or guarantee success (natives may want to be paid), but just that success is possible.

Parameters:
tile - The Tile to consider.
Returns:
True if the tile ownership can be claimed.

canAcquireForImprovement

public boolean canAcquireForImprovement(Tile tile)
Can a tile be acquired from its owners and used for an improvement? Slightly weakens canClaimForImprovement to allow for purchase and/or stealing.

Parameters:
tile - The Tile to consider.
Returns:
True if the tile ownership can be claimed.

getUnit

public final Unit getUnit(java.lang.String id)
Get the Unit value.

Returns:
a List value

setUnit

public final void setUnit(Unit newUnit)
Set the Unit value.

Parameters:
newUnit - The new Units value.

removeUnit

public void removeUnit(Unit oldUnit)
Remove Unit.

Parameters:
oldUnit - an Unit value

getPrice

public int getPrice(AbstractUnit au)
Gets the price to this player for a proposed unit.

Parameters:
au - The proposed AbstractUnit.
Returns:
The price for the unit.

getSoL

public int getSoL()
Gets the total percentage of rebels in all this player's colonies.

Returns:
The total percentage of rebels in all this player's colonies.

getIndependentNationName

public final java.lang.String getIndependentNationName()
Get the IndependentNationName value.

Returns:
a String value

setIndependentNationName

public final void setIndependentNationName(java.lang.String newIndependentNationName)
Set the IndependentNationName value.

Parameters:
newIndependentNationName - The new IndependentNationName value.

getREFPlayer

public Player getREFPlayer()
Gets the Player controlling the "Royal Expeditionary Force" for this player.

Returns:
The player, or null if this player does not have a royal expeditionary force.

getNewLandName

public java.lang.String getNewLandName()
Gets the name this player has chosen for the new land.

Returns:
The name of the new world as chosen by the Player, or null if none chosen yet.

isNewLandNamed

public boolean isNewLandNamed()
Returns true if the player already selected a new name for the discovered land.

Returns:
true if the player already set a name for the newly discovered land, otherwise false.

setNewLandName

public void setNewLandName(java.lang.String newLandName)
Sets the name this player uses for the new land.

Parameters:
newLandName - This Player's name for the new world.

getLandPrice

public int getLandPrice(Tile tile)
Returns the price of the given land.

Parameters:
tile - The Tile to get the price for.
Returns:
The price of the land if it is for sale, zero if it is already ours, unclaimed or unwanted, negative if it is not for sale.

getAttackedByPrivateers

public boolean getAttackedByPrivateers()
Returns whether this player has been attacked by privateers.

Returns:
true if this Player has been attacked by privateers.

setAttackedByPrivateers

public void setAttackedByPrivateers(boolean attacked)
Sets whether this player has been attacked by privateers.

Parameters:
attacked - True if the player has been attacked by privateers.

getEntryLocation

public Location getEntryLocation()
Gets the default Location where the units arriving from Europe will be put.

Returns:
The Location.
See Also:
Unit.getEntryLocation()

setEntryLocation

public void setEntryLocation(Location entryLocation)
Sets the Location where the units arriving from Europe will be put as a default.

Parameters:
entryLocation - The Location.
See Also:
getEntryLocation()

hasExplored

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

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.

Parameters:
tile - The Tile to set explored.
See Also:
Tile.updatePlayerExploredTile(Player, boolean)

setExplored

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

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

invalidateCanSeeTiles

public void invalidateCanSeeTiles()
Forces an update of the canSeeTiles. This method should be used to invalidate the current canSeeTiles. The method resetCanSeeTiles() will be called whenever it is needed.


canSee

public boolean canSee(Tile tile)
Checks if this Player can see the given Tile. The Tile can be seen if it is in a Unit's line of sight.

Parameters:
tile - The given Tile.
Returns:
true if the Player can see the given Tile and false otherwise.

resetCanSeeTiles

private boolean resetCanSeeTiles()
Resets this player's "can see"-tiles. This is done by setting all the tiles within each Unit and Settlements line of sight visible. The other tiles are made invisible. Use invalidateCanSeeTiles() whenever possible.

Returns:
true if successful false otherwise

makeCanSeeTiles

private boolean[][] makeCanSeeTiles(Map map)
Builds a canSeeTiles array. Note that tiles must be tested for null as they may be both valid tiles but yet null during a save game load. Note the use of copies of the unit and settlement lists to avoid nasty surprises due to asynchronous disappearance of members of either. TODO: see if this can be relaxed.

Parameters:
map - The Map to use.
Returns:
A canSeeTiles array.

canBuildColonies

public boolean canBuildColonies()
Checks if this Player can build colonies.

Returns:
true if this player is european, not the royal expeditionary force and not currently fighting the war of independence.

canHaveFoundingFathers

public boolean canHaveFoundingFathers()
Checks if this Player can get founding fathers.

Returns:
true if this player is european, not the royal expeditionary force and not currently fighting the war of independence.

hasFather

public boolean hasFather(FoundingFather someFather)
Determines whether this player has a certain Founding father.

Parameters:
someFather - a FoundingFather value
Returns:
Whether this player has this Founding father
See Also:
FoundingFather

getFatherCount

public int getFatherCount()
Returns the number of founding fathers in this players congress. Used to calculate number of liberty needed to recruit new fathers.

Returns:
The number of founding fathers in this players congress

getFathers

public java.util.Set<FoundingFather> getFathers()
Returns the founding fathers in this player's congress.

Returns:
the founding fathers in this player's congress.

addFather

public void addFather(FoundingFather father)
Add a founding father to the congress.

Parameters:
father - The FoundingFather to add.

getCurrentFather

public FoundingFather getCurrentFather()
Gets the founding father this player is working towards.

Returns:
The current FoundingFather or null if there is none
See Also:
setCurrentFather(net.sf.freecol.common.model.FoundingFather), FoundingFather

setCurrentFather

public void setCurrentFather(FoundingFather someFather)
Sets this players liberty bell production to work towards recruiting father to its congress.

Parameters:
someFather - a FoundingFather value
See Also:
FoundingFather

getOfferedFathers

public java.util.List<FoundingFather> getOfferedFathers()
Gets the set of offered fathers for this player.

Returns:
The current set of offered fathers.

clearOfferedFathers

public void clearOfferedFathers()
Clear the set of offered fathers.


setOfferedFathers

public void setOfferedFathers(java.util.List<FoundingFather> fathers)
Sets the set of offered fathers.

Parameters:
fathers - A list of FoundingFathers to offer.

getRemainingFoundingFatherCost

public int getRemainingFoundingFatherCost()
Gets the number of liberty points needed to recruit the next founding father.

Returns:
How many more liberty points the Player needs in order to recruit the next founding father.
See Also:
incrementLiberty(int)

getTotalFoundingFatherCost

public int getTotalFoundingFatherCost()
Returns how many liberty points in total are needed to earn the Founding Father we are trying to recruit. The description of the algorithm was taken from http://t-a-w.blogspot.com/2007/05/colonization-tips.html

Returns:
Total number of liberty points the Player needs to recruit the next founding father.
See Also:
incrementLiberty(int)

canMoveToEurope

public boolean canMoveToEurope()
Checks if this Player can move units to Europe.

Returns:
true if this Player has an instance of Europe.

getEurope

public Europe getEurope()
Returns the europe object that this player has.

Returns:
The europe object that this player has or null if this Player does not have an instance Europe.

setEurope

public void setEurope(Europe europe)
Set the europe object for a player.

Parameters:
europe - The new Europe object.

getEuropeNameKey

public java.lang.String getEuropeNameKey()
Describe getEuropeName method here.

Returns:
a String value

getMonarch

public Monarch getMonarch()
Returns the monarch object this player has.

Returns:
The monarch object this player has or null if this Player does not have an instance Monarch.

setMonarch

public void setMonarch(Monarch monarch)
Sets the monarch object this player has.

Parameters:
monarch - The monarch object this player should have.

getHighSeas

public final HighSeas getHighSeas()
Get the HighSeas value.

Returns:
a HighSeas value

initializeHighSeas

public void initializeHighSeas()
Initialize the highSeas. Needs to be public until the backward compatibility code in FreeColServer is gone.


getGold

public int getGold()
Returns the amount of gold that this player has.

Returns:
The amount of gold that this player has. May return GOLD_NOT_ACCOUNTED for players whose gold is not accounted.

setGold

public void setGold(int newGold)
Set the amount of gold that this player has.

Parameters:
newGold - The new player gold value.

checkGold

public boolean checkGold(int amount)
Checks if the player has enough gold to make a purchase. Use this rather than comparing with getGold(), as this handles players that do not account for gold.

Parameters:
amount - The purchase price to check.
Returns:
True if the player can afford the purchase.

modifyGold

public int modifyGold(int amount)
Modifies the amount of gold that this player has. The argument can be both positive and negative.

Parameters:
amount - The amount of gold to be added to this player.
Returns:
The amount of gold post-modification.

getUnitIterator

public java.util.Iterator<Unit> getUnitIterator()
Gets an Iterator containing all the units this player owns.

Returns:
The Iterator.
See Also:
Unit

getUnits

public java.util.List<Unit> getUnits()

getNumberOfKingLandUnits

public int getNumberOfKingLandUnits()
Gets the number of King's land units.

Returns:
The number of units

hasManOfWar

public boolean hasManOfWar()
Checks if this player has a single Man-of-War.

Returns:
true if this player owns a single Man-of-War.

getNextActiveUnit

public Unit getNextActiveUnit()
Gets a new active unit.

Returns:
A Unit that can be made active.

setNextActiveUnit

public boolean setNextActiveUnit(Unit unit)
Sets a new active unit.

Parameters:
unit - A Unit to make the next one to be active.
Returns:
True if the operation succeeded.

getNextGoingToUnit

public Unit getNextGoingToUnit()
Gets a new going_to unit.

Returns:
A Unit that can be made active.

hasNextActiveUnit

public boolean hasNextActiveUnit()
Checks if a new active unit can be made active.

Returns:
true if this is the case and false otherwise.

hasNextGoingToUnit

public boolean hasNextGoingToUnit()
Checks if a new active unit can be made active.

Returns:
true if this is the case and false otherwise.

getName

public java.lang.String getName()
Returns the name of this player.

Specified by:
getName in interface Nameable
Returns:
The name of this player.

getNameKey

public java.lang.String getNameKey()

getDisplayName

public java.lang.String getDisplayName()
Gets the name to display for this player. TODO: This is a kludge that should be fixed.

Returns:
The name to display for this player.

isUnknownEnemy

public boolean isUnknownEnemy()
Is this player the unknown enemy?


toString

public java.lang.String toString()
Returns the name of this player.

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

setName

public void setName(java.lang.String newName)
Set the Name value.

Specified by:
setName in interface Nameable
Parameters:
newName - The new Name value.

getNationType

public NationType getNationType()
Returns the nation type of this player.

Returns:
The nation type of this player.

setNationType

public void setNationType(NationType newNationType)
Sets the nation type of this player.

Parameters:
newNationType - a NationType value

getNation

public Nation getNation()
Return this Player's nation.

Returns:
a String value

setNation

public void setNation(Nation newNation)
Sets the nation for this player.

Parameters:
newNation - The new nation for this player.

getNationID

public java.lang.String getNationID()
Return the ID of this Player's nation.

Returns:
a String value

getNationNameKey

public java.lang.String getNationNameKey()
Gets a nation name suitable for use in message IDs.

Returns:
a String value

getNationName

public StringTemplate getNationName()
Returns the nation of this player as a String.

Returns:
The nation of this player as a String.

getRulerNameKey

public final java.lang.String getRulerNameKey()
Get the RulerName value.

Returns:
a String value

isReady

public boolean isReady()
Checks if this Player is ready to start the game.

Returns:
true if this Player is ready to start the game.

setReady

public void setReady(boolean ready)
Sets this Player to be ready/not ready for starting the game.

Parameters:
ready - This indicates if the player is ready to start the game.

incrementImmigration

public void incrementImmigration(int amount)

reduceImmigration

public void reduceImmigration()
Sets the number of immigration this player possess.

See Also:
incrementImmigration(int)

getImmigration

public int getImmigration()
Gets the number of immigration this player possess.

Returns:
The number.
See Also:
reduceImmigration()

setImmigration

public void setImmigration(int immigration)
Sets the number of immigration this player possess.

Parameters:
immigration - The immigration value for this player.

getTradeRoutes

public final java.util.List<TradeRoute> getTradeRoutes()
Get the TradeRoutes value.

Returns:
a List value

setTradeRoutes

public final void setTradeRoutes(java.util.List<TradeRoute> newTradeRoutes)
Set the players trade routes.

Parameters:
newTradeRoutes - The new list of TradeRoutes.

checkEmigrate

public boolean checkEmigrate()
Checks to see whether or not a colonist can emigrate, and does so if possible.

Returns:
Whether a new colonist should immigrate.

getImmigrationRequired

public int getImmigrationRequired()
Gets the number of immigration required to cause a new colonist to emigrate.

Returns:
The number of immigration required to cause a new colonist to emigrate.

setImmigrationRequired

public void setImmigrationRequired(int immigrationRequired)
Sets the number of immigration required to cause a new colonist to emigrate.

Parameters:
immigrationRequired - The number of immigration required to cause a new colonist to emigrate.

updateImmigrationRequired

public void updateImmigrationRequired()
Updates the amount of immigration needed to emigrate a Unit from Europe.


canRecruitUnits

public boolean canRecruitUnits()
Checks if this Player can recruit units by producing immigration.

Returns:
true if units can be recruited by this Player.

modifyTension

public java.util.List<FreeColGameObject> modifyTension(Player player,
                                                       int addToTension)
Modifies the hostility against the given player.

Parameters:
player - The Player.
addToTension - The amount to add to the current tension level.
Returns:
A list of objects that may need updating due to the tension change (such as native settlements).

modifyTension

public java.util.List<FreeColGameObject> modifyTension(Player player,
                                                       int addToTension,
                                                       Settlement origin)
Modifies the hostility against the given player.

Parameters:
player - The Player.
addToTension - The amount to add to the current tension level.
origin - A Settlement where the alarming event occurred.
Returns:
A list of objects that may need updating due to the tension change (such as native settlements).

setTension

public void setTension(Player player,
                       Tension newTension)
Sets the hostility against the given player.

Parameters:
player - The Player.
newTension - The Tension.

getTension

public Tension getTension(Player player)
Gets the hostility this player has against the given player.

Parameters:
player - The Player.
Returns:
An object representing the tension level.

removeTension

public void removeTension(Player player)
Removes all tension with respect to a given player. Used when a player leaves the game.

Parameters:
player - The Player to remove tension for.

getHistory

public final java.util.List<HistoryEvent> getHistory()
Get the History value.

Returns:
a List value

getOutpostValue

public int getOutpostValue(Tile t)
Calculates the value of an outpost-type colony at this tile. An "outpost" is supposed to be a colony containing one worker, exporting its whole production to europe. The value of such colony is the maximum amount of money it can make in one turn, assuming sale of its secondary goods plus farmed goods from one of the surrounding tiles.

Returns:
The value of a future colony located on this tile. This value is used by the AI when deciding where to build a new colony.

getColonyValue

public int getColonyValue(Tile t)
Gets the value of building a Colony on the given tile. This method adds bonuses to the colony value if the tile is close to (but not overlapping with) another friendly colony. Penalties for enemy units/colonies are added as well.

Parameters:
t - The Tile
Returns:
The value of building a colony on the given tile.

getStance

public Player.Stance getStance(Player player)
Returns the stance towards a given player.

One of: WAR, CEASE_FIRE, PEACE and ALLIANCE.

Parameters:
player - The Player.
Returns:
The stance.

setStance

public boolean setStance(Player player,
                         Player.Stance newStance)
Sets the stance towards a given player to one of WAR, CEASE_FIRE, PEACE and ALLIANCE.

Parameters:
player - The Player.
newStance - The new Stance.
Returns:
True if the stance change was valid.
Throws:
java.lang.IllegalArgumentException - if player is null or this.

atWarWith

public boolean atWarWith(Player player)
Is this player at war with the specified one.

Parameters:
player - The Player to check.
Returns:
True if the players are at war.

hasContacted

public boolean hasContacted(Player player)
Returns whether this player has met with the Player if the given nation.

Parameters:
player - The Player.
Returns:
true if this Player has contacted the given nation.

hasContactedEuropeans

public boolean hasContactedEuropeans()
Returns whether this player has met with any Europeans at all.

Returns:
true if this Player has contacted any Europeans.

hasContactedIndians

public boolean hasContactedIndians()
Returns whether this player has met with any natives at all.

Returns:
true if this Player has contacted any natives.

makeContact

public static void makeContact(Player player1,
                               Player player2)
Set this player as having made initial contact with another player. Always start with PEACE, which can go downhill fast.

Parameters:
player1 - a Player value
player2 - a Player value

hasVisited

public boolean hasVisited(IndianSettlement settlement)
Has a player visited a native settlement? This is needed by the native report and settlement popup to clarify whether the skill at the settlement is null because it has been depleted, or because we just have not found out what it is yet.

Parameters:
settlement - The IndianSettlement to query.
Returns:
True if the player has visited the settlement.

getRecruitPrice

public int getRecruitPrice()
Gets the price for a recruit in europe.

Returns:
The price of a single recruit in Europe.

getLiberty

public int getLiberty()
Gets the current amount of liberty this Player has.

Returns:
This player's number of liberty earned towards the current Founding Father.

setLiberty

public void setLiberty(int liberty)
Sets the current amount of liberty this player has.

Parameters:
liberty - The new amount of liberty.

incrementLiberty

public void incrementLiberty(int amount)
Adds to the current amount of liberty this player has.

Parameters:
amount - The additional amount of liberty.

getLibertyProductionNextTurn

public int getLibertyProductionNextTurn()
Returns how many total liberty will be produced if no colonies are lost and nothing unexpected happens.

Returns:
Total number of liberty this Player's Colonys will make.
See Also:
incrementLiberty(int)

resetIterators

public void resetIterators()
Reset the player iterators ready for a new turn.


getArrears

public int getArrears(GoodsType type)
Returns the arrears due for a type of goods.

Parameters:
type - a GoodsType value
Returns:
The arrears due for this type of goods.

getArrears

public int getArrears(Goods goods)
Returns the arrears due for a type of goods.

Parameters:
goods - The goods.
Returns:
The arrears due for this type of goods.

canTrade

public boolean canTrade(GoodsType type)
Returns true if type of goods can be traded in Europe.

Parameters:
type - The goods type.
Returns:
True if there are no arrears due for this type of goods.

canTrade

public boolean canTrade(GoodsType type,
                        Market.Access access)
Returns true if type of goods can be traded at specified place.

Parameters:
type - The GoodsType.
access - The way the goods are traded (Europe OR Custom)
Returns:
true if type of goods can be traded.

canTrade

public boolean canTrade(Goods goods,
                        Market.Access access)
Returns true if type of goods can be traded at specified place

Parameters:
goods - The goods.
access - Place where the goods are traded (Europe OR Custom)
Returns:
True if type of goods can be traded.

canTrade

public boolean canTrade(Goods goods)
Returns true if type of goods can be traded in Europe.

Parameters:
goods - The goods.
Returns:
True if there are no arrears due for this type of goods.

getTax

public int getTax()
Returns the current tax.

Returns:
The current tax.

setTax

public void setTax(int amount)
Sets the current tax

Parameters:
amount - The new tax.

recalculateBellsBonus

protected boolean recalculateBellsBonus()
Recalculate bells bonus when tax changes.

Returns:
True if a bells bonus was set.

getSales

public int getSales(GoodsType goodsType)
Returns the current sales.

Parameters:
goodsType - a GoodsType value
Returns:
The current sales.

modifySales

public void modifySales(GoodsType goodsType,
                        int amount)
Modifies the current sales.

Parameters:
goodsType - a GoodsType value
amount - The new sales.

hasTraded

public boolean hasTraded(GoodsType goodsType)
Has a type of goods been traded?

Parameters:
goodsType - a GoodsType value
Returns:
Whether these goods have been traded.

getMostValuableGoods

public Goods getMostValuableGoods()
Returns the most valuable goods available in one of the player's colonies for the purposes of choosing a threat-to-boycott. The goods must not currently be boycotted, the player must have traded in it, and the amount to be discarded will not exceed GoodsContainer.CARGO_SIZE.

Returns:
A goods object, or null.

getIncomeBeforeTaxes

public int getIncomeBeforeTaxes(GoodsType goodsType)
Returns the current incomeBeforeTaxes.

Parameters:
goodsType - The GoodsType.
Returns:
The current incomeBeforeTaxes.

modifyIncomeBeforeTaxes

public void modifyIncomeBeforeTaxes(GoodsType goodsType,
                                    int amount)
Modifies the current incomeBeforeTaxes.

Parameters:
goodsType - The GoodsType.
amount - The new incomeBeforeTaxes.

getIncomeAfterTaxes

public int getIncomeAfterTaxes(GoodsType goodsType)
Returns the current incomeAfterTaxes.

Parameters:
goodsType - The GoodsType.
Returns:
The current incomeAfterTaxes.

modifyIncomeAfterTaxes

public void modifyIncomeAfterTaxes(GoodsType goodsType,
                                   int amount)
Modifies the current incomeAfterTaxes.

Parameters:
goodsType - The GoodsType.
amount - The new incomeAfterTaxes.

addHistory

public void addHistory(HistoryEvent event)
Add a HistoryEvent to this player.

Parameters:
event - The HistoryEvent to add.

equals

public boolean equals(Player o)
Checks if the given Player equals this object.

Parameters:
o - The Player to compare against this object.
Returns:
true if the two Player are equal and none of both have nation == null and false otherwise.

getNameIndex

public int getNameIndex(java.lang.String key)
Gets the name index for a given key.

Parameters:
key - The key to use.

setNameIndex

public void setNameIndex(java.lang.String key,
                         int value)
Gets the name index for a given key.

Parameters:
key - The key to use.

saveSale

public void saveSale(LastSale sale)
Saves a LastSale record.

Parameters:
sale - The LastSale to save.

getLastSale

public LastSale getLastSale(Location where,
                            GoodsType what)
Gets the current sales data for a location and goods type.

Parameters:
where - The Location of the sale.
what - The GoodsType sold.
Returns:
An appropriate LastSaleData record or null.

getLastSaleString

public java.lang.String getLastSaleString(Location where,
                                          GoodsType what)
Gets the last sale price for a location and goods type as a string.

Parameters:
where - The Location of the sale.
what - The GoodsType sold.
Returns:
An abbreviation for the sale price, or null if none found.

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
                         Player player,
                         boolean showAll,
                         boolean toSavedGame)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Only attributes visible to the given Player will be added to that representation if showAll is set to false.

Specified by:
toXMLImpl in class FreeColGameObject
Parameters:
out - The target stream.
player - The Player this XML-representation should be made for, or null if showAll == true.
showAll - Only attributes visible to player will be added to the representation if showAll is set to false.
toSavedGame - If true then information that is only needed when saving a game is added.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out,
                               Player player,
                               boolean showAll,
                               boolean toSavedGame)
                        throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

writeChildren

protected void writeChildren(javax.xml.stream.XMLStreamWriter out,
                             Player player,
                             boolean showAll,
                             boolean toSavedGame)
                      throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

toXMLPartialImpl

protected void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out,
                                java.lang.String[] fields)
                         throws javax.xml.stream.XMLStreamException
Partial writer for players, so that simple updates to fields such as gold can be brief.

Overrides:
toXMLPartialImpl in class FreeColObject
Parameters:
out - The target stream.
fields - The fields to write.
Throws:
javax.xml.stream.XMLStreamException - If there are problems writing the stream.

readFromXMLPartialImpl

protected void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
                               throws javax.xml.stream.XMLStreamException
Partial reader for players, so that simple updates to fields such as gold can be brief.

Overrides:
readFromXMLPartialImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - If there are problems reading the stream.

getXMLElementTagName

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

Returns:
"player"