Package net.sf.freecol.common.model
Class BuildingType
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.FreeColSpecObjectType
-
- net.sf.freecol.common.model.BuildableType
-
- net.sf.freecol.common.model.BuildingType
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,BaseProduction,Named,ObjectWithId
public final class BuildingType extends BuildableType implements BaseProduction
Encapsulates data common to all instances of a particular kind ofBuilding, such as the number of workplaces, and the types of goods it produces and consumes.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCOMPETENCE_FACTOR_TAGprivate floatcompetenceFactorA multiplier for any unit goods-specific bonus for this building type.private intexpertConnectionProductionMaximum production from the "experts have connections" option.private static java.lang.StringEXPERTS_WITH_CONNECTION_PRODUCTION_TAGprivate intlevelThe level of building.private static java.lang.StringMAXIMUM_SKILL_TAGprivate intmaxSkillThe maximum unit skill to work in buildings of this type.private static java.lang.StringMINIMUM_SKILL_TAGprivate intminSkillThe minimum unit skill to work in buildings of this type.private static java.lang.StringOLD_MAX_SKILL_TAGprivate static java.lang.StringOLD_MIN_SKILL_TAGprivate static java.lang.StringOLD_UPGRADES_FROM_TAGprivate intpriorityConsumption order.private static java.lang.StringPRIORITY_TAGprivate static java.lang.StringPRODUCTION_TAGprivate java.util.List<ProductionType>productionTypesThe possible production types of this building type.private static java.lang.StringREBEL_FACTOR_TAGprivate floatrebelFactorThe multiplier for the colony rebel bonus for this building type.static java.lang.StringTAGprivate static java.lang.StringUPGRADES_FROM_TAGprivate BuildingTypeupgradesFromThe building type this upgrades from.private BuildingTypeupgradesToThe building type this upgrades to.private intupkeepUpkeep per turn for buildings ot this type.private static java.lang.StringUPKEEP_TAGprivate intworkPlacesThe number of work places a unit can work in buildings of this type.private static java.lang.StringWORKPLACES_TAG-
Fields inherited from class net.sf.freecol.common.model.BuildableType
REQUIRED_POPULATION_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
DELETE_TAG, EXTENDS_TAG, PRESERVE_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description BuildingType(java.lang.String id, Specification specification)Creates a newBuildingTypeinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProductionType(ProductionType productionType)Add a production type to this building type.booleancanAdd(UnitType unitType)Can a unit of a given type be added to a Building of this type?Colony.NoBuildReasoncanBeBuiltInColony(Colony colony, java.util.List<BuildableType> assumeBuilt)Check to see if this buildable type can be built in a colony based on the buildings or units available.booleancanProduce(GoodsType goodsType, UnitType unitType)Can a tile of this type produce a given goods type?intcompareTo(FreeColObject other)Base for Comparable implementations.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.java.util.List<ProductionType>getAvailableProductionTypes(boolean unattended)Get the production types provided by this building type at the current difficulty level.java.util.List<ProductionType>getAvailableProductionTypes(boolean unattended, java.lang.String level)Gets the production types available at the current difficulty level.floatgetCompetenceFactor()Get a work location specific factor to multiply any unit goods specific bonuses by.intgetExpertConnectionProduction()Get the maximum production for the Experts-With-Connections option.BuildingTypegetFirstLevel()Gets the first level of this BuildingType.intgetLevel()Get the level of this BuildingType.intgetMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)intgetMaximumSkill()intgetMinimumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)intgetMinimumSkill()UnitLocation.NoAddReasongetNoAddReason(UnitType unitType)Gets the reason why a given unit type can not be added to a building of this type.intgetPotentialProduction(GoodsType goodsType, UnitType unitType)Get the amount of goods of a given goods type the given unit type could produce on a tile of this tile type.intgetPriority()The consumption priority of a Building of this type.GoodsTypegetProducedGoodsType()Gets the type of goods produced by this BuildingType.protected java.util.List<ProductionType>getProductionTypes()Get the production type list.floatgetRebelFactor()Get a work location specific factor to multiply the colony rebel bonus by.FreeColSpecObjectTypegetType()Gets the type of the building type, which is trivially just this object.BuildingTypegetUpgradesFrom()Gets the BuildingType this BuildingType upgrades from.BuildingTypegetUpgradesTo()Get the BuildingType this BuildingType upgrades to.intgetUpkeep()Gets the amount of gold necessary to maintain a Building of this type for one turn.intgetWorkPlaces()Gets the number of workplaces, that is the maximum number of Units that can work in this BuildingType.java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleanisAutomaticBuild()Is this building type automatically built in any colony?booleanisDefenceType()Is this a defence-related building type? Such buildings (stockade et al) are visible to other players.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidsetProductionTypes(java.util.List<ProductionType> productionTypes)Set the production type list.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.BuildableType
addRequiredAbility, getCurrentlyBuildingLabel, getLimits, getRequiredAbilities, getRequiredAmountOf, getRequiredGoods, getRequiredGoodsList, getRequiredPopulation, isAvailableTo, needsGoodsToBuild, readChildren, removeRequiredAbility, requiresAbility, setLimits, setRequiredAbilities, setRequiredGoods, setRequiredPopulation
-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
addScope, appliesTo, copyScopes, getDescriptionKey, getFeatureContainer, getIndex, getNameKey, getScopeList, getScopes, isAbstractType, removeScope, setIndex, toString
-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
getSpecification, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, 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.BaseProduction
getBaseProduction
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
level
private int level
The level of building.
-
workPlaces
private int workPlaces
The number of work places a unit can work in buildings of this type.
-
minSkill
private int minSkill
The minimum unit skill to work in buildings of this type.
-
maxSkill
private int maxSkill
The maximum unit skill to work in buildings of this type.
-
upkeep
private int upkeep
Upkeep per turn for buildings ot this type.
-
priority
private int priority
Consumption order.
-
expertConnectionProduction
private int expertConnectionProduction
Maximum production from the "experts have connections" option.
-
competenceFactor
private float competenceFactor
A multiplier for any unit goods-specific bonus for this building type.
-
rebelFactor
private float rebelFactor
The multiplier for the colony rebel bonus for this building type.
-
upgradesFrom
private BuildingType upgradesFrom
The building type this upgrades from.
-
upgradesTo
private BuildingType upgradesTo
The building type this upgrades to.
-
productionTypes
private final java.util.List<ProductionType> productionTypes
The possible production types of this building type.
-
COMPETENCE_FACTOR_TAG
private static final java.lang.String COMPETENCE_FACTOR_TAG
- See Also:
- Constant Field Values
-
EXPERTS_WITH_CONNECTION_PRODUCTION_TAG
private static final java.lang.String EXPERTS_WITH_CONNECTION_PRODUCTION_TAG
- See Also:
- Constant Field Values
-
MAXIMUM_SKILL_TAG
private static final java.lang.String MAXIMUM_SKILL_TAG
- See Also:
- Constant Field Values
-
MINIMUM_SKILL_TAG
private static final java.lang.String MINIMUM_SKILL_TAG
- See Also:
- Constant Field Values
-
PRIORITY_TAG
private static final java.lang.String PRIORITY_TAG
- See Also:
- Constant Field Values
-
PRODUCTION_TAG
private static final java.lang.String PRODUCTION_TAG
- See Also:
- Constant Field Values
-
REBEL_FACTOR_TAG
private static final java.lang.String REBEL_FACTOR_TAG
- See Also:
- Constant Field Values
-
UPGRADES_FROM_TAG
private static final java.lang.String UPGRADES_FROM_TAG
- See Also:
- Constant Field Values
-
UPKEEP_TAG
private static final java.lang.String UPKEEP_TAG
- See Also:
- Constant Field Values
-
WORKPLACES_TAG
private static final java.lang.String WORKPLACES_TAG
- See Also:
- Constant Field Values
-
OLD_MAX_SKILL_TAG
private static final java.lang.String OLD_MAX_SKILL_TAG
- See Also:
- Constant Field Values
-
OLD_MIN_SKILL_TAG
private static final java.lang.String OLD_MIN_SKILL_TAG
- See Also:
- Constant Field Values
-
OLD_UPGRADES_FROM_TAG
private static final java.lang.String OLD_UPGRADES_FROM_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BuildingType
public BuildingType(java.lang.String id, Specification specification)Creates a newBuildingTypeinstance.- Parameters:
id- The object identifier.specification- TheSpecificationto refer to.
-
-
Method Detail
-
getLevel
public int getLevel()
Get the level of this BuildingType.- Returns:
- The building level.
-
getWorkPlaces
public int getWorkPlaces()
Gets the number of workplaces, that is the maximum number of Units that can work in this BuildingType.- Returns:
- The number of work places.
-
getMinimumSkill
public int getMinimumSkill()
-
getMaximumSkill
public int getMaximumSkill()
-
getUpkeep
public int getUpkeep()
Gets the amount of gold necessary to maintain a Building of this type for one turn.- Returns:
- The per turn upkeep for this building type.
-
getExpertConnectionProduction
public int getExpertConnectionProduction()
Get the maximum production for the Experts-With-Connections option.- Returns:
- The production amount.
-
getCompetenceFactor
public float getCompetenceFactor()
Get a work location specific factor to multiply any unit goods specific bonuses by.- Returns:
- The competence factor.
-
getRebelFactor
public float getRebelFactor()
Get a work location specific factor to multiply the colony rebel bonus by.- Returns:
- The rebel factor.
-
getPriority
public int getPriority()
The consumption priority of a Building of this type. The higher the priority, the earlier will the Consumer be allowed to consume the goods it requires.- Returns:
- The consumption priority.
-
getNoAddReason
public UnitLocation.NoAddReason getNoAddReason(UnitType unitType)
Gets the reason why a given unit type can not be added to a building of this type.- Parameters:
unitType- TheUnitTypeto test.- Returns:
- The reason why adding would fail.
-
canAdd
public boolean canAdd(UnitType unitType)
Can a unit of a given type be added to a Building of this type?- Parameters:
unitType- TheUnitTypeto check.- Returns:
- True if the unit type can be added.
-
getType
public FreeColSpecObjectType getType()
Gets the type of the building type, which is trivially just this object.- Returns:
- This.
-
getUpgradesFrom
public BuildingType getUpgradesFrom()
Gets the BuildingType this BuildingType upgrades from.- Returns:
- The
BuildingTypethat upgrades to this one.
-
getUpgradesTo
public BuildingType getUpgradesTo()
Get the BuildingType this BuildingType upgrades to.- Returns:
- The
BuildingTypeto upgrade to from this one.
-
getFirstLevel
public BuildingType getFirstLevel()
Gets the first level of this BuildingType.- Returns:
- The base
BuildingType.
-
isAutomaticBuild
public boolean isAutomaticBuild()
Is this building type automatically built in any colony?- Returns:
- True if this building type is automatically built.
-
getProductionTypes
protected java.util.List<ProductionType> getProductionTypes()
Get the production type list.- Returns:
- The
ProductionTypelist.
-
setProductionTypes
protected void setProductionTypes(java.util.List<ProductionType> productionTypes)
Set the production type list.- Parameters:
productionTypes- The newProductionTypelist.
-
addProductionType
public void addProductionType(ProductionType productionType)
Add a production type to this building type.- Parameters:
productionType- TheProductionTypeto add.
-
getAvailableProductionTypes
public java.util.List<ProductionType> getAvailableProductionTypes(boolean unattended)
Get the production types provided by this building type at the current difficulty level.- Specified by:
getAvailableProductionTypesin interfaceBaseProduction- Parameters:
unattended- Whether the production is unattended.- Returns:
- A list of
ProductionTypes.
-
getAvailableProductionTypes
public java.util.List<ProductionType> getAvailableProductionTypes(boolean unattended, java.lang.String level)
Gets the production types available at the current difficulty level. FIXME: TileType.getAvailableProductionTypes(boolean) uses the GameOptions.TILE_PRODUCTION option. Should we implement a corresponding one for BuildingTypes?- Parameters:
unattended- Whether the production is unattended.level- The production level (NYI).- Returns:
- A list of
ProductionTypes.
-
getProducedGoodsType
public GoodsType getProducedGoodsType()
Gets the type of goods produced by this BuildingType.- Returns:
- The produced
GoodsType.
-
isDefenceType
public boolean isDefenceType()
Is this a defence-related building type? Such buildings (stockade et al) are visible to other players.- Returns:
- True if this is a defence related building.
-
canProduce
public boolean canProduce(GoodsType goodsType, UnitType unitType)
Can a tile of this type produce a given goods type?- Parameters:
goodsType- TheGoodsTypeto produce.unitType- An optionalUnitTypethat is to do the work, if null the unattended production is considered.- Returns:
- True if this tile type produces the goods.
-
getPotentialProduction
public int getPotentialProduction(GoodsType goodsType, UnitType unitType)
Get the amount of goods of a given goods type the given unit type could produce on a tile of this tile type.- Parameters:
goodsType- TheGoodsTypeto produce.unitType- An optionalUnitTypethat is to do the work, if null the unattended production is considered.- Returns:
- The amount of goods produced.
-
canBeBuiltInColony
public Colony.NoBuildReason canBeBuiltInColony(Colony colony, java.util.List<BuildableType> assumeBuilt)
Check to see if this buildable type can be built in a colony based on the buildings or units available.- Specified by:
canBeBuiltInColonyin classBuildableType- Parameters:
colony- TheColonyto check.assumeBuilt- A list ofBuildableTypes.- Returns:
- The reason the for failure, or NoBuildReason.NONE on success.
-
getMinimumIndex
public int getMinimumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
- Overrides:
getMinimumIndexin classBuildableType
-
getMaximumIndex
public int getMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
- Overrides:
getMaximumIndexin classBuildableType
-
compareTo
public int compareTo(FreeColObject other)
Base for Comparable implementations.- Specified by:
compareToin interfacejava.lang.Comparable<FreeColObject>- Overrides:
compareToin classFreeColObject- Parameters:
other- The otherFreeColObjectsubclass to compare.- Returns:
- The comparison result.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classBuildableType- 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 classBuildableType- 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 classBuildableType- 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 classBuildableType- 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 classBuildableType- 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.
-
-