Skip to content

Resources: spread functions

Azgaar edited this page May 8, 2021 · 20 revisions

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.

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.

Build-in functions make models syntax easier to read:

  • nth(number): true for each nth cell only, e.g. nth(2) will skip 50% of cells
  • biome(biomeId, biomeId, ...): check against biome id, see below to get 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(number): 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

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

  • 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]),
  • Hills: i => cells.h[i] >= 40 || (cells.h[i] >= 30 && !(i % 10)),
  • Mountains: i => cells.h[i] >= 60 || (cells.h[i] >= 40 && !(i % 10)),
  • Mountains_and_wetlands: i => cells.h[i] >= 60 || (cells.biome[i] === 12 && !(i % 8)),
  • Headwaters: i => cells.h[i] >= 40 && cells.r[i],
  • Biome_habitability: i => chance(biomesData.habitability[cells.biome[i]]),
  • Marine_and_rivers: i => (cells.t[i] < 0 && ["ocean", "freshwater", "salt"].includes(group(i))) || (cells.t[i] > 0 && cells.t[i] < 3 && cells.r[i]),
  • Pastures_and_temperate_forest: i => chance(100 - cells.h[i]) && chance([0, 0, 0, 100, 100, 20, 80, 0, 0, 0, 0, 0, 0][cells.biome[i]]),
  • Tropical_forests: i => [5, 7].includes(cells.biome[i]),
  • Arid_land_and_salt_lakes: i => chance([0, 80, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10][cells.biome[i]]) || group(i) === "salt" || group(i) === "dry",
  • Deserts: i => cells.biome[i] === 1 || cells.biome[i] === 2,
  • Grassland_and_cold_desert: i => cells.biome[i] === 3 || (!(i % 4) && cells.biome[i] === 2),
  • Hot_biomes: i => [1, 3, 5, 7].includes(cells.biome[i]),
  • Hot_desert_and_tropical_forest: i => [1, 7].includes(cells.biome[i]),
  • Tropical_rainforest: i => cells.biome[i] === 7,
  • Tropical_waters: i => cells.t[i] === -1 && temp(i) >= 18,
  • Hilly_tropical_rainforest: i => cells.h[i] >= 40 && cells.biome[i] === 7,
  • Subtropical_waters: i => cells.t[i] === -1 && temp(i) >= 14,
  • Habitable_biome_or_marine: i => biomesData.habitability[cells.biome[i]] || cells.t[i] === -1,
  • Foresty_seashore: i => cells.t[i] === 1 && [6, 7, 8, 9].includes(cells.biome[i]),
  • Boreal_forests: i => chance([0, 0, 0, 0, 0, 0, 20, 0, 20, 100, 50, 0, 10][cells.biome[i]]),
  • 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
Clone this wiki locally