Package net.sf.freecol.common.model
Class IndianSettlement
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Location
,Nameable
,Ownable
,TradeLocation
,ObjectWithId
- Direct Known Subclasses:
ServerIndianSettlement
public class IndianSettlement extends Settlement implements TradeLocation
Represents an Indian settlement.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IndianSettlement.ContactLevel
The level of contact between a player and this settlement.-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<Player,Tension>
alarm
Stores the alarm levels.private static java.lang.String
ALARM_TAG
private static java.lang.String
CONTACT_LEVEL_TAG
protected java.util.Map<Player,IndianSettlement.ContactLevel>
contactLevels
A map that tells if a player has spoken to the chief of this settlement.private static java.lang.String
CONVERT_PROGRESS_TAG
protected int
convertProgress
Used for monitoring the progress towards creating a convert.private java.util.List<Goods>
forSale
Cache of goods offered for sale.static int
GIFT_MAXIMUM
The maximum gift amount.static int
GIFT_MINIMUM
The minimum gift amount.static int
GIFT_THRESHOLD
Generate gifts from goods that exceed KEEP_RAW_MATERIAL + GIFT_THRESHOLD.static int
GOODS_BASE_PRICE
static int
KEEP_RAW_MATERIAL
The amount of raw material that should be available before producing manufactured goods.private static java.lang.String
LAST_TRIBUTE_TAG
protected int
lastTribute
The number of the turn during which the last tribute was paid.static java.lang.String
LEARNABLE_SKILL_TAG
protected UnitType
learnableSkill
This is the skill that can be learned by Europeans at this settlement.private static java.lang.String
LEVEL_TAG
private static java.util.logging.Logger
logger
protected Unit
missionary
The missionary at this settlement.private static java.lang.String
MISSIONARY_TAG
private static java.lang.String
MOST_HATED_TAG
protected Player
mostHated
The most hated nation.private static java.lang.String
NAME_TAG
static double
NATIVE_PRODUCTION_EFFICIENCY
The production fudge factor.private static java.lang.String
OWNED_UNITS_TAG
protected java.util.List<Unit>
ownedUnits
Units that belong to this settlement.private static java.lang.String
PLAYER_TAG
static java.lang.String
TAG
static int
TALES_RADIUS
Radius of native tales map reveal.static int
TRADE_MINIMUM_PRICE
Do not buy goods when the price is this low.static int
TRADE_MINIMUM_SIZE
Do not sell less than this amount of goods.static int
WANTED_GOODS_COUNT
The maximum number of wanted goods.static java.lang.String
WANTED_GOODS_TAG
protected java.util.List<GoodsType>
wantedGoods
The goods this settlement wants.-
Fields inherited from class net.sf.freecol.common.model.Settlement
FOOD_PER_COLONIST, owner, tile
-
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
-
Fields inherited from interface net.sf.freecol.common.model.Location
LOCATION_RANK_EUROPE, LOCATION_RANK_HIGHSEAS, LOCATION_RANK_NOWHERE
-
-
Constructor Summary
Constructors Modifier Constructor Description IndianSettlement(Game game, java.lang.String id)
Creates a newIndianSettlement
with the given identifier.protected
IndianSettlement(Game game, Player owner, java.lang.String name, Tile tile)
Constructor for ServerIndianSettlement.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Locatable locatable)
Adds aLocatable
to this Location.void
addOwnedUnit(Unit unit)
Adds the givenUnit
to the list of units that belongs to thisIndianSettlement
.void
addRandomGoods(java.util.Random random)
Add some initial goods to a newly generated settlement.boolean
allowContact(Unit unit)
Is a unit permitted to make contact with this settlement? The unit must be from a nation that has already made contact, or in the first instance, must be arriving by land, with the exception of trading ships.int
calculateSettlementValue(int value, Unit unit)
Determines the value of a potential attack on aIndianSettlement
Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.private void
clearAlarm()
Clear the alarm levels.private void
clearContactLevels()
Clear the contact levels.private void
clearOwnedUnits()
Clear the owned units.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.void
disposeResources()
Dispose of the resources of this object, and finally remove it from the game.private static java.util.List<GoodsType>
emptyWantedGoods()
Create an empty wanted goods list.protected java.util.Map<Player,Tension>
getAlarm()
Get the alarm map.Tension
getAlarm(Player player)
Gets the alarm level towards the given player.java.lang.String
getAlarmLevelKey(Player player)
Gets a message key for a short alarm message associated with the alarm level of this player.StringTemplate
getAlarmLevelLabel(Player player)
Gets a label indicating the alarm level at this settlement with respect to another player.int
getAvailableGoodsCount(GoodsType goodsType)
Get the amount of a given goods type at this trade location.IndianSettlement.ContactLevel
getContactLevel(Player player)
Gets the contact level between this settlement and a player.int
getConvertProgress()
Gets the convert progress status for this settlement.double
getDefenceRatio()
Get the ratio between defence at this settlement, and the general settlement size.Unit
getDefendingUnit(Unit attacker)
Gets theUnit
that is currently defending thisSettlement
.int
getExportAmount(GoodsType goodsType, int turns)
Gets the amount of a given goods type that can be exported from this trade location after a given number of turns.int
getGoodsCapacity()
Gets the maximum number ofGoods
this Location can hold.java.util.List<Goods>
getGoodsForSale()
Get the current goods offered for sale.int
getImportAmount(GoodsType goodsType, int turns)
Gets the amount of a given goods type that can be imported to this trade location after a given number of turns.IndianSettlement
getIndianSettlement()
Gets the native settlement at this location.int
getLastTribute()
Get the year of the last tribute.UnitType
getLearnableSkill()
Gets the skill that can be learned at this settlement.StringTemplate
getLearnableSkillLabel(boolean visited)
Get a label appropriate to the current learnable skill and whether the requestor has visited this settlement.StringTemplate
getLocationLabelFor(Player player)
Get a label for this location for a particular player.java.lang.String
getLocationName(TradeLocation tradeLocation)
Function for returning the name of a TradeLocationint
getMaximumProduction(GoodsType goodsType)
Gets the maximum possible production of the given type of goods.private int
getMilitaryGoodsPriceToBuy(GoodsType type, int amount)
Price some goods that have military value to the settlement.Unit
getMissionary()
Gets the missionary from this settlement.int
getMissionaryLineOfSight()
Get the line of sight used by a missionary at this settlement.java.util.List<Tile>
getMissionaryVisibleTiles()
Get a stream of tiles that should be visible to a missionary at this settlement.Player
getMostHated()
Gets the most hated nation of this settlement.StringTemplate
getMostHatedLabel(boolean contacted)
Get a template for the current most hated nation, depending whether the requestor has contacted this settlement.private int
getNormalGoodsPriceToBuy(GoodsType type, int amount)
Price some goods according to the amount present in the settlement.java.util.List<Unit>
getOwnedUnitList()
Gets a list of the units native to this settlement.RandomRange
getPlunderRange(Unit attacker)
Gets the range of gold plunderable when this settlement is captured.int
getPriceToBuy(GoodsType type, int amount)
Gets the amount of gold thisIndianSettlment
is willing to pay for the givenGoods
.<T extends AbstractGoods>
intgetPriceToBuy(T goods)
Gets the amount of gold thisIndianSettlment
is willing to pay for the givenGoods
.int
getPriceToSell(GoodsType type, int amount)
Gets the amount of gold thisIndianSettlment
is willing to sell the givenGoods
for.<T extends AbstractGoods>
intgetPriceToSell(T goods)
Gets the amount of gold thisIndianSettlment
is willing to sell the givenGoods
for.Goods
getRandomGift(java.util.Random random)
Gets a random goods gift from this settlement.int
getRequiredDefenders()
Get the number of braves expected to be present for the settlement not to be "badly defended".java.util.List<Goods>
getSellGoods(Unit unit)
Gets the goods this settlement is willing to sell.int
getSoL()
Gets the current Sons of Liberty in this settlement.int
getTotalProductionOf(GoodsType type)
Gets the total production of the given type of goods in this settlement.int
getUpkeep()
Get the amount of gold necessary to maintain all of the settlement's buildings.java.util.List<GoodsType>
getWantedGoods()
Gets the goods wanted by this settlement.GoodsType
getWantedGoods(int index)
Gets one of the goods wanted by this settlement.protected int
getWantedGoodsAmount(GoodsType type)
Calculates how much of the given goods type this settlement wants and should retain.int
getWantedGoodsCount()
Get the number of wanted goods.java.util.List<StringTemplate>
getWantedGoodsLabel(int index, Player player)
Get a label for one of the wanted goods.java.lang.String
getXMLTagName()
Get the serialization tag for this object.private GoodsType
goodsToMake()
Chooses a type of goods for some of the natives in a settlement to manufacture.boolean
hasAnyScouted()
Has any European player spoken with the chief of this settlement.boolean
hasContacted(Player player)
Has this settlement contacted a given player? Allow player == null as this is true in the map editor where the user player is moot.boolean
hasMissionary()
Does this settlement have a missionary?boolean
hasMissionary(Player player)
Does this settlement have a missionary from the given player?boolean
hasScouted(Player player)
Has a player has spoken with the chief of this settlement.boolean
hasVisited(Player player)
Has a player visited this settlement?protected void
initializeAlarm(Player player)
Initialize the alarm at this settlement with respect to a player with the current national tension.void
invalidateCache()
Invalidate any cache dependent on the goods levels.boolean
isBadlyDefended()
Is this settlement insufficiently defended?protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.boolean
removeOwnedUnit(Unit unit)
Removes the givenUnit
to the list of units that belongs to thisIndianSettlement
.protected void
setAlarm(java.util.Map<Player,Tension> alarm)
Set the alarm map.void
setAlarm(Player player, Tension newAlarm)
Sets alarm towards the given player.boolean
setContacted(Player player)
Make contact with this settlement (if it has not been previously contacted).private void
setContactLevel(Player player, IndianSettlement.ContactLevel level)
Sets a contact level between this settlement and a player.protected void
setContactLevels(java.util.Map<Player,IndianSettlement.ContactLevel> contactLevels)
Set the contact levels.void
setConvertProgress(int progress)
Sets the convert progress status for this settlement.void
setGoodsForSale(java.util.List<Goods> forSale)
Set the current goods offered for sale.void
setLastTribute(int lastTribute)
Set the year of the last tribute.void
setLearnableSkill(UnitType skill)
Sets the learnable skill for this Indian settlement.void
setMissionary(Unit missionary)
Sets the missionary for this settlement.void
setMostHated(Player mostHated)
Sets the most hated nation of this settlement.protected void
setOwnedUnitList(java.util.List<Unit> ownedUnits)
Set the owned units list.boolean
setScouted(Player player)
Sets the contact level of this settlement to indicate that a European player has had a chat with the chief.boolean
setVisited(Player player)
Sets the contact level of this settlement to indicate that a European player has visited the settlement.void
setWantedGoods(int index, GoodsType type)
Sets the goods wanted by this settlement.void
setWantedGoods(java.util.List<GoodsType> wanted)
Sets the goods wanted by this Settlement.java.lang.String
toShortString()
Get a short description of this location.java.lang.String
toString()
void
tradeGoodsWithSettlement(IndianSettlement is)
Allows spread of horses and arms between settlementsLocation
up()
Promote this location to a more meaningful one if possible.void
updateWantedGoods()
Updates the goods wanted by this settlement.private boolean
validWantedGoodsIndex(int index)
Is a given index with the range of normal wanted goods.boolean
willSell(GoodsType type)
Will this settlement sell a type of goods.boolean
worthScouting(Player player)
Is this settlement worth scouting? That is, has it been contacted, but not scouted already, or visited when the "Chief contact" option is set.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.Settlement
addTile, canBombardEnemyShip, canImproveUnitMilitaryRole, canProvideGoods, changeOwner, equipForRole, exciseSettlement, getAllUnitsList, getConsumptionOf, getConsumptionOf, getFeatureContainer, getFoodConsumption, getHighSeasCount, getImmigration, getLiberty, getLineOfSight, getLinkTarget, getLocationImageKey, getLocationLabel, getName, getNoAddReason, getOwnedTiles, getOwner, getPlunder, getRadius, getRank, getSettlement, getTile, getType, getVisibleTileSet, getWarehouseCapacity, isCapital, isConnectedPort, isLandLocked, placeSettlement, priceGoods, removeTile, setCapital, setName, setOwnedTiles, setOwner, setType
-
Methods inherited from class net.sf.freecol.common.model.GoodsLocation
addGoods, addGoods, addGoods, contains, containsGoods, getCompactGoodsList, getDisposables, getGoodsContainer, getGoodsCount, getGoodsList, moveGoods, remove, removeAll, removeGoods, removeGoods, removeGoods, setGoodsContainer
-
Methods inherited from class net.sf.freecol.common.model.UnitLocation
canAdd, clearUnitList, getCarrierForUnit, getColony, getFirstUnit, getLastUnit, getNavalUnits, getSpaceTaken, getTotalUnitCount, getUnitCapacity, getUnitCount, getUnitList, getUnits, hasCarrierWithSpace, intern, isEmpty, isFull, moveToFront
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, equals, fundamentalDispose, getClassIndex, getGame, getSpecification, hashCode, 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, getDisplayObject, 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
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.freecol.common.model.TradeLocation
canBeInput, getNameAsJlabel
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
NATIVE_PRODUCTION_EFFICIENCY
public static final double NATIVE_PRODUCTION_EFFICIENCY
The production fudge factor.- See Also:
- Constant Field Values
-
WANTED_GOODS_COUNT
public static final int WANTED_GOODS_COUNT
The maximum number of wanted goods.- See Also:
- Constant Field Values
-
TALES_RADIUS
public static final int TALES_RADIUS
Radius of native tales map reveal.- See Also:
- Constant Field Values
-
TRADE_MINIMUM_SIZE
public static final int TRADE_MINIMUM_SIZE
Do not sell less than this amount of goods.- See Also:
- Constant Field Values
-
TRADE_MINIMUM_PRICE
public static final int TRADE_MINIMUM_PRICE
Do not buy goods when the price is this low.- See Also:
- Constant Field Values
-
GOODS_BASE_PRICE
public static final int GOODS_BASE_PRICE
- See Also:
- Constant Field Values
-
KEEP_RAW_MATERIAL
public static final int KEEP_RAW_MATERIAL
The amount of raw material that should be available before producing manufactured goods.- See Also:
- Constant Field Values
-
GIFT_THRESHOLD
public static final int GIFT_THRESHOLD
Generate gifts from goods that exceed KEEP_RAW_MATERIAL + GIFT_THRESHOLD.- See Also:
- Constant Field Values
-
GIFT_MINIMUM
public static final int GIFT_MINIMUM
The minimum gift amount.- See Also:
- Constant Field Values
-
GIFT_MAXIMUM
public static final int GIFT_MAXIMUM
The maximum gift amount.- See Also:
- Constant Field Values
-
learnableSkill
protected UnitType learnableSkill
This is the skill that can be learned by Europeans at this settlement. At the server side its value will be null when the skill has already been taught to a European. At the client side the value null is also possible in case the player hasn't checked out the settlement yet.
-
wantedGoods
protected final java.util.List<GoodsType> wantedGoods
The goods this settlement wants.
-
contactLevels
protected final java.util.Map<Player,IndianSettlement.ContactLevel> contactLevels
A map that tells if a player has spoken to the chief of this settlement. At the client side, only the information regarding the player on that client should be included.
-
ownedUnits
protected final java.util.List<Unit> ownedUnits
Units that belong to this settlement.
-
missionary
protected Unit missionary
The missionary at this settlement.
-
convertProgress
protected int convertProgress
Used for monitoring the progress towards creating a convert.
-
lastTribute
protected int lastTribute
The number of the turn during which the last tribute was paid.
-
mostHated
protected Player mostHated
The most hated nation.
-
alarm
protected final java.util.Map<Player,Tension> alarm
Stores the alarm levels. Only used by AI. "Alarm" means: Tension with respect to a player from an IndianSettlement. Alarm is overloaded with the concept of "contact". If a settlement has never been contacted by a player, alarm.get(player) will be null. Acts causing contact initialize this variable.
-
forSale
private final java.util.List<Goods> forSale
Cache of goods offered for sale. Do not serialize.
-
ALARM_TAG
private static final java.lang.String ALARM_TAG
- See Also:
- Constant Field Values
-
CONTACT_LEVEL_TAG
private static final java.lang.String CONTACT_LEVEL_TAG
- See Also:
- Constant Field Values
-
CONVERT_PROGRESS_TAG
private static final java.lang.String CONVERT_PROGRESS_TAG
- See Also:
- Constant Field Values
-
LAST_TRIBUTE_TAG
private static final java.lang.String LAST_TRIBUTE_TAG
- See Also:
- Constant Field Values
-
LEVEL_TAG
private static final java.lang.String LEVEL_TAG
- See Also:
- Constant Field Values
-
MISSIONARY_TAG
private static final java.lang.String MISSIONARY_TAG
- See Also:
- Constant Field Values
-
MOST_HATED_TAG
private static final java.lang.String MOST_HATED_TAG
- See Also:
- Constant Field Values
-
NAME_TAG
private static final java.lang.String NAME_TAG
- See Also:
- Constant Field Values
-
OWNED_UNITS_TAG
private static final java.lang.String OWNED_UNITS_TAG
- See Also:
- Constant Field Values
-
PLAYER_TAG
private static final java.lang.String PLAYER_TAG
- See Also:
- Constant Field Values
-
LEARNABLE_SKILL_TAG
public static final java.lang.String LEARNABLE_SKILL_TAG
- See Also:
- Constant Field Values
-
WANTED_GOODS_TAG
public static final java.lang.String WANTED_GOODS_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IndianSettlement
protected IndianSettlement(Game game, Player owner, java.lang.String name, Tile tile)
Constructor for ServerIndianSettlement.- Parameters:
game
- The enclosingGame
.owner
- ThePlayer
owning this settlement.name
- The name for this settlement.tile
- The containingTile
.
-
IndianSettlement
public IndianSettlement(Game game, java.lang.String id)
Creates a newIndianSettlement
with the given identifier. The object should later be initialized by calling eitherFreeColGameObject.readFromXML(FreeColXMLReader)
.- Parameters:
game
- TheGame
in which this object belong.id
- The object identifier.
-
-
Method Detail
-
emptyWantedGoods
private static java.util.List<GoodsType> emptyWantedGoods()
Create an empty wanted goods list.- Returns:
- A list of null wanted goods.
-
getOwnedUnitList
public java.util.List<Unit> getOwnedUnitList()
Gets a list of the units native to this settlement.- Returns:
- The list of units native to this settlement.
-
setOwnedUnitList
protected void setOwnedUnitList(java.util.List<Unit> ownedUnits)
Set the owned units list.- Parameters:
ownedUnits
- The new ownedUnit
list.
-
addOwnedUnit
public void addOwnedUnit(Unit unit)
Adds the givenUnit
to the list of units that belongs to thisIndianSettlement
.- Parameters:
unit
- TheUnit
to be added.
-
clearOwnedUnits
private void clearOwnedUnits()
Clear the owned units.
-
removeOwnedUnit
public boolean removeOwnedUnit(Unit unit)
Removes the givenUnit
to the list of units that belongs to thisIndianSettlement
. Returns true if the Unit was removed.- Parameters:
unit
- TheUnit
to be removed from the list of the units thisIndianSettlement
owns.- Returns:
- a
boolean
value
-
getLastTribute
public int getLastTribute()
Get the year of the last tribute.- Returns:
- The year of the last tribute.
-
setLastTribute
public void setLastTribute(int lastTribute)
Set the year of the last tribute.- Parameters:
lastTribute
- The new last tribute year.
-
getLearnableSkill
public UnitType getLearnableSkill()
Gets the skill that can be learned at this settlement.- Returns:
- The skill that can be learned at this settlement.
-
setLearnableSkill
public void setLearnableSkill(UnitType skill)
Sets the learnable skill for this Indian settlement.- Parameters:
skill
- The new learnable skill for this Indian settlement.
-
getLearnableSkillLabel
public StringTemplate getLearnableSkillLabel(boolean visited)
Get a label appropriate to the current learnable skill and whether the requestor has visited this settlement.- Parameters:
visited
- The visiting status.- Returns:
- A
StringTemplate
describing the perceived skill.
-
getMissionary
public Unit getMissionary()
Gets the missionary from this settlement.- Returns:
- The missionary at this settlement, or null if there is none.
-
hasMissionary
public boolean hasMissionary()
Does this settlement have a missionary?- Returns:
- True if there is a missionary at this settlement.
-
hasMissionary
public boolean hasMissionary(Player player)
Does this settlement have a missionary from the given player?- Parameters:
player
- ThePlayer
to test.- Returns:
- True if there is a suitable missionary present.
-
setMissionary
public void setMissionary(Unit missionary)
Sets the missionary for this settlement. -vis: This routine has visibility implications when enhanced missionaries are enabled. -til: This changes the tile appearance.- Parameters:
missionary
- The missionary for this settlement.
-
getMissionaryLineOfSight
public int getMissionaryLineOfSight()
Get the line of sight used by a missionary at this settlement.- Returns:
- The missionary line of sight.
-
getMissionaryVisibleTiles
public java.util.List<Tile> getMissionaryVisibleTiles()
Get a stream of tiles that should be visible to a missionary at this settlement.- Returns:
- A list of
Tile
s.
-
getConvertProgress
public int getConvertProgress()
Gets the convert progress status for this settlement.- Returns:
- The convert progress status.
-
setConvertProgress
public void setConvertProgress(int progress)
Sets the convert progress status for this settlement.- Parameters:
progress
- The new convert progress status.
-
validWantedGoodsIndex
private boolean validWantedGoodsIndex(int index)
Is a given index with the range of normal wanted goods.- Parameters:
index
- The index to test.- Returns:
- True if the index is in range.
-
getWantedGoods
public java.util.List<GoodsType> getWantedGoods()
Gets the goods wanted by this settlement.- Returns:
- The wanted goods list.
-
getWantedGoods
public GoodsType getWantedGoods(int index)
Gets one of the goods wanted by this settlement.- Parameters:
index
- Which of the goods to get.- Returns:
- The wanted
GoodsType
or null if not present or the index is out of range.
-
setWantedGoods
public void setWantedGoods(java.util.List<GoodsType> wanted)
Sets the goods wanted by this Settlement.- Parameters:
wanted
- The new wantedGoodsType
list.
-
setWantedGoods
public void setWantedGoods(int index, GoodsType type)
Sets the goods wanted by this settlement.- Parameters:
index
- Which of the (usually 3) goods to set.type
- TheGoodsType
wanted.
-
getWantedGoodsCount
public int getWantedGoodsCount()
Get the number of wanted goods. If any members of the array are null, we assume that subsequent ones are too.- Returns:
- The number of wanted goods.
-
getWantedGoodsLabel
public java.util.List<StringTemplate> getWantedGoodsLabel(int index, Player player)
Get a label for one of the wanted goods.- Parameters:
index
- The index into the wanted goods.player
- The requestingPlayer
.- Returns:
- A list of a
StringTemplate
for the label, and optionally one for a tool tip.
-
getMostHated
public Player getMostHated()
Gets the most hated nation of this settlement.- Returns:
- The most hated nation.
-
setMostHated
public void setMostHated(Player mostHated)
Sets the most hated nation of this settlement. -til: Changes the tile appearance.- Parameters:
mostHated
- The new most hated nation.
-
getMostHatedLabel
public StringTemplate getMostHatedLabel(boolean contacted)
Get a template for the current most hated nation, depending whether the requestor has contacted this settlement.- Parameters:
contacted
- The contact status.- Returns:
- A
StringTemplate
describing the perceived most hated nation.
-
setContactLevels
protected void setContactLevels(java.util.Map<Player,IndianSettlement.ContactLevel> contactLevels)
Set the contact levels.- Parameters:
contactLevels
- The new contact level map.
-
clearContactLevels
private void clearContactLevels()
Clear the contact levels.
-
getContactLevel
public IndianSettlement.ContactLevel getContactLevel(Player player)
Gets the contact level between this settlement and a player.- Parameters:
player
- ThePlayer
to check.- Returns:
- The contact level.
-
setContactLevel
private void setContactLevel(Player player, IndianSettlement.ContactLevel level)
Sets a contact level between this settlement and a player.- Parameters:
player
- The contactedPlayer
.level
- The newContactLevel
.
-
setContacted
public boolean setContacted(Player player)
Make contact with this settlement (if it has not been previously contacted). Initialize tension level to the general level with respect to the contacting player--- effectively the average reputation of this player with the overall tribe.- Parameters:
player
- ThePlayer
making contact.- Returns:
- True if this was indeed the first contact between settlement and player.
-
hasVisited
public boolean hasVisited(Player player)
Has a player visited this settlement?- Parameters:
player
- ThePlayer
to check.- Returns:
- True if the player has contacted this settlement.
-
setVisited
public boolean setVisited(Player player)
Sets the contact level of this settlement to indicate that a European player has visited the settlement.- Parameters:
player
- The visitingPlayer
.- Returns:
- True if this was the first time the settlement was visited by the player.
-
hasScouted
public boolean hasScouted(Player player)
Has a player has spoken with the chief of this settlement.- Parameters:
player
- ThePlayer
to check.- Returns:
- True if the player has visited this settlement to speak with the chief.
-
setScouted
public boolean setScouted(Player player)
Sets the contact level of this settlement to indicate that a European player has had a chat with the chief.- Parameters:
player
- The visitingPlayer
.- Returns:
- True if this was the first time the settlement was scouted by the player.
-
hasAnyScouted
public boolean hasAnyScouted()
Has any European player spoken with the chief of this settlement.- Returns:
- True if any European player has spoken with the chief.
-
worthScouting
public boolean worthScouting(Player player)
Is this settlement worth scouting? That is, has it been contacted, but not scouted already, or visited when the "Chief contact" option is set.- Parameters:
player
- ThePlayer
contemplating scouting.- Returns:
- Whether it might be worth the player scouting this settlement.
-
getAlarm
protected java.util.Map<Player,Tension> getAlarm()
Get the alarm map.- Returns:
- The map of player to tension.
-
setAlarm
protected void setAlarm(java.util.Map<Player,Tension> alarm)
Set the alarm map.- Parameters:
alarm
- The new map ofPlayer
toTension
.
-
getAlarm
public Tension getAlarm(Player player)
Gets the alarm level towards the given player.- Parameters:
player
- ThePlayer
to get the alarm level for.- Returns:
- The current alarm level or null if the settlement has not encoutered the player.
-
setAlarm
public void setAlarm(Player player, Tension newAlarm)
Sets alarm towards the given player. -til: Might change tile appearance through most hated state- Parameters:
player
- ThePlayer
to set the alarm level for.newAlarm
- The new alarm value.
-
clearAlarm
private void clearAlarm()
Clear the alarm levels.
-
initializeAlarm
protected void initializeAlarm(Player player)
Initialize the alarm at this settlement with respect to a player with the current national tension.- Parameters:
player
- ThePlayer
to set the alarm level for.
-
getAlarmLevelKey
public java.lang.String getAlarmLevelKey(Player player)
Gets a message key for a short alarm message associated with the alarm level of this player.- Parameters:
player
- The otherPlayer
.- Returns:
- The alarm message key.
-
getGoodsForSale
public java.util.List<Goods> getGoodsForSale()
Get the current goods offered for sale.- Returns:
- A list of
Goods
for sale.
-
setGoodsForSale
public void setGoodsForSale(java.util.List<Goods> forSale)
Set the current goods offered for sale.- Parameters:
forSale
- A new list ofGoods
for sale.
-
allowContact
public boolean allowContact(Unit unit)
Is a unit permitted to make contact with this settlement? The unit must be from a nation that has already made contact, or in the first instance, must be arriving by land, with the exception of trading ships.- Parameters:
unit
- TheUnit
that proposes to contact this settlement.- Returns:
- True if the settlement accepts such contact.
-
getPriceToBuy
public <T extends AbstractGoods> int getPriceToBuy(T goods)
Gets the amount of gold thisIndianSettlment
is willing to pay for the givenGoods
. It is only meaningful to call this method from the server, since the settlement'sGoodsContainer
is hidden from the clients.- Type Parameters:
T
- The base type of the goods.- Parameters:
goods
- The goods to price.- Returns:
- The price.
-
getPriceToBuy
public int getPriceToBuy(GoodsType type, int amount)
Gets the amount of gold thisIndianSettlment
is willing to pay for the givenGoods
. It is only meaningful to call this method from the server, since the settlement'sGoodsContainer
is hidden from the clients. The AI uses it though so it stays here for now. Note that it takes no account of whether the native player actually has the gold. FIXME: this is rancid with magic numbers.- Parameters:
type
- The type ofGoods
to price.amount
- The amount ofGoods
to price.- Returns:
- The price.
-
getNormalGoodsPriceToBuy
private int getNormalGoodsPriceToBuy(GoodsType type, int amount)
Price some goods according to the amount present in the settlement.- Parameters:
type
- The type of goods for sale.amount
- The amount of goods for sale.- Returns:
- A price for the goods.
-
getWantedGoodsAmount
protected int getWantedGoodsAmount(GoodsType type)
Calculates how much of the given goods type this settlement wants and should retain.- Parameters:
type
- TheGoodsType
.- Returns:
- The amount of goods wanted.
-
getMilitaryGoodsPriceToBuy
private int getMilitaryGoodsPriceToBuy(GoodsType type, int amount)
Price some goods that have military value to the settlement.- Parameters:
type
- The type of goods for sale.amount
- The amount of goods for sale.- Returns:
- A price for the goods.
-
getPriceToSell
public <T extends AbstractGoods> int getPriceToSell(T goods)
Gets the amount of gold thisIndianSettlment
is willing to sell the givenGoods
for. It is only meaningful to call this method from the server, since the settlement'sGoodsContainer
is hidden from the clients.- Type Parameters:
T
- The base type of the goods.- Parameters:
goods
- The goods to price.- Returns:
- The price.
-
getPriceToSell
public int getPriceToSell(GoodsType type, int amount)
Gets the amount of gold thisIndianSettlment
is willing to sell the givenGoods
for. It is only meaningful to call this method from the server, since the settlement'sGoodsContainer
is hidden from the clients.- Parameters:
type
- The type ofGoods
to price.amount
- The amount ofGoods
to price.- Returns:
- The price.
-
willSell
public boolean willSell(GoodsType type)
Will this settlement sell a type of goods. Placeholder until we have a spec-configured blacklist.- Parameters:
type
- TheGoodsType
to consider.- Returns:
- True if the settlement would sell the goods.
-
getSellGoods
public java.util.List<Goods> getSellGoods(Unit unit)
Gets the goods this settlement is willing to sell. Sell new world goods first, then by decreasing price, then decreasing amount.- Parameters:
unit
- An optionalUnit
that is trading.- Returns:
- A list of goods to sell.
-
tradeGoodsWithSettlement
public void tradeGoodsWithSettlement(IndianSettlement is)
Allows spread of horses and arms between settlements- Parameters:
is
- The otherIndianSettlement
to trade with.
-
getMaximumProduction
public int getMaximumProduction(GoodsType goodsType)
Gets the maximum possible production of the given type of goods.- Parameters:
goodsType
- The type of goods to check.- Returns:
- The maximum amount, of the given type of goods, that can be produced in one turn.
-
updateWantedGoods
public void updateWantedGoods()
Updates the goods wanted by this settlement. It is only meaningful to call this method from the server, since the settlement'sGoodsContainer
is hidden from the clients.
-
goodsToMake
private GoodsType goodsToMake()
Chooses a type of goods for some of the natives in a settlement to manufacture. Simple rule: choose the refined goods that is the greatest shortage for which there is a surplus of the raw material.- Returns:
- A
GoodsType
to manufacture, or null if none suitable.
-
getRandomGift
public Goods getRandomGift(java.util.Random random)
Gets a random goods gift from this settlement.- Parameters:
random
- A pseudo random number source.- Returns:
- A random goods gift, or null if none found.
-
addRandomGoods
public void addRandomGoods(java.util.Random random)
Add some initial goods to a newly generated settlement. After all, they have been here for some time.- Parameters:
random
- A pseudo-random number source.
-
getRequiredDefenders
public int getRequiredDefenders()
Get the number of braves expected to be present for the settlement not to be "badly defended".- Returns:
- The required defender number.
-
disposeResources
public void disposeResources()
Dispose of the resources of this object, and finally remove it from the game. To be extended by subclasses, but they must tail call up towards this. -vis: Visibility changes when the settlement is removed.- Overrides:
disposeResources
in classSettlement
-
getLocationLabelFor
public StringTemplate getLocationLabelFor(Player player)
Get a label for this location for a particular player.- Specified by:
getLocationLabelFor
in interfaceLocation
- Overrides:
getLocationLabelFor
in classUnitLocation
- Parameters:
player
- ThePlayer
to return the name for.- Returns:
- A label for this location.
-
add
public boolean add(Locatable locatable)
Adds aLocatable
to this Location.- Specified by:
add
in interfaceLocation
- Overrides:
add
in classGoodsLocation
- Parameters:
locatable
- TheLocatable
to add to this Location.- Returns:
- True if the locatable was added.
-
getIndianSettlement
public final IndianSettlement getIndianSettlement()
Gets the native settlement at this location.- Specified by:
getIndianSettlement
in interfaceLocation
- Overrides:
getIndianSettlement
in classUnitLocation
- Returns:
- The
IndianSettlement
at this location if any, or null if none found.
-
up
public Location up()
Promote this location to a more meaningful one if possible. For example: a settlement is more meaningful than the tile it occupies.
-
toShortString
public java.lang.String toShortString()
Get a short description of this location.- Specified by:
toShortString
in interfaceLocation
- Returns:
- A short description.
-
invalidateCache
public void invalidateCache()
Invalidate any cache dependent on the goods levels.- Specified by:
invalidateCache
in classGoodsLocation
-
getGoodsCapacity
public int getGoodsCapacity()
Gets the maximum number ofGoods
this Location can hold.- Specified by:
getGoodsCapacity
in classGoodsLocation
- Returns:
- The capacity for goods
-
getDefendingUnit
public Unit getDefendingUnit(Unit attacker)
Gets theUnit
that is currently defending thisSettlement
.- Specified by:
getDefendingUnit
in classSettlement
- Parameters:
attacker
- TheUnit
that is attacking thisSettlement
.- Returns:
- The
Unit
that has been chosen to defend thisSettlement
.
-
getDefenceRatio
public double getDefenceRatio()
Get the ratio between defence at this settlement, and the general settlement size.- Specified by:
getDefenceRatio
in classSettlement
- Returns:
- A ratio of defence power to settlement size.
-
isBadlyDefended
public boolean isBadlyDefended()
Is this settlement insufficiently defended?- Specified by:
isBadlyDefended
in classSettlement
- Returns:
- True if this settlement needs more defence.
-
getPlunderRange
public RandomRange getPlunderRange(Unit attacker)
Gets the range of gold plunderable when this settlement is captured.- Specified by:
getPlunderRange
in classSettlement
- Parameters:
attacker
- TheUnit
that takes the settlement.- Returns:
- A
RandomRange
encapsulating the range of plunder available.
-
getSoL
public int getSoL()
Gets the current Sons of Liberty in this settlement.- Specified by:
getSoL
in classSettlement
- Returns:
- The current SoL.
-
getUpkeep
public int getUpkeep()
Get the amount of gold necessary to maintain all of the settlement's buildings.- Specified by:
getUpkeep
in classSettlement
- Returns:
- The gold required for upkeep.
-
getTotalProductionOf
public int getTotalProductionOf(GoodsType type)
Gets the total production of the given type of goods in this settlement.- Specified by:
getTotalProductionOf
in classSettlement
- Parameters:
type
- The type of goods to get the production for.- Returns:
- The total production of the given type of goods.
-
hasContacted
public boolean hasContacted(Player player)
Has this settlement contacted a given player? Allow player == null as this is true in the map editor where the user player is moot.- Specified by:
hasContacted
in classSettlement
- Parameters:
player
- The otherPlayer
to check.- Returns:
- True if the settlement has contacted the player.
-
getAlarmLevelLabel
public StringTemplate getAlarmLevelLabel(Player player)
Gets a label indicating the alarm level at this settlement with respect to another player.- Specified by:
getAlarmLevelLabel
in classSettlement
- Parameters:
player
- The otherPlayer
.- Returns:
- A
StringTemplate
describing the alarm.
-
calculateSettlementValue
public int calculateSettlementValue(int value, Unit unit)
Determines the value of a potential attack on aIndianSettlement
- Specified by:
calculateSettlementValue
in classSettlement
- Parameters:
value
- The previously calculated input value from#scoreSettlementPath(AIUnit, PathNode, Settlement)
unit
- TheAIUnit
to check- Returns:
- The calculated value
-
getAvailableGoodsCount
public int getAvailableGoodsCount(GoodsType goodsType)
Get the amount of a given goods type at this trade location.- Specified by:
getAvailableGoodsCount
in interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- The amount of goods present.
-
getExportAmount
public int getExportAmount(GoodsType goodsType, int turns)
Gets the amount of a given goods type that can be exported from this trade location after a given number of turns.- Specified by:
getExportAmount
in interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
to check.turns
- The number of turns before the goods is required.- Returns:
- The amount of goods to export.
-
getImportAmount
public int getImportAmount(GoodsType goodsType, int turns)
Gets the amount of a given goods type that can be imported to this trade location after a given number of turns.- Specified by:
getImportAmount
in interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
to check.turns
- The number of turns before the goods will arrive.- Returns:
- The amount of goods to import.
-
getLocationName
public java.lang.String getLocationName(TradeLocation tradeLocation)
Function for returning the name of a TradeLocation- Specified by:
getLocationName
in interfaceTradeLocation
- Parameters:
tradeLocation
- TheTradeLocation
to return the name.- Returns:
- The name.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Overrides:
checkIntegrity
in classSettlement
- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
to log to.- Returns:
- A suitable
IntegrityType
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classSettlement
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classSettlement
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildren
in classSettlement
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classSettlement
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classSettlement
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChild
protected void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChild
in classSettlement
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-