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:
Locatable, Location, Nameable, Named, Ownable, Typed<UnitType>

public class Unit
extends FreeColGameObject
implements Locatable, Location, Ownable, Nameable, Typed<UnitType>

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
static java.lang.String CARGO_CHANGE
           
static java.lang.String EQUIPMENT_CHANGE
           
static int TURNS_TO_SAIL
          The number of turns required to sail between Europe and the New World.
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
Unit(Game game, org.w3c.dom.Element e)
          Initialize this object from an XML-representation of this object.
Unit(Game game, Location location, Player owner, UnitType type, Unit.UnitState state)
          Initiate a new Unit with the specified parameters.
Unit(Game game, Location location, Player owner, UnitType type, Unit.UnitState state, EquipmentType... initialEquipment)
          Initiate a new Unit with the specified parameters.
Unit(Game game, Player owner, UnitType type)
          Initiate a new Unit of a specified type with the state set to Unit.UnitState.ACTIVE if a carrier and Unit.UnitState.SENTRY otherwise.
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
 void activeAdjacentSentryUnits(Tile tile)
          Active units with sentry state wich are adjacent to a specified tile
 void add(Locatable locatable)
          Adds a locatable to this Unit.
 void addFeature(Feature feature)
          Add the given Feature to the Features Map.
 void adjustTension(Unit enemyUnit)
          Adjusts the tension and alarm levels of the enemy unit's owner according to the type of attack.
 void boardShip(Unit carrier)
          Boards a carrier that is on the same tile.
 void buildColony(Colony colony)
          Makes this unit build the specified colony.
 void buyGoods(GoodsType goodsType, int amount)
          Buys goods of a specified type and amount and adds it to this Unit.
 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.
static 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 on the tile where it is located.
 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 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.
 boolean canTradeWith(Settlement settlement)
          Returns true if this unit can enter a settlement in order to trade.
 void captureGoods(Unit enemyUnit)
          Captures the goods on board of the enemy unit.
 boolean checkSetState(Unit.UnitState s)
          Checks if a Unit can get the given state set.
 void clearSpeciality()
          Clear the specialty of a Unit changing the UnitType to the UnitType specified for clearing.
 void contactAdjacent(Tile tile)
          Contact Players with Units or Settlements on surrounding Tiles.
 boolean contains(Locatable locatable)
          Checks if this Unit contains the specified Locatable.
 void dispose()
          Removes all references to this object.
 void disposeAllUnits()
          Disposes all Units aboard this one.
 void doAssignedWork()
          The status of units that are currently working (for instance on building a road, or fortifying themselves) is updated in this method.
 void embark(Unit unit)
          Embarks this unit onto the specified unit.
 void equipWith(EquipmentType equipmentType)
          Describe equipWith method here.
 void equipWith(EquipmentType equipmentType, boolean asResultOfCombat)
          Describe equipWith method here.
 void equipWith(EquipmentType equipmentType, int amount)
          Describe equipWith method here.
 void equipWith(EquipmentType equipmentType, int amount, boolean asResultOfCombat)
          Equip this unit with the given EquipmentType, provided that all requirements are met, and that the EquipmentType can be built at this location or is present as a result of combat.
 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.
 TypeCountMap<EquipmentType> getAutomaticEquipment()
           
 Colony getColony()
          Gets the Colony this unit is in.
 TradeRoute.Stop getCurrentStop()
          Get the current stop.
 Location getDestination()
          Returns the destination of this unit.
 java.lang.String getDetailedOccupationIndicator()
          Get detailed occupation indicator
 Location getEntryLocation()
          Gets the Location in which this unit will be put when returning from Europe.
 TypeCountMap<EquipmentType> getEquipment()
          Get the Equipment value.
 int getEquipmentCount(EquipmentType equipmentType)
          Describe getEquipmentCount method here.
 java.lang.String getEquipmentLabel()
          Return a description of the unit's equipment.
 int getExperience()
          Gets the experience of this Unit at its current workType.
 Unit getFirstUnit()
          Gets the first Unit beeing carried by this Unit.
 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.
 Unit getLastUnit()
          Gets the last Unit beeing carried by this Unit.
 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.
 java.util.Set<Modifier> getModifierSet(java.lang.String id)
          Get a modifier that applies to this Unit.
 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.
 Unit.MoveType getMoveType(Tile from, Tile target, int ml, boolean ignoreEnemyUnits)
          Gets the type of a move that is made when moving from one tile to another.
 java.lang.String getName()
          Returns the name of this Unit (most likely 'null').
 int getNeededTurnsOfTraining()
          Gets the number of turns this unit has to train to educate a student.
static int getNeededTurnsOfTraining(UnitType typeTeacher, UnitType typeStudent)
          Gets the number of turns this unit has to train to educate a student.
 java.lang.String getOccupationIndicator()
          Get occupation indicator
 Player getOwner()
          Gets the owner of this Unit.
 java.lang.String getPathTypeImage()
          Return the type of the image which will be used to draw the path
 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.
 Unit.Role getRole()
          Gets the Role of this Unit.
 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, boolean ignoreEnemyUnits)
          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()
           
 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.
 Unit getStudent()
          Get the Student value.
 Unit getTeacher()
          Get the Teacher value.
 Tile getTile()
          Returns the Tile where this Unit is located.
 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 end)
          Returns the number of turns this Unit will have to use in order to reach the given Tile.
 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.
 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()
          Returns a list containing all the Units present at this Location.
static UnitType getUnitTypeTeaching(UnitType typeTeacher, UnitType typeStudent)
          Gets the UnitType which a teacher is teaching to a student.
 Location getVacantEntryLocation()
          Gets the Location in which this unit will be put when returning from Europe.
 int getVisibleGoodsCount()
          Returns the amount of goods that is carried by this unit.
 TileImprovement getWorkImprovement()
          Gets the TileImprovement that this pioneer is contributing to.
 int getWorkLeft()
          Get the number of turns of work left.
 Building getWorkLocation()
          Gets the Building this unit is working in.
 ColonyTile getWorkTile()
          Gets the ColonyTile this unit is working in.
 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 isAlreadyOnHighSea()
          Returns true if this unit has already been moved onto high seas but not to europe.
 boolean isArmed()
           
 boolean isBetweenEuropeAndNewWorld()
          Checks if this Unit is either a carrier or on one, bound to/from Europe
 boolean isCarrier()
          Checks if this Unit is able to carry Locatables.
static boolean isCarrier(UnitType unitType)
          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 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 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.
 void joinColony(Colony colony)
          Join existing colony.
 void learnFromIndianSettlement(IndianSettlement settlement)
           
 void modifyExperience(int value)
          Modifies the experience of this Unit at its current workType.
 void move(Map.Direction direction)
          Moves this unit in the specified direction.
 void moveToAmerica()
          Moves this unit to america.
 void moveToEurope()
          Moves this unit to Europe.
 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).
 void newTurn()
          Prepares the Unit for a new turn.
 void nextStop()
          Set current stop to the next valid stop if any.
 void putOutsideColony()
          Puts this Unit outside the Colony by moving it to the Tile below.
 void remove(Locatable locatable)
          Removes a Locatable from this Unit.
 void removeAllEquipment(boolean asResultOfCombat)
           
 void removeEquipment(EquipmentType equipmentType)
           
 void removeEquipment(EquipmentType equipmentType, int amount)
          Describe removeEquipment method here.
 void removeEquipment(EquipmentType equipmentType, int amount, boolean asResultOfCombat)
          Describe removeEquipment method here.
 void sendToRepairLocation(Location l)
          Sends this Unit to the closest Location it can get repaired.
 void setAlreadyOnHighSea(boolean alreadyOnHighSea)
          Tells unit that it has just entered the high seas but instead of going to europe, it stays on the current side of the atlantic.
 void setDestination(Location newDestination)
          Sets the destination of this unit.
 void setEntryLocation(Location entryLocation)
          Sets the Location in which this unit will be put when returning from Europe.
 void setEquipment(TypeCountMap<EquipmentType> newEquipment)
          Set the Equipment value.
 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 setOwner(Player owner)
          Sets the owner of this Unit.
 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.
 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 setWorkType(GoodsType type)
          Sets the type of goods this unit is producing in its current occupation.
 void switchEquipmentWith(Unit unit)
          Switches equipment between colonists
 java.lang.String toString()
          Returns a String representation of this Unit.
 void train()
          Train the current unit in the job of its teacher.
 void work(TileImprovement improvement)
          Sets this Unit to work at this TileImprovement
 void work(WorkLocation workLocation)
          Sets this Unit to work in the specified WorkLocation.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addToRemoveElement, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, setGame, setId, toSavedXML, toXML, updateFreeColGameObject, updateID
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAttribute, hasListeners, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Location
getId
 

Field Detail

TURNS_TO_SAIL

public static final int TURNS_TO_SAIL
The number of turns required to sail between Europe and the New World. TODO: In the future, this should be replaced by an advanced sailing model taking prevailing winds into account.


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
Constructor Detail

Unit

public Unit(Game game,
            Player owner,
            UnitType type)
Initiate a new Unit of a specified type with the state set to Unit.UnitState.ACTIVE if a carrier and Unit.UnitState.SENTRY otherwise. The Location is set to null.

Parameters:
game - The Game in which this Unit belong.
owner - The Player owning the unit.
type - The type of the unit.

Unit

public Unit(Game game,
            Location location,
            Player owner,
            UnitType type,
            Unit.UnitState state)
Initiate a new Unit with the specified parameters.

Parameters:
game - The Game in which this Unit belong.
location - The Location to place this Unit upon.
owner - The Player owning this unit.
type - The type of the unit.
state - The initial state for this Unit (one of Unit.UnitState.ACTIVE, Unit.UnitState.FORTIFIED...).

Unit

public Unit(Game game,
            Location location,
            Player owner,
            UnitType type,
            Unit.UnitState state,
            EquipmentType... initialEquipment)
Initiate a new Unit with the specified parameters.

Parameters:
game - The Game in which this Unit belong.
location - The Location to place this Unit upon.
owner - The Player owning this unit.
type - The type of the unit.
state - The initial state for this Unit (one of Unit.UnitState.ACTIVE, Unit.UnitState.FORTIFIED...).
initialEquipment - The list of initial EquimentTypes

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

canCarryGoods

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

Returns:
a boolean value

getType

public final UnitType getType()
Get the UnitType value.

Specified by:
getType in interface Typed<UnitType>
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.

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.

getCurrentStop

public TradeRoute.Stop getCurrentStop()
Get the current stop.

Returns:
the current stop.

nextStop

public void nextStop()
Set current stop to the next valid stop if any. TODO: This should be a server-only method, which is called from the UpdateCurrentStopMessage handler.


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

isColonist

public boolean isColonist()
Checks if this Unit is a colonist. A Unit is a colonist if it can build a new Colony.

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

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 static 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()

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 workType.

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

modifyExperience

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

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

hasAbility

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

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.

Parameters:
id - a String 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 static 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.


getWorkTile

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


getWorkType

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

Returns:
The type of goods this unit would produce.

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

setWorkImprovement

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


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. Calling PathNode.getTile() on this object, will return the Tile right after the specified starting tile, and PathNode.getDirection() will return the direction you need to take in order to reach that tile. This method returns null if no path is found.
Throws:
java.lang.IllegalArgumentException - if end == null
See Also:
Map.findPath(Tile, Tile, PathType), Map.findPath(Unit, Tile , Tile)

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.
See Also:
findPath(Tile)

getTurnsToReach

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

Parameters:
end - The Tile to be reached by this Unit.
Returns:
The number of turns it will take to reach the end, or Integer.MAX_VALUE if no path can be 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 Integer.MAX_VALUE 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 Integer.MAX_VALUE if no path can be found.

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.
See Also:
Tile.getMoveCost(net.sf.freecol.common.model.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.
See Also:
Tile.getMoveCost(net.sf.freecol.common.model.Tile)

canTradeWith

public boolean canTradeWith(Settlement settlement)
Returns true if this unit can enter a settlement in order to trade.

Parameters:
settlement - The settlement to enter.
Returns:
true if this Player can trade with the given Settlement. The unit will for instance need to be a carrier and have goods onboard.

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.

getMoveType

public Unit.MoveType getMoveType(Tile from,
                                 Tile target,
                                 int ml,
                                 boolean ignoreEnemyUnits)
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.
ignoreEnemyUnits - Should be true if enemy units should be ignored when determining the move type.
Returns:
The move type.

getSimpleMoveType

public Unit.MoveType getSimpleMoveType(Tile from,
                                       Tile target,
                                       boolean ignoreEnemyUnits)
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.
ignoreEnemyUnits - Should be true if enemy units should be ignored when determining the move type.
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.

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.

move

public void move(Map.Direction direction)
Moves this unit in the specified direction.

Parameters:
direction - The direction
Throws:
java.lang.IllegalStateException - If the move is illegal.
See Also:
getMoveType(Map.Direction)

activeAdjacentSentryUnits

public void activeAdjacentSentryUnits(Tile tile)
Active units with sentry state wich are adjacent to a specified tile

Parameters:
tile - The tile to iterate over adjacent tiles.

embark

public void embark(Unit unit)
Embarks this unit onto the specified unit.

Parameters:
unit - The unit to embark onto.
Throws:
java.lang.IllegalStateException - If the embark is illegal.

boardShip

public void boardShip(Unit carrier)
Boards a carrier that is on the same tile.

Parameters:
carrier - The carrier this unit shall embark.
Throws:
java.lang.IllegalStateException - If the carrier is on another tile than 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.

add

public void 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 void 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()
Description copied from interface: Location
Returns a list containing all the Units present at this Location.

Specified by:
getUnitList in interface Location
Returns:
a list containing the Units present at this location.

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.

work

public void work(WorkLocation workLocation)
Sets this Unit to work in the specified WorkLocation.

Parameters:
workLocation - The place where this Unit shall be out to work.
Throws:
java.lang.IllegalStateException - If the workLocation is in another Colony than this Unit.

work

public void work(TileImprovement improvement)
Sets this Unit to work at this TileImprovement

Parameters:
improvement - a TileImprovement value
Throws:
java.lang.IllegalStateException - If the TileImprovement is on another Tile than this Unit or is not a valid pioneer.

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 of the Unit.

contactAdjacent

public void contactAdjacent(Tile tile)
Contact Players with Units or Settlements on surrounding Tiles.

Parameters:
tile - a Tile value

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.

putOutsideColony

public void putOutsideColony()
Puts this Unit outside the Colony by moving it to the Tile below.


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.

equipWith

public void equipWith(EquipmentType equipmentType)
Describe equipWith method here.

Parameters:
equipmentType - an EquipmentType value

equipWith

public void equipWith(EquipmentType equipmentType,
                      int amount)
Describe equipWith method here.

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

equipWith

public void equipWith(EquipmentType equipmentType,
                      boolean asResultOfCombat)
Describe equipWith method here.

Parameters:
equipmentType - an EquipmentType value
asResultOfCombat - a boolean value

equipWith

public void equipWith(EquipmentType equipmentType,
                      int amount,
                      boolean asResultOfCombat)
Equip this unit with the given EquipmentType, provided that all requirements are met, and that the EquipmentType can be built at this location or is present as a result of combat.

Parameters:
equipmentType - an EquipmentType value
amount - an int value
asResultOfCombat - a boolean value
See Also:
canBeEquippedWith(net.sf.freecol.common.model.EquipmentType)

removeEquipment

public void removeEquipment(EquipmentType equipmentType)

removeEquipment

public void removeEquipment(EquipmentType equipmentType,
                            int amount)
Describe removeEquipment method here.

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

removeEquipment

public void removeEquipment(EquipmentType equipmentType,
                            int amount,
                            boolean asResultOfCombat)
Describe removeEquipment method here.

Parameters:
equipmentType - an EquipmentType value
amount - an int value
asResultOfCombat - a boolean value

removeAllEquipment

public void removeAllEquipment(boolean asResultOfCombat)

getEquipmentCount

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

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

switchEquipmentWith

public void switchEquipmentWith(Unit unit)
Switches equipment between colonists


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.

isBetweenEuropeAndNewWorld

public boolean isBetweenEuropeAndNewWorld()
Checks if this Unit is either a carrier or on one, bound to/from Europe

Returns:
The result.

buyGoods

public void buyGoods(GoodsType goodsType,
                     int amount)
Buys goods of a specified type and amount and adds it to this Unit. Can only be used when the Unit is a carrier and is located in Europe.

Parameters:
goodsType - The type of goods to buy.
amount - The amount of goods to buy.

isCarrier

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

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

isCarrier

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

Parameters:
unitType - The type used when checking.
Returns:
'true' if the unit can carry other units, 'false' otherwise.

getOwner

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

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

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.

setType

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

Parameters:
newUnitType - The new type of the unit.

getMovesLeft

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

Returns:
The amount of moves this Unit has left. If the unit.isUnderRepair() then 0 is always returned.

isArmed

public boolean isArmed()

isMounted

public boolean isMounted()

getEquipmentLabel

public java.lang.String getEquipmentLabel()
Return a description of the unit's equipment.

Returns:
a String value

getName

public java.lang.String getName()
Returns the name of this Unit (most likely 'null').

Specified by:
getName in interface Named
Returns:
the name of this Unit.

setName

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

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

getInitialMovesLeft

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

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.

sendToRepairLocation

public void sendToRepairLocation(Location l)
Sends this Unit to the closest Location it can get repaired.


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.

getOccupationIndicator

public java.lang.String getOccupationIndicator()
Get occupation indicator

Returns:
The occupation indicator string

getDetailedOccupationIndicator

public java.lang.String getDetailedOccupationIndicator()
Get detailed occupation indicator

Returns:
The detailed occupation indicator string.

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.

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.

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, ...}.

canMoveToEurope

public boolean canMoveToEurope()
Checks if this Unit can be moved to Europe.

Returns:
true if this unit can move to Europe.

moveToEurope

public void moveToEurope()
Moves this unit to Europe.

Throws:
java.lang.IllegalStateException - If the move is illegal.

moveToAmerica

public void moveToAmerica()
Moves this unit to america.

Throws:
java.lang.IllegalStateException - If the move is illegal.

canBuildColony

public boolean canBuildColony()
Check if this unit can build a colony on the tile where it is located.

Returns:
true if this unit can build a colony on the tile where it is located and false otherwise.

buildColony

public void buildColony(Colony colony)
Makes this unit build the specified colony.

Parameters:
colony - The colony this unit shall build.

joinColony

public void joinColony(Colony colony)
Join existing colony.

Parameters:
colony - a Colony value

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()
Get the number of turns of work left. Caution: This does not equal the internal amount of work left as expert bonuses are included in the returned number.

Returns:
number of turns of work left.

doAssignedWork

public void doAssignedWork()
The status of units that are currently working (for instance on building a road, or fortifying themselves) is updated in this method.


setEntryLocation

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

Parameters:
entryLocation - The Location.
See Also:
getEntryLocation()

getEntryLocation

public Location getEntryLocation()
Gets the Location in which this unit will be put when returning from Europe. If this Unit has not not been outside europe before, it will return the default value from the Player owning this Unit.

Returns:
The Location.
See Also:
Player.getEntryLocation(), getVacantEntryLocation()

getVacantEntryLocation

public Location getVacantEntryLocation()
Gets the Location in which this unit will be put when returning from Europe. If this Unit has not not been outside europe before, it will return the default value from the Player owning this Unit. If the tile is occupied by a enemy unit, then a nearby tile is choosen.

WARNING: Only the server has the information to determine which Tile is occupied. Use ModelController.setToVacantEntryLocation(net.sf.freecol.common.model.Unit) instead.

Returns:
The Location.
See Also:
getEntryLocation()

isOffensiveUnit

public boolean isOffensiveUnit()
Checks if this is an offensive unit.

Returns:
true if this is an offensive unit meaning it can attack other units.

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.

isUndead

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

Returns:
return true if the unit is undead

train

public void train()
Train the current unit in the job of its teacher.


adjustTension

public void adjustTension(Unit enemyUnit)
Adjusts the tension and alarm levels of the enemy unit's owner according to the type of attack.

Parameters:
enemyUnit - The unit we are attacking.

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.

captureGoods

public void captureGoods(Unit enemyUnit)
Captures the goods on board of the enemy unit.

Parameters:
enemyUnit - The unit we are attacking.

getColony

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

Specified by:
getColony in interface Location
Returns:
The Colony it's in, or null if it is not in a Colony

clearSpeciality

public void clearSpeciality()
Clear the specialty of a Unit changing the UnitType to the UnitType specified for clearing.


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.

disposeAllUnits

public void disposeAllUnits()
Disposes all Units aboard this one.


dispose

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

Overrides:
dispose in class FreeColGameObject

newTurn

public void newTurn()
Prepares the Unit for a new turn.


isAlreadyOnHighSea

public boolean isAlreadyOnHighSea()
Returns true if this unit has already been moved onto high seas but not to europe.

Returns:
true if the unit has already been moved onto high seas

setAlreadyOnHighSea

public void setAlreadyOnHighSea(boolean alreadyOnHighSea)
Tells unit that it has just entered the high seas but instead of going to europe, it stays on the current side of the atlantic.

Parameters:
alreadyOnHighSea -

getTurnsForRepair

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

Returns:
turns to be repaired

getPathTypeImage

public java.lang.String getPathTypeImage()
Return the type of the image which will be used to draw the path

Returns:
a String to form the resource key

getAutomaticEquipment

public TypeCountMap<EquipmentType> getAutomaticEquipment()

getXMLElementTagName

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

Returns:
"unit"

learnFromIndianSettlement

public void learnFromIndianSettlement(IndianSettlement settlement)