Class Goods

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • game

        private final Game game
        The game containing these goods. It would be nice to make this a FreeColGameObject, but then it could not extend AbstractGoods.
      • location

        private Location location
        Where the goods are. This should always be non-null except for the really special case of goods that are in the process of being looted from a ship --- we can not use the ship as it is removed/disposed at once while the looting is still being resolved.
    • Constructor Detail

      • Goods

        private Goods​(Game game)
        Fundamental constructor.
        Parameters:
        game - The enclosing Game.
      • Goods

        public Goods​(Game game,
                     java.lang.String id)
        Creates a standard Goods-instance given the place where the goods is. Used by Game.newInstance.
        Parameters:
        game - The enclosing Game.
        id - The identifier (ignored, type gives identifier here).
      • Goods

        public Goods​(Game game,
                     Location location,
                     GoodsType type,
                     int amount)
        Creates a standard Goods-instance given the place where the goods is. This constructor only asserts that the game and that the location (if given) can store goods. The goods will not be added to the location (use Location.add for this).
        Parameters:
        game - The enclosing Game.
        location - The Location of the goods (may be null).
        type - The GoodsType for the goods.
        amount - The amount of the goods.
      • Goods

        public Goods​(Game game,
                     FreeColXMLReader xr)
              throws javax.xml.stream.XMLStreamException
        Creates a new Goods instance.
        Parameters:
        game - The enclosing Game.
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurs
    • Method Detail

      • adjustAmount

        public void adjustAmount()
        If the amount of goods is greater than the container can hold, then this method adjusts the amount to the maximum amount possible.
      • getLocation

        public Location getLocation()
        Gets the location of this Locatable.
        Specified by:
        getLocation in interface Locatable
        Returns:
        The location of this Locatable.
      • setLocation

        public boolean setLocation​(Location location)
        Description copied from interface: Locatable
        Sets the location for this Locatable.
        Specified by:
        setLocation in interface Locatable
        Parameters:
        location - The Settlement that is located on this Tile
        Returns:
        True if the location change succeeds.
      • isInEurope

        public boolean isInEurope()
        Is this locatable in Europe.
        Specified by:
        isInEurope in interface Locatable
        Returns:
        True if the Locatable is in Europe.
      • getTile

        public Tile getTile()
        Get the Tile where this Locatable is located, or null if it is in Europe.
        Specified by:
        getTile in interface Locatable
        Returns:
        The Tile where this Locatable is located, if any.
      • getSpaceTaken

        public int getSpaceTaken()
        Gets the number of cargo slots consumed when this Locatable if put onto a carrier.
        Specified by:
        getSpaceTaken in interface Locatable
        Returns:
        The number of cargo slots required.
      • getOwner

        public Player getOwner()
        Gets the owner of this Ownable.
        Specified by:
        getOwner in interface Ownable
        Returns:
        The Player controlling this Ownable.
      • setOwner

        public void setOwner​(Player p)
        Sets the owner of this Ownable.
        Specified by:
        setOwner in interface Ownable
        Parameters:
        p - The Player that should take ownership of this Ownable.
      • setSpecification

        public void setSpecification​(Specification specification)
        Sets the specification for this object.
        Overrides:
        setSpecification in class FreeColObject
        Parameters:
        specification - The Specification to use.
      • getGame

        public Game getGame()
        Gets the game this object belongs to.
        Overrides:
        getGame in class FreeColObject
        Returns:
        The Game this object belongs to.
      • setGame

        public void setGame​(Game game)
        Sets the game object this object belongs to.
        Overrides:
        setGame in class FreeColObject
        Parameters:
        game - The Game to set.
      • getDisplayObject

        public FreeColObject getDisplayObject()
        Get an object to display when showing the user messages for this object. Example: If this object is a Building, the object to display will be the BuildingType.
        Overrides:
        getDisplayObject in class FreeColObject
        Returns:
        A suitable FreeColObject to display, defaults to this.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class AbstractGoods
        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 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.
        Overrides:
        getXMLTagName in class AbstractGoods
        Returns:
        The tag.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class AbstractGoods