Hot Air About Water

Water is obviously an important chemical for any world to sustain life as we know it. It’s why so much of SagaSim’s world generation revolves around the distribution of water. Up to this point, we have oceans and inland lakes, but we’ve not discussed rivers, nor assignment of biomes. Both of these are influenced by climate, and biomes are also influenced by rivers. I will discuss how each is generated.

River Run

Let’s start by generating another new world, because that’s just so much fun. (You’ve probably gotten the impression by now that the world generation process is fairly disposable and I can make new ones quickly and easily. You’d be right!) Let’s start with the terrain and climate maps, since those will determine the behavior of the river generator.

[caption id=“attachment_57” align=“alignnone” width=“600”]terrain for river demo Terrain to be used for river demo.[/caption]

[caption id=“attachment_58” align=“alignnone” width=“600”]climate for river demo Climate map to be used for river demo.[/caption]

After the river generation process is run, the river map is stored as a single image, where blue pixels signify the presence of a river and black pixels signify… well, nothing. They aren’t important to the river map. When overlaid the terrain and climate maps, you can see the rivers pretty easily and the ways they flow should make logical sense:

[caption id=“attachment_59” align=“alignnone” width=“600”]terrain map with rivers Terrain map with rivers overlaid.[/caption]

[caption id=“attachment_60” align=“alignnone” width=“600”]climate map with rivers Climate map with rivers overlaid.[/caption]

You can see how they flow down from high ground to low ground, either working toward the coast or toward the lowest point they can reach. Sometimes, multiple rivers will meet at the same low point and join together. Sometimes, a river may flow around a low level long enough to create a lake. So, how are they actually generated?

It begins by selecting a pixel–any pixel–from the climate map. Each climate is either considered rainy or not. A river can only begin on a rainy climate, so the randomly-chosen pixel is checked, and if it falls on a rainy climate, then it is considered a valid starting point for our river. Then, the river generation process begins. The pixels surrounding our chosen starting point are examined. If any of the surrounding pixels are lower than the current one, they are added to the list of possible successor pixels. Out of that list, the generator always picks the lowest one available. If two or more pixels are tied for the lowest, one is chosen at random. Then, the process is run again from the next pixel. This is done a set number of times, based on the following formula:

river length < (width * height * 0.005)

Given our existing map dimensions (600x465), each river will run for up to 1395 pixels. That may sound like a lot, but bear in mind that once a river reaches the ocean, it has nowhere else to go, and once it reaches its lowest point, it will simply pool around that. Rivers can never climb uphill. The length limiter is admittedly arbitrary. One could generate much longer rivers by making that number larger. I’ve found that 0.001 makes them too short, but 0.005 produces lengthy yet not overwhelming rivers.

This process is run to generate a set number of rivers. I use 100 as a default, but it’s a user-defined option so you can have as many or as few as you like.

Intro to Biomatics

Biomes are easily the most complex part of the world generation, because they bring together all the other elements we’ve created so far: terrain, climate, and rivers. The available biome types are:

  * Tundra
  * Taiga
  * Montane Grass/Shrubland
  * Temperate Coniferous Forest
  * Temperate Broadleaf Forest
  * Tropical Coniferous Forest
  * Mixed Forest
  * Coastal Forest
  * Tropical Broadleaf Forest
  * Temperate Grassland/Savanna/Shrubland
  * Tropical Grassland/Savanna/Shrubland
  * Desert
  * Flooded Grassland/Savanna
  * Riparian
  * Wetland

Each biome type is associated with one or more climate types and one or more terrain types. For a given land pixel, the possible biome types are determined based on the terrain, climate, and whether any adjacent pixels are river or ocean pixels. In particular, riparian biomes must be adjacent to/on a river, and coastal forest biomes must be adjacent to an ocean. Once we have the list of possible biomes for this pixel, the logic is then very much like climate logic: surrounding pixels are examined for their biomes, and the biome generator will either pick one of those or (less likely) pick a random one from the possible biomes for this pixel. This produces a “banding” effect similar to the climate generator. Like the climate generator, the biome generator currently doesn’t wrap seamlessly at the left and right edges of the map. Unlike the climate generator, we only make a single pass to generate the biomes, rather than several. These issues will likely be corrected/modified at some point in the future, but they are sufficient for now.

The final biome map, with the rivers overlaid, looks like this:

[caption id=“attachment_61” align=“alignnone” width=“600”]biome map with rivers Biome map with rivers overlaid.[/caption]

The color key for the map is as follows:

  * **Tundra**
  * **Taiga**
  * **Montane Grassland/Shrubland**
  * **Temperate Coniferous Forest**
  * **Temperate Broadleaf Forest**
  * **Tropical Coniferous Forest**
  * **Mixed Forest**
  * **Coastal Forest**
  * **Tropical Broadleaf Forest**
  * **Temperate Grassland/Savanna/Shrubland**
  * **Tropical Grassland/Savanna/Shrubland**
  * **Desert**
  * **Flooded Grassland/Savanna**
  * **Riparian**
  * **Wetland**

These classifications are all based on the World Wildlife Federation’s terrestrial biome system. No sense reinventing the wheel here, right?

Believe it or not, at this point we’ve taken care of the basics of world generation. We have a planet with a terrain map, we’ve laid out its climate, waterways, and biomes, and now we’re ready to start populating it with forms of life: plants and animals! Those will be discussed next time.

Note: In the course of working on this entry, I realized there was a bug in the river generator, which I’ve since fixed, though the images were generated with the buggy version. Let them serve as a lesson that there are always improvements to be made. Future blog entries will use the corrected river generation algorithm.