Hi everyone
I love three things: Simutrans, train/transport network graphs and programming, so writing an utility script that draws those network graphs for my Simutrans games was an obvious thing for me to do.
So far it outputs either (ugly) ASCII or (also ugly) PNGs, doesn't handle 'complex' graphs yet and there's no text/colors on the pictures, but hey, I got something:
ASCII Output:
Sakai Metro
~~~~~~~~~~~
###---***---***---***---***
\
***
|
### ###---***---***---***---***---###---***---###
\ |
*** ***
\ |
*** ### ***
\ | |
###---***---***---***---***---***---***---###---***---***---###---***---***---***---###
/ |
*** ***
/ |
*** ***
/ |
*** ***
/ |
### ***
|
***
|
***
|
###
PNG Output (EDIT: Now with colors, EDIT2: Now with legend):
(http://ubuntuone.com/p/rJk/)
Next up will be naming of 'major' Stations (the big black dots, where several lines join or cross and the end stations of lines), correctly handling line colors, a legend for the line colors, and titles for PNGs.
Currently it takes it's input from a yaml file that looks like this:
name: Sakai Metro
lines:
- name: Aomorisen
color: darkgreen
stations: Sagamihara - A16 v> Sagamihara - A15 v> Sagamihara - A14 v> Aomori Eki > Aomori - A12 / U12 > Nagasaki Eki > Hamamatsu Eki > Okayama - A11 / U11 > Okayama - A10 / U10 > Okayama - O1 / A9 / U9 > Okayama Eki (Sakai Shinkansen Terminal) > Nishi-Okayama Eki > Higashi-Sakai Eki > Sakai Eki > Sakai T6 / A4 / U4 > Takamatsu - T7 / A3 / U3 > Takamatsu Eki > Takamatsu - T9 / A1 / U1
- name: Utsunomiyasen
color: green
stations: Utsunomiya - U18 ^> Utsunomiya - U17 ^> Utsunomiya - U16 ^> Aomori - U15 ^v> Aomori - U14 ^> Aomori Eki > Aomori - A12 / U12 > Nagasaki Eki > Hamamatsu Eki > Okayama - A11 / U11 > Okayama - A10 / U10 > Okayama - O1 / A9 / U9 > Okayama Eki (Sakai Shinkansen Terminal) > Nishi-Okayama Eki > Higashi-Sakai Eki > Sakai Eki > Sakai T6 / A4 / U4 > Takamatsu - T7 / A3 / U3 > Takamatsu Eki > Takamatsu - T9 / A1 / U1
- name: Kakogawasen
color: saddlebrown
stations: Toyota - K1 > Toyota - K2 > Toyota - K3 / MM6 > Nishi-Toyota Eki > Toyota - K5 > Higashi-Toyota Eki > Sakai - K7 > Kakogawa Eki
- name: Nanbokusen
color: turquoise
stations: Toyota - N1 > Toyota - N2 / TR8 > Toyota - N3 > Naka-Toyota Eki > Toyota - N5 v> Toyota - N6 v Higashi-Toyota Eki v Sakai - N8 / SM5 / S8 v Sakai - N9 / S7 v Sakai Eki v Sakai - N11 v Sakai - N12 v Kawaguchi - N13 v Kawaguchi - N14 v Kawaguchi - N15 v Kawaguchi Eki v Kawaguchi - N17
- name: Tozaisen
color: pink
stations: Okayama - T1 / MM1 v Okayama Eki (Sakai Shinkansen Terminal) > Nishi-Okayama Eki > Higashi-Sakai Eki > Sakai Eki > Sakai T6 / A4 / U4 > Takamatsu - T7 / A3 / U3 > Takamatsu Eki > Takamatsu - T9 / A1 / U1
The ultimate goal is to somehow extract all that info from simutrans savefiles.
Once I get the initial version to work (no savefile support yet), I'll release the sourcecode with docs on how to use it as well as probably a small website that runs the script for you ;-)
Just thought I'd share this little sneak peak at what the bored me does.
It would be rather nice, if you could code this in C-code, so this could be done directly within simutrans. So far most algorithms I saw choked on more complex layouts.
Yes, it only works on very simple graphs right now.
As for C: I don't know C, all my attempts at coding in it failed (I guess I'm spoiled by the easy Python). So I'll continue coding this tool in Python, once it becomes mature, either someone can port it to C, or we make it callable from C (that would require the C code to be compiled with python installed).
What would help more would be a specification on how the savefile format looks, so this can be done outside of simutrans (which would be better imho).
As written countless times before the savegame format can and will change with every version. Thus why integrating such a tool into simutrans is the only way to go.
Quote from: prissi on May 06, 2011, 02:59:22 PM
As written countless times before the savegame format can and will change with every version. Thus why integrating such a tool into simutrans is the only way to go.
Yea I know, that was just me dreaming ;-). What *could* be integrated into simutrans is a way to export the YAML file I use to generate the graphs.
Anyway I'll probably release the code later tonight or tomorrow, so if anyone wants to port it into simutrans, go nuts.
Quote from: prissi on May 06, 2011, 02:59:22 PM
As written countless times before the savegame format can and will change with every version. Thus why integrating such a tool into simutrans is the only way to go.
An alternative would be to take the C library concerning reading/writing savegame files and provide a Python interface to it.
The difficulty is that there isn't a library concerning reading/writing savegame files: the reading/writing code is scattered all about the main code, and relies on the code that is reading the data to know the exact byte order in which the code writing the data wrote them; every time that new data are added to the save routine, the byte order changes, and, if the code does not recognise the new format (by version numbers) and act appropriately, all data after the change will be as junk.
And where is download of this? I would like to try it.
A couple of old threads about network diagrams are Network diagrams (http://forum.simutrans.com/index.php?topic=4103) and How do you organize your network? (http://forum.simutrans.com/index.php?topic=2448).
I am finding mostly software that ojii used - but all I found (in forum) is that it was written in Python (instead of C) - but it is irelevant for me because I have installed it for using of TileCutter.