Package net.sf.freecol.server.ai
Class GoodsWish
- 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
-
- net.sf.freecol.server.ai.GoodsWish
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
public final class GoodsWish extends Wish
Represents the need for goods within aColony.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringAMOUNT_REQUESTED_TAGprivate intamountRequestedThe amount of goods required.private static java.lang.StringGOODS_TYPE_TAGprivate GoodsTypegoodsTypeThe type of goods required.private static java.util.logging.Loggerloggerstatic java.lang.StringTAGprivate static java.lang.StringTRANSPORTABLE_TAG-
Fields inherited from class net.sf.freecol.server.ai.Wish
destination, transportable
-
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 GoodsWish(AIMain aiMain, java.lang.String id)Creates a new uninitializedGoodsWish.GoodsWish(AIMain aiMain, FreeColXMLReader xr)Creates a newGoodsWishfrom the given XML-representation.GoodsWish(AIMain aiMain, Location destination, int value, int amountRequested, GoodsType goodsType)Creates a newGoodsWish.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)AIObjects need integrity checking too.booleanequals(java.lang.Object o)intgetGoodsAmount()Gets the amount of goods wished for.GoodsTypegetGoodsType()Gets the type of goods wished for.java.lang.StringgetXMLTagName()Get the serialization tag for this object.inthashCode()protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.booleansatisfiedBy(Unit unit)Does a specified unit satisfy this wish?<T extends AbstractGoods>
booleansatisfiedBy(T goods)Does some specified goods satisfy this wish?voidsetGoodsAmount(int amount)Sets the amount of goods wished for.voidsetInitialized()Set the initialized flag in this object.booleanshouldBeStored()Checks if thisWishneeds to be stored in a savegame.java.lang.StringtoString()voidupdate(GoodsType goodsType, int amount, int value)Updates thisGoodsWishwith the given attributes.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.server.ai.Wish
dispose, getDestination, getDestinationAIColony, getTransportable, setTransportable
-
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, readChild, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
goodsType
private GoodsType goodsType
The type of goods required.
-
amountRequested
private int amountRequested
The amount of goods required.
-
AMOUNT_REQUESTED_TAG
private static final java.lang.String AMOUNT_REQUESTED_TAG
- See Also:
- Constant Field Values
-
GOODS_TYPE_TAG
private static final java.lang.String GOODS_TYPE_TAG
- See Also:
- Constant Field Values
-
TRANSPORTABLE_TAG
private static final java.lang.String TRANSPORTABLE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GoodsWish
public GoodsWish(AIMain aiMain, java.lang.String id)
Creates a new uninitializedGoodsWish.- Parameters:
aiMain- The main AI-object.id- The object identifier.
-
GoodsWish
public GoodsWish(AIMain aiMain, Location destination, int value, int amountRequested, GoodsType goodsType)
Creates a newGoodsWish.- Parameters:
aiMain- The main AI-object.destination- TheLocationin which thetransportableassigned to thisGoodsWishwill have to reach.value- The value identifying the importance of thisWish.amountRequested- The amount requested.goodsType- The type of goods needed for releasing this wish completly.
-
GoodsWish
public GoodsWish(AIMain aiMain, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newGoodsWishfrom 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:
setInitializedin classAIObject
-
update
public void update(GoodsType goodsType, int amount, int value)
Updates thisGoodsWishwith the given attributes.- Parameters:
goodsType- TheGoodsTypeto wish for.amount- The amount of goods.value- The urgency of the wish.
-
shouldBeStored
public boolean shouldBeStored()
Checks if thisWishneeds to be stored in a savegame.- Overrides:
shouldBeStoredin classWish- Returns:
- True. We always store goods wishes.
-
getGoodsType
public GoodsType getGoodsType()
Gets the type of goods wished for.- Returns:
- The type of goods wished for.
-
getGoodsAmount
public int getGoodsAmount()
Gets the amount of goods wished for.- Returns:
- The amount of goods wished for.
-
setGoodsAmount
public void setGoodsAmount(int amount)
Sets the amount of goods wished for. Called in AIColony when the colony needs to change the required goods amount.- Parameters:
amount- The new amount of goods wished for.
-
satisfiedBy
public boolean satisfiedBy(Unit unit)
Does a specified unit satisfy this wish?- Specified by:
satisfiedByin classWish- 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 <T extends AbstractGoods> boolean satisfiedBy(T goods)
Does some specified goods satisfy this wish?- Specified by:
satisfiedByin classWish- 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.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
AIObjects need integrity checking too.- Overrides:
checkIntegrityin classWish- 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 classWish- 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 classWish- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
-