Town Generation

Started by
2 comments, last by Tereth 10 years, 6 months ago

I am having trouble making a suitable Town Generating Algorithm. I'm making a dungeon crawler/survival game in which the player encounters towns along their journey that are built on the pseudo-randomly generated maps. It get's pretty boring when every town has the same basic pattern as well, it doesn't reflect the different cultures in the game. I've looked at some materials on random town generation and I've been extremely underwhelmed. That's probably because I don't know where to look. Can anyone point me to some good resources or have any advice on this topic?

Advertisement

What style are you looking for? I would probably start by generating the street layout and then placing buildings based on plot size... I don't know of many articles though... read a few a while ago and will look around for them, but in the meantime maybe that will be a helpful starting point^^;

I collaborated in a project called Descensor, which was left half finished about 10 years ago. You can see the results here. I originally came up with the general structure of the code, and then a couple of friends of mine worked for several months implementing the details of the actual design (one of them was an architect).

The general idea (my contribution) is pretty simple. You start with a pseudo-randomly generated terrain, which is something like a noise function which can be sampled anywhere, a polygon on the ground and a number to be used as the [64-bit or 128-bit] seed for pseudo-random numbers. The task is "build a city on this polygon". A few random points inside the polygon are chosen as important squares, joined by avenues, and the resulting polygons surrounded by avenues are neighborhoods. Now the problem is reduced to several instances of "build a neighborhood on this polygon". Each neighborhood gets its own seed as well (and this is important). Neighborhoods are similarly divided into city sections, sections into blocks, blocks into plots and plots into buildings (or parks). Only two types of building were implemented in Descensor (a tower block and a traditional building around a patio, which shows up in many cultures). You can keep decomposing design problems into subproblems until the problem is simple enough that you can just write down the geometry ("build a wall here", or "build a flight of stairs there").

One neat thing about this way of proceeding is that the whole scene can be seen as a tree and can be generated dynamically when needed. Since every node in the tree has its own seed, you can forget about some part of the tree and regenerate it when needed. With a culling algorithm you only need to generate the parts of the city that you can see from where the camera is standing (so if there is a neighborhood entirely outside the view frustum you don't generate it at all).

You can also edit specific nodes in the scene, by deciding some properties (say, height of a building) and how it is decomposed into simpler elements, skipping the procedural part. These edited nodes are stored in a hash table, which is indexed by the random seed. The generating algorithm will check if the seed is in this table before generating the node procedurally. So you can now take a pseudo-random scene, navigate it, change what you want, perhaps even place purely human-designed sections (say, a cathedral) where something important might happen, and then the description of the scene is limited to the top-level seed and the list of human-designed nodes. This makes it possible to distribute enormous maps in an MMORPG, for example, by distributing very small files.

The project got to the point where I think it validated that the idea was sound, but it was never incorporated into any games or anything, and it was never polished enough to make a really cool demo, although I think that wouldn't take too much effort from where the project was abandoned.

@Ryutenchi: I appreciate the response and the idea. That's a lot of what I have seen in my search. I was looking for more complex city types.I'm basically looking for a modular city/town planning algorithm that can express the different cultures of the game just by adjusting the parameters. In fact, most of my game works off of the same principle for dungeon generation, character generation and biome creation, however, making a city/town, I have found is very tricky. For example, I want to make a tribal faction's cities look disorganized, but yet in clusters of families. Whereas, I want more civilized factions to have cities that are more organized, with zoning and must more of the grid-like organization. As well, much of the towns encountered are not huge metropolises, but rather hamlets of ranging from 10-50 people and I would like to have each one, even if they are apart of the same faction, look and feel like a unique settlement.

@Alvaro


The general idea (my contribution) is pretty simple. You start with a pseudo-randomly generated terrain, which is something like a noise function which can be sampled anywhere, a polygon on the ground and a number to be used as the [64-bit or 128-bit] seed for pseudo-random numbers. The task is "build a city on this polygon". A few random points inside the polygon are chosen as important squares, joined by avenues, and the resulting polygons surrounded by avenues are neighborhoods. Now the problem is reduced to several instances of "build a neighborhood on this polygon". Each neighborhood gets its own seed as well (and this is important). Neighborhoods are similarly divided into city sections, sections into blocks, blocks into plots and plots into buildings (or parks). Only two types of building were implemented in Descensor (a tower block and a traditional building around a patio, which shows up in many cultures). You can keep decomposing design problems into subproblems until the problem is simple enough that you can just write down the geometry ("build a wall here", or "build a flight of stairs there").

One neat thing about this way of proceeding is that the whole scene can be seen as a tree and can be generated dynamically when needed. Since every node in the tree has its own seed, you can forget about some part of the tree and regenerate it when needed. With a culling algorithm you only need to generate the parts of the city that you can see from where the camera is standing (so if there is a neighborhood entirely outside the view frustum you don't generate it at all).

This is such a cool idea! I wish I could give you 20 thumbs up! I could definitely use something like this for larger towns. For the past few hours, I have been trying to see if I can use graph theory to build a minimum spanning tree between nodes in the city to develop the central paths of the town and then radiate paths from the central tree for peripheral homes. The nodes being key points in the town's economy (i.e. farms, mine, place of government), which I would place according the the culture/economic focus of the town. Let's see if this works out.

I may PM you at a later time about the referenced idea, if you don't mind. I really appreciate your response!

Also, I am still open to more ideas!

This topic is closed to new replies.

Advertisement