Export: OpenTTD maps to a text format?

Got an idea for OpenTTD? Post it here!

Moderator: OpenTTD Developers

Post Reply
pekarna
Engineer
Engineer
Posts: 5
Joined: 10 Oct 2009 11:43

Export: OpenTTD maps to a text format?

Post by pekarna »

Hi OpenTTD developers,

please, is there a convertor of OpenTTD map files to some text format?
No matter what - XML, plain text... the only necessity is to be parseable.

If not, could someone write it?
Yes, I could write it for myself... but you know the code right away and would code it much faster than I would.

I intend to use that for an opensource project - WebTTD (which you may join if you want :) )
WebTTD

Thanks, Ondra Zizka
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Export: OpenTTD maps to a text format?

Post by Zuu »

1. It is not an easy task.

2. How would someone else than you find value of spending their time on this for you? While it might be true that *someone* might do it faster than you, he or she still need to get something out of it. The person who do it must see a benefit of doing it.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Re: Export: OpenTTD maps to a text format?

Post by XeryusTC »

pekarna wrote:No matter what - XML, plain text... the only necessity is to be parseable.
The current format is already parseable, it is just binary and quite hard to parse but OTTD is still able to read its own savegames so it is possible. Maybe you should take a look at all the save/load functions.
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Export: OpenTTD maps to a text format?

Post by Roujin »

What exactly do you mean with "map"? Everything that's stored in a savegame?

In OpenTTD, savegames consist of two parts.
Part 1 being the map array, a big array (or arrays) where each element is associated with a tile, describing what is on the tile. See docs/landscape.html
Part 2 is various variable-sized "pools" that store stuff that either is not associated with a certain tile on the map (e.g. company information, cargo packets...), or is too big to fit into the map array, so it's stored in the pool and to be able to access it in the map array is stored an index pointing to the corresponding item in the pool (e.g. stations).

So if you're gonna export that to xml or something similar, it's probably going to look something like this:

Code: Select all

<savegame>
  <map_array>
    <tile>
      <x>0</x>
      <y>0</y>
      <type_height>xxxxxxxx</type_height>
      <m1>xxxxxxxx</m1>               // if you chose to write it in binary - it's 8 bits. x = either 0 or 1
      <m2>xxxxxxxxxxxxxxxx</m2> // 16 bits
      <m3>xxxxxxxx</m3>
      <m4>xxxxxxxx</m4>
      <m5>xxxxxxxx</m5>
      <m6>xxxxxxxx</m6>
      <m7>xxxxxxxx</m7>
    </tile>
    <tile>
      ...
    </tile>
    ...
    ...  // all the other tiles
    ...
  </map_array>
  <pools>
    <company_pool>
      <company>
        <id>0</id>
        <whateverstuffisstoredthere>...</whateverstuffisstoredthere>
      </company>
      ...
    </company_pool>
    <cargopacket_pool>
      <cargopacket>
        <id>0</id>
        <whateverstuffisstoredthere>...</whateverstuffisstoredthere>
      </cargopacket>
    </cargopacket_pool>
    ...
    ...    // all the other pools
    ...
  </pools>
</savegame>
(btw I'm not volunteering to code this for you, only helping. The others are probably right that you'll have to code it yourself.)

Disclaimer: This is only from what I remember and using the above mentioned landscape.html, so there may be mistakes. Don't rely on it too much and get a second opinion, if this is correct.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
pekarna
Engineer
Engineer
Posts: 5
Joined: 10 Oct 2009 11:43

Re: Export: OpenTTD maps to a text format?

Post by pekarna »

Thanks for info, Roujin and XeryusTC.

I would even suffice with some numbers and delimiters logged to a debug output.
The problem is not the code itself, but to get it compile, which I didn't manage to yet.

Zuu, the motivation for anyone to code this for the WebTTD project is the same as coding anything for any other free opensource project.
Imagine OpenTTD in the form of a MMO browser-based game. Don't you like this idea?
User avatar
Gremnon
Tycoon
Tycoon
Posts: 1517
Joined: 16 Sep 2005 12:23
Skype: the_gremnon
Location: /home
Contact:

Re: Export: OpenTTD maps to a text format?

Post by Gremnon »

I'd prefer to keep it offline, as it is myself.
That way, I don't have to be online to play, I get to choose what GRFs are active, and what the settings are. Online play is what the multiplayer function is for.
But that's just my view, don't let it discourage you.
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Export: OpenTTD maps to a text format?

Post by Roujin »

There are instructions on the wiki that should help you getting OpenTTD compiled: http://wiki.openttd.org/FAQ_development ... pile_it.3F
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
maquinista
Tycoon
Tycoon
Posts: 1829
Joined: 10 Jul 2006 00:43
Location: Spain

Re: Export: OpenTTD maps to a text format?

Post by maquinista »

pekarna wrote:Hi OpenTTD developers,

please, is there a convertor of OpenTTD map files to some text format?
No matter what - XML, plain text... the only necessity is to be parseable.

If not, could someone write it?
Yes, I could write it for myself... but you know the code right away and would code it much faster than I would.

I intend to use that for an opensource project - WebTTD (which you may join if you want :) )
WebTTD

Thanks, Ondra Zizka
It looks interesting.

I recomend You to use only OpenGFX images, because They have a free license.
Sorry if my english is too poor, I want learn it, but it isn't too easy.[/list][/size]
pekarna
Engineer
Engineer
Posts: 5
Joined: 10 Oct 2009 11:43

Re: Export: OpenTTD maps to a text format?

Post by pekarna »

I have managed to build OpenTTD using MinGW. Thanks for the wiki page link!
pekarna
Engineer
Engineer
Posts: 5
Joined: 10 Oct 2009 11:43

Re: Export: OpenTTD maps to a text format?

Post by pekarna »

How can I enable logging to a file?

I've tried DEBUG, or printf, but that goes to a console (Windows XP, compiled using MinGW.
I've tried openttd -d 1 > foo.txt, but OpenTTD opens another console for stdout...

Thanks, Ondra
Eddi
Tycoon
Tycoon
Posts: 8289
Joined: 17 Jan 2007 00:14

Re: Export: OpenTTD maps to a text format?

Post by Eddi »

[to repeat the answer from the chat:]

you need to convert openttd.exe to a console application with http://devs.openttd.org/~glx/convert.zip
pekarna
Engineer
Engineer
Posts: 5
Joined: 10 Oct 2009 11:43

Re: Export: OpenTTD maps to a text format?

Post by pekarna »

Well, it didn't work on Windows, so I was hoping there is some logging implemented other than DEBUG(). If not, never mind, I'll use fprintf() ;-) Thanks for help.
Post Reply

Return to “OpenTTD Suggestions”

Who is online

Users browsing this forum: No registered users and 2 guests