|
|||||||||
| 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.server.ai.AIObject
net.sf.freecol.server.ai.mission.Mission
public abstract class Mission
A mission describes what a unit should do; attack, build colony,
wander etc. Every AIUnit should have a mission. By
extending this class, you create different missions.
| Field Summary | |
|---|---|
private AIUnit |
aiUnit
|
private static java.util.logging.Logger |
logger
|
protected static int |
MINIMUM_TRANSPORT_PRIORITY
|
protected static int |
NO_MORE_MOVES_LEFT
|
protected static int |
NO_PATH_TO_TARGET
|
protected static int |
NORMAL_TRANSPORT_PRIORITY
|
| Fields inherited from class net.sf.freecol.server.ai.AIObject |
|---|
uninitialized |
| 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 |
| Constructor Summary | |
|---|---|
Mission(AIMain aiMain)
Creates a mission. |
|
Mission(AIMain aiMain,
AIUnit aiUnit)
Creates a mission for the given AIUnit. |
|
| Method Summary | |
|---|---|
void |
dispose()
Disposes this mission by removing any references to it. |
abstract void |
doMission(Connection connection)
Performs the mission. |
protected PathNode |
findNearestOtherSettlement(Unit unit)
Find the nearest reachable settlement to a unit (owned by the same player) excepting the any on the current tile. |
protected PathNode |
findTarget(int maxTurns)
Finds the best target to attack within the given range. |
protected java.util.Random |
getAIRandom()
Convenience accessor for the unit/player PRNG. |
AIUnit |
getAIUnit()
Gets the AI-unit this mission has been created for. |
java.lang.String |
getDebuggingInfo()
Gets debugging information about this mission. |
protected EuropeanAIPlayer |
getEuropeanAIPlayer()
Convenience accessor for the owning European AI player. |
protected static Tile |
getPathStartTile(Unit unit)
Gets a suitable tile to start path searches from for a unit. |
Location |
getTransportDestination()
Gets the transport destination of the unit associated with this mission. |
int |
getTransportPriority()
Gets the priority of getting the unit to the transport destination. |
Unit |
getUnit()
Gets the unit this mission has been created for. |
boolean |
isOneTime()
Checks if this Mission should only be carried out once. |
boolean |
isValid()
Checks if this mission is still valid to perform. |
static boolean |
isValid(AIUnit aiUnit)
Checks if this mission is valid for the given unit. |
protected boolean |
moveButDontAttack(Map.Direction direction)
Move in a specified direction, but do not attack. |
protected void |
moveRandomly()
Move a unit randomly. |
protected Map.Direction |
moveTowards(PathNode pathNode)
Moves the unit owning this mission using the given path. |
protected Map.Direction |
moveTowards(Tile tile)
Moves the unit owning this mission towards the given Tile. |
protected void |
moveUnitToAmerica()
|
protected void |
moveUnitToEurope()
|
protected void |
readAttributes(javax.xml.stream.XMLStreamReader in)
|
protected boolean |
sellCargoInEurope(Goods goods)
Sell some goods in Europe. |
protected void |
setAIUnit(AIUnit aiUnit)
Sets the AI-unit this mission has been created for. |
protected boolean |
shouldTakeTransportToTile(Tile tile)
Should the unit use transport to get to a specified tile? True if: - The unit is not there already AND - the unit already has transport, this will always be faster (TODO: actually, mounted units on good roads might be faster, check for this) - if not on the map - if on the map but can not find a path to the tile, unless adjacent to the destination which usually means the path finding failed due to a temporary blockage such as an enemy unit - if the path to the tile will take more than MAX_TURNS |
protected Unit.MoveType |
travelToTarget(java.lang.String logMe,
Location target)
Tries to move this mission's unit to a target location. |
protected boolean |
unitLeavesShip(AIUnit aiUnit)
Unload a unit. |
protected boolean |
unloadCargoInColony(Goods goods)
Unload some goods in a colony. |
protected void |
writeAttributes(javax.xml.stream.XMLStreamWriter out)
|
| Methods inherited from class net.sf.freecol.server.ai.AIObject |
|---|
getAIMain, getGame, getSpecification, getXMLElementTagName, isUninitialized, readFromXML |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
protected static final int MINIMUM_TRANSPORT_PRIORITY
protected static final int NORMAL_TRANSPORT_PRIORITY
protected static final int NO_PATH_TO_TARGET
protected static final int NO_MORE_MOVES_LEFT
private AIUnit aiUnit
| Constructor Detail |
|---|
public Mission(AIMain aiMain)
aiMain - The main AI-object.
public Mission(AIMain aiMain,
AIUnit aiUnit)
AIUnit.
aiMain - The main AI-object.aiUnit - The AIUnit this mission
is created for.
java.lang.NullPointerException - if aiUnit == null.| Method Detail |
|---|
public void dispose()
dispose in class AIObjectpublic Unit getUnit()
Unit.public AIUnit getAIUnit()
AIUnit.protected void setAIUnit(AIUnit aiUnit)
aiUnit - The AIUnit.protected java.util.Random getAIRandom()
Random to use.protected EuropeanAIPlayer getEuropeanAIPlayer()
EuropeanAIPlayer.protected Map.Direction moveTowards(Tile tile)
Tile. This is done in a loop until the tile is
reached, there are no moves left, the path to the target cannot
be found or that the next step is not a move.
tile - The Tile the unit should move towards.
protected Map.Direction moveTowards(PathNode pathNode)
pathNode - The first node of the path.
protected void moveRandomly()
protected void moveUnitToAmerica()
protected void moveUnitToEurope()
protected boolean moveButDontAttack(Map.Direction direction)
direction - The Direction to move.
protected PathNode findTarget(int maxTurns)
maxTurns - The maximum number of turns the unit is allowed
to spend in order to reach the target.
null if no target can
be found.protected PathNode findNearestOtherSettlement(Unit unit)
unit - The Unit to check.
protected boolean unitLeavesShip(AIUnit aiUnit)
aiUnit - The AIUnit to unload.
protected boolean unloadCargoInColony(Goods goods)
goods - The Goods to unload.
protected boolean sellCargoInEurope(Goods goods)
goods - The Goods to sell.
protected boolean shouldTakeTransportToTile(Tile tile)
tile - The Tile to go to.
protected static Tile getPathStartTile(Unit unit)
unit - The Unit to check.
protected Unit.MoveType travelToTarget(java.lang.String logMe,
Location target)
logMe - A prefix string for the log messages.target - The destination Location.
public Location getTransportDestination()
null if no transport is needed.public int getTransportPriority()
public static boolean isValid(AIUnit aiUnit)
aiUnit - The AIUnit to check.
public boolean isValid()
public boolean isOneTime()
public abstract void doMission(Connection connection)
connection - The Connection to the server.public java.lang.String getDebuggingInfo()
protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
throws javax.xml.stream.XMLStreamException
writeAttributes in class FreeColObjectout - The target stream.
javax.xml.stream.XMLStreamException - if there are any problems writing
to the stream.
protected void readAttributes(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readAttributes in class FreeColObjectin - The XML input stream.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||