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

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

public class PioneeringMission
extends Mission

Mission for controlling a pioneer.

See Also:
Unit.Role.PIONEER

Field Summary
private  Colony colonyWithTools
          A colony to go to to equip if required.
private static java.util.logging.Logger logger
           
private static int MAX_TURNS
          Maximum number of turns to travel to make progress on pioneering.
private  TileImprovementPlan tileImprovementPlan
          The improvement this pioneer is to work on.
 
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
PioneeringMission(AIMain aiMain, AIUnit aiUnit)
          Creates a pioneering mission for the given AIUnit.
PioneeringMission(AIMain aiMain, org.w3c.dom.Element element)
          Loads a mission from the given element.
PioneeringMission(AIMain aiMain, javax.xml.stream.XMLStreamReader in)
          Creates a new PioneeringMission and reads the given element.
 
Method Summary
private  void abandonTileImprovementPlan()
          Abandons the current plan if any.
private static boolean checkColonyForTools(AIUnit aiUnit, Colony colony)
          Checks if a colony can provide the tools required for a pioneer.
private  boolean checkTileImprovementPlan(TileImprovementPlan tip)
          Checks that a tile improvement plan is valid.
 void dispose()
          Disposes of this pioneering mission.
 void doMission(Connection connection)
          Performs this mission.
static Colony findColonyWithTools(AIUnit aiUnit)
          Finds the closest colony within MAX_TURNS that can equip the unit.
static TileImprovementPlan findTileImprovementPlan(AIUnit aiUnit)
          Finds the best tile improvement plan for a supplied AI unit.
 java.lang.String getDebuggingInfo()
          Gets debugging information about this mission.
 TileImprovementPlan getTileImprovementPlan()
          Gets the TileImprovementPlan for this mission.
 Location getTransportDestination()
          Gets the transport destination for units with this mission.
static java.lang.String getXMLElementTagName()
          Returns the tag name of the root element representing this object.
private  boolean hasTools()
          Does this pioneer have tools?
private static boolean hasTools(AIUnit aiUnit)
          Does a supplied unit have tools?
 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  void readAttributes(javax.xml.stream.XMLStreamReader in)
          
 void setTileImprovementPlan(TileImprovementPlan tip)
          Sets the TileImprovementPlan which should be the next target.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          Writes all of the AIObjects and other AI-related information to an XML-stream.
private static boolean validateTileImprovementPlan(TileImprovementPlan tip, EuropeanAIPlayer aiPlayer)
          Weeds out a broken or obsolete tile improvement plan.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          
 
Methods inherited from class net.sf.freecol.server.ai.mission.Mission
findNearestOtherSettlement, findTarget, getAIRandom, getAIUnit, getEuropeanAIPlayer, getPathStartTile, getTransportPriority, getUnit, isOneTime, moveButDontAttack, moveRandomly, moveTowards, moveTowards, moveUnitToAmerica, moveUnitToEurope, sellCargoInEurope, setAIUnit, shouldTakeTransportToTile, travelToTarget, unitLeavesShip, unloadCargoInColony
 
Methods inherited from class net.sf.freecol.server.ai.AIObject
getAIMain, getGame, getSpecification, 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, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, 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

MAX_TURNS

private static final int MAX_TURNS
Maximum number of turns to travel to make progress on pioneering. This is low-ish because it is usually more efficient to ship the tools where they are needed and either create a new pioneer on site or send a hardy pioneer on horseback. The AI is probably smart enough to do the former already, and one day the latter.

See Also:
Constant Field Values

tileImprovementPlan

private TileImprovementPlan tileImprovementPlan
The improvement this pioneer is to work on.


colonyWithTools

private Colony colonyWithTools
A colony to go to to equip if required.

Constructor Detail

PioneeringMission

public PioneeringMission(AIMain aiMain,
                         AIUnit aiUnit)
Creates a pioneering mission for the given AIUnit. Note that PioneeringMission.isValid(aiUnit) should be called before this, to guarantee that findTileImprovementPlan/findColonyWithTools succeed.

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

PioneeringMission

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

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

PioneeringMission

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

getTileImprovementPlan

public TileImprovementPlan getTileImprovementPlan()
Gets the TileImprovementPlan for this mission.

Returns:
The TileImprovementPlan.

setTileImprovementPlan

public void setTileImprovementPlan(TileImprovementPlan tip)
Sets the TileImprovementPlan which should be the next target.

Parameters:
tip - The TileImprovementPlan.

abandonTileImprovementPlan

private void abandonTileImprovementPlan()
Abandons the current plan if any.


dispose

public void dispose()
Disposes of this pioneering mission.

Overrides:
dispose in class Mission

hasTools

private static boolean hasTools(AIUnit aiUnit)
Does a supplied unit have tools?

Parameters:
unit - The pioneer Unit to check.
Returns:
True if the pioneer has tools.

hasTools

private boolean hasTools()
Does this pioneer have tools?

Returns:
True if the pioneer has tools.

checkColonyForTools

private static boolean checkColonyForTools(AIUnit aiUnit,
                                           Colony colony)
Checks if a colony can provide the tools required for a pioneer.

Parameters:
aiUnit - The AIUnit that needs tools.
colony - The Colony to check.
Returns:
True if the colony can provide tools.

findColonyWithTools

public static Colony findColonyWithTools(AIUnit aiUnit)
Finds the closest colony within MAX_TURNS that can equip the unit. Public for the test suite.

Parameters:
aiUnit - The AIUnit to equip.
Returns:
The closest colony that can equip the unit.

validateTileImprovementPlan

private static boolean validateTileImprovementPlan(TileImprovementPlan tip,
                                                   EuropeanAIPlayer aiPlayer)
Weeds out a broken or obsolete tile improvement plan.

Parameters:
tip - The TileImprovementPlan to test.
aiPlayer - The AIPlayer that owns the plan.
Returns:
True if the plan survives this check.

checkTileImprovementPlan

private boolean checkTileImprovementPlan(TileImprovementPlan tip)
Checks that a tile improvement plan is valid.

Parameters:
tip - The TileImprovementPlan to check.
Returns:
True if the plan is valid.

findTileImprovementPlan

public static TileImprovementPlan findTileImprovementPlan(AIUnit aiUnit)
Finds the best tile improvement plan for a supplied AI unit. Public for the test suite.

Parameters:
aiUnit - The AIUnit to find a plan for.
Returns:
The best available tile improvement plan, or null if none found.

getTransportDestination

public Location getTransportDestination()
Gets the transport destination for units with this mission.

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

isValid

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

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

isValid

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

Parameters:
aiUnit - The AIUnit to check.
Returns:
True if the AI unit can be assigned a PioneeringMission.

doMission

public void doMission(Connection connection)
Performs this mission. - Gets tools if needed. - Makes sure we have a valid plan. - Get to the target. - Claim it if necessary. - Make the improvement.

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

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) P" (for plowing)
  • "(x, y) R" (for building road)
  • "(x, y) Getting tools: (x, y)"

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

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

Overrides:
readAttributes in class Mission
Parameters:
in - The XML input stream.
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:
"pioneeringMission".