Prototype/NamedNoiseExpression: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
m (fixed link)
(Added examples for intended_property)
Line 2: Line 2:
A [[Types/NoiseExpression|NoiseExpression]] together with a name.
A [[Types/NoiseExpression|NoiseExpression]] together with a name.


Named noise expressions are used to specify functions for elevation, temperature, moisture, aux, and cliffiness; e.g. the "elevation" expression is used to calculate elevation for every point on a map.
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]].


[http://lua-api.factorio.com/latest/Concepts.html#MapGenSettings MapGenSettings] can override which named expression is used to calculate a given property by having an entry in  
Named noise expressions can be used by [http://lua-api.factorio.com/latest/Concepts.html#MapGenSettings MapGenSettings] and [[Types/MapGenPreset]] to override which named expression is used to calculate a given property by having an entry in <code>property_expression_names</code> e.g. <code>elevation = "0.16-elevation"</code>.<br>
<code>property_expression_names</code> e.g. <code>elevation = "0.16-elevation"</code>. Alternate expressions can be made available in the map generator GUI by setting their <code>intended_property</code> to the name of the property they should override.
Alternate expressions can be made available in the map generator GUI by setting their <code>intended_property</code> to the name of the property they should override.<br>
Named noise expressions can also be used by [[Types/NoiseExpression#variable|noise variables]], e.g. <code>noise.var("my-named-expression")</code>.


{{Prototype TOC|noise-expression}}
{{Prototype TOC|noise-expression}}
Line 13: Line 14:


{{Prototype property|expression|[[Types/NoiseExpression|NoiseExpression]]}}
{{Prototype property|expression|[[Types/NoiseExpression|NoiseExpression]]}}
The expression itself.
The noise expression itself. This is where most of the noise magic happens.


== Optional properties ==
== Optional properties ==
Line 22: Line 23:
intended property, in which case it will be hidden and selected by default.
intended property, in which case it will be hidden and selected by default.


For example if a noise expression is intended to be used as an alternative temperature generator, <code>intended_property</code> should be "temperature".
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, <code>intended_property</code> 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 ===
=== order ===
Line 36: Line 40:
can thereby override the default generator used when creating a new map through the GUI without automatically overriding
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.
the 'technical default' generator, which is probably used by existing maps.
== Example ==
=== 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):
<syntaxhighlight lang="lua">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 =  ...
  }
}
</syntaxhighlight>
=== Custom intended_property ===
Mods can define any intended_property with any name. This examples aims to show what this is useful for.
A [[Types/NoiseExpression#variable|noise variable]] can reference a named noise expression, so by defining the "test" named noise expression, <code>noise.var("test")</code> may be used in other [[Types/NoiseExpression|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]] (<code>noise.ridge(noise.var("y"), -10, 6</code>) will provide the value for the noise variable "test" instead.<br>
For easy demonstration, that value is assigned to the "elevation" named noise expression, so changing the "test" generator changes the <code>noise.var("test")</code> 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.<br>
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 <code>noise.var("test")</code> isn't used anymore so changing the test generator no longer has an effect.
<syntaxhighlight lang="lua">
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"
</syntaxhighlight>

Revision as of 14:31, 9 September 2020

Template:Prototype parent 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").

Template:Prototype TOC

Mandatory properties

Inherits all properties from PrototypeBase.

Template:Prototype property The noise expression itself. This is where most of the noise magic happens.

Optional properties

Template:Prototype property 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.

Example

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"