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

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
              extended by net.sf.freecol.server.ai.mission.TransportMission

public class TransportMission
extends Mission

Mission for transporting units and goods on a carrier.

See Also:
Unit

Field Summary
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
TransportMission(AIMain aiMain, AIUnit aiUnit)
          Creates a mission for the given AIUnit.
TransportMission(AIMain aiMain, org.w3c.dom.Element element)
          Loads a TransportMission from the given element.
TransportMission(AIMain aiMain, javax.xml.stream.XMLStreamReader in)
          Creates a new TransportMission and reads the given element.
 
Method Summary
 void addToTransportList(Transportable newTransportable)
          Adds the given Transportable to the transport list.
 AIGoods buyGoodsInEurope(Connection connection, GoodsType type, int amount, Location destination)
          Buys the given cargo.
 void dispose()
          Disposes this Mission.
 void doMission(Connection connection)
          Performs the mission.
 int getAvailableSpace()
          Returns the available space for any type of unit going to any type of location.
 int getAvailableSpace(Transportable t)
          Returns the available space for the given Transportable.
 int getAvailableSpace(UnitType unitType, Location source, Location destination)
          Returns the available space for the given type of Unit at the given Location.
 java.lang.String getDebuggingInfo()
          Gets debugging information about this mission.
 PathNode getPath(Transportable transportable)
          Returns the path the carrier should use to get/drop the given Transportable.
static int getPlayerNavalTransportMissionCount(AIPlayer aiPlayer, Unit unitExcluded)
          Gives the number of naval units assigned with a Transport Mission
 Tile getTransportDestination()
          Returns the destination of a required transport.
 int getTransportPriority()
          Returns the priority of getting the unit to the transport destination.
static java.lang.String getXMLElementTagName()
          Returns the tag name of the root element representing this object.
 boolean isOnTransportList(Transportable newTransportable)
          Checks if the given Transportable is on the transport list.
 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.
 void removeFromTransportList(Transportable transportable)
          Removes the given Transportable from the transport list.
 java.lang.String toString()
          Creates a String representation of this mission to be used for debugging purposes.
 
Methods inherited from class net.sf.freecol.server.ai.mission.Mission
attack, buyGoods, findNearestColony, getAIUnit, getUnit
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
getAIMain, getGame, 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, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransportMission

public TransportMission(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.

TransportMission

public TransportMission(AIMain aiMain,
                        org.w3c.dom.Element element)
Loads a TransportMission from the given element.

Parameters:
aiMain - The main AI-object.
element - An Element containing an XML-representation of this object.

TransportMission

public TransportMission(AIMain aiMain,
                        javax.xml.stream.XMLStreamReader in)
                 throws javax.xml.stream.XMLStreamException
Creates a new TransportMission and reads the given element.

Parameters:
aiMain - The main AI-object.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
See Also:
AIObject.readFromXML(javax.xml.stream.XMLStreamReader)
Method Detail

dispose

public void dispose()
Disposes this Mission.

Overrides:
dispose in class Mission

isOnTransportList

public boolean isOnTransportList(Transportable newTransportable)
Checks if the given Transportable is on the transport list.

Parameters:
newTransportable - The Transportable to be checked
Returns:
true if the given Transportable was on the transport list, and false otherwise.

removeFromTransportList

public void removeFromTransportList(Transportable transportable)
Removes the given Transportable from the transport list. This method calls Transportable.setTransport(AIUnit).

Parameters:
transportable - The Transportable.

addToTransportList

public void addToTransportList(Transportable newTransportable)
Adds the given Transportable to the transport list. The method returns immediately if the Transportable has already be added.

Both the source and destination Location for the Transportable is entered into the transport list if the Transportable is not already loaded onto the transport. If the Transportable is onboard the transport, then only the destination is put on the transport list.

Parameters:
newTransportable - The Transportable.

doMission

public void doMission(Connection connection)
Performs the mission.

Specified by:
doMission in class Mission
Parameters:
connection - The Connection to the server.

buyGoodsInEurope

public AIGoods buyGoodsInEurope(Connection connection,
                                GoodsType type,
                                int amount,
                                Location destination)
Buys the given cargo.

Warning: This method can only be called when the carrier is located in Europe.

Parameters:
connection - The Connection to use when communicating with the server.
type - The type of goods to buy.
amount - The amount of goods to buy.
destination - The Location to which the goods should be transported.
Returns:
The goods.

getPath

public PathNode getPath(Transportable transportable)
Returns the path the carrier should use to get/drop the given Transportable.

Parameters:
transportable - The Transportable.
Returns:
The path.

getAvailableSpace

public int getAvailableSpace(Transportable t)
Returns the available space for the given Transportable.

Parameters:
t - The Transportable
Returns:
The space available for Transportables with the same source and destination.

getAvailableSpace

public int getAvailableSpace(UnitType unitType,
                             Location source,
                             Location destination)
Returns the available space for the given type of Unit at the given Location.

Parameters:
unitType - The type of Unit or null for Goods
source - The source for the unit. This is where the unit is presently located.
destination - The destination for the unit.
Returns:
The space available

getAvailableSpace

public int getAvailableSpace()
Returns the available space for any type of unit going to any type of location.

Returns:
The space available

isValid

public static boolean isValid(AIUnit aiUnit)
Checks if this mission is valid for the given unit.

Parameters:
aiUnit - The unit.
Returns:
true if this mission is valid to perform and false otherwise.

isValid

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

Overrides:
isValid in class Mission
Returns:
true

getTransportDestination

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

Overrides:
getTransportDestination in class Mission
Returns:
null

getTransportPriority

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

Overrides:
getTransportPriority in class Mission
Returns:
o

getPlayerNavalTransportMissionCount

public static int getPlayerNavalTransportMissionCount(AIPlayer aiPlayer,
                                                      Unit unitExcluded)
Gives the number of naval units assigned with a Transport Mission


getXMLElementTagName

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

Returns:
The String "transportMission".

getDebuggingInfo

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

Overrides:
getDebuggingInfo in class Mission
Returns:
The String: "(x, y) z" or "(x, y) z!" where x and y is the coordinates of the target tile for this mission, and z is the value of building the colony. The exclamation mark is added if the unit should continue searching for a colony site if the targeted site is lost.

toString

public java.lang.String toString()
Creates a String representation of this mission to be used for debugging purposes.

Overrides:
toString in class java.lang.Object