Town generation started out with the basics; each town would be defined from the seeded towns discussed in the last update, and would grow outward from a weighted center point of the town plot.
The first step to generating towns is road generation. I made a critical mistake during my initial attempt at solving the problem, and locked myself into a solution that used templates to generate roads. This means that each town would have had a road system that inherited from a pre-defined template with several random variations. By the time I realized how awful of an idea this was, I had already blown most of my spring break programming it.
Example of one of the templated road systems. Purple lines represent roads, and green square represent potential zones for residential development. |
Okay - with that garbage out the window, I came up with a much more natural approach to the problem that likely emulates how roads are created in real life. The idea is to break the local map down into grids that contain several square meters of land. An entity that we'll call a road builder is spawned at a random location somewhere near the center of the local map. If the grid that the road builder lands on is not connected to a road, then it will construct a road connecting that grid to the main road system. By repeating the process and moving the road builder to another random spot on the grid, a kind of "crack" of roads is formed.
Shit, it already looks better than that template crap. |
In order to resolve the utter lack of interconnectivity on the road grid, an algorithm is executed which connects the endpoints of each path to other endpoints to increase connectivity and to make everything look a bit more natural.
At least it doesn't look like a spider web anymore. Notice how the earliest built roads form a backbone for the network. |
The nice thing about this road builder algorithm is that it works for any size town. It can be used to generate a town of only a few homes or even a metropolis of 500+ buildings.
Road network from above seeded with building lots(green). There are about 200 buildings lots served by this road network. |
That's it for this update. Tune in next time for even more images of lines and boxes.
-zalzane
No comments:
Post a Comment