Package net.sf.freecol.common.model
Class DiplomaticTrade
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.DiplomaticTrade
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
public class DiplomaticTrade extends FreeColGameObject
The classDiplomaticTraderepresents an offer one player can make another. This has to be a FCGO so that it can be serialized, but instances are not interned.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDiplomaticTrade.TradeContextA context for the trade.static classDiplomaticTrade.TradeStatusA type for the trade status.
-
Field Summary
Fields Modifier and Type Field Description private DiplomaticTrade.TradeContextcontextThe context of this agreement.private static java.lang.StringCONTEXT_TAGprivate java.util.List<TradeItem>itemsThe individual items the trade consists of.private PlayerrecipientThe player who is to accept this agreement.private static java.lang.StringRECIPIENT_TAGprivate PlayersenderThe player who proposed agreement.private static java.lang.StringSENDER_TAGprivate DiplomaticTrade.TradeStatusstatusThe status of this agreement.private static java.lang.StringSTATUS_TAGstatic java.lang.StringTAGprivate intversionCounter for the number of iterations on this attempt to agree.private static java.lang.StringVERSION_TAG-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
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 DiplomaticTrade(Game game, java.lang.String id)Simple constructor, used in Game.newInstance.DiplomaticTrade(Game game, DiplomaticTrade.TradeContext context, Player sender, Player recipient, java.util.List<TradeItem> items, int version)Creates a newDiplomaticTradeinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(TradeItem newItem)Add to the DiplomaticTrade.voidclear()Remove all trade items from this agreement.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.java.util.List<Colony>getColoniesGivenBy(Player player)Get a list of colonies offered in this trade.DiplomaticTrade.TradeContextgetContext()Get the trade context.intgetGoldGivenBy(Player player)Get the gold offered in this trade by a given player.java.util.List<Goods>getGoodsGivenBy(Player player)Get the goods being offered.java.util.List<TradeItem>getItems()Get a list of all items to trade.java.util.List<TradeItem>getItemsGivenBy(Player player)Get the items offered by a particular player.PlayergetOtherPlayer(Player player)Get the other player in a trade.StringTemplategetReceiveMessage(Player player)Handy utility to get the message associated with sending this agreement from a player to a settlement owner.PlayergetRecipient()Get the recipient player.PlayergetSender()Get the sending player.StringTemplategetSendMessage(Player player, Settlement settlement)Handy utility to get the message associated with sending this agreement from a player to a settlement owner.StancegetStance()Get the stance being offered.DiplomaticTrade.TradeStatusgetStatus()Get the trade status.java.util.List<Unit>getUnitsGivenBy(Player player)Get a list of units offered in this trade.intgetVersion()Gets the version of this agreement.PlayergetVictim()Get the player being incited against.java.lang.StringgetXMLTagName()Get the serialization tag for this object.voidincrementVersion()Increment the version of this agreement.booleanisEmpty()Are there no trade items present?booleanisInternable()Should this object be interned into its Game? Usually true, but there are some special containers that have to be FCGOs but are unsuitable to be interned.static DiplomaticTrademakePeaceTreaty(DiplomaticTrade.TradeContext context, Player sender, Player recipient)Make a new diplomatic trade for a given context that establishes peace between two given players.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.voidremove(int index)Remove from the DiplomaticTrade.voidremove(TradeItem newItem)Remove a from the DiplomaticTrade.voidremoveType(java.lang.Class<? extends TradeItem> itemClass)Removes all trade items of the same class as the given argument.voidsetRecipient(Player newRecipient)Set the recieving player.voidsetSender(Player newSender)Set the sending player.voidsetStatus(DiplomaticTrade.TradeStatus status)Set the trade status.java.lang.StringtoString()protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(FreeColXMLWriter xw)Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, disposeResources, equals, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, hashCode, intern, internId, isDisposed, isInitialized, readFromXML, 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, 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, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
context
private DiplomaticTrade.TradeContext context
The context of this agreement.
-
status
private DiplomaticTrade.TradeStatus status
The status of this agreement.
-
sender
private Player sender
The player who proposed agreement.
-
recipient
private Player recipient
The player who is to accept this agreement.
-
items
private final java.util.List<TradeItem> items
The individual items the trade consists of.
-
version
private int version
Counter for the number of iterations on this attempt to agree.
-
CONTEXT_TAG
private static final java.lang.String CONTEXT_TAG
- See Also:
- Constant Field Values
-
RECIPIENT_TAG
private static final java.lang.String RECIPIENT_TAG
- See Also:
- Constant Field Values
-
SENDER_TAG
private static final java.lang.String SENDER_TAG
- See Also:
- Constant Field Values
-
STATUS_TAG
private static final java.lang.String STATUS_TAG
- See Also:
- Constant Field Values
-
VERSION_TAG
private static final java.lang.String VERSION_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DiplomaticTrade
public DiplomaticTrade(Game game, java.lang.String id)
Simple constructor, used in Game.newInstance.- Parameters:
game- The enclosingGame.id- The identifier (ignored).
-
DiplomaticTrade
public DiplomaticTrade(Game game, DiplomaticTrade.TradeContext context, Player sender, Player recipient, java.util.List<TradeItem> items, int version)
Creates a newDiplomaticTradeinstance.- Parameters:
game- The enclosingGame.context- TheTradeContextfor this agreement.sender- The sendingPlayer.recipient- The recipientPlayer.items- A list of items to trade.version- The trade version number.
-
-
Method Detail
-
makePeaceTreaty
public static DiplomaticTrade makePeaceTreaty(DiplomaticTrade.TradeContext context, Player sender, Player recipient)
Make a new diplomatic trade for a given context that establishes peace between two given players.- Parameters:
context- TheTradeContextthe peace arises in.sender- The sendingPlayer.recipient- The recipientPlayer.- Returns:
- A suitable
DiplomaticTrade.
-
getContext
public DiplomaticTrade.TradeContext getContext()
Get the trade context.- Returns:
- The context of this agreement.
-
getStatus
public DiplomaticTrade.TradeStatus getStatus()
Get the trade status.- Returns:
- The status of this agreement.
-
setStatus
public void setStatus(DiplomaticTrade.TradeStatus status)
Set the trade status.- Parameters:
status- The newTradeStatusfor this agreement.
-
getSender
public final Player getSender()
Get the sending player.- Returns:
- The sending
Player.
-
setSender
public final void setSender(Player newSender)
Set the sending player.- Parameters:
newSender- The new sendingPlayer.
-
getRecipient
public final Player getRecipient()
Get the recipient player.- Returns:
- The recipient
Player.
-
setRecipient
public final void setRecipient(Player newRecipient)
Set the recieving player.- Parameters:
newRecipient- The new recipientPlayer.
-
getOtherPlayer
public Player getOtherPlayer(Player player)
Get the other player in a trade.- Parameters:
player- The knownPlayer.- Returns:
- The other player, not the supplied known one.
-
getSendMessage
public StringTemplate getSendMessage(Player player, Settlement settlement)
Handy utility to get the message associated with sending this agreement from a player to a settlement owner.- Parameters:
player- The sendingPlayer.settlement- TheSettlementto send to.- Returns:
- A
StringTemplatefor the message.
-
getReceiveMessage
public StringTemplate getReceiveMessage(Player player)
Handy utility to get the message associated with sending this agreement from a player to a settlement owner.- Parameters:
player- ThePlayerthe offer came from.- Returns:
- A
StringTemplatefor the message.
-
add
public void add(TradeItem newItem)
Add to the DiplomaticTrade.- Parameters:
newItem- TheTradeItemto add.
-
remove
public void remove(TradeItem newItem)
Remove a from the DiplomaticTrade.- Parameters:
newItem- TheTradeItemto remove.
-
remove
public void remove(int index)
Remove from the DiplomaticTrade.- Parameters:
index- The index of theTradeItemto remove
-
removeType
public void removeType(java.lang.Class<? extends TradeItem> itemClass)
Removes all trade items of the same class as the given argument.- Parameters:
itemClass- TheClassofTradeItemto remove.
-
clear
public void clear()
Remove all trade items from this agreement.
-
getItems
public final java.util.List<TradeItem> getItems()
Get a list of all items to trade.- Returns:
- A list of all the
TradeItems.
-
isEmpty
public final boolean isEmpty()
Are there no trade items present?- Returns:
- True if there are no trade items present.
-
getItemsGivenBy
public java.util.List<TradeItem> getItemsGivenBy(Player player)
Get the items offered by a particular player.- Parameters:
player- ThePlayerto check.- Returns:
- A list of
TradeItems offered by the player.
-
getStance
public Stance getStance()
Get the stance being offered.- Returns:
- The
Stanceoffered in this trade, or null if none.
-
getColoniesGivenBy
public java.util.List<Colony> getColoniesGivenBy(Player player)
Get a list of colonies offered in this trade.- Parameters:
player- ThePlayeroffering the colonies.- Returns:
- A list of
Colonys offered in this trade.
-
getGoldGivenBy
public int getGoldGivenBy(Player player)
Get the gold offered in this trade by a given player.- Parameters:
player- ThePlayerto check.- Returns:
- The gold offered in this trade.
-
getGoodsGivenBy
public java.util.List<Goods> getGoodsGivenBy(Player player)
Get the goods being offered.- Parameters:
player- ThePlayeroffering the goods.- Returns:
- A list of
Goodsoffered in this trade.
-
getVictim
public Player getVictim()
Get the player being incited against.- Returns:
- The
Playerto be incited against.
-
getUnitsGivenBy
public java.util.List<Unit> getUnitsGivenBy(Player player)
Get a list of units offered in this trade.- Parameters:
player- ThePlayeroffering the units.- Returns:
- A list of
Units offered in this trade.
-
getVersion
public int getVersion()
Gets the version of this agreement.- Returns:
- The version number.
-
incrementVersion
public void incrementVersion()
Increment the version of this agreement.
-
isInternable
public boolean isInternable()
Should this object be interned into its Game? Usually true, but there are some special containers that have to be FCGOs but are unsuitable to be interned. These classes will override this routine.- Overrides:
isInternablein classFreeColGameObject- Returns:
- True if this object should be interned.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classFreeColGameObject- Type Parameters:
T- TheFreeColObjectsubclass of the object to copy in.- Parameters:
other- The other object.- Returns:
- True if the copy in is succesful.
-
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 classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
writeChildrenin classFreeColObject- 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 classFreeColGameObject- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildrenin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classFreeColObject- 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
-
-