Class DiplomaticTrade

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, ObjectWithId

    public class DiplomaticTrade
    extends FreeColGameObject
    The class DiplomaticTrade represents an offer one player can make another. This has to be a FCGO so that it can be serialized, but instances are not interned.
    • Constructor Detail

      • DiplomaticTrade

        public DiplomaticTrade​(Game game,
                               java.lang.String id)
        Simple constructor, used in Game.newInstance.
        Parameters:
        game - The enclosing Game.
        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 new DiplomaticTrade instance.
        Parameters:
        game - The enclosing Game.
        context - The TradeContext for this agreement.
        sender - The sending Player.
        recipient - The recipient Player.
        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 - The TradeContext the peace arises in.
        sender - The sending Player.
        recipient - The recipient Player.
        Returns:
        A suitable DiplomaticTrade.
      • setStatus

        public void setStatus​(DiplomaticTrade.TradeStatus status)
        Set the trade status.
        Parameters:
        status - The new TradeStatus for 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 sending Player.
      • 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 recipient Player.
      • getOtherPlayer

        public Player getOtherPlayer​(Player player)
        Get the other player in a trade.
        Parameters:
        player - The known Player.
        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 sending Player.
        settlement - The Settlement to send to.
        Returns:
        A StringTemplate for 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 - The Player the offer came from.
        Returns:
        A StringTemplate for the message.
      • add

        public void add​(TradeItem newItem)
        Add to the DiplomaticTrade.
        Parameters:
        newItem - The TradeItem to add.
      • remove

        public void remove​(TradeItem newItem)
        Remove a from the DiplomaticTrade.
        Parameters:
        newItem - The TradeItem to remove.
      • remove

        public void remove​(int index)
        Remove from the DiplomaticTrade.
        Parameters:
        index - The index of the TradeItem to 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 - The Class of TradeItem to 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 - The Player to check.
        Returns:
        A list of TradeItems offered by the player.
      • getStance

        public Stance getStance()
        Get the stance being offered.
        Returns:
        The Stance offered 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 - The Player offering 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 - The Player to check.
        Returns:
        The gold offered in this trade.
      • getGoodsGivenBy

        public java.util.List<Goods> getGoodsGivenBy​(Player player)
        Get the goods being offered.
        Parameters:
        player - The Player offering the goods.
        Returns:
        A list of Goods offered in this trade.
      • getVictim

        public Player getVictim()
        Get the player being incited against.
        Returns:
        The Player to be incited against.
      • getUnitsGivenBy

        public java.util.List<Unit> getUnitsGivenBy​(Player player)
        Get a list of units offered in this trade.
        Parameters:
        player - The Player offering 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:
        isInternable in class FreeColGameObject
        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:
        copyIn in class FreeColGameObject
        Type Parameters:
        T - The FreeColObject subclass 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:
        writeAttributes in class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class FreeColGameObject
        Parameters:
        xr - The FreeColXMLReader to 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:
        readChildren in class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Returns:
        The tag.