Package net.sf.freecol.common.model
Class Europe
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.UnitLocation
-
- net.sf.freecol.common.model.Europe
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Location
,Named
,Ownable
,TradeLocation
,ObjectWithId
- Direct Known Subclasses:
ServerEurope
public class Europe extends UnitLocation implements Ownable, Named, TradeLocation
Represents Europe in the game. EachPlayer
has it's ownEurope
. In Europe, you can recruit, train and purchase new units. You can also equip units, as well as sell and buy goods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Europe.MigrationType
Migration handling.-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
-
-
Field Summary
Fields Modifier and Type Field Description static Ability
ABILITY_DRESS_MISSIONARY
protected int
baseRecruitPrice
Current price to recruit a unit.private static int
EUROPE_CLASS_INDEX
Class index for Europe.private FeatureContainer
featureContainer
A feature container for this Europe's special features.private static java.util.logging.Logger
logger
private static int
LOWER_CAP_INITIAL
The initial lower bound on recruitment price.private Player
owner
The owner of this instance of Europe.private static java.lang.String
OWNER_TAG
private static java.lang.String
PRICE_TAG
private static java.lang.String
RECRUIT_ID_TAG
private static java.lang.String
RECRUIT_LOWER_CAP_TAG
private static java.lang.String
RECRUIT_NUMBER_TAG
private static int
RECRUIT_PRICE_INITIAL
The initial recruit price.private static java.lang.String
RECRUIT_PRICE_TAG
private static java.lang.String
RECRUIT_ROLE_TAG
private static java.lang.String
RECRUIT_TAG
private static java.lang.String
RECRUIT_TYPE_TAG
protected java.util.List<AbstractUnit>
recruitables
This list represents the types of the units that can be recruited in Europe.protected int
recruitLowerCap
The lower bound on recruitment price.static java.lang.String
TAG
static java.lang.String
UNIT_CHANGE
private static java.lang.String
UNIT_PRICE_TAG
private static java.lang.String
UNIT_TYPE_TAG
protected java.util.Map<UnitType,java.lang.Integer>
unitPrices
Prices for trainable or purchasable units.-
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Locatable locatable)
Adds aLocatable
to this Location.protected boolean
addRecruitable(AbstractUnit au, boolean force)
Add a recruitable abstract unit.protected boolean
addRecruitable(UnitType unitType, boolean force)
Add a recruitable unit type.boolean
canAdd(Locatable locatable)
Checks whether or not the specified locatable may be added to thisLocation
.boolean
canBeInput()
Can a TradeLocation be set as the input location on a TradeRouteInputPanel<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.boolean
equipForRole(Unit unit, Role role, int roleCount)
Equip a unit for a role using resources at this location.java.util.stream.Stream<Ability>
getAbilities(java.lang.String id, FreeColSpecObjectType fcgot, Turn turn)
Gets the set of abilities with the given identifier from this object.int
getAvailableGoodsCount(GoodsType goodsType)
Get the amount of a given goods type at this trade location.protected int
getBaseRecruitPrice()
Get the base recruit price.int
getClassIndex()
Accessor for the class index.int
getCurrentRecruitPrice()
Gets the current price for a recruit.java.util.List<AbstractUnit>
getExpandedRecruitables(boolean full)
Get an expanded list of recruitable abstract units, with single counts and limited to valid indices.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.FeatureContainer
getFeatureContainer()
Gets the feature container for this object, if any.int
getImmigration(int production)
Get any immigration produced in Europe.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.FreeColGameObject
getLinkTarget(Player player)
Get a suitable game object to use as a clickable link in messages to a player.java.lang.String
getLocationImageKey()
Get an image key for this location.StringTemplate
getLocationLabel()
Get a label for this location.java.lang.String
getLocationName(TradeLocation tradeLocation)
Function for returning the name of a TradeLocationjavax.swing.JLabel
getNameAsJlabel()
Get the name of this instance as a JLabel.java.lang.String
getNameKey()
Gets the name of this named object.Player
getOwner()
Gets the owner of thisOwnable
.int
getRank()
Get a integer for this location, for the benefit of location comparators.protected java.util.List<AbstractUnit>
getRecruitables()
Get a list of the current recruitables.protected int
getRecruitLowerCap()
Get the recruit lower cap price.int
getUnitPrice(UnitType unitType)
Gets the price of a unit in Europe.protected java.util.Map<UnitType,java.lang.Integer>
getUnitPrices()
Get the unit price map.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
priceGoods(java.util.List<AbstractGoods> goods)
What would the price be for a collection of goods at this location?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.void
setOwner(Player p)
Sets the owner of thisOwnable
.private void
setRecruitables(java.util.List<AbstractUnit> recruitables)
Set the recruitables list.protected void
setUnitPrices(java.util.Map<UnitType,java.lang.Integer> unitPrices)
Set the unit price map.java.lang.String
toShortString()
Get a short description of this location.java.lang.String
toString()
Location
up()
Promote this location to a more meaningful one if possible.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.UnitLocation
clearUnitList, contains, getCarrierForUnit, getColony, getDisposables, getFirstUnit, getGoodsContainer, getIndianSettlement, getLastUnit, getLocationLabelFor, getNavalUnits, getNoAddReason, getSettlement, getSpaceTaken, getTile, getTotalUnitCount, getUnitCapacity, getUnitCount, getUnitList, getUnits, hasCarrierWithSpace, intern, isEmpty, isFull, moveToFront, remove
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, equals, fundamentalDispose, 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, 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
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
EUROPE_CLASS_INDEX
private static final int EUROPE_CLASS_INDEX
Class index for Europe.- See Also:
- Constant Field Values
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
RECRUIT_PRICE_INITIAL
private static final int RECRUIT_PRICE_INITIAL
The initial recruit price.- See Also:
- Constant Field Values
-
LOWER_CAP_INITIAL
private static final int LOWER_CAP_INITIAL
The initial lower bound on recruitment price.- See Also:
- Constant Field Values
-
UNIT_CHANGE
public static final java.lang.String UNIT_CHANGE
- See Also:
- Constant Field Values
-
ABILITY_DRESS_MISSIONARY
public static final Ability ABILITY_DRESS_MISSIONARY
-
recruitables
protected final java.util.List<AbstractUnit> recruitables
This list represents the types of the units that can be recruited in Europe.
-
unitPrices
protected final java.util.Map<UnitType,java.lang.Integer> unitPrices
Prices for trainable or purchasable units.
-
baseRecruitPrice
protected int baseRecruitPrice
Current price to recruit a unit.
-
recruitLowerCap
protected int recruitLowerCap
The lower bound on recruitment price.
-
owner
private Player owner
The owner of this instance of Europe.
-
featureContainer
private final FeatureContainer featureContainer
A feature container for this Europe's special features.
-
OWNER_TAG
private static final java.lang.String OWNER_TAG
- See Also:
- Constant Field Values
-
PRICE_TAG
private static final java.lang.String PRICE_TAG
- See Also:
- Constant Field Values
-
RECRUIT_LOWER_CAP_TAG
private static final java.lang.String RECRUIT_LOWER_CAP_TAG
- See Also:
- Constant Field Values
-
RECRUIT_NUMBER_TAG
private static final java.lang.String RECRUIT_NUMBER_TAG
- See Also:
- Constant Field Values
-
RECRUIT_PRICE_TAG
private static final java.lang.String RECRUIT_PRICE_TAG
- See Also:
- Constant Field Values
-
RECRUIT_ROLE_TAG
private static final java.lang.String RECRUIT_ROLE_TAG
- See Also:
- Constant Field Values
-
RECRUIT_TAG
private static final java.lang.String RECRUIT_TAG
- See Also:
- Constant Field Values
-
RECRUIT_TYPE_TAG
private static final java.lang.String RECRUIT_TYPE_TAG
- See Also:
- Constant Field Values
-
UNIT_PRICE_TAG
private static final java.lang.String UNIT_PRICE_TAG
- See Also:
- Constant Field Values
-
UNIT_TYPE_TAG
private static final java.lang.String UNIT_TYPE_TAG
- See Also:
- Constant Field Values
-
RECRUIT_ID_TAG
private static final java.lang.String RECRUIT_ID_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Europe
protected Europe(Game game, Player owner)
Constructor for ServerEurope.- Parameters:
game
- The enclosingGame
.owner
- The owningPlayer
.
-
Europe
public Europe(Game game, java.lang.String id)
Creates a newEurope
with the given identifier. ( The object should be initialized later.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
getRecruitables
protected java.util.List<AbstractUnit> getRecruitables()
Get a list of the current recruitables.- Returns:
- A list of recruitable
AbstractUnit
s.
-
getExpandedRecruitables
public java.util.List<AbstractUnit> getExpandedRecruitables(boolean full)
Get an expanded list of recruitable abstract units, with single counts and limited to valid indices.- Parameters:
full
- If true, return the full list, otherwise limit to the standard number of migrants.- Returns:
- A list of
AbstractUnit
s.
-
setRecruitables
private void setRecruitables(java.util.List<AbstractUnit> recruitables)
Set the recruitables list.- Parameters:
recruitables
- The new list of recruitablesAbstractUnit
s.
-
addRecruitable
protected boolean addRecruitable(AbstractUnit au, boolean force)
Add a recruitable abstract unit.- Parameters:
au
- The recruitableAbstractUnit
to add.force
- If true, add beyond the standard limit.- Returns:
- True if the recruitable was added.
-
addRecruitable
protected boolean addRecruitable(UnitType unitType, boolean force)
Add a recruitable unit type.- Parameters:
unitType
- The recruitableUnitType
to add.force
- If true, add beyond the standard limit.- Returns:
- True if the recruitable was added.
-
getUnitPrices
protected java.util.Map<UnitType,java.lang.Integer> getUnitPrices()
Get the unit price map.- Returns:
- The map of
UnitType
to its price.
-
setUnitPrices
protected void setUnitPrices(java.util.Map<UnitType,java.lang.Integer> unitPrices)
Set the unit price map.- Parameters:
unitPrices
- The new map ofUnitType
s to price.
-
getUnitPrice
public int getUnitPrice(UnitType unitType)
Gets the price of a unit in Europe.- Parameters:
unitType
- TheUnitType
to price.- Returns:
- The price of this unit when trained/purchased in Europe, or UNDEFINED on failure.
-
getBaseRecruitPrice
protected int getBaseRecruitPrice()
Get the base recruit price.- Returns:
- The base recruit price.
-
getCurrentRecruitPrice
public int getCurrentRecruitPrice()
Gets the current price for a recruit.- Returns:
- The current price of the recruit in this
Europe
.
-
getRecruitLowerCap
protected int getRecruitLowerCap()
Get the recruit lower cap price.- Returns:
- The lower cap on the recruit price.
-
getImmigration
public int getImmigration(int production)
Get any immigration produced in Europe. Col1 penalizes immigration by -4 per unit in Europe per turn, but there is a +2 player bonus, which we might as well add here. Total immigration per turn can not be negative, but that is handled in ServerPlayer.- Parameters:
production
- The current total colony production.- Returns:
- Immigration produced this turn in Europe.
-
getLocationLabel
public StringTemplate getLocationLabel()
Get a label for this location.- Specified by:
getLocationLabel
in interfaceLocation
- Overrides:
getLocationLabel
in classUnitLocation
- 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 classUnitLocation
- Parameters:
locatable
- TheLocatable
to add to this Location.- Returns:
- True if the locatable was added.
-
canAdd
public boolean canAdd(Locatable locatable)
Checks whether or not the specified locatable may be added to thisLocation
.- Specified by:
canAdd
in interfaceLocation
- Overrides:
canAdd
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to add.- Returns:
- True if the locatable can be added to this location.
-
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.
-
getRank
public int getRank()
Get a integer for this location, for the benefit of location comparators.
-
toShortString
public java.lang.String toShortString()
Get a short description of this location.- Specified by:
toShortString
in interfaceLocation
- Returns:
- A short description.
-
getLocationImageKey
public java.lang.String getLocationImageKey()
Get an image key for this location.- Specified by:
getLocationImageKey
in interfaceLocation
- Returns:
- A key for image lookup, null by default.
-
priceGoods
public int priceGoods(java.util.List<AbstractGoods> goods) throws FreeColException
What would the price be for a collection of goods at this location?- Overrides:
priceGoods
in classUnitLocation
- Parameters:
goods
- The list ofAbstractGoods
to check for.- Returns:
- The net cost of acquiring the goods at this location.
- Throws:
FreeColException
- if the goods are unavailable for any reason.
-
equipForRole
public boolean equipForRole(Unit unit, Role role, int roleCount)
Equip a unit for a role using resources at this location.- Overrides:
equipForRole
in classUnitLocation
- Parameters:
unit
- TheUnit
to equip.role
- TheRole
to build for.roleCount
- The role count.- Returns:
- True if the equipping succeeded.
-
getNameKey
public java.lang.String getNameKey()
Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.- Specified by:
getNameKey
in interfaceNamed
- Returns:
- The name of the
Named
.
-
getOwner
public Player getOwner()
Gets the owner of thisOwnable
.
-
setOwner
public void setOwner(Player p)
Sets the owner of thisOwnable
.
-
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.
-
getNameAsJlabel
public javax.swing.JLabel getNameAsJlabel()
Get the name of this instance as a JLabel.- Specified by:
getNameAsJlabel
in interfaceTradeLocation
- Returns:
- The
JLabel
with the result ofTradeLocation.getLocationName(TradeLocation)
-
canBeInput
public boolean canBeInput()
Can a TradeLocation be set as the input location on a TradeRouteInputPanel- Specified by:
canBeInput
in interfaceTradeLocation
- Returns:
- True if possible, false by default.
-
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.- Overrides:
disposeResources
in classUnitLocation
-
getLinkTarget
public FreeColGameObject getLinkTarget(Player player)
Get a suitable game object to use as a clickable link in messages to a player. Objects do not have links by default, hence the null return here. However, for example, a player's colony should return itself as a link target.- Overrides:
getLinkTarget
in classFreeColGameObject
- Parameters:
player
- ThePlayer
to make a link for.- Returns:
- A suitable link target if available, although usually null.
-
getFeatureContainer
public FeatureContainer getFeatureContainer()
Gets the feature container for this object, if any.- Overrides:
getFeatureContainer
in classFreeColObject
- Returns:
- The
FeatureContainer
for this object.
-
getAbilities
public java.util.stream.Stream<Ability> getAbilities(java.lang.String id, FreeColSpecObjectType fcgot, Turn turn)
Gets the set of abilities with the given identifier from this object. Subclasses with complex ability handling should override this as all prior routines are derived from it.- Overrides:
getAbilities
in classFreeColObject
- Parameters:
id
- The object identifier.fcgot
- An optionalFreeColSpecObjectType
the ability applies to.turn
- An optional applicableTurn
.- Returns:
- A set of abilities.
-
getClassIndex
public int getClassIndex()
Accessor for the class index.- Overrides:
getClassIndex
in classFreeColGameObject
- Returns:
- The class index used by
ClientOptions
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classUnitLocation
- 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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildren
in classUnitLocation
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
public void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classFreeColGameObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classUnitLocation
- 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 classUnitLocation
- 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
-
-