Saturday, March 3, 2012

Project Forge: World Generation and Town Seeding

Over the past few weeks, I have shifted design focus away from engine components and more onto the procedural generation components of the Forge. I have yet to make the decision on whether or not to use a graphics engine for Forge, or to use something lower-level like openGL.

Anyways the first procedural component I pumped out was a terrain generator. Right now it's nothing special and is just a placeholder until I can iron out all of the details. For the purpose of debugging and working on other features I'm using a 4km by 4km map, however in the future that will probably scale up to something much bigger like 16km by 16km, as long as memory restrictions allow. The placeholder terrain generator actually doesn't look all that bad, and because of how it works, some natural artifacts show up that may pass off as rivers at a later stage in development.
The brighter the blue color, the higher the pixel is from sea-level.

The next item on the itinerary was resource and town seeding. Each town would be seeded on areas of very high natural resource concentration, something I expected would normally happen for towns in real life. Several different resource maps were generated, each of which with their own unique density and spread. This is supposed to mirror how in real life, certain resources like fertile ground may be pervasive for many miles, however resources such as precious metals may only have deposits a few meters wide. Since the NPCs founding towns aren't supposed to be omniscient, they will only recognize areas as having a specific resource if the concentration of that resource passes a specific threshold. For example, an NPC would only recognize an area as having iron deposits because the concentration of iron in the local area is so dense that rocks of hematite or magnetite are found on the surface.
Example of a resource map for Iron. Areas of solid blue are where  traces of the metal are visible on the surface.
The average of these resource maps is taken, and a threshold is applied to the new cumulative map, symbolizing areas where potential settlers would recognize that there are plenty of local resources.
Each blue pockets represents an area with an unusually high resource concentration
For each of these high-density resource pockets, a town is founded. The next step was to connect these towns with roads, a process which turned to be much more painful than I had expected and added over 1000 lines of code to the project. 3 weeks and several cans of coffee later, I found the best solution for generating roads to be the use of Dijkstra's algorithm with a set of cost constraints based on how hard it is to travel through a certain area.
Red dots represent towns, green lines are roads.
Blue background is the cost map, with ligther blue having a higher cost.
For the pathfinding cost map, I did a threshold where if a pixel was deemed to be neigh-impossible to travel through (mountains, swamps, rivers,  etc), then the road would avoid traveling through it at all costs. However in some situations these areas must be crossed because there is no way around, in which case there will have to be bridges, massive elevators (I can dream), or stonework roads required to pass through. In the future it may be possible for NPCs to create their own roads after the initial batch in order to supplement the current system, but speculating that far down the development like probably isn't that good of an idea. 

That's it for this update. Next up in the queue is NPC generation and simulation, which is starting to look like a very interesting component to develop.

-zalzane

No comments:

Post a Comment