Updated Resources: spread functions (markdown)

Azgaar 2021-05-10 21:05:21 +03:00
parent 08fcc6a8a5
commit 657d8b6368

@ -1,49 +1,30 @@
# 🚧 Under construction. The described functionality is not ready
# 🚧 Under construction
Resource **spread models** are bits of JavaScript code applied for cell to check whether resource can or cannot be placed there. Fantasy Map Generator allows to create custom models, but they are not verified and can easily break the application. Someone else's code can be potentially be harmful as well. Please apply custom spread functions only if you know programming basics. Trusted and useful functions will be listed on this page.
Resource **spread models** are JavaScript functions applied to check whether resource can or cannot be placed in a cell. Fantasy Map Generator allows to create custom spread models, but it requires some understanding on how functions work.
# Technical info
Technically spread models are functional expressions evaluated for each cell to return a Boolean: `true` indicates that resource can be placed in cells and `false` indicates the opposite. The expressions are vanilla JS function, you can use any logical operators (`!` for not, `||` for OR, `&&` for and etc.) and other features.
Technically spread models are functional expressions evaluated for each cell to return `true` or `false`. If `true` is returned, the resource can be placed in the cell. The expressions are valid JS, you can use logical operators (`!` for not, `||` for OR, `&&` for and, etc.) and other features.
Build-in functions make models syntax easier to read:
* `habitable()`: true if biome habitability >0
However the function is limited to a number of build-in functions. These functions make models syntax easier to read and write:
* `random(number)`: percentage of true, e.g. `50` will return true in 50% of cases
* `nth(number)`: true for each nth cell only, e.g. `nth(2)` skips 50% of cells, `nth(5)` skips 80% of cells
* `habitable()`: true if biome habitability is greater than 0
* `habitability()`: check against biome habitability. Always true for habitability `>=100`, false for `0`, skips 50% of cells if habitability is `50` and so on
* `biome(biomeId, biomeId, ...)`: check against biome id, see below to get biome id reference
* `elevation()`: check against cell's height - the higher cell is, the greater chance is. If you need resource to be more frequent in lower elevation areas, than just negate the function: `!elevation()`
* `biome(biomeId, biomeId, ...)`: check against list of biome ids, see below to get biome id reference
* `minHeight(number)`: true if cell height >= number. Number is in range `[0-100]`, where `0` is deep ocean and `20` is minimal land elevation
* `maxHeight(number)`: true if cell height <= number
* `minTemp(number)`: true if cell temperature (in Celsius) >= number
* `maxTemp(number)`: true if cell temperature <= number
* `shore(ringId, ringId, ...)`: check against cell distance to shore, where `1` is land next to water (coastline cells), `2` - next land ring, `-1` - water cells next to land (shallow water), `-2, -3, ...` - next water rings, `0` - value not assigned, usually values are assigned only for first 2 land rings, so other land cells have zero value
* `type(string, string, ...)`: check against cell type. Types of all water cells connected to map border is `ocean`, lake types are `freshwater`, `salt`, `sinkhole`, `frozen`, `lava` and `dry`. Land types are defined not so clear, so I don't recommend to use them. In any case land types are `continent`, `island`, `isle` and `lake_island`
* `nth(number)`: true for each nth cell only, e.g. `nth(2)` skips 50% of cells, `nth(5)` skips 80% of cells
* `random(number)`: percentage of true, e.g. `50` will return true in 50% of cases
* `river()`: true if there is a river in the cell
# Examples
Let's say we want a resource to be generated in hot and highly elevated areas. If altitude is medium, let it also be allowed, but pretty rarely. The model will be something like `minTemp(15) && (minHeight(70) || minHeight(40) && nth(5))`.
-----
const fn = new Function("i", "minTemp(15) && (minHeight(70) || minHeight(40) && nth(5))");
fn(i);
Default biome ids:
* 0: Marine
* 1: Hot desert
* 2: Cold desert
* 3: Savanna
* 4: Grassland
* 5: Tropical seasonal forest
* 6: Temperate deciduous forest
* 7: Tropical rainforest
* 8: Temperate rainforest
* 9: Taiga
* 10: Tundra
* 11: Glacier
* 12: Wetland
To get actual biome id run `biomesData.name.map((n,i) => `${i}: ${n}`)` in FMG console (F12).
See the section below to review default models, it should make it pretty clear how to define custom ones.
# Default models
# Built-in models
* `Deciduous_forests: i => [6, 7, 8].includes(cells.biome[i]),`
* `Any_forest: i => [5, 6, 7, 8, 9].includes(cells.biome[i]),`
* `Temperate_and_boreal_forests: i => [6, 8, 9].includes(cells.biome[i]),`
@ -70,3 +51,22 @@ See the section below to review default models, it should make it pretty clear h
* `Less_habitable_seashore: i => cells.t[i] === 1 && chance([0, 50, 30, 30, 20, 10, 10, 20, 10, 20, 10, 0, 5][cells.biome[i]]),`
* `Less_habitable_biomes: i => chance([5, 80, 30, 10, 20, 5, 5, 5, 5, 30, 90, 0, 5][cells.biome[i]]),`
* `Arctic_waters: i => cells.t[i] < 0 && temp(i) < 8`
# Biomes ids
Default biome ids:
* 0: Marine
* 1: Hot desert
* 2: Cold desert
* 3: Savanna
* 4: Grassland
* 5: Tropical seasonal forest
* 6: Temperate deciduous forest
* 7: Tropical rainforest
* 8: Temperate rainforest
* 9: Taiga
* 10: Tundra
* 11: Glacier
* 12: Wetland
To get actual biome id run `biomesData.name.map((n,i) => `${i}: ${n}`)` in FMG console (F12).