Package net.sf.freecol.server.ai
Class TileImprovementPlan
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.server.ai.AIObject
-
- net.sf.freecol.server.ai.ValuedAIObject
-
- net.sf.freecol.server.ai.TileImprovementPlan
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public class TileImprovementPlan extends ValuedAIObject
Represents a plan to improve aTile
in some way. For instance by plowing or by building a road.- See Also:
Tile
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Logger
logger
private AIUnit
pioneer
The pioneer which should make the improvement (if aUnit
has been assigned).private static java.lang.String
PIONEER_TAG
static java.lang.String
TAG
private Tile
target
TheTile
to be improved.private static java.lang.String
TARGET_TAG
private TileImprovementType
type
The type of improvement, from TileImprovementTypes.private static java.lang.String
TYPE_TAG
-
Fields inherited from class net.sf.freecol.server.ai.ValuedAIObject
ascendingValueComparator, descendingValueComparator
-
Fields inherited from class net.sf.freecol.server.ai.AIObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description TileImprovementPlan(AIMain aiMain, java.lang.String id)
Creates a new uninitializedTileImprovementPlan
.TileImprovementPlan(AIMain aiMain, FreeColXMLReader xr)
Creates a newTileImprovementPlan
from the given XML-representation.TileImprovementPlan(AIMain aiMain, Tile target, TileImprovementType type, int value)
Creates a newTileImprovementPlan
and initializes its critical fields.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
AIObjects need integrity checking too.void
dispose()
Disposes thisTileImprovementPlan
.boolean
equals(java.lang.Object o)
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 thisTileImprovementPlan
.TileImprovementType
getType()
Gets theTileImprovementType
of this plan.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
hashCode()
boolean
isComplete()
Is this improvement complete?protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setInitialized()
Set the initialized flag in this object.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 thisTileImprovementPlan
.java.lang.String
toString()
void
toXML(FreeColXMLWriter xw)
This method writes an XML-representation of this object to the given stream.boolean
update(GoodsType goodsType)
Updates this tile improvement plan to the best available for its tile and the specified goods type.boolean
validate()
Weeds out a broken or obsolete tile improvement plan.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.server.ai.ValuedAIObject
getValue, setValue
-
Methods inherited from class net.sf.freecol.server.ai.AIObject
addAIObjectWithId, checkIntegrity, copyIn, getAIMain, getGame, getSpecification, isDisposed, setGame, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readChild, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
type
private TileImprovementType type
The type of improvement, from TileImprovementTypes.
-
target
private Tile target
TheTile
to be improved.
-
pioneer
private AIUnit pioneer
The pioneer which should make the improvement (if aUnit
has been assigned).
-
PIONEER_TAG
private static final java.lang.String PIONEER_TAG
- See Also:
- Constant Field Values
-
TARGET_TAG
private static final java.lang.String TARGET_TAG
- See Also:
- Constant Field Values
-
TYPE_TAG
private static final java.lang.String TYPE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TileImprovementPlan
public TileImprovementPlan(AIMain aiMain, java.lang.String id)
Creates a new uninitializedTileImprovementPlan
.- Parameters:
aiMain
- The main AI-object.id
- The object identifier.
-
TileImprovementPlan
public TileImprovementPlan(AIMain aiMain, Tile target, TileImprovementType type, int value)
Creates a newTileImprovementPlan
and initializes its critical fields.- Parameters:
aiMain
- The main AI-object.target
- The targetTile
for the improvement.type
- The type of improvement.value
- The value identifying the importance of thisTileImprovementPlan
- a higher value signals a higher importance.
-
TileImprovementPlan
public TileImprovementPlan(AIMain aiMain, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newTileImprovementPlan
from the given XML-representation.- Parameters:
aiMain
- The main AI-object.xr
- The input stream containing the XML.- Throws:
javax.xml.stream.XMLStreamException
- if a problem was encountered during parsing.
-
-
Method Detail
-
setInitialized
public final void setInitialized()
Set the initialized flag in this object. To be implemented by leaf classes, and called in their constructors plus the special case in readChild below where we resolve forward references.- Specified by:
setInitialized
in classAIObject
-
getPioneer
public final 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, andnull
if nobody has been assigned this mission.
-
setPioneer
public final 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 aUnit
has been assigned, andnull
if nobody has been assigned this mission.
-
getType
public final TileImprovementType getType()
Gets theTileImprovementType
of this plan.- Returns:
- The type of the improvement.
-
setType
public final void setType(TileImprovementType type)
Sets the type of thisTileImprovementPlan
.- Parameters:
type
- TheTileImprovementType
.- See Also:
getType()
-
getTarget
public final Tile getTarget()
Gets the target of thisTileImprovementPlan
.- Returns:
- The
Tile
wherepioneer
should make the givenimprovement
.
-
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
- TheTile
that will be improved.goodsType
- TheGoodsType
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
- TheGoodsType
to be prioritized.- Returns:
- True if the plan is still viable.
-
isComplete
public boolean isComplete()
Is this improvement complete?- Returns:
- True if the tile improvement has been completed.
-
validate
public boolean validate()
Weeds out a broken or obsolete tile improvement plan.- Returns:
- True if the plan survives this check.
-
dispose
public void dispose()
Disposes thisTileImprovementPlan
. If a pioneer has been assigned to making this improvement, then abort its mission.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
AIObjects need integrity checking too.- Overrides:
checkIntegrity
in classAIObject
- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
to log to.- Returns:
- -1 if there are problems remaining, zero if problems were fixed, +1 if no problems found at all.
-
toXML
public void toXML(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream. All attributes will be made visible.- Overrides:
toXML
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classValuedAIObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classValuedAIObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classValuedAIObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classValuedAIObject
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-