Class GoodsType

    • Field Detail

      • DEFAULT_PRODUCTION_WEIGHT

        private static final float DEFAULT_PRODUCTION_WEIGHT
        See Also:
        Constant Field Values
      • DEFAULT_LOW_PRODUCTION_THRESHOLD

        private static final float DEFAULT_LOW_PRODUCTION_THRESHOLD
        See Also:
        Constant Field Values
      • DEFAULT_ZERO_PRODUCTION_FACTOR

        private static final float DEFAULT_ZERO_PRODUCTION_FACTOR
        See Also:
        Constant Field Values
      • goodsTypeComparator

        public static final java.util.Comparator<GoodsType> goodsTypeComparator
        A comparator to impose a useful order on goods types.
      • isFarmed

        private boolean isFarmed
        Is this a farmed goods type.
      • isFood

        private boolean isFood
        Is this a food type.
      • ignoreLimit

        private boolean ignoreLimit
        Does this goods type ignore warehouse limits.
      • newWorldGoods

        private boolean newWorldGoods
        Is this goods type native to the New World.
      • isMilitary

        private boolean isMilitary
        Whether this type of goods is required for building equipment that grants an offence bonus or defence bonus.
      • buildingMaterial

        private boolean buildingMaterial
        Whether this type of goods is required for building. (Derived attribute)
      • tradeGoods

        private boolean tradeGoods
        Whether these are trade goods that can only be obtained in Europe.
      • storable

        private boolean storable
        Whether this type of goods can be stored in a warehouse.
      • storedAs

        private GoodsType storedAs
        What this goods type is stored as.
      • madeFrom

        private GoodsType madeFrom
        What this goods type is made from.
      • makes

        private GoodsType makes
        What this goods type can make. (Derived attribute)
      • initialAmount

        private int initialAmount
        The initial amount of this goods type in a market.
      • initialPrice

        private int initialPrice
        The initial minimum sales price for this type of goods.
      • priceDiff

        private int priceDiff
        The initial market price difference for this type of goods.
      • breedingNumber

        private int breedingNumber
        The number of units required to breed this type of goods. This obviously only applies to animals.
      • price

        private int price
        The price of this type of goods. This is only used for goods that can not be traded in the market, such as hammers.
      • productionWeight

        private float productionWeight
        A weight for the potential production of this goods type at a colony site.
      • lowProductionThreshold

        private float lowProductionThreshold
        A threshold amount of potential production of this goods type at a colony site, below which the score for the site is reduced.
      • zeroProductionFactor

        private float zeroProductionFactor
        The multiplicative factor with which to penalize a colony site with zero production of this goods type, scaling linearly to unity when the amount reaches lowResourceThreshold.
      • BREEDING_NUMBER_TAG

        private static final java.lang.String BREEDING_NUMBER_TAG
        See Also:
        Constant Field Values
      • IGNORE_LIMIT_TAG

        private static final java.lang.String IGNORE_LIMIT_TAG
        See Also:
        Constant Field Values
      • INITIAL_AMOUNT_TAG

        private static final java.lang.String INITIAL_AMOUNT_TAG
        See Also:
        Constant Field Values
      • INITIAL_PRICE_TAG

        private static final java.lang.String INITIAL_PRICE_TAG
        See Also:
        Constant Field Values
      • LOW_PRODUCTION_THRESHOLD_TAG

        private static final java.lang.String LOW_PRODUCTION_THRESHOLD_TAG
        See Also:
        Constant Field Values
      • NEW_WORLD_GOODS_TAG

        private static final java.lang.String NEW_WORLD_GOODS_TAG
        See Also:
        Constant Field Values
      • PRICE_DIFFERENCE_TAG

        private static final java.lang.String PRICE_DIFFERENCE_TAG
        See Also:
        Constant Field Values
      • PRODUCTION_WEIGHT_TAG

        private static final java.lang.String PRODUCTION_WEIGHT_TAG
        See Also:
        Constant Field Values
      • ZERO_PRODUCTION_FACTOR_TAG

        private static final java.lang.String ZERO_PRODUCTION_FACTOR_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • GoodsType

        public GoodsType​(java.lang.String id,
                         Specification specification)
        Create a new goods type.
        Parameters:
        id - The object identifier.
        specification - The Specification to refer to.
    • Method Detail

      • isFarmed

        public boolean isFarmed()
        Is this a farmed goods type?
        Returns:
        True if this is a farmed goods type.
      • isFoodType

        public boolean isFoodType()
        Is this an edible goods type?
        Returns:
        True if this is a food type.
      • getMilitary

        public boolean getMilitary()
        Is this goods type a military goods type?
        Returns:
        True if this is a military goods type.
      • setMilitary

        public void setMilitary()
      • limitIgnored

        public boolean limitIgnored()
        Do warehouse storage limits not apply to this goods type?
        Returns:
        True if unlimited amounts of this goods type can be stored.
      • isNewWorldGoodsType

        public boolean isNewWorldGoodsType()
        Is this a goods type native to the New World?
        Returns:
        True if this goods type is native to the New World.
      • isNewWorldLuxuryType

        public boolean isNewWorldLuxuryType()
        Is this goods type made from a New World goods type?
        Returns:
        True if this goods type is made from New World goods.
      • isBuildingMaterial

        public boolean isBuildingMaterial()
        Is this type of goods is required for building a BuildableType?
        Returns:
        True if this is a simple building material.
        See Also:
        BuildableType
      • isTradeGoods

        public boolean isTradeGoods()
        Is this a trade goods type?
        Returns:
        True if this goods type is trade goods.
      • isLibertyType

        public boolean isLibertyType()
        Does this type of goods produce liberty?
        Returns:
        True if this goods type produces liberty.
      • isImmigrationType

        public boolean isImmigrationType()
        Does this type of goods produce immigration?
        Returns:
        True if this goods type produces immigration.
      • isStorable

        public boolean isStorable()
        Is this goods type storable?
        Returns:
        True if this goods type is storable.
      • isStoredAs

        public boolean isStoredAs()
        Is this type of goods stored as something else?
        Returns:
        True if this type of goods is stored as another type.
      • getStoredAs

        public GoodsType getStoredAs()
        What type of goods is this goods type stored as?
        Returns:
        The GoodsType this is stored as, usually itself.
      • isRawMaterial

        public boolean isRawMaterial()
        Can this goods type be made into somthing?
        Returns:
        True if this GoodsType can be made into something.
      • isRefined

        public boolean isRefined()
        Is this goods type made from somthing?
        Returns:
        True if this GoodsType is made from something.
      • getOutputType

        public GoodsType getOutputType()
        What is this goods made into?
        Returns:
        The GoodsType this is made into, if anything.
      • getInputType

        public GoodsType getInputType()
        What is this goods type made from?
        Returns:
        The GoodsType this is made from, if anything.
      • getInitialAmount

        public int getInitialAmount()
        Get the default initial amount of this goods type in a market.
        Returns:
        The default initial amount.
      • getInitialSellPrice

        int getInitialSellPrice()
        Get the initial minimum sales price for this type of goods. The actual initial sales price in a particular Market may be higher. This method is only used for initializing Markets.
        Returns:
        The initial sell price.
        See Also:
        Market
      • getInitialBuyPrice

        int getInitialBuyPrice()
        The default initial purchase price for this goods type.
        Returns:
        The default initial purchase price.
      • getPriceDifference

        int getPriceDifference()
        The default initial price difference (between purchase and sale price) for this type of goods.
        Returns:
        The default initial price difference.
      • getBreedingNumber

        public int getBreedingNumber()
        Get the breeding number for this goods type.
        Returns:
        The breeding number.
      • isBreedable

        public boolean isBreedable()
        Is this type of goods breedable?
        Returns:
        True if this GoodsType is breedable.
      • getPrice

        public int getPrice()
        Get the price of a non-tradeable goods type.
        Returns:
        The price.
      • setPrice

        public void setPrice​(int newPrice)
      • getProductionWeight

        public float getProductionWeight()
        Get the production weight.
        Returns:
        The production weight.
      • getLowProductionThreshold

        public float getLowProductionThreshold()
        Get the low production threshold.
        Returns:
        The low production threshold.
      • getZeroProductionFactor

        public float getZeroProductionFactor()
        Get the zero production factor.
        Returns:
        The zero production factor.
      • getLabel

        public StringTemplate getLabel()
        Gets the i18n-ed name for this goods type.
        Returns:
        The name of this GoodsType.
      • getWorkingAsKey

        public final java.lang.String getWorkingAsKey()
        Gets the "workingAs" key for the profession that makes this goods type.
        Returns:
        The "workingAs" message key.
      • getProductionChain

        public java.util.List<GoodsType> getProductionChain()
        Gets the production chain of the goods type, beginning with a raw material that can not be produced from any other. The last member of the production chain is the goods type itself. Note that this does not really handle goods that are stored as something else as is the case for grain etc. FIXME: fix or retire this routine?
        Returns:
        The production chain of this GoodsType as a list.
      • isRawBuildingMaterial

        public boolean isRawBuildingMaterial()
        Is this type of goods required somewhere in the chain for producing a BuildableType, and is not itself buildable.
        Returns:
        True if a raw building type.
        See Also:
        BuildableType
      • getEquivalentTypes

        public java.util.Set<GoodsType> getEquivalentTypes()
        Get all the equivalent goods types, in the sense that they are stored as this type.
        Returns:
        A set of equivalent GoodsTypes, which must include this one.
      • setDerivedAttributes

        public static void setDerivedAttributes​(Specification spec)
        Set the derived fields for the goods types in a specification. The "derived" fields are: buildingMaterial + makes - buildingMaterial depends on whether a GoodsType is present on a BuildableType requiredGoods list - makes depends on whether a GoodsType madeFrom field refers to another This is called from Specification.clean() when the specification is fully read. We must wait until then as the made-from field can change in extended specifications and mods. The current example of which is horses, which is made-from food in the classic ruleset and made-from grain in the freecol ruleset.
        Parameters:
        spec - The Specification to operate on.
      • getRank

        private int getRank()
        Impose a general order on the goods types.
        Returns:
        An integer useful in comparators.
      • copyIn

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