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 classPlayer.ColonyValueCategoryColony value categories.static classPlayer.NoClaimReasonA 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 classPlayer.NoValueTypeSpecial return values for showstopper getColonyValue fail.static classPlayer.PlayerTypeTypes of players.
-
Field Summary
Fields Modifier and Type Field Description protected booleanadminIs this player an admin?private static java.lang.StringADMIN_TAGprotected booleanaiIs this player an AI?private static java.lang.StringAI_TAGstatic java.lang.StringASSIGN_SETTLEMENT_NAMEA 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.StringATTACKED_BY_PRIVATEERS_TAGprotected booleanattackedByPrivateersTrue if player has been attacked by privateers.private static java.lang.StringBAN_MISSIONS_TAGprivate booleanbankruptWhether the player is bankrupt, i.e.private static java.lang.StringBANKRUPT_TAGprotected java.util.Set<Player>bannedMissionsA list of players who can not establish missions to this player.private java.lang.ObjectcanSeeLockDo not access canSeeTiles without taking canSeeLock.private boolean[][]canSeeTilesThe tiles the player can see.private booleancanSeeValidAre the canSeeTiles valid or do they need to be recalculated?private java.util.Comparator<Colony>colonyComparatorA comparator to enforce the player prefered colony order.private static java.lang.StringCURRENT_FATHER_TAGprotected FoundingFathercurrentFatherCurrent founding father being recruited.protected booleandeadIs this player dead?private static java.lang.StringDEAD_TAGprivate static java.lang.StringENTRY_LOCATION_TAGprotected TileentryTileThe player starting tile on the map.protected EuropeeuropeThe European port/location for this player.protected FeatureContainerfeatureContainerA container for the abilities and modifiers of this type.private static java.lang.StringFOUNDING_FATHERS_TAGprotected java.util.Set<FoundingFather>foundingFathersThe founding fathers in this Player's congress.protected intgoldThe amount of gold this player owns.static intGOLD_NOT_ACCOUNTEDA magic constant to denote that a players gold is not tracked.private static java.lang.StringGOLD_TAGprotected HighSeashighSeasThe HighSeas is a Location that enables Units to travel between the New World and one or several European Ports.protected java.util.List<HistoryEvent>historyThe history events occuring with this player.protected intimmigrationThe number of immigration points.private static java.lang.StringIMMIGRATION_REQUIRED_TAGprivate static java.lang.StringIMMIGRATION_TAGprotected intimmigrationRequiredThe amount of immigration needed until the next unit decides to migrate.private static java.lang.StringINDEPENDENT_NATION_NAME_TAGprotected java.lang.StringindependentNationNameThe name of this player as an independent nation.private static java.lang.StringINTERVENTION_BELLS_TAGprotected intinterventionBellsThe number of liberty bells produced towards the intervention force.protected java.util.HashMap<java.lang.String,LastSale>lastSalesThe last-sale data.protected intlibertyThe number of liberty points.private static java.lang.StringLIBERTY_TAGprivate static java.util.logging.Loggerloggerprotected MarketmarketThe market for Europe.private intmaximumFoodConsumptionThe maximum food consumption of unit types available to this player.protected java.util.List<ModelMessage>modelMessagesThe current model messages for this player.protected MonarchmonarchThe monarch for this player.protected java.lang.StringnameThe name of this player.private static java.lang.StringNATION_ID_TAGprivate static java.lang.StringNATION_TYPE_TAGprivate java.util.Map<Player,NationSummary>nationCacheA cached map of the current nation summary for all live nations.protected java.lang.StringnationIdThe nation identifier of this player, e.g.protected NationTypenationTypeThe player nation type.private static java.lang.StringNEW_LAND_NAME_TAGprotected java.lang.StringnewLandNameThe name this player uses for the New World.private UnitIteratornextActiveUnitIteratorAn iterator for the player units that are still active this turn.private UnitIteratornextGoingToUnitIteratorAn iterator for the player units that have a destination to go to.private static java.lang.StringOFFERED_FATHERS_TAGprotected java.util.List<FoundingFather>offeredFathersThe offered founding fathers.private static java.lang.StringOLD_SOL_TAGprotected intoldSoLSoL from last turn.private static intPLAYER_CLASS_INDEXClass index for a player.private static java.lang.StringPLAYER_TAGprivate static java.lang.StringPLAYER_TYPE_TAGstatic java.util.Comparator<Player>playerComparatorA comparator for ordering players.protected Player.PlayerTypeplayerTypeThe type of player.protected booleanreadyIs this player ready to start?private static java.lang.StringREADY_TAGprotected intscoreThe current score of this player.private static java.lang.StringSCORE_TAGprotected java.util.List<Settlement>settlementsThe settlements this player owns.protected java.util.Map<java.lang.String,Stance>stanceStores the stance towards the other players.private static java.lang.StringSTANCE_TAGstatic java.lang.StringTAGprotected inttaxThe current tax rate for this player.private static java.lang.StringTAX_TAGprotected java.util.Map<Player,Tension>tensionThe tension levels, 0-1000, with 1000 being maximum hostility.private static java.lang.StringTENSION_TAGprotected java.util.List<TradeRoute>tradeRoutesThe trade routes defined by this player.private java.util.Set<Unit>unitsThe units this player owns.private static java.lang.StringUSERNAME_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 voidaddFather(FoundingFather father)Add a founding father to the congress.voidaddHistory(HistoryEvent event)Add a history event to this player.voidaddLastSale(LastSale sale)Saves a record of a sale.voidaddMissionBan(Player player)Ban a player from establishing missions to this player.voidaddModelMessage(ModelMessage modelMessage)Adds a message for this player.booleanaddOwnable(Ownable o)Add an ownable to a caching container.booleanaddSettlement(Settlement settlement)Adds a given settlement to this player's list of settlements.voidaddStartGameMessage()Add the tutorial message for the start of the game.voidaddTradeRoute(TradeRoute tradeRoute)Add a new trade route.booleanaddUnit(Unit newUnit)Add a unit to this player.booleanatWarWith(Player player)Is this player at war with the specified one.intcalculateStrength(boolean naval)Generic strength calculation.booleancanAcquireForImprovement(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.booleancanBuildColonies()Can this player build colonies?booleancanClaimForImprovement(Tile tile)Can the ownership of this tile be claimed for the purposes of making an improvement.booleancanClaimForSettlement(Tile tile)Checks if a tile can be claimed for use by a settlement.Player.NoClaimReasoncanClaimForSettlementReason(Tile tile)The test for whether a tile can be freely claimed by a player settlement (freely implies not by purchase or stealing).private booleancanClaimFreeCenterTile(Tile tile)Is this tile claimable for a colony center tile under the special provisions of the model.option.buildOnNativeLand option.booleancanClaimToFoundSettlement(Tile tile)Can a tile be claimed to found a settlement on?Player.NoClaimReasoncanClaimToFoundSettlementReason(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 acquisitionbooleancanHaveFoundingFathers()Can this player recruit founding fathers?booleancanMoveToEurope()Checks if this player can move units to Europe.booleancanOwnTile(Tile tile)Can a tile be owned by this player?private Player.NoClaimReasoncanOwnTileReason(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.booleancanSee(Tile tile)Can this player see a given tile.booleancanSeeUnit(Unit unit)Checks if this player can see a unit.booleancanTrade(GoodsType type)Can a type of goods can be traded in Europe?booleancanTrade(GoodsType type, Market.Access access)Can a type of goods can be traded at a specified place?voidchangeNationType(NationType newNationType)Changes the nation type of this player, handling the features.voidchangePlayerType(Player.PlayerType type)Change the player type.StringTemplatecheckDeclareIndependence()Check whether this player can declare independence.booleancheckEmigrate()Should a new colonist emigrate?booleancheckGold(int amount)Checks if the player has enough gold to make a purchase.Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)Checks the integrity of this game object.private voidclearHistory()Clear the history events.voidclearModelMessages()Removes all the model messages for this player.voidclearNationCache()Clear the nation cache.voidclearNationSummary(Player player)Clear the nation cache entry for a player.voidclearOfferedFathers()Clear the set of offered fathers.private voidclearTradeRoutes()Clear the trade routes.ChangeSetclientError(java.lang.String message)Convenience function to create a client error message, log it, and wrap it into a change set.ChangeSetclientError(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.voiddivertModelMessages(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 aColonyon the given tile for eachColonyValueCategory.intgetArrears(GoodsType type)Gets the arrears due for a type of goods.booleangetAttackedByPrivateers()Has player has been attacked by privateers?booleangetBankrupt()Get the bankruptcy state.protected java.util.Set<Player>getBannedMissions()Get the players that can not set up missions.java.lang.StringgetCapitalName(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.intgetClassIndex()Accessor for the class index.SettlementgetClosestPortForEurope()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.intgetColoniesPopulation()Gets the sum of units currently working in the colonies of this player.ColonygetColonyByName(java.lang.String name)Gets theColonywith the given name.java.util.List<Colony>getColonyList()Get a fresh list of all colonies this player owns.intgetColonyValue(Tile tile)Gets the value for building aColonyon 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.ConnectiongetConnection()Gets the connection of this player.StringTemplategetCountryLabel()Get a template for this players country.FoundingFathergetCurrentFather()Gets thefounding fatherthis player is working towards.booleangetDead()Get the player death state.java.lang.StringgetDebugName()Get a short debug-suitable name for this player.FreeColObjectgetDisplayObject()Get an object to display when showing the user messages for this object.java.util.Map<java.lang.String,Turn>getElectionTurns()Gets theTurns during which FoundingFathers were elected to the Continental CongressModelMessagegetEmigrationMessage(Unit unit)Get a message for a newly migrating unit.TilegetEntryTile()Gets the default initial location where the units arriving fromEuropeappear on the map.EuropegetEurope()Gets this players Europe object.intgetEuropeanPurchasePrice(AbstractUnit au)Gets the price to this player to purchase a unit in Europe.intgetEuropeanRecruitPrice()Gets the price for a recruit in Europe.java.lang.StringgetEuropeNameKey()Get a name key for the player Europe.TilegetFallbackTile()Get a default tile to display at the start of the player turn should there not be any active units.intgetFatherCount()Gets the number of founding fathers in this players congress.FeatureContainergetFeatureContainer()Gets the feature container for this object, if any.StringTemplategetForcesLabel()Get a label indicating for the national forces.java.util.Set<FoundingFather>getFoundingFathers()Gets the founding fathers in this player's congress.intgetGold()Get the amount of gold that this player has.HighSeasgetHighSeas()Get the players high seas.java.util.List<HistoryEvent>getHistory()Get the history events for this player.intgetImmigration()Gets the amount of immigration this player possess.intgetImmigrationRequired()Gets the amount of immigration required to cause a new colonist to emigrate.intgetIncomeAfterTaxes(GoodsType goodsType)Get the current incomeAfterTaxes.intgetIncomeBeforeTaxes(GoodsType goodsType)Get the current incomeBeforeTaxes.java.lang.StringgetIndependentNationName()Get the new post-declaration player name.IndianSettlementgetIndianSettlementByName(java.lang.String name)Gets theIndianSettlementwith 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 intgetInterventionBells()Get the bells for intervention.StringTemplategetLabel()Get a label for this player.intgetLandPrice(Tile tile)Gets the price of the given land.LastSalegetLastSale(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.StringgetLastSaleString(Location where, GoodsType what)Gets the last sale price for a location and goods type as a string.StringTemplategetLastSaleTip(Location where, GoodsType what)Get a template for the last sale price for a location and goods type.intgetLiberty()Gets the current amount of liberty points this player has.intgetLibertyProductionNextTurn()Gets how much liberty will be produced next turn if no colonies are lost and nothing unexpected happens.MarketgetMarket()Get this player's Market.StringTemplategetMarketName()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.intgetMaximumFoodConsumption()Gets the maximum food consumption of any unit types available to this player.intgetMercenaryHirePrice(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.MonarchgetMonarch()Gets the monarch object this player has.GoodsgetMostValuableGoods()Get the most valuable goods available in one of the player's colonies for the purposes of choosing a threat-to-boycott.java.lang.StringgetName()Gets the name of this player.java.lang.StringgetNameForNewLand()Get a name for the new land.java.lang.StringgetNameForRegion(Region region)Get a name for a region.java.lang.StringgetNameForTradeRoute()Get a unique name for a new trade route.java.lang.StringgetNameForUnit(UnitType type, java.util.Random random)Gets a new name for a unit.NationgetNation()Gets this Player's nation.java.awt.ColorgetNationColor()Gets the player nation color.java.lang.StringgetNationId()Get the identifier for this Player's nation.StringTemplategetNationLabel()Get a template for this players nation name.java.lang.StringgetNationResourceKey()Gets a resource key for the nation name.NationSummarygetNationSummary(Player player)Access the nation cache.NationTypegetNationType()Get the nation type of this player.TradeRoutegetNewestTradeRoute()Get the most recently defined trade route.java.lang.StringgetNewLandName()Gets the name this player has chosen for the new world.java.util.List<ModelMessage>getNewModelMessages()Gets all new messages for this player.UnitgetNextActiveUnit()Gets a new active unit.UnitgetNextGoingToUnit()Gets a new going-to unit.intgetNumberOfKingLandUnits()Gets the number of King's land units.intgetNumberOfPorts()Get the number of port settlements.java.util.List<FoundingFather>getOfferedFathers()Gets the offered fathers for this player.protected intgetOldSoL()Get the old SoL.<T extends FreeColGameObject>
TgetOurFreeColGameObject(java.lang.String id, java.lang.Class<T> returnClass)Get aFreeColGameObjectwith the specified identifier and class, owned by this player.Player.PlayerTypegetPlayerType()Get the type of this player.intgetRank()Get an integer to broadly categorized the player for sorting.booleangetReady()Get the readiness state.java.util.List<Player>getRebels()Gets a list of the players in rebellion against this (REF) player.doublegetRebelStrengthRatio(boolean naval)Get the strength ratio of this player with respect to its REF.PlayergetREFPlayer()Gets thePlayercontrolling the "Royal Expeditionary Force" for this player.java.util.List<AbstractUnit>getREFUnits()Get a list of abstract REF units for this player.intgetRemainingFoundingFatherCost()Gets the number of liberty points needed to recruit the next founding father.java.lang.StringgetRulerNameKey()Get a name key for the player nation ruler.intgetSales(GoodsType goodsType)Get the current sales of a type of goods.intgetScore()Gets the current score of the player.SettlementgetSettlementByName(java.lang.String name)Find aSettlementby name.intgetSettlementCount()Get the count of settlements.java.util.List<Settlement>getSettlementList()Gets a the settlements this player owns.java.lang.StringgetSettlementName(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.intgetSoL()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.intgetSpanishSuccessionScore()Gets the score by which we decide the weakest and strongest AI players for the Spanish Succession event.StancegetStance(Player player)Gets the stance towards a given player.protected java.util.Map<java.lang.String,Stance>getStances()Get the stance map.doublegetStrengthRatio(Player other, boolean naval)Get the strength ratio of this player with respect to another.intgetTax()Get the current tax.protected java.util.Map<Player,Tension>getTension()Get the tension map.TensiongetTension(Player player)Gets the hostility this player has against the given player.intgetTotalFoundingFatherCost()How many liberty points in total are needed to earn the Founding Father we are trying to recruit.intgetTotalImmigrationProduction()Get the total immigration production for this player.TradeRoutegetTradeRouteByName(java.lang.String name, TradeRoute exclude)Get a trade route by name.intgetTradeRouteCount()Get number of trade routes defined for this player.java.util.List<TradeRoute>getTradeRoutes()Get the trade routes defined for this player.UnitgetUnitByName(java.lang.String name)Get a player unit by name.intgetUnitCount()Get the number of units a player has.intgetUnitCount(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.StringTemplategetWaitingLabel()Get a label indicating that we are waiting for this player.java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleanhasContacted(Player player)Has this player met contacted the given one?booleanhasContactedEuropeans()Has this player has met with any Europeans at all?booleanhasContactedIndians()Has this player met any natives at all?booleanhasExplored(Tile tile)Checks if this player has explored the given tile.booleanhasFather(FoundingFather someFather)Does this player have a certain Founding father.booleanhasNextActiveUnit()Checks if a new active unit can be made active.booleanhasNextGoingToUnit()Checks if there is a unit that has a destination.booleanhasSettlement(Settlement settlement)Does this player own a given settlement.booleanhasSettlements()Does this player have any settlements at present.booleanhasTraded(GoodsType goodsType)Has a type of goods been traded?booleanhasUnit(Unit unit)Does this player's units list contain the given unit?booleanhasUnitType(java.lang.String typeId)Checks if this player has at least one of a given unit type.private booleanhasZeroSettlements()The second and third cases of buildOnNative land need to test if the player has no settlements yet.voidinitializeHighSeas()Initialize the highSeas.voidinvalidateCanSeeTiles()Forces an update of thecanSeeTiles.booleanisAdmin()Is this player an admin.booleanisAI()Is this an AI player?booleanisAtWar()Checks whether this player is at war with any other player.booleanisColonial()Checks if this player is colonial, and thus can recruit units by producing immigration.booleanisConnected()Is this player is currently connected to the server?booleanisDead()Checks if this player is dead.booleanisEuropean()Checks if this player is European, with does include the REF.booleanisIndian()Is this a native player?booleanisNewLandNamed()Has the player already selected a name for the new world?booleanisPotentialEnemy(Player player)Is this player currently on good terms with a given player, and thus a suitable candidate for a random monarch war declaration?booleanisPotentialFriend(Player player)Is this player currently on bad terms with a given player, and thus a suitable candidate for a random monarch peace declaration?booleanisReady()Is this player ready to start the game?booleanisRebel()Is this a colonial rebel player?booleanisREF()Is this a REF player?booleanisUndead()Is this an undead player?booleanisUnknownEnemy()Is this player the unknown enemy?booleanisWorkForREF()Checks if this player has work to do if it is a REF-player.voidlogCheat(java.lang.String what)Standardized log of an instance of cheating by this player.private boolean[][]makeCanSeeTiles(Map map)Builds a canSeeTiles array.static voidmakeContact(Player player1, Player player2)Set this player as having made initial contact with another player.booleanmissionsBanned(Player player)Does this player ban missions from another player?intmodifyGold(int amount)Modifies the amount of gold that this player has.voidmodifyImmigration(int amount)Modify the player immigration.voidmodifyIncomeAfterTaxes(GoodsType goodsType, int amount)Modifies the current incomeAfterTaxes.voidmodifyIncomeBeforeTaxes(GoodsType goodsType, int amount)Modifies the current incomeBeforeTaxes.voidmodifyLiberty(int amount)Modifies the current amount of liberty this player has.voidmodifySales(GoodsType goodsType, int amount)Modifies the current sales.booleanowns(Ownable ownable)Does this player own something?voidputNationSummary(Player player, NationSummary ns)Update the nation cache.voidputSettlementName(java.lang.String name)Puts a suggested settlement name back into the pool.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.protected booleanrecalculateBellsBonus()Recalculate bells bonus when tax changes.voidreduceImmigration()Sets the number of immigration this player possess.voidrefilterModelMessages(OptionGroup options)Refilters the current model messages, removing the ones that are no longer valid.voidreinitialiseMarket()Resets this player's Market.voidremoveDisplayedModelMessages()Removes all undisplayed model messages for this player.voidremoveMissionBan(Player player)Remove a mission ban from a player.booleanremoveOwnable(Ownable o)Remove an ownable from a caching container.booleanremoveSettlement(Settlement settlement)Removes the given settlement from this player's list of settlements.voidremoveTension(Player player)Removes all tension with respect to a given player.java.util.List<Unit>removeTradeRoute(TradeRoute tradeRoute)Remove a trade route.booleanremoveUnit(Unit oldUnit)Remove a unit from this player.voidresetIterators()Reset the player iterators ready for a new turn.UnitrestoreActiveUnit()Recover the active unit when restoring a game.booleansend(ChangeSet cs)Send a change set across the connection.voidsetAI(boolean ai)Sets whether this player is an AI player.voidsetAttackedByPrivateers(boolean attacked)Sets whether this player has been attacked by privateers.voidsetBankrupt(boolean newBankrupt)Set the bankruptcy state.protected voidsetBannedMissions(java.util.Collection<Player> bannedMissions)Set banned mission set.voidsetColonyComparator(java.util.Comparator<Colony> cc)Set the local colony comparator.voidsetConnection(Connection connection)Sets the connection of this player.voidsetCurrentFather(FoundingFather someFather)Sets the current founding father to recruit.voidsetDead(boolean dead)Sets this player to be dead or not.voidsetEntryTile(Tile entryTile)Sets the default initial location where the units arriving fromEuropeappear on the map.voidsetEurope(Europe europe)Set the Europe object for a player.protected voidsetFoundingFathers(java.util.Set<FoundingFather> foundingFathers)Gets the founding fathers in this player's congress.voidsetGold(int newGold)Set the amount of gold that this player has.protected voidsetHistory(java.util.List<HistoryEvent> history)Clear the history events.voidsetImmigration(int immigration)Sets the amount of immigration this player possess.voidsetImmigrationRequired(int immigrationRequired)Sets the number of immigration required to cause a new colonist to emigrate.voidsetIndependentNationName(java.lang.String newIndependentNationName)Set the post-declaration player name.protected voidsetLastSales(java.util.Map<java.lang.String,LastSale> lastSales)Set the last sales events.voidsetLiberty(int liberty)Sets the current amount of liberty this player has.protected voidsetModelMessages(java.util.List<ModelMessage> modelMessages)Set the model message list.voidsetMonarch(Monarch monarch)Sets the monarch object this player has.voidsetName(java.lang.String newName)Set the player name.voidsetNation(Nation newNation)Sets the nation for this player.voidsetNationType(NationType newNationType)Sets the nation type of this player.voidsetNewLandName(java.lang.String newLandName)Sets the name this player uses for the new world.booleansetNextGoingToUnit(Unit unit)Sets a new going-to unit.voidsetOfferedFathers(java.util.List<FoundingFather> fathers)Sets the set of offered fathers.private voidsetPlayerType(Player.PlayerType type)Sets the player type.voidsetReady(boolean ready)Sets this players readiness state.voidsetScore(int score)Set the current score of the player.booleansetStance(Player player, Stance newStance)Sets the stance towards a given player.protected voidsetStances(java.util.Map<java.lang.String,Stance> stances)Set the stance map.voidsetTax(int amount)Sets the current taxprotected voidsetTension(java.util.Map<Player,Tension> tension)Set the tension map.voidsetTension(Player player, Tension newTension)Sets the tension with respect to a given player.static doublestrengthRatio(double ours, double theirs)Abstraction of the strength ratio calculation.java.lang.StringtoString()voidupdateImmigrationRequired()Updates the amount of immigration needed to emigrate aUnitfromEurope.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(FreeColXMLWriter xw)Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeResources, 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 newPlayerwith the given id. The object should be initialized later.- Parameters:
game- TheGamethis 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
StringTemplatefor 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- TheRegionto 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- TheUnitTypeto 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- TheChangeSetto 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- ThePlayerto 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- ThePlayerto 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
NationTypeof 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
Playeris 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. APlayerdies when it loses the game.- Returns:
- True if this
Playeris 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
Playeris 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 thePlayercontrolling the "Royal Expeditionary Force" for this player.- Returns:
- The player, or
nullif 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 aUnitfromEurope.
-
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- TheUnitthat 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'sColonys will make next turn.
-
getOldSoL
protected int getOldSoL()
Get the old SoL.- Returns:
- The SoL amount from the previous turn.
-
getSoL
public int getSoL()
Gets the total percentage of rebels in all this player's colonies.- Returns:
- The total percentage of rebels in all this player's colonies.
-
getInterventionBells
protected int getInterventionBells()
Get the bells for intervention.- Returns:
- The intervention bell amount.
-
getFoundingFathers
public java.util.Set<FoundingFather> getFoundingFathers()
Gets the founding fathers in this player's congress.- Returns:
- A set of
FoundingFathers in congress.
-
setFoundingFathers
protected void setFoundingFathers(java.util.Set<FoundingFather> foundingFathers)
Gets the founding fathers in this player's congress.- Parameters:
foundingFathers- A set ofFoundingFathers in congress.
-
hasFather
public boolean hasFather(FoundingFather someFather)
Does this player have a certain Founding father.- Parameters:
someFather- TheFoundingFatherto 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- TheFoundingFatherto add.
-
getCurrentFather
public FoundingFather getCurrentFather()
Gets thefounding fatherthis 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- TheFoundingFatherto recruit.- See Also:
FoundingFather
-
getOfferedFathers
public java.util.List<FoundingFather> getOfferedFathers()
Gets the offered fathers for this player.- Returns:
- A list of the current offered
FoundingFathers.
-
clearOfferedFathers
public void clearOfferedFathers()
Clear the set of offered fathers.
-
setOfferedFathers
public void setOfferedFathers(java.util.List<FoundingFather> fathers)
Sets the set of offered fathers.- Parameters:
fathers- A list ofFoundingFathers 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
Playerneeds 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
Playerneeds to recruit the nextFoundingFather.
-
getElectionTurns
public java.util.Map<java.lang.String,Turn> getElectionTurns()
Gets theTurns during which FoundingFathers were elected to the Continental Congress- Returns:
- A map of father id to
Turns.
-
checkDeclareIndependence
public StringTemplate checkDeclareIndependence()
Check whether this player can declare independence.- Returns:
- Null if there is no barrier to declaration, otherwise
a
StringTemplateexplaining the problem.
-
calculateStrength
public int calculateStrength(boolean naval)
Generic strength calculation.- Parameters:
naval- If true consider naval units, otherwise land units.- Returns:
- A measure of naval or land offensive power.
-
getRebelStrengthRatio
public double getRebelStrengthRatio(boolean naval)
Get the strength ratio of this player with respect to its REF.- Parameters:
naval- If true consider naval units, otherwise land units.- Returns:
- A measure of the military viability of this player.
-
getREFUnits
public java.util.List<AbstractUnit> getREFUnits()
Get a list of abstract REF units for this player.- Returns:
- A list of
AbstractUnits defining the REF, or null if not available.
-
getMilitaryUnits
public java.util.List<AbstractUnit> getMilitaryUnits()
Get a list of the military units for this player.- Returns:
- A list of military
AbstractUnits.
-
getTax
public int getTax()
Get the current tax.- Returns:
- The current tax.
-
setTax
public void setTax(int amount)
Sets the current tax- Parameters:
amount- The new tax amount.
-
getMarket
public Market getMarket()
Get this player's Market. Beware, this *can* be null in special cases such as when spying on another player's settlement.- Returns:
- The
Market.
-
reinitialiseMarket
public void reinitialiseMarket()
Resets this player's Market.
-
getLastSales
protected java.util.Map<java.lang.String,LastSale> getLastSales()
Get the last sales events.- Returns:
- The
LastSales list.
-
setLastSales
protected void setLastSales(java.util.Map<java.lang.String,LastSale> lastSales)
Set the last sales events.- Parameters:
lastSales- The new list ofLastSales.
-
getLastSale
public LastSale getLastSale(Location where, GoodsType what)
Gets the current sales data for a location and goods type.- Parameters:
where- TheLocationof the sale.what- TheGoodsTypesold.- Returns:
- An appropriate
LastSaleDatarecord, or null if no appropriate sale can be found.
-
addLastSale
public void addLastSale(LastSale sale)
Saves a record of a sale.- Parameters:
sale- TheLastSaleto 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- TheLocationof the sale.what- TheGoodsTypesold.- 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- TheLocationof the sale.what- TheGoodsTypesold.- Returns:
- A
StringTemplatefor the sale, or null if none found.
-
getArrears
public int getArrears(GoodsType type)
Gets the arrears due for a type of goods.- Parameters:
type- TheGoodsTypeto 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- TheGoodsTypeto 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- TheGoodsTypeto 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- TheGoodsTypeto query.- Returns:
- The current sales.
-
modifySales
public void modifySales(GoodsType goodsType, int amount)
Modifies the current sales.- Parameters:
goodsType- TheGoodsTypeto modify.amount- The new sales.
-
hasTraded
public boolean hasTraded(GoodsType goodsType)
Has a type of goods been traded?- Parameters:
goodsType- TheGoodsTypeto 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- TheGoodsTypeto query.- Returns:
- The current incomeBeforeTaxes.
-
modifyIncomeBeforeTaxes
public void modifyIncomeBeforeTaxes(GoodsType goodsType, int amount)
Modifies the current incomeBeforeTaxes.- Parameters:
goodsType- TheGoodsTypeto modify.amount- The new incomeBeforeTaxes.
-
getIncomeAfterTaxes
public int getIncomeAfterTaxes(GoodsType goodsType)
Get the current incomeAfterTaxes.- Parameters:
goodsType- TheGoodsTypeto query.- Returns:
- The current incomeAfterTaxes.
-
modifyIncomeAfterTaxes
public void modifyIncomeAfterTaxes(GoodsType goodsType, int amount)
Modifies the current incomeAfterTaxes.- Parameters:
goodsType- TheGoodsTypeto 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 newEuropeobject.
-
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
Monarchobject 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 newMonarchobject.
-
hasUnit
public boolean hasUnit(Unit unit)
Does this player's units list contain the given unit?- Parameters:
unit- TheUnitto test.- Returns:
- True if the player has the unit.
-
getUnits
public java.util.stream.Stream<Unit> getUnits()
Get a stream of the players units. Have to serialize the copy created by getUnitList, otherwise concurrent modification exceptions show up.- Returns:
- A stream of the player
Units.
-
getUnitSet
public java.util.Set<Unit> getUnitSet()
Get a copy of the players units.- Returns:
- A set of the player
Units.
-
getUnitCount
public int getUnitCount()
Get the number of units a player has.- Returns:
- The number of units.
-
getUnitByName
public Unit getUnitByName(java.lang.String name)
Get a player unit by name.- Parameters:
name- The name of the unit.- Returns:
- The unit with the given name, or null if none found.
-
addUnit
public final boolean addUnit(Unit newUnit)
Add a unit to this player.- Parameters:
newUnit- The newUnitvalue.- Returns:
- True if the units container changed.
-
removeUnit
public boolean removeUnit(Unit oldUnit)
Remove a unit from this player.- Parameters:
oldUnit- TheUnitto 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- TheUnitto 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
Unitthat 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
Unitthat can be made active.
-
setNextGoingToUnit
public boolean setNextGoingToUnit(Unit unit)
Sets a new going-to unit.- Parameters:
unit- AUnitto make the next one to be active.- Returns:
- True if the operation succeeded.
-
hasNextGoingToUnit
public boolean hasNextGoingToUnit()
Checks if there is a unit that has a destination.- Returns:
- True if there is a unit with a destination.
-
resetIterators
public void resetIterators()
Reset the player iterators ready for a new turn.
-
getTradeRoutes
public final java.util.List<TradeRoute> getTradeRoutes()
Get the trade routes defined for this player.- Returns:
- A copy of the list of
TradeRoutes for this player.
-
getTradeRouteCount
public final int getTradeRouteCount()
Get number of trade routes defined for this player.- Returns:
- The trade route count.
-
getNewestTradeRoute
public final TradeRoute getNewestTradeRoute()
Get the most recently defined trade route. Relies on trade routes *always* being added at the end of the list.- Returns:
- The most recently defined
TradeRoute.
-
addTradeRoute
public final void addTradeRoute(TradeRoute tradeRoute)
Add a new trade route.- Parameters:
tradeRoute- TheTradeRouteto 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 optionalTradeRouteto exclude.- Returns:
- The
TradeRoutefound.
-
removeTradeRoute
public final java.util.List<Unit> removeTradeRoute(TradeRoute tradeRoute)
Remove a trade route.- Parameters:
tradeRoute- TheTradeRouteto 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- TheOwnableto 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- TheOwnableto 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
Settlementsthis player owns.
-
getSettlements
public java.util.stream.Stream<Settlement> getSettlements()
Get a stream of the settlements this player owns.- Returns:
- The strean of
Settlementsthis player owns.
-
hasSettlements
public boolean hasSettlements()
Does this player have any settlements at present.- Returns:
- True if this player has settlements.
-
getSettlementCount
public int getSettlementCount()
Get the count of settlements.- Returns:
- The number of settlements this player has.
-
getNumberOfPorts
public int getNumberOfPorts()
Get the number of port settlements.- Returns:
- The number of port settlements this player has.
-
getConnectedPortList
public java.util.List<Colony> getConnectedPortList()
Get the connected port settlements.- Returns:
- A list of connected port
Colonys.
-
getConnectedPorts
public java.util.stream.Stream<Colony> getConnectedPorts()
Get a stream of the connected port settlements.- Returns:
- A stream of connected port
Colonys.
-
hasSettlement
public boolean hasSettlement(Settlement settlement)
Does this player own a given settlement.- Parameters:
settlement- TheSettlementto check.- Returns:
- True if this
Playerowns 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- TheSettlementto 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- TheSettlementto 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 theColonywith the given name.- Parameters:
name- The name of theColony.- Returns:
- The
Colonywith the given name, or null if not found.
-
getIndianSettlementByName
public IndianSettlement getIndianSettlementByName(java.lang.String name)
Gets theIndianSettlementwith the given name.- Parameters:
name- The name of theIndianSettlement.- Returns:
- The
IndianSettlementwith the given name, or null if not found.
-
getColonies
public java.util.stream.Stream<Colony> getColonies()
Get a stream of all colonies this player owns.- Returns:
- A stream of the
Colonys this player owns.
-
getColonyList
public java.util.List<Colony> getColonyList()
Get a fresh list of all colonies this player owns.- Returns:
- A list of the
Colonys this player owns.
-
getSortedColonies
public java.util.List<Colony> getSortedColonies(java.util.Comparator<Colony> comp)
Get a sorted list of all colonies this player owns.- Parameters:
comp- AComparatorto operate on the colony list.- Returns:
- A fresh list of the
Colonys this player owns.
-
getIndianSettlements
public java.util.stream.Stream<IndianSettlement> getIndianSettlements()
Get a stream of all the indian settlements this player owns.- Returns:
- A stream of the
IndianSettlements this player owns.
-
getIndianSettlementList
public java.util.List<IndianSettlement> getIndianSettlementList()
Get a list of all the IndianSettlements this player owns.- Returns:
- A list of the
IndianSettlements this player owns.
-
getIndianSettlementsWithMissionaryList
public java.util.List<IndianSettlement> getIndianSettlementsWithMissionaryList(Player p)
Get a list of all indian settlements owned by this player with a missionary from a given player.- Parameters:
p- ThePlayer.- Returns:
- A list of the
IndianSettlements with a matching missionary.
-
getIndianSettlementsWithMissionary
public java.util.stream.Stream<IndianSettlement> getIndianSettlementsWithMissionary(Player p)
Get a stream of all indian settlements owned by this player with a missionary from a given player.- Parameters:
p- ThePlayer.- Returns:
- A stream of the
IndianSettlements with a matching missionary.
-
getSettlementByName
public Settlement getSettlementByName(java.lang.String name)
Find aSettlementby name.- Parameters:
name- The name of theSettlement.- Returns:
- The
Settlement, ornullif not found.
-
getClosestPortForEurope
public Settlement getClosestPortForEurope()
Gets the port closest to Europe owned by this player.- Returns:
- This players closest port.
-
getModelMessages
public java.util.List<ModelMessage> getModelMessages()
Gets all the model messages for this player.- Returns:
- A copy of the
ModelMessages for thisPlayer.
-
getNewModelMessages
public java.util.List<ModelMessage> getNewModelMessages()
Gets all new messages for this player.- Returns:
- all The new
ModelMessages for thisPlayer.
-
addModelMessage
public void addModelMessage(ModelMessage modelMessage)
Adds a message for this player.- Parameters:
modelMessage- TheModelMessageto add.
-
refilterModelMessages
public void refilterModelMessages(OptionGroup options)
Refilters the current model messages, removing the ones that are no longer valid.- Parameters:
options- TheOptionGroupfor 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
HistoryEvents for this player.
-
addHistory
public void addHistory(HistoryEvent event)
Add a history event to this player.- Parameters:
event- TheHistoryEventto 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 newHistoryEvents.
-
getEntryTile
public Tile getEntryTile()
Gets the default initial location where the units arriving fromEuropeappear on the map.- Returns:
- The entry
Tile.
-
setEntryTile
public void setEntryTile(Tile entryTile)
Sets the default initial location where the units arriving fromEuropeappear 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
HighSeasfor 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- TheTileto check.- Returns:
- True if the
Tilehas been explored.
-
invalidateCanSeeTiles
public void invalidateCanSeeTiles()
Forces an update of thecanSeeTiles. This method should be used to invalidate the currentcanSeeTileswhen 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- TheTileto 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- TheUnitto check.- Returns:
- True if the
Unitis visible to the player.
-
getVisibleTileSet
public java.util.Set<Tile> getVisibleTileSet()
Get the set of tiles visible to this player.- Returns:
- A set of visible
Tiles.
-
makeCanSeeTiles
private boolean[][] makeCanSeeTiles(Map map)
Builds a canSeeTiles array.- Parameters:
map- TheMapto 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- ThePlayerto 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 otherPlayerto 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- ThePlayerto ban.
-
removeMissionBan
public void removeMissionBan(Player player)
Remove a mission ban from a player.- Parameters:
player- ThePlayerto 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 otherPlayerto check.- Returns:
- The stance.
-
setStance
public boolean setStance(Player player, Stance newStance)
Sets the stance towards a given player.- Parameters:
player- ThePlayerto set theStancefor.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 otherPlayerto 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 otherPlayerto check.- Returns:
- True if this
Playerhas contacted the other.
-
hasContactedEuropeans
public boolean hasContactedEuropeans()
Has this player has met with any Europeans at all?- Returns:
- True if this
Playerhas contacted any Europeans.
-
hasContactedIndians
public boolean hasContactedIndians()
Has this player met any natives at all?- Returns:
- True if this
Playerhas 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- OnePlayerto check.player2- The otherPlayerto check.
-
getLandPrice
public int getLandPrice(Tile tile)
Gets the price of the given land.- Parameters:
tile- TheTileto 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- ThePlayerto get the summary for.- Returns:
- The current
NationSummaryfor a player.
-
putNationSummary
public void putNationSummary(Player player, NationSummary ns)
Update the nation cache.- Parameters:
player- ThePlayerto get the summary for.ns- The newNationSummaryfor the player.
-
clearNationSummary
public void clearNationSummary(Player player)
Clear the nation cache entry for a player.- Parameters:
player- ThePlayerto 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- TheTileto 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- TheTileto 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- TheTileto 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- TheTileto 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- TheTileto 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- TheTileto 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- TheTileto 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- TheTileto 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- TheTileto 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 aColonyon 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 aColonyon 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- TheOwnableto check.- Returns:
- True if the
Ownableis ours.
-
getOurFreeColGameObject
public <T extends FreeColGameObject> T getOurFreeColGameObject(java.lang.String id, java.lang.Class<T> returnClass)
Get aFreeColGameObjectwith 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:
checkIntegrityin classFreeColGameObject- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto log to.- Returns:
- A suitable
IntegrityType.
-
getFeatureContainer
public final FeatureContainer getFeatureContainer()
Gets the feature container for this object, if any.- Overrides:
getFeatureContainerin classFreeColObject- Returns:
- The
FeatureContainerfor this object.
-
getClassIndex
public int getClassIndex()
Accessor for the class index.- Overrides:
getClassIndexin 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:
copyInin classFreeColGameObject- Type Parameters:
T- TheFreeColObjectsubclass of the object to copy in.- Parameters:
other- The other object.- Returns:
- True if the copy in is succesful.
-
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:
getDisplayObjectin classFreeColObject- Returns:
- A suitable
FreeColObjectto 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:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildrenin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributesin classFreeColGameObject- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildrenin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
readChild
protected void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChildin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
-