Package net.sf.freecol.common.model
Class ColonyTile
- 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.WorkLocation
-
- net.sf.freecol.common.model.ColonyTile
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Location
,Ownable
,ObjectWithId
- Direct Known Subclasses:
ServerColonyTile
public class ColonyTile extends WorkLocation
Represents a work location on a tile. Each ColonyTile except the colony center tile provides a work place for a single unit and produces a single type of goods. The colony center tile generally produces two different of goods, one food type and one new world raw material.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.WorkLocation
WorkLocation.Suggestion
-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Logger
logger
static java.lang.String
TAG
static int
UNIT_CAPACITY
The maximum number of units a ColonyTile can hold.static java.lang.String
UNIT_CHANGE
private static java.lang.String
WORK_TILE_TAG
protected Tile
workTile
The tile to work.-
Fields inherited from class net.sf.freecol.common.model.WorkLocation
colony, EMPTY_LIST
-
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 ColonyTile(Game game, java.lang.String id)
Create a newColonyTile
with the given identifier.protected
ColonyTile(Game game, Colony colony, Tile workTile)
Constructor for ServerColonyTile.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canAutoProduce()
Can this work location can produce goods without workers?boolean
canProduce(GoodsType goodsType, UnitType unitType)
Can this work location produce a given goods type with an optional unit.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.int
evaluateFor(Player player)
Evaluate this work location for a given player.java.util.List<ProductionType>
getAvailableProductionTypes(boolean unattended)
Get the production types available for this work location.int
getBaseProduction(ProductionType productionType, GoodsType goodsType, UnitType unitType)
Gets the base production of a given goods type optionally using a unit of a given type in this work location.ProductionInfo
getBasicProductionInfo()
Gets the basic production information for the colony tile, ignoring any colony limits (which for now, should be irrelevant).StringTemplate
getClaimTemplate()
Gets a template describing whether this work location can/needs-to be claimed.float
getCompetenceFactor()
Get a work location specific factor to multiply any goods-specific unit production bonuses by.FreeColObject
getDisplayObject()
Get an object to display when showing the user messages for this object.StringTemplate
getLabel()
Get a description of the work location, with any expected extra detail.int
getLevel()
Get the "level" of this work location.StringTemplate
getLocationLabel()
Get a label for this location.UnitLocation.NoAddReason
getNoAddReason(Locatable locatable)
Gets the reason why a givenLocatable
can not be added to this Location.UnitLocation.NoAddReason
getNoWorkReason()
Checks if this work location is available to the colony to be worked.Unit
getOccupyingUnit()
Gets a unit who is occupying the tile.java.util.stream.Stream<Modifier>
getProductionModifiers(GoodsType goodsType, UnitType unitType)
Gets the production modifiers for the given type of goods and unit type.float
getRebelFactor()
Get a work location specific factor to multiply the colony rebel bonus by.int
getUnitCapacity()
Gets the maximum number ofUnits
this Location can hold.Tile
getWorkTile()
Gets the work tile, that is the actual tile being worked.java.lang.String
getXMLTagName()
Get the serialization tag for this object.protected boolean
goodSuggestionCheck(UnitType unitType, Unit unit, GoodsType goodsType)
Determines whether aWorkLocation
is a good suggestionint
improvedBy(TileImprovementType ti)
Would a given tile improvement be beneficial to this colony tile?boolean
isAvailable()
Is this work location available?boolean
isColonyCenterTile()
Is this the tile where theColony
is located?boolean
isCurrent()
Is this a current work location of this colony?boolean
isOccupied()
Is there a fortified enemy unit on the work tile? Production can not occur on occupied tiles.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setWorkTile(Tile workTile)
Sets the work tile.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.-
Methods inherited from class net.sf.freecol.common.model.WorkLocation
add, canBeWorked, canTeach, getBestProductionType, getColony, getCurrentWorkType, getExpertUnitType, getGenericPotential, getInputs, getLocationLabelFor, getMaximumProductionOf, getOccupation, getOccupation, getOutputs, getOwner, getPotentialProduction, getProduction, getProductionDeficit, getProductionInfo, getProductionOf, getProductionType, getRank, getSettlement, getSuggestions, getTile, getTotalProductionOf, getUnitProduction, getWorkFor, goodSuggestionCheck, hasInputs, hasOutputs, produces, readChild, remove, setColony, setOwner, setProductionType, setWorkFor, updateProductionType, writeChildren
-
Methods inherited from class net.sf.freecol.common.model.UnitLocation
canAdd, clearUnitList, contains, disposeResources, equipForRole, getCarrierForUnit, getDisposables, getFirstUnit, getGoodsContainer, getIndianSettlement, getLastUnit, getNavalUnits, getSpaceTaken, getTotalUnitCount, getUnitCount, getUnitList, getUnits, hasCarrierWithSpace, intern, isEmpty, isFull, moveToFront, priceGoods, readChildren
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, equals, fundamentalDispose, getClassIndex, getGame, getLinkTarget, 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, getFeatureContainer, 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.Location
getId, getLocationImageKey
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
UNIT_CHANGE
public static final java.lang.String UNIT_CHANGE
- See Also:
- Constant Field Values
-
UNIT_CAPACITY
public static final int UNIT_CAPACITY
The maximum number of units a ColonyTile can hold.- See Also:
- Constant Field Values
-
workTile
protected Tile workTile
The tile to work. This is accessed through getWorkTile(). Beware! Do not confuse this with getTile(), which returns the colony center tile (because every work location belongs to the enclosing colony).
-
WORK_TILE_TAG
private static final java.lang.String WORK_TILE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ColonyTile
protected ColonyTile(Game game, Colony colony, Tile workTile)
Constructor for ServerColonyTile.- Parameters:
game
- The enclosingGame
.colony
- TheColony
this object belongs to.workTile
- The tile in which thisColonyTile
represents aWorkLocation
for.
-
ColonyTile
public ColonyTile(Game game, java.lang.String id)
Create a newColonyTile
with the given identifier. The object should later be initialized by calling eitherFreeColGameObject.readFromXML(FreeColXMLReader)
.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
isColonyCenterTile
public boolean isColonyCenterTile()
Is this the tile where theColony
is located?- Returns:
- True if this is the colony center tile.
-
getWorkTile
public Tile getWorkTile()
Gets the work tile, that is the actual tile being worked.- Specified by:
getWorkTile
in classWorkLocation
- Returns:
- The
Tile
in which thisColonyTile
represents aWorkLocation
for.
-
setWorkTile
public void setWorkTile(Tile workTile)
Sets the work tile. Needed to fix copied colonies. Do not use otherwise!- Parameters:
workTile
- The new workTile
.
-
getOccupyingUnit
public Unit getOccupyingUnit()
Gets a unit who is occupying the tile.- Returns:
- A
Unit
who is occupying the work tile, if any. - See Also:
isOccupied()
-
isOccupied
public boolean isOccupied()
Is there a fortified enemy unit on the work tile? Production can not occur on occupied tiles.- Returns:
- True if an fortified enemy unit is in the tile.
-
getBasicProductionInfo
public ProductionInfo getBasicProductionInfo()
Gets the basic production information for the colony tile, ignoring any colony limits (which for now, should be irrelevant). In the original game, the following special rules apply to colony center tiles: - All tile improvements contribute to the production of food - Only natural tile improvements, such as rivers, contribute to the production of other types of goods. - Artificial tile improvements, such as plowing, are ignored.- Returns:
- The raw production of this colony tile.
- See Also:
ProductionCache.update()
-
improvedBy
public int improvedBy(TileImprovementType ti)
Would a given tile improvement be beneficial to this colony tile?- Parameters:
ti
- TheTileImprovementType
to assess.- Returns:
- A measure of improvement (negative is a bad idea).
-
evaluateFor
public int evaluateFor(Player player)
Evaluate this work location for a given player.- Overrides:
evaluateFor
in classWorkLocation
- Parameters:
player
- ThePlayer
to evaluate for.- Returns:
- A value for the player.
-
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.
-
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.- Returns:
- A more meaningful
Location
, or this one.
-
toShortString
public java.lang.String toShortString()
Get a short description of this location.- Returns:
- A short description.
-
getNoAddReason
public UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
Gets the reason why a givenLocatable
can not be added to this Location. Be careful to test for unit presence last before success (NoAddReason.NONE) except perhaps for the capacity test, so that we can treat ALREADY_PRESENT as success in some cases (e.g. if the unit changes type --- does it still have a required skill?) FIXME: consider moving this up to Location?- Overrides:
getNoAddReason
in classWorkLocation
- Parameters:
locatable
- TheLocatable
to test.- Returns:
- The reason why adding would fail.
-
getUnitCapacity
public int getUnitCapacity()
Gets the maximum number ofUnits
this Location can hold. To be overridden by subclasses.- Overrides:
getUnitCapacity
in classUnitLocation
- Returns:
- Integer.MAX_VALUE, denoting no effective limit.
-
goodSuggestionCheck
protected boolean goodSuggestionCheck(UnitType unitType, Unit unit, GoodsType goodsType)
Description copied from class:WorkLocation
Determines whether aWorkLocation
is a good suggestion- Overrides:
goodSuggestionCheck
in classWorkLocation
- Parameters:
unitType
- The type ofUnit
to check.unit
- The Unit itself.goodsType
- TheGoodsType
to check.- Returns:
- True or false, depending on whether the suggestion is valid.
-
getLabel
public StringTemplate getLabel()
Get a description of the work location, with any expected extra detail.- Specified by:
getLabel
in classWorkLocation
- Returns:
- A label
StringTemplate
for this work location.
-
isAvailable
public boolean isAvailable()
Is this work location available?- Specified by:
isAvailable
in classWorkLocation
- Returns:
- True if the work location is either current or can be claimed.
-
isCurrent
public boolean isCurrent()
Is this a current work location of this colony?- Specified by:
isCurrent
in classWorkLocation
- Returns:
- True if the work location is current.
-
getNoWorkReason
public UnitLocation.NoAddReason getNoWorkReason()
Checks if this work location is available to the colony to be worked.- Specified by:
getNoWorkReason
in classWorkLocation
- Returns:
- The reason why/not the work location can be worked.
-
getLevel
public int getLevel()
Get the "level" of this work location. Note: only meaningful for buildings at present.- Specified by:
getLevel
in classWorkLocation
- Returns:
- The work location level.
-
canAutoProduce
public boolean canAutoProduce()
Can this work location can produce goods without workers?- Specified by:
canAutoProduce
in classWorkLocation
- Returns:
- True if this work location can produce goods without workers.
-
canProduce
public boolean canProduce(GoodsType goodsType, UnitType unitType)
Can this work location produce a given goods type with an optional unit.- Specified by:
canProduce
in classWorkLocation
- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- An optionalUnitType
, if null the unattended production is considered.- Returns:
- True if this location can produce the goods.
-
getBaseProduction
public int getBaseProduction(ProductionType productionType, GoodsType goodsType, UnitType unitType)
Gets the base production of a given goods type optionally using a unit of a given type in this work location. That is, the production exclusive of any modifiers. If no unit type is specified, the unattended production is calculated.- Specified by:
getBaseProduction
in classWorkLocation
- Parameters:
productionType
- An optionalProductionType
to use, if null the best available one is used.goodsType
- TheGoodsType
to produce.unitType
- An optionalUnitType
to produce the goods.- Returns:
- The amount of goods potentially produced.
-
getProductionModifiers
public java.util.stream.Stream<Modifier> getProductionModifiers(GoodsType goodsType, UnitType unitType)
Gets the production modifiers for the given type of goods and unit type. If no unit is specified the unattended production is calculated.- Specified by:
getProductionModifiers
in classWorkLocation
- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- The optionalUnitType
to produce them.- Returns:
- A stream of the applicable modifiers.
-
getAvailableProductionTypes
public java.util.List<ProductionType> getAvailableProductionTypes(boolean unattended)
Get the production types available for this work location.- Specified by:
getAvailableProductionTypes
in classWorkLocation
- Parameters:
unattended
- If true, get unattended production types.- Returns:
- A list of suitable
ProductionType
s.
-
getCompetenceFactor
public float getCompetenceFactor()
Get a work location specific factor to multiply any goods-specific unit production bonuses by.- Specified by:
getCompetenceFactor
in classWorkLocation
- Returns:
- The competence factor.
-
getRebelFactor
public float getRebelFactor()
Get a work location specific factor to multiply the colony rebel bonus by.- Specified by:
getRebelFactor
in classWorkLocation
- Returns:
- The rebel factor.
-
getClaimTemplate
public StringTemplate getClaimTemplate()
Gets a template describing whether this work location can/needs-to be claimed. To be overridden by classes where this is meaningful. This is a default null implementation.- Overrides:
getClaimTemplate
in classWorkLocation
- Returns:
- A suitable template.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classWorkLocation
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
getDisplayObject
public FreeColObject getDisplayObject()
Get an object to display when showing the user messages for this object. Example: If this object is a Building, the object to display will be the BuildingType.- Overrides:
getDisplayObject
in classFreeColObject
- Returns:
- A suitable
FreeColObject
to display, defaults to this.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classWorkLocation
- 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 classWorkLocation
- 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
-
-