Package net.sf.freecol.common.model
Class Specification
- java.lang.Object
-
- net.sf.freecol.common.model.Specification
-
- All Implemented Interfaces:
OptionContainer
public final class Specification extends java.lang.Object implements OptionContainer
This class encapsulates any parts of the "specification" for FreeCol that are expressed best using XML. The XML is loaded through the class loader from the resource named "specification.xml" in the same package as this class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
Specification.ChildReader
private class
Specification.ModifierReader
Modifiers have to be hooked to the specification and added to the special modifiers list, hence the special purpose reader.private class
Specification.OptionReader
Options are special as they live in the allOptionGroups collection, which has its own particular semantics.static class
Specification.Source
Sources.private class
Specification.TypeReader<T extends FreeColSpecObjectType>
A reader for ordinary spec object types.
-
Field Summary
Fields Modifier and Type Field Description private int[]
ages
The turn number for the game ages for FF recruitment.private java.util.Map<java.lang.String,java.util.List<Ability>>
allAbilities
All the abilities by identifier.private java.util.Map<java.lang.String,java.util.List<Modifier>>
allModifiers
private java.util.Map<java.lang.String,OptionGroup>
allOptionGroups
private java.util.Map<java.lang.String,AbstractOption>
allOptions
private java.util.Map<java.lang.String,FreeColSpecObjectType>
allTypes
All the FreeColSpecObjectType objects, indexed by identifier.static Specification.Source
AMBUSH_BONUS_SOURCE
static Specification.Source
AMPHIBIOUS_ATTACK_PENALTY_SOURCE
static Specification.Source
ARTILLERY_PENALTY_SOURCE
static Specification.Source
ATTACK_BONUS_SOURCE
static Specification.Source
BASE_DEFENCE_SOURCE
static Specification.Source
BASE_OFFENCE_SOURCE
private java.util.ArrayList<UnitType>
buildableUnitTypes
private static java.lang.String
BUILDING_TYPES_TAG
private java.util.List<BuildingType>
buildingTypeList
static Specification.Source
CARGO_PENALTY_SOURCE
static Specification.Source
COLONY_GOODS_PARTY_SOURCE
private static java.lang.String[]
coreOptionGroups
The option groups to save.private static java.lang.String
DEFAULT_FOOD_TYPE
The default food type.private static java.lang.String
DEFAULT_NATION_TYPE
The default nation type, which does nothing special.static java.lang.String
DEFAULT_ROLE_ID
The default role.private static java.util.Map<java.lang.String,java.awt.Color>
defaultColors
A map of default nation colours.private java.util.List<UnitType>
defaultUnitTypes
private static java.lang.String
DIFFICULTY_LEVEL_TAG
static java.lang.String
DIFFICULTY_LEVELS
The difficulty levels option group is special.private java.lang.String
difficultyLevel
The name of the difficulty level option group.private java.util.List<Disaster>
disasters
private static java.lang.String
DISASTERS_TAG
private static java.lang.String
EUROPEAN_NATION_TYPES_TAG
private java.util.List<Nation>
europeanNations
private java.util.List<EuropeanNationType>
europeanNationTypes
private java.util.List<Event>
events
private static java.lang.String
EVENTS_TAG
private java.util.Map<GoodsType,UnitType>
experts
private java.util.List<GoodsType>
farmedGoodsTypeList
private UnitType
fastestLandUnitType
private UnitType
fastestNavalUnitType
private java.util.List<GoodsType>
foodGoodsTypeList
static Specification.Source
FORTIFICATION_BONUS_SOURCE
private static java.lang.String
FOUNDING_FATHERS_TAG
private java.util.List<FoundingFather>
foundingFathers
private static java.lang.String
GOODS_TYPES_TAG
private java.util.List<GoodsType>
goodsTypeList
private java.lang.String
id
The specification identifier.private java.util.List<GoodsType>
immigrationGoodsTypeList
private static java.lang.String
INDIAN_NATION_TYPES_TAG
static Specification.Source
INDIAN_RAID_BONUS_SOURCE
private java.util.List<Nation>
indianNations
private java.util.List<IndianNationType>
indianNationTypes
private boolean
initialized
private java.util.List<GoodsType>
libertyGoodsTypeList
private static java.util.logging.Logger
logger
private java.util.List<Role>
militaryRoles
A cache of the military roles in decreasing order.private static java.lang.String
MODIFIERS_TAG
static Specification.Source
MOVEMENT_PENALTY_SOURCE
private java.util.List<Nation>
nations
private static java.lang.String
NATIONS_TAG
private java.util.List<NationType>
nationTypes
private static java.lang.Class[]
newTypeClasses
Fixed class array argument used in newType().private java.util.List<GoodsType>
newWorldGoodsTypeList
private java.util.List<GoodsType>
newWorldLuxuryGoodsTypeList
static int
NUMBER_OF_AGES
How many game ages.private static java.lang.String
OLD_DIFFICULTY_LEVEL_TAG
private static java.lang.String
OLD_EQUIPMENT_TYPES_TAG
private static java.lang.String
OLD_TILEIMPROVEMENT_TYPES_TAG
private static java.lang.String
OPTIONS_TAG
private java.util.List<GoodsType>
rawBuildingGoodsTypeList
private java.util.Map<java.lang.String,Specification.ChildReader>
readerMap
A map from specification object group identifier to a reader for it.private java.util.List<Nation>
REFNations
private java.util.List<EuropeanNationType>
REFNationTypes
private static java.lang.String
RESOURCE_TYPES_TAG
private java.util.List<ResourceType>
resourceTypeList
private java.util.List<Role>
roles
static java.lang.String
ROLES_COMPAT_FILE_NAME
Roles backward compatibility fragment.private static java.lang.String
ROLES_TAG
static Specification.Source
SHIP_TRADE_PENALTY_SOURCE
static Specification.Source
SOL_MODIFIER_SOURCE
private static Specification.Source[]
sources
All the special static sources.private java.util.List<Modifier>
specialModifiers
private java.util.List<GoodsType>
storableGoodsTypeList
static java.lang.String
TAG
private static java.lang.String
TILE_IMPROVEMENT_TYPES_TAG
private static java.lang.String
TILE_TYPES_TAG
private java.util.List<TileImprovementType>
tileImprovementTypeList
private java.util.List<TileType>
tileTypeList
static java.lang.String
UNIT_CHANGE_TYPES_COMPAT_FILE_NAME
Unit change types backward compatibility fragment.private static java.lang.String
UNIT_CHANGE_TYPES_TAG
private static java.lang.String
UNIT_TYPES_TAG
private java.util.List<UnitChangeType>
unitChangeTypeList
private java.util.List<UnitType>
unitTypeList
private java.util.List<UnitType>
unitTypesPurchasedInEurope
private java.util.List<UnitType>
unitTypesTrainedInEurope
private java.lang.String
version
The specification version.private static java.lang.String
VERSION_TAG
-
Constructor Summary
Constructors Constructor Description Specification()
Creates a new Specification object.Specification(java.io.InputStream in)
Creates a new Specification object by loading it from the givenInputStream
.Specification(FreeColXMLReader xr)
Creates a new Specification object by loading it from the givenFreeColXMLReader
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAbility(java.lang.String id)
Registers an Ability's id as defined.void
addAbility(Ability ability)
Registers an Ability as defined.private void
addAbstractOption(AbstractOption abstractOption)
Adds anAbstractOption
to this specification.void
addModifier(Modifier modifier)
Add a modifier.private void
addOptionGroup(OptionGroup optionGroup, boolean recursive)
Adds anOptionGroup
to this specification.void
addTestFather(FoundingFather ff)
Add a father, for test purposes.private void
addType(java.lang.String id, FreeColSpecObjectType type)
Add a type by identifier.void
applyDifficultyLevel(java.lang.String difficulty)
Applies the difficulty level identified by the given String to the current specification.void
applyDifficultyLevel(OptionGroup level)
Applies the given difficulty level to the current specification.private boolean
applyFixes()
Apply all the special fixes to bring older specifications up to date.private boolean
checkDifficultyIntegerOption(java.lang.String id, java.lang.String gr, LogBuilder lb, int defaultValue)
private boolean
checkDifficultyOptionGroup(java.lang.String gr, LogBuilder lb, java.lang.String... ids)
private boolean
checkDifficultyPercentageOption(java.lang.String id, java.lang.String gr, LogBuilder lb, int defaultValue)
private UnitListOption
checkDifficultyUnitListOption(java.lang.String id, java.lang.String gr, LogBuilder lb)
private <R,T extends Option<R>>
booleancheckOp(java.lang.String id, java.lang.String gr, R defaultValue, java.lang.Class<T> returnClass)
Check if an option exists, and if not, create and install it.void
clean(java.lang.String why)
Clean up the specification.void
clearEuropeanNationalAdvantages()
Clear all European advantages.private int
compareVersion(java.lang.String other)
Compare a spec version number with the current one.void
disableEditing()
Disable editing of some critical option groups.private void
dropOptions(AbstractOption o, java.util.Collection<AbstractOption> all)
Drop an option and its descendents from a collection.<T extends FreeColSpecObjectType>
TfindType(java.lang.String id, java.lang.Class<T> returnClass)
Find theFreeColSpecObjectType
with the given identifier.private boolean
fixDifficultyOptions()
Backward compatibility code to make sure this specification contains a default value for every difficulty option.private boolean
fixGameOptions()
Backward compatibility code to make sure this specification contains a default value for every game option.private boolean
fixMapGeneratorOptions()
Backward compatibility code to make sure this specification contains a default value for every map option.private boolean
fixOrphanOptions()
Find and remove orphan options/groups that are not part of the core tree of options.private boolean
fixRoles()
Handle the reworking of roles that landed in 0.11.0.private boolean
fixSpec()
Backward compatibility for the Specification in general.private boolean
fixUnitChanges()
void
generateDynamicOptions()
Generate the dynamic options.java.util.stream.Stream<Ability>
getAbilities(java.lang.String id)
Get all the Abilities with the given identifier.int
getAge(Turn turn)
Gets the age corresponding to a given turn.BuildableType
getBuildableType(java.lang.String id)
java.util.List<UnitType>
getBuildableUnitTypes()
Get the list of buildable unit types.BuildingType
getBuildingType(java.lang.String id)
Get a building type by identifier.java.util.List<BuildingType>
getBuildingTypeList()
NationType
getDefaultNationType()
Role
getDefaultRole()
Get the default role.UnitType
getDefaultUnitType()
Get the most vanilla unit type.UnitType
getDefaultUnitType(NationType nationType)
Get the most vanilla unit type for a type of nation.UnitType
getDefaultUnitType(Player player)
Get the most vanilla unit type for a given player.java.lang.String
getDifficultyLevel()
Get the current difficulty level.java.util.List<OptionGroup>
getDifficultyLevels()
Gets the difficulty levels in this specification.OptionGroup
getDifficultyOptionGroup()
Gets the current difficulty level options.OptionGroup
getDifficultyOptionGroup(java.lang.String id)
Gets difficulty level options by id.Disaster
getDisaster(java.lang.String id)
Get a disaster by identifier.java.util.List<Disaster>
getDisasters()
java.util.List<Nation>
getEuropeanNations()
java.util.List<EuropeanNationType>
getEuropeanNationTypes()
Event
getEvent(java.lang.String id)
Get an event by identifier.java.util.List<Event>
getEvents()
UnitType
getExpertForProducing(GoodsType goodsType)
Get the unit type that is the expert for producing a type of goods.java.util.List<GoodsType>
getFarmedGoodsTypeList()
UnitType
getFastestLandUnitType()
Gets the fastest land unit type in this specification.UnitType
getFastestNavalUnitType()
Gets the fastest naval unit type in this specification.java.util.List<GoodsType>
getFoodGoodsTypeList()
FoundingFather
getFoundingFather(java.lang.String id)
Get a founding father type by identifier.java.util.List<FoundingFather>
getFoundingFathers()
OptionGroup
getGameOptions()
GoodsType
getGoodsType(java.lang.String id)
Get a goods type by identifier.java.util.List<GoodsType>
getGoodsTypeList()
java.lang.String
getId()
Get the specification identifier.java.util.List<GoodsType>
getImmigrationGoodsTypeList()
java.util.List<Nation>
getIndianNations()
java.util.List<IndianNationType>
getIndianNationTypes()
int
getInitialPrice(GoodsType goodsType)
Get the initial minimum price of the given goods type.java.util.List<GoodsType>
getLibertyGoodsTypeList()
OptionGroup
getMapGeneratorOptions()
java.util.stream.Stream<Role>
getMilitaryRoles()
Get the available military roles as a stream.java.util.List<Role>
getMilitaryRolesList()
Get the military roles in this specification, in decreasing order of effectiveness.Role
getMissionaryRole()
Get the missionary role.java.util.stream.Stream<Modifier>
getModifiers(java.lang.String id)
Get all the Modifiers with the given identifier.Nation
getNation(java.lang.String id)
Get a nation by identifier.java.util.List<Nation>
getNations()
NationType
getNationType(java.lang.String id)
Get a nation type by identifier.java.util.List<NationType>
getNationTypes()
int
getNeededTurnsOfTraining(UnitType typeTeacher, UnitType typeStudent)
Gets the number of turns a unit has to train to educate a student.java.util.List<GoodsType>
getNewWorldGoodsTypeList()
java.util.List<GoodsType>
getNewWorldLuxuryGoodsTypeList()
<T extends Option>
TgetOption(java.lang.String id, java.lang.Class<T> returnClass)
Get an option in this group (or descendents) by object identifier.OptionGroup
getOptionGroup(java.lang.String id)
Gets the value of anOptionGroup
.Role
getPioneerRole()
Get the pioneer role.GoodsType
getPrimaryFoodType()
Get the primary food type.java.util.List<GoodsType>
getRawBuildingGoodsTypeList()
java.util.List<Nation>
getREFNations()
java.util.List<EuropeanNationType>
getREFNationTypes()
java.util.stream.Stream<Role>
getREFRoles(boolean naval)
Gets the roles suitable for a REF unit as a stream.java.util.List<Role>
getREFRolesList(boolean naval)
Gets the roles suitable for a REF unit.java.util.List<UnitType>
getREFUnitTypes(boolean naval)
Gets the REF unit types.ResourceType
getResourceType(java.lang.String id)
Get a resource type by identifier.java.util.List<ResourceType>
getResourceTypeList()
Role
getRole(java.lang.String id)
Get a role by identifier.java.util.stream.Stream<Role>
getRoles()
Get all the available roles as a stream.java.util.List<Role>
getRolesList()
Get all the available roles.Role
getRoleWithAbility(java.lang.String id, java.util.List<Role> roles)
Get a role with an ability.Role
getScoutRole()
Get the scout role.java.util.List<GoodsType>
getStorableGoodsTypeList()
TileImprovementType
getTileImprovementType(java.lang.String id)
Get a tile improvement type by identifier.java.util.List<TileImprovementType>
getTileImprovementTypeList()
TileType
getTileType(java.lang.String id)
Get a tile type by identifier.java.util.List<TileType>
getTileTypeList()
FreeColSpecObjectType
getType(java.lang.String id)
Get aFreeColSpecObjectType
by id.private <T extends FreeColSpecObjectType>
TgetType(java.lang.String id, java.lang.Class<T> returnClass)
Find aFreeColSpecObjectType
by id and class.java.util.List<FreeColSpecObjectType>
getTypesProviding(java.lang.String id, boolean value)
Get the FreeColSpecObjectTypes that provide the required ability.<T extends FreeColSpecObjectType>
java.util.List<T>getTypesWithAbility(java.lang.Class<T> resultType, java.lang.String... abilities)
Get all types which have any of the given abilities.<T extends FreeColSpecObjectType>
java.util.List<T>getTypesWithoutAbility(java.lang.Class<T> resultType, java.lang.String... abilities)
Get all types which have none of the given abilities.UnitTypeChange
getUnitChange(java.lang.String id, UnitType fromType)
Get a specific unit change for a given unit change type, a source unit type to change, and a destination unit type.UnitTypeChange
getUnitChange(java.lang.String id, UnitType fromType, UnitType toType)
Get a specific unit change for a given unit change type, a source unit type to change, and a destination unit type.java.util.List<UnitTypeChange>
getUnitChanges(java.lang.String id, UnitType fromType)
Get a specific unit change for a given unit change type and source unit type to change.UnitChangeType
getUnitChangeType(java.lang.String id)
Get a specific type of unit change type.java.util.List<UnitChangeType>
getUnitChangeTypeList()
Get the list of all unit change types.UnitType
getUnitType(java.lang.String id)
Get a unit type by identifier.java.util.List<UnitType>
getUnitTypeList()
java.util.List<UnitType>
getUnitTypesPurchasedInEurope()
Get the unit types that can be purchased in Europe.java.util.List<UnitType>
getUnitTypesTrainedInEurope()
Gets the unit types that can be trained in Europe.java.util.List<UnitType>
getUnitTypesWithAbility(java.lang.String... abilities)
Get the unit types which have any of the given abilitiesjava.util.List<UnitType>
getUnitTypesWithoutAbility(java.lang.String... abilities)
Get the unit types which have none of the given abilitiesNation
getUnknownEnemyNation()
Get the special unknown enemy nation.java.lang.String
getVersion()
Get the specification version.java.lang.String
getXMLTagName()
<T extends Option>
booleanhasOption(java.lang.String id, java.lang.Class<T> returnClass)
Is an option present in the container.private void
load(java.io.InputStream in)
Load a specification or fragment from a stream.boolean
loadMods(java.util.List<FreeColModFile> mods)
Load mods into this specification.boolean
mergeGameOptions(OptionGroup newGameOptions, java.lang.String who)
Merge in a new set of game options.private OptionGroup
mergeGroup(OptionGroup group)
Merge an option group into the spec.boolean
mergeMapGeneratorOptions(OptionGroup newMapGeneratorOptions, java.lang.String who)
Merge in a new set of map options.private <T extends FreeColSpecObjectType>
TnewType(java.lang.String id, java.lang.Class<T> returnClass)
Build a newFreeColSpecObjectType
with given identifier and class.void
prepare(NationOptions.Advantages advantages, java.lang.String difficulty)
Prepare a specification with given advantages and difficulty level.void
prepare(NationOptions.Advantages advantages, OptionGroup difficulty)
Prepare a specification with given advantages and difficulty level.void
readFromXML(FreeColXMLReader xr)
Initializes this object from its XML-representation.private FreeColSpecObjectType
removeType(java.lang.String id)
Remove reference to a type.private void
setDifficultyOptionGroup(OptionGroup difficulty)
Add/overwrite a difficulty option group.void
setGameOptions(OptionGroup go)
void
setMapGeneratorOptions(OptionGroup mgo)
protected void
toXML(FreeColXMLWriter xw)
Write an XML-representation of this object to the given stream.boolean
updateGameAndMapOptions()
Update the game and map options from the user configuration files.private <T extends FreeColObject>
voidwriteSection(FreeColXMLWriter xw, java.lang.String section, java.util.Collection<T> items)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.freecol.common.option.OptionContainer
getBoolean, getFile, getInteger, getIntegerMinimum, getModList, getPercentage, getPercentageMultiplier, getRange, getSelection, getSelectionName, getString, getText, getUnitList, setBoolean, setFile, setInteger, setIntegerMinimum, setString, setText
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
newTypeClasses
private static final java.lang.Class[] newTypeClasses
Fixed class array argument used in newType().
-
AMBUSH_BONUS_SOURCE
public static final Specification.Source AMBUSH_BONUS_SOURCE
-
AMPHIBIOUS_ATTACK_PENALTY_SOURCE
public static final Specification.Source AMPHIBIOUS_ATTACK_PENALTY_SOURCE
-
ARTILLERY_PENALTY_SOURCE
public static final Specification.Source ARTILLERY_PENALTY_SOURCE
-
ATTACK_BONUS_SOURCE
public static final Specification.Source ATTACK_BONUS_SOURCE
-
BASE_DEFENCE_SOURCE
public static final Specification.Source BASE_DEFENCE_SOURCE
-
BASE_OFFENCE_SOURCE
public static final Specification.Source BASE_OFFENCE_SOURCE
-
CARGO_PENALTY_SOURCE
public static final Specification.Source CARGO_PENALTY_SOURCE
-
COLONY_GOODS_PARTY_SOURCE
public static final Specification.Source COLONY_GOODS_PARTY_SOURCE
-
FORTIFICATION_BONUS_SOURCE
public static final Specification.Source FORTIFICATION_BONUS_SOURCE
-
INDIAN_RAID_BONUS_SOURCE
public static final Specification.Source INDIAN_RAID_BONUS_SOURCE
-
MOVEMENT_PENALTY_SOURCE
public static final Specification.Source MOVEMENT_PENALTY_SOURCE
-
SHIP_TRADE_PENALTY_SOURCE
public static final Specification.Source SHIP_TRADE_PENALTY_SOURCE
-
SOL_MODIFIER_SOURCE
public static final Specification.Source SOL_MODIFIER_SOURCE
-
sources
private static final Specification.Source[] sources
All the special static sources.
-
defaultColors
private static final java.util.Map<java.lang.String,java.awt.Color> defaultColors
A map of default nation colours.
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
DIFFICULTY_LEVELS
public static final java.lang.String DIFFICULTY_LEVELS
The difficulty levels option group is special.- See Also:
- Constant Field Values
-
ROLES_COMPAT_FILE_NAME
public static final java.lang.String ROLES_COMPAT_FILE_NAME
Roles backward compatibility fragment.- See Also:
- Constant Field Values
-
UNIT_CHANGE_TYPES_COMPAT_FILE_NAME
public static final java.lang.String UNIT_CHANGE_TYPES_COMPAT_FILE_NAME
Unit change types backward compatibility fragment.- See Also:
- Constant Field Values
-
DEFAULT_FOOD_TYPE
private static final java.lang.String DEFAULT_FOOD_TYPE
The default food type.- See Also:
- Constant Field Values
-
DEFAULT_NATION_TYPE
private static final java.lang.String DEFAULT_NATION_TYPE
The default nation type, which does nothing special.- See Also:
- Constant Field Values
-
DEFAULT_ROLE_ID
public static final java.lang.String DEFAULT_ROLE_ID
The default role.- See Also:
- Constant Field Values
-
NUMBER_OF_AGES
public static final int NUMBER_OF_AGES
How many game ages.- See Also:
- Constant Field Values
-
coreOptionGroups
private static final java.lang.String[] coreOptionGroups
The option groups to save.
-
readerMap
private final java.util.Map<java.lang.String,Specification.ChildReader> readerMap
A map from specification object group identifier to a reader for it.
-
buildingTypeList
private final java.util.List<BuildingType> buildingTypeList
-
disasters
private final java.util.List<Disaster> disasters
-
europeanNationTypes
private final java.util.List<EuropeanNationType> europeanNationTypes
-
events
private final java.util.List<Event> events
-
foundingFathers
private final java.util.List<FoundingFather> foundingFathers
-
goodsTypeList
private final java.util.List<GoodsType> goodsTypeList
-
indianNationTypes
private final java.util.List<IndianNationType> indianNationTypes
-
nations
private final java.util.List<Nation> nations
-
resourceTypeList
private final java.util.List<ResourceType> resourceTypeList
-
roles
private final java.util.List<Role> roles
-
tileTypeList
private final java.util.List<TileType> tileTypeList
-
tileImprovementTypeList
private final java.util.List<TileImprovementType> tileImprovementTypeList
-
unitChangeTypeList
private final java.util.List<UnitChangeType> unitChangeTypeList
-
unitTypeList
private final java.util.List<UnitType> unitTypeList
-
allModifiers
private final java.util.Map<java.lang.String,java.util.List<Modifier>> allModifiers
-
specialModifiers
private final java.util.List<Modifier> specialModifiers
-
allOptions
private final java.util.Map<java.lang.String,AbstractOption> allOptions
-
allOptionGroups
private final java.util.Map<java.lang.String,OptionGroup> allOptionGroups
-
storableGoodsTypeList
private final java.util.List<GoodsType> storableGoodsTypeList
-
farmedGoodsTypeList
private final java.util.List<GoodsType> farmedGoodsTypeList
-
foodGoodsTypeList
private final java.util.List<GoodsType> foodGoodsTypeList
-
newWorldGoodsTypeList
private final java.util.List<GoodsType> newWorldGoodsTypeList
-
newWorldLuxuryGoodsTypeList
private final java.util.List<GoodsType> newWorldLuxuryGoodsTypeList
-
libertyGoodsTypeList
private final java.util.List<GoodsType> libertyGoodsTypeList
-
immigrationGoodsTypeList
private final java.util.List<GoodsType> immigrationGoodsTypeList
-
rawBuildingGoodsTypeList
private final java.util.List<GoodsType> rawBuildingGoodsTypeList
-
europeanNations
private final java.util.List<Nation> europeanNations
-
REFNations
private final java.util.List<Nation> REFNations
-
indianNations
private final java.util.List<Nation> indianNations
-
nationTypes
private final java.util.List<NationType> nationTypes
-
REFNationTypes
private final java.util.List<EuropeanNationType> REFNationTypes
-
buildableUnitTypes
private final java.util.ArrayList<UnitType> buildableUnitTypes
-
unitTypesTrainedInEurope
private final java.util.List<UnitType> unitTypesTrainedInEurope
-
unitTypesPurchasedInEurope
private final java.util.List<UnitType> unitTypesPurchasedInEurope
-
fastestLandUnitType
private UnitType fastestLandUnitType
-
fastestNavalUnitType
private UnitType fastestNavalUnitType
-
defaultUnitTypes
private final java.util.List<UnitType> defaultUnitTypes
-
allTypes
private final java.util.Map<java.lang.String,FreeColSpecObjectType> allTypes
All the FreeColSpecObjectType objects, indexed by identifier.
-
allAbilities
private final java.util.Map<java.lang.String,java.util.List<Ability>> allAbilities
All the abilities by identifier.
-
militaryRoles
private java.util.List<Role> militaryRoles
A cache of the military roles in decreasing order. Do not serialize.
-
initialized
private boolean initialized
-
id
private java.lang.String id
The specification identifier.
-
version
private java.lang.String version
The specification version.
-
difficultyLevel
private java.lang.String difficultyLevel
The name of the difficulty level option group.
-
ages
private final int[] ages
The turn number for the game ages for FF recruitment.
-
BUILDING_TYPES_TAG
private static final java.lang.String BUILDING_TYPES_TAG
- See Also:
- Constant Field Values
-
DIFFICULTY_LEVEL_TAG
private static final java.lang.String DIFFICULTY_LEVEL_TAG
- See Also:
- Constant Field Values
-
DISASTERS_TAG
private static final java.lang.String DISASTERS_TAG
- See Also:
- Constant Field Values
-
EUROPEAN_NATION_TYPES_TAG
private static final java.lang.String EUROPEAN_NATION_TYPES_TAG
- See Also:
- Constant Field Values
-
EVENTS_TAG
private static final java.lang.String EVENTS_TAG
- See Also:
- Constant Field Values
-
FOUNDING_FATHERS_TAG
private static final java.lang.String FOUNDING_FATHERS_TAG
- See Also:
- Constant Field Values
-
GOODS_TYPES_TAG
private static final java.lang.String GOODS_TYPES_TAG
- See Also:
- Constant Field Values
-
INDIAN_NATION_TYPES_TAG
private static final java.lang.String INDIAN_NATION_TYPES_TAG
- See Also:
- Constant Field Values
-
MODIFIERS_TAG
private static final java.lang.String MODIFIERS_TAG
- See Also:
- Constant Field Values
-
NATIONS_TAG
private static final java.lang.String NATIONS_TAG
- See Also:
- Constant Field Values
-
OPTIONS_TAG
private static final java.lang.String OPTIONS_TAG
- See Also:
- Constant Field Values
-
RESOURCE_TYPES_TAG
private static final java.lang.String RESOURCE_TYPES_TAG
- See Also:
- Constant Field Values
-
ROLES_TAG
private static final java.lang.String ROLES_TAG
- See Also:
- Constant Field Values
-
TILE_TYPES_TAG
private static final java.lang.String TILE_TYPES_TAG
- See Also:
- Constant Field Values
-
TILE_IMPROVEMENT_TYPES_TAG
private static final java.lang.String TILE_IMPROVEMENT_TYPES_TAG
- See Also:
- Constant Field Values
-
UNIT_CHANGE_TYPES_TAG
private static final java.lang.String UNIT_CHANGE_TYPES_TAG
- See Also:
- Constant Field Values
-
UNIT_TYPES_TAG
private static final java.lang.String UNIT_TYPES_TAG
- See Also:
- Constant Field Values
-
VERSION_TAG
private static final java.lang.String VERSION_TAG
- See Also:
- Constant Field Values
-
OLD_DIFFICULTY_LEVEL_TAG
private static final java.lang.String OLD_DIFFICULTY_LEVEL_TAG
- See Also:
- Constant Field Values
-
OLD_TILEIMPROVEMENT_TYPES_TAG
private static final java.lang.String OLD_TILEIMPROVEMENT_TYPES_TAG
- See Also:
- Constant Field Values
-
OLD_EQUIPMENT_TYPES_TAG
private static final java.lang.String OLD_EQUIPMENT_TYPES_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Specification
public Specification()
Creates a new Specification object.
-
Specification
public Specification(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a new Specification object by loading it from the givenFreeColXMLReader
.- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem with the stream.
-
Specification
public Specification(java.io.InputStream in) throws javax.xml.stream.XMLStreamException
Creates a new Specification object by loading it from the givenInputStream
.- Parameters:
in
- TheInputStream
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem with the stream.
-
-
Method Detail
-
load
private void load(java.io.InputStream in) throws javax.xml.stream.XMLStreamException
Load a specification or fragment from a stream.- Parameters:
in
- TheInputStream
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem with the stream.
-
loadMods
public boolean loadMods(java.util.List<FreeColModFile> mods)
Load mods into this specification.- Parameters:
mods
- A list ofFreeColModFile
s for the active mods.- Returns:
- True if any mod was loaded.
-
prepare
public void prepare(NationOptions.Advantages advantages, java.lang.String difficulty)
Prepare a specification with given advantages and difficulty level.- Parameters:
advantages
- An optionalAdvantages
setting.difficulty
- An optional identifier for the difficulty level.
-
prepare
public void prepare(NationOptions.Advantages advantages, OptionGroup difficulty)
Prepare a specification with given advantages and difficulty level.- Parameters:
advantages
- An optionalAdvantages
setting.difficulty
- An optional difficulty levelOptionGroup
.
-
clean
public void clean(java.lang.String why)
Clean up the specification. Builds all the cached containers and secondary variables. This *must* clear any containers before building as it may be called multiple times in response to various specification updates.- Parameters:
why
- A short statement of why the specification needed to be cleaned.
-
getId
public java.lang.String getId()
Get the specification identifier.- Returns:
- The specification identifier.
-
getVersion
public java.lang.String getVersion()
Get the specification version.- Returns:
- The specification version.
-
getType
public FreeColSpecObjectType getType(java.lang.String id)
Get aFreeColSpecObjectType
by id.- Parameters:
id
- The identifier to look for.- Returns:
- The
FreeColSpecObjectType
found if any.
-
getType
private <T extends FreeColSpecObjectType> T getType(java.lang.String id, java.lang.Class<T> returnClass)
Find aFreeColSpecObjectType
by id and class.- Type Parameters:
T
- The actual return type.- Parameters:
id
- The object identifier to look for.returnClass
- The expectedClass
.- Returns:
- The
FreeColSpecObjectType
found if any.
-
addType
private void addType(java.lang.String id, FreeColSpecObjectType type)
Add a type by identifier.- Parameters:
id
- The identifier to associate with.type
- TheFreeColSpecObjectType
to add.
-
removeType
private FreeColSpecObjectType removeType(java.lang.String id)
Remove reference to a type.- Parameters:
id
- The type identifier to remove.- Returns:
- The removed
FreeColSpecObjectType
.
-
addAbility
public void addAbility(Ability ability)
Registers an Ability as defined.- Parameters:
ability
- anAbility
value
-
addAbility
public void addAbility(java.lang.String id)
Registers an Ability's id as defined. This is useful for abilities that are required rather than provided by FreeColSpecObjectTypes.- Parameters:
id
- The object identifier.
-
getAbilities
public java.util.stream.Stream<Ability> getAbilities(java.lang.String id)
Get all the Abilities with the given identifier.- Parameters:
id
- The object identifier to look for.- Returns:
- A stream of
Ability
s.
-
addModifier
public void addModifier(Modifier modifier)
Add a modifier.- Parameters:
modifier
- TheModifier
to add.
-
getModifiers
public java.util.stream.Stream<Modifier> getModifiers(java.lang.String id)
Get all the Modifiers with the given identifier.- Parameters:
id
- The object identifier to look for.- Returns:
- A stream of
Modifier
s.
-
addTestFather
public void addTestFather(FoundingFather ff)
Add a father, for test purposes.- Parameters:
ff
- TheFoundingFather
to add.
-
disableEditing
public void disableEditing()
Disable editing of some critical option groups.
-
compareVersion
private int compareVersion(java.lang.String other)
Compare a spec version number with the current one.- Parameters:
other
- The other spec version number.- Returns:
- Positive if the current version is greater than the other, negative if the current version is lower than the other, zero if they are equal.
-
hasOption
public <T extends Option> boolean hasOption(java.lang.String id, java.lang.Class<T> returnClass)
Is an option present in the container.- Specified by:
hasOption
in interfaceOptionContainer
- Type Parameters:
T
- The actual return type.- Parameters:
id
- The object identifier.returnClass
- The expected option class.- Returns:
- True if the option is present.
-
getOption
public <T extends Option> T getOption(java.lang.String id, java.lang.Class<T> returnClass)
Get an option in this group (or descendents) by object identifier.- Specified by:
getOption
in interfaceOptionContainer
- Type Parameters:
T
- The actual return type.- Parameters:
id
- The object identifier.returnClass
- The expected option class.- Returns:
- The option, or a run time exception if the option does not exist or is of the wrong class.
-
getOptionGroup
public OptionGroup getOptionGroup(java.lang.String id)
Gets the value of anOptionGroup
.- Specified by:
getOptionGroup
in interfaceOptionContainer
- Parameters:
id
- The object identifier.- Returns:
- The
OptionGroup
value.
-
addOptionGroup
private void addOptionGroup(OptionGroup optionGroup, boolean recursive)
Adds anOptionGroup
to this specification.- Parameters:
optionGroup
- TheOptionGroup
to add.recursive
- If true, add recursively to subgroups.
-
addAbstractOption
private void addAbstractOption(AbstractOption abstractOption)
Adds anAbstractOption
to this specification.- Parameters:
abstractOption
- TheAbstractOption
to add.
-
mergeGroup
private OptionGroup mergeGroup(OptionGroup group)
Merge an option group into the spec.- Parameters:
group
- TheOptionGroup
to merge.- Returns:
- The merged
OptionGroup
from thisSpecification
.
-
getDifficultyLevels
public java.util.List<OptionGroup> getDifficultyLevels()
Gets the difficulty levels in this specification.- Returns:
- A list of difficulty levels in this specification.
-
getDifficultyLevel
public java.lang.String getDifficultyLevel()
Get the current difficulty level.- Returns:
- The difficulty level.
-
getDifficultyOptionGroup
public OptionGroup getDifficultyOptionGroup()
Gets the current difficulty level options.- Returns:
- The current difficulty level
OptionGroup
.
-
getDifficultyOptionGroup
public OptionGroup getDifficultyOptionGroup(java.lang.String id)
Gets difficulty level options by id.- Parameters:
id
- The difficulty level identifier to look for.- Returns:
- The corresponding difficulty level
OptionGroup
, if any.
-
setDifficultyOptionGroup
private void setDifficultyOptionGroup(OptionGroup difficulty)
Add/overwrite a difficulty option group.- Parameters:
difficulty
- TheOptionGroup
to add.
-
applyDifficultyLevel
public void applyDifficultyLevel(java.lang.String difficulty)
Applies the difficulty level identified by the given String to the current specification.- Parameters:
difficulty
- The identifier of a difficulty level to apply.
-
applyDifficultyLevel
public void applyDifficultyLevel(OptionGroup level)
Applies the given difficulty level to the current specification. Public for the test suite.- Parameters:
level
- The difficulty levelOptionGroup
to apply.
-
getGameOptions
public OptionGroup getGameOptions()
-
setGameOptions
public void setGameOptions(OptionGroup go)
-
getMapGeneratorOptions
public OptionGroup getMapGeneratorOptions()
-
setMapGeneratorOptions
public void setMapGeneratorOptions(OptionGroup mgo)
-
updateGameAndMapOptions
public boolean updateGameAndMapOptions()
Update the game and map options from the user configuration files.- Returns:
- True if any option was fixed.
-
generateDynamicOptions
public void generateDynamicOptions()
Generate the dynamic options. Only call this in the server. If clients call it the European prices can be desynchronized.
-
mergeGameOptions
public boolean mergeGameOptions(OptionGroup newGameOptions, java.lang.String who)
Merge in a new set of game options.- Parameters:
newGameOptions
- The new game optionsOptionGroup
to merge.who
- Where are we, client or server?- Returns:
- True if the merge succeeded.
-
mergeMapGeneratorOptions
public boolean mergeMapGeneratorOptions(OptionGroup newMapGeneratorOptions, java.lang.String who)
Merge in a new set of map options.- Parameters:
newMapGeneratorOptions
- The new game optionsOptionGroup
to merge.who
- Where are we, client or server?- Returns:
- True if the merge succeeded.
-
getAge
public int getAge(Turn turn)
Gets the age corresponding to a given turn.- Parameters:
turn
- TheTurn
to check.- Returns:
- The age of the given turn.
-
getBuildableType
public BuildableType getBuildableType(java.lang.String id)
-
getBuildingTypeList
public java.util.List<BuildingType> getBuildingTypeList()
-
getBuildingType
public BuildingType getBuildingType(java.lang.String id)
Get a building type by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
BuildingType
found.
-
getDisasters
public java.util.List<Disaster> getDisasters()
-
getDisaster
public Disaster getDisaster(java.lang.String id)
Get a disaster by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
Disaster
found.
-
getEvents
public java.util.List<Event> getEvents()
-
getEvent
public Event getEvent(java.lang.String id)
Get an event by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
Event
found.
-
getFoundingFathers
public java.util.List<FoundingFather> getFoundingFathers()
-
getFoundingFather
public FoundingFather getFoundingFather(java.lang.String id)
Get a founding father type by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
FoundingFather
found.
-
getGoodsTypeList
public java.util.List<GoodsType> getGoodsTypeList()
-
getStorableGoodsTypeList
public java.util.List<GoodsType> getStorableGoodsTypeList()
-
getFarmedGoodsTypeList
public java.util.List<GoodsType> getFarmedGoodsTypeList()
-
getNewWorldGoodsTypeList
public java.util.List<GoodsType> getNewWorldGoodsTypeList()
-
getNewWorldLuxuryGoodsTypeList
public java.util.List<GoodsType> getNewWorldLuxuryGoodsTypeList()
-
getLibertyGoodsTypeList
public java.util.List<GoodsType> getLibertyGoodsTypeList()
-
getImmigrationGoodsTypeList
public java.util.List<GoodsType> getImmigrationGoodsTypeList()
-
getFoodGoodsTypeList
public java.util.List<GoodsType> getFoodGoodsTypeList()
-
getRawBuildingGoodsTypeList
public final java.util.List<GoodsType> getRawBuildingGoodsTypeList()
-
getPrimaryFoodType
public GoodsType getPrimaryFoodType()
Get the primary food type. FIXME: The "Food" type is handled as a special case in many places. This routine was added to collect them into one place, in the hope we can one day deprecate this routine and clean up the special cases.- Returns:
- The main food type.
-
getInitialPrice
public int getInitialPrice(GoodsType goodsType)
Get the initial minimum price of the given goods type. The initial price in a particular Market may be higher.- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- The minimum price.
-
getGoodsType
public GoodsType getGoodsType(java.lang.String id)
Get a goods type by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
GoodsType
found.
-
getTileImprovementTypeList
public java.util.List<TileImprovementType> getTileImprovementTypeList()
-
getTileImprovementType
public TileImprovementType getTileImprovementType(java.lang.String id)
Get a tile improvement type by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
TileImprovementType
found.
-
getNationTypes
public java.util.List<NationType> getNationTypes()
-
getEuropeanNationTypes
public java.util.List<EuropeanNationType> getEuropeanNationTypes()
-
getREFNationTypes
public java.util.List<EuropeanNationType> getREFNationTypes()
-
getIndianNationTypes
public java.util.List<IndianNationType> getIndianNationTypes()
-
getNationType
public NationType getNationType(java.lang.String id)
Get a nation type by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
NationType
found.
-
getDefaultNationType
public NationType getDefaultNationType()
-
getNations
public java.util.List<Nation> getNations()
-
getEuropeanNations
public java.util.List<Nation> getEuropeanNations()
-
getIndianNations
public java.util.List<Nation> getIndianNations()
-
getREFNations
public java.util.List<Nation> getREFNations()
-
getNation
public Nation getNation(java.lang.String id)
Get a nation by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
Nation
found.
-
getUnknownEnemyNation
public Nation getUnknownEnemyNation()
Get the special unknown enemy nation.- Returns:
- The unknown enemy
Nation
.
-
clearEuropeanNationalAdvantages
public void clearEuropeanNationalAdvantages()
Clear all European advantages. Implements the Advantages==NONE setting.
-
getResourceTypeList
public java.util.List<ResourceType> getResourceTypeList()
-
getResourceType
public ResourceType getResourceType(java.lang.String id)
Get a resource type by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
ResourceType
found.
-
getRolesList
public java.util.List<Role> getRolesList()
Get all the available roles.- Returns:
- A list of available
Role
s.
-
getRoles
public java.util.stream.Stream<Role> getRoles()
Get all the available roles as a stream.- Returns:
- A stream of available
Role
s.
-
getRole
public Role getRole(java.lang.String id)
Get a role by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
Role
found.
-
getDefaultRole
public Role getDefaultRole()
Get the default role.- Returns:
- The default
Role
.
-
getMilitaryRolesList
public java.util.List<Role> getMilitaryRolesList()
Get the military roles in this specification, in decreasing order of effectiveness.- Returns:
- An unmodifiable list of military
Role
s.
-
getMilitaryRoles
public java.util.stream.Stream<Role> getMilitaryRoles()
Get the available military roles as a stream.- Returns:
- A stream of military
Role
s.
-
getREFRolesList
public java.util.List<Role> getREFRolesList(boolean naval)
Gets the roles suitable for a REF unit.- Parameters:
naval
- If true, choose roles for naval units, if not, land units.- Returns:
- A list of
Role
s suitable for REF units.
-
getREFRoles
public java.util.stream.Stream<Role> getREFRoles(boolean naval)
Gets the roles suitable for a REF unit as a stream.- Parameters:
naval
- If true, choose roles for naval units, if not, land units.- Returns:
- A stream of
Role
s suitable for REF units.
-
getRoleWithAbility
public Role getRoleWithAbility(java.lang.String id, java.util.List<Role> roles)
Get a role with an ability.- Parameters:
id
- The ability identifier to look for.roles
- An optional list ofRole
s to look in, if null all roles are used.- Returns:
- The first
Role
found with the required ability, or null if none found.
-
getMissionaryRole
public Role getMissionaryRole()
Get the missionary role.- Returns:
- The missionary
Role
.
-
getPioneerRole
public Role getPioneerRole()
Get the pioneer role.- Returns:
- The pioneer
Role
.
-
getScoutRole
public Role getScoutRole()
Get the scout role.- Returns:
- The scout
Role
.
-
getTileTypeList
public java.util.List<TileType> getTileTypeList()
-
getTileType
public TileType getTileType(java.lang.String id)
Get a tile type by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
TileType
found.
-
getUnitChangeTypeList
public java.util.List<UnitChangeType> getUnitChangeTypeList()
Get the list of all unit change types.- Returns:
- The unit change type list.
-
getUnitChangeType
public UnitChangeType getUnitChangeType(java.lang.String id)
Get a specific type of unit change type. Suitable indexing constants are in UnitChangeType.- Parameters:
id
- The identifier for the required change type.- Returns:
- The
UnitChangeType
found, or null if none present.
-
getUnitChanges
public java.util.List<UnitTypeChange> getUnitChanges(java.lang.String id, UnitType fromType)
Get a specific unit change for a given unit change type and source unit type to change. Suitable indexing constants are in UnitChangeType.- Parameters:
id
- The identifier for the required change type.fromType
- TheUnitType
to change.- Returns:
- A list of
UnitChange
s.
-
getUnitChange
public UnitTypeChange getUnitChange(java.lang.String id, UnitType fromType)
Get a specific unit change for a given unit change type, a source unit type to change, and a destination unit type. Suitable indexing constants are in UnitChangeType.- Parameters:
id
- The identifier for the required change type.fromType
- TheUnitType
to change from.- Returns:
- The
UnitChange
found, or null if the change is impossible.
-
getUnitChange
public UnitTypeChange getUnitChange(java.lang.String id, UnitType fromType, UnitType toType)
Get a specific unit change for a given unit change type, a source unit type to change, and a destination unit type. Suitable indexing constants are in UnitChangeType.- Parameters:
id
- The identifier for the required change type.fromType
- TheUnitType
to change from.toType
- TheUnitType
to change to.- Returns:
- The
UnitChange
found, or null if the change is impossible.
-
getNeededTurnsOfTraining
public int getNeededTurnsOfTraining(UnitType typeTeacher, UnitType typeStudent)
Gets the number of turns a unit has to train to educate a student. This value is only meaningful for units that can be put in a school.- Parameters:
typeTeacher
- The teacherUnitType
.typeStudent
- the studentUnitType
.- Returns:
- The turns of training needed.
-
getUnitTypeList
public java.util.List<UnitType> getUnitTypeList()
-
getDefaultUnitType
public UnitType getDefaultUnitType(Player player)
Get the most vanilla unit type for a given player.- Parameters:
player
- ThePlayer
to find the default unit type for, or null indicating a normal player nation (i.e. non-REF European).- Returns:
- The default unit type.
-
getDefaultUnitType
public UnitType getDefaultUnitType(NationType nationType)
Get the most vanilla unit type for a type of nation. Provides a type to use to make a neutral comparison of the productivity of work locations.- Parameters:
nationType
- TheNationType
to find the default unit type for, or null indicating a normal player nation (i.e. non-REF European).- Returns:
- The free colonist unit type.
-
getDefaultUnitType
public UnitType getDefaultUnitType()
Get the most vanilla unit type.- Returns:
- The default unit type.
-
getBuildableUnitTypes
public java.util.List<UnitType> getBuildableUnitTypes()
Get the list of buildable unit types.- Returns:
- The list of buildable unit types.
-
getExpertForProducing
public UnitType getExpertForProducing(GoodsType goodsType)
Get the unit type that is the expert for producing a type of goods.- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- The expert
UnitType
, or null if none.
-
getUnitTypesWithAbility
public java.util.List<UnitType> getUnitTypesWithAbility(java.lang.String... abilities)
Get the unit types which have any of the given abilities- Parameters:
abilities
- The abilities for the search- Returns:
- A list of
UnitType
s with the abilities.
-
getUnitTypesWithoutAbility
public java.util.List<UnitType> getUnitTypesWithoutAbility(java.lang.String... abilities)
Get the unit types which have none of the given abilities- Parameters:
abilities
- The abilities for the search- Returns:
- A list of
UnitType
s without the abilities.
-
getUnitTypesTrainedInEurope
public java.util.List<UnitType> getUnitTypesTrainedInEurope()
Gets the unit types that can be trained in Europe.- Returns:
- A list of Europe-trainable
UnitType
s.
-
getUnitTypesPurchasedInEurope
public java.util.List<UnitType> getUnitTypesPurchasedInEurope()
Get the unit types that can be purchased in Europe.- Returns:
- A list of Europe-purchasable
UnitType
s.
-
getFastestLandUnitType
public UnitType getFastestLandUnitType()
Gets the fastest land unit type in this specification.- Returns:
- The fastest land unit type.
-
getFastestNavalUnitType
public UnitType getFastestNavalUnitType()
Gets the fastest naval unit type in this specification.- Returns:
- The fastest naval unit type.
-
getREFUnitTypes
public java.util.List<UnitType> getREFUnitTypes(boolean naval)
Gets the REF unit types.- Parameters:
naval
- If true, choose naval units, if not, land units.- Returns:
- A list of
UnitType
s allowed for the REF.
-
getUnitType
public UnitType getUnitType(java.lang.String id)
Get a unit type by identifier.- Parameters:
id
- The object identifier.- Returns:
- The
UnitType
found.
-
findType
public <T extends FreeColSpecObjectType> T findType(java.lang.String id, java.lang.Class<T> returnClass)
Find theFreeColSpecObjectType
with the given identifier.- Type Parameters:
T
- The actual return type.- Parameters:
id
- The object identifier to look for.returnClass
- The expectedClass
.- Returns:
- The
FreeColSpecObjectType
found.
-
newType
private <T extends FreeColSpecObjectType> T newType(java.lang.String id, java.lang.Class<T> returnClass)
Build a newFreeColSpecObjectType
with given identifier and class.- Type Parameters:
T
- The actual return type.- Parameters:
id
- The identifier to look for.returnClass
- The expectedClass
.- Returns:
- The new
FreeColSpecObjectType
or null on error.
-
getTypesProviding
public java.util.List<FreeColSpecObjectType> getTypesProviding(java.lang.String id, boolean value)
Get the FreeColSpecObjectTypes that provide the required ability.- Parameters:
id
- The object identifier.value
- The ability value to check.- Returns:
- A list of
FreeColSpecObjectType
s that provide the required ability.
-
getTypesWithAbility
public <T extends FreeColSpecObjectType> java.util.List<T> getTypesWithAbility(java.lang.Class<T> resultType, java.lang.String... abilities)
Get all types which have any of the given abilities.- Type Parameters:
T
- The actual return type.- Parameters:
resultType
- The expected result type.abilities
- The abilities for the search.- Returns:
- A list of
FreeColSpecObjectType
s with at least one of the given abilities.
-
getTypesWithoutAbility
public <T extends FreeColSpecObjectType> java.util.List<T> getTypesWithoutAbility(java.lang.Class<T> resultType, java.lang.String... abilities)
Get all types which have none of the given abilities.- Type Parameters:
T
- The actual return type.- Parameters:
resultType
- The expected result type.abilities
- The abilities for the search- Returns:
- A list of
FreeColSpecObjectType
s without the given abilities.
-
applyFixes
private boolean applyFixes()
Apply all the special fixes to bring older specifications up to date.- Returns:
- True if a change was made.
-
fixOrphanOptions
private boolean fixOrphanOptions()
Find and remove orphan options/groups that are not part of the core tree of options.- Returns:
- True if a fix was made.
-
dropOptions
private void dropOptions(AbstractOption o, java.util.Collection<AbstractOption> all)
Drop an option and its descendents from a collection.- Parameters:
o
- TheAbstractOption
to drop.all
- The collection of options to drop from.
-
fixRoles
private boolean fixRoles()
Handle the reworking of roles that landed in 0.11.0. Deliberately not part of applyFixes(), this is called from readFromXML which can most accurately determine whether it is needed.- Returns:
- True if a fix was made.
-
fixUnitChanges
private boolean fixUnitChanges()
-
fixSpec
private boolean fixSpec()
Backward compatibility for the Specification in general.- Returns:
- True if a fix was made.
-
fixDifficultyOptions
private boolean fixDifficultyOptions()
Backward compatibility code to make sure this specification contains a default value for every difficulty option. When a new difficulty option is added to the spec, add a sensible default here.- Returns:
- True if an option was missing and added.
-
checkDifficultyOptionGroup
private boolean checkDifficultyOptionGroup(java.lang.String gr, LogBuilder lb, java.lang.String... ids)
-
checkDifficultyIntegerOption
private boolean checkDifficultyIntegerOption(java.lang.String id, java.lang.String gr, LogBuilder lb, int defaultValue)
-
checkDifficultyPercentageOption
private boolean checkDifficultyPercentageOption(java.lang.String id, java.lang.String gr, LogBuilder lb, int defaultValue)
-
checkDifficultyUnitListOption
private UnitListOption checkDifficultyUnitListOption(java.lang.String id, java.lang.String gr, LogBuilder lb)
-
fixGameOptions
private boolean fixGameOptions()
Backward compatibility code to make sure this specification contains a default value for every game option. When a new game option is added to the spec, add a sensible default here.- Returns:
- True if an option was missing and added.
-
fixMapGeneratorOptions
private boolean fixMapGeneratorOptions()
Backward compatibility code to make sure this specification contains a default value for every map option. When a new map option is added to the spec, add a sensible default here.- Returns:
- True if an option was missing and added.
-
checkOp
private <R,T extends Option<R>> boolean checkOp(java.lang.String id, java.lang.String gr, R defaultValue, java.lang.Class<T> returnClass)
Check if an option exists, and if not, create and install it. FIXME: Handles failure to create a needed option badly.- Type Parameters:
R
- The underlying type encapsulated by the option.T
- The option type.- Parameters:
id
- The option identifier.gr
- The option group identifier.defaultValue
- The default value of the option.returnClass
- The expected class of option.- Returns:
- True if the option did not exist and was successfully created.
-
toXML
protected void toXML(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write an XML-representation of this object to the given stream.- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeSection
private <T extends FreeColObject> void writeSection(FreeColXMLWriter xw, java.lang.String section, java.util.Collection<T> items) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
readFromXML
public void readFromXML(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Initializes this object from its XML-representation.- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
-
-