ID:39230
 
Keywords: demo, maps
Source code: http://www.byond.com/members/DreamMakers/files/ gughunter.2008%2D0215/ArchipelagoGenerator_src.zip

Introduction

The Archipelago Generator was originally (and still is) a component of an unfinished project, Seven Bits of Eight, a game about the age of Caribbean piracy. It's meant to be a "quick and easy" imitation of the far more complex random map generator in the classic video game Seven Cities of Gold. It is said that Seven Cities of Gold goes so far as to model plate tectonics in its random Earths, but the Archipelago Generator only aims for a proper balance of land and water, with reasonably plausible coastlines. The process is simple, and this article will describe it in detail so you can adapt it to your own needs.


Land Generation

The number of "seeds" is defined by the developer. Imagine each "seed" as a meteor that plummets into the ocean and deploys an army of "landbots." Once all seeds have splashed down, landbots randomly take turns making moves. A landbot can move in any of the four cardinal directions, and whenever it moves into a water turf, it builds land there. Once there is enough land to meet the world's desired land-to-water ratio, the landbots are destroyed.

If you look at the #define directives in the demo, you'll see that only the number of landbots per seed is declared explicitly. The amount of land in the world is expressed as a fraction of total turfs. The number of seeds that splash down is expressed as a fraction of the world's total area. This is to make the generation process "scalable" -- in other words, to make it produce comparable results regardless of the map size. But of course, there is more than one way to define scalable: it could mean that you generate islands of the same size but more of them, or it could mean that you generate the same number of islands, but they are larger. Ultimately there is no substitute for getting your hands dirty, plugging in some values, and doing test runs to see what kinds of maps result.

Since the landbots use a random walk, setting a higher number of landbots per seed tends to smooth out much of the "stringiness" that can result from a single roaming landbot; sooner or later, a lone landbot can get on a tear and scoot away from the landmass it's been creating, leaving a thin isthmus in its path (good luck reading that aloud). Deploying several in the same place tends to cancel out some of the noise, while still allowing for outliers that make for an interesting coastline.

This method does have some weaknesses that you should be aware of. With multiple landbots per seed, there is very little chance of water appearing near the seed, and conversely, the coastlines can get a little ragged. That's not necessarily bad, but it's not entirely realistic. Along the same lines, this method of map generation doesn't produce elevations or rivers -- though you could always write some code to generate them after the land is created. And it's worth mentioning that even if your tests produce terrific maps, the random nature of the generator makes it certain that it will produce a stinker now and again. (With some preparation, and Lummox JR's help, there is a way to avoid this -- read on.)


Ornamentation

Having generated all the land we can stand, it's time to decorate it. You'll notice that the oview() proc is heavily used; it's a quick way to generate a list of all the turfs (and any other objects) within a given distance of a single turf.

Shallows: This is just a graphical effect that makes water lighter when it's adjacent to the coastline. You could make this more realistic by choosing random places where the shallows extend further out into the ocean.

Rocks: They're rocks. I don't know what else to say. (Okay, how about this: in gameplay terms, rocks on the land could block movement, and rocks in the shallows could damage ships.)

Greenery: In real life, trees tend to congregate. This is sometimes due to human action like forestry and farming, but it's also due to the fact that, as the old saying goes, the acorn doesn't fall far from the tree. The greenery generator works by sprinkling some random trees around the map, and once the quota of random trees is met, all future trees can only grow adjacent to existing trees. (You could call the second round of trees "constrained random" trees.) This simple process works surprisingly well to create "belts" of vegetation. Watch out for the worst-case scenario, though, in which, through a low number of random trees or just sheer bad luck, small islands may never get a single random tree, and thus will remain permanently bare.

Clouds: It's worth taking a moment to consider that the clouds provide two valuable services, even if they never do anything but float there. First, they serve to break up the visual monotony of a broad expanse of water. Second, because of their high contrast with the water, they provide a more vivid sense of movement than the scrolling water itself can hope to -- particularly if the water is only one color, as in this demo.

Turtles: Sea turtles can appear either in the shallows or on sand adjacent to shallows. This example is worth remembering for your own creature types that have their own terrain preferences.


Items of Interest

If you think you might like to try this method of generating maps, but you're leery of exposing players to the occasional random clunker, please check out Lummox JR's recent article, Fire Your Level Designer (http://www.byond.com/members/ DreamMakers?command=view_post&post=38985). Following his examples, you can generate maps with random seeds and build up a library of "approved" maps. In an hour or two of test runs you can come up with a list of your favorites, and only let players visit maps generated by the seeds you've approved.

Tom of Dantom was kind enough to remind me of an existing project along similar lines, Dan's dungeon generator (http://www.byond.com/developer/Dan/maze). I'm pretty sure there are other good map-generators out there, too; if you know of one I've overlooked, feel free to link to it in the comments.

IainPeregrine has mentioned the possibility that the landbots could be transformed into riverbots. If a riverbot is placed on dry land, sufficiently removed from the ocean, it could probably generate rivers following a few simple rules. The rules he proposes (which are untested, but to me at least, they sound quite plausible) are:

1: The bot generally prefers to continue walking in the direction it is walking

2: The bot could weigh each direction based on how close the ocean is, and

3: The bot never puts down a river tile if one is adjacent (excepting the one he just came from).


Finally, I'd like to remind you that this is just a demo, and though it was written to achieve a specific effect (and the icons were drawn and colored accordingly), the techniques used in this demo may be useful far beyond the realm of 17th-century Caribbean piracy. Instead of generating islands, you might generate underground oil pools the players have to explore and drill for. You might switch water and land, and make the "landmass" a lake for a fishing game. Or you might make the land represent trees, and generate patches of forest with clear land between them. As is so often the case with BYOND (and life in general), the possibilities are limited only by your creativity.
That is really cool! I actually tried to make a map generator about eight years ago and it was awful. Yours makes some pretty nice looking terrains. I'd like to see a game built off this. Actually, if you combine it with Dan's generator (assuming it still works), you could probably recreate Ultima III/IV!
An interesting approach would be to make the "meteors" place several circular patches of land next to each other at random locations instead of random walkers to create smoother islands, if that makes any sense.
I made an island generator for a survival-type game I started a while ago. In addition to generating an island shape and a beach around the island, there was also a river, ground vegetation such as short grasses, and longer vegetation which would drop seeds, which could then be carried away by winds (the winds would also cause the grasses to wave). It was pretty cool.
Nice, I feel like making a graveyard with that program to help scatter bones and blood for certain events that may occur when a game of mine reboots (dungeon game anyone? >_> Well, when I stop being lazy/busy and get back to work on it).

As a side note, the Developer FAQ site no longer works, maybe it should link to the other wiki?
This article is especially useful to my current project - we had already developed a terrain generator by the time I found this, but some of the information is still very helpful.

Good job, Gug!