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 interfaceSpecification.ChildReaderprivate classSpecification.ModifierReaderModifiers have to be hooked to the specification and added to the special modifiers list, hence the special purpose reader.private classSpecification.OptionReaderOptions are special as they live in the allOptionGroups collection, which has its own particular semantics.static classSpecification.SourceSources.private classSpecification.TypeReader<T extends FreeColSpecObjectType>A reader for ordinary spec object types.
-
Field Summary
Fields Modifier and Type Field Description private int[]agesThe turn number for the game ages for FF recruitment.private java.util.Map<java.lang.String,java.util.List<Ability>>allAbilitiesAll the abilities by identifier.private java.util.Map<java.lang.String,java.util.List<Modifier>>allModifiersprivate java.util.Map<java.lang.String,OptionGroup>allOptionGroupsprivate java.util.Map<java.lang.String,AbstractOption>allOptionsprivate java.util.Map<java.lang.String,FreeColSpecObjectType>allTypesAll the FreeColSpecObjectType objects, indexed by identifier.static Specification.SourceAMBUSH_BONUS_SOURCEstatic Specification.SourceAMPHIBIOUS_ATTACK_PENALTY_SOURCEstatic Specification.SourceARTILLERY_PENALTY_SOURCEstatic Specification.SourceATTACK_BONUS_SOURCEstatic Specification.SourceBASE_DEFENCE_SOURCEstatic Specification.SourceBASE_OFFENCE_SOURCEprivate java.util.ArrayList<UnitType>buildableUnitTypesprivate static java.lang.StringBUILDING_TYPES_TAGprivate java.util.List<BuildingType>buildingTypeListstatic Specification.SourceCARGO_PENALTY_SOURCEstatic Specification.SourceCOLONY_GOODS_PARTY_SOURCEprivate static java.lang.String[]coreOptionGroupsThe option groups to save.private static java.lang.StringDEFAULT_FOOD_TYPEThe default food type.private static java.lang.StringDEFAULT_NATION_TYPEThe default nation type, which does nothing special.static java.lang.StringDEFAULT_ROLE_IDThe default role.private static java.util.Map<java.lang.String,java.awt.Color>defaultColorsA map of default nation colours.private java.util.List<UnitType>defaultUnitTypesprivate static java.lang.StringDIFFICULTY_LEVEL_TAGstatic java.lang.StringDIFFICULTY_LEVELSThe difficulty levels option group is special.private java.lang.StringdifficultyLevelThe name of the difficulty level option group.private java.util.List<Disaster>disastersprivate static java.lang.StringDISASTERS_TAGprivate static java.lang.StringEUROPEAN_NATION_TYPES_TAGprivate java.util.List<Nation>europeanNationsprivate java.util.List<EuropeanNationType>europeanNationTypesprivate java.util.List<Event>eventsprivate static java.lang.StringEVENTS_TAGprivate java.util.Map<GoodsType,UnitType>expertsprivate java.util.List<GoodsType>farmedGoodsTypeListprivate UnitTypefastestLandUnitTypeprivate UnitTypefastestNavalUnitTypeprivate java.util.List<GoodsType>foodGoodsTypeListstatic Specification.SourceFORTIFICATION_BONUS_SOURCEprivate static java.lang.StringFOUNDING_FATHERS_TAGprivate java.util.List<FoundingFather>foundingFathersprivate static java.lang.StringGOODS_TYPES_TAGprivate java.util.List<GoodsType>goodsTypeListprivate java.lang.StringidThe specification identifier.private java.util.List<GoodsType>immigrationGoodsTypeListprivate static java.lang.StringINDIAN_NATION_TYPES_TAGstatic Specification.SourceINDIAN_RAID_BONUS_SOURCEprivate java.util.List<Nation>indianNationsprivate java.util.List<IndianNationType>indianNationTypesprivate booleaninitializedprivate java.util.List<GoodsType>libertyGoodsTypeListprivate static java.util.logging.Loggerloggerprivate java.util.List<Role>militaryRolesA cache of the military roles in decreasing order.private static java.lang.StringMODIFIERS_TAGstatic Specification.SourceMOVEMENT_PENALTY_SOURCEprivate java.util.List<Nation>nationsprivate static java.lang.StringNATIONS_TAGprivate java.util.List<NationType>nationTypesprivate static java.lang.Class[]newTypeClassesFixed class array argument used in newType().private java.util.List<GoodsType>newWorldGoodsTypeListprivate java.util.List<GoodsType>newWorldLuxuryGoodsTypeListstatic intNUMBER_OF_AGESHow many game ages.private static java.lang.StringOLD_DIFFICULTY_LEVEL_TAGprivate static java.lang.StringOLD_EQUIPMENT_TYPES_TAGprivate static java.lang.StringOLD_TILEIMPROVEMENT_TYPES_TAGprivate static java.lang.StringOPTIONS_TAGprivate java.util.List<GoodsType>rawBuildingGoodsTypeListprivate java.util.Map<java.lang.String,Specification.ChildReader>readerMapA map from specification object group identifier to a reader for it.private java.util.List<Nation>REFNationsprivate java.util.List<EuropeanNationType>REFNationTypesprivate static java.lang.StringRESOURCE_TYPES_TAGprivate java.util.List<ResourceType>resourceTypeListprivate java.util.List<Role>rolesstatic java.lang.StringROLES_COMPAT_FILE_NAMERoles backward compatibility fragment.private static java.lang.StringROLES_TAGstatic Specification.SourceSHIP_TRADE_PENALTY_SOURCEstatic Specification.SourceSOL_MODIFIER_SOURCEprivate static Specification.Source[]sourcesAll the special static sources.private java.util.List<Modifier>specialModifiersprivate java.util.List<GoodsType>storableGoodsTypeListstatic java.lang.StringTAGprivate static java.lang.StringTILE_IMPROVEMENT_TYPES_TAGprivate static java.lang.StringTILE_TYPES_TAGprivate java.util.List<TileImprovementType>tileImprovementTypeListprivate java.util.List<TileType>tileTypeListstatic java.lang.StringUNIT_CHANGE_TYPES_COMPAT_FILE_NAMEUnit change types backward compatibility fragment.private static java.lang.StringUNIT_CHANGE_TYPES_TAGprivate static java.lang.StringUNIT_TYPES_TAGprivate java.util.List<UnitChangeType>unitChangeTypeListprivate java.util.List<UnitType>unitTypeListprivate java.util.List<UnitType>unitTypesPurchasedInEuropeprivate java.util.List<UnitType>unitTypesTrainedInEuropeprivate java.lang.StringversionThe specification version.private static java.lang.StringVERSION_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 voidaddAbility(java.lang.String id)Registers an Ability's id as defined.voidaddAbility(Ability ability)Registers an Ability as defined.private voidaddAbstractOption(AbstractOption abstractOption)Adds anAbstractOptionto this specification.voidaddModifier(Modifier modifier)Add a modifier.private voidaddOptionGroup(OptionGroup optionGroup, boolean recursive)Adds anOptionGroupto this specification.voidaddTestFather(FoundingFather ff)Add a father, for test purposes.private voidaddType(java.lang.String id, FreeColSpecObjectType type)Add a type by identifier.voidapplyDifficultyLevel(java.lang.String difficulty)Applies the difficulty level identified by the given String to the current specification.voidapplyDifficultyLevel(OptionGroup level)Applies the given difficulty level to the current specification.private booleanapplyFixes()Apply all the special fixes to bring older specifications up to date.private booleancheckDifficultyIntegerOption(java.lang.String id, java.lang.String gr, LogBuilder lb, int defaultValue)private booleancheckDifficultyOptionGroup(java.lang.String gr, LogBuilder lb, java.lang.String... ids)private booleancheckDifficultyPercentageOption(java.lang.String id, java.lang.String gr, LogBuilder lb, int defaultValue)private UnitListOptioncheckDifficultyUnitListOption(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.voidclean(java.lang.String why)Clean up the specification.voidclearEuropeanNationalAdvantages()Clear all European advantages.private intcompareVersion(java.lang.String other)Compare a spec version number with the current one.voiddisableEditing()Disable editing of some critical option groups.private voiddropOptions(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 theFreeColSpecObjectTypewith the given identifier.private booleanfixDifficultyOptions()Backward compatibility code to make sure this specification contains a default value for every difficulty option.private booleanfixGameOptions()Backward compatibility code to make sure this specification contains a default value for every game option.private booleanfixMapGeneratorOptions()Backward compatibility code to make sure this specification contains a default value for every map option.private booleanfixOrphanOptions()Find and remove orphan options/groups that are not part of the core tree of options.private booleanfixRoles()Handle the reworking of roles that landed in 0.11.0.private booleanfixSpec()Backward compatibility for the Specification in general.private booleanfixUnitChanges()voidgenerateDynamicOptions()Generate the dynamic options.java.util.stream.Stream<Ability>getAbilities(java.lang.String id)Get all the Abilities with the given identifier.intgetAge(Turn turn)Gets the age corresponding to a given turn.BuildableTypegetBuildableType(java.lang.String id)java.util.List<UnitType>getBuildableUnitTypes()Get the list of buildable unit types.BuildingTypegetBuildingType(java.lang.String id)Get a building type by identifier.java.util.List<BuildingType>getBuildingTypeList()NationTypegetDefaultNationType()RolegetDefaultRole()Get the default role.UnitTypegetDefaultUnitType()Get the most vanilla unit type.UnitTypegetDefaultUnitType(NationType nationType)Get the most vanilla unit type for a type of nation.UnitTypegetDefaultUnitType(Player player)Get the most vanilla unit type for a given player.java.lang.StringgetDifficultyLevel()Get the current difficulty level.java.util.List<OptionGroup>getDifficultyLevels()Gets the difficulty levels in this specification.OptionGroupgetDifficultyOptionGroup()Gets the current difficulty level options.OptionGroupgetDifficultyOptionGroup(java.lang.String id)Gets difficulty level options by id.DisastergetDisaster(java.lang.String id)Get a disaster by identifier.java.util.List<Disaster>getDisasters()java.util.List<Nation>getEuropeanNations()java.util.List<EuropeanNationType>getEuropeanNationTypes()EventgetEvent(java.lang.String id)Get an event by identifier.java.util.List<Event>getEvents()UnitTypegetExpertForProducing(GoodsType goodsType)Get the unit type that is the expert for producing a type of goods.java.util.List<GoodsType>getFarmedGoodsTypeList()UnitTypegetFastestLandUnitType()Gets the fastest land unit type in this specification.UnitTypegetFastestNavalUnitType()Gets the fastest naval unit type in this specification.java.util.List<GoodsType>getFoodGoodsTypeList()FoundingFathergetFoundingFather(java.lang.String id)Get a founding father type by identifier.java.util.List<FoundingFather>getFoundingFathers()OptionGroupgetGameOptions()GoodsTypegetGoodsType(java.lang.String id)Get a goods type by identifier.java.util.List<GoodsType>getGoodsTypeList()java.lang.StringgetId()Get the specification identifier.java.util.List<GoodsType>getImmigrationGoodsTypeList()java.util.List<Nation>getIndianNations()java.util.List<IndianNationType>getIndianNationTypes()intgetInitialPrice(GoodsType goodsType)Get the initial minimum price of the given goods type.java.util.List<GoodsType>getLibertyGoodsTypeList()OptionGroupgetMapGeneratorOptions()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.RolegetMissionaryRole()Get the missionary role.java.util.stream.Stream<Modifier>getModifiers(java.lang.String id)Get all the Modifiers with the given identifier.NationgetNation(java.lang.String id)Get a nation by identifier.java.util.List<Nation>getNations()NationTypegetNationType(java.lang.String id)Get a nation type by identifier.java.util.List<NationType>getNationTypes()intgetNeededTurnsOfTraining(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.OptionGroupgetOptionGroup(java.lang.String id)Gets the value of anOptionGroup.RolegetPioneerRole()Get the pioneer role.GoodsTypegetPrimaryFoodType()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.ResourceTypegetResourceType(java.lang.String id)Get a resource type by identifier.java.util.List<ResourceType>getResourceTypeList()RolegetRole(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.RolegetRoleWithAbility(java.lang.String id, java.util.List<Role> roles)Get a role with an ability.RolegetScoutRole()Get the scout role.java.util.List<GoodsType>getStorableGoodsTypeList()TileImprovementTypegetTileImprovementType(java.lang.String id)Get a tile improvement type by identifier.java.util.List<TileImprovementType>getTileImprovementTypeList()TileTypegetTileType(java.lang.String id)Get a tile type by identifier.java.util.List<TileType>getTileTypeList()FreeColSpecObjectTypegetType(java.lang.String id)Get aFreeColSpecObjectTypeby id.private <T extends FreeColSpecObjectType>
TgetType(java.lang.String id, java.lang.Class<T> returnClass)Find aFreeColSpecObjectTypeby 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.UnitTypeChangegetUnitChange(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.UnitTypeChangegetUnitChange(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.UnitChangeTypegetUnitChangeType(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.UnitTypegetUnitType(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 abilitiesNationgetUnknownEnemyNation()Get the special unknown enemy nation.java.lang.StringgetVersion()Get the specification version.java.lang.StringgetXMLTagName()<T extends Option>
booleanhasOption(java.lang.String id, java.lang.Class<T> returnClass)Is an option present in the container.private voidload(java.io.InputStream in)Load a specification or fragment from a stream.booleanloadMods(java.util.List<FreeColModFile> mods)Load mods into this specification.booleanmergeGameOptions(OptionGroup newGameOptions, java.lang.String who)Merge in a new set of game options.private OptionGroupmergeGroup(OptionGroup group)Merge an option group into the spec.booleanmergeMapGeneratorOptions(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 newFreeColSpecObjectTypewith given identifier and class.voidprepare(NationOptions.Advantages advantages, java.lang.String difficulty)Prepare a specification with given advantages and difficulty level.voidprepare(NationOptions.Advantages advantages, OptionGroup difficulty)Prepare a specification with given advantages and difficulty level.voidreadFromXML(FreeColXMLReader xr)Initializes this object from its XML-representation.private FreeColSpecObjectTyperemoveType(java.lang.String id)Remove reference to a type.private voidsetDifficultyOptionGroup(OptionGroup difficulty)Add/overwrite a difficulty option group.voidsetGameOptions(OptionGroup go)voidsetMapGeneratorOptions(OptionGroup mgo)protected voidtoXML(FreeColXMLWriter xw)Write an XML-representation of this object to the given stream.booleanupdateGameAndMapOptions()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- TheFreeColXMLReaderto 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.XMLStreamExceptionCreates a new Specification object by loading it from the givenInputStream.- Parameters:
in- TheInputStreamto 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.XMLStreamExceptionLoad a specification or fragment from a stream.- Parameters:
in- TheInputStreamto 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 ofFreeColModFiles 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 optionalAdvantagessetting.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 optionalAdvantagessetting.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 aFreeColSpecObjectTypeby id.- Parameters:
id- The identifier to look for.- Returns:
- The
FreeColSpecObjectTypefound if any.
-
getType
private <T extends FreeColSpecObjectType> T getType(java.lang.String id, java.lang.Class<T> returnClass)
Find aFreeColSpecObjectTypeby id and class.- Type Parameters:
T- The actual return type.- Parameters:
id- The object identifier to look for.returnClass- The expectedClass.- Returns:
- The
FreeColSpecObjectTypefound 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- TheFreeColSpecObjectTypeto 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- anAbilityvalue
-
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
Abilitys.
-
addModifier
public void addModifier(Modifier modifier)
Add a modifier.- Parameters:
modifier- TheModifierto 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
Modifiers.
-
addTestFather
public void addTestFather(FoundingFather ff)
Add a father, for test purposes.- Parameters:
ff- TheFoundingFatherto 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:
hasOptionin 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:
getOptionin 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:
getOptionGroupin interfaceOptionContainer- Parameters:
id- The object identifier.- Returns:
- The
OptionGroupvalue.
-
addOptionGroup
private void addOptionGroup(OptionGroup optionGroup, boolean recursive)
Adds anOptionGroupto this specification.- Parameters:
optionGroup- TheOptionGroupto add.recursive- If true, add recursively to subgroups.
-
addAbstractOption
private void addAbstractOption(AbstractOption abstractOption)
Adds anAbstractOptionto this specification.- Parameters:
abstractOption- TheAbstractOptionto add.
-
mergeGroup
private OptionGroup mergeGroup(OptionGroup group)
Merge an option group into the spec.- Parameters:
group- TheOptionGroupto merge.- Returns:
- The merged
OptionGroupfrom 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- TheOptionGroupto 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 levelOptionGroupto 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 optionsOptionGroupto 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 optionsOptionGroupto 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- TheTurnto 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
BuildingTypefound.
-
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
Disasterfound.
-
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
Eventfound.
-
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
FoundingFatherfound.
-
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- TheGoodsTypeto 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
GoodsTypefound.
-
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
TileImprovementTypefound.
-
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
NationTypefound.
-
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
Nationfound.
-
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
ResourceTypefound.
-
getRolesList
public java.util.List<Role> getRolesList()
Get all the available roles.- Returns:
- A list of available
Roles.
-
getRoles
public java.util.stream.Stream<Role> getRoles()
Get all the available roles as a stream.- Returns:
- A stream of available
Roles.
-
getRole
public Role getRole(java.lang.String id)
Get a role by identifier.- Parameters:
id- The object identifier.- Returns:
- The
Rolefound.
-
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
Roles.
-
getMilitaryRoles
public java.util.stream.Stream<Role> getMilitaryRoles()
Get the available military roles as a stream.- Returns:
- A stream of military
Roles.
-
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
Roles 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
Roles 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 ofRoles to look in, if null all roles are used.- Returns:
- The first
Rolefound 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
TileTypefound.
-
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
UnitChangeTypefound, 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- TheUnitTypeto change.- Returns:
- A list of
UnitChanges.
-
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- TheUnitTypeto change from.- Returns:
- The
UnitChangefound, 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- TheUnitTypeto change from.toType- TheUnitTypeto change to.- Returns:
- The
UnitChangefound, 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- ThePlayerto 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- TheNationTypeto 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- TheGoodsTypeto 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
UnitTypes 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
UnitTypes 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
UnitTypes.
-
getUnitTypesPurchasedInEurope
public java.util.List<UnitType> getUnitTypesPurchasedInEurope()
Get the unit types that can be purchased in Europe.- Returns:
- A list of Europe-purchasable
UnitTypes.
-
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
UnitTypes 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
UnitTypefound.
-
findType
public <T extends FreeColSpecObjectType> T findType(java.lang.String id, java.lang.Class<T> returnClass)
Find theFreeColSpecObjectTypewith the given identifier.- Type Parameters:
T- The actual return type.- Parameters:
id- The object identifier to look for.returnClass- The expectedClass.- Returns:
- The
FreeColSpecObjectTypefound.
-
newType
private <T extends FreeColSpecObjectType> T newType(java.lang.String id, java.lang.Class<T> returnClass)
Build a newFreeColSpecObjectTypewith given identifier and class.- Type Parameters:
T- The actual return type.- Parameters:
id- The identifier to look for.returnClass- The expectedClass.- Returns:
- The new
FreeColSpecObjectTypeor 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
FreeColSpecObjectTypes 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
FreeColSpecObjectTypes 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
FreeColSpecObjectTypes 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- TheAbstractOptionto 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- TheFreeColXMLWriterto 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- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
-
-