net.sf.freecol.common.model
Class Unit

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
          extended by net.sf.freecol.common.model.Unit
All Implemented Interfaces:
Consumer, Locatable, Location, Movable, Nameable, Ownable
Direct Known Subclasses:
ServerUnit

public class Unit
extends FreeColGameObject
implements Consumer, Locatable, Location, Movable, Nameable, Ownable

Represents all pieces that can be moved on the map-board. This includes: colonists, ships, wagon trains e.t.c.

Every Unit is owned by a Player and has a Location.


Nested Class Summary
static class Unit.MoveType
          A move type.
static class Unit.Role
          The roles a Unit can have.
static class Unit.UnitState
          A state a Unit can have.
 
Field Summary
protected  int attrition
          The attrition this unit has accumulated.
static java.lang.String CARGO_CHANGE
           
protected  int currentStop
          Which stop in a trade route the unit is going to.
protected  Location destination
           
protected  Location entryLocation
           
protected  TypeCountMap<EquipmentType> equipment
          The equipment this Unit carries.
static java.lang.String EQUIPMENT_CHANGE
           
private static java.lang.String EQUIPMENT_TAG
          XML tag name for equipment list.
protected  java.lang.String ethnicity
           
protected  int experience
           
private  GoodsType experienceType
          What type of goods this unit last earned experience producing.
protected  GoodsContainer goodsContainer
           
protected  int hitpoints
           
protected  IndianSettlement indianSettlement
           
protected  Location location
           
private static java.util.logging.Logger logger
           
protected  int movesLeft
           
protected  java.lang.String name
          The individual name of this unit, not of the unit type.
protected  java.lang.String nationality
           
protected  Player owner
           
protected  Unit.Role role
           
private static java.util.Comparator<Unit> skillLevelComp
           
protected  Unit.UnitState state
           
protected  Unit student
          The student of this Unit, if it has one.
protected  Unit teacher
          The teacher of this Unit, if it has one.
protected  TradeRoute tradeRoute
          The trade route this unit has.
protected  int treasureAmount
          To be used only for type == TREASURE_TRAIN
protected  int turnsOfTraining
           
protected  java.util.List<Unit> units
           
protected  UnitType unitType
           
protected  int visibleGoodsCount
          The amount of goods carried by this unit.
protected  TileImprovement workImprovement
          What is being improved (to be used only for PIONEERs - where they are working.
protected  int workLeft
          The number of turns until the work is finished, or '-1' if a Unit can stay in its state forever.
protected  GoodsType workType
          What type of goods this unit produces in its occupation.
 
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
UNITS_TAG_NAME
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, 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
protected Unit()
          Constructor for ServerUnit.
protected Unit(Game game)
          Constructor for ServerUnit.
  Unit(Game game, org.w3c.dom.Element e)
          Initialize this object from an XML-representation of this object.
  Unit(Game game, java.lang.String id)
          Initiates a new Unit with the given ID.
  Unit(Game game, javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 
Method Summary
 boolean add(Locatable locatable)
          Adds a locatable to this Unit.
 void addFeature(Feature feature)
          Add the given Feature to the Features Map.
private  boolean allowContact(Settlement settlement)
          Is this unit allowed to contact a settlement?
private  boolean allowMoveFrom(Tile from)
          Is this unit allowed to move from a source tile? Implements the restrictions on moving from water.
static boolean betterDefender(Unit defender, float defenderPower, Unit other, float otherPower)
          Is an alternate unit a better defender than the current choice.
 boolean canAdd(Locatable locatable)
          Checks wether or not the specified locatable may be added to this Unit.
 boolean canBeEquippedWith(EquipmentType equipmentType)
          Checks whether this unit can be equipped with the given EquipmentType at the current Location.
 boolean canBeStudent(Unit teacher)
          Returns true if this unit can be a student.
 boolean canBeStudent(UnitType typeStudent, UnitType typeTeacher)
          Returns true if this type of unit can be a student.
 boolean canBuildColony()
          Check if this unit can build a colony.
 EquipmentType canCaptureEquipment(EquipmentType equip, Unit loser)
          After winning a battle, can this unit the loser equipment?
 boolean canCaptureGoods()
          Returns true if this unit is a ship that can capture enemy goods.
 boolean canCarryGoods()
          Returns true if the Unit can carry Goods.
 boolean canCarryTreasure()
          Returns true if this unit can carry treasure (like a treasure train)
 boolean canCarryUnit(Unit u)
          Is this unit able to carry a specified one?
 boolean canCarryUnits()
          Returns true if the Unit can carry other Units.
 boolean canCashInTreasureTrain()
          Checks if the treasure train can be cashed in at it's current Location.
 boolean canCashInTreasureTrain(Location loc)
          Checks if the treasure train can be cashed in at the given Location.
 boolean canMoveToEurope()
          Checks if this Unit can be moved to Europe.
 java.util.List<EquipmentType> changeEquipment(EquipmentType type, int amount)
          Changes the equipment a unit has and returns a list of equipment it still has but needs to drop due to the changed equipment being incompatible.
 boolean checkSetState(Unit.UnitState s)
          Checks if a Unit can get the given state set.
 void clearEquipment()
          Clears all Equipment held by this unit.
 boolean contains(Locatable locatable)
          Checks if this Unit contains the specified Locatable.
 boolean couldMove()
          Returns true if this Unit could still be moved.
 void dispose()
          Removes all references to this object.
 java.util.List<FreeColGameObject> disposeList()
          Removes all references to this object.
 PathNode findPath(Tile end)
          Finds a shortest path from the current Tile to the one specified.
 PathNode findPath(Tile start, Tile end)
          Finds a shortest path from the current Tile to the one specified.
 PathNode findPath(Tile start, Tile end, Unit carrier)
          Finds a shortest path from the current Tile to the one specified.
 PathNode findPath(Tile start, Tile end, Unit carrier, CostDecider costDecider)
          Finds a shortest path from the current Tile to the one specified.
 PathNode findPathToEurope()
          Convenience wrapper to find a path to Europe for this unit.
 PathNode findPathToEurope(Tile start)
          Convenience wrapper to find a path to Europe for this unit.
 StringTemplate getApparentOwnerName()
          Get the name of the apparent owner of this Unit, (like getOwner().getNationAsString() but handles pirates)
 int getAttrition()
          Gets the attrition of this unit.
 TypeCountMap<EquipmentType> getAutomaticEquipment()
          Gets the available equipment that can be equipped automatically in case of an attack.
 EquipmentType getBestCombatEquipmentType(TypeCountMap<EquipmentType> equipment)
          Gets the best combat equipment type that this unit has.
 float getBurnProbability()
          Gets the probability that an attack by this unit will provoke natives to burn our missions.
 Colony getColony()
          Gets the Colony this unit is in.
 java.util.List<AbstractGoods> getConsumedGoods()
          Returns a list of GoodsTypes this Consumer consumes.
 float getConvertProbability()
          Gets the probability that an attack by this unit will provoke a native to convert.
 int getCurrentStop()
          Get the current stop.
 Location getDestination()
          Returns the destination of this unit.
 Location getEntryLocation()
          Gets the entry location for this unit to use when returning from Europe.
 TypeCountMap<EquipmentType> getEquipment()
          Get the Equipment value.
 int getEquipmentCount(EquipmentType equipmentType)
          Describe getEquipmentCount method here.
 StringTemplate getEquipmentLabel()
          Return a description of the unit's equipment.
 java.lang.String getEthnicity()
          Gets the ethnicity of this Unit.
 int getExperience()
          Gets the experience of this Unit at its current experienceType.
 GoodsType getExperienceType()
          Gets the type of goods this unit has accrued experience producing.
 Unit getFirstUnit()
          Gets the first Unit beeing carried by this Unit.
 Tile getFullEntryLocation()
          Gets the entry tile for this unit, or if null the default entry location for the owning player.
 GoodsContainer getGoodsContainer()
          Gets the GoodsContainer this Location use for storing it's goods.
 int getGoodsCount()
           
 java.util.Iterator<Goods> getGoodsIterator()
          Gets a Iterator of every Unit directly located on this Location.
 java.util.List<Goods> getGoodsList()
          Returns a List containing the goods carried by this unit.
 int getHitpoints()
          Returns the hitpoints.
 IndianSettlement getIndianSettlement()
          Gets the IndianSettlement that owns this unit.
 int getInitialMovesLeft()
          Gets the amount of moves this unit has at the beginning of each turn.
 StringTemplate getLabel()
          Describe getLabel method here.
private  Unit.MoveType getLandMoveType(Tile from, Tile target)
          Gets the type of a move that is made when moving a land unit to from one tile to another.
 Unit getLastUnit()
          Gets the last Unit beeing carried by this Unit.
private  Unit.MoveType getLearnMoveType(Tile from, Settlement settlement)
          Get the MoveType when moving a colonist to a settlement.
 int getLineOfSight()
          Gets the line of sight of this Unit.
 int getLoadableAmount(GoodsType type)
          Returns the amount of a GoodsType that could be loaded.
 Location getLocation()
          Gets the location of this Unit.
 StringTemplate getLocationName()
          Returns a name for this unit, as a location.
 StringTemplate getLocationNameFor(Player player)
          Returns the name for this unit, as a location, for a particular player.
private  Unit.MoveType getMissionaryMoveType(Tile from, Settlement settlement)
          Get the MoveType when moving a missionary to a settlement.
 java.util.Set<Modifier> getModifierSet(java.lang.String id)
          Get a modifier that applies to this Unit.
 java.util.Set<Modifier> getModifierSet(java.lang.String id, Ownable ownable)
          Get a modifier that applies to the given Ownable.
 int getMoveCost(Tile target)
          Gets the cost of moving this Unit onto the given Tile.
 int getMoveCost(Tile from, Tile target, int ml)
          Gets the cost of moving this Unit from the given Tile onto the given Tile.
 java.lang.String getMovesAsString()
           
 int getMovesLeft()
          Returns the amount of moves this Unit has left.
 Unit.MoveType getMoveType(Map.Direction direction)
          Gets the type of a move made in a specified direction.
 Unit.MoveType getMoveType(Tile target)
          Gets the type of a move that is made when moving from one tile to another.
 Unit.MoveType getMoveType(Tile from, Tile target, int ml)
          Gets the type of a move that is made when moving from one tile to another.
 java.lang.String getName()
          Describe getName method here.
 java.lang.String getNationality()
          Gets the nationality of this Unit.
private  Unit.MoveType getNavalMoveType(Tile from, Tile target)
          Gets the type of a move that is made when moving a naval unit from one tile to another.
 int getNeededTurnsOfTraining()
          Gets the number of turns this unit has to train to educate a student.
 int getNeededTurnsOfTraining(UnitType typeTeacher, UnitType typeStudent)
          Gets the number of turns this unit has to train to educate a student.
 Player getOwner()
          Gets the owner of this Unit.
 int getPriority()
          The priority of this Consumer.
 ProductionInfo getProductionInfo(java.util.List<AbstractGoods> input)
          Describe getProductionInfo method here.
 int getProductionOf(GoodsType goodsType, int base)
          Given a type of goods to produce in the field and a tile, returns the unit's potential to produce goods.
 Location getRepairLocation()
          Finds the closest Location to this tile where this ship can be repaired.
 Unit.Role getRole()
          Gets the Role of this Unit.
 int getSailTurns()
          Gets the number of turns this unit will need to sail to/from Europe.
private  Unit.MoveType getScoutMoveType(Tile from, Settlement settlement)
          Get the MoveType when moving a scout to a settlement.
 Settlement getSettlement()
          Gets the Settlement this unit is in.
 Unit.MoveType getSimpleMoveType(Map.Direction direction)
          Gets the type of a move made in a specified direction, without checking if the unit has moves left or logging errors.
 Unit.MoveType getSimpleMoveType(Tile target)
          Gets the type of a move that is made when moving from one tile to another, without checking if the unit has moves left or logging errors.
 Unit.MoveType getSimpleMoveType(Tile from, Tile target)
          Gets the type of a move that is made when moving from one tile to another, without checking if the unit has moves left or logging errors.
 int getSkillLevel()
          Gets the skill level.
static int getSkillLevel(UnitType unitType)
          Gets the skill level of the given type of Unit.
static java.util.Comparator<Unit> getSkillLevelComparator()
          Returns a Comparator that compares the skill levels of given units.
 int getSpaceLeft()
          Returns the amount of space left on this Unit.
 int getSpaceTaken()
          Gets the amount of space this Unit takes when put on a carrier.
 Unit.UnitState getState()
          Gets the state of this Unit.
 TradeRoute.Stop getStop()
          Get the stop the unit is heading for or at.
 Unit getStudent()
          Get the Student value.
 Unit getTeacher()
          Get the Teacher value.
 Tile getTile()
          Returns the Tile where this Unit is located.
private  Unit.MoveType getTradeMoveType(Settlement settlement)
          Get the MoveType when moving a trading unit to a settlement.
 TradeRoute getTradeRoute()
          Get the TradeRoute value.
 int getTransportFee()
          Return the fee that would have to be paid to transport this treasure to Europe.
 int getTreasureAmount()
          Returns the current amount of treasure in this unit.
 int getTurnsForRepair()
          Return how many turns left to be repaired
 int getTurnsOfTraining()
          Gets the number of turns this unit has been training.
 int getTurnsToReach(Location destination)
          Returns the number of turns this Unit will have to use in order to reach the given Location.
 int getTurnsToReach(Tile start, Tile end)
          Returns the number of turns this Unit will have to use in order to reach the given Tile.
 UnitType getType()
          Get the UnitType value.
 UnitType getTypeChange(UnitTypeChange.ChangeType change, Player owner)
          Get a type change for this unit.
 int getUnitCount()
          Gets the amount of Units at this Location.
 java.util.Iterator<Unit> getUnitIterator()
          Gets a Iterator of every Unit directly located on this Location.
 java.util.List<Unit> getUnitList()
          Gets a list of the units in this carrier unit.
static UnitType getUnitTypeTeaching(UnitType typeTeacher, UnitType typeStudent)
          Gets the UnitType which a teacher is teaching to a student.
 int getVisibleGoodsCount()
          Returns the amount of goods that is carried by this unit.
 Building getWorkBuilding()
          Gets the Building this unit is working in.
 TileImprovement getWorkImprovement()
          Gets the TileImprovement that this pioneer is contributing to.
 int getWorkLeft()
          Gets the amount of work left.
 Building getWorkLocation()
          Gets the Building this unit is working in.
 Location getWorkLocation2()
          Gets the Location this unit is working in.
 ColonyTile getWorkTile()
          Gets the ColonyTile this unit is working in.
 int getWorkTurnsLeft()
          Get the number of turns of work left.
 GoodsType getWorkType()
          Gets the type of goods this unit is producing in its current occupation.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean hasAbility(java.lang.String id)
          Returns true if the Unit, or its owner has the ability identified by id.
 boolean hasNativeEthnicity()
          Identifies whether this unit came from a native tribe.
 boolean isArmed()
           
 boolean isAtSea()
          Checks whether this Unit is at sea off the map, or on board of a carrier that is.
 boolean isCarrier()
          Checks if this Unit is able to carry Locatables.
 boolean isColonist()
          Checks if this Unit is a `colonist'.
 boolean isDefensiveUnit()
          Checks if this is an defensive unit.
 boolean isInEurope()
          Checks if this Unit is located in Europe.
 boolean isInMission()
          Checks if this unit is running a mission.
 boolean isMounted()
           
 boolean isNaval()
          Checks if this Unit is naval.
 boolean isOffensiveUnit()
          Checks if this is an offensive unit.
 boolean isOnCarrier()
          Verifies if the unit is aboard a carrier
 boolean isPerson()
          Checks if this unit is a person, that is not a ship or wagon.
 boolean isTradingUnit()
          Checks if this is a trading Unit, meaning that it can trade with settlements.
 boolean isUndead()
          Checks if this unit is an undead.
 boolean isUnderRepair()
          Checks if this unit is under repair.
 boolean isVisibleTo(Player player)
          Checks if this unit is visible to the given player.
 boolean losingEquipmentDemotesUnit(EquipmentType lose)
          Does losing a piece of equipment mean the demotion of this unit?
 boolean losingEquipmentKillsUnit(EquipmentType lose)
          Does losing a piece of equipment mean the death of this unit?
 void modifyExperience(int value)
          Modifies the experience of this Unit at its current experienceType.
 void moveToFront(Unit u)
          Move the given unit to the front of this carrier (make sure it'll be the first unit in this unit's unit list).
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
protected  void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
          Partial reader for units, so that "remove" messages can be brief.
 boolean remove(Locatable locatable)
          Removes a Locatable from this Unit.
 PathNode search(Tile start, GoalDecider gd, CostDecider cd, int maxTurns, Unit carrier)
          Convenience wrapper for the Map.search(net.sf.freecol.common.model.Unit, net.sf.freecol.common.model.Tile, net.sf.freecol.common.model.pathfinding.GoalDecider, net.sf.freecol.common.model.pathfinding.CostDecider, int, net.sf.freecol.common.model.Unit) function.
 void setAttrition(int attrition)
          Sets the attrition of this unit.
 void setCurrentStop(int currentStop)
          Set the current stop.
 void setDestination(Location newDestination)
          Sets the destination of this unit.
 void setEntryLocation(Location entryLocation)
          Sets the entry location in which this unit will be put when returning from Europe.
 void setEquipment(TypeCountMap<EquipmentType> newEquipment)
          Set the Equipment value.
 void setEthnicity(java.lang.String newEthnicity)
          Sets the ethnicity of this Unit.
 void setExperience(int experience)
          Sets the experience of this Unit at its current experienceType.
 void setHitpoints(int hitpoints)
          Sets the hitpoints for this unit.
 void setIndianSettlement(IndianSettlement indianSettlement)
          Sets the IndianSettlement that owns this unit.
 void setLocation(Location newLocation)
          Sets the location of this Unit.
 void setLocationNoUpdate(Location newLocation)
          Sets the units location without updating any other variables
 void setMovesLeft(int movesLeft)
          Sets the movesLeft.
 void setName(java.lang.String newName)
          Set the Name value.
 void setNationality(java.lang.String newNationality)
          Sets the nationality of this Unit.
 void setOwner(Player owner)
          Sets the owner of this Unit.
protected  void setRole()
          Determine role based on equipment.
 void setState(Unit.UnitState s)
          Sets a new state for this unit and initializes the amount of work the unit has left.
 void setStateToAllChildren(Unit.UnitState state)
          Sets the given state to all the units that si beeing carried.
protected  void setStateUnchecked(Unit.UnitState s)
           
 void setStudent(Unit newStudent)
          Set the Student value.
 void setTeacher(Unit newTeacher)
          Set the Teacher value.
 void setTradeRoute(TradeRoute newTradeRoute)
          Set the TradeRoute value.
 void setTreasureAmount(int amt)
          The current amount of treasure in this unit.
 void setTurnsOfTraining(int turnsOfTraining)
          Sets the number of turns this unit has been training.
 void setType(UnitType newUnitType)
          Sets the type of the unit.
 void setWorkImprovement(TileImprovement imp)
          Sets the TileImprovement that this pioneer is contributing to.
 void setWorkLeft(int workLeft)
          Sets the amount of work left.
 void setWorkType(GoodsType type)
          Sets the type of goods this unit is producing in its current occupation.
private  void spendAllMoves()
          Set movesLeft to 0 if has some spent moves and it's in a colony
 java.lang.String toString()
          Returns a String representation of this Unit.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
protected  void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out, java.lang.String[] fields)
          Partial writer for units, so that "remove" messages can be brief.
private  void unitsToXML(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
           
 int validateCurrentStop()
          Validate and return the current stop.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject
 
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, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Location
getId
 

Field Detail

skillLevelComp

private static java.util.Comparator<Unit> skillLevelComp

logger

private static final java.util.logging.Logger logger

EQUIPMENT_TAG

private static final java.lang.String EQUIPMENT_TAG
XML tag name for equipment list.

See Also:
Constant Field Values

CARGO_CHANGE

public static final java.lang.String CARGO_CHANGE
See Also:
Constant Field Values

EQUIPMENT_CHANGE

public static final java.lang.String EQUIPMENT_CHANGE
See Also:
Constant Field Values

unitType

protected UnitType unitType

movesLeft

protected int movesLeft

state

protected Unit.UnitState state

role

protected Unit.Role role

workLeft

protected int workLeft
The number of turns until the work is finished, or '-1' if a Unit can stay in its state forever.


hitpoints

protected int hitpoints

owner

protected Player owner

nationality

protected java.lang.String nationality

ethnicity

protected java.lang.String ethnicity

units

protected java.util.List<Unit> units

goodsContainer

protected GoodsContainer goodsContainer

entryLocation

protected Location entryLocation

location

protected Location location

indianSettlement

protected IndianSettlement indianSettlement

destination

protected Location destination

tradeRoute

protected TradeRoute tradeRoute
The trade route this unit has.


currentStop

protected int currentStop
Which stop in a trade route the unit is going to.


treasureAmount

protected int treasureAmount
To be used only for type == TREASURE_TRAIN


workImprovement

protected TileImprovement workImprovement
What is being improved (to be used only for PIONEERs - where they are working.


workType

protected GoodsType workType
What type of goods this unit produces in its occupation.


experienceType

private GoodsType experienceType
What type of goods this unit last earned experience producing.


experience

protected int experience

turnsOfTraining

protected int turnsOfTraining

attrition

protected int attrition
The attrition this unit has accumulated. At the moment, this equals the number of turns it has spent in the open.


name

protected java.lang.String name
The individual name of this unit, not of the unit type.


visibleGoodsCount

protected int visibleGoodsCount
The amount of goods carried by this unit. This variable is only used by the clients. A negative value signals that the variable is not in use.

See Also:
getVisibleGoodsCount()

student

protected Unit student
The student of this Unit, if it has one.


teacher

protected Unit teacher
The teacher of this Unit, if it has one.


equipment

protected TypeCountMap<EquipmentType> equipment
The equipment this Unit carries.

Constructor Detail

Unit

protected Unit()
Constructor for ServerUnit.


Unit

protected Unit(Game game)
Constructor for ServerUnit.

Parameters:
game - The Game in which this unit belongs.

Unit

public Unit(Game game,
            javax.xml.stream.XMLStreamReader in)
     throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Parameters:
game - The Game in which this Unit belong.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

Unit

public Unit(Game game,
            org.w3c.dom.Element e)
Initialize this object from an XML-representation of this object.

Parameters:
game - The Game in which this Unit belong.
e - An XML-element that will be used to initialize this object.

Unit

public Unit(Game game,
            java.lang.String id)
Initiates a new Unit with the given ID. The object should later be initialized by calling either FreeColGameObject.readFromXML(XMLStreamReader) or FreeColObject.readFromXMLElement(Element).

Parameters:
game - The Game in which this object belong.
id - The unique identifier for this object.
Method Detail

canCarryUnits

public boolean canCarryUnits()
Returns true if the Unit can carry other Units.

Returns:
a boolean value

canCarryUnit

public boolean canCarryUnit(Unit u)
Is this unit able to carry a specified one?

Parameters:
The - potential cargo Unit.
Returns:
True if this unit can carry the cargo unit.

canCarryGoods

public boolean canCarryGoods()
Returns true if the Unit can carry Goods.

Returns:
a boolean value

getLocationName

public StringTemplate getLocationName()
Returns a name for this unit, as a location.

Specified by:
getLocationName in interface Location
Returns:
A name for this unit, as a location.

getLocationNameFor

public StringTemplate getLocationNameFor(Player player)
Returns the name for this unit, as a location, for a particular player.

Specified by:
getLocationNameFor in interface Location
Parameters:
player - The Player to prepare the name for.
Returns:
A name for this unit, as a location.

getType

public final UnitType getType()
Get the UnitType value.

Returns:
an UnitType value

getTreasureAmount

public int getTreasureAmount()
Returns the current amount of treasure in this unit. Should be type of TREASURE_TRAIN.

Returns:
The amount of treasure.

setTreasureAmount

public void setTreasureAmount(int amt)
The current amount of treasure in this unit. Should be type of TREASURE_TRAIN.

Parameters:
amt - The amount of treasure

getEquipment

public final TypeCountMap<EquipmentType> getEquipment()
Get the Equipment value.

Returns:
a List value

setEquipment

public final void setEquipment(TypeCountMap<EquipmentType> newEquipment)
Set the Equipment value.

Parameters:
newEquipment - The new Equipment value.

clearEquipment

public void clearEquipment()
Clears all Equipment held by this unit.


getTradeRoute

public final TradeRoute getTradeRoute()
Get the TradeRoute value.

Returns:
a TradeRoute value

setTradeRoute

public final void setTradeRoute(TradeRoute newTradeRoute)
Set the TradeRoute value.

Parameters:
newTradeRoute - The new TradeRoute value.

getStop

public TradeRoute.Stop getStop()
Get the stop the unit is heading for or at.

Returns:
The target stop.

getCurrentStop

public int getCurrentStop()
Get the current stop.

Returns:
The current stop (an index in stops).

setCurrentStop

public void setCurrentStop(int currentStop)
Set the current stop.

Parameters:
currentStop - A new value for the currentStop.

validateCurrentStop

public int validateCurrentStop()
Validate and return the current stop.

Returns:
The current stop (an index in stops).

canCashInTreasureTrain

public boolean canCashInTreasureTrain()
Checks if the treasure train can be cashed in at it's current Location.

Returns:
true if the treasure train can be cashed in.
Throws:
java.lang.IllegalStateException - if this unit is not a treasure train.

canCashInTreasureTrain

public boolean canCashInTreasureTrain(Location loc)
Checks if the treasure train can be cashed in at the given Location.

Parameters:
loc - The Location.
Returns:
true if the treasure train can be cashed in.
Throws:
java.lang.IllegalStateException - if this unit is not a treasure train.

getTransportFee

public int getTransportFee()
Return the fee that would have to be paid to transport this treasure to Europe.

Returns:
an int value

isTradingUnit

public boolean isTradingUnit()
Checks if this is a trading Unit, meaning that it can trade with settlements.

Returns:
True if this is a trading unit.

isColonist

public boolean isColonist()
Checks if this Unit is a `colonist'. A unit is a colonist if it is European and can build a new Colony.

Returns:
true if this unit is a colonist and false otherwise.

isOffensiveUnit

public boolean isOffensiveUnit()
Checks if this is an offensive unit. That is, one that can attack other units.

Returns:
true if this is an offensive unit.

getNeededTurnsOfTraining

public int getNeededTurnsOfTraining()
Gets the number of turns this unit has to train to educate a student. This value is only meaningful for units that can be put in a school.

Returns:
The turns of training needed to teach its current type to a free colonist or to promote an indentured servant or a petty criminal.
See Also:
getTurnsOfTraining()

getNeededTurnsOfTraining

public int getNeededTurnsOfTraining(UnitType typeTeacher,
                                    UnitType typeStudent)
Gets the number of turns this unit has to train to educate a student. This value is only meaningful for units that can be put in a school.

Parameters:
typeTeacher - the unit type of the teacher
typeStudent - the unit type of the student
Returns:
The turns of training needed to teach its current type to a free colonist or to promote an indentured servant or a petty criminal.
See Also:
getTurnsOfTraining()

getUnitTypeTeaching

public static UnitType getUnitTypeTeaching(UnitType typeTeacher,
                                           UnitType typeStudent)
Gets the UnitType which a teacher is teaching to a student. This value is only meaningful for teachers that can be put in a school.

Parameters:
typeTeacher - the unit type of the teacher
typeStudent - the unit type of the student
Returns:
an UnitType value
See Also:
getTurnsOfTraining()

getSkillLevel

public int getSkillLevel()
Gets the skill level.

Returns:
The level of skill for this unit. A higher value signals a more advanced type of units.

getSkillLevel

public static int getSkillLevel(UnitType unitType)
Gets the skill level of the given type of Unit.

Parameters:
unitType - The type of Unit.
Returns:
The level of skill for the given unit. A higher value signals a more advanced type of units.

getSkillLevelComparator

public static java.util.Comparator<Unit> getSkillLevelComparator()
Returns a Comparator that compares the skill levels of given units.

Returns:
skill Comparator

getTurnsOfTraining

public int getTurnsOfTraining()
Gets the number of turns this unit has been training.

Returns:
The number of turns of training this Unit has given.
See Also:
setTurnsOfTraining(int), getNeededTurnsOfTraining()

setTurnsOfTraining

public void setTurnsOfTraining(int turnsOfTraining)
Sets the number of turns this unit has been training.

Parameters:
turnsOfTraining - The number of turns of training this Unit has given.
See Also:
getNeededTurnsOfTraining()

getExperience

public int getExperience()
Gets the experience of this Unit at its current experienceType.

Returns:
The experience of this Unit at its current experienceType.
See Also:
modifyExperience(int)

setExperience

public void setExperience(int experience)
Sets the experience of this Unit at its current experienceType.

Parameters:
experience - The new experience of this Unit at its current experienceType.
See Also:
modifyExperience(int)

modifyExperience

public void modifyExperience(int value)
Modifies the experience of this Unit at its current experienceType.

Parameters:
value - The value by which to modify the experience of this Unit.
See Also:
getExperience()

getAttrition

public int getAttrition()
Gets the attrition of this unit.

Returns:
The attrition of this unit.

setAttrition

public void setAttrition(int attrition)
Sets the attrition of this unit.

Parameters:
attrition - The new attrition of this unit.

hasAbility

public boolean hasAbility(java.lang.String id)
Returns true if the Unit, or its owner has the ability identified by id.

Specified by:
hasAbility in interface Consumer
Overrides:
hasAbility in class FreeColObject
Parameters:
id - a String value
Returns:
a boolean value

getModifierSet

public java.util.Set<Modifier> getModifierSet(java.lang.String id)
Get a modifier that applies to this Unit.

Specified by:
getModifierSet in interface Consumer
Parameters:
id - a String value
Returns:
a Modifier value

getModifierSet

public java.util.Set<Modifier> getModifierSet(java.lang.String id,
                                              Ownable ownable)
Get a modifier that applies to the given Ownable. This is used for the offenceAgainst and defenceAgainst modifiers.

Parameters:
id - a String value
ownable - a Ownable value
Returns:
a Modifier value

addFeature

public void addFeature(Feature feature)
Add the given Feature to the Features Map. If the Feature given can not be combined with a Feature with the same ID already present, the old Feature will be replaced.

Parameters:
feature - a Feature value

canBeStudent

public boolean canBeStudent(Unit teacher)
Returns true if this unit can be a student.

Parameters:
teacher - the teacher which is trying to teach it
Returns:
a boolean value

canBeStudent

public boolean canBeStudent(UnitType typeStudent,
                            UnitType typeTeacher)
Returns true if this type of unit can be a student.

Parameters:
typeStudent - the unit type of the student
typeTeacher - the unit type of the teacher which is trying to teach it
Returns:
a boolean value

getStudent

public final Unit getStudent()
Get the Student value.

Returns:
an Unit value

setStudent

public final void setStudent(Unit newStudent)
Set the Student value.

Parameters:
newStudent - The new Student value.

getTeacher

public final Unit getTeacher()
Get the Teacher value.

Returns:
an Unit value

setTeacher

public final void setTeacher(Unit newTeacher)
Set the Teacher value.

Parameters:
newTeacher - The new Teacher value.

getWorkLocation

public Building getWorkLocation()
Gets the Building this unit is working in. TODO: migrate usage of this to getWorkBuilding(), then delete this and rename the method below


getWorkLocation2

public Location getWorkLocation2()
Gets the Location this unit is working in.


getWorkBuilding

public Building getWorkBuilding()
Gets the Building this unit is working in.


getWorkTile

public ColonyTile getWorkTile()
Gets the ColonyTile this unit is working in.


getExperienceType

public GoodsType getExperienceType()
Gets the type of goods this unit has accrued experience producing.

Returns:
The type of goods this unit would produce.

getWorkType

public GoodsType getWorkType()
Gets the type of goods this unit is producing in its current occupation.

Returns:
The type of goods this unit is producing.

setWorkType

public void setWorkType(GoodsType type)
Sets the type of goods this unit is producing in its current occupation.

Parameters:
type - The type of goods to attempt to produce.

getWorkImprovement

public TileImprovement getWorkImprovement()
Gets the TileImprovement that this pioneer is contributing to.

Returns:
The TileImprovement the pioneer is working on.

setWorkImprovement

public void setWorkImprovement(TileImprovement imp)
Sets the TileImprovement that this pioneer is contributing to.

Parameters:
imp - The new TileImprovement the pioneer is to work on.

getDestination

public Location getDestination()
Returns the destination of this unit.

Returns:
The destination of this unit.

setDestination

public void setDestination(Location newDestination)
Sets the destination of this unit.

Parameters:
newDestination - The new destination of this unit.

findPath

public PathNode findPath(Tile end)
Finds a shortest path from the current Tile to the one specified. Only paths on water are allowed if isNaval() and only paths on land if not. The Tile at the end will not be checked against the legal moves of this Unit.

Parameters:
end - The Tile in which the path ends.
Returns:
A PathNode for the first tile in the path.
Throws:
java.lang.IllegalArgumentException - if end == null

findPath

public PathNode findPath(Tile start,
                         Tile end)
Finds a shortest path from the current Tile to the one specified. Only paths on water are allowed if isNaval() and only paths on land if not.

Parameters:
start - The Tile in which the path starts.
end - The Tile in which the path ends.
Returns:
A PathNode for the first tile in the path.

findPath

public PathNode findPath(Tile start,
                         Tile end,
                         Unit carrier)
Finds a shortest path from the current Tile to the one specified. Only paths on water are allowed if isNaval() and only paths on land if not.

Parameters:
start - The Tile in which the path starts.
end - The Tile in which the path ends.
carrier - An optional Unit to carry the unit.
Returns:
A PathNode for the first tile in the path.

findPath

public PathNode findPath(Tile start,
                         Tile end,
                         Unit carrier,
                         CostDecider costDecider)
Finds a shortest path from the current Tile to the one specified. Only paths on water are allowed if isNaval() and only paths on land if not.

Parameters:
start - The Tile in which the path starts from.
end - The Tile at the end of the path.
carrier - An optional Unit to carry the unit.
costDecider - An optional CostDecider for determining the movement costs (uses default cost deciders for the unit/s if not provided).
Returns:
A PathNode for the first tile in the path.

findPathToEurope

public PathNode findPathToEurope()
Convenience wrapper to find a path to Europe for this unit.

Returns:
A path to Europe, or null if none found.

findPathToEurope

public PathNode findPathToEurope(Tile start)
Convenience wrapper to find a path to Europe for this unit.

Parameters:
start - The Tile to start from.
Returns:
A path to Europe, or null if none found.

getTurnsToReach

public int getTurnsToReach(Tile start,
                           Tile end)
Returns the number of turns this Unit will have to use in order to reach the given Tile.

Parameters:
start - The Tile to start the search from.
end - The Tile to be reached by this Unit.
Returns:
The number of turns it will take to reach the end, or INFINITY if no path can be found.

getTurnsToReach

public int getTurnsToReach(Location destination)
Returns the number of turns this Unit will have to use in order to reach the given Location.

Parameters:
destination - The destination for this unit.
Returns:
The number of turns it will take to reach the destination, or INFINITY if no path can be found.

search

public PathNode search(Tile start,
                       GoalDecider gd,
                       CostDecider cd,
                       int maxTurns,
                       Unit carrier)
Convenience wrapper for the Map.search(net.sf.freecol.common.model.Unit, net.sf.freecol.common.model.Tile, net.sf.freecol.common.model.pathfinding.GoalDecider, net.sf.freecol.common.model.pathfinding.CostDecider, int, net.sf.freecol.common.model.Unit) function.

Parameters:
startTile - The Tile to start the search from.
gd - The object responsible for determining whether a given PathNode is a goal or not.
costDecider - An optional CostDecider responsible for determining the path cost.
maxTurns - The maximum number of turns the given Unit is allowed to move.
carrier - The carrier the unit is currently onboard or null if the unit is either not onboard a carrier or should not use the carrier while finding the path.
Returns:
The path to a goal determined by the given GoalDecider.

getMoveCost

public int getMoveCost(Tile target)
Gets the cost of moving this Unit onto the given Tile. A call to getMoveType(Tile) will return MOVE_NO_MOVES, if getMoveCost(net.sf.freecol.common.model.Tile) returns a move cost larger than the moves left.

Parameters:
target - The Tile this Unit will move onto.
Returns:
The cost of moving this unit onto the given Tile.

getMoveCost

public int getMoveCost(Tile from,
                       Tile target,
                       int ml)
Gets the cost of moving this Unit from the given Tile onto the given Tile. A call to getMoveType(Tile, Tile, int) will return MOVE_NO_MOVES, if getMoveCost(net.sf.freecol.common.model.Tile) returns a move cost larger than the moves left.

Parameters:
from - The Tile this Unit will move from.
target - The Tile this Unit will move onto.
ml - The amount of moves this Unit has left.
Returns:
The cost of moving this unit onto the given Tile.

getMoveType

public Unit.MoveType getMoveType(Map.Direction direction)
Gets the type of a move made in a specified direction.

Parameters:
direction - The Direction of the move.
Returns:
The move type.

getMoveType

public Unit.MoveType getMoveType(Tile target)
Gets the type of a move that is made when moving from one tile to another.

Parameters:
target - The target Tile of the move.
Returns:
The move type.

getMoveType

public Unit.MoveType getMoveType(Tile from,
                                 Tile target,
                                 int ml)
Gets the type of a move that is made when moving from one tile to another.

Parameters:
from - The origin Tile of the move.
target - The target Tile of the move.
ml - The amount of moves this unit has left.
Returns:
The move type.

getSimpleMoveType

public Unit.MoveType getSimpleMoveType(Tile from,
                                       Tile target)
Gets the type of a move that is made when moving from one tile to another, without checking if the unit has moves left or logging errors.

Parameters:
from - The origin Tile of the move.
target - The target Tile of the move.
Returns:
The move type, which will be one of the extended illegal move types on failure.

getSimpleMoveType

public Unit.MoveType getSimpleMoveType(Tile target)
Gets the type of a move that is made when moving from one tile to another, without checking if the unit has moves left or logging errors.

Parameters:
target - The target Tile of the move.
Returns:
The move type, which will be one of the extended illegal move types on failure.

getSimpleMoveType

public Unit.MoveType getSimpleMoveType(Map.Direction direction)
Gets the type of a move made in a specified direction, without checking if the unit has moves left or logging errors.

Parameters:
direction - The direction of the move.
Returns:
The move type.

getNavalMoveType

private Unit.MoveType getNavalMoveType(Tile from,
                                       Tile target)
Gets the type of a move that is made when moving a naval unit from one tile to another.

Parameters:
from - The origin Tile of the move.
target - The target Tile of the move.
Returns:
The move type.

getLandMoveType

private Unit.MoveType getLandMoveType(Tile from,
                                      Tile target)
Gets the type of a move that is made when moving a land unit to from one tile to another.

Parameters:
from - The origin Tile of the move.
target - The target Tile of the move.
Returns:
The move type.

getTradeMoveType

private Unit.MoveType getTradeMoveType(Settlement settlement)
Get the MoveType when moving a trading unit to a settlement.

Parameters:
settlement - The Settlement to move to.
Returns:
The appropriate MoveType.

getLearnMoveType

private Unit.MoveType getLearnMoveType(Tile from,
                                       Settlement settlement)
Get the MoveType when moving a colonist to a settlement.

Parameters:
from - The Tile to move from.
settlement - The Settlement to move to.
Returns:
The appropriate MoveType.

getMissionaryMoveType

private Unit.MoveType getMissionaryMoveType(Tile from,
                                            Settlement settlement)
Get the MoveType when moving a missionary to a settlement.

Parameters:
from - The Tile to move from.
settlement - The Settlement to move to.
Returns:
The appropriate MoveType.

getScoutMoveType

private Unit.MoveType getScoutMoveType(Tile from,
                                       Settlement settlement)
Get the MoveType when moving a scout to a settlement.

Parameters:
from - The Tile to move from.
settlement - The Settlement to move to.
Returns:
The appropriate MoveType.

allowMoveFrom

private boolean allowMoveFrom(Tile from)
Is this unit allowed to move from a source tile? Implements the restrictions on moving from water.

Parameters:
from - The Tile to consider.
Returns:
True if the move is allowed.

allowContact

private boolean allowContact(Settlement settlement)
Is this unit allowed to contact a settlement?

Parameters:
settlement - The Settlement to consider.
Returns:
True if the contact is allowed.

getMovesLeft

public int getMovesLeft()
Returns the amount of moves this Unit has left.

Specified by:
getMovesLeft in interface Movable
Returns:
The amount of moves this Unit has left.

setMovesLeft

public void setMovesLeft(int movesLeft)
Sets the movesLeft.

Parameters:
movesLeft - The new amount of moves left this Unit should have. If movesLeft < 0 then movesLeft = 0.

getSpaceTaken

public int getSpaceTaken()
Gets the amount of space this Unit takes when put on a carrier.

Specified by:
getSpaceTaken in interface Locatable
Returns:
The space this Unit takes.

getLineOfSight

public int getLineOfSight()
Gets the line of sight of this Unit. That is the distance this Unit can spot new tiles, enemy unit e.t.c.

Returns:
The line of sight of this Unit.

isOnCarrier

public boolean isOnCarrier()
Verifies if the unit is aboard a carrier


setStateToAllChildren

public void setStateToAllChildren(Unit.UnitState state)
Sets the given state to all the units that si beeing carried.

Parameters:
state - The state.

spendAllMoves

private void spendAllMoves()
Set movesLeft to 0 if has some spent moves and it's in a colony

See Also:
add(Locatable), remove(Locatable)

couldMove

public boolean couldMove()
Returns true if this Unit could still be moved. This is used to prevent an accidental end of turn order.

Returns:
True if this unit could still be moved by the player.

getRepairLocation

public Location getRepairLocation()
Finds the closest Location to this tile where this ship can be repaired.

Returns:
The closest Location where a ship can be repaired.

add

public boolean add(Locatable locatable)
Adds a locatable to this Unit.

Specified by:
add in interface Location
Parameters:
locatable - The Locatable to add to this Unit.

remove

public boolean remove(Locatable locatable)
Removes a Locatable from this Unit.

Specified by:
remove in interface Location
Parameters:
locatable - The Locatable to remove from this Unit.

contains

public boolean contains(Locatable locatable)
Checks if this Unit contains the specified Locatable.

Specified by:
contains in interface Location
Parameters:
locatable - The Locatable to test the presence of.
Returns:
  • true if the specified Locatable is on this Unit and
  • false otherwise.

canAdd

public boolean canAdd(Locatable locatable)
Checks wether or not the specified locatable may be added to this Unit. The locatable cannot be added is this Unit if it is not a carrier or if there is no room left.

Specified by:
canAdd in interface Location
Parameters:
locatable - The Locatable to test the addabillity of.
Returns:
The result.

getLoadableAmount

public int getLoadableAmount(GoodsType type)
Returns the amount of a GoodsType that could be loaded.

Parameters:
type - a GoodsType value
Returns:
an int value

getUnitCount

public int getUnitCount()
Gets the amount of Units at this Location.

Specified by:
getUnitCount in interface Location
Returns:
The amount of Units at this Location.

getFirstUnit

public Unit getFirstUnit()
Gets the first Unit beeing carried by this Unit.

Returns:
The Unit.

getLastUnit

public Unit getLastUnit()
Gets the last Unit beeing carried by this Unit.

Returns:
The Unit.

isVisibleTo

public boolean isVisibleTo(Player player)
Checks if this unit is visible to the given player.

Parameters:
player - The Player.
Returns:
true if this Unit is visible to the given Player.

getUnitIterator

public java.util.Iterator<Unit> getUnitIterator()
Gets a Iterator of every Unit directly located on this Location.

Specified by:
getUnitIterator in interface Location
Returns:
The Iterator.

getUnitList

public java.util.List<Unit> getUnitList()
Gets a list of the units in this carrier unit.

Specified by:
getUnitList in interface Location
Returns:
The list of units in this carrier unit.

getGoodsIterator

public java.util.Iterator<Goods> getGoodsIterator()
Gets a Iterator of every Unit directly located on this Location.

Returns:
The Iterator.

getGoodsList

public java.util.List<Goods> getGoodsList()
Returns a List containing the goods carried by this unit.

Returns:
a List containing the goods carried by this unit.

getGoodsContainer

public GoodsContainer getGoodsContainer()
Description copied from interface: Location
Gets the GoodsContainer this Location use for storing it's goods.

Specified by:
getGoodsContainer in interface Location
Returns:
The GoodsContainer or null if the Location cannot store any goods.

setLocationNoUpdate

public void setLocationNoUpdate(Location newLocation)
Sets the units location without updating any other variables

Parameters:
newLocation - The new Location

setLocation

public void setLocation(Location newLocation)
Sets the location of this Unit.

Specified by:
setLocation in interface Locatable
Parameters:
newLocation - The new Location.

setIndianSettlement

public void setIndianSettlement(IndianSettlement indianSettlement)
Sets the IndianSettlement that owns this unit.

Parameters:
indianSettlement - The IndianSettlement that should now be owning this Unit.

getIndianSettlement

public IndianSettlement getIndianSettlement()
Gets the IndianSettlement that owns this unit.

Returns:
The IndianSettlement.

getLocation

public Location getLocation()
Gets the location of this Unit.

Specified by:
getLocation in interface Locatable
Returns:
The location of this Unit.

canBeEquippedWith

public boolean canBeEquippedWith(EquipmentType equipmentType)
Checks whether this unit can be equipped with the given EquipmentType at the current Location. This is the case if all requirements of the EquipmentType are met.

Parameters:
equipmentType - an EquipmentType value
Returns:
whether this unit can be equipped with the given EquipmentType at the current location.

changeEquipment

public java.util.List<EquipmentType> changeEquipment(EquipmentType type,
                                                     int amount)
Changes the equipment a unit has and returns a list of equipment it still has but needs to drop due to the changed equipment being incompatible.

Parameters:
type - The EquipmentType to change.
amount - The amount to change by (may be negative).
Returns:
A list of equipment types that the unit must now drop.

getEquipmentCount

public int getEquipmentCount(EquipmentType equipmentType)
Describe getEquipmentCount method here.

Parameters:
equipmentType - an EquipmentType value
Returns:
an int value

isInEurope

public boolean isInEurope()
Checks if this Unit is located in Europe. That is; either directly or onboard a carrier which is in Europe.

Returns:
The result.

isAtSea

public boolean isAtSea()
Checks whether this Unit is at sea off the map, or on board of a carrier that is.

Returns:
The result.

isCarrier

public boolean isCarrier()
Checks if this Unit is able to carry Locatables.

Returns:
'true' if this unit can carry goods or other units, 'false' otherwise.

isPerson

public boolean isPerson()
Checks if this unit is a person, that is not a ship or wagon. Surprisingly difficult without explicit enumeration because model.ability.person only arrived in 0.10.1.

Returns:
True if this unit is a person.

getOwner

public Player getOwner()
Gets the owner of this Unit.

Specified by:
getOwner in interface Ownable
Returns:
The owner of this Unit.

getApparentOwnerName

public StringTemplate getApparentOwnerName()
Get the name of the apparent owner of this Unit, (like getOwner().getNationAsString() but handles pirates)

Returns:
The name of the owner of this Unit unless this is hidden.

setOwner

public void setOwner(Player owner)
Sets the owner of this Unit.

Specified by:
setOwner in interface Ownable
Parameters:
owner - The new owner of this Unit.

getNationality

public java.lang.String getNationality()
Gets the nationality of this Unit. Nationality represents a Unit's personal allegiance to a nation. This may conflict with who currently issues orders to the Unit (the owner).

Returns:
The nationality of this Unit.

setNationality

public void setNationality(java.lang.String newNationality)
Sets the nationality of this Unit. A unit will change nationality when it switches owners willingly. Currently only Converts do this, but it opens the possibility of naturalisation.

Parameters:
newNationality - The new nationality of this Unit.

getEthnicity

public java.lang.String getEthnicity()
Gets the ethnicity of this Unit. Ethnicity is inherited from the inhabitants of the place where the Unit was born. Allows former converts to become native-looking colonists.

Returns:
The ethnicity of this Unit.

setEthnicity

public void setEthnicity(java.lang.String newEthnicity)
Sets the ethnicity of this Unit. Ethnicity is something units are born with. It cannot be subsequently changed.

Parameters:
newEthnicity - The new ethnicity of this Unit.

hasNativeEthnicity

public boolean hasNativeEthnicity()
Identifies whether this unit came from a native tribe.

Returns:
Whether this unit looks native or not.

setType

public void setType(UnitType newUnitType)
Sets the type of the unit.

Parameters:
newUnitType - The new type of the unit.

isArmed

public boolean isArmed()

isMounted

public boolean isMounted()

getName

public java.lang.String getName()
Describe getName method here.

Specified by:
getName in interface Nameable
Returns:
a String value

setName

public void setName(java.lang.String newName)
Set the Name value.

Specified by:
setName in interface Nameable
Parameters:
newName - The new Name value.

getLabel

public StringTemplate getLabel()
Describe getLabel method here.

Returns:
a StringTemplate value

getEquipmentLabel

public StringTemplate getEquipmentLabel()
Return a description of the unit's equipment.

Returns:
a String value

getInitialMovesLeft

public int getInitialMovesLeft()
Gets the amount of moves this unit has at the beginning of each turn.

Specified by:
getInitialMovesLeft in interface Movable
Returns:
The amount of moves this unit has at the beginning of each turn.

setHitpoints

public void setHitpoints(int hitpoints)
Sets the hitpoints for this unit.

Parameters:
hitpoints - The hitpoints this unit has. This is currently only used for damaged ships, but might get an extended use later.
See Also:
UnitType.getHitPoints()

getHitpoints

public int getHitpoints()
Returns the hitpoints.

Returns:
The hitpoints this unit has. This is currently only used for damaged ships, but might get an extended use later.
See Also:
UnitType.getHitPoints()

isUnderRepair

public boolean isUnderRepair()
Checks if this unit is under repair.

Returns:
true if under repair and false otherwise.

isInMission

public boolean isInMission()
Checks if this unit is running a mission.

Returns:
True if this unit is running a mission.

toString

public java.lang.String toString()
Returns a String representation of this Unit.

Overrides:
toString in class FreeColGameObject
Returns:
A String representation of this Unit.

getMovesAsString

public java.lang.String getMovesAsString()

isNaval

public boolean isNaval()
Checks if this Unit is naval.

Returns:
true if this Unit is a naval Unit and false otherwise.

getState

public Unit.UnitState getState()
Gets the state of this Unit.

Returns:
The state of this Unit.

getRole

public Unit.Role getRole()
Gets the Role of this Unit.

Returns:
The role of this Unit.

setRole

protected void setRole()
Determine role based on equipment.


checkSetState

public boolean checkSetState(Unit.UnitState s)
Checks if a Unit can get the given state set.

Parameters:
s - The new state for this Unit. Should be one of {UnitState.ACTIVE, FORTIFIED, ...}.
Returns:
'true' if the Unit's state can be changed to the new value, 'false' otherwise.

getSailTurns

public int getSailTurns()
Gets the number of turns this unit will need to sail to/from Europe.

Returns:
The number of turns to sail to/from Europe.

setState

public void setState(Unit.UnitState s)
Sets a new state for this unit and initializes the amount of work the unit has left. If the work needs turns to be completed (for instance when plowing), then the moves the unit has still left will be used up. Some work (basically building a road with a hardy pioneer) might actually be finished already in this method-call, in which case the state is set back to UnitState.ACTIVE.

Parameters:
s - The new state for this Unit. Should be one of {UnitState.ACTIVE, UnitState.FORTIFIED, ...}.

setStateUnchecked

protected void setStateUnchecked(Unit.UnitState s)

canMoveToEurope

public boolean canMoveToEurope()
Checks if this Unit can be moved to Europe. TODO: the new Carribean map has no south pole, and this allows moving to Europe via the bottom edge of the map, which is approximately the equator line. Should we enforce moving to Europe requires high seas, and no movement via north/south poles? mpope 201103: Just leave it up to the map itself, tiles can include a "moveToEurope" attribute to override the default behaviour, which is to allow movement to Europe from tiles with the moveToEurope ability or on the map borders. Now, IMHO on the Carribean map, settling on the land next to the south border gives an unfair advantage and we *should* set moveToEurope==false on the nearby sea tiles.

Returns:
true if this unit can move to Europe.

canBuildColony

public boolean canBuildColony()
Check if this unit can build a colony. Does not consider whether the tile where the unit is located is suitable,

Returns:
true if this unit can build a colony.
See Also:
Player.canClaimToFoundSettlement(Tile)

getTile

public Tile getTile()
Returns the Tile where this Unit is located. Or null if its location is Europe.

Specified by:
getTile in interface Locatable
Specified by:
getTile in interface Location
Returns:
The Tile where this Unit is located. Or null if its location is Europe.

getSpaceLeft

public int getSpaceLeft()
Returns the amount of space left on this Unit.

Returns:
The amount of units/goods than can be moved onto this Unit.

getVisibleGoodsCount

public int getVisibleGoodsCount()
Returns the amount of goods that is carried by this unit.

Returns:
The amount of goods carried by this Unit. This value might different from the one returned by getGoodsCount() when the model is owned by a client and cargo hiding has been enabled.

getGoodsCount

public int getGoodsCount()

moveToFront

public void moveToFront(Unit u)
Move the given unit to the front of this carrier (make sure it'll be the first unit in this unit's unit list).

Parameters:
u - The unit to move to the front.

getWorkLeft

public int getWorkLeft()
Gets the amount of work left.

Returns:
The amount of work left.

setWorkLeft

public void setWorkLeft(int workLeft)
Sets the amount of work left.

Parameters:
workLeft - The new amount of work left.

getWorkTurnsLeft

public int getWorkTurnsLeft()
Get the number of turns of work left.

Returns:
The number of turns of work left.

setEntryLocation

public void setEntryLocation(Location entryLocation)
Sets the entry location in which this unit will be put when returning from Europe.

Parameters:
entryLocation - The entry location.
See Also:
getEntryLocation()

getEntryLocation

public Location getEntryLocation()
Gets the entry location for this unit to use when returning from Europe.

Returns:
The entry location.

getFullEntryLocation

public Tile getFullEntryLocation()
Gets the entry tile for this unit, or if null the default entry location for the owning player.

Returns:
The entry tile.

isDefensiveUnit

public boolean isDefensiveUnit()
Checks if this is an defensive unit. That is: a unit which can be used to defend a Settlement.

Note! As this method is used by the AI it really means that the unit can defend as is. To be specific an unarmed colonist is not defensive yet, even if Paul Revere and stockpiled muskets are available. That check is only performed on an actual attack.

A settlement is lost when there are no more defensive units.

Returns:
true if this is a defensive unit meaning it can be used to defend a Colony. This would normally mean that a defensive unit also will be offensive.

betterDefender

public static boolean betterDefender(Unit defender,
                                     float defenderPower,
                                     Unit other,
                                     float otherPower)
Is an alternate unit a better defender than the current choice. Prefer if there is no current defender, or if the alternate unit is better armed, or provides greater defensive power and does not replace a defensive unit defender with a non-defensive unit.

Parameters:
defender - The current defender Unit.
defenderPower - Its defence power.
other - An alternate Unit.
otherPower - Its defence power.
Returns:
True if the other unit should be preferred.

isUndead

public boolean isUndead()
Checks if this unit is an undead.

Returns:
return true if the unit is undead

canCarryTreasure

public boolean canCarryTreasure()
Returns true if this unit can carry treasure (like a treasure train)

Returns:
true if this Unit is capable of carrying treasure.

canCaptureGoods

public boolean canCaptureGoods()
Returns true if this unit is a ship that can capture enemy goods.

Returns:
true if this Unit is capable of capturing goods.

canCaptureEquipment

public EquipmentType canCaptureEquipment(EquipmentType equip,
                                         Unit loser)
After winning a battle, can this unit the loser equipment?

Parameters:
equip - The EquipmentType to consider.
loser - The loser Unit.
Returns:
The EquipmentType to capture, which may differ from the equip parameter due to transformations such as to the native versions of horses and muskets. Or return null if capture is not possible.

getSettlement

public Settlement getSettlement()
Gets the Settlement this unit is in.

Specified by:
getSettlement in interface Location
Returns:
The Settlement this unit is in, or null if none.

getColony

public Colony getColony()
Gets the Colony this unit is in.

Specified by:
getColony in interface Location
Returns:
The Colony this unit is in, or null if none.

getProductionOf

public int getProductionOf(GoodsType goodsType,
                           int base)
Given a type of goods to produce in the field and a tile, returns the unit's potential to produce goods.

Parameters:
goodsType - The type of goods to be produced.
base - an int value
Returns:
The potential amount of goods to be farmed.

disposeList

public java.util.List<FreeColGameObject> disposeList()
Removes all references to this object.

Overrides:
disposeList in class FreeColGameObject
Returns:
A list of disposed objects.

dispose

public void dispose()
Removes all references to this object.

Overrides:
dispose in class FreeColGameObject

getTurnsForRepair

public int getTurnsForRepair()
Return how many turns left to be repaired

Returns:
turns to be repaired

getAutomaticEquipment

public TypeCountMap<EquipmentType> getAutomaticEquipment()
Gets the available equipment that can be equipped automatically in case of an attack.

Returns:
The equipment that can be automatically equipped by this unit, or null if none.

losingEquipmentKillsUnit

public boolean losingEquipmentKillsUnit(EquipmentType lose)
Does losing a piece of equipment mean the death of this unit?

Parameters:
lose - The EquipmentType to lose.
Returns:
True if the unit is doomed.

losingEquipmentDemotesUnit

public boolean losingEquipmentDemotesUnit(EquipmentType lose)
Does losing a piece of equipment mean the demotion of this unit?

Parameters:
lose - The EquipmentType to lose.
Returns:
True if the unit is to be demoted.

getConvertProbability

public float getConvertProbability()
Gets the probability that an attack by this unit will provoke a native to convert.

Returns:
A probability of conversion.

getBurnProbability

public float getBurnProbability()
Gets the probability that an attack by this unit will provoke natives to burn our missions.

Returns:
A probability of burning missions.

getTypeChange

public UnitType getTypeChange(UnitTypeChange.ChangeType change,
                              Player owner)
Get a type change for this unit.

Parameters:
change - The ChangeType to consider.
owner - The Player to own this unit after a change of type CAPTURE or UNDEAD.
Returns:
The resulting unit type or null if there is no change suitable.

getBestCombatEquipmentType

public EquipmentType getBestCombatEquipmentType(TypeCountMap<EquipmentType> equipment)
Gets the best combat equipment type that this unit has.

Parameters:
equipment - The equipment to look through, such as returned by
Returns:
The equipment type to lose, or null if none.
See Also:
and/or @see Unit#getAutomaticEquipment().

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

getProductionInfo

public ProductionInfo getProductionInfo(java.util.List<AbstractGoods> input)
Describe getProductionInfo method here.

Returns:
a ProductionInfo 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

unitsToXML

private void unitsToXML(javax.xml.stream.XMLStreamWriter out,
                        Player player,
                        boolean showAll,
                        boolean toSavedGame)
                 throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
                         Player player,
                         boolean showAll,
                         boolean toSavedGame)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Only attributes visible to the given Player will be added to that representation if showAll is set to false.

Specified by:
toXMLImpl in class FreeColGameObject
Parameters:
out - The target stream.
player - The Player this XML-representation should be made for, or null if showAll == true.
showAll - Only attributes visible to player will be added to the representation if showAll is set to false.
toSavedGame - If true then information that is only needed when saving a game is added.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - is thrown if something goes wrong.

toXMLPartialImpl

protected void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out,
                                java.lang.String[] fields)
                         throws javax.xml.stream.XMLStreamException
Partial writer for units, so that "remove" messages can be brief.

Overrides:
toXMLPartialImpl in class FreeColObject
Parameters:
out - The target stream.
fields - The fields to write.
Throws:
javax.xml.stream.XMLStreamException - If there are problems writing the stream.

readFromXMLPartialImpl

protected void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
                               throws javax.xml.stream.XMLStreamException
Partial reader for units, so that "remove" messages can be brief.

Overrides:
readFromXMLPartialImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - If there are problems reading the stream.

getXMLElementTagName

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

Returns:
"unit"