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 intbaseDefenceThe defence of this UnitType.private intbaseOffenceThe offence of this UnitType.private static java.lang.StringCONSUMES_TAGprivate TypeCountMap<GoodsType>consumptionThe goods consumed per turn when in a settlement.static intDEFAULT_DEFENCEThe default offence value.static intDEFAULT_OFFENCEThe default offence value.private static java.lang.StringDEFAULT_ROLE_TAGprivate static java.lang.StringDEFAULT_UNIT_TAGprivate RoledefaultRoleThe default role for a unit of this type.private booleandefaultUnitTypeIs this the default unit type?private static java.lang.StringDEFENCE_TAGstatic java.util.Comparator<UnitType>defenceComparatorComparator for defence ability.private static java.lang.StringDOWNGRADE_TAGprivate static java.lang.StringEXPERT_PRODUCTION_TAGprivate GoodsTypeexpertProductionThe expert production of this UnitType.private static java.lang.StringHIT_POINTS_TAGprivate inthitPointsThe number of hit points this UnitType has.private static java.lang.StringLINE_OF_SIGHT_TAGprivate intlineOfSightThe maximum distance of tiles this UnitType can observe.private static java.lang.StringMAXIMUM_ATTRITION_TAGprivate static java.lang.StringMAXIMUM_EXPERIENCE_TAGprivate intmaximumAttritionThe maximum attrition this UnitType can accumulate without being destroyed.private intmaximumExperienceThe maximum experience a unit of this type can accumulate.private static java.lang.StringMERCENARY_PRICE_TAGprivate intmercenaryPriceThe optional price of this UnitType for use by mercenary forces.private intmovementThe initial moves of this UnitType.private static java.lang.StringMOVEMENT_TAGprivate static java.lang.StringOFFENCE_TAGprivate static java.lang.StringOLD_DEFAULT_EQUIPMENT_TAGprivate static java.lang.StringOLD_DEFAULT_UNIT_TAGprivate static java.lang.StringOLD_HIT_POINTS_TAGprivate static java.lang.StringOLD_LINE_OF_SIGHT_TAGprivate static java.lang.StringOLD_MAXIMUM_ATTRITION_TAGprivate static java.lang.StringOLD_MAXIMUM_EXPERIENCE_TAGprivate static java.lang.StringOLD_RECRUIT_PROBABILITY_TAGprivate static java.lang.StringOLD_SCORE_VALUE_TAGprivate static java.lang.StringOLD_SKILL_TAUGHT_TAGprivate static java.lang.StringOLD_SPACE_TAKEN_TAGprivate intpriceThe price of this UnitType.private static java.lang.StringPRICE_TAGprivate intpriorityConsumption order.private static java.lang.StringPRIORITY_TAGprivate static java.lang.StringRECRUIT_PROBABILITY_TAGprivate intrecruitProbabilityThe probability of recruiting a Unit of this type in Europe.private static java.lang.StringSCORE_VALUE_TAGprivate intscoreValueHow much a Unit of this type contributes to the Player's score.private intskillThe skill level of this UnitType.private static java.lang.StringSKILL_TAGprivate static java.lang.StringSKILL_TAUGHT_TAGprivate UnitTypeskillTaughtThe skill this UnitType teaches, mostly its own.private intspaceThe capacity of this UnitType.private static java.lang.StringSPACE_TAGprivate static java.lang.StringSPACE_TAKEN_TAGprivate intspaceTakenThe space taken by this UnitType.static java.lang.StringTAGprivate static java.lang.StringUNIT_TAGprivate static java.lang.StringUPGRADE_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 newUnitTypeinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddConsumption(GoodsType type, int amount)Add consumption.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.booleancanBuildColony()Is this unit type able to build a colony?booleancanCarryGoods()Can this unit type carry goods?booleancanCarryUnits()Can this unit type carry units?booleancanMoveToHighSeas()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.intgetBaseDefence()Get the base defence value.intgetBaseOffence()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.intgetConsumptionOf(GoodsType goodsType)Gets the number of units of the given GoodsType this UnitType consumes per turn (when in a settlement).RolegetDefaultRole()Gets the default role of this unit type, mostly model.role.default.doublegetDefence()Get the total defence of this unit type.java.lang.StringgetDisplayRoleId()Get a role identifier for display routines to use for this unit type.GoodsTypegetExpertProduction()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.intgetHitPoints()Get the unit type hit points.intgetLineOfSight()Get the `line of sight' distance (in tiles).intgetMaximumAttrition()Get the maximum attrition for this unit type (greater attrition than this destroys the unit).intgetMaximumExperience()Get the maximum experience required a unit of this type may achieve.intgetMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)intgetMercenaryPrice()Get the special price used by mercenary forces when there is no standard base price (e.g.intgetMinimumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)intgetMovement()Get the base movement of this unit type.doublegetOffence()Get the offence of this unit type.intgetPrice()Get the base price of this unit type.intgetPriority()The priority of this Consumer.intgetRecruitProbability()Get the relative probability of recruiting this unit in Europe.intgetScoreValue()Gets the score for acquiring a unit of this type.intgetSkill()Get the skill level associated with this unit type.UnitTypegetSkillTaught()Get the skill taught by this unit type.intgetSpace()Get the space this unit type has to carry cargo.intgetSpaceTaken()Gets the number of cargo slots a unit of this type takes on a carrier.UnitTypegetTeachingType(UnitType teacherType)Get the type that this unit type can be educated to by a teacher unit type, if any.java.lang.StringgetWorkingAsKey()Get a key for the working as this unit type message.java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleanhasMaximumAttrition()Is this unit type subject to attrition?booleanhasPrice()Does this UnitType have a price?booleanhasSkill()Does this UnitType have a skill?booleanisDefaultUnitType()Is this the default unit type?booleanisDefensive()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.booleanisNaval()Is this a naval unit type?booleanisOffensive()Is this an offensive unit type?booleanisPerson()Is this a person, not a ship or wagon?booleanisRecruitable()Is this UnitType recruitable in Europe?protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.protected voidsetConsumption(TypeCountMap<GoodsType> consumption)Set the consumption map.voidsetMercenaryPrice(int price)Set the mercenary price.voidsetSkill(int newSkill)Set the skill level associated with this unit type.voidsetSpace(int newSpace)Set the space this unit type has to carry cargo.voidsetSpaceTaken(int newSpaceTaken)Set the number of cargo slots a unit of this type takes on a carrier.java.lang.StringtoString()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, 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 newUnitTypeinstance.- Parameters:
id- The object identifier.specification- TheSpecificationto 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- TheUnitTypeof the teacher.- Returns:
- The
UnitTypethat 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- TheGoodsTypeto consume.- Returns:
- The amount of goods consumed per turn.
-
addConsumption
private void addConsumption(GoodsType type, int amount)
Add consumption.- Parameters:
type- TheGoodsTypeto 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:
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
-
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.
-
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.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildrenin 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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColSpecObjectType
-
-