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 aTilein 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.Loggerloggerprivate AIUnitpioneerThe pioneer which should make the improvement (if aUnithas been assigned).private static java.lang.StringPIONEER_TAGstatic java.lang.StringTAGprivate TiletargetTheTileto be improved.private static java.lang.StringTARGET_TAGprivate TileImprovementTypetypeThe type of improvement, from TileImprovementTypes.private static java.lang.StringTYPE_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 newTileImprovementPlanfrom the given XML-representation.TileImprovementPlan(AIMain aiMain, Tile target, TileImprovementType type, int value)Creates a newTileImprovementPlanand initializes its critical fields.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)AIObjects need integrity checking too.voiddispose()Disposes thisTileImprovementPlan.booleanequals(java.lang.Object o)static TileImprovementTypegetBestTileImprovementType(Tile tile, GoodsType goodsType)Gets the 'most effective' TileImprovementType allowed for a given tile and goods type.AIUnitgetPioneer()Gets the pioneer who have been assigned to making the improvement described by this object.TilegetTarget()Gets the target of thisTileImprovementPlan.TileImprovementTypegetType()Gets theTileImprovementTypeof this plan.java.lang.StringgetXMLTagName()Get the serialization tag for this object.inthashCode()booleanisComplete()Is this improvement complete?protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidsetInitialized()Set the initialized flag in this object.voidsetPioneer(AIUnit pioneer)Sets the pioneer who have been assigned to making the improvement described by this object.voidsetType(TileImprovementType type)Sets the type of thisTileImprovementPlan.java.lang.StringtoString()voidtoXML(FreeColXMLWriter xw)This method writes an XML-representation of this object to the given stream.booleanupdate(GoodsType goodsType)Updates this tile improvement plan to the best available for its tile and the specified goods type.booleanvalidate()Weeds out a broken or obsolete tile improvement plan.protected voidwriteAttributes(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
TheTileto be improved.
-
pioneer
private AIUnit pioneer
The pioneer which should make the improvement (if aUnithas 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 newTileImprovementPlanand initializes its critical fields.- Parameters:
aiMain- The main AI-object.target- The targetTilefor 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 newTileImprovementPlanfrom 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:
setInitializedin 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
AIUnithas been assigned, andnullif 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 aUnithas been assigned, andnullif nobody has been assigned this mission.
-
getType
public final TileImprovementType getType()
Gets theTileImprovementTypeof 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
Tilewherepioneershould 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- TheTilethat will be improved.goodsType- TheGoodsTypeto be prioritized.- Returns:
- The best
TileImprovementTypeavailable 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- TheGoodsTypeto 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:
checkIntegrityin classAIObject- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto 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:
toXMLin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
writeAttributesin classValuedAIObject- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classValuedAIObject- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classValuedAIObject
-
hashCode
public int hashCode()
- Overrides:
hashCodein classValuedAIObject
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
-