Class 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.
    • 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().
      • AMPHIBIOUS_ATTACK_PENALTY_SOURCE

        public static final Specification.Source AMPHIBIOUS_ATTACK_PENALTY_SOURCE
      • defaultColors

        private static final java.util.Map<java.lang.String,​java.awt.Color> defaultColors
        A map of default nation colours.
      • 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
      • 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
      • EUROPEAN_NATION_TYPES_TAG

        private static final java.lang.String EUROPEAN_NATION_TYPES_TAG
        See Also:
        Constant Field Values
      • FOUNDING_FATHERS_TAG

        private static final java.lang.String FOUNDING_FATHERS_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
      • RESOURCE_TYPES_TAG

        private static final java.lang.String RESOURCE_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
      • 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 given FreeColXMLReader.
        Parameters:
        xr - The FreeColXMLReader 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 given InputStream.
        Parameters:
        in - The InputStream 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 - The InputStream 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 of FreeColModFiles 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 optional Advantages 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 optional Advantages setting.
        difficulty - An optional difficulty level OptionGroup.
      • 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 a FreeColSpecObjectType 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 a FreeColSpecObjectType by id and class.
        Type Parameters:
        T - The actual return type.
        Parameters:
        id - The object identifier to look for.
        returnClass - The expected Class.
        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 - The FreeColSpecObjectType 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 - an Ability 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 Abilitys.
      • addModifier

        public void addModifier​(Modifier modifier)
        Add a modifier.
        Parameters:
        modifier - The Modifier 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 Modifiers.
      • addTestFather

        public void addTestFather​(FoundingFather ff)
        Add a father, for test purposes.
        Parameters:
        ff - The FoundingFather 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 interface OptionContainer
        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 interface OptionContainer
        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 an OptionGroup.
        Specified by:
        getOptionGroup in interface OptionContainer
        Parameters:
        id - The object identifier.
        Returns:
        The OptionGroup value.
      • addOptionGroup

        private void addOptionGroup​(OptionGroup optionGroup,
                                    boolean recursive)
        Adds an OptionGroup to this specification.
        Parameters:
        optionGroup - The OptionGroup to add.
        recursive - If true, add recursively to subgroups.
      • addAbstractOption

        private void addAbstractOption​(AbstractOption abstractOption)
        Adds an AbstractOption to this specification.
        Parameters:
        abstractOption - The AbstractOption to add.
      • mergeGroup

        private OptionGroup mergeGroup​(OptionGroup group)
        Merge an option group into the spec.
        Parameters:
        group - The OptionGroup to merge.
        Returns:
        The merged OptionGroup from this Specification.
      • 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 - The OptionGroup 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 level OptionGroup to apply.
      • 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 options OptionGroup 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 options OptionGroup 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 - The Turn 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 - The GoodsType 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()
      • 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 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 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 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 of Roles 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 - The UnitType to 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 - The UnitType 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 - The UnitType to change from.
        toType - The UnitType 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 teacher UnitType.
        typeStudent - the student UnitType.
        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 - The Player 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 - The NationType 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 - The GoodsType 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 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 UnitType found.
      • findType

        public <T extends FreeColSpecObjectType> T findType​(java.lang.String id,
                                                            java.lang.Class<T> returnClass)
        Find the FreeColSpecObjectType with the given identifier.
        Type Parameters:
        T - The actual return type.
        Parameters:
        id - The object identifier to look for.
        returnClass - The expected Class.
        Returns:
        The FreeColSpecObjectType found.
      • newType

        private <T extends FreeColSpecObjectType> T newType​(java.lang.String id,
                                                            java.lang.Class<T> returnClass)
        Build a new FreeColSpecObjectType with given identifier and class.
        Type Parameters:
        T - The actual return type.
        Parameters:
        id - The identifier to look for.
        returnClass - The expected Class.
        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 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 - The AbstractOption 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 - The FreeColXMLWriter 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 - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems reading the stream.
      • getXMLTagName

        public java.lang.String getXMLTagName()