Author Topic: Scripted map generation  (Read 3327 times)

0 Members and 1 Guest are viewing this topic.

Online Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4251
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Scripted map generation
« 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:
Code: [Select]
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.
Parsley, sage, rosemary, and maggikraut.

Offline VS

  • Senior Plumber (Devotee)
  • Devotee
  • *
  • Posts: 4849
  • Total likes: 25
  • Helpful: 63
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: Scripted map generation
« Reply #1 on: November 05, 2012, 08:34:43 PM »
I am not looking at patch, so perhaps a dumb question - why the declarative/imperative mix?

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Online Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4251
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Scripted map generation
« Reply #2 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:
Code: [Select]
set_water_level( 2 )
create_city("City", ...)
or
Code: [Select]
water_level = 2
create_city("City", ...)
?
Parsley, sage, rosemary, and maggikraut.

Offline Combuijs

  • Web Team
  • Devotee
  • *
  • Posts: 1387
  • Total likes: 22
  • Helpful: 53
  • Maintainer of maps.simutrans.com
    • Combuijs
  • Languages: EN, NL
Re: Scripted map generation
« Reply #3 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...
Bob Marley: No woman, no cry

Programmer: No user, no bugs



Offline VS

  • Senior Plumber (Devotee)
  • Devotee
  • *
  • Posts: 4849
  • Total likes: 25
  • Helpful: 63
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: Scripted map generation
« Reply #4 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!

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • Total likes: 7
  • Helpful: 91
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Scripted map generation
« Reply #5 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.

Offline Sarlock

Re: Scripted map generation
« Reply #6 on: November 05, 2012, 11:54:08 PM »
Great work!

I can see rivers being very tricky to implement...
Current projects: Pak128 Trees, blender graphics

Offline IgorEliezer

  • Devotee
  • Administrator
  • *
  • Posts: 3952
  • Total likes: 145
  • Helpful: 71
  • Lost In Stupid Parenthesis
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: Scripted map generation
« Reply #7 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.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8823
  • Total likes: 323
  • Helpful: 229
  • Languages: De,EN,JP
Re: Scripted map generation
« Reply #8 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.

Offline Carl

Re: Scripted map generation
« Reply #9 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! :)

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • Total likes: 7
  • Helpful: 91
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Scripted map generation
« Reply #10 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.

Offline Combuijs

  • Web Team
  • Devotee
  • *
  • Posts: 1387
  • Total likes: 22
  • Helpful: 53
  • Maintainer of maps.simutrans.com
    • Combuijs
  • Languages: EN, NL
Re: Scripted map generation
« Reply #11 on: November 06, 2012, 10:47:50 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...
Bob Marley: No woman, no cry

Programmer: No user, no bugs



Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • Total likes: 7
  • Helpful: 91
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Scripted map generation
« Reply #12 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".

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4870
  • Total likes: 202
  • Helpful: 108
  • Languages: EN, NO
Re: Scripted map generation
« Reply #13 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.

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • Total likes: 7
  • Helpful: 91
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Scripted map generation
« Reply #14 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.