Package net.sf.freecol.common.model
Class GoodsType
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.FreeColSpecObjectType
-
- net.sf.freecol.common.model.GoodsType
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Named
,ObjectWithId
public final class GoodsType extends FreeColSpecObjectType
A type of goods, derived from the specification.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
BREEDING_NUMBER_TAG
private int
breedingNumber
The number of units required to breed this type of goods.private boolean
buildingMaterial
Whether this type of goods is required for building.private static float
DEFAULT_LOW_PRODUCTION_THRESHOLD
private static float
DEFAULT_PRODUCTION_WEIGHT
private static float
DEFAULT_ZERO_PRODUCTION_FACTOR
static java.util.Comparator<GoodsType>
goodsTypeComparator
A comparator to impose a useful order on goods types.private static java.lang.String
IGNORE_LIMIT_TAG
private boolean
ignoreLimit
Does this goods type ignore warehouse limits.private static java.lang.String
INITIAL_AMOUNT_TAG
private static java.lang.String
INITIAL_PRICE_TAG
private int
initialAmount
The initial amount of this goods type in a market.private int
initialPrice
The initial minimum sales price for this type of goods.private static java.lang.String
IS_FARMED_TAG
private static java.lang.String
IS_FOOD_TAG
private static java.lang.String
IS_MILITARY_TAG
private boolean
isFarmed
Is this a farmed goods type.private boolean
isFood
Is this a food type.private boolean
isMilitary
Whether this type of goods is required for building equipment that grants an offence bonus or defence bonus.private static java.lang.String
LOW_PRODUCTION_THRESHOLD_TAG
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.private static java.lang.String
MADE_FROM_TAG
private GoodsType
madeFrom
What this goods type is made from.private GoodsType
makes
What this goods type can make.private static java.lang.String
MARKET_TAG
private static java.lang.String
NEW_WORLD_GOODS_TAG
private boolean
newWorldGoods
Is this goods type native to the New World.private int
price
The price of this type of goods.private static java.lang.String
PRICE_DIFFERENCE_TAG
private static java.lang.String
PRICE_TAG
private int
priceDiff
The initial market price difference for this type of goods.private static java.lang.String
PRODUCTION_WEIGHT_TAG
private float
productionWeight
A weight for the potential production of this goods type at a colony site.private boolean
storable
Whether this type of goods can be stored in a warehouse.private static java.lang.String
STORABLE_TAG
private static java.lang.String
STORED_AS_TAG
private GoodsType
storedAs
What this goods type is stored as.static java.lang.String
TAG
private static java.lang.String
TRADE_GOODS_TAG
private boolean
tradeGoods
Whether these are trade goods that can only be obtained in Europe.private static java.lang.String
ZERO_PRODUCTION_FACTOR_TAG
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.-
Fields inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
DELETE_TAG, EXTENDS_TAG, PRESERVE_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description GoodsType(java.lang.String id, Specification specification)
Create a new goods type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.int
getBreedingNumber()
Get the breeding number for this goods type.java.util.Set<GoodsType>
getEquivalentTypes()
Get all the equivalent goods types, in the sense that they are stored as this type.int
getInitialAmount()
Get the default initial amount of this goods type in a market.(package private) int
getInitialBuyPrice()
The default initial purchase price for this goods type.(package private) int
getInitialSellPrice()
Get the initial minimum sales price for this type of goods.GoodsType
getInputType()
What is this goods type made from?StringTemplate
getLabel()
Gets the i18n-ed name for this goods type.float
getLowProductionThreshold()
Get the low production threshold.boolean
getMilitary()
Is this goods type a military goods type?GoodsType
getOutputType()
What is this goods made into?int
getPrice()
Get the price of a non-tradeable goods type.(package private) int
getPriceDifference()
The default initial price difference (between purchase and sale price) for this type of goods.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.float
getProductionWeight()
Get the production weight.private int
getRank()
Impose a general order on the goods types.GoodsType
getStoredAs()
What type of goods is this goods type stored as?java.lang.String
getWorkingAsKey()
Gets the "workingAs" key for the profession that makes this goods type.java.lang.String
getXMLTagName()
Get the serialization tag for this object.float
getZeroProductionFactor()
Get the zero production factor.boolean
isBreedable()
Is this type of goods breedable?boolean
isBuildingMaterial()
Is this type of goods is required for building a BuildableType?boolean
isFarmed()
Is this a farmed goods type?boolean
isFoodType()
Is this an edible goods type?boolean
isImmigrationType()
Does this type of goods produce immigration?boolean
isLibertyType()
Does this type of goods produce liberty?boolean
isNewWorldGoodsType()
Is this a goods type native to the New World?boolean
isNewWorldLuxuryType()
Is this goods type made from a New World goods type?boolean
isRawBuildingMaterial()
Is this type of goods required somewhere in the chain for producing a BuildableType, and is not itself buildable.boolean
isRawMaterial()
Can this goods type be made into somthing?boolean
isRefined()
Is this goods type made from somthing?boolean
isStorable()
Is this goods type storable?boolean
isStoredAs()
Is this type of goods stored as something else?boolean
isTradeGoods()
Is this a trade goods type?boolean
limitIgnored()
Do warehouse storage limits not apply to this goods type?protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.static void
setDerivedAttributes(Specification spec)
Set the derived fields for the goods types in a specification.void
setMilitary()
void
setPrice(int newPrice)
protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
addScope, appliesTo, copyScopes, getDescriptionKey, getFeatureContainer, getIndex, getNameKey, getScopeList, getScopes, isAbstractType, readChildren, removeScope, setIndex, toString
-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
getSpecification, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
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
-
IS_FARMED_TAG
private static final java.lang.String IS_FARMED_TAG
- See Also:
- Constant Field Values
-
IS_FOOD_TAG
private static final java.lang.String IS_FOOD_TAG
- See Also:
- Constant Field Values
-
IS_MILITARY_TAG
private static final java.lang.String IS_MILITARY_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
-
MADE_FROM_TAG
private static final java.lang.String MADE_FROM_TAG
- See Also:
- Constant Field Values
-
MARKET_TAG
private static final java.lang.String MARKET_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_TAG
private static final java.lang.String PRICE_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
-
STORABLE_TAG
private static final java.lang.String STORABLE_TAG
- See Also:
- Constant Field Values
-
STORED_AS_TAG
private static final java.lang.String STORED_AS_TAG
- See Also:
- Constant Field Values
-
TRADE_GOODS_TAG
private static final java.lang.String TRADE_GOODS_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
- TheSpecification
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
GoodsType
s, 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
- TheSpecification
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 classFreeColSpecObjectType
- Type Parameters:
T
- TheFreeColObject
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColSpecObjectType
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColSpecObjectType
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColSpecObjectType
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Returns:
- The tag.
-
-