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 LocationdestinationThe requesting location of this wish.private static java.lang.StringDESTINATION_TAGprivate static java.util.logging.Loggerloggerprotected TransportableAIObjecttransportableTheTransportableAIObjectwhich will realize the wish, or null if none has been assigned.private static java.lang.StringTRANSPORTABLE_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 newWishfrom the given XML-representation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)AIObjects need integrity checking too.voiddispose()Disposes of thisAIObjectby removing any references to this object.booleanequals(java.lang.Object o)LocationgetDestination()Gets the destination of thisWish.AIColonygetDestinationAIColony()Gets the destination AI colony, if any.TransportableAIObjectgetTransportable()Gets theTransportableAIObjectassigned to this wish.inthashCode()protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.abstract booleansatisfiedBy(Unit unit)Does a specified unit satisfy this wish?abstract <T extends AbstractGoods>
booleansatisfiedBy(T goods)Does some specified goods satisfy this wish?voidsetTransportable(TransportableAIObject transportable)Assigns aTransportableAIObjectto thisWish.booleanshouldBeStored()Checks if thisWishneeds to be stored in a savegame.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, 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
TheTransportableAIObjectwhich 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 newWishfrom 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 thisWishneeds to be stored in a savegame.- Returns:
- True if it has been allocated a transportable.
-
getTransportable
public TransportableAIObject getTransportable()
Gets theTransportableAIObjectassigned to this wish.- Returns:
- The
TransportableAIObjectwhich 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 aTransportableAIObjectto thisWish.- Parameters:
transportable- TheTransportableAIObjectwhich should realize this wish.- See Also:
getTransportable(),WishRealizationMission
-
getDestination
public final Location getDestination()
Gets the destination of thisWish.- Returns:
- The
Locationin which thetransportableassigned to thisWishwill 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- TheUnitto 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 thisAIObjectby removing any references to this object.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
AIObjects need integrity checking too.- Overrides:
checkIntegrityin classAIObject- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto 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:
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
-
-