Class Resource

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

    public class Resource
    extends TileItem
    Represents a production resource, such as prime tobacco, or an ore vein, located on a Tile. A resource may be exhausted. In the original game, only resources that produced silver were exhausted.
    • Field Detail

      • logger

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

        private static final int UNLIMITED
        Some resources are unlimited.
        See Also:
        Constant Field Values
      • quantity

        private int quantity
        The amount of the resource present.
    • Constructor Detail

      • Resource

        public Resource​(Game game,
                        Tile tile,
                        ResourceType type,
                        int quantity)
        Creates a standard Resource-instance. This constructor asserts that the game, tile and type are valid.
        Parameters:
        game - The enclosing Game.
        tile - The Tile on which this object sits.
        type - The ResourceType of this Resource.
        quantity - The quantity of resource.
      • Resource

        public Resource​(Game game,
                        Tile tile,
                        ResourceType type)
        Creates a standard Resource-instance. This constructor asserts that the game, tile and type are valid.
        Parameters:
        game - The enclosing Game.
        tile - The Tile on which this object sits.
        type - The ResourceType of this Resource.
      • Resource

        public Resource​(Game game,
                        java.lang.String id)
        Creates new Resource.
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • getType

        public ResourceType getType()
        Get the type of this resource.
        Returns:
        The resource type.
      • isUnlimited

        public boolean isUnlimited()
        Is this an unlimited resource?
        Returns:
        True if this is an unlimited resource.
      • getQuantity

        public int getQuantity()
        Get the resource quantity.
        Returns:
        The resource quantity.
      • setQuantity

        public void setQuantity​(int newQuantity)
        Set the resource quantity.
        Parameters:
        newQuantity - The new resource quantity.
      • getBestGoodsType

        public GoodsType getBestGoodsType()
        Get the best goods type to produce here.
        Returns:
        The best goods type.
      • useQuantity

        public int useQuantity​(GoodsType goodsType,
                               UnitType unitType,
                               int potential)
        Reduce the available quantity by the bonus output of GoodsType.
        Parameters:
        goodsType - The GoodsType to check.
        unitType - The producing UnitType.
        potential - The base potential of the tile.
        Returns:
        The new quantity of resource.
      • useQuantity

        private int useQuantity​(int usedQuantity)
        Reduces the available quantity.
        Parameters:
        usedQuantity - The quantity that was used up.
        Returns:
        The final value of quantity.
      • getNameKey

        public java.lang.String getNameKey()
        Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.
        Specified by:
        getNameKey in interface Named
        Specified by:
        getNameKey in class TileItem
        Returns:
        The name of the Named.
      • getZIndex

        public final int getZIndex()
        Get the ZIndex value.
        Specified by:
        getZIndex in class TileItem
        Returns:
        The z-index.
      • isTileTypeAllowed

        public boolean isTileTypeAllowed​(TileType tileType)
        Is a tile type compatible with this tile item?
        Specified by:
        isTileTypeAllowed in class TileItem
        Parameters:
        tileType - The TileType to check.
        Returns:
        True if the tile type is compatible.
      • applyBonus

        public int applyBonus​(GoodsType goodsType,
                              UnitType unitType,
                              int potential)
        Applies the production bonus for the given goods type and unit type to the given potential production.
        Specified by:
        applyBonus in class TileItem
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - The UnitType that is to work.
        potential - The base potential production.
        Returns:
        The production with resource bonuses.
      • canProduce

        public boolean canProduce​(GoodsType goodsType,
                                  UnitType unitType)
        Does this tile item allow its enclosing tile to produce a given goods type?
        Specified by:
        canProduce in class TileItem
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - The optional unitType to produce with.
        Returns:
        True if this tile item produces the goods.
      • getProductionModifiers

        public java.util.stream.Stream<Modifier> getProductionModifiers​(GoodsType goodsType,
                                                                        UnitType unitType)
        Gets the production modifiers for the given type of goods and unit.
        Specified by:
        getProductionModifiers in class TileItem
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - The optional unitType to produce them.
        Returns:
        A stream of the applicable modifiers.
      • isNatural

        public boolean isNatural()
        Is this a natural TileItem?
        Specified by:
        isNatural in class TileItem
        Returns:
        True if this is a natural TileItem.
      • isComplete

        public boolean isComplete()
        Is this improvement complete?
        Specified by:
        isComplete in class TileItem
        Returns:
        True if complete.
      • getLayer

        public Map.Layer getLayer()
        Get the layer associated with this tile item.
        Specified by:
        getLayer in class TileItem
        Returns:
        The layer.
      • checkIntegrity

        public Constants.IntegrityType checkIntegrity​(boolean fix,
                                                      LogBuilder lb)
        Checks the integrity of this game object.
        Overrides:
        checkIntegrity in class TileItem
        Parameters:
        fix - If true, fix problems if possible.
        lb - A LogBuilder to log to.
        Returns:
        A suitable IntegrityType.
      • copyIn

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

        public java.lang.String getXMLTagName()
        Get the serialization tag for this object.
        Specified by:
        getXMLTagName in class FreeColObject
        Returns:
        The tag.