Package net.sf.freecol.server.ai
Class Wish
- 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.Wish
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
- Direct Known Subclasses:
GoodsWish
,WorkerWish
public abstract class Wish extends ValuedAIObject
Represents a need for something at a givenLocation
.
-
-
Field Summary
Fields Modifier and Type Field Description protected Location
destination
The requesting location of this wish.private static java.lang.String
DESTINATION_TAG
private static java.util.logging.Logger
logger
protected TransportableAIObject
transportable
TheTransportableAIObject
which will realize the wish, or null if none has been assigned.private static java.lang.String
TRANSPORTABLE_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 Wish(AIMain aiMain, java.lang.String id)
Creates a new uninitializedWish
.Wish(AIMain aiMain, FreeColXMLReader xr)
Creates a newWish
from the given XML-representation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
AIObjects need integrity checking too.void
dispose()
Disposes of thisAIObject
by removing any references to this object.boolean
equals(java.lang.Object o)
Location
getDestination()
Gets the destination of thisWish
.AIColony
getDestinationAIColony()
Gets the destination AI colony, if any.TransportableAIObject
getTransportable()
Gets theTransportableAIObject
assigned to this wish.int
hashCode()
protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.abstract boolean
satisfiedBy(Unit unit)
Does a specified unit satisfy this wish?abstract <T extends AbstractGoods>
booleansatisfiedBy(T goods)
Does some specified goods satisfy this wish?void
setTransportable(TransportableAIObject transportable)
Assigns aTransportableAIObject
to thisWish
.boolean
shouldBeStored()
Checks if thisWish
needs to be stored in a savegame.protected void
writeAttributes(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, copyIn, 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
-
logger
private static final java.util.logging.Logger logger
-
destination
protected Location destination
The requesting location of this wish.
-
transportable
protected TransportableAIObject transportable
TheTransportableAIObject
which will realize the wish, or null if none has been assigned.
-
DESTINATION_TAG
private static final java.lang.String DESTINATION_TAG
- See Also:
- Constant Field Values
-
TRANSPORTABLE_TAG
private static final java.lang.String TRANSPORTABLE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Wish
public Wish(AIMain aiMain, java.lang.String id)
Creates a new uninitializedWish
.- Parameters:
aiMain
- The main AI-object.id
- The object identifier.
-
Wish
public Wish(AIMain aiMain, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newWish
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
-
shouldBeStored
public boolean shouldBeStored()
Checks if thisWish
needs to be stored in a savegame.- Returns:
- True if it has been allocated a transportable.
-
getTransportable
public TransportableAIObject getTransportable()
Gets theTransportableAIObject
assigned to this wish.- Returns:
- The
TransportableAIObject
which will realize this wish, or null if none has been assigned. - See Also:
setTransportable(net.sf.freecol.server.ai.TransportableAIObject)
,WishRealizationMission
-
setTransportable
public void setTransportable(TransportableAIObject transportable)
Assigns aTransportableAIObject
to thisWish
.- Parameters:
transportable
- TheTransportableAIObject
which should realize this wish.- See Also:
getTransportable()
,WishRealizationMission
-
getDestination
public final Location getDestination()
Gets the destination of thisWish
.- Returns:
- The
Location
in which thetransportable
assigned to thisWish
will have to reach.
-
getDestinationAIColony
public final AIColony getDestinationAIColony()
Gets the destination AI colony, if any.- Returns:
- The destination
AIColony
.
-
satisfiedBy
public abstract boolean satisfiedBy(Unit unit)
Does a specified unit satisfy this wish?- Parameters:
unit
- TheUnit
to test.- Returns:
- True if the unit either matches exactly if expertRequired, or at least matches in a land/naval sense if not.
-
satisfiedBy
public abstract <T extends AbstractGoods> boolean satisfiedBy(T goods)
Does some specified goods satisfy this wish?- Type Parameters:
T
- The base type of the goods.- Parameters:
goods
- The goods to test.- Returns:
- True if the goods type matches and amount is not less than that requested.
-
dispose
public void dispose()
Disposes of thisAIObject
by removing any references to this object.
-
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 classValuedAIObject
- 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 classValuedAIObject
- Parameters:
xr
- TheFreeColXMLReader
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 classValuedAIObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classValuedAIObject
-
-