net.sf.freecol.server.ai
Class TileImprovementPlan

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.ValuedAIObject
              extended by net.sf.freecol.server.ai.TileImprovementPlan
All Implemented Interfaces:
java.lang.Comparable<ValuedAIObject>

public class TileImprovementPlan
extends ValuedAIObject

Represents a Tile which should be improved in some way. For instance by plowing or by building a road.

See Also:
Tile

Field Summary
private static java.util.logging.Logger logger
           
private  AIUnit pioneer
          The pioneer which should make the improvement (if a Unit has been assigned).
private  Tile target
          The Tile to be improved.
private  TileImprovementType type
          The type of improvement, from TileImprovementTypes.
 
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
TileImprovementPlan(AIMain aiMain, org.w3c.dom.Element element)
          Creates a new TileImprovementPlan from the given XML-representation.
TileImprovementPlan(AIMain aiMain, java.lang.String id)
          Creates a new TileImprovementPlan from the given XML-representation.
TileImprovementPlan(AIMain aiMain, Tile target, TileImprovementType type, int value)
          Creates a new TileImprovementPlan.
TileImprovementPlan(AIMain aiMain, javax.xml.stream.XMLStreamReader in)
          Creates a new TileImprovementPlan from the given XML-representation.
 
Method Summary
 void dispose()
          Disposes this TileImprovementPlan.
static TileImprovementType getBestTileImprovementType(Tile tile, GoodsType goodsType)
          Gets the 'most effective' TileImprovementType allowed for a given tile and goods type.
 AIUnit getPioneer()
          Gets the pioneer who have been assigned to making the improvement described by this object.
 Tile getTarget()
          Gets the target of this TileImprovementPlan.
 TileImprovementType getType()
          Returns the TileImprovementType of this plan.
static java.lang.String getXMLElementTagName()
          Returns the tag name of the root element representing this object.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Reads information for this object from an XML stream.
 void setPioneer(AIUnit pioneer)
          Sets the pioneer who have been assigned to making the improvement described by this object.
 void setType(TileImprovementType type)
          Sets the type of this TileImprovementPlan.
 java.lang.String toString()
           
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          Writes this object to an XML stream.
 boolean update(GoodsType goodsType)
          Updates this tile improvement plan to the best available for its tile and the specified goods type.
 
Methods inherited from class net.sf.freecol.server.ai.ValuedAIObject
compareTo, getValue, setValue
 
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, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

type

private TileImprovementType type
The type of improvement, from TileImprovementTypes.


pioneer

private AIUnit pioneer
The pioneer which should make the improvement (if a Unit has been assigned).


target

private Tile target
The Tile to be improved.

Constructor Detail

TileImprovementPlan

public TileImprovementPlan(AIMain aiMain,
                           Tile target,
                           TileImprovementType type,
                           int value)
Creates a new TileImprovementPlan.

Parameters:
aiMain - The main AI-object.
target - The target Tile for the improvement.
type - The type of improvement.
value - The value identifying the importance of this TileImprovementPlan - a higher value signals a higher importance.

TileImprovementPlan

public TileImprovementPlan(AIMain aiMain,
                           org.w3c.dom.Element element)
Creates a new TileImprovementPlan from the given XML-representation.

Parameters:
aiMain - The main AI-object.
element - The root element for the XML-representation of a Wish.

TileImprovementPlan

public TileImprovementPlan(AIMain aiMain,
                           javax.xml.stream.XMLStreamReader in)
                    throws javax.xml.stream.XMLStreamException
Creates a new TileImprovementPlan from the given XML-representation.

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.

TileImprovementPlan

public TileImprovementPlan(AIMain aiMain,
                           java.lang.String id)
                    throws javax.xml.stream.XMLStreamException
Creates a new TileImprovementPlan from the given XML-representation.

Parameters:
aiMain - The main AI-object.
id - The ID.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
Method Detail

dispose

public void dispose()
Disposes this TileImprovementPlan. If a pioneer has been assigned to making this improvement, then this pioneer gets informed that the improvement is no longer wanted.

Overrides:
dispose in class AIObject

getPioneer

public AIUnit getPioneer()
Gets the pioneer who have been assigned to making the improvement described by this object.

Returns:
The pioneer which should make the improvement, if such a AIUnit has been assigned, and null if nobody has been assigned this mission.

setPioneer

public void setPioneer(AIUnit pioneer)
Sets the pioneer who have been assigned to making the improvement described by this object.

Parameters:
pioneer - The pioneer which should make the improvement, if such a Unit has been assigned, and null if nobody has been assigned this mission.

getType

public TileImprovementType getType()
Returns the TileImprovementType of this plan.

Returns:
The type of the improvement.

setType

public void setType(TileImprovementType type)
Sets the type of this TileImprovementPlan.

Parameters:
type - The TileImprovementType.
See Also:
getType()

getTarget

public Tile getTarget()
Gets the target of this TileImprovementPlan.

Returns:
The Tile where pioneer should make the given improvement.

getBestTileImprovementType

public static TileImprovementType getBestTileImprovementType(Tile tile,
                                                             GoodsType goodsType)
Gets the 'most effective' TileImprovementType allowed for a given tile and goods type. Useful for AI in deciding the Improvements to prioritize.

Parameters:
tile - The Tile that will be improved.
goodsType - The GoodsType to be prioritized.
Returns:
The best TileImprovementType available to be done.

update

public boolean update(GoodsType goodsType)
Updates this tile improvement plan to the best available for its tile and the specified goods type.

Parameters:
goodsType - The GoodsType to be prioritized.
Returns:
True if the plan is still viable.

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
Writes this object 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.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Reads information for this object from an XML stream.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems reading from the stream.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getXMLElementTagName

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

Returns:
"tileImprovementPlan"