Package net.sf.freecol.server.ai
Class AIGoods
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public final class AIGoods extends TransportableAIObject
Objects of this class contains AI-information for a singleGoods
.
-
-
Field Summary
Fields Modifier and Type Field Description private Location
destination
The destination location for the goods.private static java.lang.String
DESTINATION_TAG
private Goods
goods
The underlying goods.private static java.util.logging.Logger
logger
static java.lang.String
TAG
-
Fields inherited from class net.sf.freecol.server.ai.TransportableAIObject
FULL_DELIVERY, IMPORTANT_DELIVERY, TOOLS_FOR_BUILDING, TOOLS_FOR_COLONY_PRIORITY, TOOLS_FOR_IMPROVEMENT, TOOLS_FOR_PIONEER
-
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 AIGoods(AIMain aiMain, java.lang.String id)
Creates a new uninitializedAIGoods
.AIGoods(AIMain aiMain, FreeColXMLReader xr)
Creates a newAIGoods
from the given XML-representation.AIGoods(AIMain aiMain, Location location, GoodsType type, int amount, Location destination)
Creates a newAIGoods
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canMove()
This transportable can move now.boolean
carriableBy(Unit carrier)
Can this transportable be carried by a given carrier unit?Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
AIObjects need integrity checking too.void
dispose()
Disposes this object.boolean
equals(java.lang.Object o)
PathNode
getDeliveryPath(Unit carrier, Location dst)
Get the path to deliver this transportable to its destination with a given carrier.Goods
getGoods()
Gets the goods thisAIGoods
is controlling.int
getGoodsAmount()
Gets the amount of goods thisAIGoods
is controlling.GoodsType
getGoodsType()
Gets the type of goods thisAIGoods
is controlling.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.Location
getTransportDestination()
Get the destination location for this transportable AI object.Locatable
getTransportLocatable()
Gets the underlying locatable object which should be transported.Location
getTransportSource()
Get the source location for this transportable AI object.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
hashCode()
java.lang.String
invalidReason()
Is there a reason to invalidate transporting this object?boolean
joinTransport(Unit carrier, Direction direction)
This object joins a carrier unit.boolean
leaveTransport()
This object leaves its current carrier unit by the most suitable means.private boolean
leaveTransport(int amount)
Goods leaves a ship.boolean
leaveTransport(Direction direction)
This object leaves its current carrier unit.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.void
setGoods(Goods goods)
Sets the goods thisAIGoods
is controlling.void
setGoodsAmount(int amount)
Sets the amount of goods thisAIGoods
is controlling.void
setInitialized()
Set the initialized flag in this object.void
setTransportDestination(Location destination)
Set the destination location for this transportable AI object.java.lang.String
toString()
protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.server.ai.TransportableAIObject
changeTransport, dropTransport, getLocation, getSpaceTaken, getTransport, getTransportPriority, incrementTransportPriority, setTransport, setTransportPriority
-
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, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
goods
private Goods goods
The underlying goods.
-
destination
private Location destination
The destination location for the goods.
-
DESTINATION_TAG
private static final java.lang.String DESTINATION_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AIGoods
public AIGoods(AIMain aiMain, java.lang.String id)
Creates a new uninitializedAIGoods
.- 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 newAIGoods
.- 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 theLocation
to which the goods should be transported.
-
AIGoods
public AIGoods(AIMain aiMain, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newAIGoods
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 classAIObject
-
getGoods
public final Goods getGoods()
Gets the goods thisAIGoods
is controlling.- Returns:
- The
Goods
.
-
setGoods
public final void setGoods(Goods goods)
Sets the goods thisAIGoods
is controlling.- Parameters:
goods
- The newGoods
.
-
getGoodsType
public final GoodsType getGoodsType()
Gets the type of goods thisAIGoods
is controlling.- Returns:
- The
GoodsType
.
-
getGoodsAmount
public final int getGoodsAmount()
Gets the amount of goods thisAIGoods
is controlling.- Returns:
- The amount of goods.
-
setGoodsAmount
public final void setGoodsAmount(int amount)
Sets the amount of goods thisAIGoods
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.
-
getTransportLocatable
public Locatable getTransportLocatable()
Gets the underlying locatable object which should be transported.- Specified by:
getTransportLocatable
in classTransportableAIObject
- Returns:
- The
Locatable
.
-
getTransportSource
public Location getTransportSource()
Get the source location for this transportable AI object. This is normally the location of thelocatable
.- Specified by:
getTransportSource
in classTransportableAIObject
- Returns:
- The source
Location
.
-
getTransportDestination
public Location getTransportDestination()
Get the destination location for this transportable AI object. This can be the targetTile
of the transport or the target of the mission.- Specified by:
getTransportDestination
in classTransportableAIObject
- Returns:
- The destination
Location
.
-
setTransportDestination
public void setTransportDestination(Location destination)
Set the destination location for this transportable AI object.- Specified by:
setTransportDestination
in classTransportableAIObject
- Parameters:
destination
- The destinationLocation
.
-
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 classTransportableAIObject
- Parameters:
carrier
- The carrierUnit
to use.dst
- The destinationLocation
, 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 classTransportableAIObject
- Parameters:
carrier
- The carrierUnit
to use.dst
- The destinationLocation
, 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 classTransportableAIObject
- Parameters:
carrier
- The potential carrierUnit
.- 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 classTransportableAIObject
- 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 classTransportableAIObject
- 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 classTransportableAIObject
- Parameters:
direction
- TheDirection
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 classTransportableAIObject
- Parameters:
carrier
- The carrierUnit
to join.direction
- TheDirection
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 classTransportableAIObject
- Returns:
- A reason to abort transport, or null if none found.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
AIObjects need integrity checking too.- Overrides:
checkIntegrity
in classAIObject
- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
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 classTransportableAIObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classTransportableAIObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classTransportableAIObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classTransportableAIObject
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-