Package net.sf.freecol.common.model
Class Player
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Player.ColonyValueCategory
Colony value categories.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.NoValueType
Special return values for showstopper getColonyValue fail.static class
Player.PlayerType
Types of players.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
admin
Is this player an admin?private static java.lang.String
ADMIN_TAG
protected boolean
ai
Is this player an AI?private static java.lang.String
AI_TAG
static 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.private static java.lang.String
ATTACKED_BY_PRIVATEERS_TAG
protected boolean
attackedByPrivateers
True if player has been attacked by privateers.private static java.lang.String
BAN_MISSIONS_TAG
private boolean
bankrupt
Whether the player is bankrupt, i.e.private static java.lang.String
BANKRUPT_TAG
protected java.util.Set<Player>
bannedMissions
A list of players who can not establish missions to this player.private java.lang.Object
canSeeLock
Do not access canSeeTiles without taking canSeeLock.private boolean[][]
canSeeTiles
The tiles the player can see.private boolean
canSeeValid
Are the canSeeTiles valid or do they need to be recalculated?private java.util.Comparator<Colony>
colonyComparator
A comparator to enforce the player prefered colony order.private static java.lang.String
CURRENT_FATHER_TAG
protected FoundingFather
currentFather
Current founding father being recruited.protected boolean
dead
Is this player dead?private static java.lang.String
DEAD_TAG
private static java.lang.String
ENTRY_LOCATION_TAG
protected Tile
entryTile
The player starting tile on the map.protected Europe
europe
The European port/location for this player.protected FeatureContainer
featureContainer
A container for the abilities and modifiers of this type.private static java.lang.String
FOUNDING_FATHERS_TAG
protected java.util.Set<FoundingFather>
foundingFathers
The founding fathers in this Player's congress.protected int
gold
The amount of gold this player owns.static int
GOLD_NOT_ACCOUNTED
A magic constant to denote that a players gold is not tracked.private static java.lang.String
GOLD_TAG
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.private static java.lang.String
IMMIGRATION_REQUIRED_TAG
private static java.lang.String
IMMIGRATION_TAG
protected int
immigrationRequired
The amount of immigration needed until the next unit decides to migrate.private static java.lang.String
INDEPENDENT_NATION_NAME_TAG
protected java.lang.String
independentNationName
The name of this player as an independent nation.private static java.lang.String
INTERVENTION_BELLS_TAG
protected int
interventionBells
The number of liberty bells produced towards the intervention force.protected java.util.HashMap<java.lang.String,LastSale>
lastSales
The last-sale data.protected int
liberty
The number of liberty points.private static java.lang.String
LIBERTY_TAG
private static java.util.logging.Logger
logger
protected Market
market
The market for Europe.private int
maximumFoodConsumption
The maximum food consumption of unit types available to this player.protected java.util.List<ModelMessage>
modelMessages
The current model messages for this player.protected Monarch
monarch
The monarch for this player.protected java.lang.String
name
The name of this player.private static java.lang.String
NATION_ID_TAG
private static java.lang.String
NATION_TYPE_TAG
private java.util.Map<Player,NationSummary>
nationCache
A cached map of the current nation summary for all live nations.protected java.lang.String
nationId
The nation identifier of this player, e.g.protected NationType
nationType
The player nation type.private static java.lang.String
NEW_LAND_NAME_TAG
protected java.lang.String
newLandName
The name this player uses for the New World.private UnitIterator
nextActiveUnitIterator
An iterator for the player units that are still active this turn.private UnitIterator
nextGoingToUnitIterator
An iterator for the player units that have a destination to go to.private static java.lang.String
OFFERED_FATHERS_TAG
protected java.util.List<FoundingFather>
offeredFathers
The offered founding fathers.private static java.lang.String
OLD_SOL_TAG
protected int
oldSoL
SoL from last turn.private static int
PLAYER_CLASS_INDEX
Class index for a player.private static java.lang.String
PLAYER_TAG
private static java.lang.String
PLAYER_TYPE_TAG
static java.util.Comparator<Player>
playerComparator
A comparator for ordering players.protected Player.PlayerType
playerType
The type of player.protected boolean
ready
Is this player ready to start?private static java.lang.String
READY_TAG
protected int
score
The current score of this player.private static java.lang.String
SCORE_TAG
protected java.util.List<Settlement>
settlements
The settlements this player owns.protected java.util.Map<java.lang.String,Stance>
stance
Stores the stance towards the other players.private static java.lang.String
STANCE_TAG
static java.lang.String
TAG
protected int
tax
The current tax rate for this player.private static java.lang.String
TAX_TAG
protected java.util.Map<Player,Tension>
tension
The tension levels, 0-1000, with 1000 being maximum hostility.private static java.lang.String
TENSION_TAG
protected java.util.List<TradeRoute>
tradeRoutes
The trade routes defined by this player.private java.util.Set<Unit>
units
The units this player owns.private static java.lang.String
USERNAME_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFather(FoundingFather father)
Add a founding father to the congress.void
addHistory(HistoryEvent event)
Add a history event to this player.void
addLastSale(LastSale sale)
Saves a record of a sale.void
addMissionBan(Player player)
Ban a player from establishing missions to this player.void
addModelMessage(ModelMessage modelMessage)
Adds a message for this player.boolean
addOwnable(Ownable o)
Add an ownable to a caching container.boolean
addSettlement(Settlement settlement)
Adds a given settlement to this player's list of settlements.void
addStartGameMessage()
Add the tutorial message for the start of the game.void
addTradeRoute(TradeRoute tradeRoute)
Add a new trade route.boolean
addUnit(Unit newUnit)
Add a unit to this player.boolean
atWarWith(Player player)
Is this player at war with the specified one.int
calculateStrength(boolean naval)
Generic strength calculation.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()
Can this player 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 implies 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 acquisitionboolean
canHaveFoundingFathers()
Can this player recruit 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
canSee(Tile tile)
Can this player see a given tile.boolean
canSeeUnit(Unit unit)
Checks if this player can see a unit.boolean
canTrade(GoodsType type)
Can a type of goods can be traded in Europe?boolean
canTrade(GoodsType type, Market.Access access)
Can a type of goods can be traded at a specified place?void
changeNationType(NationType newNationType)
Changes the nation type of this player, handling the features.void
changePlayerType(Player.PlayerType type)
Change the player type.StringTemplate
checkDeclareIndependence()
Check whether this player can declare independence.boolean
checkEmigrate()
Should a new colonist emigrate?boolean
checkGold(int amount)
Checks if the player has enough gold to make a purchase.Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.private void
clearHistory()
Clear the history events.void
clearModelMessages()
Removes all the model messages for this player.void
clearNationCache()
Clear the nation cache.void
clearNationSummary(Player player)
Clear the nation cache entry for a player.void
clearOfferedFathers()
Clear the set of offered fathers.private void
clearTradeRoutes()
Clear the trade routes.ChangeSet
clientError(java.lang.String message)
Convenience function to create a client error message, log it, and wrap it into a change set.ChangeSet
clientError(StringTemplate template)
Convenience function to create a client error message for this player, log it, and wrap it into a change set.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.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.java.util.List<java.lang.Double>
getAllColonyValues(Tile tile)
Gets a list of values for building aColony
on the given tile for eachColonyValueCategory
.int
getArrears(GoodsType type)
Gets the arrears due for a type of goods.boolean
getAttackedByPrivateers()
Has player has been attacked by privateers?boolean
getBankrupt()
Get the bankruptcy state.protected java.util.Set<Player>
getBannedMissions()
Get the players that can not set up missions.java.lang.String
getCapitalName(java.util.Random random)
Gets the name of this players capital.java.util.List<Unit>
getCarriersForUnit(Unit unit)
Gets the carrier units that can carry the supplied unit, if one exists.java.util.List<Tile>
getClaimableTiles(Tile centerTile, int radius)
Gets the list of tiles that might be claimable by a settlement.int
getClassIndex()
Accessor for the class index.Settlement
getClosestPortForEurope()
Gets the port closest to Europe owned by this player.java.util.stream.Stream<Colony>
getColonies()
Get a stream of all colonies this player owns.int
getColoniesPopulation()
Gets the sum of units currently working in the colonies of this player.Colony
getColonyByName(java.lang.String name)
Gets theColony
with the given name.java.util.List<Colony>
getColonyList()
Get a fresh list of all colonies this player owns.int
getColonyValue(Tile tile)
Gets the value for building aColony
on the given tile.java.util.List<Colony>
getConnectedPortList()
Get the connected port settlements.java.util.stream.Stream<Colony>
getConnectedPorts()
Get a stream of the connected port settlements.Connection
getConnection()
Gets the connection of this player.StringTemplate
getCountryLabel()
Get a template for this players country.FoundingFather
getCurrentFather()
Gets thefounding father
this player is working towards.boolean
getDead()
Get the player death state.java.lang.String
getDebugName()
Get a short debug-suitable name for this player.FreeColObject
getDisplayObject()
Get an object to display when showing the user messages for this object.java.util.Map<java.lang.String,Turn>
getElectionTurns()
Gets theTurn
s during which FoundingFathers were elected to the Continental CongressModelMessage
getEmigrationMessage(Unit unit)
Get a message for a newly migrating unit.Tile
getEntryTile()
Gets the default initial location where the units arriving fromEurope
appear on the map.Europe
getEurope()
Gets this players Europe object.int
getEuropeanPurchasePrice(AbstractUnit au)
Gets the price to this player to purchase a unit in Europe.int
getEuropeanRecruitPrice()
Gets the price for a recruit in Europe.java.lang.String
getEuropeNameKey()
Get a name key for the player Europe.Tile
getFallbackTile()
Get a default tile to display at the start of the player turn should there not be any active units.int
getFatherCount()
Gets the number of founding fathers in this players congress.FeatureContainer
getFeatureContainer()
Gets the feature container for this object, if any.StringTemplate
getForcesLabel()
Get a label indicating for the national forces.java.util.Set<FoundingFather>
getFoundingFathers()
Gets the founding fathers in this player's congress.int
getGold()
Get the amount of gold that this player has.HighSeas
getHighSeas()
Get the players high seas.java.util.List<HistoryEvent>
getHistory()
Get the history events for this player.int
getImmigration()
Gets the amount of immigration this player possess.int
getImmigrationRequired()
Gets the amount of immigration required to cause a new colonist to emigrate.int
getIncomeAfterTaxes(GoodsType goodsType)
Get the current incomeAfterTaxes.int
getIncomeBeforeTaxes(GoodsType goodsType)
Get the current incomeBeforeTaxes.java.lang.String
getIndependentNationName()
Get the new post-declaration player name.IndianSettlement
getIndianSettlementByName(java.lang.String name)
Gets theIndianSettlement
with the given name.java.util.List<IndianSettlement>
getIndianSettlementList()
Get a list of all the IndianSettlements this player owns.java.util.stream.Stream<IndianSettlement>
getIndianSettlements()
Get a stream of all the indian settlements this player owns.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.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.protected int
getInterventionBells()
Get the bells for intervention.StringTemplate
getLabel()
Get a label for this player.int
getLandPrice(Tile tile)
Gets the price of the given land.LastSale
getLastSale(Location where, GoodsType what)
Gets the current sales data for a location and goods type.protected java.util.Map<java.lang.String,LastSale>
getLastSales()
Get the last sales events.java.lang.String
getLastSaleString(Location where, GoodsType what)
Gets the last sale price for a location and goods type as a string.StringTemplate
getLastSaleTip(Location where, GoodsType what)
Get a template for the last sale price for a location and goods type.int
getLiberty()
Gets the current amount of liberty points this player has.int
getLibertyProductionNextTurn()
Gets how much liberty will be produced next turn if no colonies are lost and nothing unexpected happens.Market
getMarket()
Get 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()
Gets the maximum food consumption of any unit types available to this player.int
getMercenaryHirePrice(AbstractUnit au)
Gets the price to this player to hire a mercenary unit.java.util.List<AbstractUnit>
getMilitaryUnits()
Get a list of the military units for this player.java.util.List<ModelMessage>
getModelMessages()
Gets all the model messages for this player.Monarch
getMonarch()
Gets the monarch object this player has.Goods
getMostValuableGoods()
Get 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()
Gets the name of this player.java.lang.String
getNameForNewLand()
Get a name for the new land.java.lang.String
getNameForRegion(Region region)
Get a name for a region.java.lang.String
getNameForTradeRoute()
Get a unique name for a new trade route.java.lang.String
getNameForUnit(UnitType type, java.util.Random random)
Gets a new name for a unit.Nation
getNation()
Gets this Player's nation.java.awt.Color
getNationColor()
Gets the player nation color.java.lang.String
getNationId()
Get the identifier for this Player's nation.StringTemplate
getNationLabel()
Get a template for this players nation name.java.lang.String
getNationResourceKey()
Gets a resource key for the nation name.NationSummary
getNationSummary(Player player)
Access the nation cache.NationType
getNationType()
Get the nation type of this player.TradeRoute
getNewestTradeRoute()
Get the most recently defined trade route.java.lang.String
getNewLandName()
Gets the name this player has chosen for the new world.java.util.List<ModelMessage>
getNewModelMessages()
Gets all new messages 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
getNumberOfPorts()
Get the number of port settlements.java.util.List<FoundingFather>
getOfferedFathers()
Gets the offered fathers for this player.protected int
getOldSoL()
Get the old SoL.<T extends FreeColGameObject>
TgetOurFreeColGameObject(java.lang.String id, java.lang.Class<T> returnClass)
Get aFreeColGameObject
with the specified identifier and class, owned by this player.Player.PlayerType
getPlayerType()
Get the type of this player.int
getRank()
Get an integer to broadly categorized the player for sorting.boolean
getReady()
Get the readiness state.java.util.List<Player>
getRebels()
Gets a list of the players in rebellion against this (REF) player.double
getRebelStrengthRatio(boolean naval)
Get the strength ratio of this player with respect to its REF.Player
getREFPlayer()
Gets thePlayer
controlling the "Royal Expeditionary Force" for this player.java.util.List<AbstractUnit>
getREFUnits()
Get a list of abstract REF units for this player.int
getRemainingFoundingFatherCost()
Gets the number of liberty points needed to recruit the next founding father.java.lang.String
getRulerNameKey()
Get a name key for the player nation ruler.int
getSales(GoodsType goodsType)
Get the current sales of a type of goods.int
getScore()
Gets the current score of the player.Settlement
getSettlementByName(java.lang.String name)
Find aSettlement
by name.int
getSettlementCount()
Get the count of settlements.java.util.List<Settlement>
getSettlementList()
Gets a the settlements this player owns.java.lang.String
getSettlementName(java.util.Random random)
Gets a settlement name suitable for this player.java.util.stream.Stream<Settlement>
getSettlements()
Get a stream of the 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> comp)
Get a sorted list of all colonies this player owns.int
getSpanishSuccessionScore()
Gets the score by which we decide the weakest and strongest AI players for the Spanish Succession event.Stance
getStance(Player player)
Gets the stance towards a given player.protected java.util.Map<java.lang.String,Stance>
getStances()
Get the stance map.double
getStrengthRatio(Player other, boolean naval)
Get the strength ratio of this player with respect to another.int
getTax()
Get the current tax.protected java.util.Map<Player,Tension>
getTension()
Get the tension map.Tension
getTension(Player player)
Gets the hostility this player has against the given player.int
getTotalFoundingFatherCost()
How many liberty points in total are needed to earn the Founding Father we are trying to recruit.int
getTotalImmigrationProduction()
Get the total immigration production for this player.TradeRoute
getTradeRouteByName(java.lang.String name, TradeRoute exclude)
Get a trade route by name.int
getTradeRouteCount()
Get number of trade routes defined for this player.java.util.List<TradeRoute>
getTradeRoutes()
Get the trade routes defined for this player.Unit
getUnitByName(java.lang.String name)
Get a player unit by name.int
getUnitCount()
Get the number of units a player has.int
getUnitCount(boolean naval)
Get the number of units a player has, either land or naval.java.util.stream.Stream<Unit>
getUnits()
Get a stream of the players units.java.util.Set<Unit>
getUnitSet()
Get a copy of the players units.java.util.Set<Tile>
getVisibleTileSet()
Get the set of tiles visible to this player.StringTemplate
getWaitingLabel()
Get a label indicating that we are waiting for this player.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
hasContacted(Player player)
Has this player met contacted the given one?boolean
hasContactedEuropeans()
Has this player has met with any Europeans at all?boolean
hasContactedIndians()
Has this player met any natives at all?boolean
hasExplored(Tile tile)
Checks if this player has explored the given tile.boolean
hasFather(FoundingFather someFather)
Does this player have a certain Founding father.boolean
hasNextActiveUnit()
Checks if a new active unit can be made active.boolean
hasNextGoingToUnit()
Checks if there is a unit that has a destination.boolean
hasSettlement(Settlement settlement)
Does this player own a given settlement.boolean
hasSettlements()
Does this player have any settlements at present.boolean
hasTraded(GoodsType goodsType)
Has a type of goods been traded?boolean
hasUnit(Unit unit)
Does this player's units list contain the given unit?boolean
hasUnitType(java.lang.String typeId)
Checks if this player has at least one of a given unit type.private boolean
hasZeroSettlements()
The second and third cases of buildOnNative land need to test if the player has no settlements yet.void
initializeHighSeas()
Initialize the highSeas.void
invalidateCanSeeTiles()
Forces an update of thecanSeeTiles
.boolean
isAdmin()
Is this player an admin.boolean
isAI()
Is this an AI player?boolean
isAtWar()
Checks whether this player is at war with any other player.boolean
isColonial()
Checks if this player is colonial, and thus can recruit units by producing immigration.boolean
isConnected()
Is this player is currently connected to the server?boolean
isDead()
Checks if this player is dead.boolean
isEuropean()
Checks if this player is European, with does include the REF.boolean
isIndian()
Is this a native player?boolean
isNewLandNamed()
Has the player already selected a name for the new world?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?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?boolean
isReady()
Is this player ready to start the game?boolean
isRebel()
Is this a colonial rebel player?boolean
isREF()
Is this a REF player?boolean
isUndead()
Is this an undead player?boolean
isUnknownEnemy()
Is this player the unknown enemy?boolean
isWorkForREF()
Checks if this player has work to do if it is a REF-player.void
logCheat(java.lang.String what)
Standardized log of an instance of cheating by this 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.boolean
missionsBanned(Player player)
Does this player ban missions from another player?int
modifyGold(int amount)
Modifies the amount of gold that this player has.void
modifyImmigration(int amount)
Modify the player immigration.void
modifyIncomeAfterTaxes(GoodsType goodsType, int amount)
Modifies the current incomeAfterTaxes.void
modifyIncomeBeforeTaxes(GoodsType goodsType, int amount)
Modifies the current incomeBeforeTaxes.void
modifyLiberty(int amount)
Modifies the current amount of liberty this player has.void
modifySales(GoodsType goodsType, int amount)
Modifies the current sales.boolean
owns(Ownable ownable)
Does this player own something?void
putNationSummary(Player player, NationSummary ns)
Update the nation cache.void
putSettlementName(java.lang.String name)
Puts a suggested settlement name back into the pool.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.protected boolean
recalculateBellsBonus()
Recalculate bells bonus when tax changes.void
reduceImmigration()
Sets the number of immigration this player possess.void
refilterModelMessages(OptionGroup options)
Refilters the current model messages, removing the ones that are no longer valid.void
reinitialiseMarket()
Resets this player's Market.void
removeDisplayedModelMessages()
Removes all undisplayed model messages for this player.void
removeMissionBan(Player player)
Remove a mission ban from a player.boolean
removeOwnable(Ownable o)
Remove an ownable from a caching container.boolean
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.java.util.List<Unit>
removeTradeRoute(TradeRoute tradeRoute)
Remove a trade route.boolean
removeUnit(Unit oldUnit)
Remove a unit from this player.void
resetIterators()
Reset the player iterators ready for a new turn.Unit
restoreActiveUnit()
Recover the active unit when restoring a game.boolean
send(ChangeSet cs)
Send a change set across the connection.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
setBankrupt(boolean newBankrupt)
Set the bankruptcy state.protected void
setBannedMissions(java.util.Collection<Player> bannedMissions)
Set banned mission set.void
setColonyComparator(java.util.Comparator<Colony> cc)
Set the local colony comparator.void
setConnection(Connection connection)
Sets the connection of this player.void
setCurrentFather(FoundingFather someFather)
Sets the current founding father to recruit.void
setDead(boolean dead)
Sets this player to be dead or not.void
setEntryTile(Tile entryTile)
Sets the default initial location where the units arriving fromEurope
appear on the map.void
setEurope(Europe europe)
Set the Europe object for a player.protected void
setFoundingFathers(java.util.Set<FoundingFather> foundingFathers)
Gets the founding fathers in this player's congress.void
setGold(int newGold)
Set the amount of gold that this player has.protected void
setHistory(java.util.List<HistoryEvent> history)
Clear the history events.void
setImmigration(int immigration)
Sets the amount 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 post-declaration player name.protected void
setLastSales(java.util.Map<java.lang.String,LastSale> lastSales)
Set the last sales events.void
setLiberty(int liberty)
Sets the current amount of liberty this player has.protected void
setModelMessages(java.util.List<ModelMessage> modelMessages)
Set the model message list.void
setMonarch(Monarch monarch)
Sets the monarch object this player has.void
setName(java.lang.String newName)
Set the player name.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 world.boolean
setNextGoingToUnit(Unit unit)
Sets a new going-to unit.void
setOfferedFathers(java.util.List<FoundingFather> fathers)
Sets the set of offered fathers.private void
setPlayerType(Player.PlayerType type)
Sets the player type.void
setReady(boolean ready)
Sets this players readiness state.void
setScore(int score)
Set the current score of the player.boolean
setStance(Player player, Stance newStance)
Sets the stance towards a given player.protected void
setStances(java.util.Map<java.lang.String,Stance> stances)
Set the stance map.void
setTax(int amount)
Sets the current taxprotected void
setTension(java.util.Map<Player,Tension> tension)
Set the tension map.void
setTension(Player player, Tension newTension)
Sets the tension with respect to a given player.static double
strengthRatio(double ours, double theirs)
Abstraction of the strength ratio calculation.java.lang.String
toString()
void
updateImmigrationRequired()
Updates the amount of immigration needed to emigrate aUnit
fromEurope
.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeResources, equals, fundamentalDispose, getDisposables, getGame, getLinkTarget, getSpecification, hashCode, intern, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
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
-
TAG
public static final java.lang.String TAG
- 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.
-
playerType
protected Player.PlayerType playerType
The type of player.
-
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.
-
ADMIN_TAG
private static final java.lang.String ADMIN_TAG
- See Also:
- Constant Field Values
-
AI_TAG
private static final java.lang.String AI_TAG
- See Also:
- Constant Field Values
-
ATTACKED_BY_PRIVATEERS_TAG
private static final java.lang.String ATTACKED_BY_PRIVATEERS_TAG
- See Also:
- Constant Field Values
-
BANKRUPT_TAG
private static final java.lang.String BANKRUPT_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
-
DEAD_TAG
private static final java.lang.String DEAD_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
-
GOLD_TAG
private static final java.lang.String GOLD_TAG
- See Also:
- Constant Field Values
-
IMMIGRATION_TAG
private static final java.lang.String IMMIGRATION_TAG
- See Also:
- Constant Field Values
-
IMMIGRATION_REQUIRED_TAG
private static final java.lang.String IMMIGRATION_REQUIRED_TAG
- See Also:
- Constant Field Values
-
LIBERTY_TAG
private static final java.lang.String LIBERTY_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
-
NATION_ID_TAG
private static final java.lang.String NATION_ID_TAG
- See Also:
- Constant Field Values
-
NATION_TYPE_TAG
private static final java.lang.String NATION_TYPE_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
-
OLD_SOL_TAG
private static final java.lang.String OLD_SOL_TAG
- See Also:
- Constant Field Values
-
PLAYER_TAG
private static final java.lang.String PLAYER_TAG
- See Also:
- Constant Field Values
-
PLAYER_TYPE_TAG
private static final java.lang.String PLAYER_TYPE_TAG
- See Also:
- Constant Field Values
-
READY_TAG
private static final java.lang.String READY_TAG
- See Also:
- Constant Field Values
-
SCORE_TAG
private static final java.lang.String SCORE_TAG
- See Also:
- Constant Field Values
-
STANCE_TAG
private static final java.lang.String STANCE_TAG
- See Also:
- Constant Field Values
-
TAX_TAG
private static final java.lang.String TAX_TAG
- See Also:
- Constant Field Values
-
TENSION_TAG
private static final java.lang.String TENSION_TAG
- See Also:
- Constant Field Values
-
USERNAME_TAG
private static final java.lang.String USERNAME_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Player
protected Player(Game game)
Constructor for ServerPlayer.- Parameters:
game
- The enclosingGame
.
-
Player
public Player(Game game, java.lang.String id)
Creates a newPlayer
with the given id. The object should be initialized later.- Parameters:
game
- TheGame
this object belongs to.id
- The object identifier.
-
-
Method Detail
-
getName
public java.lang.String getName()
Gets the name of this player.
-
setName
public void setName(java.lang.String newName)
Set the player name.
-
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
- ThisPlayer
'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
- TheRegion
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
- TheUnitType
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
- TheConnection
.
-
send
public boolean send(ChangeSet cs)
Send a change set across the connection.- Parameters:
cs
- TheChangeSet
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
- ThePlayer
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
- ThePlayer
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 newNationType
.
-
changeNationType
public void changeNationType(NationType newNationType)
Changes the nation type of this player, handling the features.- Parameters:
newNationType
- The newNationType
.
-
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 newNation
.
-
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. APlayer
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 thePlayer
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 aUnit
fromEurope
.
-
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
- TheUnit
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
'sColony
s 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
FoundingFather
s in congress.
-
setFoundingFathers
protected void setFoundingFathers(java.util.Set<FoundingFather> foundingFathers)
Gets the founding fathers in this player's congress.- Parameters:
foundingFathers
- A set ofFoundingFather
s in congress.
-
hasFather
public boolean hasFather(FoundingFather someFather)
Does this player have a certain Founding father.- Parameters:
someFather
- TheFoundingFather
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
- TheFoundingFather
to add.
-
getCurrentFather
public FoundingFather getCurrentFather()
Gets thefounding 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 the current founding father to recruit.- Parameters:
someFather
- TheFoundingFather
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
FoundingFather
s.
-
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 ofFoundingFather
s 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 nextFoundingFather
.
-
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 nextFoundingFather
.
-
getElectionTurns
public java.util.Map<java.lang.String,Turn> getElectionTurns()
Gets theTurn
s during which FoundingFathers were elected to the Continental Congress- Returns:
- A map of father id to
Turn
s.
-
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
AbstractUnit
s 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
AbstractUnit
s.
-
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
LastSale
s list.
-
setLastSales
protected void setLastSales(java.util.Map<java.lang.String,LastSale> lastSales)
Set the last sales events.- Parameters:
lastSales
- The new list ofLastSale
s.
-
getLastSale
public LastSale getLastSale(Location where, GoodsType what)
Gets the current sales data for a location and goods type.- Parameters:
where
- TheLocation
of the sale.what
- TheGoodsType
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
- TheLastSale
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
- TheLocation
of the sale.what
- TheGoodsType
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
- TheLocation
of the sale.what
- TheGoodsType
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
- TheGoodsType
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
- TheGoodsType
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
- TheGoodsType
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
- TheGoodsType
to query.- Returns:
- The current sales.
-
modifySales
public void modifySales(GoodsType goodsType, int amount)
Modifies the current sales.- Parameters:
goodsType
- TheGoodsType
to modify.amount
- The new sales.
-
hasTraded
public boolean hasTraded(GoodsType goodsType)
Has a type of goods been traded?- Parameters:
goodsType
- TheGoodsType
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
- TheGoodsType
to query.- Returns:
- The current incomeBeforeTaxes.
-
modifyIncomeBeforeTaxes
public void modifyIncomeBeforeTaxes(GoodsType goodsType, int amount)
Modifies the current incomeBeforeTaxes.- Parameters:
goodsType
- TheGoodsType
to modify.amount
- The new incomeBeforeTaxes.
-
getIncomeAfterTaxes
public int getIncomeAfterTaxes(GoodsType goodsType)
Get the current incomeAfterTaxes.- Parameters:
goodsType
- TheGoodsType
to query.- Returns:
- The current incomeAfterTaxes.
-
modifyIncomeAfterTaxes
public void modifyIncomeAfterTaxes(GoodsType goodsType, int amount)
Modifies the current incomeAfterTaxes.- Parameters:
goodsType
- TheGoodsType
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 newEurope
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 proposedAbstractUnit
.- 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 proposedAbstractUnit
.- 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 newMonarch
object.
-
hasUnit
public boolean hasUnit(Unit unit)
Does this player's units list contain the given unit?- Parameters:
unit
- TheUnit
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
Unit
s.
-
getUnitSet
public java.util.Set<Unit> getUnitSet()
Get a copy of the players units.- Returns:
- A set of the player
Unit
s.
-
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 newUnit
value.- Returns:
- True if the units container changed.
-
removeUnit
public boolean removeUnit(Unit oldUnit)
Remove a unit from this player.- Parameters:
oldUnit
- TheUnit
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
- TheUnit
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
- AUnit
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
TradeRoute
s 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
- TheTradeRoute
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 optionalTradeRoute
to exclude.- Returns:
- The
TradeRoute
found.
-
removeTradeRoute
public final java.util.List<Unit> removeTradeRoute(TradeRoute tradeRoute)
Remove a trade route.- Parameters:
tradeRoute
- TheTradeRoute
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
- TheOwnable
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
- TheOwnable
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
Colony
s.
-
getConnectedPorts
public java.util.stream.Stream<Colony> getConnectedPorts()
Get a stream of the connected port settlements.- Returns:
- A stream of connected port
Colony
s.
-
hasSettlement
public boolean hasSettlement(Settlement settlement)
Does this player own a given settlement.- Parameters:
settlement
- TheSettlement
to check.- Returns:
- True if this
Player
owns the givenSettlement
.
-
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
- TheSettlement
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
- TheSettlement
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 theColony
with the given name.- Parameters:
name
- The name of theColony
.- Returns:
- The
Colony
with the given name, or null if not found.
-
getIndianSettlementByName
public IndianSettlement getIndianSettlementByName(java.lang.String name)
Gets theIndianSettlement
with the given name.- Parameters:
name
- The name of theIndianSettlement
.- 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
Colony
s 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
Colony
s 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
- AComparator
to operate on the colony list.- Returns:
- A fresh list of the
Colony
s 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
IndianSettlement
s 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
IndianSettlement
s 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
- ThePlayer
.- Returns:
- A list of the
IndianSettlement
s 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
- ThePlayer
.- Returns:
- A stream of the
IndianSettlement
s with a matching missionary.
-
getSettlementByName
public Settlement getSettlementByName(java.lang.String name)
Find aSettlement
by name.- Parameters:
name
- The name of theSettlement
.- Returns:
- The
Settlement
, ornull
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
ModelMessage
s for thisPlayer
.
-
getNewModelMessages
public java.util.List<ModelMessage> getNewModelMessages()
Gets all new messages for this player.- Returns:
- all The new
ModelMessage
s for thisPlayer
.
-
addModelMessage
public void addModelMessage(ModelMessage modelMessage)
Adds a message for this player.- Parameters:
modelMessage
- TheModelMessage
to add.
-
refilterModelMessages
public void refilterModelMessages(OptionGroup options)
Refilters the current model messages, removing the ones that are no longer valid.- Parameters:
options
- TheOptionGroup
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 newModelMessages
.
-
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
HistoryEvent
s for this player.
-
addHistory
public void addHistory(HistoryEvent event)
Add a history event to this player.- Parameters:
event
- TheHistoryEvent
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 newHistoryEvent
s.
-
getEntryTile
public Tile getEntryTile()
Gets the default initial location where the units arriving fromEurope
appear on the map.- Returns:
- The entry
Tile
.
-
setEntryTile
public void setEntryTile(Tile entryTile)
Sets the default initial location where the units arriving fromEurope
appear on the map.- Parameters:
entryTile
- The new entryTile
.- 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
- TheTile
to check.- Returns:
- True if the
Tile
has been explored.
-
invalidateCanSeeTiles
public void invalidateCanSeeTiles()
Forces an update of thecanSeeTiles
. This method should be used to invalidate the currentcanSeeTiles
when something significant changes. The methodmakeCanSeeTiles(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
- TheTile
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
- TheUnit
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
Tile
s.
-
makeCanSeeTiles
private boolean[][] makeCanSeeTiles(Map map)
Builds a canSeeTiles array.- Parameters:
map
- TheMap
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 otherPlayer
.- 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 otherPlayer
.newTension
- The newTension
.
-
removeTension
public void removeTension(Player player)
Removes all tension with respect to a given player. Used when a player leaves the game.- Parameters:
player
- ThePlayer
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 otherPlayer
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
- ThePlayer
to ban.
-
removeMissionBan
public void removeMissionBan(Player player)
Remove a mission ban from a player.- Parameters:
player
- ThePlayer
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 otherPlayer
to check.- Returns:
- The stance.
-
setStance
public boolean setStance(Player player, Stance newStance)
Sets the stance towards a given player.- Parameters:
player
- ThePlayer
to set theStance
for.newStance
- The newStance
.- 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 otherPlayer
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 otherPlayer
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
- OnePlayer
to check.player2
- The otherPlayer
to check.
-
getLandPrice
public int getLandPrice(Tile tile)
Gets the price of the given land.- Parameters:
tile
- TheTile
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
- ThePlayer
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
- ThePlayer
to get the summary for.ns
- The newNationSummary
for the player.
-
clearNationSummary
public void clearNationSummary(Player player)
Clear the nation cache entry for a player.- Parameters:
player
- ThePlayer
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 otherPlayer
.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
- TheTile
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
- TheTile
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
- TheTile
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
- TheTile
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
- TheTile
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
- TheTile
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
- TheTile
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
- TheTile
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
- TheTile
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 centerTile
.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 aColony
on the given tile for eachColonyValueCategory
. FIXME: tune magic numbers and expose more to the spec.- Parameters:
tile
- TheTile
- Returns:
- A list of values.
-
getColonyValue
public int getColonyValue(Tile tile)
Gets the value for building aColony
on the given tile. FIXME: tune magic numbers and expose more to the spec.- Parameters:
tile
- TheTile
- 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
- TheOwnable
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 aFreeColGameObject
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 newComparator
.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Overrides:
checkIntegrity
in classFreeColGameObject
- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
to log to.- Returns:
- A suitable
IntegrityType
.
-
getFeatureContainer
public final FeatureContainer getFeatureContainer()
Gets the feature container for this object, if any.- Overrides:
getFeatureContainer
in classFreeColObject
- Returns:
- The
FeatureContainer
for this object.
-
getClassIndex
public int getClassIndex()
Accessor for the class index.- Overrides:
getClassIndex
in classFreeColGameObject
- Returns:
- The class index used by
ClientOptions
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColGameObject
- Type Parameters:
T
- TheFreeColObject
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 classFreeColObject
- 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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColGameObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-