Prototype/NamedNoiseExpression

From Official Factorio Wiki
Jump to navigation Jump to search

Prototype definitions » PrototypeBase » Prototype/NamedNoiseExpression


A NoiseExpression together with a name.

The base game uses named noise expressions to specify functions for many map properties to be used in map generation; e.g. the "elevation" expression is used to calculate elevation for every point on a map. For a list of the built-in named noise expressions, see Data.raw#noise-expression.

Named noise expressions can be used by MapGenSettings and Types/MapGenPreset to override which named expression is used to calculate a given property by having an entry in property_expression_names e.g. elevation = "0.16-elevation".
Alternate expressions can be made available in the map generator GUI by setting their intended_property to the name of the property they should override.
Named noise expressions can also be used by noise variables, e.g. noise.var("my-named-expression").


Prototype/NamedNoiseExpression — noise-expression
expression::NoiseExpression
intended_property::string (optional)
Inherited from PrototypeBase
name::string
type::string
localised_description::LocalisedString (optional)
localised_name::LocalisedString (optional)
order::Order (optional)

Mandatory properties

Inherits all properties from PrototypeBase.

expression

Type: NoiseExpression
The noise expression itself. This is where most of the noise magic happens.

Optional properties

intended_property

Type: string
Names the property that this expression is intended to provide a value for, if any. This will make the expression show up as an option in the map generator GUI, unless it is the only expression with that intended property, in which case it will be hidden and selected by default.

Note that the "Map type" dropdown in the map generation GUI is actually a selector for "elevation" generators. If generators are available for other properties, the "Map type" dropdown in the GUI will be renamed to "elevation" and shown along with selectors for the other selectable properties.

For example if a noise expression is intended to be used as an alternative temperature generator, intended_property should be "temperature". The base game uses the intended_properties elevation, temperature, moisture and aux. For how the named noise expression with those intended_properties are used in the base game see the notable named noise expression list on Types/NoiseExpression#variable. Mods may add any other intended_property or modify the existing noise expressions to change/remove their intended properties. Furthermore, mods may remove the use of those named noise expressions from the map generation code or change what they affect.

order

See PrototypeBase#order

Used to order alternative expressions in the map generator GUI. For a given property (e.g. 'temperature'), the NamedNoiseExpression with that property's name as its intended_property with the lowest order will be chosen as the default in the GUI.

If no order is specified, it defaults to "2000" if the property name matches the expression name (making it the 'technical default' generator for the property if none is specified in MapGenSettings), or "3000" otherwise. A generator defined with an order less than "2000" but with a unique name can thereby override the default generator used when creating a new map through the GUI without automatically overriding the 'technical default' generator, which is probably used by existing maps.

Examples

intended_property in the base game

The base game defines two named noise expressions that have the intended_property "elevation" so that are selectable via the "Map type" dropdown (which actually selects elevation generators):

local noise = require("noise")
data:extend{
  {
    type = "noise-expression",
    name = "elevation",
    intended_property = "elevation",
    expression = noise.var("0_17-lakes-elevation") -- "0_17-lakes-elevation" is another named noise expression. Noise variables may reference named noise expressions.
  },
  {
    type = "noise-expression",
    name = "0_17-island",
    intended_property = "elevation",
    -- A large island surrounded by an endless ocean
    -- expression =  ...
  }
}

Custom intended_property

Mods can define any intended_property with any name. This examples aims to show what this is useful for.

A noise variable can reference a named noise expression, so by defining the "test" named noise expression, noise.var("test") may be used in other noise expressions. Intended_property allows to override what the variable references: With the example, if "more-test" is selected in the dropdown in the map generator GUI, its #expression (noise.ridge(noise.var("y"), -10, 6) will provide the value for the noise variable "test" instead.
For easy demonstration, that value is assigned to the "elevation" named noise expression, so changing the "test" generator changes the noise.var("test") which in turn is used by the "elevation" named noise expression. The "elevation" noise variable is used by water generation, so changing the test generators is immediately visible in the map generation preview.
Note that the player can select the "Island" elevation generator in the Elevation dropdown (previously named Map type), which means the 0_17-island named noise expression is selected and noise.var("test") isn't used anymore so changing the test generator no longer has an effect.

local noise = require("noise")

data:extend{
  {
    type = "noise-expression",
    name = "test",
    intended_property = "test",
    expression = noise.ridge(noise.var("x"), -80, 8),
  },
  {
    type = "noise-expression",
    name = "more-test",
    intended_property = "test", -- override the "test" noise variable when selected by the player
    expression = noise.ridge(noise.var("y"), -10, 6),
  }
}

data.raw["noise-expression"]["elevation"].expression = noise.var("test") -- the noise variable "test"