Class AIGoods

    • Field Detail

      • logger

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

        private Goods goods
        The underlying goods.
      • destination

        private Location destination
        The destination location for the goods.
    • Constructor Detail

      • AIGoods

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

        public AIGoods​(AIMain aiMain,
                       Location location,
                       GoodsType type,
                       int amount,
                       Location destination)
        Creates a new AIGoods.
        Parameters:
        aiMain - The main AI-object.
        location - The location of the goods.
        type - The type of goods.
        amount - The amount of goods.
        destination - The destination of the goods. This is the Location to which the goods should be transported.
      • AIGoods

        public AIGoods​(AIMain aiMain,
                       FreeColXMLReader xr)
                throws javax.xml.stream.XMLStreamException
        Creates a new AIGoods 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 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
      • getGoods

        public final Goods getGoods()
        Gets the goods this AIGoods is controlling.
        Returns:
        The Goods.
      • setGoods

        public final void setGoods​(Goods goods)
        Sets the goods this AIGoods is controlling.
        Parameters:
        goods - The new Goods.
      • getGoodsType

        public final GoodsType getGoodsType()
        Gets the type of goods this AIGoods is controlling.
        Returns:
        The GoodsType.
      • getGoodsAmount

        public final int getGoodsAmount()
        Gets the amount of goods this AIGoods is controlling.
        Returns:
        The amount of goods.
      • setGoodsAmount

        public final void setGoodsAmount​(int amount)
        Sets the amount of goods this AIGoods is controlling.
        Parameters:
        amount - The new amount of goods.
      • leaveTransport

        private boolean leaveTransport​(int amount)
        Goods leaves a ship.
        Parameters:
        amount - The amount of goods to unload.
        Returns:
        True if the unload succeeds.
      • getTransportDestination

        public Location getTransportDestination()
        Get the destination location for this transportable AI object. This can be the target Tile of the transport or the target of the mission.
        Specified by:
        getTransportDestination in class TransportableAIObject
        Returns:
        The destination Location.
      • setTransportDestination

        public void setTransportDestination​(Location destination)
        Set the destination location for this transportable AI object.
        Specified by:
        setTransportDestination in class TransportableAIObject
        Parameters:
        destination - The destination Location.
      • getDeliveryPath

        public PathNode getDeliveryPath​(Unit carrier,
                                        Location dst)
        Get the path to deliver this transportable to its destination with a given carrier.
        Specified by:
        getDeliveryPath in class TransportableAIObject
        Parameters:
        carrier - The carrier Unit to use.
        dst - The destination Location, defaulting to the transport destination if null.
        Returns:
        A path, or null if none found.
      • getIntermediatePath

        public PathNode getIntermediatePath​(Unit carrier,
                                            Location dst)
        Get the path to make progress with this transport, for the carrier to either collect or deliver the transportable, albeit it need only improve the current situation rather than complete the delivery to the destination.
        Specified by:
        getIntermediatePath in class TransportableAIObject
        Parameters:
        carrier - The carrier Unit to use.
        dst - The destination Location, defaulting to the transport destination if null.
        Returns:
        A path, or null if none found.
      • carriableBy

        public boolean carriableBy​(Unit carrier)
        Can this transportable be carried by a given carrier unit?
        Specified by:
        carriableBy in class TransportableAIObject
        Parameters:
        carrier - The potential carrier Unit.
        Returns:
        True if the unit can carry this transportable.
      • canMove

        public boolean canMove()
        This transportable can move now. Useful for units that may or may not have enough moves left to join or leave a carrier.
        Specified by:
        canMove in class TransportableAIObject
        Returns:
        True if the transportable can move.
      • leaveTransport

        public boolean leaveTransport()
        This object leaves its current carrier unit by the most suitable means.
        Specified by:
        leaveTransport in class TransportableAIObject
        Returns:
        True if the object successfully left the carrier.
      • leaveTransport

        public boolean leaveTransport​(Direction direction)
        This object leaves its current carrier unit.
        Specified by:
        leaveTransport in class TransportableAIObject
        Parameters:
        direction - The Direction to leave in, null to leave in place.
        Returns:
        True if the object successfully left the carrier.
      • joinTransport

        public boolean joinTransport​(Unit carrier,
                                     Direction direction)
        This object joins a carrier unit.
        Specified by:
        joinTransport in class TransportableAIObject
        Parameters:
        carrier - The carrier Unit to join.
        direction - The Direction to move, null to join a carrier in the same location.
        Returns:
        True if the object has joined tha carrier.
      • invalidReason

        public java.lang.String invalidReason()
        Is there a reason to invalidate transporting this object?
        Specified by:
        invalidReason in class TransportableAIObject
        Returns:
        A reason to abort transport, or null if none found.
      • dispose

        public void dispose()
        Disposes this object.
        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.
      • 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 TransportableAIObject
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • writeChildren

        protected void writeChildren​(FreeColXMLWriter xw)
                              throws javax.xml.stream.XMLStreamException
        Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeChildren in class FreeColObject
        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 TransportableAIObject
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readChild

        protected void readChild​(FreeColXMLReader xr)
                          throws javax.xml.stream.XMLStreamException
        Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.
        Overrides:
        readChild in class FreeColObject
        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.