The International Simutrans Forum

Community => Simutrans Help Center => Topic started by: Spacethingy on December 13, 2013, 02:54:02 PM

Title: Extract save game data?
Post by: Spacethingy on December 13, 2013, 02:54:02 PM
It's a long story, but I'm doing Zipf's Law (https://en.wikipedia.org/wiki/Zipf%27s_law) and I want to play Simutrans too, sooooooo......


Is there any way of magically plucking city size data out of a save file? I've had a go with setting the save type to .xml, but even with a relatively small map, Chrome takes about 10 minutes to render it (and none of it makes even the remotest sense...), and Excel/Gnumeric just crash.


In an ideal world, I'd like a little "export data" button ingame, but I have a feeling that may be a heck of a lot of work for very little gain...  ;D


Thanks for any suggestions!


EDIT:
This is a small map's 13 cities that are connected to my network, x=log(rank) y=log(population)
Not a bad correlation already!
(http://i.imgur.com/f9CxJdq.png)
Title: Re: Extract save game data?
Post by: Dwachs on December 13, 2013, 04:32:34 PM
You can write a pseudo-scenario script to export the numbers.

See attached file. Unpack this into <your pakset>/scenario. Use nightly r>=6980. Start with '-debug 2 -log 1'. Open your savegame. Then start the scenario:
Options -> Load Scenario -> world_stats. The scenario prints the size of the cities to the log-file.
Title: Re: Extract save game data?
Post by: An_dz on December 13, 2013, 05:02:04 PM
Amazing, those scenario scripts are powerful.

But just to answer the xml:
All cities are <![CDATA[]]> tags followed by a <koord> tag.
The city size is the first <i64> tag.
Title: Re: Extract save game data?
Post by: Spacethingy on December 13, 2013, 07:34:44 PM
Thanks guys, I'll try it when r6980 compiles tonight. Didn't know the scripting system was going to be so powerful and useful!
Title: Re: Extract save game data?
Post by: Spacethingy on December 14, 2013, 02:29:38 PM
...and work it does, awsome! That's dead useful.


So, a little analysis of 15ish of the pak64 III server's biggest cities:
(http://i.imgur.com/lu7l7mr.png)


The gradient of the trendline could be approximated to -1/6, implying that the population of a city on the server is roughly inversely proportional to the sixth root of it's rank on the city size list.

Or very roughly:
(http://i.imgur.com/2ORco5R.gif)

Darn, I love Simutrans...  8)

Edit: woops, used wrong log base.