[GS] FGVersionController

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
idioty
Engineer
Engineer
Posts: 59
Joined: 21 Jun 2010 11:54

[GS] FGVersionController

Post by idioty »

This library help to use new features of GS, while the old versions of OpenTTD remain supported.

Version 2 is available!
Special thanks for the help of krinn.

And usage is simple:
create an instance of this class (with minimum supported system):

Code: Select all

this.versionController = FGVersionController(1, 3, 1);
and example tests:

Code: Select all

if (this.versionController.IsCurrentVersionLessThan(1, 3, 0) {…}
if (this.versionController.IsCurrentVersionGreatherThanOrEqualTo(1, 3, 0)) {. . .}
Full documentation: http://feca.homedns.org/documentations/ ... index.html
lastest version available:
Bananas download link: http://binaries.openttd.org/bananas/gsl ... r-2.tar.gz
Last edited by idioty on 03 Nov 2013 11:28, edited 1 time in total.
Sorry my bad english, I don't speak english!
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: [GS] FGVersionController

Post by krinn »

Why hardcoding openttd versions like that, that's somehow strange.
Would be easier (and better no update need when new openttd version is out) to simply :

user_maj = user_maj << 8;
user_min = user_min << 4;
user_version = user_maj + user_min + user_build;

ottd_version = AIController.GetVersion() >> 0x14;
ottd_maj = ottd_version & 0xf00;
ottd_min = ottd_version & 0xf0;
ottd_build = ottd_version & 0xf;

now you can easy compare : ottd_version < user_version...
idioty
Engineer
Engineer
Posts: 59
Joined: 21 Jun 2010 11:54

Re: [GS] FGVersionController

Post by idioty »

Thanks!
That it is a good idea! There's something to learn! :D

But this does'nt work for me:

Code: Select all

ottd_version = AIController.GetVersion() >> 0x14;
ottd_maj = ottd_version & 0xf00;
ottd_min = ottd_version & 0xf0;
ottd_build = ottd_version & 0xf;
But I found a solution on this forum:

Code: Select all

local v = GSController.GetVersion();
local major =   (v & 0xF0000000) >> 28;
local minor =   (v & 0x0F000000) >> 24;
local build =   (v & 0x00F00000) >> 20;
local release = (v & 0x00080000) != 0;
local revision = v & 0x0007FFFF;
And this work! Thanks again for the replay.
I will write a special thanks for you in the next release :D :bow:

this is the topic:
http://www.tt-forums.net/viewtopic.php? ... on#p787612
Sorry my bad english, I don't speak english!
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: [GS] FGVersionController

Post by krinn »

You're welcome.
BTW, did you check AI/GSInfo.GetAPIVersion setting ? Because it should solve the need to check openttd version.
idioty
Engineer
Engineer
Posts: 59
Joined: 21 Jun 2010 11:54

Re: [GS] FGVersionController

Post by idioty »

I do not think is necessary, because I set the minimum was 1.2 Api version.
This is GS only and the GS available only from 1.2 version.
And the user can set the minimum script requirement.
In my game script is 1.3.0 because I need the GSCargoMonitor.
Sorry my bad english, I don't speak english!
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [GS] FGVersionController

Post by Zuu »

An alternative to checking for OpenTTD version is to check for the availability of an API method.

Code: Select all

if ("GetName" in GSTown) { /* do something */ }
If you need to check for an entire class you need to use some magic by krinn included in SuperLib.Story.IsStoryBookAvailable().

If you plan to check for availability of StoryBook, I recommend using SuperLib.Story.IsStoryBookAvailable() because it will return false for some revisions when the API is available but there was a save/load bug in the Story book feature causing trouble at loading. So it is best to just not use the Story Book feature at those revisions and rely on the above mentioned method to detect if a user has a new enough nighly/release. As long as you obey GPL v2, you can of course copy this check method from SuperLib if you do not want to add it as dependency for just this method.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
idioty
Engineer
Engineer
Posts: 59
Joined: 21 Jun 2010 11:54

Re: [GS] FGVersionController

Post by idioty »

I understand, but I think the nigthly edition contains many errors, and users know this.
My source code is included in the new API options, but I do not recommend the use of going live.
And users are aware that (I guess).
Sorry my bad english, I don't speak english!
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [GS] FGVersionController

Post by Lord Aro »

Nightly/trunk usually doesn't actually contain anymore bugs than stable (other than the rare build breaking bugs) I would say a fair proportion of users use nightly as their main version (I do)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
idioty
Engineer
Engineer
Posts: 59
Joined: 21 Jun 2010 11:54

Re: [GS] FGVersionController

Post by idioty »

I am also think same way.

And why it's better

Code: Select all

if (("GetName" in GSTown) && ("FoundTown" in GSTown) && ...  {}
than

Code: Select all

if (this.versionController.IsCurrentVersionGreatherThanOrEqualTo(1, 4, 0) {}
?

Actually, no matter, I wrote to myself :D
Sorry my bad english, I don't speak english!
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 6 guests