Bean Counter game script?
Moderator: OpenTTD Developers
Bean Counter game script?
I sometimes run long experiments, and try to keep track of finances. See for instance viewtopic.php?f=29&t=75052&start=20#p1173635
I've just started to look at game scripts, and at the moment I'm just wondering if it's possible to write one that extracts the financial status at the start of a new year and output it to a file, similar to my hand-written pradtown.txt? Manually recording these figures at 1st January each year is sheer drudgery, and sometimes I'd just like to keep the game on fast forward.
I've been a casual programmer since the 1980s, and I've just had my first look at the "Minimal GS". I'd like to give it a try, but I may need some advice
I've just started to look at game scripts, and at the moment I'm just wondering if it's possible to write one that extracts the financial status at the start of a new year and output it to a file, similar to my hand-written pradtown.txt? Manually recording these figures at 1st January each year is sheer drudgery, and sometimes I'd just like to keep the game on fast forward.
I've been a casual programmer since the 1980s, and I've just had my first look at the "Minimal GS". I'd like to give it a try, but I may need some advice
Re: Bean Counter game script?
No, you can't [Yes, you can make such GS.]
Documentation:
1. NoGo - GSCompany contains information how to get values(balance, loan, expenses, etc.), also GSDate would be useful
2. Squirell - to print the data into the file
Also, it seems you can open any GS, that you can download on BaNaNaS, etc.
UPD: Maybe i missed something, but i really thought that Squirell was fully included. Anyway, you can make it as patch. And it should be easier
Documentation:
1. NoGo - GSCompany contains information how to get values(balance, loan, expenses, etc.), also GSDate would be useful
2. Squirell - to print the data into the file
Also, it seems you can open any GS, that you can download on BaNaNaS, etc.
UPD: Maybe i missed something, but i really thought that Squirell was fully included. Anyway, you can make it as patch. And it should be easier
Last edited by PropH on 24 Jul 2016 11:55, edited 2 times in total.
Sorry for my "great" English
Re: Bean Counter game script?
Writing a game script to record the information is quite doable.
Writing it to something external is quite not doable.
For safety reasons, most of the standard Squirrel libraries has been stripped out. You can't open an external file.
Listing it in a game script window, and taking a screen shot would work.
Writing it to something external is quite not doable.
For safety reasons, most of the standard Squirrel libraries has been stripped out. You can't open an external file.
Listing it in a game script window, and taking a screen shot would work.
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: Bean Counter game script?
Thanks to both PropH and Alberth for your replies. There are of course other methods than a game script. Provided that I auto-save the game at the end of each year, which I currently do, it should be possible to access the save file from eg. an external Perl script, which I know how to write, and get the figures out. That way, I only need a clear documentation of the save file format. Where do I find that?
Re: Bean Counter game script?
If you know C++, you can try to modify CompaniesYearlyLoop().
I wish that's cheaper than deal with savegames. Anyway, it would be better to wait for Alberth's answer, because i could be wrong, as it was with my first answer
I wish that's cheaper than deal with savegames. Anyway, it would be better to wait for Alberth's answer, because i could be wrong, as it was with my first answer
Sorry for my "great" English
Re: Bean Counter game script?
Thanks, but I'd rather eat oatmeal with toe nail clippings than hacking my way through a C++ file. I've actually worked through Kernighan & Ritchie's classic "The C Programming Language" and once started with Moo & Koenig's "Accelerated C++" but I just don't get the hang of it. In my eyes, OOP is a horrible tangle of spaghetti code.PropH wrote:If you know C++, you can try to modify CompaniesYearlyLoop().
I wish that's cheaper than deal with savegames. Anyway, it would be better to wait for Alberth's answer, because i could be wrong, as it was with my first answer
Re: Bean Counter game script?
By the way, i can help you. I didn't learn all aspects of C++, but it's easy, or at least it seems to be.
UPD: i mean, it's easy to solve current problem, not to learn program language
UPD: i mean, it's easy to solve current problem, not to learn program language
Last edited by PropH on 24 Jul 2016 16:59, edited 1 time in total.
Sorry for my "great" English
Re: Bean Counter game script?
Re: Bean Counter game script?
Hex-editor won't do, if you expect some value at a constant offset.
OpenTTD compresses its savegames, and uses chunks of varying size to store its data (there is a varying number of vehicles, industries, stations, companies etc in the game, fixed offsets make little sense). Also, save game format varies through time, what works today may break tomorrow.
Simplest "hex editor" is OpenTTD itself, it knows how to load its own data
OpenTTD compresses its savegames, and uses chunks of varying size to store its data (there is a varying number of vehicles, industries, stations, companies etc in the game, fixed offsets make little sense). Also, save game format varies through time, what works today may break tomorrow.
Simplest "hex editor" is OpenTTD itself, it knows how to load its own data
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: Bean Counter game script?
So it would appear that the "open" in OpenTTD doesn't extend to the savegame format. I have been working with proprietary database formats that's been a lot easier to unravel.
I don't intend this as a criticism of the project; I understand that (as I can understand why) you have simply continued working with a legacy format, created at a time when computer resources were very limited.
I don't intend this as a criticism of the project; I understand that (as I can understand why) you have simply continued working with a legacy format, created at a time when computer resources were very limited.
Re: Bean Counter game script?
Oh, it's open alright. Compression is some external library that gets linked, and the source code defines the chunks completely (everything built around tables of fields from structures that should be saved or loaded, for every version of save games). There is no external documentation, mostly for the practical reason that it's always obsolete.leifbk wrote:So it would appear that the "open" in OpenTTD doesn't extend to the savegame format.
Changing the savegame format is just a matter of changing one or more tables.
It does mean however in practice that you have to program a reader to load the file. Take the tables from OpenTTD, and implement the code that uses the tables to load the data. You typically want to store the read data too, so you need storage structures too. If you want to load older save games, there is also code that converts old save game formats to the current version, so it makes sense in todays context.
This is of course exactly what OpenTTD is doing already. For this reason, if you intend to read savegame data, it's always simpler to just take OpenTTD, and hook your code into it. A reader is a non-trivial piece of software,why implement it if a perfect working implementation is readily available in source form?
Note that data formats like this exist at other places too. A .gif, .jpg, or a .png is not a simple linear array of pixel colours. You need to write a decoder, a reader to make sense of the data, and expand it to pixels with colours.
I wasn't there at the time, but the old legacy format is much more crappy than what we have now, as far as I know. There is also code that tries to guess what version old file we actually get (not sure this is for original game, more likely it is for TTDPatch files, that have partial support afaik).leifbk wrote:I don't intend this as a criticism of the project; I understand that (as I can understand why) you have simply continued working with a legacy format, created at a time when computer resources were very limited.
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: Bean Counter game script?
I'm perfectly aware of that. I'm also perfectly aware of how to find documentation of eg. the .png format that enables me to implement a decoder in any program language that I may consider fit for the purpose. As far as I am concerned, C++ is not, or will ever be, one of those languages.Alberth wrote:Note that data formats like this exist at other places too. A .gif, .jpg, or a .png is not a simple linear array of pixel colours. You need to write a decoder, a reader to make sense of the data, and expand it to pixels with colours.
Re: Bean Counter game script?
A GS can write to the log. If you increase the log level for script source to iirc 5, then you get messages from GS and AIs included.
On Linux you just direct stderr or stdout to a file. Then parse that.
Another option is to make GS send messages to the admin port client that you write and connect to your multiplayer server. Have a look on ServerGS for some help on this either to write a custom GS oruse ServerGS as your GS.
On Linux you just direct stderr or stdout to a file. Then parse that.
Another option is to make GS send messages to the admin port client that you write and connect to your multiplayer server. Have a look on ServerGS for some help on this either to write a custom GS oruse ServerGS as your GS.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Bean Counter game script?
I was thinking this too. Then remove all the lines from the log that are not relevant with an external program (or automate it with e.g. python), and you have the finance report file you're afterZuu wrote:A GS can write to the log. If you increase the log level for script source to iirc 5, then you get messages from GS and AIs included.
Re: Bean Counter game script?
I'm a happy Gentoo Linux user and have been so since abt. 2003. Thanks for the hint, maybe I'm gonna grok this after all. It should be rather trivial to parse the log with a Perl script; that's one of the things that I've actually done for a living. Now I'm a retiree and have too much time on my hands.Zuu wrote:A GS can write to the log. If you increase the log level for script source to iirc 5, then you get messages from GS and AIs included.
On Linux you just direct stderr or stdout to a file. Then parse that.
Re: Bean Counter game script?
Good point Zuu, didn't think of that
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: Bean Counter game script?
Here's a quick and dirty savegame unpacker written in Perl. This should be good enough for savegames created with recent versions of OpenTTD, but of course it won't work with the old formats. You'll probably need the IO::Uncompress::UnLzma and IO::Uncompress::RawInflate modules.
The result should be a (hopefully) still valid savegame.
The result should be a (hopefully) still valid savegame.
Re: Bean Counter game script?
Nice I got it working and am browsing the data in Bless.lcd_47 wrote:Here's a quick and dirty savegame unpacker written in Perl. This should be good enough for savegames created with recent versions of OpenTTD, but of course it won't work with the old formats. You'll probably need the IO::Uncompress::UnLzma and IO::Uncompress::RawInflate modules.
The result should be a (hopefully) still valid savegame.
Re: Bean Counter game script?
This just pushes the problem a little further, you still need to decode the RIFF chunks. You probably need to either adapt the program posted by @frosch here, or extend File::Format::RIFF. You might get away with just finding and decoding PLYR chunks, but you'll need to look at the sources for the exact format anyway.
Who is online
Users browsing this forum: No registered users and 5 guests