Biomes

As always, we can copy an existing biome to create our custom biome faster. Biome files are located in stonehearth/data/biome.

Adding the biome to the list

First, let's make an alias for our biome in our manifest:

  "aliases" : {
     "biome:silent_woods" : "file(data/biome/silent_woods.json)"
  }

Then, let's add the mixinto so that our biome appears in the list of available biomes:

  "mixintos" : {
     "stonehearth:biome:index" : "file(data/biome/index.json)"
  }

Our index.json mixinto file would look like this:

  {
     "biomes": {
        "silent_woods": "silent_woods:biome:silent_woods"
     }
  }

The key is a custom identifier for our biome, and the alias points to our biome alias preceded by the namespace of our mod plus a colon.

Biome info

The definition of biomes is divided into two files. The first one contains the basic information, and it's the one that we reference in our alias (in our example, silent_woods.json). The second one contains only the data related to the actual terrain generation (in our example, it would be silent_woods_generation_data.json).

The info files contain these fields:

The warning about the biome not being the preferred biome for the chosen kingdom will not appear for custom mods, only for the stonehearth one.

Biome generation data

The terrain generation is managed from stonehearth/services/server/world_generation/world_generation_service.lua, with help of all the other files inside the stonehearth/services/server/world_generation directory, although the actual work is done from the C++ side. The terrain itself is generated from stonehearth/data/service/game_creation_service.lua, once the game knows which biome / seed / etc. it has to use.

The terrain service takes care of things like territory and visibility (fog of war). The hydrology service manages the behavior or the water (when it should create waterfalls, the rate at which it should deplete, etc). There are also some related components.

The data used in the generation data files is extracted from the "generation_file" linked in the main biome file. Within it we can determine things like height of the terrain, depth of water, which plants and trees will appear in our custom biome, etc. Some mods override the Lua files that generate the terrain, to allow for a different terrain generation (by default it's based on a noise function). For example, the Archipelago mod, Sky Lands mod, and Rivers mod (which adds rivers to the terrain generation).

The temperate_generation_data.json file has more comments than the corresponding files of the desert and arctic biomes, so it's a good start. Many comments have "Def N", which is the default value for that parameter, if we made some mistake and need to revert back to a reasonable value, or min/max values, so that we don't try to add invalid values. If we add a mixinto to stonehearth/data/terrain/terrain_blocks.json adding more terrain types, we'll be able to use them in our biome as well.

Ideally we'll start defining the shape of the terrain, then adding the trees/plants that we want, and finally double checking any static scenario that we want / don't want our biome to have (such as bunny statues, critter nests, landmarks, etc).

If we used a wrong value in the generation files, an error will pop up in game when generating the map. Sometimes it won't fail there, but only with certain seeds so we can try rerolling the map a few times and see if anything's wrong. Some values might also be affected by other ones, so while they aren't wrong, they might cause issues depending on the other values.

In short, it is recommended to change the values one by one and test a lot, so that we know exactly which value is causing the problem, and how much effect did our last change have in the terrain generation.

Let's explain a bit the different fields that we can find in the generation file:

Here's the old Desktop Tuesday about biomes, and this is the one about the Northern Alliance and the arctic biome (after seasons and weather were introduced).

You can find more biome mods at the Steam Workshop here.