A downloadable tool

Download NowName your own price

This simple addon is a mere godot Resource (but it also comes with a demo to show its potentiality) that is used to generate a top-down square lattice city layout.

Let me explain what I mean.

1- Layout: the resource does not generate a Tileset or anything else of graphic nature. It outputs a mere array of ints. The entries of the array tell what is contained in the position (x,y) of the grid. If there is 0, there is a road. Otherwise a building.

2- The program allows you to identify clusters, or connected components, of buildings. This is because it might be desirable that "buildings" all connected to each other have a similar layout, and disconnected "buildings", instead, not necessarily. 

Basically, in the resource city_generator.gd (which is all you need, all the rest is just the demo) you have two methods:

generate_city_layout: generates an array of 0 and 1, the 1's are buildings.

Returns: the array. You don't actually need that return, because the array is a global var in the resource so if you want you can access it directly.

clusters_from_city_layout: AFTER you called generate_city_layout, this method converts all the "1" in numbers from 1 to the max number of connected components, with each connected component having a different number. Use this only if you need, as it requires additional time. In the demo provided, this is used to set different colors for the connected components, while roads are all grey (0.5, 0.5, 0.5)

Returns an array of two elements: the first is the agumented city layout, the second is simply the number of connected components.

3- The code ensures that the roads are fully connected (so every position in the city can be reached from any other position), but at a price: there is a "ring road" all around the city. You cannot avoid this; ensuring full connectedness without the ring IS possible, but the algorithm should be changed.  Since ring roads are common in metropolis and are a convenient way to ensure connected, I took advantage of it to make the algorithm fast. Another convenient possibility would be to add one vertical and one horizontal road gioing from endpoint to endpoint of the city, without outer ring. Please let me know if you are interested in this and want me to add to the addon!

4- You can customize: city width, city height, probability (estimate) of a road, the random number generator if you want to fix it to a certain value or if you want to change it every time (in the latter case, set it to -1. WARINING: the demo does not allow to change this, it works with -1, so every time a new rng is generated), and if you allow double roads or not (default: not)

The probability, of roads, is only an estimate for 2 reasons. The first, number of roads is an int, and the city size too, so the real frequency of streets is discretized, while the probability is a float. Second, to ensure connectedness, the last generated road might be longer than it should be.

 Allow double roads if you want a "village" like structure, i.e. small chunks of buildings with a lot of space in between. Also set a low probability of roads, of course. Let it be clear that I did NOT make this resource to generate villages tough, I had in mind a metropolis, i.e. clusters of palaces with roads in between, not scattered houses. I don't think this app is the best solution for that. 

- I did not add an "autotiling" for streets (i.e. setting different values depending on the type of road piece: straight horizontal, crossroads, bent top right...) because I don't have the tileset... no, actually I do have it, but only if you do NOT allow for double roads. Ask me if you want me to add a simple autotiling solution that works for single roads only! In my code (yes, I made this for a game I have in mind), I use negative numbers for roads, and each different number is associated with a tile from my tileset.


I am open to suggestions and requests and comments!

If you decide to use this addon in your project, please credit me as "coros (boris marcone)".


Updated 1 day ago
Published 3 days ago
StatusReleased
CategoryTool
AuthorCoros Games
Tags2D, Godot, No AI, Procedural Generation, resource, square-lattice, Top-Down

Download

Download NowName your own price

Click download now to get access to the following files:

metropolis_generator.zip 486 kB

Leave a comment

Log in with itch.io to leave a comment.