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. EachPlayerhas 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 classEurope.MigrationTypeMigration handling.-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
-
-
Field Summary
Fields Modifier and Type Field Description static AbilityABILITY_DRESS_MISSIONARYprotected intbaseRecruitPriceCurrent price to recruit a unit.private static intEUROPE_CLASS_INDEXClass index for Europe.private FeatureContainerfeatureContainerA feature container for this Europe's special features.private static java.util.logging.Loggerloggerprivate static intLOWER_CAP_INITIALThe initial lower bound on recruitment price.private PlayerownerThe owner of this instance of Europe.private static java.lang.StringOWNER_TAGprivate static java.lang.StringPRICE_TAGprivate static java.lang.StringRECRUIT_ID_TAGprivate static java.lang.StringRECRUIT_LOWER_CAP_TAGprivate static java.lang.StringRECRUIT_NUMBER_TAGprivate static intRECRUIT_PRICE_INITIALThe initial recruit price.private static java.lang.StringRECRUIT_PRICE_TAGprivate static java.lang.StringRECRUIT_ROLE_TAGprivate static java.lang.StringRECRUIT_TAGprivate static java.lang.StringRECRUIT_TYPE_TAGprotected java.util.List<AbstractUnit>recruitablesThis list represents the types of the units that can be recruited in Europe.protected intrecruitLowerCapThe lower bound on recruitment price.static java.lang.StringTAGstatic java.lang.StringUNIT_CHANGEprivate static java.lang.StringUNIT_PRICE_TAGprivate static java.lang.StringUNIT_TYPE_TAGprotected java.util.Map<UnitType,java.lang.Integer>unitPricesPrices 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 booleanadd(Locatable locatable)Adds aLocatableto this Location.protected booleanaddRecruitable(AbstractUnit au, boolean force)Add a recruitable abstract unit.protected booleanaddRecruitable(UnitType unitType, boolean force)Add a recruitable unit type.booleancanAdd(Locatable locatable)Checks whether or not the specified locatable may be added to thisLocation.booleancanBeInput()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.voiddisposeResources()Dispose of the resources of this object, and finally remove it from the game.booleanequipForRole(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.intgetAvailableGoodsCount(GoodsType goodsType)Get the amount of a given goods type at this trade location.protected intgetBaseRecruitPrice()Get the base recruit price.intgetClassIndex()Accessor for the class index.intgetCurrentRecruitPrice()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.intgetExportAmount(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.FeatureContainergetFeatureContainer()Gets the feature container for this object, if any.intgetImmigration(int production)Get any immigration produced in Europe.intgetImportAmount(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.FreeColGameObjectgetLinkTarget(Player player)Get a suitable game object to use as a clickable link in messages to a player.java.lang.StringgetLocationImageKey()Get an image key for this location.StringTemplategetLocationLabel()Get a label for this location.java.lang.StringgetLocationName(TradeLocation tradeLocation)Function for returning the name of a TradeLocationjavax.swing.JLabelgetNameAsJlabel()Get the name of this instance as a JLabel.java.lang.StringgetNameKey()Gets the name of this named object.PlayergetOwner()Gets the owner of thisOwnable.intgetRank()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 intgetRecruitLowerCap()Get the recruit lower cap price.intgetUnitPrice(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.StringgetXMLTagName()Get the serialization tag for this object.intpriceGoods(java.util.List<AbstractGoods> goods)What would the price be for a collection of goods at this location?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.voidsetOwner(Player p)Sets the owner of thisOwnable.private voidsetRecruitables(java.util.List<AbstractUnit> recruitables)Set the recruitables list.protected voidsetUnitPrices(java.util.Map<UnitType,java.lang.Integer> unitPrices)Set the unit price map.java.lang.StringtoShortString()Get a short description of this location.java.lang.StringtoString()Locationup()Promote this location to a more meaningful one if possible.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.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 newEuropewith 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
AbstractUnits.
-
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
AbstractUnits.
-
setRecruitables
private void setRecruitables(java.util.List<AbstractUnit> recruitables)
Set the recruitables list.- Parameters:
recruitables- The new list of recruitablesAbstractUnits.
-
addRecruitable
protected boolean addRecruitable(AbstractUnit au, boolean force)
Add a recruitable abstract unit.- Parameters:
au- The recruitableAbstractUnitto 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 recruitableUnitTypeto 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
UnitTypeto its price.
-
setUnitPrices
protected void setUnitPrices(java.util.Map<UnitType,java.lang.Integer> unitPrices)
Set the unit price map.- Parameters:
unitPrices- The new map ofUnitTypes to price.
-
getUnitPrice
public int getUnitPrice(UnitType unitType)
Gets the price of a unit in Europe.- Parameters:
unitType- TheUnitTypeto 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:
getLocationLabelin interfaceLocation- Overrides:
getLocationLabelin classUnitLocation- Returns:
- A label for this location.
-
add
public boolean add(Locatable locatable)
Adds aLocatableto this Location.- Specified by:
addin interfaceLocation- Overrides:
addin classUnitLocation- Parameters:
locatable- TheLocatableto 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:
canAddin interfaceLocation- Overrides:
canAddin classUnitLocation- Parameters:
locatable- TheLocatableto 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:
toShortStringin interfaceLocation- Returns:
- A short description.
-
getLocationImageKey
public java.lang.String getLocationImageKey()
Get an image key for this location.- Specified by:
getLocationImageKeyin 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:
priceGoodsin classUnitLocation- Parameters:
goods- The list ofAbstractGoodsto 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:
equipForRolein classUnitLocation- Parameters:
unit- TheUnitto equip.role- TheRoleto 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:
getNameKeyin 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:
getAvailableGoodsCountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getExportAmountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getImportAmountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getLocationNamein interfaceTradeLocation- Parameters:
tradeLocation- TheTradeLocationto return the name.- Returns:
- The name.
-
getNameAsJlabel
public javax.swing.JLabel getNameAsJlabel()
Get the name of this instance as a JLabel.- Specified by:
getNameAsJlabelin interfaceTradeLocation- Returns:
- The
JLabelwith the result ofTradeLocation.getLocationName(TradeLocation)
-
canBeInput
public boolean canBeInput()
Can a TradeLocation be set as the input location on a TradeRouteInputPanel- Specified by:
canBeInputin 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:
disposeResourcesin 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:
getLinkTargetin classFreeColGameObject- Parameters:
player- ThePlayerto 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:
getFeatureContainerin classFreeColObject- Returns:
- The
FeatureContainerfor 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:
getAbilitiesin classFreeColObject- Parameters:
id- The object identifier.fcgot- An optionalFreeColSpecObjectTypethe ability applies to.turn- An optional applicableTurn.- Returns:
- A set of abilities.
-
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 classUnitLocation- Type Parameters:
T- TheFreeColObjectsubclass 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:
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 classUnitLocation- Parameters:
xw- TheFreeColXMLWriterto 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:
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 classUnitLocation- 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 classUnitLocation- 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
-
-