net.sf.freecol.server.ai.mission
Class Mission

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.server.ai.AIObject
          extended by net.sf.freecol.server.ai.mission.Mission
Direct Known Subclasses:
BuildColonyMission, CashInTreasureTrainMission, DefendSettlementMission, IdleAtColonyMission, IndianBringGiftMission, IndianDemandMission, PioneeringMission, PrivateerMission, ScoutingMission, TransportMission, UnitSeekAndDestroyMission, UnitWanderHostileMission, UnitWanderMission, WishRealizationMission, WorkInsideColonyMission

public abstract class Mission
extends AIObject

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, PARTIAL_ATTRIBUTE
 
Constructor Summary
Mission(AIMain aiMain)
          Creates a mission.
Mission(AIMain aiMain, AIUnit aiUnit)
          Creates a mission for the given AIUnit.
 
Method Summary
 void attack(Connection connection, Unit unit, Map.Direction direction)
           
 boolean buyGoods(Connection connection, Unit carrier, GoodsType goodsType, int amount)
           
 void dispose()
          Disposes this mission by removing any references to it.
abstract  void doMission(Connection connection)
          Performs the mission.
protected  void exploreLostCityRumour(Connection connection)
          Makes the unit explore the lost city rumour located on it's current Tile (if any).
 PathNode findNearestColony(Unit unit)
           
protected  PathNode findTarget(int maxTurns)
          Finds the best target to attack within the given range.
 AIUnit getAIUnit()
          Gets the AI-unit this mission has been created for.
 java.lang.String getDebuggingInfo()
          Gets debugging information about this mission.
 Tile getTransportDestination()
          Returns the destination of a required transport.
 int getTransportPriority()
          Returns the priority of getting the unit to the transport destination.
 Unit getUnit()
          Gets the unit this mission has been created for.
 boolean isValid()
          Checks if this mission is still valid to perform.
protected  void move(Connection connection, Map.Direction direction)
          Moves the unit owning this mission in the given direction.
protected  void moveButDontAttack(Connection connection, Map.Direction direction)
           
protected  void moveRandomly(Connection connection)
           
protected  Map.Direction moveTowards(Connection connection, PathNode pathNode)
          Moves the unit owning this mission using the given pathNode.
protected  Map.Direction moveTowards(Connection connection, Tile tile)
          Moves the unit owning this mission towards the given Tile.
protected  void moveUnitToAmerica(Connection connection, Unit unit)
           
protected  void moveUnitToEurope(Connection connection, Unit unit)
           
protected  boolean sellCargoInEurope(Connection connection, Unit carrier, Goods goods)
           
protected  void setAIUnit(AIUnit aiUnit)
          Sets the AI-unit this mission has been created for.
protected  void unitLeavesShip(Connection connection, Unit u)
           
protected  boolean unloadCargoInColony(Connection connection, Unit carrier, Goods goods)
           
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
getAIMain, getAIRandom, getGame, getXMLElementTagName, isUninitialized, readFromXML
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readChildren, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, setId, toArrayElement, toArrayElement, toListElement, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLImpl, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

MINIMUM_TRANSPORT_PRIORITY

protected static final int MINIMUM_TRANSPORT_PRIORITY
See Also:
Constant Field Values

NORMAL_TRANSPORT_PRIORITY

protected static final int NORMAL_TRANSPORT_PRIORITY
See Also:
Constant Field Values

NO_PATH_TO_TARGET

protected static final int NO_PATH_TO_TARGET
See Also:
Constant Field Values

NO_MORE_MOVES_LEFT

protected static final int NO_MORE_MOVES_LEFT
See Also:
Constant Field Values

aiUnit

private AIUnit aiUnit
Constructor Detail

Mission

public Mission(AIMain aiMain)
Creates a mission.

Parameters:
aiMain - The main AI-object.

Mission

public Mission(AIMain aiMain,
               AIUnit aiUnit)
Creates a mission for the given AIUnit.

Parameters:
aiMain - The main AI-object.
aiUnit - The AIUnit this mission is created for.
Throws:
java.lang.NullPointerException - if aiUnit == null.
Method Detail

moveTowards

protected Map.Direction moveTowards(Connection connection,
                                    Tile tile)
Moves the unit owning this mission towards the given 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.

Parameters:
connection - The Connection to use when communicating with the server.
tile - The Tile the unit should move towards.
Returns:
The direction to take the final move (greater than or equal to zero), or NO_MORE_MOVES_LEFT if there are no more moves left and NO_PATH_TO_TARGET if there is no path to follow. If a direction is returned, it is guaranteed that moving in that direction is not an illegal move, but a direction also gets returned if the resulting move would be an Unit.MoveType.ATTACK etc. A direction can also be returned during the path, if the path has been blocked.

moveTowards

protected Map.Direction moveTowards(Connection connection,
                                    PathNode pathNode)
Moves the unit owning this mission using the given pathNode. This is done in a loop until the end of the path is reached, the next step is not a move or when there are no moves left.

Parameters:
connection - The Connection to use when communicating with the server.
pathNode - The first node of the path.
Returns:
The direction to continue moving the path (greater than or equal to zero), or NO_MORE_MOVES_LEFT if there are no more moves left. If a direction is returned, it is guaranteed that moving in that direction is not an illegal move. A directions gets returned when moving in the given direction would not be a Unit.MoveType.MOVE or Unit.MoveType.MOVE_HIGH_SEAS.

moveRandomly

protected void moveRandomly(Connection connection)

move

protected void move(Connection connection,
                    Map.Direction direction)
Moves the unit owning this mission in the given direction.

Parameters:
connection - The Connection to use when communicating with the server.
direction - The direction to move the unit.

moveUnitToAmerica

protected void moveUnitToAmerica(Connection connection,
                                 Unit unit)

moveUnitToEurope

protected void moveUnitToEurope(Connection connection,
                                Unit unit)

moveButDontAttack

protected void moveButDontAttack(Connection connection,
                                 Map.Direction direction)

exploreLostCityRumour

protected void exploreLostCityRumour(Connection connection)
Makes the unit explore the lost city rumour located on it's current Tile (if any).

Parameters:
connection - The Connection to make the request on.

findTarget

protected PathNode findTarget(int maxTurns)
Finds the best target to attack within the given range.

Parameters:
maxTurns - The maximum number of turns the unit is allowed to spend in order to reach the target.
Returns:
The path to the target or null if no target can be found.

getTransportDestination

public Tile getTransportDestination()
Returns the destination of a required transport.

Returns:
The destination of a required transport or null if no transport is needed.

getTransportPriority

public int getTransportPriority()
Returns the priority of getting the unit to the transport destination.

Returns:
The priority.

unloadCargoInColony

protected boolean unloadCargoInColony(Connection connection,
                                      Unit carrier,
                                      Goods goods)

sellCargoInEurope

protected boolean sellCargoInEurope(Connection connection,
                                    Unit carrier,
                                    Goods goods)

dispose

public void dispose()
Disposes this mission by removing any references to it.

Overrides:
dispose in class AIObject

doMission

public abstract void doMission(Connection connection)
Performs the mission. This method should be implemented by a subclass.

Parameters:
connection - The Connection to the server.

isValid

public boolean isValid()
Checks if this mission is still valid to perform.

A mission can be invalidated for a number of reasons. For example: a seek-and-destroy mission can be invalidated in case the relationship towards the targeted player improves.

Returns:
The default value: true.

getUnit

public Unit getUnit()
Gets the unit this mission has been created for.

Returns:
The Unit.

getAIUnit

public AIUnit getAIUnit()
Gets the AI-unit this mission has been created for.

Returns:
The AIUnit.

setAIUnit

protected void setAIUnit(AIUnit aiUnit)
Sets the AI-unit this mission has been created for.

Parameters:
aiUnit - The AIUnit.

getDebuggingInfo

public java.lang.String getDebuggingInfo()
Gets debugging information about this mission. This string is a short representation of this object's state.

Returns:
An empty String. Should be replaced by subclasses.

attack

public void attack(Connection connection,
                   Unit unit,
                   Map.Direction direction)

unitLeavesShip

protected void unitLeavesShip(Connection connection,
                              Unit u)

buyGoods

public boolean buyGoods(Connection connection,
                        Unit carrier,
                        GoodsType goodsType,
                        int amount)

findNearestColony

public PathNode findNearestColony(Unit unit)