Package net.sf.freecol.common.model
Class BuildableType
- 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
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Named
,ObjectWithId
- Direct Known Subclasses:
BuildingType
,Role
,UnitType
public abstract class BuildableType extends FreeColSpecObjectType
Contains information on buildable types.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
DEFAULT_REQUIRED_POPULATION
The required population for an ordinary buildable.private java.util.List<Limit>
limits
Limits on the production of this type.private static java.lang.String
REQUIRED_ABILITY_TAG
private static java.lang.String
REQUIRED_GOODS_TAG
static java.lang.String
REQUIRED_POPULATION_TAG
private java.util.Map<java.lang.String,java.lang.Boolean>
requiredAbilities
Stores the abilities required by this Type.private java.util.List<AbstractGoods>
requiredGoods
A list of AbstractGoods required to build this type.private int
requiredPopulation
The minimum population that a Colony needs in order to build this type.-
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 BuildableType(java.lang.String id, Specification specification)
Creates a new buildable type.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private void
addLimit(Limit limit)
Add a new limit.void
addRequiredAbility(java.lang.String tag, boolean value)
Add a new required ability.private void
addRequiredGoods(AbstractGoods ag)
Add a new goods requirement.abstract 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.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.StringTemplate
getCurrentlyBuildingLabel()
Get a label describing this buildable type as being currently built.java.util.List<Limit>
getLimits()
Get the limits on this buildable.int
getMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
int
getMinimumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
java.util.Map<java.lang.String,java.lang.Boolean>
getRequiredAbilities()
Gets the abilities required by this type.int
getRequiredAmountOf(GoodsType type)
Get the amount required of a givenGoodsType
to build an instance of this buildable.java.util.stream.Stream<AbstractGoods>
getRequiredGoods()
Get the goods required to build an instance of this buildable as a stream.java.util.List<AbstractGoods>
getRequiredGoodsList()
Get the goods required to build an instance of this buildable.int
getRequiredPopulation()
Get the population required to build this buildable type.boolean
isAvailableTo(FreeColObject... fco)
Is this buildable available to a given FreeColObject?boolean
needsGoodsToBuild()
Does this buildable need goods to build?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
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.void
removeRequiredAbility(java.lang.String tag)
Remove a required ability.boolean
requiresAbility(java.lang.String key)
void
setLimits(java.util.List<Limit> newLimits)
Set the limits on this buildable.void
setRequiredAbilities(java.util.Map<java.lang.String,java.lang.Boolean> abilities)
Sets the abilities required by this type.void
setRequiredGoods(java.util.List<AbstractGoods> goods)
Set the goods required to build an instance of this buildable.void
setRequiredPopulation(int newPopulation)
Set the population required to build this buildable type.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.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, compareTo, 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, getXMLTagName, 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
-
-
-
-
Field Detail
-
DEFAULT_REQUIRED_POPULATION
private static final int DEFAULT_REQUIRED_POPULATION
The required population for an ordinary buildable.- See Also:
- Constant Field Values
-
requiredPopulation
private int requiredPopulation
The minimum population that a Colony needs in order to build this type.
-
requiredAbilities
private java.util.Map<java.lang.String,java.lang.Boolean> requiredAbilities
Stores the abilities required by this Type.
-
requiredGoods
private java.util.List<AbstractGoods> requiredGoods
A list of AbstractGoods required to build this type.
-
limits
private java.util.List<Limit> limits
Limits on the production of this type.
-
REQUIRED_ABILITY_TAG
private static final java.lang.String REQUIRED_ABILITY_TAG
- See Also:
- Constant Field Values
-
REQUIRED_GOODS_TAG
private static final java.lang.String REQUIRED_GOODS_TAG
- See Also:
- Constant Field Values
-
REQUIRED_POPULATION_TAG
public static final java.lang.String REQUIRED_POPULATION_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BuildableType
public BuildableType(java.lang.String id, Specification specification)
Creates a new buildable type.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
-
Method Detail
-
getRequiredPopulation
public int getRequiredPopulation()
Get the population required to build this buildable type.- Returns:
- The population required.
-
setRequiredPopulation
public void setRequiredPopulation(int newPopulation)
Set the population required to build this buildable type.- Parameters:
newPopulation
- The new population required.
-
getRequiredAbilities
public java.util.Map<java.lang.String,java.lang.Boolean> getRequiredAbilities()
Gets the abilities required by this type.- Returns:
- A copy of the required abilities map.
-
requiresAbility
public boolean requiresAbility(java.lang.String key)
-
setRequiredAbilities
public void setRequiredAbilities(java.util.Map<java.lang.String,java.lang.Boolean> abilities)
Sets the abilities required by this type.- Parameters:
abilities
- The new required abilities.
-
addRequiredAbility
public void addRequiredAbility(java.lang.String tag, boolean value)
Add a new required ability. Public for specification fixes.- Parameters:
tag
- The ability name.value
- The ability value.
-
removeRequiredAbility
public void removeRequiredAbility(java.lang.String tag)
Remove a required ability. Public for specification fixes.- Parameters:
tag
- The ability name to remove.
-
isAvailableTo
public boolean isAvailableTo(FreeColObject... fco)
Is this buildable available to a given FreeColObject?- Parameters:
fco
- TheFreeColObject
s to check.- Returns:
- True if the buildable is available.
-
getRequiredGoodsList
public java.util.List<AbstractGoods> getRequiredGoodsList()
Get the goods required to build an instance of this buildable. Note we must take care to return a deep copy, as these lists are subject to complex manipulations in the role code.- Returns:
- A deep copy of the list of required goods.
-
getRequiredGoods
public java.util.stream.Stream<AbstractGoods> getRequiredGoods()
Get the goods required to build an instance of this buildable as a stream.- Returns:
- A stream of the required goods.
-
setRequiredGoods
public void setRequiredGoods(java.util.List<AbstractGoods> goods)
Set the goods required to build an instance of this buildable.- Parameters:
goods
- The new required goods.
-
getRequiredAmountOf
public int getRequiredAmountOf(GoodsType type)
Get the amount required of a givenGoodsType
to build an instance of this buildable.- Parameters:
type
- TheGoodsType
to check.- Returns:
- The amount of goods required.
-
addRequiredGoods
private void addRequiredGoods(AbstractGoods ag)
Add a new goods requirement.- Parameters:
ag
- The requiredAbstractGoods
to add.
-
needsGoodsToBuild
public boolean needsGoodsToBuild()
Does this buildable need goods to build?- Returns:
- True if goods are required to build this buildable.
-
getLimits
public java.util.List<Limit> getLimits()
Get the limits on this buildable.- Returns:
- A list of
Limit
s.
-
setLimits
public void setLimits(java.util.List<Limit> newLimits)
Set the limits on this buildable.- Parameters:
newLimits
- The newLimits
value.
-
addLimit
private void addLimit(Limit limit)
Add a new limit.- Parameters:
limit
- TheLimit
to add.
-
getCurrentlyBuildingLabel
public StringTemplate getCurrentlyBuildingLabel()
Get a label describing this buildable type as being currently built.- Returns:
- A suitable label.
-
canBeBuiltInColony
public abstract 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.- 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)
-
getMaximumIndex
public int getMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColSpecObjectType
- 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 classFreeColObject
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- Parameters:
xr
- TheFreeColXMLReader
to 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:
readChildren
in classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
-