The International Simutrans Forum

Development => Patches & Projects => Topic started by: Dwachs on November 05, 2012, 08:08:24 PM

Title: Scripted map generation
Post by: Dwachs on November 05, 2012, 08:08:24 PM
Here is some proof-of-concept of using scripts to generate maps (aka placing cities and adjusting water level).

Example map-files can be found here:
https://github.com/Dwachs/simutrans-scenarios/tree/poland_map/maps

Here is a sample file placing some Polish cities at correct locations:

heightmap = "poland319x214.ppm"

settings.water_height = 0

create_city("Warszawa", 210, 89, 2345)
create_city("Krakow", 201, 161, 1234)
create_city("Poznan", 100, 81, 1234)
create_city("Bydgoszcz", 130, 48, 1234)
create_city("Szczeczin", 47, 47, 2345)
create_city("Bialystok", 292, 52, 2345)
create_city("Wroclaw", 110, 128, 2345)
create_city("Legnica", 70, 115, 2345)
create_city("Olsztyn", 193, 36, 2345)
create_city("Gdansk", 155, 24, 2345)


River generation by script is a pain, as the available heightfield data it too rough. More thoughts needed.
Title: Re: Scripted map generation
Post by: VS on November 05, 2012, 08:34:43 PM
I am not looking at patch, so perhaps a dumb question - why the declarative/imperative mix?
Title: Re: Scripted map generation
Post by: Dwachs on November 05, 2012, 08:42:56 PM
It happened to be like this. No idea why, no thoughts put into this.

What is easier to grasp for the potential script writer:

set_water_level( 2 )
create_city("City", ...)

or

water_level = 2
create_city("City", ...)

?
Title: Re: Scripted map generation
Post by: Combuijs on November 05, 2012, 09:05:44 PM
I think your proof of concept with map, water level and cities looks really good, practical and extendable. Is it already working in Simutrans 112.0?

Can't restrain excitement...
Title: Re: Scripted map generation
Post by: VS on November 05, 2012, 09:12:50 PM
Maybe newbies would not mind at all, and it is just me, with years of conditioning to the two syntax paradigms, always unmixable?

I believe the confusion comes from not knowing whether to treat this as sequential commands that get executed, or just a fancy list of options.




I don't mean to criticize the effort, though - just weirded out, that is all. What this enables is really important and exciting!
Title: Re: Scripted map generation
Post by: Fabio on November 05, 2012, 10:45:07 PM
Rivers could be a polygonal list of coordinates (x1, y1, x2, y2, ..., xn, yn), then the way builder performs the needed terraforming and places the river way.  It might be indicated where rivers must get wider as well.
Title: Re: Scripted map generation
Post by: Sarlock on November 05, 2012, 11:54:08 PM
Great work!

I can see rivers being very tricky to implement...
Title: Re: Scripted map generation
Post by: IgorEliezer on November 06, 2012, 02:32:16 AM
Just a crazy idea: What about a minimalistic heightmap editor? Something like Tilecutter interface but way simpler.

You load the ppm or image which is displayed in a window. Then by buttons ("Add City", "Add River" etc) or by commands ("/add city <name> <param1> <param2> ....") entered in a field, the editor would create and edit the script. Points for cities and rivers would be defined by clicking on the map.

If we desire something more fancier, this editor would have 2 toggleable layers: one would be the actual ppm, the other would be an overlay image, for example, if I want to create a script for a country, I'd load a real map over the ppm so I'd be able to see where the cities and rivers are in real life and use their positions to create the script.
Title: Re: Scripted map generation
Post by: prissi on November 06, 2012, 09:05:38 AM
Maybe (as suggested in the other thread) to use always 10000 by 10000 corrdinates, which then were scaled to the real map size (and same for inhabitants). THat way scaled down heightmaps would use the same files.

And I think as VS said, consequently "command(parameters)" is best way.
Title: Re: Scripted map generation
Post by: Carl on November 06, 2012, 09:49:51 AM
Just to say this is a really exciting feature -- and one that would have saved me countless hours on some of my projects! :)
Title: Re: Scripted map generation
Post by: Fabio on November 06, 2012, 10:06:37 AM
Maybe maps could even be scaled on the fly using simple interpolation, so that if I download, say, a 1024*4096 UK map I can then play it at whatever map size I like just preserving proportions.
Title: Re: Scripted map generation
Post by: Combuijs on November 06, 2012, 10:47:50 AM
Quote from: Fabio on November 06, 2012, 10:06:37 AM
Maybe maps could even be scaled on the fly using simple interpolation, so that if I download, say, a 1024*4096 UK map I can then play it at whatever map size I like just preserving proportions.

But if maps don't have the same proportions, they will most likely have a different area of the country. If you look at all British maps in Simutrans Maps you can't use one citylist and interpolate because they don't contain the same area. Imagine Blackpool falling in the sea...
Title: Re: Scripted map generation
Post by: Fabio on November 06, 2012, 11:37:37 AM
If the position (and dimension) is relative, the map can be scaled up or down containing exactly the same area, only at a different "zoom level".
Title: Re: Scripted map generation
Post by: Ters on November 06, 2012, 03:43:10 PM
I think you might still end up with cities in the sea if the land it's supposed to be on is interpolated away.
Title: Re: Scripted map generation
Post by: Fabio on November 06, 2012, 03:54:22 PM
Well, city builder should check that and either remove that city, either place it on nearest land shore.