|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.common.model.FreeColGameObject
net.sf.freecol.common.model.Unit
public class Unit
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 | |
|---|---|
private boolean |
alreadyOnHighSea
Describes if the unit has been moved onto high sea but not to europe. |
private int |
attrition
The attrition this unit has accumulated. |
static java.lang.String |
CARGO_CHANGE
|
private int |
currentStop
|
private Location |
destination
|
private Location |
entryLocation
|
private 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. |
private int |
experience
|
private GoodsContainer |
goodsContainer
|
private int |
hitpoints
|
private IndianSettlement |
indianSettlement
|
private Location |
location
|
private static java.util.logging.Logger |
logger
|
private int |
movesLeft
|
private java.lang.String |
name
The individual name of this unit, not of the unit type. |
private boolean |
naval
|
private Player |
owner
|
private Unit.Role |
role
|
private static UnitType |
scoutSkill
|
private static java.util.Comparator<Unit> |
skillLevelComp
|
private Unit.UnitState |
state
|
private Unit |
student
The student of this Unit, if it has one. |
private Unit |
teacher
The teacher of this Unit, if it has one. |
private TradeRoute |
tradeRoute
|
private int |
treasureAmount
|
static int |
TURNS_TO_SAIL
The number of turns required to sail between Europe and the New World. |
private int |
turnsOfTraining
|
private java.util.List<Unit> |
units
|
private static java.lang.String |
UNITS_TAG_NAME
|
private UnitType |
unitType
|
private int |
visibleGoodsCount
The amount of goods carried by this unit. |
private TileImprovement |
workImprovement
|
private int |
workLeft
The number of turns until the work is finished, or '-1' if a Unit can stay in its state forever. |
private GoodsType |
workType
|
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE |
| 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. |
private void |
checkExperiencePromotion()
Checks if a colonist can get promoted by experience. |
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. |
private void |
dumpEquipment(EquipmentType equipmentType,
int amount,
boolean asResultOfCombat)
|
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. |
private void |
expendEquipment(EquipmentType type,
int amount)
Reduces the number of tools and produces a warning if all tools are used up. |
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. |
private Unit.MoveType |
getLandMoveType(Tile from,
Tile target,
boolean ignoreEnemyUnits)
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. |
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'). |
private Unit.MoveType |
getNavalMoveType(Tile from,
Tile target,
boolean ignoreEnemyUnits)
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. |
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). |
private Location |
newLocation(Game game,
java.lang.String locationString)
|
void |
newTurn()
Prepares the Unit for a new turn. |
void |
nextStop()
Set current stop to the next valid stop if any. |
private boolean |
perhapsLearnFromSettlement(IndianSettlement settlement)
Can we perhaps learn a skill in this settlement? |
void |
putOutsideColony()
Puts this Unit outside the Colony by moving it to
the Tile below. |
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. |
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. |
private 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. |
private 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 |
setWorkType(GoodsType type)
Sets the type of goods this unit is producing in its current occupation. |
(package private) boolean |
shouldGoToStop(TradeRoute.Stop stop)
Returns true if the Unit should proceed to the given stop. |
private void |
spendAllMoves()
Set movesLeft to 0 if has some spent moves and it's in a colony |
void |
switchEquipmentWith(Unit unit)
Switches equipment between colonists |
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. |
void |
train()
Train the current unit in the job of its teacher. |
private void |
unitsToXML(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
|
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 |
|---|
addModelMessage, addModelMessage, addModelMessage, addToRemoveElement, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, readFromXMLPartialByClass, setFakeID, setGame, setId, toSavedXML, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject, updateID |
| 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 |
|---|
private static java.util.Comparator<Unit> skillLevelComp
private static final java.util.logging.Logger logger
private static final java.lang.String EQUIPMENT_TAG
private static final java.lang.String UNITS_TAG_NAME
public static final int TURNS_TO_SAIL
public static final java.lang.String CARGO_CHANGE
public static final java.lang.String EQUIPMENT_CHANGE
private UnitType unitType
private boolean naval
private int movesLeft
private Unit.UnitState state
private Unit.Role role
private int workLeft
private int hitpoints
private Player owner
private java.util.List<Unit> units
private GoodsContainer goodsContainer
private Location entryLocation
private Location location
private IndianSettlement indianSettlement
private Location destination
private TradeRoute tradeRoute
private int currentStop
private int treasureAmount
private TileImprovement workImprovement
private GoodsType workType
private int experience
private int turnsOfTraining
private int attrition
private java.lang.String name
private int visibleGoodsCount
getVisibleGoodsCount()private boolean alreadyOnHighSea
private Unit student
private Unit teacher
private TypeCountMap<EquipmentType> equipment
private static UnitType scoutSkill
| Constructor Detail |
|---|
public Unit(Game game,
Player owner,
UnitType type)
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.
game - The Game in which this Unit
belong.owner - The Player owning the unit.type - The type of the unit.
public Unit(Game game,
Location location,
Player owner,
UnitType type,
Unit.UnitState state)
Unit with the specified 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...).
public Unit(Game game,
Location location,
Player owner,
UnitType type,
Unit.UnitState state,
EquipmentType... initialEquipment)
Unit with the specified 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
public Unit(Game game,
javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
game - The Game in which this Unit
belong.in - The input stream containing the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
public Unit(Game game,
org.w3c.dom.Element e)
game - The Game in which this Unit
belong.e - An XML-element that will be used to initialize this object.
public Unit(Game game,
java.lang.String id)
Unit with the given ID. The object should
later be initialized by calling either
FreeColGameObject.readFromXML(XMLStreamReader) or
FreeColObject.readFromXMLElement(Element).
game - The Game in which this object belong.id - The unique identifier for this object.| Method Detail |
|---|
public boolean canCarryUnits()
true if the Unit can carry other Units.
boolean valuepublic boolean canCarryGoods()
true if the Unit can carry Goods.
boolean valuepublic final UnitType getType()
UnitType value.
getType in interface Typed<UnitType>UnitType valuepublic int getTreasureAmount()
public void setTreasureAmount(int amt)
amt - The amount of treasurepublic final TypeCountMap<EquipmentType> getEquipment()
Equipment value.
List valuepublic final void setEquipment(TypeCountMap<EquipmentType> newEquipment)
Equipment value.
newEquipment - The new Equipment value.public final TradeRoute getTradeRoute()
TradeRoute value.
TradeRoute valuepublic final void setTradeRoute(TradeRoute newTradeRoute)
TradeRoute value.
newTradeRoute - The new TradeRoute value.public TradeRoute.Stop getCurrentStop()
public void nextStop()
boolean shouldGoToStop(TradeRoute.Stop stop)
stop - a Stop value
boolean valuepublic boolean canCashInTreasureTrain()
Location.
true if the treasure train can be cashed in.
java.lang.IllegalStateException - if this unit is not a treasure train.public boolean canCashInTreasureTrain(Location loc)
Location.
loc - The Location.
true if the treasure train can be cashed in.
java.lang.IllegalStateException - if this unit is not a treasure train.public int getTransportFee()
int valuepublic boolean isColonist()
Unit is a colonist. A Unit
is a colonist if it can build a new Colony.
public int getNeededTurnsOfTraining()
getTurnsOfTraining()
public static int getNeededTurnsOfTraining(UnitType typeTeacher,
UnitType typeStudent)
typeTeacher - the unit type of the teachertypeStudent - the unit type of the student
getTurnsOfTraining()
public static UnitType getUnitTypeTeaching(UnitType typeTeacher,
UnitType typeStudent)
typeTeacher - the unit type of the teachertypeStudent - the unit type of the student
UnitType valuegetTurnsOfTraining()public int getSkillLevel()
public static int getSkillLevel(UnitType unitType)
Unit.
unitType - The type of Unit.
public static java.util.Comparator<Unit> getSkillLevelComparator()
public int getTurnsOfTraining()
Unit has
given.setTurnsOfTraining(int),
getNeededTurnsOfTraining()public void setTurnsOfTraining(int turnsOfTraining)
turnsOfTraining - The number of turns of training this
Unit has given.getNeededTurnsOfTraining()public int getExperience()
Unit at its current workType.
Unit at its current
workType.modifyExperience(int)public void modifyExperience(int value)
Unit at its current
workType.
value - The value by which to modify the experience of this
Unit.getExperience()public boolean hasAbility(java.lang.String id)
id.
hasAbility in class FreeColObjectid - a String value
boolean valuepublic java.util.Set<Modifier> getModifierSet(java.lang.String id)
id - a String value
Modifier valuepublic void addFeature(Feature feature)
feature - a Feature valuepublic boolean canBeStudent(Unit teacher)
teacher - the teacher which is trying to teach it
boolean value
public static boolean canBeStudent(UnitType typeStudent,
UnitType typeTeacher)
typeStudent - the unit type of the studenttypeTeacher - the unit type of the teacher which is trying to teach
it
boolean valuepublic final Unit getStudent()
Student value.
Unit valuepublic final void setStudent(Unit newStudent)
Student value.
newStudent - The new Student value.public final Unit getTeacher()
Teacher value.
Unit valuepublic final void setTeacher(Unit newTeacher)
Teacher value.
newTeacher - The new Teacher value.public Building getWorkLocation()
Building this unit is working in.
public ColonyTile getWorkTile()
ColonyTile this unit is working in.
public GoodsType getWorkType()
public void setWorkType(GoodsType type)
type - The type of goods to attempt to produce.public TileImprovement getWorkImprovement()
TileImprovementpublic void setWorkImprovement(TileImprovement imp)
public Location getDestination()
public void setDestination(Location newDestination)
newDestination - The new destination of this unit.public PathNode findPath(Tile end)
Tile to the one
specified. Only paths on water are allowed if isNaval()
and only paths on land if not.
Tile at the end will not be checked
against the legal moves of this Unit.
end - The Tile in which the path ends.
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.
java.lang.IllegalArgumentException - if end == nullMap.findPath(Tile, Tile, PathType),
Map.findPath(Unit, Tile , Tile)
public PathNode findPath(Tile start,
Tile end)
Tile to the one
specified. Only paths on water are allowed if isNaval()
and only paths on land if not.
start - The Tile in which the path starts.end - The Tile in which the path ends.
PathNode for the first tile in the path.findPath(Tile)public int getTurnsToReach(Tile end)
Unit will have to use in
order to reach the given Tile.
end - The Tile to be reached by this
Unit.
end,
or Integer.MAX_VALUE if no path can be found.
public int getTurnsToReach(Tile start,
Tile end)
Unit will have to use in
order to reach the given Tile.
start - The Tile to start the search from.end - The Tile to be reached by this
Unit.
end,
or Integer.MAX_VALUE if no path can be found.public int getTurnsToReach(Location destination)
Unit will have to use in
order to reach the given Location.
destination - The destination for this unit.
destination, or Integer.MAX_VALUE
if no path can be found.public int getMoveCost(Tile target)
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.
target - The Tile this Unit will move
onto.
Tile.Tile.getMoveCost(net.sf.freecol.common.model.Tile)
public int getMoveCost(Tile from,
Tile target,
int ml)
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.
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.
Tile.Tile.getMoveCost(net.sf.freecol.common.model.Tile)public boolean canTradeWith(Settlement settlement)
settlement - The settlement to enter.
true if this Player can trade with
the given Settlement. The unit will for instance
need to be a carrier and have goods onboard.public Unit.MoveType getMoveType(Map.Direction direction)
direction - The direction of the move.
public Unit.MoveType getMoveType(Tile target)
target - The target Tile of the move.
public Unit.MoveType getMoveType(Tile from,
Tile target,
int ml)
from - The origin Tile of the move.target - The target Tile of the move.ml - The amount of moves this unit has left.
public Unit.MoveType getMoveType(Tile from,
Tile target,
int ml,
boolean ignoreEnemyUnits)
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.
public Unit.MoveType getSimpleMoveType(Tile from,
Tile target,
boolean ignoreEnemyUnits)
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.
public Unit.MoveType getSimpleMoveType(Tile target)
target - The target Tile of the move.
public Unit.MoveType getSimpleMoveType(Map.Direction direction)
direction - The direction of the move.
private Unit.MoveType getNavalMoveType(Tile from,
Tile target,
boolean ignoreEnemyUnits)
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.
private boolean perhapsLearnFromSettlement(IndianSettlement settlement)
settlement - The IndianSettlement to test.
- Returns:
- True/false if there is possibly a skill to learn.
private Unit.MoveType getLandMoveType(Tile from,
Tile target,
boolean ignoreEnemyUnits)
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.
public void setMovesLeft(int movesLeft)
movesLeft.
movesLeft - The new amount of moves left this Unit
should have. If movesLeft < 0 then
movesLeft = 0.public int getSpaceTaken()
Unit takes when put on a
carrier.
getSpaceTaken in interface LocatableUnit takes.public int getLineOfSight()
Unit. That is the distance
this Unit can spot new tiles, enemy unit e.t.c.
Unit.public void move(Map.Direction direction)
direction - The direction
java.lang.IllegalStateException - If the move is illegal.getMoveType(Map.Direction)public void activeAdjacentSentryUnits(Tile tile)
tile - The tile to iterate over adjacent tiles.public void embark(Unit unit)
unit - The unit to embark onto.
java.lang.IllegalStateException - If the embark is illegal.public void boardShip(Unit carrier)
carrier - The carrier this unit shall embark.
java.lang.IllegalStateException - If the carrier is on another tile than
this unit.public boolean isOnCarrier()
public void setStateToAllChildren(Unit.UnitState state)
state - The state.private void spendAllMoves()
add(Locatable),
remove(Locatable)public void add(Locatable locatable)
Unit.
add in interface Locationlocatable - The Locatable to add to this
Unit.public void remove(Locatable locatable)
Locatable from this Unit.
remove in interface Locationlocatable - The Locatable to remove from this
Unit.public boolean contains(Locatable locatable)
Unit contains the specified
Locatable.
contains in interface Locationlocatable - The Locatable to test the presence of.
Locatable is
on this Unit and
public boolean canAdd(Locatable locatable)
Unit. The locatable cannot be added is this
Unit if it is not a carrier or if there is no room left.
canAdd in interface Locationlocatable - The Locatable to test the addabillity of.
public int getLoadableAmount(GoodsType type)
type - a GoodsType value
int valuepublic int getUnitCount()
getUnitCount in interface Locationpublic Unit getFirstUnit()
Unit beeing carried by this
Unit.
Unit.public Unit getLastUnit()
Unit beeing carried by this
Unit.
Unit.public boolean isVisibleTo(Player player)
player - The Player.
true if this Unit is visible to the
given Player.public java.util.Iterator<Unit> getUnitIterator()
Iterator of every Unit directly
located on this Location.
getUnitIterator in interface LocationIterator.public java.util.List<Unit> getUnitList()
Location
getUnitList in interface Locationpublic java.util.Iterator<Goods> getGoodsIterator()
Iterator of every Unit directly
located on this Location.
Iterator.public java.util.List<Goods> getGoodsList()
List containing the goods carried by this unit.
List containing the goods carried by this unit.public GoodsContainer getGoodsContainer()
LocationGoodsContainer this Location use
for storing it's goods.
getGoodsContainer in interface LocationGoodsContainer or null if the
Location cannot store any goods.public void work(WorkLocation workLocation)
Unit to work in the specified
WorkLocation.
workLocation - The place where this Unit shall be out
to work.
java.lang.IllegalStateException - If the workLocation is in
another Colony than this Unit.public void work(TileImprovement improvement)
Unit to work at this
TileImprovement
improvement - a TileImprovement value
java.lang.IllegalStateException - If the TileImprovement is
on another Tile than this Unit or
is not a valid pioneer.public void setLocationNoUpdate(Location newLocation)
newLocation - The new Locationpublic void setLocation(Location newLocation)
setLocation in interface LocatablenewLocation - The new Location of the Unit.public void contactAdjacent(Tile tile)
tile - a Tile valuepublic void setIndianSettlement(IndianSettlement indianSettlement)
IndianSettlement that owns this unit.
indianSettlement - The IndianSettlement that should
now be owning this Unit.public IndianSettlement getIndianSettlement()
IndianSettlement that owns this unit.
IndianSettlement.public Location getLocation()
getLocation in interface Locatablepublic void putOutsideColony()
Unit outside the Colony by moving it to
the Tile below.
public boolean canBeEquippedWith(EquipmentType equipmentType)
EquipmentType at the current Location.
This is the case if all requirements of the EquipmentType are met.
equipmentType - an EquipmentType value
EquipmentType at the current location.public void equipWith(EquipmentType equipmentType)
equipWith method here.
equipmentType - an EquipmentType value
public void equipWith(EquipmentType equipmentType,
int amount)
equipWith method here.
equipmentType - an EquipmentType valueamount - an int value
public void equipWith(EquipmentType equipmentType,
boolean asResultOfCombat)
equipWith method here.
equipmentType - an EquipmentType valueasResultOfCombat - a boolean value
public void equipWith(EquipmentType equipmentType,
int amount,
boolean asResultOfCombat)
equipmentType - an EquipmentType valueamount - an int valueasResultOfCombat - a boolean valuecanBeEquippedWith(net.sf.freecol.common.model.EquipmentType)public void removeEquipment(EquipmentType equipmentType)
public void removeEquipment(EquipmentType equipmentType,
int amount)
removeEquipment method here.
equipmentType - an EquipmentType valueamount - an int value
public void removeEquipment(EquipmentType equipmentType,
int amount,
boolean asResultOfCombat)
removeEquipment method here.
equipmentType - an EquipmentType valueamount - an int valueasResultOfCombat - a boolean valuepublic void removeAllEquipment(boolean asResultOfCombat)
private void dumpEquipment(EquipmentType equipmentType,
int amount,
boolean asResultOfCombat)
public int getEquipmentCount(EquipmentType equipmentType)
getEquipmentCount method here.
equipmentType - an EquipmentType value
int valuepublic void switchEquipmentWith(Unit unit)
public boolean isInEurope()
Unit is located in Europe. That is; either
directly or onboard a carrier which is in Europe.
public boolean isBetweenEuropeAndNewWorld()
Unit is either a carrier or on one, bound
to/from Europe
public void buyGoods(GoodsType goodsType,
int amount)
Unit. Can only be used when the Unit is a
carrier and is located in Europe.
goodsType - The type of goods to buy.amount - The amount of goods to buy.public boolean isCarrier()
Unit is able to carry Locatables.
public static boolean isCarrier(UnitType unitType)
Unit is able to carry Locatables.
unitType - The type used when checking.
public Player getOwner()
getOwner in interface Ownablepublic void setOwner(Player owner)
setOwner in interface Ownableowner - The new owner of this Unit.public void setType(UnitType newUnitType)
newUnitType - The new type of the unit.public int getMovesLeft()
unit.isUnderRepair() then 0 is
always returned.public boolean isArmed()
public boolean isMounted()
public java.lang.String getEquipmentLabel()
String valuepublic java.lang.String getName()
getName in interface Namedpublic void setName(java.lang.String newName)
Name value.
setName in interface NameablenewName - The new Name value.public int getInitialMovesLeft()
public void setHitpoints(int hitpoints)
hitpoints - The hitpoints this unit has. This is currently only used
for damaged ships, but might get an extended use later.UnitType.getHitPoints()public int getHitpoints()
UnitType.getHitPoints()public boolean isUnderRepair()
public void sendToRepairLocation(Location l)
Unit to the closest Location it
can get repaired.
public java.lang.String toString()
toString in class FreeColGameObjectpublic java.lang.String getMovesAsString()
public boolean isNaval()
Unit is naval.
public java.lang.String getOccupationIndicator()
public java.lang.String getDetailedOccupationIndicator()
public Unit.UnitState getState()
Unit.
Unit.public Unit.Role getRole()
Role of this Unit.
role of this Unit.private void setRole()
public boolean checkSetState(Unit.UnitState s)
Unit can get the given state set.
s - The new state for this Unit. Should be one of {UnitState.ACTIVE,
FORTIFIED, ...}.
public void setState(Unit.UnitState s)
s - The new state for this Unit. Should be one of {UnitState.ACTIVE,
UnitState.FORTIFIED, ...}.private void setStateUnchecked(Unit.UnitState s)
public boolean canMoveToEurope()
Unit can be moved to Europe.
true if this unit can move to Europe.public void moveToEurope()
java.lang.IllegalStateException - If the move is illegal.public void moveToAmerica()
java.lang.IllegalStateException - If the move is illegal.public boolean canBuildColony()
true if this unit can build a colony on the tile
where it is located and false otherwise.public void buildColony(Colony colony)
colony - The colony this unit shall build.public void joinColony(Colony colony)
colony - a Colony valuepublic Tile getTile()
getTile in interface LocatablegetTile in interface Locationpublic int getSpaceLeft()
public int getVisibleGoodsCount()
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.public int getGoodsCount()
public void moveToFront(Unit u)
u - The unit to move to the front.public int getWorkLeft()
public void doAssignedWork()
private void expendEquipment(EquipmentType type,
int amount)
amount - The number of tools to remove.public void setEntryLocation(Location entryLocation)
Location in which this unit will be put when
returning from Europe.
entryLocation - The Location.getEntryLocation()public Location getEntryLocation()
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.
Location.Player.getEntryLocation(),
getVacantEntryLocation()public Location getVacantEntryLocation()
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.
Tile is occupied. Use
ModelController.setToVacantEntryLocation(net.sf.freecol.common.model.Unit) instead.
Location.getEntryLocation()public boolean isOffensiveUnit()
true if this is an offensive unit meaning it can
attack other units.public boolean isDefensiveUnit()
Settlement.
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.public boolean isUndead()
public void train()
public void adjustTension(Unit enemyUnit)
enemyUnit - The unit we are attacking.public boolean canCarryTreasure()
true if this Unit is capable of
carrying treasure.public boolean canCaptureGoods()
true if this Unit is capable of
capturing goods.public void captureGoods(Unit enemyUnit)
enemyUnit - The unit we are attacking.public Colony getColony()
getColony in interface Locationpublic void clearSpeciality()
Unit changing the UnitType to the
UnitType specified for clearing.
public int getProductionOf(GoodsType goodsType,
int base)
goodsType - The type of goods to be produced.base - an int value
public void disposeAllUnits()
public void dispose()
dispose in class FreeColGameObjectprivate void checkExperiencePromotion()
public void newTurn()
Unit for a new turn.
private Location newLocation(Game game,
java.lang.String locationString)
public boolean isAlreadyOnHighSea()
public void setAlreadyOnHighSea(boolean alreadyOnHighSea)
alreadyOnHighSea - public int getTurnsForRepair()
public java.lang.String getPathTypeImage()
String to form the resource keypublic TypeCountMap<EquipmentType> getAutomaticEquipment()
private void unitsToXML(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
throws javax.xml.stream.XMLStreamException
Player will be added
to that representation if showAll is set to
false.
toXMLImpl in class FreeColGameObjectout - 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.
javax.xml.stream.XMLStreamException - if there are any problems writing to the
stream.
protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readFromXMLImpl in class FreeColObjectin - The input stream with the XML.
javax.xml.stream.XMLStreamException - is thrown if something goes
wrong.
protected void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out,
java.lang.String[] fields)
throws javax.xml.stream.XMLStreamException
toXMLPartialImpl in class FreeColObjectout - The target stream.fields - The fields to write.
javax.xml.stream.XMLStreamException - If there are problems writing the stream.
protected void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readFromXMLPartialImpl in class FreeColObjectin - The input stream with the XML.
javax.xml.stream.XMLStreamException - If there are problems reading the stream.public static java.lang.String getXMLElementTagName()
public void learnFromIndianSettlement(IndianSettlement settlement)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||