Woe! How ill a fate... for ’tis decreed that the Descent of Darkness shall mark the beginning of a new era... a time of hatred and contempt, of sorrow and despair. Thus spake the prophet Eréimul (Aesthurian translation of an excerpt from the Codex of Eréimul). |
In this article, I shall comment a way of creating interesting forests. By "forests" I do not mean large areas covered with trees and with grass in between, but rather any sort of non persistent map generated when visiting overworld tiles such as plains or mountains.
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 dull and extremely uninteresting to explore or even look at.
First of all, one must realize that a forest does not consist only of grass and trees. Various tree types may be used (like oaks and birches), some of them might be made dead. Apart from that, rocks and shrubs may be 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.
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). Please don't mind the varying ground colour, it's just an effect used by UR to make vast, uniform ground look less dull.
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.
Until now, we have only commented a way of generating forests, but the exact same algorithm can be used to create any type of wilderness map. You may solve the question your own way, but I think the one used in UR is quite effective. The method takes as an argument the tile type it is created for (pine forest, oak forest, plains, mountains, tundra, etc.). 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. Of course, you may use a different number of tiles.
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_ROCKYGROUND.
You may as well decide to put more features on your maps, you are not limited to varying tiles. The two ground colours used in UR provide a simple way of making vast grass/dirt/rock/whatever areas look interesting despite placing no features on them. Another possible addition are streams and rivers. This subject is covered in the article dedicated to rivermaking.
Some features may depend on the tile the map is created upon, for instance an abandoned mud hut could only appear on plains, a forest could hold a camp of contrabandists, while a mountainous area could sport a dwarven graveyard. This dependence can be solved the same way the tile choice is: based on the method's argument.
Finally, to make the article complete, I present a few sample images made using the technique described above.