Class TileImprovementPlan

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, ObjectWithId

    public class TileImprovementPlan
    extends ValuedAIObject
    Represents a plan to improve a Tile in some way. For instance by plowing or by building a road.
    See Also:
    Tile
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • target

        private Tile target
        The Tile to be improved.
      • pioneer

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

      • TileImprovementPlan

        public TileImprovementPlan​(AIMain aiMain,
                                   java.lang.String id)
        Creates a new uninitialized TileImprovementPlan.
        Parameters:
        aiMain - The main AI-object.
        id - The object identifier.
      • TileImprovementPlan

        public TileImprovementPlan​(AIMain aiMain,
                                   Tile target,
                                   TileImprovementType type,
                                   int value)
        Creates a new TileImprovementPlan and initializes its critical fields.
        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,
                                   FreeColXMLReader xr)
                            throws javax.xml.stream.XMLStreamException
        Creates a new TileImprovementPlan 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 class AIObject
      • 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, and null 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 a Unit has been assigned, and null if nobody has been assigned this mission.
      • getType

        public final TileImprovementType getType()
        Gets the TileImprovementType of this plan.
        Returns:
        The type of the improvement.
      • setType

        public final void setType​(TileImprovementType type)
        Sets the type of this TileImprovementPlan.
        Parameters:
        type - The TileImprovementType.
        See Also:
        getType()
      • getTarget

        public final 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.
      • 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 this TileImprovementPlan. If a pioneer has been assigned to making this improvement, then abort its mission.
        Overrides:
        dispose in class AIObject
      • checkIntegrity

        public Constants.IntegrityType checkIntegrity​(boolean fix,
                                                      LogBuilder lb)
        AIObjects need integrity checking too.
        Overrides:
        checkIntegrity in class AIObject
        Parameters:
        fix - If true, fix problems if possible.
        lb - A LogBuilder 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 class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class ValuedAIObject
        Parameters:
        xw - The FreeColXMLWriter 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 class ValuedAIObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Returns:
        The tag.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class ValuedAIObject