Class TradeItem

    • Field Detail

      • INVALID_TRADE_ITEM

        public static final int INVALID_TRADE_ITEM
        Flag for validity tests.
        See Also:
        Constant Field Values
      • source

        private Player source
        The player who is to provide this item.
      • destination

        private Player destination
        The player who is to receive this item.
    • Constructor Detail

      • TradeItem

        protected TradeItem​(Game game,
                            java.lang.String id,
                            Player source,
                            Player destination)
        Creates a new TradeItem instance.
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
        source - The source Player.
        destination - The destination Player.
      • TradeItem

        protected TradeItem​(Game game,
                            FreeColXMLReader xr)
                     throws javax.xml.stream.XMLStreamException
        Creates a new TradeItem instance.
        Parameters:
        game - The enclosing Game.
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
    • Method Detail

      • getSource

        public final Player getSource()
        Get the source player.
        Returns:
        The source Player.
      • setSource

        public final void setSource​(Player newSource)
        Set the source player.
        Parameters:
        newSource - The new source Player.
      • getDestination

        public final Player getDestination()
        Get the destination player.
        Returns:
        The destination Player.
      • setDestination

        public final void setDestination​(Player newDestination)
        Set the destination player.
        Parameters:
        newDestination - The new destination Player.
      • getOther

        public final Player getOther​(Player player)
        Get the other player for this trade item.
        Parameters:
        player - The Player we do not want.
        Returns:
        The Player we want.
      • isValid

        public abstract boolean isValid()
        Is this trade item valid? That is, is the request well formed.
        Returns:
        True if the item is valid.
      • isUnique

        public abstract boolean isUnique()
        Is this trade item unique? This is true for the StanceTradeItem and the GoldTradeItem, and false for all others.
        Returns:
        True if the item is unique.
      • getLabel

        public abstract StringTemplate getLabel()
        Get a label for this item.
        Returns:
        A StringTemplate describing this item.
      • getColony

        public Colony getColony​(Game game)
        Get the colony to trade.
        Parameters:
        game - A Game to look for the colony in.
        Returns:
        The Colony to trade.
      • getGoods

        public Goods getGoods()
        Get the goods to trade.
        Returns:
        The Goods to trade.
      • setGoods

        public void setGoods​(Goods goods)
        Set the goods to trade.
        Parameters:
        goods - The new Goods to trade.
      • getGold

        public int getGold()
        Get the gold to trade.
        Returns:
        The gold to trade.
      • setGold

        public void setGold​(int gold)
        Set the gold to trade.
        Parameters:
        gold - The new gold to trade.
      • getVictim

        public Player getVictim()
        Get the victim player to incite war against.
        Returns:
        The Player to trade.
      • getStance

        public Stance getStance()
        Get the stance to trade.
        Returns:
        The Stance to trade.
      • setStance

        public void setStance​(Stance stance)
        Set the stance to trade.
        Parameters:
        stance - The new Stance to trade.
      • getUnit

        public Unit getUnit()
        Get the unit to trade.
        Returns:
        The Unit to trade.
      • setUnit

        public void setUnit​(Unit unit)
        Set the unit to trade.
        Parameters:
        unit - The new Unit to trade.
      • evaluateFor

        public abstract int evaluateFor​(Player player)
        Evaluate this trade item for a given player.
        Parameters:
        player - The Player to evaluate for.
        Returns:
        A value for the player, INVALID_TRADE_ITEM for invalid.
      • 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.
      • 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.