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.String
COMPETENCE_FACTOR_TAG
private float
competenceFactor
A multiplier for any unit goods-specific bonus for this building type.private int
expertConnectionProduction
Maximum production from the "experts have connections" option.private static java.lang.String
EXPERTS_WITH_CONNECTION_PRODUCTION_TAG
private int
level
The level of building.private static java.lang.String
MAXIMUM_SKILL_TAG
private int
maxSkill
The maximum unit skill to work in buildings of this type.private static java.lang.String
MINIMUM_SKILL_TAG
private int
minSkill
The minimum unit skill to work in buildings of this type.private static java.lang.String
OLD_MAX_SKILL_TAG
private static java.lang.String
OLD_MIN_SKILL_TAG
private static java.lang.String
OLD_UPGRADES_FROM_TAG
private int
priority
Consumption order.private static java.lang.String
PRIORITY_TAG
private static java.lang.String
PRODUCTION_TAG
private java.util.List<ProductionType>
productionTypes
The possible production types of this building type.private static java.lang.String
REBEL_FACTOR_TAG
private float
rebelFactor
The multiplier for the colony rebel bonus for this building type.static java.lang.String
TAG
private static java.lang.String
UPGRADES_FROM_TAG
private BuildingType
upgradesFrom
The building type this upgrades from.private BuildingType
upgradesTo
The building type this upgrades to.private int
upkeep
Upkeep per turn for buildings ot this type.private static java.lang.String
UPKEEP_TAG
private int
workPlaces
The number of work places a unit can work in buildings of this type.private static java.lang.String
WORKPLACES_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 newBuildingType
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProductionType(ProductionType productionType)
Add a production type to this building type.boolean
canAdd(UnitType unitType)
Can a unit of a given type be added to a Building of this type?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.boolean
canProduce(GoodsType goodsType, UnitType unitType)
Can a tile of this type produce a given goods type?int
compareTo(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.float
getCompetenceFactor()
Get a work location specific factor to multiply any unit goods specific bonuses by.int
getExpertConnectionProduction()
Get the maximum production for the Experts-With-Connections option.BuildingType
getFirstLevel()
Gets the first level of this BuildingType.int
getLevel()
Get the level of this BuildingType.int
getMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
int
getMaximumSkill()
int
getMinimumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
int
getMinimumSkill()
UnitLocation.NoAddReason
getNoAddReason(UnitType unitType)
Gets the reason why a given unit type can not be added to a building of this type.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.int
getPriority()
The consumption priority of a Building of this type.GoodsType
getProducedGoodsType()
Gets the type of goods produced by this BuildingType.protected java.util.List<ProductionType>
getProductionTypes()
Get the production type list.float
getRebelFactor()
Get a work location specific factor to multiply the colony rebel bonus by.FreeColSpecObjectType
getType()
Gets the type of the building type, which is trivially just this object.BuildingType
getUpgradesFrom()
Gets the BuildingType this BuildingType upgrades from.BuildingType
getUpgradesTo()
Get the BuildingType this BuildingType upgrades to.int
getUpkeep()
Gets the amount of gold necessary to maintain a Building of this type for one turn.int
getWorkPlaces()
Gets the number of workplaces, that is the maximum number of Units that can work in this BuildingType.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
isAutomaticBuild()
Is this building type automatically built in any colony?boolean
isDefenceType()
Is this a defence-related building type? Such buildings (stockade et al) are visible to other players.protected 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
setProductionTypes(java.util.List<ProductionType> productionTypes)
Set the production type list.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.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 newBuildingType
instance.- Parameters:
id
- The object identifier.specification
- TheSpecification
to 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
- TheUnitType
to 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
- TheUnitType
to 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
BuildingType
that upgrades to this one.
-
getUpgradesTo
public BuildingType getUpgradesTo()
Get the BuildingType this BuildingType upgrades to.- Returns:
- The
BuildingType
to 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
ProductionType
list.
-
setProductionTypes
protected void setProductionTypes(java.util.List<ProductionType> productionTypes)
Set the production type list.- Parameters:
productionTypes
- The newProductionType
list.
-
addProductionType
public void addProductionType(ProductionType productionType)
Add a production type to this building type.- Parameters:
productionType
- TheProductionType
to 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:
getAvailableProductionTypes
in interfaceBaseProduction
- Parameters:
unattended
- Whether the production is unattended.- Returns:
- A list of
ProductionType
s.
-
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
ProductionType
s.
-
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
- TheGoodsType
to produce.unitType
- An optionalUnitType
that 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
- TheGoodsType
to produce.unitType
- An optionalUnitType
that 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:
canBeBuiltInColony
in classBuildableType
- Parameters:
colony
- TheColony
to check.assumeBuilt
- A list ofBuildableType
s.- 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:
getMinimumIndex
in classBuildableType
-
getMaximumIndex
public int getMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
- Overrides:
getMaximumIndex
in classBuildableType
-
compareTo
public int compareTo(FreeColObject other)
Base for Comparable implementations.- Specified by:
compareTo
in interfacejava.lang.Comparable<FreeColObject>
- Overrides:
compareTo
in classFreeColObject
- Parameters:
other
- The otherFreeColObject
subclass 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:
copyIn
in classBuildableType
- 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 classBuildableType
- 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 classBuildableType
- 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 classBuildableType
- 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 classBuildableType
- 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.
-
-