Class TransportableAIObject

    • Field Detail

      • IMPORTANT_DELIVERY

        public static final int IMPORTANT_DELIVERY
        The priority for a goods that are hitting the warehouse limit.
        See Also:
        Constant Field Values
      • FULL_DELIVERY

        public static final int FULL_DELIVERY
        The priority for goods that provide at least a full cargo load.
        See Also:
        Constant Field Values
      • TOOLS_FOR_COLONY_PRIORITY

        public static final int TOOLS_FOR_COLONY_PRIORITY
        The priority of tools intended for a Colony with none stored at the present (and with no special needs).
        See Also:
        Constant Field Values
      • TOOLS_FOR_IMPROVEMENT

        public static final int TOOLS_FOR_IMPROVEMENT
        The extra priority value added to the base value of TOOLS_FOR_COLONY_PRIORITY for each ColonyTile needing a terrain improvement.
        See Also:
        Constant Field Values
      • TOOLS_FOR_BUILDING

        public static final int TOOLS_FOR_BUILDING
        The extra priority value added to the base value of TOOLS_FOR_COLONY_PRIORITY if a building is lacking tools. The number of tools is also added to the total amount.
        See Also:
        Constant Field Values
      • transport

        private AIUnit transport
        The AIUnit which has been allocated to transport this object.
    • Constructor Detail

      • TransportableAIObject

        public TransportableAIObject​(AIMain aiMain,
                                     java.lang.String id)
        Create a new uninitialized transportable AI object.
        Parameters:
        aiMain - an AIMain value
        id - The object identifier.
      • TransportableAIObject

        public TransportableAIObject​(AIMain aiMain,
                                     FreeColXMLReader xr)
                              throws javax.xml.stream.XMLStreamException
        Creates a new transportable AI object 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

      • getTransportPriority

        public int getTransportPriority()
        Gets the priority of transporting this object to its destination.
        Returns:
        The priority of the transport.
      • setTransportPriority

        public void setTransportPriority​(int transportPriority)
        Sets the priority of getting this object to its destination.
        Parameters:
        transportPriority - The priority.
      • incrementTransportPriority

        public final void incrementTransportPriority()
        Increases the transport priority.
      • getTransport

        public final AIUnit getTransport()
        Gets the carrier responsible for transporting this object.
        Returns:
        The AIUnit which will transport this object.
      • setTransport

        public final void setTransport​(AIUnit transport)
        Sets the carrier responsible for transporting this object.
        Parameters:
        transport - The new carrier AIUnit.
      • getSpaceTaken

        public int getSpaceTaken()
        Gets the number of cargo slots taken by this transportable.
        Returns:
        The number of cargo slots taken.
      • dropTransport

        public boolean dropTransport()
        Drop the current transport, keeping the transport mission consistent. Public so removeAIObject can drop its responsibilities.
        Returns:
        True if the unit has no allocated transport.
      • changeTransport

        public boolean changeTransport​(AIUnit aiCarrier)
        Change the allocated transport for this transportable to a different carrier unit. FIXME: partial attempt to maintain consistency of any carrier TransportMission lists, and disembark from the old carrier if possible.
        Parameters:
        aiCarrier - The new carrier AIUnit.
        Returns:
        True if the transport was changed, false if the transportable was unable to disembark from the old carrier or unable to be added to the new carrier transport list.
      • getLocation

        public Location getLocation()
        Get the transportables location if any.
        Returns:
        The transportable Location.
      • getTransportLocatable

        public abstract Locatable getTransportLocatable()
        Gets the underlying locatable object which should be transported.
        Returns:
        The Locatable.
      • getTransportSource

        public abstract Location getTransportSource()
        Get the source location for this transportable AI object. This is normally the location of the locatable.
        Returns:
        The source Location.
      • getTransportDestination

        public abstract 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.
        Returns:
        The destination Location.
      • setTransportDestination

        public abstract void setTransportDestination​(Location destination)
        Set the destination location for this transportable AI object.
        Parameters:
        destination - The destination Location.
      • getDeliveryPath

        public abstract PathNode getDeliveryPath​(Unit carrier,
                                                 Location dst)
        Get the path to deliver this transportable to its destination with a given carrier.
        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 abstract 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.
        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 abstract boolean carriableBy​(Unit carrier)
        Can this transportable be carried by a given carrier unit?
        Parameters:
        carrier - The potential carrier Unit.
        Returns:
        True if the unit can carry this transportable.
      • canMove

        public abstract 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.
        Returns:
        True if the transportable can move.
      • leaveTransport

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

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

        public abstract boolean joinTransport​(Unit carrier,
                                              Direction direction)
        This object joins a carrier unit.
        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 abstract java.lang.String invalidReason()
        Is there a reason to invalidate transporting this object?
        Returns:
        A reason to abort transport, or null if none found.
      • 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.
      • equals

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