Random map generation (wilderness tiles)

I shall comment here the way maps that can be visited directly from the wilderness are generated. It's not about towns (they have been described in a separate article), but plain forest maps and such.

An obvious way to create a forest

The most intuitive way to generate a random forest is by cycling through all the map's tiles and randomly placing trees on them (based on a given percentage, which may vary according to the forest's thickness). The result is a uniform area consisting of certain percentages of grass and trees. While it's easy to both grasp and implement, the resulting map is very boring. The following sample image has been made with 20% trees, 80% grass tiles.

As you can see, the map can be described using a single word: boredom. However, such an uninteresting look can be changed. I've used two ways to do so.

Making the forest more interesting

First of all, one must realize that a forest does not consist only of grass and trees. The early screenshot of a forest placed in the Screenshots section of the site is an example: it contains two tree types (pines and oaks), some (few) of them dead. Apart from that, rocks and shrubs are randomly placed on the map (they are more scarce than the trees, obviously, since they're just decoration, not a real map element). That is a step forward, but the map is still rather uninteresting to look at.

Making the forest even more interesting

Take a look at this screenshot.

As you can see, there are some areas with more tree density as well as others with nearly (or absolutely) none, in other words, forest clearings. Shrubs and rocks are present as well, making this forest map much more interesting to explore (or at least to look at).

Now, how can such an effect be achieved? It's quite simple, actually. When generating the map, a 2d array of one byte integers is created, its dimensions equal to the map's. Using a noise generator (in this case, Fractional Brownian Motion, or FBM), values ranging from 0 to 100 are assigned for each byte of the mentioned array. They express a per cent chance to place a tree there. When the percentage is higher in an area, more trees will be generated there. When it's low or zero, it will become a clearing.

Versatilization of the algorithm

The described way of generating maps is versatile enough to become usable in case of other wilderness tiles, not only forests. In UR, the function takes as an argument the wilderness tile type it will be created on. Based on that argument, four variables representing different map tiles are created. For example, in case of a pine forest, these are: ground = TILE_GRASS, basic = TILE_TREE_PINE, rare1 = TILE_SHRUB, rare2 = TILE_ROCK.

Now, for each cell a random number from 0 to 100 is generated and compared to this cell's population per cent chance. If the check succeeds, a "basic" tile (a tree) is placed there. If not, another check is made: one out of 50 chance of placing a "rare1" tile. If it fails, an identical check is made for "rare2" tile. If all checks fail (which is the majority of the cases), the cell is filled with the "ground" tile.

The basic guidelines for this method are: "ground", "rare1" and "rare2" tiles should be passable and transparent, while "basic" tiles may or may not be transparent and/or passable. For example, a "plains" map would be (in this order: basic, rare1, rare2, ground): TILE_GRASS, TILE_SHRUB, TILE_ROCK, TILE_DIRT, while a "mountains" map would be: TILE_BOULDER, TILE_ROCK, TILE_SHRUB_DEAD, TILE_DIRT.

Other ideas

Apart from the basic algorithm roughly presented above, there may be a given chance of placing other features on the map as well. An abandoned hut, some ruins, a stream, a lake or a swamp might work out well and enrich the otherwise boring map. Such features, when added, should be able to turn an uninteresting part of the game into something really worth exploring.

Sample maps

Take a look at these sample maps generated with the basic "one-size-fits-all" algorithm (no special features).


plains


mountains


tundra