
A description of the terraforming terrain

## Generating Full Heightmap

The full heightmap for the world is generated before the game even starts. In
this map each point represents the intersection of four pages (flat chunks)

The file `map.mpk.gz` contains:

```
[
  size:int,
  height:array of size*size float,
  erosion:array of size*size float,
  sediment:array of size*size float,
  water:array of size*size float
]
```

### World Shape

The landmass where we play is always surrounded by water, to achieve this the
basic shape is raised above 0 in the center, and below 0 in the extremes.
Several shapes are possible, but the basic one is a gauss bell.

To this basic shape we aplly a number of octaves of noise; these provide the
general shape of the land.

### Wind Erosion

NOT IMPLEMENTED YET

Choose a random position in the world, and starting from there, blow in a
general east-west direction; as the simulation goes on, the particle gathers
moisture and sediment from the terrain. When simulation ends, drop the
remaining sediment and moisture back to the ground.

### Rain Erosion

Choose a random position in the world and starting from there, allow a particle
to fall through the world in a direction determined by the terrain normal;
again, the particle gathers moisture and sediment from the terrain, and when
simulation ends, the remaining sediment and moisture falls back to the ground

### Coastal Erosion

NOT DESIGNED YET

### Water propagation

After all erosion effects have been processed, we simulate rain again, but this
time instead of eroding the terrain we just build a water map; every point of
the grid where a water droplet moves through gets a small amount of water. this
produces a rough hydration map where the points with larger values are rivers
and lakes, points with average values are well-hydrated land, and points with
low values are arid zones.

## Generating Chunks

When a chunk is to be generated, the heightmap for each cell is determined by:

- averaging the heights, erosion, deposition and humidity values of the four
  closest corners

| value         | source |
|---------------|--------|
| bedrock       | height of solid stone |
| gravel        | loose material over stone |
| topsoil       | actual soil with vegetation over gravel |

The topsoil level is set to whatever the height map was.

In points where the deposition level is small enough (less than 0.1) gravel and
bedrock levels are the same as topsoil producing exposed rock.

In points where the erosion level is big enough (more than 0.75) there's no
topsoil, but there's a layer of gravel 4 blocks high

Otherwise, there are two levels of topsoil and two of gravel.
