Package net.sf.freecol.server.ai
Class TransportableAIObject
- 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.TransportableAIObject
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
public abstract class TransportableAIObject extends ValuedAIObject
A single item in a carrier's transport list. AnyLocatablewhich should be able to be transported by a carrier using theTransportMission, should extend this class.- See Also:
TransportMission
-
-
Field Summary
Fields Modifier and Type Field Description static intFULL_DELIVERYThe priority for goods that provide at least a full cargo load.static intIMPORTANT_DELIVERYThe priority for a goods that are hitting the warehouse limit.static intTOOLS_FOR_BUILDINGThe extra priority value added to the base value ofTOOLS_FOR_COLONY_PRIORITYif a building is lacking tools.static intTOOLS_FOR_COLONY_PRIORITYThe priority of tools intended for a Colony with none stored at the present (and with no special needs).static intTOOLS_FOR_IMPROVEMENTThe extra priority value added to the base value ofTOOLS_FOR_COLONY_PRIORITYfor each ColonyTile needing a terrain improvement.static intTOOLS_FOR_PIONEERThe extra priority value added to the base value ofTOOLS_FOR_COLONY_PRIORITYif a Pioneer is lacking toolsprivate AIUnittransportTheAIUnitwhich has been allocated to transport this object.private static java.lang.StringTRANSPORT_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 TransportableAIObject(AIMain aiMain, java.lang.String id)Create a new uninitialized transportable AI object.TransportableAIObject(AIMain aiMain, FreeColXMLReader xr)Creates a new transportable AI object from the given XML-representation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract booleancanMove()This transportable can move now.abstract booleancarriableBy(Unit carrier)Can this transportable be carried by a given carrier unit?booleanchangeTransport(AIUnit aiCarrier)Change the allocated transport for this transportable to a different carrier unit.booleandropTransport()Drop the current transport, keeping the transport mission consistent.booleanequals(java.lang.Object o)abstract PathNodegetDeliveryPath(Unit carrier, Location dst)Get the path to deliver this transportable to its destination with a given carrier.abstract PathNodegetIntermediatePath(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.LocationgetLocation()Get the transportables location if any.intgetSpaceTaken()Gets the number of cargo slots taken by this transportable.AIUnitgetTransport()Gets the carrier responsible for transporting this object.abstract LocationgetTransportDestination()Get the destination location for this transportable AI object.abstract LocatablegetTransportLocatable()Gets the underlying locatable object which should be transported.intgetTransportPriority()Gets the priority of transporting this object to its destination.abstract LocationgetTransportSource()Get the source location for this transportable AI object.inthashCode()voidincrementTransportPriority()Increases the transport priority.abstract java.lang.StringinvalidReason()Is there a reason to invalidate transporting this object?abstract booleanjoinTransport(Unit carrier, Direction direction)This object joins a carrier unit.abstract booleanleaveTransport()This object leaves its current carrier unit by the most suitable means.abstract booleanleaveTransport(Direction direction)This object leaves its current carrier unit.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidsetTransport(AIUnit transport)Sets the carrier responsible for transporting this object.abstract voidsetTransportDestination(Location destination)Set the destination location for this transportable AI object.voidsetTransportPriority(int transportPriority)Sets the priority of getting this object to its destination.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, checkIntegrity, copyIn, dispose, getAIMain, getGame, getSpecification, isDisposed, setGame, setInitialized, 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, getXMLTagName, 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, toString, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
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 ofTOOLS_FOR_COLONY_PRIORITYfor each ColonyTile needing a terrain improvement.- See Also:
- Constant Field Values
-
TOOLS_FOR_PIONEER
public static final int TOOLS_FOR_PIONEER
The extra priority value added to the base value ofTOOLS_FOR_COLONY_PRIORITYif a Pioneer is lacking tools- See Also:
- Constant Field Values
-
TOOLS_FOR_BUILDING
public static final int TOOLS_FOR_BUILDING
The extra priority value added to the base value ofTOOLS_FOR_COLONY_PRIORITYif 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
TheAIUnitwhich has been allocated to transport this object.
-
TRANSPORT_TAG
private static final java.lang.String TRANSPORT_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TransportableAIObject
public TransportableAIObject(AIMain aiMain, java.lang.String id)
Create a new uninitialized transportable AI object.- Parameters:
aiMain- anAIMainvalueid- 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
AIUnitwhich will transport this object.
-
setTransport
public final void setTransport(AIUnit transport)
Sets the carrier responsible for transporting this object.- Parameters:
transport- The new carrierAIUnit.
-
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 carrierAIUnit.- 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 thelocatable.- Returns:
- The source
Location.
-
getTransportDestination
public abstract Location getTransportDestination()
Get the destination location for this transportable AI object. This can be the targetTileof 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 destinationLocation.
-
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 carrierUnitto use.dst- The destinationLocation, 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 carrierUnitto use.dst- The destinationLocation, 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 carrierUnit.- 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- TheDirectionto 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 carrierUnitto join.direction- TheDirectionto 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:
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.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classValuedAIObject
-
hashCode
public int hashCode()
- Overrides:
hashCodein classValuedAIObject
-
-