Package net.sf.freecol.common.model
Class UnitType
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Consumer
,Named
,ObjectWithId
public final class UnitType extends BuildableType implements Consumer
The various types of units in FreeCol.
-
-
Field Summary
Fields Modifier and Type Field Description private int
baseDefence
The defence of this UnitType.private int
baseOffence
The offence of this UnitType.private static java.lang.String
CONSUMES_TAG
private TypeCountMap<GoodsType>
consumption
The goods consumed per turn when in a settlement.static int
DEFAULT_DEFENCE
The default offence value.static int
DEFAULT_OFFENCE
The default offence value.private static java.lang.String
DEFAULT_ROLE_TAG
private static java.lang.String
DEFAULT_UNIT_TAG
private Role
defaultRole
The default role for a unit of this type.private boolean
defaultUnitType
Is this the default unit type?private static java.lang.String
DEFENCE_TAG
static java.util.Comparator<UnitType>
defenceComparator
Comparator for defence ability.private static java.lang.String
DOWNGRADE_TAG
private static java.lang.String
EXPERT_PRODUCTION_TAG
private GoodsType
expertProduction
The expert production of this UnitType.private static java.lang.String
HIT_POINTS_TAG
private int
hitPoints
The number of hit points this UnitType has.private static java.lang.String
LINE_OF_SIGHT_TAG
private int
lineOfSight
The maximum distance of tiles this UnitType can observe.private static java.lang.String
MAXIMUM_ATTRITION_TAG
private static java.lang.String
MAXIMUM_EXPERIENCE_TAG
private int
maximumAttrition
The maximum attrition this UnitType can accumulate without being destroyed.private int
maximumExperience
The maximum experience a unit of this type can accumulate.private static java.lang.String
MERCENARY_PRICE_TAG
private int
mercenaryPrice
The optional price of this UnitType for use by mercenary forces.private int
movement
The initial moves of this UnitType.private static java.lang.String
MOVEMENT_TAG
private static java.lang.String
OFFENCE_TAG
private static java.lang.String
OLD_DEFAULT_EQUIPMENT_TAG
private static java.lang.String
OLD_DEFAULT_UNIT_TAG
private static java.lang.String
OLD_HIT_POINTS_TAG
private static java.lang.String
OLD_LINE_OF_SIGHT_TAG
private static java.lang.String
OLD_MAXIMUM_ATTRITION_TAG
private static java.lang.String
OLD_MAXIMUM_EXPERIENCE_TAG
private static java.lang.String
OLD_RECRUIT_PROBABILITY_TAG
private static java.lang.String
OLD_SCORE_VALUE_TAG
private static java.lang.String
OLD_SKILL_TAUGHT_TAG
private static java.lang.String
OLD_SPACE_TAKEN_TAG
private int
price
The price of this UnitType.private static java.lang.String
PRICE_TAG
private int
priority
Consumption order.private static java.lang.String
PRIORITY_TAG
private static java.lang.String
RECRUIT_PROBABILITY_TAG
private int
recruitProbability
The probability of recruiting a Unit of this type in Europe.private static java.lang.String
SCORE_VALUE_TAG
private int
scoreValue
How much a Unit of this type contributes to the Player's score.private int
skill
The skill level of this UnitType.private static java.lang.String
SKILL_TAG
private static java.lang.String
SKILL_TAUGHT_TAG
private UnitType
skillTaught
The skill this UnitType teaches, mostly its own.private int
space
The capacity of this UnitType.private static java.lang.String
SPACE_TAG
private static java.lang.String
SPACE_TAKEN_TAG
private int
spaceTaken
The space taken by this UnitType.static java.lang.String
TAG
private static java.lang.String
UNIT_TAG
private static java.lang.String
UPGRADE_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
-
Fields inherited from interface net.sf.freecol.common.model.Consumer
BUILDING_PRIORITY, COLONY_PRIORITY, COMPARATOR, POPULATION_PRIORITY, UNIT_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description UnitType(java.lang.String id, Specification specification)
Creates a newUnitType
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addConsumption(GoodsType type, int amount)
Add consumption.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
canBuildColony()
Is this unit type able to build a colony?boolean
canCarryGoods()
Can this unit type carry goods?boolean
canCarryUnits()
Can this unit type carry units?boolean
canMoveToHighSeas()
Can this unit type move to the High Seas? ATM this is synonymous with being a naval unit, but we should use this routine instead of isNaval() in case this changes.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.int
getBaseDefence()
Get the base defence value.int
getBaseOffence()
Get the base offence value.java.util.List<AbstractGoods>
getConsumedGoods()
Returns a list of GoodsTypes this Consumer consumes.protected TypeCountMap<GoodsType>
getConsumption()
Get the consumption map.java.util.stream.Stream<Modifier>
getConsumptionModifiers(java.lang.String id)
Get the modifier set with the given id.int
getConsumptionOf(GoodsType goodsType)
Gets the number of units of the given GoodsType this UnitType consumes per turn (when in a settlement).Role
getDefaultRole()
Gets the default role of this unit type, mostly model.role.default.double
getDefence()
Get the total defence of this unit type.java.lang.String
getDisplayRoleId()
Get a role identifier for display routines to use for this unit type.GoodsType
getExpertProduction()
Get the type of goods this unit type has expert ability to produce.java.util.List<Role>
getExpertRoles()
Returns a list of roles for which a unit of this type is an expert.int
getHitPoints()
Get the unit type hit points.int
getLineOfSight()
Get the `line of sight' distance (in tiles).int
getMaximumAttrition()
Get the maximum attrition for this unit type (greater attrition than this destroys the unit).int
getMaximumExperience()
Get the maximum experience required a unit of this type may achieve.int
getMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
int
getMercenaryPrice()
Get the special price used by mercenary forces when there is no standard base price (e.g.int
getMinimumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
int
getMovement()
Get the base movement of this unit type.double
getOffence()
Get the offence of this unit type.int
getPrice()
Get the base price of this unit type.int
getPriority()
The priority of this Consumer.int
getRecruitProbability()
Get the relative probability of recruiting this unit in Europe.int
getScoreValue()
Gets the score for acquiring a unit of this type.int
getSkill()
Get the skill level associated with this unit type.UnitType
getSkillTaught()
Get the skill taught by this unit type.int
getSpace()
Get the space this unit type has to carry cargo.int
getSpaceTaken()
Gets the number of cargo slots a unit of this type takes on a carrier.UnitType
getTeachingType(UnitType teacherType)
Get the type that this unit type can be educated to by a teacher unit type, if any.java.lang.String
getWorkingAsKey()
Get a key for the working as this unit type message.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
hasMaximumAttrition()
Is this unit type subject to attrition?boolean
hasPrice()
Does this UnitType have a price?boolean
hasSkill()
Does this UnitType have a skill?boolean
isDefaultUnitType()
Is this the default unit type?boolean
isDefensive()
Is this a defensive unit type? Default defence is 1, same a for colonists, thus to be defensive, a colonist must have a military role.boolean
isNaval()
Is this a naval unit type?boolean
isOffensive()
Is this an offensive unit type?boolean
isPerson()
Is this a person, not a ship or wagon?boolean
isRecruitable()
Is this UnitType recruitable in Europe?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.protected void
setConsumption(TypeCountMap<GoodsType> consumption)
Set the consumption map.void
setMercenaryPrice(int price)
Set the mercenary price.void
setSkill(int newSkill)
Set the skill level associated with this unit type.void
setSpace(int newSpace)
Set the space this unit type has to carry cargo.void
setSpaceTaken(int newSpaceTaken)
Set the number of cargo slots a unit of this type takes on a carrier.java.lang.String
toString()
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, 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
-
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, 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
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
defenceComparator
public static final java.util.Comparator<UnitType> defenceComparator
Comparator for defence ability.
-
DEFAULT_OFFENCE
public static final int DEFAULT_OFFENCE
The default offence value.- See Also:
- Constant Field Values
-
DEFAULT_DEFENCE
public static final int DEFAULT_DEFENCE
The default offence value.- See Also:
- Constant Field Values
-
baseOffence
private int baseOffence
The offence of this UnitType. Only Units with an offence value greater than zero can attack.
-
baseDefence
private int baseDefence
The defence of this UnitType.
-
space
private int space
The capacity of this UnitType.
-
defaultUnitType
private boolean defaultUnitType
Is this the default unit type?
-
hitPoints
private int hitPoints
The number of hit points this UnitType has. At the moment, this is only used for ships. All other UnitTypes are downgraded or destroyed if they lose a battle.
-
spaceTaken
private int spaceTaken
The space taken by this UnitType.
-
skill
private int skill
The skill level of this UnitType.
-
price
private int price
The price of this UnitType.
-
mercenaryPrice
private int mercenaryPrice
The optional price of this UnitType for use by mercenary forces.
-
movement
private int movement
The initial moves of this UnitType.
-
lineOfSight
private int lineOfSight
The maximum distance of tiles this UnitType can observe.
-
recruitProbability
private int recruitProbability
The probability of recruiting a Unit of this type in Europe.
-
expertProduction
private GoodsType expertProduction
The expert production of this UnitType.
-
scoreValue
private int scoreValue
How much a Unit of this type contributes to the Player's score.
-
maximumExperience
private int maximumExperience
The maximum experience a unit of this type can accumulate.
-
maximumAttrition
private int maximumAttrition
The maximum attrition this UnitType can accumulate without being destroyed.
-
priority
private int priority
Consumption order.
-
skillTaught
private UnitType skillTaught
The skill this UnitType teaches, mostly its own.
-
defaultRole
private Role defaultRole
The default role for a unit of this type.
-
consumption
private TypeCountMap<GoodsType> consumption
The goods consumed per turn when in a settlement.
-
CONSUMES_TAG
private static final java.lang.String CONSUMES_TAG
- See Also:
- Constant Field Values
-
DEFAULT_ROLE_TAG
private static final java.lang.String DEFAULT_ROLE_TAG
- See Also:
- Constant Field Values
-
DEFAULT_UNIT_TAG
private static final java.lang.String DEFAULT_UNIT_TAG
- See Also:
- Constant Field Values
-
DEFENCE_TAG
private static final java.lang.String DEFENCE_TAG
- See Also:
- Constant Field Values
-
EXPERT_PRODUCTION_TAG
private static final java.lang.String EXPERT_PRODUCTION_TAG
- See Also:
- Constant Field Values
-
HIT_POINTS_TAG
private static final java.lang.String HIT_POINTS_TAG
- See Also:
- Constant Field Values
-
LINE_OF_SIGHT_TAG
private static final java.lang.String LINE_OF_SIGHT_TAG
- See Also:
- Constant Field Values
-
MERCENARY_PRICE_TAG
private static final java.lang.String MERCENARY_PRICE_TAG
- See Also:
- Constant Field Values
-
MOVEMENT_TAG
private static final java.lang.String MOVEMENT_TAG
- See Also:
- Constant Field Values
-
MAXIMUM_EXPERIENCE_TAG
private static final java.lang.String MAXIMUM_EXPERIENCE_TAG
- See Also:
- Constant Field Values
-
MAXIMUM_ATTRITION_TAG
private static final java.lang.String MAXIMUM_ATTRITION_TAG
- See Also:
- Constant Field Values
-
OFFENCE_TAG
private static final java.lang.String OFFENCE_TAG
- See Also:
- Constant Field Values
-
PRICE_TAG
private static final java.lang.String PRICE_TAG
- See Also:
- Constant Field Values
-
PRIORITY_TAG
private static final java.lang.String PRIORITY_TAG
- See Also:
- Constant Field Values
-
RECRUIT_PROBABILITY_TAG
private static final java.lang.String RECRUIT_PROBABILITY_TAG
- See Also:
- Constant Field Values
-
SCORE_VALUE_TAG
private static final java.lang.String SCORE_VALUE_TAG
- See Also:
- Constant Field Values
-
SKILL_TAG
private static final java.lang.String SKILL_TAG
- See Also:
- Constant Field Values
-
SKILL_TAUGHT_TAG
private static final java.lang.String SKILL_TAUGHT_TAG
- See Also:
- Constant Field Values
-
SPACE_TAG
private static final java.lang.String SPACE_TAG
- See Also:
- Constant Field Values
-
SPACE_TAKEN_TAG
private static final java.lang.String SPACE_TAKEN_TAG
- See Also:
- Constant Field Values
-
UNIT_TAG
private static final java.lang.String UNIT_TAG
- See Also:
- Constant Field Values
-
OLD_DEFAULT_EQUIPMENT_TAG
private static final java.lang.String OLD_DEFAULT_EQUIPMENT_TAG
- See Also:
- Constant Field Values
-
OLD_DEFAULT_UNIT_TAG
private static final java.lang.String OLD_DEFAULT_UNIT_TAG
- See Also:
- Constant Field Values
-
OLD_HIT_POINTS_TAG
private static final java.lang.String OLD_HIT_POINTS_TAG
- See Also:
- Constant Field Values
-
OLD_LINE_OF_SIGHT_TAG
private static final java.lang.String OLD_LINE_OF_SIGHT_TAG
- See Also:
- Constant Field Values
-
OLD_MAXIMUM_EXPERIENCE_TAG
private static final java.lang.String OLD_MAXIMUM_EXPERIENCE_TAG
- See Also:
- Constant Field Values
-
OLD_MAXIMUM_ATTRITION_TAG
private static final java.lang.String OLD_MAXIMUM_ATTRITION_TAG
- See Also:
- Constant Field Values
-
OLD_RECRUIT_PROBABILITY_TAG
private static final java.lang.String OLD_RECRUIT_PROBABILITY_TAG
- See Also:
- Constant Field Values
-
OLD_SCORE_VALUE_TAG
private static final java.lang.String OLD_SCORE_VALUE_TAG
- See Also:
- Constant Field Values
-
OLD_SKILL_TAUGHT_TAG
private static final java.lang.String OLD_SKILL_TAUGHT_TAG
- See Also:
- Constant Field Values
-
OLD_SPACE_TAKEN_TAG
private static final java.lang.String OLD_SPACE_TAKEN_TAG
- See Also:
- Constant Field Values
-
DOWNGRADE_TAG
private static final java.lang.String DOWNGRADE_TAG
- See Also:
- Constant Field Values
-
UPGRADE_TAG
private static final java.lang.String UPGRADE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UnitType
public UnitType(java.lang.String id, Specification specification)
Creates a newUnitType
instance.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
-
Method Detail
-
getWorkingAsKey
public final java.lang.String getWorkingAsKey()
Get a key for the working as this unit type message.- Returns:
- A message key.
-
canCarryUnits
public boolean canCarryUnits()
Can this unit type carry units?- Returns:
- True if units can be carried.
-
canCarryGoods
public boolean canCarryGoods()
Can this unit type carry goods?- Returns:
- True if goods can be carried.
-
getScoreValue
public int getScoreValue()
Gets the score for acquiring a unit of this type.- Returns:
- The score for this unit type.
-
getBaseOffence
public int getBaseOffence()
Get the base offence value.- Returns:
- The base offence value.
-
getOffence
public double getOffence()
Get the offence of this unit type.- Returns:
- The offence value.
-
isOffensive
public boolean isOffensive()
Is this an offensive unit type?- Returns:
- True if base offensive ability is greater than the default.
-
getBaseDefence
public int getBaseDefence()
Get the base defence value.- Returns:
- The defence value.
-
getDefence
public double getDefence()
Get the total defence of this unit type.- Returns:
- The defence value.
-
isDefensive
public boolean isDefensive()
Is this a defensive unit type? Default defence is 1, same a for colonists, thus to be defensive, a colonist must have a military role. Artillery of all sorts has higher defense so they are automatically defensive.- Returns:
- True if base defensive ability is greater than the default.
-
isDefaultUnitType
public boolean isDefaultUnitType()
Is this the default unit type?- Returns:
- True if this is the default unit type.
-
getLineOfSight
public int getLineOfSight()
Get the `line of sight' distance (in tiles).- Returns:
- The line of sight distance.
-
getSpace
public int getSpace()
Get the space this unit type has to carry cargo.- Returns:
- The cargo capacity of this unit type.
-
setSpace
public void setSpace(int newSpace)
Set the space this unit type has to carry cargo. Required by the test suite.- Parameters:
newSpace
- The new cargo capacity.
-
getHitPoints
public int getHitPoints()
Get the unit type hit points.- Returns:
- The hit points.
-
getSpaceTaken
public int getSpaceTaken()
Gets the number of cargo slots a unit of this type takes on a carrier.- Returns:
- The number of cargo slots.
-
setSpaceTaken
public void setSpaceTaken(int newSpaceTaken)
Set the number of cargo slots a unit of this type takes on a carrier. Required by the test suite.- Parameters:
newSpaceTaken
- The new number of cargo slots.
-
isRecruitable
public boolean isRecruitable()
Is this UnitType recruitable in Europe?- Returns:
- True if European-recruitable.
-
getRecruitProbability
public int getRecruitProbability()
Get the relative probability of recruiting this unit in Europe.- Returns:
- A relative probability.
-
getSkill
public int getSkill()
Get the skill level associated with this unit type.- Returns:
- The skill level.
-
setSkill
public void setSkill(int newSkill)
Set the skill level associated with this unit type. Required by the test suite.- Parameters:
newSkill
- The new skill level.
-
getPrice
public int getPrice()
Get the base price of this unit type. For the actual price of the unit, useEurope.getUnitPrice(UnitType)
- Returns:
- The base price.
-
getMercenaryPrice
public int getMercenaryPrice()
Get the special price used by mercenary forces when there is no standard base price (e.g. ManOWar).- Returns:
- The mercenary price.
-
setMercenaryPrice
public void setMercenaryPrice(int price)
Set the mercenary price.- Parameters:
price
- The mercenary price.
-
getMovement
public int getMovement()
Get the base movement of this unit type.- Returns:
- The base movement.
-
getMaximumExperience
public final int getMaximumExperience()
Get the maximum experience required a unit of this type may achieve.- Returns:
- The maximum experience.
-
hasMaximumAttrition
public boolean hasMaximumAttrition()
Is this unit type subject to attrition?- Returns:
- True if attrition can happen for this unit type.
-
getMaximumAttrition
public int getMaximumAttrition()
Get the maximum attrition for this unit type (greater attrition than this destroys the unit).- Returns:
- The maximum attrition.
-
getExpertProduction
public GoodsType getExpertProduction()
Get the type of goods this unit type has expert ability to produce.- Returns:
- The expert production
GoodsType
.
-
getSkillTaught
public UnitType getSkillTaught()
Get the skill taught by this unit type.- Returns:
- The skill taught by this unit type.
-
getDefaultRole
public Role getDefaultRole()
Gets the default role of this unit type, mostly model.role.default.- Returns:
- The default
Role
.
-
getExpertRoles
public java.util.List<Role> getExpertRoles()
Returns a list of roles for which a unit of this type is an expert.- Returns:
- a list of expert roles
-
getDisplayRoleId
public java.lang.String getDisplayRoleId()
Get a role identifier for display routines to use for this unit type.- Returns:
- A suitable role identifier for display purposes.
-
getTeachingType
public UnitType getTeachingType(UnitType teacherType)
Get the type that this unit type can be educated to by a teacher unit type, if any.- Parameters:
teacherType
- TheUnitType
of the teacher.- Returns:
- The
UnitType
that this unit type can be educated to by the teacher unit type, or null if education is not possible.
-
isNaval
public boolean isNaval()
Is this a naval unit type?- Returns:
- True if this is a naval unit type.
-
isPerson
public boolean isPerson()
Is this a person, not a ship or wagon?- Returns:
- True if this unit type represents a person
-
canBuildColony
public boolean canBuildColony()
Is this unit type able to build a colony?- Returns:
- True if this unit type can build colonies.
-
canMoveToHighSeas
public boolean canMoveToHighSeas()
Can this unit type move to the High Seas? ATM this is synonymous with being a naval unit, but we should use this routine instead of isNaval() in case this changes.- Returns:
- True if units of this type can move to the High Seas.
-
hasSkill
public boolean hasSkill()
Does this UnitType have a skill?- Returns:
- True if this unit type has a skill.
-
hasPrice
public boolean hasPrice()
Does this UnitType have a price?- Returns:
- True if the unit type has a price.
-
getConsumption
protected TypeCountMap<GoodsType> getConsumption()
Get the consumption map.- Returns:
- The map of the consumed goods.
-
setConsumption
protected void setConsumption(TypeCountMap<GoodsType> consumption)
Set the consumption map.- Parameters:
consumption
- The new map of the consumed goods.
-
getConsumptionOf
public int getConsumptionOf(GoodsType goodsType)
Gets the number of units of the given GoodsType this UnitType consumes per turn (when in a settlement).- Parameters:
goodsType
- TheGoodsType
to consume.- Returns:
- The amount of goods consumed per turn.
-
addConsumption
private void addConsumption(GoodsType type, int amount)
Add consumption.- Parameters:
type
- TheGoodsType
to consume.amount
- The amount of goods to consume.
-
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
-
getConsumedGoods
public java.util.List<AbstractGoods> getConsumedGoods()
Returns a list of GoodsTypes this Consumer consumes.- Specified by:
getConsumedGoods
in interfaceConsumer
- Returns:
- a
List
value
-
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:
getPriority
in interfaceConsumer
- Returns:
- an
int
value
-
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:
getConsumptionModifiers
in interfaceConsumer
- Parameters:
id
- The object identifier.- Returns:
- The stream of
Modifier
s found.
-
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.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColSpecObjectType
-
-