Is there any API for user's vehicles, stations, routes, etc.?

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
Andrew_if
Engineer
Engineer
Posts: 3
Joined: 23 Jan 2018 12:51
Location: Moscow, RU

Is there any API for user's vehicles, stations, routes, etc.?

Post by Andrew_if »

Hi all,

I'd like to make some analysis/data visualization for OpenTTD data. At the moment it looks to me like the best option would be to get a kind of events happening in it (like train #n stopped at the station $station_name; train #n unloaded $cargo_name for $dollars; factory $factory_name has increased output to $value, etc). Or the other suitable option is to have an API and poll it periodically for changes.


Correct me if I wrong, but it seems to me that NoAI and Game Scripts frameworks have only access to non-player objects.

Is there anything like that available? I don't think I can build it inside of OpenTTD so I'm looking for a way to get the data outside of it.
User avatar
orudge
Administrator
Administrator
Posts: 25137
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Re: Is there any API for user's vehicles, stations, routes, etc.?

Post by orudge »

I think if you're wanting to hook into a live game, the best way to do so is via a multiplayer server. JOAN (Java OpenTTD Admin Library) seems to be the most complete project that does this. There's also an older Python project available.

If you're just wanting to interrogate a saved game, I started work on a C# library to do this some years ago - it's a bit stuck in limbo but one day I will hopefully release it (although it may not be complete!)
Andrew_if
Engineer
Engineer
Posts: 3
Joined: 23 Jan 2018 12:51
Location: Moscow, RU

Re: Is there any API for user's vehicles, stations, routes, etc.?

Post by Andrew_if »

Thanks for the hint. Both libraries look a bit undocumented to me but connecting to (or maybe emulating?) a network server looks like a good idea to start with.
Jony1(Yosselko)
Engineer
Engineer
Posts: 26
Joined: 20 Dec 2017 17:56

Re: Is there any API for user's vehicles, stations, routes, etc.?

Post by Jony1(Yosselko) »

What's an api ?
User avatar
JGR
Tycoon
Tycoon
Posts: 2559
Joined: 08 Aug 2005 13:46
Location: Ipswich

Re: Is there any API for user's vehicles, stations, routes, etc.?

Post by JGR »

Andrew_if wrote:Is there anything like that available? I don't think I can build it inside of OpenTTD so I'm looking for a way to get the data outside of it.
I would expect that doing it from within OpenTTD would be by far the easiest way to do it.

Events like trains stopping at stations, cargo unloading, etc. are not directly recorded in savegames after the fact, and are not transmitted as part of the multiplayer protocol.
Each multiplayer client runs a full game simulation separately.

Adding some printf lines to key functions in the source, recompiling, running it, and then analysing the output is probably your best bet.
Ex TTDPatch Coder
Patch Pack, Github
Andrew_if
Engineer
Engineer
Posts: 3
Joined: 23 Jan 2018 12:51
Location: Moscow, RU

Re: Is there any API for user's vehicles, stations, routes, etc.?

Post by Andrew_if »

JGR wrote:
Andrew_if wrote:Is there anything like that available? I don't think I can build it inside of OpenTTD so I'm looking for a way to get the data outside of it.
I would expect that doing it from within OpenTTD would be by far the easiest way to do it.
By "outside" I mean that my data viz project won't be a part of the game. At the moment I'm thinking about a streaming engine like Apache Kafka plus Grafana as a front-end. Maybe a kind of database in between. I hope it will be interesting/useful not only for me but don't know if it possible at all and if I can do it simple and reproducible. The question is if I can feed this system with data.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 25 guests