|
|||||||||
| 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 | |
|---|---|
protected int |
attrition
The attrition this unit has accumulated. |
static java.lang.String |
CARGO_CHANGE
|
protected int |
currentStop
Which stop in a trade route the unit is going to. |
protected Location |
destination
|
protected Location |
entryLocation
|
protected TypeCountMap<EquipmentType> |
equipment
The equipment this Unit carries. |
static java.lang.String |
EQUIPMENT_CHANGE
|
private static java.lang.String |
EQUIPMENT_TAG
XML tag name for equipment list. |
protected java.lang.String |
ethnicity
|
protected int |
experience
|
private GoodsType |
experienceType
What type of goods this unit last earned experience producing. |
protected GoodsContainer |
goodsContainer
|
protected int |
hitpoints
|
protected IndianSettlement |
indianSettlement
|
protected Location |
location
|
private static java.util.logging.Logger |
logger
|
protected int |
movesLeft
|
protected java.lang.String |
name
The individual name of this unit, not of the unit type. |
protected java.lang.String |
nationality
|
protected Player |
owner
|
protected Unit.Role |
role
|
private static java.util.Comparator<Unit> |
skillLevelComp
|
protected Unit.UnitState |
state
|
protected Unit |
student
The student of this Unit, if it has one. |
protected Unit |
teacher
The teacher of this Unit, if it has one. |
protected TradeRoute |
tradeRoute
The trade route this unit has. |
protected int |
treasureAmount
To be used only for type == TREASURE_TRAIN |
protected int |
turnsOfTraining
|
protected java.util.List<Unit> |
units
|
protected UnitType |
unitType
|
protected int |
visibleGoodsCount
The amount of goods carried by this unit. |
protected TileImprovement |
workImprovement
What is being improved (to be used only for PIONEERs - where they are working. |
protected int |
workLeft
The number of turns until the work is finished, or '-1' if a Unit can stay in its state forever. |
protected GoodsType |
workType
What type of goods this unit produces in its occupation. |
| Fields inherited from class net.sf.freecol.common.model.FreeColGameObject |
|---|
UNITS_TAG_NAME |
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG |
| Fields inherited from interface net.sf.freecol.common.model.Consumer |
|---|
BUILDING_PRIORITY, COLONY_PRIORITY, COMPARATOR, POPULATION_PRIORITY, UNIT_PRIORITY |
| Constructor Summary | |
|---|---|
protected |
Unit()
Constructor for ServerUnit. |
protected |
Unit(Game game)
Constructor for ServerUnit. |
|
Unit(Game game,
org.w3c.dom.Element e)
Initialize this object from an XML-representation of this object. |
|
Unit(Game game,
java.lang.String id)
Initiates a new Unit with the given ID. |
|
Unit(Game game,
javax.xml.stream.XMLStreamReader in)
Initialize this object from an XML-representation of this object. |
| Method Summary | |
|---|---|
boolean |
add(Locatable locatable)
Adds a locatable to this Unit. |
void |
addFeature(Feature feature)
Add the given Feature to the Features Map. |
private boolean |
allowContact(Settlement settlement)
Is this unit allowed to contact a settlement? |
private boolean |
allowMoveFrom(Tile from)
Is this unit allowed to move from a source tile? Implements the restrictions on moving from water. |
static boolean |
betterDefender(Unit defender,
float defenderPower,
Unit other,
float otherPower)
Is an alternate unit a better defender than the current choice. |
boolean |
canAdd(Locatable locatable)
Checks wether or not the specified locatable may be added to this Unit. |
boolean |
canBeEquippedWith(EquipmentType equipmentType)
Checks whether this unit can be equipped with the given EquipmentType at the current
Location. |
boolean |
canBeStudent(Unit teacher)
Returns true if this unit can be a student. |
boolean |
canBeStudent(UnitType typeStudent,
UnitType typeTeacher)
Returns true if this type of unit can be a student. |
boolean |
canBuildColony()
Check if this unit can build a colony. |
EquipmentType |
canCaptureEquipment(EquipmentType equip,
Unit loser)
After winning a battle, can this unit the loser equipment? |
boolean |
canCaptureGoods()
Returns true if this unit is a ship that can capture enemy goods. |
boolean |
canCarryGoods()
Returns true if the Unit can carry Goods. |
boolean |
canCarryTreasure()
Returns true if this unit can carry treasure (like a treasure train) |
boolean |
canCarryUnit(Unit u)
Is this unit able to carry a specified one? |
boolean |
canCarryUnits()
Returns true if the Unit can carry other Units. |
boolean |
canCashInTreasureTrain()
Checks if the treasure train can be cashed in at it's current Location. |
boolean |
canCashInTreasureTrain(Location loc)
Checks if the treasure train can be cashed in at the given Location. |
boolean |
canMoveToEurope()
Checks if this Unit can be moved to Europe. |
java.util.List<EquipmentType> |
changeEquipment(EquipmentType type,
int amount)
Changes the equipment a unit has and returns a list of equipment it still has but needs to drop due to the changed equipment being incompatible. |
boolean |
checkSetState(Unit.UnitState s)
Checks if a Unit can get the given state set. |
void |
clearEquipment()
Clears all Equipment held by this unit. |
boolean |
contains(Locatable locatable)
Checks if this Unit contains the specified
Locatable. |
boolean |
couldMove()
Returns true if this Unit could still be moved. |
void |
dispose()
Removes all references to this object. |
java.util.List<FreeColGameObject> |
disposeList()
Removes all references to this object. |
PathNode |
findPath(Tile end)
Finds a shortest path from the current Tile to the one
specified. |
PathNode |
findPath(Tile start,
Tile end)
Finds a shortest path from the current Tile to the one
specified. |
PathNode |
findPath(Tile start,
Tile end,
Unit carrier)
Finds a shortest path from the current Tile to the one
specified. |
PathNode |
findPath(Tile start,
Tile end,
Unit carrier,
CostDecider costDecider)
Finds a shortest path from the current Tile to the one
specified. |
PathNode |
findPathToEurope()
Convenience wrapper to find a path to Europe for this unit. |
PathNode |
findPathToEurope(Tile start)
Convenience wrapper to find a path to Europe for this unit. |
StringTemplate |
getApparentOwnerName()
Get the name of the apparent owner of this Unit, (like getOwner().getNationAsString() but handles pirates) |
int |
getAttrition()
Gets the attrition of this unit. |
TypeCountMap<EquipmentType> |
getAutomaticEquipment()
Gets the available equipment that can be equipped automatically in case of an attack. |
EquipmentType |
getBestCombatEquipmentType(TypeCountMap<EquipmentType> equipment)
Gets the best combat equipment type that this unit has. |
float |
getBurnProbability()
Gets the probability that an attack by this unit will provoke natives to burn our missions. |
Colony |
getColony()
Gets the Colony this unit is in. |
java.util.List<AbstractGoods> |
getConsumedGoods()
Returns a list of GoodsTypes this Consumer consumes. |
float |
getConvertProbability()
Gets the probability that an attack by this unit will provoke a native to convert. |
int |
getCurrentStop()
Get the current stop. |
Location |
getDestination()
Returns the destination of this unit. |
Location |
getEntryLocation()
Gets the entry location for this unit to use when returning from Europe. |
TypeCountMap<EquipmentType> |
getEquipment()
Get the Equipment value. |
int |
getEquipmentCount(EquipmentType equipmentType)
Describe getEquipmentCount method here. |
StringTemplate |
getEquipmentLabel()
Return a description of the unit's equipment. |
java.lang.String |
getEthnicity()
Gets the ethnicity of this Unit. |
int |
getExperience()
Gets the experience of this Unit at its current
experienceType. |
GoodsType |
getExperienceType()
Gets the type of goods this unit has accrued experience producing. |
Unit |
getFirstUnit()
Gets the first Unit beeing carried by this
Unit. |
Tile |
getFullEntryLocation()
Gets the entry tile for this unit, or if null the default entry location for the owning player. |
GoodsContainer |
getGoodsContainer()
Gets the GoodsContainer this Location use
for storing it's goods. |
int |
getGoodsCount()
|
java.util.Iterator<Goods> |
getGoodsIterator()
Gets a Iterator of every Unit directly
located on this Location. |
java.util.List<Goods> |
getGoodsList()
Returns a List containing the goods carried by this unit. |
int |
getHitpoints()
Returns the hitpoints. |
IndianSettlement |
getIndianSettlement()
Gets the IndianSettlement that owns this unit. |
int |
getInitialMovesLeft()
Gets the amount of moves this unit has at the beginning of each turn. |
StringTemplate |
getLabel()
Describe getLabel method here. |
private Unit.MoveType |
getLandMoveType(Tile from,
Tile target)
Gets the type of a move that is made when moving a land unit to from one tile to another. |
Unit |
getLastUnit()
Gets the last Unit beeing carried by this
Unit. |
private Unit.MoveType |
getLearnMoveType(Tile from,
Settlement settlement)
Get the MoveType when moving a colonist to a settlement. |
int |
getLineOfSight()
Gets the line of sight of this Unit. |
int |
getLoadableAmount(GoodsType type)
Returns the amount of a GoodsType that could be loaded. |
Location |
getLocation()
Gets the location of this Unit. |
StringTemplate |
getLocationName()
Returns a name for this unit, as a location. |
StringTemplate |
getLocationNameFor(Player player)
Returns the name for this unit, as a location, for a particular player. |
private Unit.MoveType |
getMissionaryMoveType(Tile from,
Settlement settlement)
Get the MoveType when moving a missionary to a settlement. |
java.util.Set<Modifier> |
getModifierSet(java.lang.String id)
Get a modifier that applies to this Unit. |
java.util.Set<Modifier> |
getModifierSet(java.lang.String id,
Ownable ownable)
Get a modifier that applies to the given Ownable. |
int |
getMoveCost(Tile target)
Gets the cost of moving this Unit onto the given
Tile. |
int |
getMoveCost(Tile from,
Tile target,
int ml)
Gets the cost of moving this Unit from the given
Tile onto the given Tile. |
java.lang.String |
getMovesAsString()
|
int |
getMovesLeft()
Returns the amount of moves this Unit has left. |
Unit.MoveType |
getMoveType(Map.Direction direction)
Gets the type of a move made in a specified direction. |
Unit.MoveType |
getMoveType(Tile target)
Gets the type of a move that is made when moving from one tile to another. |
Unit.MoveType |
getMoveType(Tile from,
Tile target,
int ml)
Gets the type of a move that is made when moving from one tile to another. |
java.lang.String |
getName()
Describe getName method here. |
java.lang.String |
getNationality()
Gets the nationality of this Unit. |
private Unit.MoveType |
getNavalMoveType(Tile from,
Tile target)
Gets the type of a move that is made when moving a naval unit from one tile to another. |
int |
getNeededTurnsOfTraining()
Gets the number of turns this unit has to train to educate a student. |
int |
getNeededTurnsOfTraining(UnitType typeTeacher,
UnitType typeStudent)
Gets the number of turns this unit has to train to educate a student. |
Player |
getOwner()
Gets the owner of this Unit. |
int |
getPriority()
The priority of this Consumer. |
ProductionInfo |
getProductionInfo(java.util.List<AbstractGoods> input)
Describe getProductionInfo method here. |
int |
getProductionOf(GoodsType goodsType,
int base)
Given a type of goods to produce in the field and a tile, returns the unit's potential to produce goods. |
Location |
getRepairLocation()
Finds the closest Location to this tile where
this ship can be repaired. |
Unit.Role |
getRole()
Gets the Role of this Unit. |
int |
getSailTurns()
Gets the number of turns this unit will need to sail to/from Europe. |
private Unit.MoveType |
getScoutMoveType(Tile from,
Settlement settlement)
Get the MoveType when moving a scout to a settlement. |
Settlement |
getSettlement()
Gets the Settlement this unit is in. |
Unit.MoveType |
getSimpleMoveType(Map.Direction direction)
Gets the type of a move made in a specified direction, without checking if the unit has moves left or logging errors. |
Unit.MoveType |
getSimpleMoveType(Tile target)
Gets the type of a move that is made when moving from one tile to another, without checking if the unit has moves left or logging errors. |
Unit.MoveType |
getSimpleMoveType(Tile from,
Tile target)
Gets the type of a move that is made when moving from one tile to another, without checking if the unit has moves left or logging errors. |
int |
getSkillLevel()
Gets the skill level. |
static int |
getSkillLevel(UnitType unitType)
Gets the skill level of the given type of Unit. |
static java.util.Comparator<Unit> |
getSkillLevelComparator()
Returns a Comparator that compares the skill levels of given units. |
int |
getSpaceLeft()
Returns the amount of space left on this Unit. |
int |
getSpaceTaken()
Gets the amount of space this Unit takes when put on a
carrier. |
Unit.UnitState |
getState()
Gets the state of this Unit. |
TradeRoute.Stop |
getStop()
Get the stop the unit is heading for or at. |
Unit |
getStudent()
Get the Student value. |
Unit |
getTeacher()
Get the Teacher value. |
Tile |
getTile()
Returns the Tile where this Unit is located. |
private Unit.MoveType |
getTradeMoveType(Settlement settlement)
Get the MoveType when moving a trading unit to a
settlement. |
TradeRoute |
getTradeRoute()
Get the TradeRoute value. |
int |
getTransportFee()
Return the fee that would have to be paid to transport this treasure to Europe. |
int |
getTreasureAmount()
Returns the current amount of treasure in this unit. |
int |
getTurnsForRepair()
Return how many turns left to be repaired |
int |
getTurnsOfTraining()
Gets the number of turns this unit has been training. |
int |
getTurnsToReach(Location destination)
Returns the number of turns this Unit will have to
use in order to reach the given Location. |
int |
getTurnsToReach(Tile start,
Tile end)
Returns the number of turns this Unit will have to use in
order to reach the given Tile. |
UnitType |
getType()
Get the UnitType value. |
UnitType |
getTypeChange(UnitTypeChange.ChangeType change,
Player owner)
Get a type change for this unit. |
int |
getUnitCount()
Gets the amount of Units at this Location. |
java.util.Iterator<Unit> |
getUnitIterator()
Gets a Iterator of every Unit directly
located on this Location. |
java.util.List<Unit> |
getUnitList()
Gets a list of the units in this carrier unit. |
static UnitType |
getUnitTypeTeaching(UnitType typeTeacher,
UnitType typeStudent)
Gets the UnitType which a teacher is teaching to a student. |
int |
getVisibleGoodsCount()
Returns the amount of goods that is carried by this unit. |
Building |
getWorkBuilding()
Gets the Building this unit is working in. |
TileImprovement |
getWorkImprovement()
Gets the TileImprovement that this pioneer is contributing to. |
int |
getWorkLeft()
Gets the amount of work left. |
Building |
getWorkLocation()
Gets the Building this unit is working in. |
Location |
getWorkLocation2()
Gets the Location this unit is working in. |
ColonyTile |
getWorkTile()
Gets the ColonyTile this unit is working in. |
int |
getWorkTurnsLeft()
Get the number of turns of work left. |
GoodsType |
getWorkType()
Gets the type of goods this unit is producing in its current occupation. |
static java.lang.String |
getXMLElementTagName()
Gets the tag name of the root element representing this object. |
boolean |
hasAbility(java.lang.String id)
Returns true if the Unit, or its owner has the ability identified by id. |
boolean |
hasNativeEthnicity()
Identifies whether this unit came from a native tribe. |
boolean |
isArmed()
|
boolean |
isAtSea()
Checks whether this Unit is at sea off the map, or
on board of a carrier that is. |
boolean |
isCarrier()
Checks if this Unit is able to carry Locatables. |
boolean |
isColonist()
Checks if this Unit is a `colonist'. |
boolean |
isDefensiveUnit()
Checks if this is an defensive unit. |
boolean |
isInEurope()
Checks if this Unit is located in Europe. |
boolean |
isInMission()
Checks if this unit is running a mission. |
boolean |
isMounted()
|
boolean |
isNaval()
Checks if this Unit is naval. |
boolean |
isOffensiveUnit()
Checks if this is an offensive unit. |
boolean |
isOnCarrier()
Verifies if the unit is aboard a carrier |
boolean |
isPerson()
Checks if this unit is a person, that is not a ship or wagon. |
boolean |
isTradingUnit()
Checks if this is a trading Unit, meaning that it
can trade with settlements. |
boolean |
isUndead()
Checks if this unit is an undead. |
boolean |
isUnderRepair()
Checks if this unit is under repair. |
boolean |
isVisibleTo(Player player)
Checks if this unit is visible to the given player. |
boolean |
losingEquipmentDemotesUnit(EquipmentType lose)
Does losing a piece of equipment mean the demotion of this unit? |
boolean |
losingEquipmentKillsUnit(EquipmentType lose)
Does losing a piece of equipment mean the death of this unit? |
void |
modifyExperience(int value)
Modifies the experience of this Unit at its current
experienceType. |
void |
moveToFront(Unit u)
Move the given unit to the front of this carrier (make sure it'll be the first unit in this unit's unit list). |
protected void |
readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
Initialize this object from an XML-representation of this object. |
protected void |
readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
Partial reader for units, so that "remove" messages can be brief. |
boolean |
remove(Locatable locatable)
Removes a Locatable from this Unit. |
PathNode |
search(Tile start,
GoalDecider gd,
CostDecider cd,
int maxTurns,
Unit carrier)
Convenience wrapper for the Map.search(net.sf.freecol.common.model.Unit, net.sf.freecol.common.model.Tile, net.sf.freecol.common.model.pathfinding.GoalDecider, net.sf.freecol.common.model.pathfinding.CostDecider, int, net.sf.freecol.common.model.Unit) function. |
void |
setAttrition(int attrition)
Sets the attrition of this unit. |
void |
setCurrentStop(int currentStop)
Set the current stop. |
void |
setDestination(Location newDestination)
Sets the destination of this unit. |
void |
setEntryLocation(Location entryLocation)
Sets the entry location in which this unit will be put when returning from Europe. |
void |
setEquipment(TypeCountMap<EquipmentType> newEquipment)
Set the Equipment value. |
void |
setEthnicity(java.lang.String newEthnicity)
Sets the ethnicity of this Unit. |
void |
setExperience(int experience)
Sets the experience of this Unit at its current
experienceType. |
void |
setHitpoints(int hitpoints)
Sets the hitpoints for this unit. |
void |
setIndianSettlement(IndianSettlement indianSettlement)
Sets the IndianSettlement that owns this unit. |
void |
setLocation(Location newLocation)
Sets the location of this Unit. |
void |
setLocationNoUpdate(Location newLocation)
Sets the units location without updating any other variables |
void |
setMovesLeft(int movesLeft)
Sets the movesLeft. |
void |
setName(java.lang.String newName)
Set the Name value. |
void |
setNationality(java.lang.String newNationality)
Sets the nationality of this Unit. |
void |
setOwner(Player owner)
Sets the owner of this Unit. |
protected void |
setRole()
Determine role based on equipment. |
void |
setState(Unit.UnitState s)
Sets a new state for this unit and initializes the amount of work the unit has left. |
void |
setStateToAllChildren(Unit.UnitState state)
Sets the given state to all the units that si beeing carried. |
protected void |
setStateUnchecked(Unit.UnitState s)
|
void |
setStudent(Unit newStudent)
Set the Student value. |
void |
setTeacher(Unit newTeacher)
Set the Teacher value. |
void |
setTradeRoute(TradeRoute newTradeRoute)
Set the TradeRoute value. |
void |
setTreasureAmount(int amt)
The current amount of treasure in this unit. |
void |
setTurnsOfTraining(int turnsOfTraining)
Sets the number of turns this unit has been training. |
void |
setType(UnitType newUnitType)
Sets the type of the unit. |
void |
setWorkImprovement(TileImprovement imp)
Sets the TileImprovement that this pioneer is contributing to. |
void |
setWorkLeft(int workLeft)
Sets the amount of work left. |
void |
setWorkType(GoodsType type)
Sets the type of goods this unit is producing in its current occupation. |
private void |
spendAllMoves()
Set movesLeft to 0 if has some spent moves and it's in a colony |
java.lang.String |
toString()
Returns a String representation of this Unit. |
protected void |
toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
This method writes an XML-representation of this object to the given stream. |
protected void |
toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out,
java.lang.String[] fields)
Partial writer for units, so that "remove" messages can be brief. |
private void |
unitsToXML(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
|
int |
validateCurrentStop()
Validate and return the current stop. |
| Methods inherited from class net.sf.freecol.common.model.FreeColGameObject |
|---|
equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject |
| Methods inherited from class 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
public static final java.lang.String CARGO_CHANGE
public static final java.lang.String EQUIPMENT_CHANGE
protected UnitType unitType
protected int movesLeft
protected Unit.UnitState state
protected Unit.Role role
protected int workLeft
protected int hitpoints
protected Player owner
protected java.lang.String nationality
protected java.lang.String ethnicity
protected java.util.List<Unit> units
protected GoodsContainer goodsContainer
protected Location entryLocation
protected Location location
protected IndianSettlement indianSettlement
protected Location destination
protected TradeRoute tradeRoute
protected int currentStop
protected int treasureAmount
protected TileImprovement workImprovement
protected GoodsType workType
private GoodsType experienceType
protected int experience
protected int turnsOfTraining
protected int attrition
protected java.lang.String name
protected int visibleGoodsCount
getVisibleGoodsCount()protected Unit student
protected Unit teacher
protected TypeCountMap<EquipmentType> equipment
| Constructor Detail |
|---|
protected Unit()
protected Unit(Game game)
game - The Game in which this unit belongs.
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 canCarryUnit(Unit u)
The - potential cargo Unit.
public boolean canCarryGoods()
true if the Unit can carry Goods.
boolean valuepublic StringTemplate getLocationName()
getLocationName in interface Locationpublic StringTemplate getLocationNameFor(Player player)
getLocationNameFor in interface Locationplayer - The Player to prepare the name for.
public final UnitType getType()
UnitType value.
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 void clearEquipment()
Equipment held by this unit.
public final TradeRoute getTradeRoute()
TradeRoute value.
TradeRoute valuepublic final void setTradeRoute(TradeRoute newTradeRoute)
TradeRoute value.
newTradeRoute - The new TradeRoute value.public TradeRoute.Stop getStop()
public int getCurrentStop()
public void setCurrentStop(int currentStop)
currentStop - A new value for the currentStop.public int validateCurrentStop()
public 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 isTradingUnit()
Unit, meaning that it
can trade with settlements.
public boolean isColonist()
Unit is a `colonist'. A unit is a
colonist if it is European and can build a new Colony.
public boolean isOffensiveUnit()
true if this is an offensive unit.public int getNeededTurnsOfTraining()
getTurnsOfTraining()
public 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
experienceType.
Unit at its current
experienceType.modifyExperience(int)public void setExperience(int experience)
Unit at its current
experienceType.
experience - The new experience of this Unit
at its current experienceType.modifyExperience(int)public void modifyExperience(int value)
Unit at its current
experienceType.
value - The value by which to modify the experience of this
Unit.getExperience()public int getAttrition()
public void setAttrition(int attrition)
attrition - The new attrition of this unit.public boolean hasAbility(java.lang.String id)
id.
hasAbility in interface ConsumerhasAbility in class FreeColObjectid - a String value
boolean valuepublic java.util.Set<Modifier> getModifierSet(java.lang.String id)
getModifierSet in interface Consumerid - a String value
Modifier value
public java.util.Set<Modifier> getModifierSet(java.lang.String id,
Ownable ownable)
id - a String valueownable - a Ownable 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 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.
TODO: migrate usage of this to getWorkBuilding(), then delete this and rename the method below
public Location getWorkLocation2()
Location this unit is working in.
public Building getWorkBuilding()
Building this unit is working in.
public ColonyTile getWorkTile()
ColonyTile this unit is working in.
public GoodsType getExperienceType()
public GoodsType getWorkType()
public void setWorkType(GoodsType type)
type - The type of goods to attempt to produce.public TileImprovement getWorkImprovement()
TileImprovement the pioneer is working on.public void setWorkImprovement(TileImprovement imp)
imp - The new TileImprovement the pioneer is to
work on.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.
The 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.
java.lang.IllegalArgumentException - if end == null
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.
public PathNode findPath(Tile start,
Tile end,
Unit carrier)
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.carrier - An optional Unit to carry the unit.
PathNode for the first tile in the path.
public PathNode findPath(Tile start,
Tile end,
Unit carrier,
CostDecider costDecider)
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 from.end - The Tile at the end of the path.carrier - An optional Unit to carry the unit.costDecider - An optional CostDecider for
determining the movement costs (uses default cost deciders
for the unit/s if not provided).
PathNode for the first tile in the path.public PathNode findPathToEurope()
public PathNode findPathToEurope(Tile start)
start - The Tile to start from.
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 INFINITY 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.
INFINITY if no path can be found.
public PathNode search(Tile start,
GoalDecider gd,
CostDecider cd,
int maxTurns,
Unit carrier)
Map.search(net.sf.freecol.common.model.Unit, net.sf.freecol.common.model.Tile, net.sf.freecol.common.model.pathfinding.GoalDecider, net.sf.freecol.common.model.pathfinding.CostDecider, int, net.sf.freecol.common.model.Unit) function.
startTile - The Tile to start the search from.gd - The object responsible for determining whether a
given PathNode is a goal or not.costDecider - An optional CostDecider
responsible for determining the path cost.maxTurns - The maximum number of turns the given
Unit is allowed to move.carrier - The carrier the unit is currently
onboard or null if the unit is
either not onboard a carrier or should not use the
carrier while finding the path.
GoalDecider.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.
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.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 getSimpleMoveType(Tile from,
Tile target)
from - The origin Tile of the move.target - The target Tile of the move.
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)
from - The origin Tile of the move.target - The target Tile of the move.
- Returns:
- The move type.
private Unit.MoveType getLandMoveType(Tile from,
Tile target)
from - The origin Tile of the move.target - The target Tile of the move.
private Unit.MoveType getTradeMoveType(Settlement settlement)
MoveType when moving a trading unit to a
settlement.
settlement - The Settlement to move to.
MoveType.
private Unit.MoveType getLearnMoveType(Tile from,
Settlement settlement)
MoveType when moving a colonist to a settlement.
from - The Tile to move from.settlement - The Settlement to move to.
MoveType.
private Unit.MoveType getMissionaryMoveType(Tile from,
Settlement settlement)
MoveType when moving a missionary to a settlement.
from - The Tile to move from.settlement - The Settlement to move to.
MoveType.
private Unit.MoveType getScoutMoveType(Tile from,
Settlement settlement)
MoveType when moving a scout to a settlement.
from - The Tile to move from.settlement - The Settlement to move to.
MoveType.private boolean allowMoveFrom(Tile from)
from - The Tile to consider.
private boolean allowContact(Settlement settlement)
settlement - The Settlement to consider.
public int getMovesLeft()
getMovesLeft in interface Movablepublic 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 boolean isOnCarrier()
public void setStateToAllChildren(Unit.UnitState state)
state - The state.private void spendAllMoves()
add(Locatable),
remove(Locatable)public boolean couldMove()
public Location getRepairLocation()
Location to this tile where
this ship can be repaired.
Location where a ship can be repaired.public boolean add(Locatable locatable)
Unit.
add in interface Locationlocatable - The Locatable to add to this
Unit.public boolean 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()
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 setLocationNoUpdate(Location newLocation)
newLocation - The new Locationpublic void setLocation(Location newLocation)
setLocation in interface LocatablenewLocation - The new Location.public 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 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 java.util.List<EquipmentType> changeEquipment(EquipmentType type,
int amount)
type - The EquipmentType to change.amount - The amount to change by (may be negative).
public int getEquipmentCount(EquipmentType equipmentType)
getEquipmentCount method here.
equipmentType - an EquipmentType value
int valuepublic boolean isInEurope()
Unit is located in Europe. That is; either
directly or onboard a carrier which is in Europe.
public boolean isAtSea()
Unit is at sea off the map, or
on board of a carrier that is.
public boolean isCarrier()
Unit is able to carry Locatables.
public boolean isPerson()
public Player getOwner()
getOwner in interface Ownablepublic StringTemplate getApparentOwnerName()
public void setOwner(Player owner)
setOwner in interface Ownableowner - The new owner of this Unit.public java.lang.String getNationality()
public void setNationality(java.lang.String newNationality)
newNationality - The new nationality of this Unit.public java.lang.String getEthnicity()
public void setEthnicity(java.lang.String newEthnicity)
newEthnicity - The new ethnicity of this Unit.public boolean hasNativeEthnicity()
public void setType(UnitType newUnitType)
newUnitType - The new type of the unit.public boolean isArmed()
public boolean isMounted()
public java.lang.String getName()
getName method here.
getName in interface NameableString valuepublic void setName(java.lang.String newName)
Name value.
setName in interface NameablenewName - The new Name value.public StringTemplate getLabel()
getLabel method here.
StringTemplate valuepublic StringTemplate getEquipmentLabel()
String valuepublic int getInitialMovesLeft()
getInitialMovesLeft in interface Movablepublic 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 boolean isInMission()
public java.lang.String toString()
toString in class FreeColGameObjectpublic java.lang.String getMovesAsString()
public boolean isNaval()
Unit is naval.
public Unit.UnitState getState()
Unit.
Unit.public Unit.Role getRole()
Role of this Unit.
role of this Unit.protected 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 int getSailTurns()
public void setState(Unit.UnitState s)
s - The new state for this Unit. Should be one of {UnitState.ACTIVE,
UnitState.FORTIFIED, ...}.protected void setStateUnchecked(Unit.UnitState s)
public boolean canMoveToEurope()
Unit can be moved to Europe.
TODO: the new Carribean map has no south pole, and this allows
moving to Europe via the bottom edge of the map, which is
approximately the equator line. Should we enforce moving to
Europe requires high seas, and no movement via north/south
poles?
mpope 201103: Just leave it up to the map itself, tiles can
include a "moveToEurope" attribute to override the default
behaviour, which is to allow movement to Europe from tiles with
the moveToEurope ability or on the map borders.
Now, IMHO on the Carribean map, settling on the land next to
the south border gives an unfair advantage and we *should* set
moveToEurope==false on the nearby sea tiles.
true if this unit can move to Europe.public boolean canBuildColony()
true if this unit can build a colony.Player.canClaimToFoundSettlement(Tile)public 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 setWorkLeft(int workLeft)
workLeft - The new amount of work left.public int getWorkTurnsLeft()
public void setEntryLocation(Location entryLocation)
Europe.
entryLocation - The entry location.getEntryLocation()public Location getEntryLocation()
Europe.
public Tile getFullEntryLocation()
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 static boolean betterDefender(Unit defender,
float defenderPower,
Unit other,
float otherPower)
defender - The current defender Unit.defenderPower - Its defence power.other - An alternate Unit.otherPower - Its defence power.
public boolean isUndead()
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 EquipmentType canCaptureEquipment(EquipmentType equip,
Unit loser)
equip - The EquipmentType to consider.loser - The loser Unit.
EquipmentType to capture, which may
differ from the equip parameter due to transformations such
as to the native versions of horses and muskets.
Or return null if capture is not possible.public Settlement getSettlement()
getSettlement in interface Locationpublic Colony getColony()
getColony in interface Location
public int getProductionOf(GoodsType goodsType,
int base)
goodsType - The type of goods to be produced.base - an int value
public java.util.List<FreeColGameObject> disposeList()
disposeList in class FreeColGameObjectpublic void dispose()
dispose in class FreeColGameObjectpublic int getTurnsForRepair()
public TypeCountMap<EquipmentType> getAutomaticEquipment()
public boolean losingEquipmentKillsUnit(EquipmentType lose)
lose - The EquipmentType to lose.
public boolean losingEquipmentDemotesUnit(EquipmentType lose)
lose - The EquipmentType to lose.
public float getConvertProbability()
public float getBurnProbability()
public UnitType getTypeChange(UnitTypeChange.ChangeType change,
Player owner)
change - The ChangeType to consider.owner - The Player to own this unit after a
change of type CAPTURE or UNDEAD.
public EquipmentType getBestCombatEquipmentType(TypeCountMap<EquipmentType> equipment)
equipment - The equipment to look through, such as returned by
and/or @see Unit#getAutomaticEquipment().public java.util.List<AbstractGoods> getConsumedGoods()
getConsumedGoods in interface ConsumerList valuepublic ProductionInfo getProductionInfo(java.util.List<AbstractGoods> input)
getProductionInfo method here.
ProductionInfo valuepublic int getPriority()
getPriority in interface Consumerint value
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()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||