Good late night,

I'd certainly like to learn more in regards to procedural generation. More specifically, I'd like to learn about generating a city with enterable buildings (that range from restaurants to retail store).

Are there any great article in regards to this? I have not been able to find too many decent ones. I realize that there are projects such as cataclysm dda (thanks ter13!) that are open source with this. But I'd actually want to know how to do it myself.
Well, generally speaking perlin noise is a great place to start for random generation.

Once you understand perlin noise, this advice will make way more sense to you: polygon-map-generation/

Generating your map, you'll want to use several diagrams for creating procedural worlds.

One diagram would be a simple heightmap. Afterward, you'd want to use a reflected linear gradient to determine temperature. Various methods exist to generate rainfall and drainage maps.

The precipitation and drainage maps should use the heightmap as input. Higher elevations will tend to get more precipitation than lower elevations, while nodes very near to the sea will get higher precipitation than those far inland. A spread map can be generated by creating alternating air currents which push outward from the sea northward or southward based on lattitude convection currents. This spread map can be used to aid in the generation of precipitation maps, allowing you to create lush valleys or arid regions blocked by mountains.

Currents that carry moisture will tend to drop it when elevation is high enough, so simply use mountains as a means of stopping air currents' spread of moisture.

These precipitation currents can also be used to create drainage maps, which will tend to flow down slopes. A blocked precipitation current will create a lake or resevoir in that region. A flowing precipitation current will create a stream, brook or river outward toward the sea.

Alright, now that we have temperature, drainage, rainfall, and elevation, we can start talking about biome maps.

Biome maps affect the type of vegetation you are going to encounter. High peaks will have little vegetation and soil, and will tend to generate rocky outcroppings. Hills and mountainsides will tend to be covered in foliage where the rainfall can reach them, and areas around rivers and lakes will also tend to be more lush than their surroundings.

^The above is a two-metric biome generator, which generates based on rainfall and temperature alone. You can use elevation as a second metric if you'd like.

Next we need to work on cities. Cities tend to be situated along the coast, near rivers, or near significant deposits of natural resources that humans are interested in exploiting. There are more complex reasons to develop cities too, like trade access, political reasons, and religious reasons, but typically, cities that are created without access to water and arable land just don't tend to last long.

Cities can be generated a few ways. You can use a voronoi diagram and then find the seed points as the epicenter of a city, or you can pre-generate a preset number of civilizations and randomly place them around the map, simulating them until all unviable cities have been destroyed and viable cities have grown to an acceptable size.

The voronoi method merely assigns a civilization factor for each pixel of the map between 0 and 1, where 0 is "wild country", and 1 is "metropolis". When generating specific cells of the map, you simply assign a likelihood of any particular cell being for a particular purpose based on the civilization factor of the point and moderated against the temperature, rainfall, and elevation factors. For instance, lush areas will tend to be more industrialized than arid areas, so you can decrease the likelihood of any buildings generating at all in an arid wasteland. Maybe you'll get a gas station or two or abandoned missile silo at best, but no chance for residences and convenience stores.

Building templates are basically just pre-generated rules for creating structures and what is often found inside of them. Assign a purpose and size to these structures upon creation and design them using geomorphs ( if you'd like, or some other method if you prefer.

Let's say at 0.0-0.6 civilization there is no chance of creating a structure at all.

At 0.6-0.75 there is a chance to create a boondock structure. Boondock structures would be like trailer parks, isolated country houses, truck stops, nature preserves, etc.

Then let's say at 0.75-0.8 civilization there is a chance of creating a suburban structure. A suburban structure would be mostly residential, neighborhoods, schools, strip malls, small restaurants, gas stations, etc.

At 0.8-0.9, there's a chance to create an urban structure. Urban structures would be apartment buildings, factories, department stores, etc.

At 0.9-1.0, there's a chance to create a capital structure. These capital structures would be like museums, luxury apartments, legal firms, hospitals, skyscrapers, etc.

Next step is to generate roads. Cities are usually planned with a grid-like structure and this is the easiest way to handle roads in your game. Just stick a grid around any major structure and pack it with roads. In the boonies, you can probably just make the roads seek the nearest major connection point. In the suburbs, you can make cul-de-sacs and a little more wandery roads and whatnot. In urban and capital areas, you want the roads to have a strong grid pattern.

Last, you are going to want to make highways that connect cities. You can do this simply by forming a network in which cities will tend to reach out to the closest nearby cities and running a road right through their urban areas. Just demolish whatever buildings are in the way. It doesn't really matter.

If any cities are left disconnected from nearby cities, just find the nearest city to them and run a road out to it.

So yeah, you have a bunch of research to to: Perlin noise, Voronoi diagrams, geomorphs, cellular automata. Have fun. This is a really research and experimentation heavy region of programming. You aren't going to have much to go on. Just play with it until something interesting happens. Pretend you are 12 again.
It should be noted that as far as cities go, using several different city planning methods is probably not a terrible idea. Voronoi is nice and all, but me personally, there are better ways of generating cities. The general idea of just about the most effective city plans tends to follow a district plan like such:

The Central Business District (Downtown) - Typically the epicentre of the city, being where the majority of the businesses are located (duh). The location of this district is mostly irrelevant as the rest of the city is basically built around this area.

Low Income Residences (Slums) - These can generally be found right beside the CBD and make up the majority of the housing in an area. An easy way to generate this is to either partially or completely surround the downtown area in this district. The idea is that these are the homes of the major working class, making it more efficient for those working to be closer to their jobs in the CBD.

Middle Class and Upper Class Residences - These homes lie closer to the outskirts of the city where land is abundant and there is more space to spread out and enjoy life, so to speak. These people likely are business owners themselves or work high-profile jobs that don't require them to clock in daily at a specific location. They're much more free to live farther from the CBD. These can generally be generated anywhere toward the outskirts with Upper Class district covering the most square area per home.

Secondary Business District - In exceptionally large cities, a second, smaller business district might pop up as a convenience. Similar to the CBD, this is usually surrounded by low income residences, but typically much closer in relation to the middle and upper class residences than the CBD.

Roads - This is a tricky thing to generate randomly, but it can be done if you put in the effort. The thing to note is that the main roads are basically the arteries of the city. They likely existed well before the city became as large as it is, possibly being an old trade road with the city built on top of it. Most cities have at least one major road that passes right through the CBD, the Main street. Being able to connect high-traffic roads to the CBD is essential for the natural growth and expansion of a city. As far as other, smaller roads, they simply serve as a passage between districts. Having each building accessible via road to any other building is an important part of city planning, which is why a grid layout is generally the easiest method of setting it up, but remember that most roads follow the easiest navigable topography of the land, meaning that they're not very likely to cross mountains and instead are more likely to go around them. Taking terrain steepness as a major factor in roadways will be important to making them feel more natural.

This is just about the basics I have of city planning. There are a lot more in-depth sources out there on the art, but I'm hardly a professional in the field and have only studied it mildly while building D&D campaign settings, so take what I have to say with a grain of salt. Overall, just adding onto the ideas Ter suggested, he's usually a very solid source of good information.
Thank you both! These are great replies. I'm going to disappear and dive into this.
Expanding on Kats' response, I think actually a secondary business district is a similar concept to a simple "commercial zone".

Near a city, you often have outlying towns that depend on the city as an anchor; the city's policies sway them enormously. For example I live in a village within 20 minutes of the city's downtown area (by driving a short way and hopping onto the highway). There's a main road that goes through here, which is all commercial development, but go onto any side street and you're suddenly in residential.

In a huge city, the concept of a secondary CBD can be thought of as the city being so large that it calves under stress and is in the process of splitting into two smaller units. This kind of thing could happen if the original CBD is simply too congested for new business, causing commercial zones elsewhere to grow in response.
@Lummox: That can sort of emerge naturally using cellular automata instead of voronoi diagrams. Larger cities could sort of swallow smaller cities and you wind up with islands of residential areas in the middle of metropolises. Metropoli? Metropopi? Metropoloxen?
Agreed, cellular automata would be an interesting way to handle that. Although that approach is still compatible with a Voronoi diagram, where each node could be a cell.
My understanding of Toady's world generation for dwarf fortress is that it starts with perlin noise and the manipulation of image maps and then moves into a cellular automata approach. It's pretty insane.
What are the needs of the game? Frankly, I tend to throw out algorithms imitating things in favor of tools the project requires.

Cities are divided into blocks. If you decide so, they're frickin' rectangles. There's more shapes in real life cities? Who cares? Divide a big rectangle into smaller ones. Slap roads on either the minimum or the maximum coordinates.

Blocks are divided into buildings. They're frickin' rectangles. Divide the smaller rectangles into even smaller ones. If you want, use cellular automata to determine which of the latter are buildings or lawns. However, if you slap paths on either the minimum or maximum coordinates then you'll know they're all accessible anyway and it can be completely random.

Buildings are divided into rooms. They're frickin' rectangles. Divide the even smaller rectangles into rectangles that are even smaller yet. Graph them into a maze if you want to determine doors. Need realism? Make sure you include at least one bathroom and a kitchen somewhere.

Seriously, if a physicist can model cows as spheres, a game developer can use rectangles to imply things that are generally rectangles in real life.
In response to ACWraith
Of course, it only works with spherical cows in a vacuum.
In response to Lummox JR
Lummox JR wrote:
Of course, it only works with spherical cows in a vacuum.

This kills the cow.
My apologies if it seems like that came out of nowhere. I just tend to find noise and cellular automata to be overkill. They help make nice landscapes if you have a divisible enough space to show the detail. However, I've found more abstract randomness with a bit of lampshading to be just as immersive within the, hopefully, refined scope of a game.

For instance, I'd use a shuffle bag to deal out whatever selection of biomes I wanted. The Minecraft-like graph might help with transitions between neighbors , but in mechanical terms what I generally need is for certain things to exist so the player can interact with them. Limiting how they appear next to each other just cuts down on the permutations that I believe help make exploring procedural worlds worthwhile.