Package net.sf.freecol.common.model
Class Building
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,Consumer,Location,Named,Ownable,ObjectWithId
- Direct Known Subclasses:
ServerBuilding
public class Building extends WorkLocation implements Named, Consumer
Represents a building in a colony.
-
-
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.lang.StringBUILDING_TYPE_TAGprotected BuildingTypebuildingTypeThe type of building.private static doubleEPSILONprivate static java.util.logging.Loggerloggerstatic java.lang.StringTAGstatic java.lang.StringUNIT_CHANGE-
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.Consumer
BUILDING_PRIORITY, COLONY_PRIORITY, COMPARATOR, POPULATION_PRIORITY, UNIT_PRIORITY
-
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 booleancanAddType(UnitType unitType)Can a particular type of unit be added to this building?booleancanAutoProduce()Can this work location can produce goods without workers?booleancanBeDamaged()Can this building can be damaged?booleancanBuildNext()Does this building have a higher level?booleancanProduce(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.java.util.List<Unit>downgrade()Downgrade this building.intevaluateFor(Player player)Evaluate this work location for a given player.java.util.stream.Stream<Ability>getAbilities(java.lang.String id, FreeColSpecObjectType type, Turn turn)Gets the set of abilities with the given identifier from this object.ProductionInfogetAdjustedProductionInfo(java.util.List<AbstractGoods> inputs, java.util.List<AbstractGoods> outputs)Gets the production information for this building taking account of the available input and output goods.private intgetAvailable(GoodsType type, java.util.List<AbstractGoods> available)Convenience function to extract a goods amount from a list of available goods.java.util.List<ProductionType>getAvailableProductionTypes(boolean unattended)Get the production types available for this work location.intgetBaseProduction(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.floatgetCompetenceFactor()Get a work location specific factor to multiply any goods-specific unit production bonuses by.java.util.stream.Stream<Modifier>getCompetenceModifiers(java.lang.String id, UnitType unitType, Turn turn)Gets the production modifiers for the given type of goods and unit type.java.util.List<AbstractGoods>getConsumedGoods()Returns a list of GoodsTypes this Consumer consumes.java.util.stream.Stream<Modifier>getConsumptionModifiers(java.lang.String id)Get the modifier set with the given id.FreeColObjectgetDisplayObject()Get an object to display when showing the user messages for this object.StringTemplategetLabel()Get a description of the work location, with any expected extra detail.intgetLevel()Get the "level" of this work location.StringTemplategetLocationLabel()Get a label for this location.java.util.stream.Stream<Modifier>getModifiers(java.lang.String id, FreeColSpecObjectType fcgot, Turn turn)Gets the set of modifiers with the given identifier from this object.java.lang.StringgetNameKey()Gets the name of this named object.UnitLocation.NoAddReasongetNoAddReason(Locatable locatable)Gets the reason why a givenLocatablecan not be added to this Location.UnitLocation.NoAddReasongetNoWorkReason()Checks if this work location is available to the colony to be worked.intgetPriority()The priority of this Consumer.java.util.stream.Stream<Modifier>getProductionModifiers(GoodsType goodsType, UnitType unitType)Gets the production modifiers for the given type of goods and unit type.floatgetRebelFactor()Get a work location specific factor to multiply the colony rebel bonus by.BuildingTypegetType()Gets the type of this building.intgetUnitCapacity()Gets the maximum number ofUnitsthis Location can hold.TilegetWorkTile()Get an associated tile, if any.java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleangoodSuggestionCheck(UnitType better, Unit unit, GoodsType goodsType)Determines whether aWorkLocationis a good suggestionbooleanisAvailable()Is this work location available?booleanisCurrent()Is this a current work location of this colony?protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.private java.util.List<Unit>setType(BuildingType newBuildingType)Changes the type of the Building.java.lang.StringtoShortString()Get a short description of this location.java.lang.StringtoString()Locationup()Promote this location to a more meaningful one if possible.java.util.List<Unit>upgrade()Upgrade this building to next level.protected voidwriteAttributes(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, getClaimTemplate, 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, getDefenceModifiers, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, 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
-
EPSILON
private static final double EPSILON
- See Also:
- Constant Field Values
-
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
-
buildingType
protected BuildingType buildingType
The type of building.
-
BUILDING_TYPE_TAG
private static final java.lang.String BUILDING_TYPE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Building
protected Building(Game game, Colony colony, BuildingType type)
Constructor for ServerBuilding.- Parameters:
game- The enclosingGame.colony- TheColonyin which this building is located.type- TheBuildingTypeof building.
-
Building
public Building(Game game, java.lang.String id)
Create a newBuildingwith the given identifier. The object should later be initialized by callingFreeColGameObject.readFromXML(FreeColXMLReader).- Parameters:
game- The enclosingGame.id- The object identifier.
-
-
Method Detail
-
getType
public BuildingType getType()
Gets the type of this building.- Returns:
- The building type.
-
setType
private java.util.List<Unit> setType(BuildingType newBuildingType)
Changes the type of the Building. The type of a building may change when it is upgraded or damaged. -til: If this is a defensive building.- Parameters:
newBuildingType- The newBuildingType.- Returns:
- A list of units present that need to be removed.
- See Also:
upgrade(),downgrade()
-
getCompetenceModifiers
public java.util.stream.Stream<Modifier> getCompetenceModifiers(java.lang.String id, UnitType unitType, Turn turn)
Gets the production modifiers for the given type of goods and unit type. We use UnitType.getModifiers but modify this according to the competence factor of this building type. Note that we do not modify *multiplicative* modifiers, as this would capture the master blacksmith doubling.- Parameters:
id- The String identifierturn- The turn number of typeTurnunitType- The optionalUnitTypeto produce them.- Returns:
- A stream of the applicable modifiers.
-
canBuildNext
public boolean canBuildNext()
Does this building have a higher level?- Returns:
- True if this
Buildingcan have a higher level.
-
canBeDamaged
public boolean canBeDamaged()
Can this building can be damaged?- Returns:
- True if this building can be damaged.
-
downgrade
public java.util.List<Unit> downgrade()
Downgrade this building. -til: If this is a defensive building.- Returns:
- A list of units to eject (usually empty) if the building was downgraded, or null on failure.
-
upgrade
public java.util.List<Unit> upgrade()
Upgrade this building to next level. -til: If this is a defensive building.- Returns:
- A list of units to eject (usually empty) if the building was upgraded, or null on failure.
-
canAddType
public boolean canAddType(UnitType unitType)
Can a particular type of unit be added to this building?- Parameters:
unitType- TheUnitTypeto check.- Returns:
- True if unit type can be added to this building.
-
getAvailable
private int getAvailable(GoodsType type, java.util.List<AbstractGoods> available)
Convenience function to extract a goods amount from a list of available goods.- Parameters:
type- TheGoodsTypeto extract the amount for.available- The list of available goods to query.- Returns:
- The goods amount, or zero if none found.
-
getAdjustedProductionInfo
public ProductionInfo getAdjustedProductionInfo(java.util.List<AbstractGoods> inputs, java.util.List<AbstractGoods> outputs)
Gets the production information for this building taking account of the available input and output goods.- Parameters:
inputs- The input goods available.outputs- The output goods already available in the colony, necessary in order to avoid excess production.- Returns:
- The production information.
- See Also:
ProductionCache.update()
-
evaluateFor
public int evaluateFor(Player player)
Evaluate this work location for a given player.- Overrides:
evaluateForin classWorkLocation- Parameters:
player- ThePlayerto evaluate for.- Returns:
- A value for the player.
-
getLocationLabel
public StringTemplate getLocationLabel()
Get a label for this location.- Specified by:
getLocationLabelin interfaceLocation- Overrides:
getLocationLabelin 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.
-
toShortString
public java.lang.String toShortString()
Get a short description of this location.- Specified by:
toShortStringin interfaceLocation- Returns:
- A short description.
-
getNoAddReason
public UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
Gets the reason why a givenLocatablecan 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:
getNoAddReasonin classWorkLocation- Parameters:
locatable- TheLocatableto test.- Returns:
- The reason why adding would fail.
-
getUnitCapacity
public int getUnitCapacity()
Gets the maximum number ofUnitsthis Location can hold. To be overridden by subclasses.- Overrides:
getUnitCapacityin classUnitLocation- Returns:
- Integer.MAX_VALUE, denoting no effective limit.
-
goodSuggestionCheck
public boolean goodSuggestionCheck(UnitType better, Unit unit, GoodsType goodsType)
Description copied from class:WorkLocationDetermines whether aWorkLocationis a good suggestion- Overrides:
goodSuggestionCheckin classWorkLocation- Parameters:
better- The type ofUnitto check.unit- The Unit itself.goodsType- TheGoodsTypeto 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:
getLabelin classWorkLocation- Returns:
- A label
StringTemplatefor this work location.
-
isAvailable
public boolean isAvailable()
Is this work location available?- Specified by:
isAvailablein 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:
isCurrentin 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:
getNoWorkReasonin classWorkLocation- Returns:
- The reason why/not the work location can be worked.
-
getWorkTile
public Tile getWorkTile()
Get an associated tile, if any.- Specified by:
getWorkTilein classWorkLocation- Returns:
- The underlying
Tilewhich is worked, if any.
-
getLevel
public int getLevel()
Get the "level" of this work location. Note: only meaningful for buildings at present.- Specified by:
getLevelin classWorkLocation- Returns:
- The work location level.
-
canAutoProduce
public boolean canAutoProduce()
Can this work location can produce goods without workers?- Specified by:
canAutoProducein 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:
canProducein classWorkLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getBaseProductionin classWorkLocation- Parameters:
productionType- An optionalProductionTypeto use, if null the best available one is used.goodsType- TheGoodsTypeto produce.unitType- An optionalUnitTypeto 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:
getProductionModifiersin classWorkLocation- Parameters:
goodsType- TheGoodsTypeto produce.unitType- The optionalUnitTypeto 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:
getAvailableProductionTypesin classWorkLocation- Parameters:
unattended- If true, get unattended production types.- Returns:
- A list of suitable
ProductionTypes.
-
getCompetenceFactor
public float getCompetenceFactor()
Get a work location specific factor to multiply any goods-specific unit production bonuses by.- Specified by:
getCompetenceFactorin classWorkLocation- Returns:
- The competence factor.
-
getRebelFactor
public float getRebelFactor()
Get a work location specific factor to multiply the colony rebel bonus by.- Specified by:
getRebelFactorin classWorkLocation- Returns:
- The rebel factor.
-
getConsumedGoods
public java.util.List<AbstractGoods> getConsumedGoods()
Returns a list of GoodsTypes this Consumer consumes.- Specified by:
getConsumedGoodsin interfaceConsumer- Returns:
- a
Listvalue
-
getPriority
public int getPriority()
The priority of this Consumer. The higher the priority, the earlier will the Consumer be allowed to consume the goods it requires.- Specified by:
getPriorityin interfaceConsumer- Returns:
- an
intvalue
-
getConsumptionModifiers
public java.util.stream.Stream<Modifier> getConsumptionModifiers(java.lang.String id)
Get the modifier set with the given id. The modifier most relevant to consumers is "consumeOnlySurplusProduction", which implies that the consumer does not consume stored goods (used by the country and stables).- Specified by:
getConsumptionModifiersin interfaceConsumer- Parameters:
id- The object identifier.- Returns:
- The stream of
Modifiers found.
-
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.
-
getAbilities
public java.util.stream.Stream<Ability> getAbilities(java.lang.String id, FreeColSpecObjectType type, 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.type- An optionalFreeColSpecObjectTypethe ability applies to.turn- An optional applicableTurn.- Returns:
- A set of abilities.
-
getModifiers
public java.util.stream.Stream<Modifier> getModifiers(java.lang.String id, FreeColSpecObjectType fcgot, Turn turn)
Gets the set of modifiers with the given identifier from this object. Subclasses with complex modifier handling may override this routine.- Overrides:
getModifiersin classFreeColObject- Parameters:
id- The object identifier.fcgot- An optionalFreeColSpecObjectTypethe modifier applies to.turn- An optional applicableTurn.- Returns:
- A set of modifiers.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classWorkLocation- Type Parameters:
T- TheFreeColObjectsubclass of the object to copy in.- Parameters:
other- The other object.- Returns:
- True if the copy in is succesful.
-
getDisplayObject
public FreeColObject getDisplayObject()
Get an object to display when showing the user messages for this object. Example: If this object is a Building, the object to display will be the BuildingType.- Overrides:
getDisplayObjectin classFreeColObject- Returns:
- A suitable
FreeColObjectto display, defaults to this.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributesin classWorkLocation- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributesin classWorkLocation- 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
-
-