The first attempt
In these days i’ve made a lot of research on different topics, one of these has been “how to generate an urban map”.
As always,the chat has been an invaluable resource, proving once again that confrontation and sharing ideas is more rewarding than googling stuff.
This time i must thank the user srd| which pointed me to a very useful pdf ( here ) .
Before that, i was trying thinking on how to develop a simple network, on paper.
Using a wife-dependant-random-number-generator i modeled a simple L-System.
I started with a single segment (a,b) and 3 different possible productions:
- apply to the segment a random midpoint displacement
- from the central point of the segment, create a new segment,perpendicular to the first
- create a block which shares one of the sides with the original segment.
After a few iterations i got a decent road map ( and by decent i mean “it’s not realistic, but it’s not crap either” ).
At the end of the drawing process i noticed some “artifacts” like:
- points lie too close to each other
- a point lies very close to a line, but doesn’t touch it
This was easily adjustable by applying some “correction algorithms” to the generated map (like “join the points”,”move the end of the segment on the line”).
So i came to the conclusion that to generate a decent map the steps must be basically something like the following:
- From a starting input iterate a certain amount of times the possible productions
- when the iterations are complete apply the correction patterns to “clean” the map.
After reading the pdf that srd| linked, i understand that a better solution is to feed population density maps and other statistical data maps to the algorithm ,so that the productions may have more data to crunch.
I am almost sure i don’t need a so realistic map.
My first try has been followed by some hours of cursing to try to create the algorithm and drawing it in SDL, just to check if something decent came out.
this was my excellent result:
I think that i’ll skip the sdl test and put this topic on one side to re-take it in some week.
The map object
While discussing maps and related topics on the chat ,i came to another conclusion : my very very simple map system must be refined.
At the moment the map keeps one layer of tiles, which each handles colors of background and foreground, character to display ,etc.
I need to further develop this system.
My next steps will be adding multi layers map (at the moment i think a background layer,an effect layer, a “solid objects” layer, and npcs ) and to create standard Tiles to avoid the handling of the graphical stuff inside the Tile object.