Class Player

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, Nameable, ObjectWithId
    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, which is further subdivided by PlayerType. In addition to storing the name, nation etc of the player, it also stores various defaults for the player.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • PLAYER_CLASS_INDEX

        private static final int PLAYER_CLASS_INDEX
        Class index for a player.
        See Also:
        Constant Field Values
      • playerComparator

        public static final java.util.Comparator<Player> playerComparator
        A comparator for ordering players.
      • GOLD_NOT_ACCOUNTED

        public static final int GOLD_NOT_ACCOUNTED
        A magic constant to denote that a players gold is not tracked.
        See Also:
        Constant Field Values
      • ASSIGN_SETTLEMENT_NAME

        public static final java.lang.String ASSIGN_SETTLEMENT_NAME
        A token to use for the settlement name in requests to the server to ask the server to choose a settlement name.
        See Also:
        Constant Field Values
      • 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 player nation type.
      • nationId

        protected java.lang.String nationId
        The nation identifier 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?
      • ai

        protected boolean ai
        Is this player an AI?
      • ready

        protected boolean ready
        Is this player ready to start?
      • dead

        protected boolean dead
        Is this player dead?
      • attackedByPrivateers

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

        private boolean bankrupt
        Whether the player is bankrupt, i.e. unable to pay for the maintenance of all buildings.
      • 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.
      • immigrationRequired

        protected int immigrationRequired
        The amount of immigration needed until the next unit decides to migrate.
      • 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.
      • oldSoL

        protected int oldSoL
        SoL from last turn.
      • interventionBells

        protected int interventionBells
        The number of liberty bells produced towards the intervention force.
      • tax

        protected int tax
        The current tax rate for this player.
      • entryTile

        protected Tile entryTile
        The player starting tile on the map.
      • 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.
      • foundingFathers

        protected final java.util.Set<FoundingFather> foundingFathers
        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.
      • tension

        protected final java.util.Map<Player,​Tension> tension
        The tension levels, 0-1000, with 1000 being maximum hostility. Only used by AI, but resist the temptation to move it to AIPlayer, the complexity is not worth it.
      • bannedMissions

        protected java.util.Set<Player> bannedMissions
        A list of players who can not establish missions to this player.
      • stance

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

        protected final java.util.List<TradeRoute> tradeRoutes
        The trade routes defined by this player.
      • modelMessages

        protected final java.util.List<ModelMessage> modelMessages
        The current 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.
      • units

        private final java.util.Set<Unit> units
        The units this player owns.
      • settlements

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

        private boolean[][] canSeeTiles
        The tiles the player can see.
      • canSeeValid

        private boolean canSeeValid
        Are the canSeeTiles valid or do they need to be recalculated?
      • canSeeLock

        private final java.lang.Object canSeeLock
        Do not access canSeeTiles without taking canSeeLock.
      • featureContainer

        protected final FeatureContainer featureContainer
        A container for the abilities and modifiers of this type.
      • maximumFoodConsumption

        private int maximumFoodConsumption
        The maximum food consumption of unit types available to this player.
      • nextActiveUnitIterator

        private final UnitIterator nextActiveUnitIterator
        An iterator for the player units that are still active this turn.
      • nextGoingToUnitIterator

        private final UnitIterator nextGoingToUnitIterator
        An iterator for the player units that have a destination to go to.
      • highSeas

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

        private final java.util.Map<Player,​NationSummary> nationCache
        A cached map of the current nation summary for all live nations.
      • colonyComparator

        private java.util.Comparator<Colony> colonyComparator
        A comparator to enforce the player prefered colony order. Only relevant client-side.
      • ATTACKED_BY_PRIVATEERS_TAG

        private static final java.lang.String ATTACKED_BY_PRIVATEERS_TAG
        See Also:
        Constant Field Values
      • BAN_MISSIONS_TAG

        private static final java.lang.String BAN_MISSIONS_TAG
        See Also:
        Constant Field Values
      • CURRENT_FATHER_TAG

        private static final java.lang.String CURRENT_FATHER_TAG
        See Also:
        Constant Field Values
      • ENTRY_LOCATION_TAG

        private static final java.lang.String ENTRY_LOCATION_TAG
        See Also:
        Constant Field Values
      • FOUNDING_FATHERS_TAG

        private static final java.lang.String FOUNDING_FATHERS_TAG
        See Also:
        Constant Field Values
      • IMMIGRATION_REQUIRED_TAG

        private static final java.lang.String IMMIGRATION_REQUIRED_TAG
        See Also:
        Constant Field Values
      • INDEPENDENT_NATION_NAME_TAG

        private static final java.lang.String INDEPENDENT_NATION_NAME_TAG
        See Also:
        Constant Field Values
      • INTERVENTION_BELLS_TAG

        private static final java.lang.String INTERVENTION_BELLS_TAG
        See Also:
        Constant Field Values
      • NEW_LAND_NAME_TAG

        private static final java.lang.String NEW_LAND_NAME_TAG
        See Also:
        Constant Field Values
      • OFFERED_FATHERS_TAG

        private static final java.lang.String OFFERED_FATHERS_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • Player

        protected Player​(Game game)
        Constructor for ServerPlayer.
        Parameters:
        game - The enclosing Game.
      • Player

        public Player​(Game game,
                      java.lang.String id)
        Creates a new Player with the given id. The object should be initialized later.
        Parameters:
        game - The Game this object belongs to.
        id - The object identifier.
    • Method Detail

      • getName

        public java.lang.String getName()
        Gets the name of this player.
        Specified by:
        getName in interface Nameable
        Returns:
        The name of this player.
      • setName

        public void setName​(java.lang.String newName)
        Set the player name.
        Specified by:
        setName in interface Nameable
        Parameters:
        newName - The new name value.
      • getLabel

        public StringTemplate getLabel()
        Get a label for this player.
        Returns:
        A suitable StringTemplate.
      • isUnknownEnemy

        public boolean isUnknownEnemy()
        Is this player the unknown enemy?
        Returns:
        True if this player is the unknown enemy.
      • getIndependentNationName

        public final java.lang.String getIndependentNationName()
        Get the new post-declaration player name.
        Returns:
        The post-declaration player name.
      • setIndependentNationName

        public final void setIndependentNationName​(java.lang.String newIndependentNationName)
        Set the post-declaration player name.
        Parameters:
        newIndependentNationName - The new player name.
      • getNewLandName

        public java.lang.String getNewLandName()
        Gets the name this player has chosen for the new world.
        Returns:
        The name of the new world as chosen by the Player, or null if none chosen yet.
      • isNewLandNamed

        public boolean isNewLandNamed()
        Has the player already selected a name for the new world?
        Returns:
        True if the new world has been named by this player.
      • setNewLandName

        public void setNewLandName​(java.lang.String newLandName)
        Sets the name this player uses for the new world.
        Parameters:
        newLandName - This Player's name for the new world.
      • getNameForNewLand

        public java.lang.String getNameForNewLand()
        Get a name for the new land.
        Returns:
        A suitable name.
      • getEuropeNameKey

        public java.lang.String getEuropeNameKey()
        Get a name key for the player Europe.
        Returns:
        A name key, or null if Europe is null.
      • getNationResourceKey

        public java.lang.String getNationResourceKey()
        Gets a resource key for the nation name.
        Returns:
        A nation resource key.
      • getNationLabel

        public StringTemplate getNationLabel()
        Get a template for this players nation name.
        Returns:
        A template for this nation name.
      • getCountryLabel

        public StringTemplate getCountryLabel()
        Get a template for this players country.
        Returns:
        A template for this country.
      • getForcesLabel

        public StringTemplate getForcesLabel()
        Get a label indicating for the national forces.
        Returns:
        A suitable StringTemplate.
      • getWaitingLabel

        public StringTemplate getWaitingLabel()
        Get a label indicating that we are waiting for this player.
        Returns:
        A suitable StringTemplate.
      • getDebugName

        public java.lang.String getDebugName()
        Get a short debug-suitable name for this player.
        Returns:
        A short name for this player.
      • getRulerNameKey

        public final java.lang.String getRulerNameKey()
        Get a name key for the player nation ruler.
        Returns:
        The ruler name key.
      • 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 StringTemplate for the player market.
      • getCapitalName

        public java.lang.String getCapitalName​(java.util.Random random)
        Gets the name of this players capital. Only meaningful to natives.
        Parameters:
        random - An optional pseudo-random number source.
        Returns:
        The name of this players capital.
      • getSettlementName

        public java.lang.String getSettlementName​(java.util.Random random)
        Gets a settlement name suitable for this player.
        Parameters:
        random - An optional pseudo-random number source.
        Returns:
        A new settlement name.
      • putSettlementName

        public void putSettlementName​(java.lang.String name)
        Puts a suggested settlement name back into the pool.
        Parameters:
        name - A formerly suggested settlement name.
      • getNameForRegion

        public java.lang.String getNameForRegion​(Region region)
        Get a name for a region.
        Parameters:
        region - The Region to name.
        Returns:
        A suitable name.
      • getNameForUnit

        public java.lang.String getNameForUnit​(UnitType type,
                                               java.util.Random random)
        Gets a new name for a unit.
        Parameters:
        type - The UnitType to choose a name for.
        random - A pseudo-random number source.
        Returns:
        A name for the unit, or null if not available.
      • isConnected

        public final boolean isConnected()
        Is this player is currently connected to the server?
        Returns:
        True if this player is currently connected to the server.
      • 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.
      • send

        public boolean send​(ChangeSet cs)
        Send a change set across the connection.
        Parameters:
        cs - The ChangeSet to send.
        Returns:
        True if the message was sent.
      • clientError

        public ChangeSet clientError​(StringTemplate template)
        Convenience function to create a client error message for this player, log it, and wrap it into a change set.
        Parameters:
        template - An i18n template.
        Returns:
        A new ChangeSet.
      • clientError

        public ChangeSet clientError​(java.lang.String message)
        Convenience function to create a client error message, log it, and wrap it into a change set.
        Parameters:
        message - The non-i18n message.
        Returns:
        A new ChangeSet.
      • getPlayerType

        public Player.PlayerType getPlayerType()
        Get the type of this player.
        Returns:
        The player type.
      • setPlayerType

        private void setPlayerType​(Player.PlayerType type)
        Sets the player type.
        Parameters:
        type - The new player type.
        See Also:
        getPlayerType()
      • changePlayerType

        public void changePlayerType​(Player.PlayerType type)
        Change the player type. Handle special abilities that are added following declaration of independence. Do not bother removing them ATM, only cases are when going undead and retiring where they are moot.
        Parameters:
        type - The new player type.
      • isColonial

        public boolean isColonial()
        Checks if this player is colonial, and thus can recruit units by producing immigration.
        Returns:
        True if this player is colonial.
      • isEuropean

        public boolean isEuropean()
        Checks if this player is European, with does include the REF.
        Returns:
        True if this player is European.
      • isIndian

        public boolean isIndian()
        Is this a native player?
        Returns:
        True if this player is a native player.
      • isRebel

        public boolean isRebel()
        Is this a colonial rebel player?
        Returns:
        True if this player is a rebel player.
      • isUndead

        public boolean isUndead()
        Is this an undead player?
        Returns:
        True if this player is undead.
      • isREF

        public boolean isREF()
        Is this a REF player?
        Returns:
        True if this is a REF player.
      • isPotentialEnemy

        public boolean isPotentialEnemy​(Player player)
        Is this player currently on good terms with a given player, and thus a suitable candidate for a random monarch war declaration?
        Parameters:
        player - The Player to possibly declare war on.
        Returns:
        True if this player is a potential enemy.
      • isPotentialFriend

        public boolean isPotentialFriend​(Player player)
        Is this player currently on bad terms with a given player, and thus a suitable candidate for a random monarch peace declaration?
        Parameters:
        player - The Player to possibly declare peace with.
        Returns:
        True if this player is a potential friend.
      • getNationType

        public NationType getNationType()
        Get the nation type of this player.
        Returns:
        The NationType of this player.
      • setNationType

        public void setNationType​(NationType newNationType)
        Sets the nation type of this player.
        Parameters:
        newNationType - The new NationType.
      • changeNationType

        public void changeNationType​(NationType newNationType)
        Changes the nation type of this player, handling the features.
        Parameters:
        newNationType - The new NationType.
      • canBuildColonies

        public boolean canBuildColonies()
        Can this player build colonies?
        Returns:
        True if this player can found colonies.
      • canHaveFoundingFathers

        public boolean canHaveFoundingFathers()
        Can this player recruit founding fathers?
        Returns:
        True if this player can recruit founding fathers.
      • getNationId

        public java.lang.String getNationId()
        Get the identifier for this Player's nation.
        Returns:
        The nation identifier.
      • getNation

        public Nation getNation()
        Gets this Player's nation.
        Returns:
        The player Nation.
      • setNation

        public void setNation​(Nation newNation)
        Sets the nation for this player.
        Parameters:
        newNation - The new Nation.
      • isAdmin

        public boolean isAdmin()
        Is this player an admin.
        Returns:
        True if the player is an admin.
      • isAI

        public boolean isAI()
        Is this an AI player?
        Returns:
        True if this is an AI player.
      • setAI

        public void setAI​(boolean ai)
        Sets whether this player is an AI player.
        Parameters:
        ai - The AI player value.
      • isReady

        public boolean isReady()
        Is this player ready to start the game?
        Returns:
        True if this Player is ready to start the game.
      • getReady

        public boolean getReady()
        Get the readiness state.
        Returns:
        The readiness state.
      • setReady

        public void setReady​(boolean ready)
        Sets this players readiness state.
        Parameters:
        ready - The new readiness state.
      • 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 - The new death state.
        See Also:
        getDead()
      • getAttackedByPrivateers

        public boolean getAttackedByPrivateers()
        Has 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.
      • 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.
      • 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.
      • getNationColor

        public java.awt.Color getNationColor()
        Gets the player nation color.
        Returns:
        The Color.
      • getRank

        public int getRank()
        Get an integer to broadly categorized the player for sorting. AIs should always follow humans, and the administrator is special.
        Returns:
        An identifying integer.
      • getScore

        public int getScore()
        Gets the current score of the player.
        Returns:
        The score.
      • setScore

        public void setScore​(int score)
        Set the current score of the player.
        Parameters:
        score - The new score.
      • getSpanishSuccessionScore

        public int getSpanishSuccessionScore()
        Gets the score by which we decide the weakest and strongest AI players for the Spanish Succession event.
        Returns:
        A strength score.
      • getGold

        public int getGold()
        Get the amount of gold that this player has. Some players do not account their gold. These players return GOLD_NOT_ACCOUNTED.
        Returns:
        The amount of gold that this player has.
      • 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.
      • getBankrupt

        public final boolean getBankrupt()
        Get the bankruptcy state. isBankrupt would be nicer, but the introspector expects getBankrupt.
        Returns:
        True if this player is bankrupt.
      • setBankrupt

        public final void setBankrupt​(boolean newBankrupt)
        Set the bankruptcy state.
        Parameters:
        newBankrupt - The new bankruptcy value.
      • getImmigration

        public int getImmigration()
        Gets the amount of immigration this player possess.
        Returns:
        The immigration value.
        See Also:
        reduceImmigration()
      • setImmigration

        public void setImmigration​(int immigration)
        Sets the amount of immigration this player possess.
        Parameters:
        immigration - The immigration value for this player.
      • reduceImmigration

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

        public void modifyImmigration​(int amount)
        Modify the player immigration.
        Parameters:
        amount - The amount to modify the immigration by.
      • getImmigrationRequired

        public int getImmigrationRequired()
        Gets the amount of immigration required to cause a new colonist to emigrate.
        Returns:
        The immigration points required to trigger emigration.
      • setImmigrationRequired

        public void setImmigrationRequired​(int immigrationRequired)
        Sets the number of immigration required to cause a new colonist to emigrate.
        Parameters:
        immigrationRequired - The new number of immigration points.
      • updateImmigrationRequired

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

        public boolean checkEmigrate()
        Should a new colonist emigrate?
        Returns:
        Whether a new colonist should emigrate.
      • getTotalImmigrationProduction

        public int getTotalImmigrationProduction()
        Get the total immigration production for this player.
        Returns:
        The total immigration production.
      • getEmigrationMessage

        public ModelMessage getEmigrationMessage​(Unit unit)
        Get a message for a newly migrating unit.
        Parameters:
        unit - The Unit that is migrating.
        Returns:
        A suitable ModelMessage.
      • getLiberty

        public int getLiberty()
        Gets the current amount of liberty points this player has. Liberty is regularly reduced to pay for a founding father.
        Returns:
        The amount of liberty points.
      • setLiberty

        public void setLiberty​(int liberty)
        Sets the current amount of liberty this player has.
        Parameters:
        liberty - The new amount of liberty.
      • modifyLiberty

        public void modifyLiberty​(int amount)
        Modifies the current amount of liberty this player has.
        Parameters:
        amount - The amount of liberty to add.
      • recalculateBellsBonus

        protected boolean recalculateBellsBonus()
        Recalculate bells bonus when tax changes.
        Returns:
        True if a bells bonus was set.
      • getLibertyProductionNextTurn

        public int getLibertyProductionNextTurn()
        Gets how much liberty will be produced next turn if no colonies are lost and nothing unexpected happens.
        Returns:
        The total amount of liberty this Player's Colonys will make next turn.
      • getOldSoL

        protected int getOldSoL()
        Get the old SoL.
        Returns:
        The SoL amount from the previous turn.
      • 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.
      • getInterventionBells

        protected int getInterventionBells()
        Get the bells for intervention.
        Returns:
        The intervention bell amount.
      • getFoundingFathers

        public java.util.Set<FoundingFather> getFoundingFathers()
        Gets the founding fathers in this player's congress.
        Returns:
        A set of FoundingFathers in congress.
      • setFoundingFathers

        protected void setFoundingFathers​(java.util.Set<FoundingFather> foundingFathers)
        Gets the founding fathers in this player's congress.
        Parameters:
        foundingFathers - A set of FoundingFathers in congress.
      • hasFather

        public boolean hasFather​(FoundingFather someFather)
        Does this player have a certain Founding father.
        Parameters:
        someFather - The FoundingFather to check.
        Returns:
        Whether this player has this Founding father
        See Also:
        FoundingFather
      • getFatherCount

        public int getFatherCount()
        Gets 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
      • addFather

        public void addFather​(FoundingFather father)
        Add a founding father to the congress.
        Parameters:
        father - The FoundingFather to add.
      • setCurrentFather

        public void setCurrentFather​(FoundingFather someFather)
        Sets the current founding father to recruit.
        Parameters:
        someFather - The FoundingFather to recruit.
        See Also:
        FoundingFather
      • getOfferedFathers

        public java.util.List<FoundingFather> getOfferedFathers()
        Gets the offered fathers for this player.
        Returns:
        A list of the current offered FoundingFathers.
      • 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 FoundingFather.
      • getTotalFoundingFatherCost

        public int getTotalFoundingFatherCost()
        How many liberty points in total are needed to earn the Founding Father we are trying to recruit. See https://sourceforge.net/p/freecol/bugs/2623 where the Col1 numbers were checked.
        Returns:
        Total number of liberty points the Player needs to recruit the next FoundingFather.
      • getElectionTurns

        public java.util.Map<java.lang.String,​Turn> getElectionTurns()
        Gets the Turns during which FoundingFathers were elected to the Continental Congress
        Returns:
        A map of father id to Turns.
      • checkDeclareIndependence

        public StringTemplate checkDeclareIndependence()
        Check whether this player can declare independence.
        Returns:
        Null if there is no barrier to declaration, otherwise a StringTemplate explaining the problem.
      • calculateStrength

        public int calculateStrength​(boolean naval)
        Generic strength calculation.
        Parameters:
        naval - If true consider naval units, otherwise land units.
        Returns:
        A measure of naval or land offensive power.
      • getRebelStrengthRatio

        public double getRebelStrengthRatio​(boolean naval)
        Get the strength ratio of this player with respect to its REF.
        Parameters:
        naval - If true consider naval units, otherwise land units.
        Returns:
        A measure of the military viability of this player.
      • getREFUnits

        public java.util.List<AbstractUnit> getREFUnits()
        Get a list of abstract REF units for this player.
        Returns:
        A list of AbstractUnits defining the REF, or null if not available.
      • getMilitaryUnits

        public java.util.List<AbstractUnit> getMilitaryUnits()
        Get a list of the military units for this player.
        Returns:
        A list of military AbstractUnits.
      • getTax

        public int getTax()
        Get the current tax.
        Returns:
        The current tax.
      • setTax

        public void setTax​(int amount)
        Sets the current tax
        Parameters:
        amount - The new tax amount.
      • getMarket

        public Market getMarket()
        Get this player's Market. Beware, this *can* be null in special cases such as when spying on another player's settlement.
        Returns:
        The Market.
      • reinitialiseMarket

        public void reinitialiseMarket()
        Resets this player's Market.
      • getLastSales

        protected java.util.Map<java.lang.String,​LastSale> getLastSales()
        Get the last sales events.
        Returns:
        The LastSales list.
      • setLastSales

        protected void setLastSales​(java.util.Map<java.lang.String,​LastSale> lastSales)
        Set the last sales events.
        Parameters:
        lastSales - The new list of LastSales.
      • 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 if no appropriate sale can be found.
      • addLastSale

        public void addLastSale​(LastSale sale)
        Saves a record of a sale.
        Parameters:
        sale - The LastSale to save.
      • 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.
      • getLastSaleTip

        public StringTemplate getLastSaleTip​(Location where,
                                             GoodsType what)
        Get a template for the last sale price for a location and goods type.
        Parameters:
        where - The Location of the sale.
        what - The GoodsType sold.
        Returns:
        A StringTemplate for the sale, or null if none found.
      • getArrears

        public int getArrears​(GoodsType type)
        Gets the arrears due for a type of goods.
        Parameters:
        type - The GoodsType to check.
        Returns:
        The arrears due for this type of goods.
      • canTrade

        public boolean canTrade​(GoodsType type)
        Can a type of goods can be traded in Europe?
        Parameters:
        type - The GoodsType to check.
        Returns:
        True if there are no arrears due for this type of goods.
      • canTrade

        public boolean canTrade​(GoodsType type,
                                Market.Access access)
        Can a type of goods can be traded at a specified place?
        Parameters:
        type - The GoodsType to check.
        access - The way the goods are traded (Europe OR Custom)
        Returns:
        True if type of goods can be traded.
      • getSales

        public int getSales​(GoodsType goodsType)
        Get the current sales of a type of goods.
        Parameters:
        goodsType - The GoodsType to query.
        Returns:
        The current sales.
      • modifySales

        public void modifySales​(GoodsType goodsType,
                                int amount)
        Modifies the current sales.
        Parameters:
        goodsType - The GoodsType to modify.
        amount - The new sales.
      • hasTraded

        public boolean hasTraded​(GoodsType goodsType)
        Has a type of goods been traded?
        Parameters:
        goodsType - The GoodsType to check.
        Returns:
        Whether these goods have been traded.
      • getMostValuableGoods

        public Goods getMostValuableGoods()
        Get 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 if nothing suitable found.
      • getIncomeBeforeTaxes

        public int getIncomeBeforeTaxes​(GoodsType goodsType)
        Get the current incomeBeforeTaxes.
        Parameters:
        goodsType - The GoodsType to query.
        Returns:
        The current incomeBeforeTaxes.
      • modifyIncomeBeforeTaxes

        public void modifyIncomeBeforeTaxes​(GoodsType goodsType,
                                            int amount)
        Modifies the current incomeBeforeTaxes.
        Parameters:
        goodsType - The GoodsType to modify.
        amount - The new incomeBeforeTaxes.
      • getIncomeAfterTaxes

        public int getIncomeAfterTaxes​(GoodsType goodsType)
        Get the current incomeAfterTaxes.
        Parameters:
        goodsType - The GoodsType to query.
        Returns:
        The current incomeAfterTaxes.
      • modifyIncomeAfterTaxes

        public void modifyIncomeAfterTaxes​(GoodsType goodsType,
                                           int amount)
        Modifies the current incomeAfterTaxes.
        Parameters:
        goodsType - The GoodsType to modify.
        amount - The new incomeAfterTaxes.
      • getEurope

        public Europe getEurope()
        Gets this players Europe object.
        Returns:
        The Europe object, or null if the player is not European or indpendent.
      • setEurope

        public void setEurope​(Europe europe)
        Set the Europe object for a player.
        Parameters:
        europe - The new Europe object.
      • canMoveToEurope

        public boolean canMoveToEurope()
        Checks if this player can move units to Europe.
        Returns:
        True if this player has an instance of Europe.
      • getEuropeanRecruitPrice

        public int getEuropeanRecruitPrice()
        Gets the price for a recruit in Europe.
        Returns:
        The price of a single recruit in Europe.
      • getEuropeanPurchasePrice

        public int getEuropeanPurchasePrice​(AbstractUnit au)
        Gets the price to this player to purchase a unit in Europe.
        Parameters:
        au - The proposed AbstractUnit.
        Returns:
        The price for the unit.
      • getMercenaryHirePrice

        public int getMercenaryHirePrice​(AbstractUnit au)
        Gets the price to this player to hire a mercenary unit. This does not need to follow the rules for unit or goods availability as it is being offered by another power.
        Parameters:
        au - The proposed AbstractUnit.
        Returns:
        The price for the unit or negative if not available.
      • getMonarch

        public Monarch getMonarch()
        Gets the monarch object this player has.
        Returns:
        The Monarch object this player has, or null if there is no monarch.
      • setMonarch

        public void setMonarch​(Monarch monarch)
        Sets the monarch object this player has.
        Parameters:
        monarch - The new Monarch object.
      • hasUnit

        public boolean hasUnit​(Unit unit)
        Does this player's units list contain the given unit?
        Parameters:
        unit - The Unit to test.
        Returns:
        True if the player has the unit.
      • getUnits

        public java.util.stream.Stream<Unit> getUnits()
        Get a stream of the players units. Have to serialize the copy created by getUnitList, otherwise concurrent modification exceptions show up.
        Returns:
        A stream of the player Units.
      • getUnitSet

        public java.util.Set<Unit> getUnitSet()
        Get a copy of the players units.
        Returns:
        A set of the player Units.
      • getUnitCount

        public int getUnitCount()
        Get the number of units a player has.
        Returns:
        The number of units.
      • getUnitByName

        public Unit getUnitByName​(java.lang.String name)
        Get a player unit by name.
        Parameters:
        name - The name of the unit.
        Returns:
        The unit with the given name, or null if none found.
      • addUnit

        public final boolean addUnit​(Unit newUnit)
        Add a unit to this player.
        Parameters:
        newUnit - The new Unit value.
        Returns:
        True if the units container changed.
      • removeUnit

        public boolean removeUnit​(Unit oldUnit)
        Remove a unit from this player.
        Parameters:
        oldUnit - The Unit to remove.
        Returns:
        True if the units container changed.
      • getCarriersForUnit

        public java.util.List<Unit> getCarriersForUnit​(Unit unit)
        Gets the carrier units that can carry the supplied unit, if one exists.
        Parameters:
        unit - The Unit to carry.
        Returns:
        A list of suitable carriers.
      • getUnitCount

        public int getUnitCount​(boolean naval)
        Get the number of units a player has, either land or naval.
        Parameters:
        naval - If true, count naval units, else count land units.
        Returns:
        The number of units.
      • getNumberOfKingLandUnits

        public int getNumberOfKingLandUnits()
        Gets the number of King's land units.
        Returns:
        The number of units
      • hasUnitType

        public boolean hasUnitType​(java.lang.String typeId)
        Checks if this player has at least one of a given unit type.
        Parameters:
        typeId - The identifier for the unit type to check.
        Returns:
        True if this player owns at least one of the specified unit type.
      • restoreActiveUnit

        public Unit restoreActiveUnit()
        Recover the active unit when restoring a game. If found, clear the active unit identifier in the game.
        Returns:
        The next active Unit.
      • getNextActiveUnit

        public Unit getNextActiveUnit()
        Gets a new active 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 there is a potential active unit.
      • getNextGoingToUnit

        public Unit getNextGoingToUnit()
        Gets a new going-to unit.
        Returns:
        A Unit that can be made active.
      • setNextGoingToUnit

        public boolean setNextGoingToUnit​(Unit unit)
        Sets a new going-to unit.
        Parameters:
        unit - A Unit to make the next one to be active.
        Returns:
        True if the operation succeeded.
      • hasNextGoingToUnit

        public boolean hasNextGoingToUnit()
        Checks if there is a unit that has a destination.
        Returns:
        True if there is a unit with a destination.
      • resetIterators

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

        public final java.util.List<TradeRoute> getTradeRoutes()
        Get the trade routes defined for this player.
        Returns:
        A copy of the list of TradeRoutes for this player.
      • getTradeRouteCount

        public final int getTradeRouteCount()
        Get number of trade routes defined for this player.
        Returns:
        The trade route count.
      • getNewestTradeRoute

        public final TradeRoute getNewestTradeRoute()
        Get the most recently defined trade route. Relies on trade routes *always* being added at the end of the list.
        Returns:
        The most recently defined TradeRoute.
      • addTradeRoute

        public final void addTradeRoute​(TradeRoute tradeRoute)
        Add a new trade route.
        Parameters:
        tradeRoute - The TradeRoute to add.
      • getTradeRouteByName

        public final TradeRoute getTradeRouteByName​(java.lang.String name,
                                                    TradeRoute exclude)
        Get a trade route by name.
        Parameters:
        name - The trade route name.
        exclude - An optional TradeRoute to exclude.
        Returns:
        The TradeRoute found.
      • removeTradeRoute

        public final java.util.List<Unit> removeTradeRoute​(TradeRoute tradeRoute)
        Remove a trade route.
        Parameters:
        tradeRoute - The TradeRoute to remove.
        Returns:
        A list of units that were formally assigned to the trade route.
      • clearTradeRoutes

        private void clearTradeRoutes()
        Clear the trade routes.
      • getNameForTradeRoute

        public java.lang.String getNameForTradeRoute()
        Get a unique name for a new trade route.
        Returns:
        A suitable name.
      • addOwnable

        public boolean addOwnable​(Ownable o)
        Add an ownable to a caching container. Not all ownables are cached.
        Parameters:
        o - The Ownable to add.
        Returns:
        True if the container changed.
      • removeOwnable

        public boolean removeOwnable​(Ownable o)
        Remove an ownable from a caching container. Not all ownables are cached.
        Parameters:
        o - The Ownable to remove.
        Returns:
        True if the container changed.
      • getSettlementList

        public java.util.List<Settlement> getSettlementList()
        Gets a the settlements this player owns.
        Returns:
        The list of Settlements this player owns.
      • getSettlements

        public java.util.stream.Stream<Settlement> getSettlements()
        Get a stream of the settlements this player owns.
        Returns:
        The strean of Settlements this player owns.
      • hasSettlements

        public boolean hasSettlements()
        Does this player have any settlements at present.
        Returns:
        True if this player has settlements.
      • getSettlementCount

        public int getSettlementCount()
        Get the count of settlements.
        Returns:
        The number of settlements this player has.
      • getNumberOfPorts

        public int getNumberOfPorts()
        Get the number of port settlements.
        Returns:
        The number of port settlements this player has.
      • getConnectedPortList

        public java.util.List<Colony> getConnectedPortList()
        Get the connected port settlements.
        Returns:
        A list of connected port Colonys.
      • getConnectedPorts

        public java.util.stream.Stream<Colony> getConnectedPorts()
        Get a stream of the connected port settlements.
        Returns:
        A stream of connected port Colonys.
      • hasSettlement

        public boolean hasSettlement​(Settlement settlement)
        Does this player own a given settlement.
        Parameters:
        settlement - The Settlement to check.
        Returns:
        True if this Player owns the given Settlement.
      • addSettlement

        public boolean addSettlement​(Settlement settlement)
        Adds a given settlement to this player's list of settlements. Note: if the comparator is present, insert the settlement in the preferred order.
        Parameters:
        settlement - The Settlement to add.
        Returns:
        True if the settlements container changed.
      • removeSettlement

        public boolean removeSettlement​(Settlement settlement)
        Removes the given settlement from this player's list of settlements.
        Parameters:
        settlement - The Settlement to remove.
        Returns:
        True if the settlements container changed.
      • getColoniesPopulation

        public int getColoniesPopulation()
        Gets the sum of units currently working in the colonies of this player.
        Returns:
        The sum of the units currently working in the colonies.
      • getColonyByName

        public Colony getColonyByName​(java.lang.String name)
        Gets the Colony with the given name.
        Parameters:
        name - The name of the Colony.
        Returns:
        The Colony with the given name, or null if not found.
      • getIndianSettlementByName

        public IndianSettlement getIndianSettlementByName​(java.lang.String name)
        Gets the IndianSettlement with the given name.
        Parameters:
        name - The name of the IndianSettlement.
        Returns:
        The IndianSettlement with the given name, or null if not found.
      • getColonies

        public java.util.stream.Stream<Colony> getColonies()
        Get a stream of all colonies this player owns.
        Returns:
        A stream of the Colonys this player owns.
      • getColonyList

        public java.util.List<Colony> getColonyList()
        Get a fresh list of all colonies this player owns.
        Returns:
        A list of the Colonys this player owns.
      • getSortedColonies

        public java.util.List<Colony> getSortedColonies​(java.util.Comparator<Colony> comp)
        Get a sorted list of all colonies this player owns.
        Parameters:
        comp - A Comparator to operate on the colony list.
        Returns:
        A fresh list of the Colonys this player owns.
      • getIndianSettlements

        public java.util.stream.Stream<IndianSettlement> getIndianSettlements()
        Get a stream of all the indian settlements this player owns.
        Returns:
        A stream of the IndianSettlements this player owns.
      • getIndianSettlementList

        public java.util.List<IndianSettlement> getIndianSettlementList()
        Get a list of all the IndianSettlements this player owns.
        Returns:
        A list of the IndianSettlements this player owns.
      • getIndianSettlementsWithMissionaryList

        public java.util.List<IndianSettlement> getIndianSettlementsWithMissionaryList​(Player p)
        Get a list of all indian settlements owned by this player with a missionary from a given player.
        Parameters:
        p - The Player.
        Returns:
        A list of the IndianSettlements with a matching missionary.
      • getIndianSettlementsWithMissionary

        public java.util.stream.Stream<IndianSettlement> getIndianSettlementsWithMissionary​(Player p)
        Get a stream of all indian settlements owned by this player with a missionary from a given player.
        Parameters:
        p - The Player.
        Returns:
        A stream of the IndianSettlements with a matching missionary.
      • getSettlementByName

        public Settlement getSettlementByName​(java.lang.String name)
        Find a Settlement by name.
        Parameters:
        name - The name of the Settlement.
        Returns:
        The Settlement, or null if not found.
      • getClosestPortForEurope

        public Settlement getClosestPortForEurope()
        Gets the port closest to Europe owned by this player.
        Returns:
        This players closest port.
      • getModelMessages

        public java.util.List<ModelMessage> getModelMessages()
        Gets all the model messages for this player.
        Returns:
        A copy of the ModelMessages for this Player.
      • getNewModelMessages

        public java.util.List<ModelMessage> getNewModelMessages()
        Gets all new messages for this player.
        Returns:
        all The new ModelMessages for this Player.
      • addModelMessage

        public void addModelMessage​(ModelMessage modelMessage)
        Adds a message for this player.
        Parameters:
        modelMessage - The ModelMessage to add.
      • refilterModelMessages

        public void refilterModelMessages​(OptionGroup options)
        Refilters the current model messages, removing the ones that are no longer valid.
        Parameters:
        options - The OptionGroup for message display to enforce.
      • removeDisplayedModelMessages

        public void removeDisplayedModelMessages()
        Removes all undisplayed model messages for this player.
      • clearModelMessages

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

        protected void setModelMessages​(java.util.List<ModelMessage> modelMessages)
        Set the model message list.
        Parameters:
        modelMessages - The new ModelMessages.
      • 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
      • addStartGameMessage

        public void addStartGameMessage()
        Add the tutorial message for the start of the game.
      • getHistory

        public final java.util.List<HistoryEvent> getHistory()
        Get the history events for this player.
        Returns:
        A copy of the HistoryEvents for this player.
      • addHistory

        public void addHistory​(HistoryEvent event)
        Add a history event to this player.
        Parameters:
        event - The HistoryEvent to add.
      • clearHistory

        private void clearHistory()
        Clear the history events.
      • setHistory

        protected void setHistory​(java.util.List<HistoryEvent> history)
        Clear the history events.
        Parameters:
        history - The new HistoryEvents.
      • getEntryTile

        public Tile getEntryTile()
        Gets the default initial location where the units arriving from Europe appear on the map.
        Returns:
        The entry Tile.
      • setEntryTile

        public void setEntryTile​(Tile entryTile)
        Sets the default initial location where the units arriving from Europe appear on the map.
        Parameters:
        entryTile - The new entry Tile.
        See Also:
        getEntryTile()
      • getFallbackTile

        public Tile getFallbackTile()
        Get a default tile to display at the start of the player turn should there not be any active units. Favour the first settlement, followed by the entry tile.
        Returns:
        A suitable Tile.
      • getHighSeas

        public final HighSeas getHighSeas()
        Get the players high seas.
        Returns:
        The HighSeas for this player.
      • initializeHighSeas

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

        public boolean hasExplored​(Tile tile)
        Checks if this player has explored the given tile.
        Parameters:
        tile - The Tile to check.
        Returns:
        True if the Tile has been explored.
      • invalidateCanSeeTiles

        public void invalidateCanSeeTiles()
        Forces an update of the canSeeTiles. This method should be used to invalidate the current canSeeTiles when something significant changes. The method makeCanSeeTiles(net.sf.freecol.common.model.Map) will be called whenever it is needed. So what is "significant"? - Unit added to map - Unit removed from map - Unit moved on map - Unit type changes (which may change its line-of-sight) - Unit ownership changes - Settlement added to map - Settlement removed from map - Settlement ownership changes - Coronado added (can now see other colonies) - Coronado removed (only in debug mode) - Mission established (if enhanced missionaries enabled) - Mission removed (if enhanced missionaries enabled) - Mission ownership changes (Spanish succession with enhanced missionaries enabled) - Map is unexplored (debug mode) - All the cases that have been forgotten Ideally then when any of these events occurs we should call invalidateCanSeeTiles(). However while iCST is quick and cheap, as soon as we then call canSee() the big expensive makeCanSeeTiles will be run. Often the situation in the server is that several routines with visibility implications will be called in succession. Usually there, the best solution is to make all the changes and issue the iCST at the end. So, to make this a bit more visible, routines that change visibility are annotated with a "-vis" comment at both definition and call sites. Similarly routines that fix up the mess have a "+vis" comment. Thus it is an error for a -vis to appear without a following +vis (unless the enclosing routine is marked -vis). By convention, we try to avoid cs* routines being -vis.
      • canSee

        public boolean canSee​(Tile tile)
        Can this player see a given tile. The tile can be seen if it is in a unit or settlement's line of sight.
        Parameters:
        tile - The Tile to check.
        Returns:
        True if this player can see the given Tile.
      • canSeeUnit

        public boolean canSeeUnit​(Unit unit)
        Checks if this player can see a unit.
        Parameters:
        unit - The Unit to check.
        Returns:
        True if the Unit is visible to the player.
      • getVisibleTileSet

        public java.util.Set<Tile> getVisibleTileSet()
        Get the set of tiles visible to this player.
        Returns:
        A set of visible Tiles.
      • makeCanSeeTiles

        private boolean[][] makeCanSeeTiles​(Map map)
        Builds a canSeeTiles array.
        Parameters:
        map - The Map to use.
        Returns:
        A new visibility array.
      • getTension

        protected java.util.Map<Player,​Tension> getTension()
        Get the tension map.
        Returns:
        The map of tension between players.
      • setTension

        protected void setTension​(java.util.Map<Player,​Tension> tension)
        Set the tension map.
        Parameters:
        tension - The new map of tension between players.
      • getTension

        public Tension getTension​(Player player)
        Gets the hostility this player has against the given player.
        Parameters:
        player - The other Player.
        Returns:
        An object representing the tension level.
      • setTension

        public void setTension​(Player player,
                               Tension newTension)
        Sets the tension with respect to a given player.
        Parameters:
        player - The other Player.
        newTension - The new Tension.
      • 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.
      • getBannedMissions

        protected java.util.Set<Player> getBannedMissions()
        Get the players that can not set up missions.
        Returns:
        The set of banned players.
      • setBannedMissions

        protected void setBannedMissions​(java.util.Collection<Player> bannedMissions)
        Set banned mission set.
        Parameters:
        bannedMissions - The new set of banned players.
      • missionsBanned

        public boolean missionsBanned​(Player player)
        Does this player ban missions from another player?
        Parameters:
        player - The other Player to test.
        Returns:
        True if the given player is banned.
      • addMissionBan

        public void addMissionBan​(Player player)
        Ban a player from establishing missions to this player.
        Parameters:
        player - The Player to ban.
      • removeMissionBan

        public void removeMissionBan​(Player player)
        Remove a mission ban from a player.
        Parameters:
        player - The Player to clear the ban for.
      • getStances

        protected java.util.Map<java.lang.String,​Stance> getStances()
        Get the stance map.
        Returns:
        A map of player identifiers to stances.
      • setStances

        protected void setStances​(java.util.Map<java.lang.String,​Stance> stances)
        Set the stance map.
        Parameters:
        stances - A new stance map.
      • getStance

        public Stance getStance​(Player player)
        Gets the stance towards a given player.
        Parameters:
        player - The other Player to check.
        Returns:
        The stance.
      • setStance

        public boolean setStance​(Player player,
                                 Stance newStance)
        Sets the stance towards a given player.
        Parameters:
        player - The Player to set the Stance for.
        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 other Player to check.
        Returns:
        True if the players are at war.
      • 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.
      • hasContacted

        public boolean hasContacted​(Player player)
        Has this player met contacted the given one?
        Parameters:
        player - The other Player to check.
        Returns:
        True if this Player has contacted the other.
      • hasContactedEuropeans

        public boolean hasContactedEuropeans()
        Has this player has met with any Europeans at all?
        Returns:
        True if this Player has contacted any Europeans.
      • hasContactedIndians

        public boolean hasContactedIndians()
        Has this player met 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 - One Player to check.
        player2 - The other Player to check.
      • getLandPrice

        public int getLandPrice​(Tile tile)
        Gets 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.
      • getNationSummary

        public NationSummary getNationSummary​(Player player)
        Access the nation cache.
        Parameters:
        player - The Player to get the summary for.
        Returns:
        The current NationSummary for a player.
      • putNationSummary

        public void putNationSummary​(Player player,
                                     NationSummary ns)
        Update the nation cache.
        Parameters:
        player - The Player to get the summary for.
        ns - The new NationSummary for the player.
      • clearNationSummary

        public void clearNationSummary​(Player player)
        Clear the nation cache entry for a player.
        Parameters:
        player - The Player to remove the entry for.
      • clearNationCache

        public void clearNationCache()
        Clear the nation cache.
      • getStrengthRatio

        public double getStrengthRatio​(Player other,
                                       boolean naval)
        Get the strength ratio of this player with respect to another. This relies on an up-to-date nation cache value for the target player.
        Parameters:
        other - The other Player.
        naval - If true, get the naval strength, else the land strength.
        Returns:
        The strength ratio (strength/sum(strengths)), or negative on error.
      • strengthRatio

        public static double strengthRatio​(double ours,
                                           double theirs)
        Abstraction of the strength ratio calculation.
        Parameters:
        ours - The player strength.
        theirs - The enemy strength.
        Returns:
        The resulting strength ratio.
      • 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 implies 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.
      • getClaimableTiles

        public java.util.List<Tile> getClaimableTiles​(Tile centerTile,
                                                      int radius)
        Gets the list of tiles that might be claimable by a settlement. We can not do a simple iteration of the rings because this allows settlements to claim tiles across unclaimable gaps (e.g. Aztecs owning tiles on nearby islands). So we have to only allow tiles that are adjacent to a known connected tile.
        Parameters:
        centerTile - The intended settlement center Tile.
        radius - The radius of the settlement.
        Returns:
        A list of potentially claimable tiles.
      • getAllColonyValues

        public java.util.List<java.lang.Double> getAllColonyValues​(Tile tile)
        Gets a list of values for building a Colony on the given tile for each ColonyValueCategory. FIXME: tune magic numbers and expose more to the spec.
        Parameters:
        tile - The Tile
        Returns:
        A list of values.
      • getColonyValue

        public int getColonyValue​(Tile tile)
        Gets the value for building a Colony on the given tile. FIXME: tune magic numbers and expose more to the spec.
        Parameters:
        tile - The Tile
        Returns:
        A score for the tile.
      • logCheat

        public void logCheat​(java.lang.String what)
        Standardized log of an instance of cheating by this player.
        Parameters:
        what - A description of the cheating.
      • getMaximumFoodConsumption

        public int getMaximumFoodConsumption()
        Gets the maximum food consumption of any unit types available to this player.
        Returns:
        A maximum food consumption value.
      • owns

        public boolean owns​(Ownable ownable)
        Does this player own something?
        Parameters:
        ownable - The Ownable to check.
        Returns:
        True if the Ownable is ours.
      • getOurFreeColGameObject

        public <T extends FreeColGameObject> T getOurFreeColGameObject​(java.lang.String id,
                                                                       java.lang.Class<T> returnClass)
        Get a FreeColGameObject with the specified identifier and class, owned by this player. Used mainly in message decoding.
        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.
      • setColonyComparator

        public void setColonyComparator​(java.util.Comparator<Colony> cc)
        Set the local colony comparator.
        Parameters:
        cc - The new Comparator.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class FreeColGameObject
        Type Parameters:
        T - The FreeColObject subclass of the object to copy in.
        Parameters:
        other - The other object.
        Returns:
        True if the copy in is succesful.
      • getDisplayObject

        public FreeColObject getDisplayObject()
        Get an object to display when showing the user messages for this object. Example: If this object is a Building, the object to display will be the BuildingType.
        Overrides:
        getDisplayObject in class FreeColObject
        Returns:
        A suitable FreeColObject to display, defaults to this.
      • 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:
        writeAttributes in class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter to 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:
        writeChildren in class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter to 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:
        readAttributes in class FreeColGameObject
        Parameters:
        xr - The FreeColXMLReader to 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:
        readChildren in class FreeColObject
        Parameters:
        xr - The FreeColXMLReader to 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:
        readChild in class FreeColObject
        Parameters:
        xr - The FreeColXMLReader to 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:
        getXMLTagName in class FreeColObject
        Returns:
        The tag.