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

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.BuildColonyMission

public class BuildColonyMission
extends Mission

Mission for building a Colony. This mission can be used in two different ways:

This mission will be aborted in the former case if the value gets below a given threshold, while a colony will always get built (if there is sufficient space on the map) in the latter case. Use the appropriate constructor to get the desired behaviour.

See Also:
Colony

Field Summary
private  boolean colonyBuilt
           
private  int colonyValue
          The value of the target Tile.
private  boolean doNotGiveUp
          The mission will look for a new colony site, instead of aborting this mission, if the colony value drop below the given level if this variable is set to true.
private static java.util.logging.Logger logger
           
private  Tile target
          The Tile where the Colony should be built.
 
Fields inherited from class net.sf.freecol.server.ai.mission.Mission
MINIMUM_TRANSPORT_PRIORITY, NO_MORE_MOVES_LEFT, NO_PATH_TO_TARGET, 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
BuildColonyMission(AIMain aiMain, AIUnit aiUnit)
          Creates a BuildColonyMission for the given AIUnit.
BuildColonyMission(AIMain aiMain, AIUnit aiUnit, Tile target, int colonyValue)
          Creates a mission for the given AIUnit.
BuildColonyMission(AIMain aiMain, org.w3c.dom.Element element)
          Creates a new BuildColonyMission.
BuildColonyMission(AIMain aiMain, javax.xml.stream.XMLStreamReader in)
          Creates a new BuildColonyMission and reads the given element.
 
Method Summary
 void doMission(Connection connection)
          Performs this mission.
static Tile findColonyLocation(Unit unit)
          Finds a site for a new colony.
 java.lang.String getDebuggingInfo()
          Gets debugging information about this mission.
 Tile getTransportDestination()
          Returns the destination for this Transportable.
 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 isValid()
          Checks if this mission is still valid to perform.
protected  void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads all the AIObjects and other AI-related information from XML data.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          Writes all of the AIObjects and other AI-related information to an XML-stream.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          Write the attributes of this object to a stream.
 
Methods inherited from class net.sf.freecol.server.ai.mission.Mission
buyGoods, dispose, findNearestColony, findTarget, getAIUnit, getUnit, isOneTime, isValid, moveButDontAttack, moveRandomly, moveTowards, moveTowards, moveUnitToAmerica, moveUnitToEurope, sellCargoInEurope, setAIUnit, unitLeavesShip, unloadCargoInColony
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
getAIMain, getAIRandom, getGame, isUninitialized, readFromXML
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeChildren
 
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

target

private Tile target
The Tile where the Colony should be built.


colonyValue

private int colonyValue
The value of the target Tile.


doNotGiveUp

private boolean doNotGiveUp
The mission will look for a new colony site, instead of aborting this mission, if the colony value drop below the given level if this variable is set to true.


colonyBuilt

private boolean colonyBuilt
Constructor Detail

BuildColonyMission

public BuildColonyMission(AIMain aiMain,
                          AIUnit aiUnit,
                          Tile target,
                          int colonyValue)
Creates a mission for the given AIUnit.

Parameters:
aiMain - The main AI-object.
aiUnit - The AIUnit this mission is created for.
target - The Tile where the Colony should be built.
colonyValue - The value of the Tile to build a Colony upon. This mission will be invalidated if target.getColonyValue() is less than this value.

BuildColonyMission

public BuildColonyMission(AIMain aiMain,
                          AIUnit aiUnit)
Creates a BuildColonyMission for the given AIUnit. The mission will try to find the closest and best site for a colony, and build the colony there. It will not stop until a Colony gets built.

Parameters:
aiMain - The main AI-object.
aiUnit - The AIUnit this mission is created for.

BuildColonyMission

public BuildColonyMission(AIMain aiMain,
                          org.w3c.dom.Element element)
Creates a new BuildColonyMission.

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

BuildColonyMission

public BuildColonyMission(AIMain aiMain,
                          javax.xml.stream.XMLStreamReader in)
                   throws javax.xml.stream.XMLStreamException
Creates a new BuildColonyMission 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

doMission

public void doMission(Connection connection)
Performs this mission.

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

getTransportDestination

public Tile getTransportDestination()
Returns the destination for this Transportable. This can either be the target Tile of the transport or the target for the entire Transportable's mission. The target for the transport is determined by TransportMission in the latter case.

Overrides:
getTransportDestination in class Mission
Returns:
The destination for this Transportable.

getTransportPriority

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

Overrides:
getTransportPriority in class Mission
Returns:
The priority.

findColonyLocation

public static Tile findColonyLocation(Unit unit)
Finds a site for a new colony. Favour closer sites.

Parameters:
unit - The Unit to find a colony site for.
Returns:
A suitable tile for a new colony.

isValid

public boolean isValid()
Checks if this mission is still valid to perform. This mission will be invalidated when the colony has been built or if the target.getColonyValue() decreases.

Overrides:
isValid in class Mission
Returns:
True if this mission is still valid to perform.

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.

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
Writes all of the AIObjects and other AI-related information to an XML-stream.

Specified by:
toXMLImpl in class FreeColObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                        throws javax.xml.stream.XMLStreamException
Description copied from class: FreeColObject
Write the attributes of this object to a stream. To be overridden by any object that uses the toXML(XMLStreamWriter, String) call.

Overrides:
writeAttributes in class Mission
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readAttributes

protected void readAttributes(javax.xml.stream.XMLStreamReader in)
                       throws javax.xml.stream.XMLStreamException
Reads all the AIObjects and other AI-related information from XML data.

Overrides:
readAttributes in class Mission
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getXMLElementTagName

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

Returns:
"buildColonyMission".