net.sf.freecol.common.model
Class UnitType

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObjectType
          extended by net.sf.freecol.common.model.BuildableType
              extended by net.sf.freecol.common.model.UnitType
All Implemented Interfaces:
java.lang.Comparable<UnitType>, Consumer

public final class UnitType
extends BuildableType
implements java.lang.Comparable<UnitType>, Consumer


Field Summary
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  EquipmentType defaultEquipment
          Describe defaultEquipment here.
private  int defence
          The defence of this UnitType.
private  GoodsType expertProduction
          The expert production of this UnitType.
private  int hitPoints
          The number of hit points this UnitType has.
private  int lineOfSight
          The maximum distance of tiles this UnitType can observe.
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  int movement
          The initial moves of this UnitType.
private  int offence
          The offence of this UnitType.
private  int price
          The price of this UnitType.
private  int recruitProbability
          The probability of recruiting a Unit of this type in Europe.
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  UnitType skillTaught
          The skill this UnitType teaches, mostly its own.
private  int space
          The capacity of this UnitType.
private  int spaceTaken
          The space taken by this UnitType.
private  java.util.List<UnitTypeChange> typeChanges
          The possible type changes for this unit type.
 
Fields inherited from class net.sf.freecol.common.model.BuildableType
NOTHING
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, logger, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Fields inherited from interface net.sf.freecol.common.model.Consumer
BUILDING_PRIORITY, COLONY_PRIORITY, COMPARATOR, POPULATION_PRIORITY, UNIT_PRIORITY
 
Constructor Summary
UnitType(java.lang.String id, Specification specification)
          Creates a new UnitType instance.
 
Method Summary
 boolean canBeBuilt()
          Returns true if this UnitType can be built.
 boolean canBeUpgraded(UnitType newType, UnitTypeChange.ChangeType changeType)
          Return true if this UnitType can be upgraded to the given UnitType by the given means of education.
 boolean canCarryGoods()
          Returns true if Units of this type can carry Goods.
 boolean canCarryUnits()
          Returns true if Units of this type can carry other Units.
 int compareTo(UnitType other)
          
 java.util.List<AbstractGoods> getConsumedGoods()
          Returns a list of GoodsTypes this Consumer consumes.
 int getConsumptionOf(GoodsType goodsType)
          Returns the number of units of the given GoodsType this UnitType consumes per turn (when in a settlement).
 EquipmentType[] getDefaultEquipment()
           
 EquipmentType getDefaultEquipmentType()
          Get the DefaultEquipment value.
 int getDefence()
          Get the Defence value.
 int getEducationTurns(UnitType unitType)
          Get the EducationTurns value.
 UnitType getEducationUnit(int maximumSkill)
          Get a UnitType to learn with a level skill less or equal than given level
 GoodsType getExpertProduction()
          Get the ExpertProduction value.
 int getHitPoints()
          Get the HitPoints value.
 int getLineOfSight()
          Get the LineOfSight value.
 int getMaximumAttrition()
          Get the MaximumAttrition value.
 int getMaximumExperience()
          Get the MaximumExperience value.
 int getMovement()
          Get the Movement value.
 int getOffence()
          Get the Offence value.
 int getPrice()
          Get the Price value.
 int getPriority()
          The priority of this Consumer.
 int getRecruitProbability()
          Get the RecruitProbability value.
 int getScoreValue()
          Get the ScoreValue value.
 int getSkill()
          Get the Skill value.
 UnitType getSkillTaught()
          Get the SkillTaught value.
 int getSpace()
          Get the Space value.
 int getSpaceTaken()
          Get the SpaceTaken value.
 UnitType getTargetType(UnitTypeChange.ChangeType changeType, Player player)
          Describe getUnitTypeChange method here.
 java.util.List<UnitTypeChange> getTypeChanges()
           
 UnitTypeChange getUnitTypeChange(UnitType newType)
          Returns the UnitTypeChange associated with the given UnitType, or null if there is none.
 UnitTypeChange getUnitTypeChange(UnitTypeChange.ChangeType changeType, Player player)
          Describe getUnitTypeChange method here.
 java.util.List<UnitType> getUnitTypesLearntInLostCity()
          Get a list of UnitType which can learn in a lost city rumour
 java.lang.String getWorkingAsKey()
           
static java.lang.String getXMLElementTagName()
          Returns the tag name of the root element representing this object.
 boolean hasPrice()
          Returns true if this UnitType has a price.
 boolean hasSkill()
          Returns true if this UnitType has a skill.
 boolean isAvailableTo(Player player)
          Returns true if the UnitType is available to the given Player.
 boolean isNaval()
          Is this a naval unit type?
 boolean isRecruitable()
          If this UnitType is recruitable in Europe
protected  void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads the attributes of this object from an XML stream.
protected  void readChild(javax.xml.stream.XMLStreamReader in)
          Reads a child object.
 void setDefaultEquipmentType(EquipmentType newDefaultEquipment)
          Set the DefaultEquipment value.
 void setDefence(int newDefence)
          Set the Defence value.
 void setExpertProduction(GoodsType newExpertProduction)
          Set the ExpertProduction value.
 void setHitPoints(int newHitPoints)
          Set the HitPoints value.
 void setLineOfSight(int newLineOfSight)
          Set the LineOfSight value.
 void setMaximumAttrition(int newMaximumAttrition)
          Set the MaximumAttrition value.
 void setMaximumExperience(int newMaximumExperience)
          Set the MaximumExperience value.
 void setMovement(int newMovement)
          Set the Movement value.
 void setOffence(int newOffence)
          Set the Offence value.
 void setPrice(int newPrice)
          Set the Price value.
 void setRecruitProbability(int newRecruitProbability)
          Set the RecruitProbability value.
 void setScoreValue(int newScoreValue)
          Set the ScoreValue value.
 void setSkill(int newSkill)
          Set the Skill value.
 void setSkillTaught(UnitType newSkillTaught)
          Set the SkillTaught value.
 void setSpace(int newSpace)
          Set the Space value.
 void setSpaceTaken(int newSpaceTaken)
          Set the SpaceTaken value.
 java.lang.String toString()
          Debug print helper.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          Makes an XML-representation of this object.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          Write the attributes of this object to a stream.
protected  void writeChildren(javax.xml.stream.XMLStreamWriter out)
          Write the children of this object to a stream.
 
Methods inherited from class net.sf.freecol.common.model.BuildableType
getAbilitiesRequired, getAmountRequiredOf, getGoodsRequired, getLimits, getPopulationRequired, needsGoodsToBuild, setGoodsRequired, setLimits, setPopulationRequired
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObjectType
addAbility, addModifier, applyDifficultyLevel, getDescriptionKey, getFeatureContainer, getIndex, getModifierIndex, getModifierIndex, getModifierSet, getNameKey, hasAbility, hasAbility, isAbstractType, readChildren, setAbstractType, setFeatureContainer, setIndex, setModifierIndex, toXMLImpl
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, hasAttribute, hasListeners, readAttributes, readChild, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Consumer
getModifierSet, hasAbility
 

Field Detail

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

offence

private int offence
The offence of this UnitType. Only Units with an offence value greater than zero can attack.


defence

private int defence
The defence of this UnitType.


space

private int space
The capacity of this UnitType.


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.


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.


skillTaught

private UnitType skillTaught
The skill this UnitType teaches, mostly its own.


defaultEquipment

private EquipmentType defaultEquipment
Describe defaultEquipment here.


consumption

private TypeCountMap<GoodsType> consumption
The goods consumed per turn when in a settlement.


typeChanges

private java.util.List<UnitTypeChange> typeChanges
The possible type changes for this unit type.

Constructor Detail

UnitType

public UnitType(java.lang.String id,
                Specification specification)
Creates a new UnitType instance.

Method Detail

getWorkingAsKey

public final java.lang.String getWorkingAsKey()

canCarryUnits

public boolean canCarryUnits()
Returns true if Units of this type can carry other Units.

Returns:
a boolean value

canCarryGoods

public boolean canCarryGoods()
Returns true if Units of this type can carry Goods.

Returns:
a boolean value

getScoreValue

public int getScoreValue()
Get the ScoreValue value.

Returns:
an int value

setScoreValue

public void setScoreValue(int newScoreValue)
Set the ScoreValue value.

Parameters:
newScoreValue - The new ScoreValue value.

getOffence

public int getOffence()
Get the Offence value.

Returns:
an int value

setOffence

public void setOffence(int newOffence)
Set the Offence value.

Parameters:
newOffence - The new Offence value.

getDefence

public int getDefence()
Get the Defence value.

Returns:
an int value

setDefence

public void setDefence(int newDefence)
Set the Defence value.

Parameters:
newDefence - The new Defence value.

getLineOfSight

public int getLineOfSight()
Get the LineOfSight value.

Returns:
an int value

setLineOfSight

public void setLineOfSight(int newLineOfSight)
Set the LineOfSight value.

Parameters:
newLineOfSight - The new Defence value.

getSpace

public int getSpace()
Get the Space value.

Returns:
an int value

setSpace

public void setSpace(int newSpace)
Set the Space value.

Parameters:
newSpace - The new Space value.

getHitPoints

public int getHitPoints()
Get the HitPoints value.

Returns:
an int value

setHitPoints

public void setHitPoints(int newHitPoints)
Set the HitPoints value.

Parameters:
newHitPoints - The new HitPoints value.

getSpaceTaken

public int getSpaceTaken()
Get the SpaceTaken value.

Returns:
an int value

setSpaceTaken

public void setSpaceTaken(int newSpaceTaken)
Set the SpaceTaken value.

Parameters:
newSpaceTaken - The new SpaceTaken value.

isRecruitable

public boolean isRecruitable()
If this UnitType is recruitable in Europe

Returns:
an boolean value

getRecruitProbability

public int getRecruitProbability()
Get the RecruitProbability value.

Returns:
an int value

setRecruitProbability

public void setRecruitProbability(int newRecruitProbability)
Set the RecruitProbability value.

Parameters:
newRecruitProbability - The new RecruitProbability value.

getSkill

public int getSkill()
Get the Skill value.

Returns:
an int value

setSkill

public void setSkill(int newSkill)
Set the Skill value.

Parameters:
newSkill - The new Skill value.

getPrice

public int getPrice()
Get the Price value.

Returns:
an int value This returns the base price of the UnitType For the actual price of the unit, use Europe.getUnitPrice(UnitType)

setPrice

public void setPrice(int newPrice)
Set the Price value.

Parameters:
newPrice - The new Price value.

getMovement

public int getMovement()
Get the Movement value.

Returns:
an int value

setMovement

public void setMovement(int newMovement)
Set the Movement value.

Parameters:
newMovement - The new Movement value.

getMaximumExperience

public final int getMaximumExperience()
Get the MaximumExperience value.

Returns:
an int value

setMaximumExperience

public final void setMaximumExperience(int newMaximumExperience)
Set the MaximumExperience value.

Parameters:
newMaximumExperience - The new MaximumExperience value.

getMaximumAttrition

public int getMaximumAttrition()
Get the MaximumAttrition value.

Returns:
an int value

setMaximumAttrition

public void setMaximumAttrition(int newMaximumAttrition)
Set the MaximumAttrition value.

Parameters:
newMaximumAttrition - The new MaximumAttrition value.

getExpertProduction

public GoodsType getExpertProduction()
Get the ExpertProduction value.

Returns:
a GoodsType value

setExpertProduction

public void setExpertProduction(GoodsType newExpertProduction)
Set the ExpertProduction value.

Parameters:
newExpertProduction - The new ExpertProduction value.

getDefaultEquipmentType

public EquipmentType getDefaultEquipmentType()
Get the DefaultEquipment value.

Returns:
an EquipmentType value

setDefaultEquipmentType

public void setDefaultEquipmentType(EquipmentType newDefaultEquipment)
Set the DefaultEquipment value.

Parameters:
newDefaultEquipment - The new DefaultEquipment value.

getDefaultEquipment

public EquipmentType[] getDefaultEquipment()

getTypeChanges

public java.util.List<UnitTypeChange> getTypeChanges()

getSkillTaught

public UnitType getSkillTaught()
Get the SkillTaught value.

Returns:
an UnitType value

setSkillTaught

public void setSkillTaught(UnitType newSkillTaught)
Set the SkillTaught value.

Parameters:
newSkillTaught - The new SkillTaught value.

isAvailableTo

public boolean isAvailableTo(Player player)
Returns true if the UnitType is available to the given Player.

Parameters:
player - a Player value
Returns:
a boolean value

getTargetType

public UnitType getTargetType(UnitTypeChange.ChangeType changeType,
                              Player player)
Describe getUnitTypeChange method here.

Parameters:
changeType - an UnitTypeChange.Type value
player - a Player value
Returns:
an UnitType value

getUnitTypeChange

public UnitTypeChange getUnitTypeChange(UnitTypeChange.ChangeType changeType,
                                        Player player)
Describe getUnitTypeChange method here.

Parameters:
changeType - an UnitTypeChange.Type value
player - a Player value
Returns:
an UnitType value

getUnitTypeChange

public UnitTypeChange getUnitTypeChange(UnitType newType)
Returns the UnitTypeChange associated with the given UnitType, or null if there is none.

Parameters:
newType - the target UnitType
Returns:
the type change

canBeUpgraded

public boolean canBeUpgraded(UnitType newType,
                             UnitTypeChange.ChangeType changeType)
Return true if this UnitType can be upgraded to the given UnitType by the given means of education. If the given UnitType is null, return true if the UnitType can be upgraded to any other UnitType by the given means of education.

Parameters:
newType - The UnitType to learn (may be null in the case of attempting to move to a native settlement when the skill taught there is still unknown).
changeType - an ChangeType value
Returns:
true if can learn the given UnitType

getUnitTypesLearntInLostCity

public java.util.List<UnitType> getUnitTypesLearntInLostCity()
Get a list of UnitType which can learn in a lost city rumour

Returns:
UnitType with a skill equal or less than given maximum

getEducationUnit

public UnitType getEducationUnit(int maximumSkill)
Get a UnitType to learn with a level skill less or equal than given level

Parameters:
maximumSkill - the maximum level skill which we are searching for
Returns:
UnitType with a skill equal or less than given maximum

getEducationTurns

public int getEducationTurns(UnitType unitType)
Get the EducationTurns value.

Returns:
a int value

isNaval

public boolean isNaval()
Is this a naval unit type?

Returns:
True if this is a naval unit type.

hasSkill

public boolean hasSkill()
Returns true if this UnitType has a skill.

Returns:
a boolean value

canBeBuilt

public boolean canBeBuilt()
Returns true if this UnitType can be built.

Returns:
a boolean value

hasPrice

public boolean hasPrice()
Returns true if this UnitType has a price.

Returns:
a boolean value

getConsumptionOf

public int getConsumptionOf(GoodsType goodsType)
Returns the number of units of the given GoodsType this UnitType consumes per turn (when in a settlement).

Returns:
units consumed

compareTo

public int compareTo(UnitType other)

Specified by:
compareTo in interface java.lang.Comparable<UnitType>

getConsumedGoods

public java.util.List<AbstractGoods> getConsumedGoods()
Returns a list of GoodsTypes this Consumer consumes.

Specified by:
getConsumedGoods in interface Consumer
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 interface Consumer
Returns:
an int value

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
Makes an XML-representation of this object.

Overrides:
toXMLImpl in class FreeColGameObjectType
Parameters:
out - The output stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                        throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream.

Overrides:
writeAttributes in class BuildableType
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

writeChildren

protected void writeChildren(javax.xml.stream.XMLStreamWriter out)
                      throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream.

Overrides:
writeChildren in class BuildableType
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readAttributes

protected void readAttributes(javax.xml.stream.XMLStreamReader in)
                       throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.

Overrides:
readAttributes in class FreeColGameObjectType
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

readChild

protected void readChild(javax.xml.stream.XMLStreamReader in)
                  throws javax.xml.stream.XMLStreamException
Reads a child object.

Overrides:
readChild in class BuildableType
Parameters:
in - The XML stream to read.
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

toString

public java.lang.String toString()
Debug print helper.

Overrides:
toString in class FreeColGameObjectType

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Returns the tag name of the root element representing this object.

Returns:
"unit-type".