Page 1 of 1

OpenTTD Version Check

Posted: 22 Oct 2007 21:07
by FooBar
As it seems we should now be able to check the OTTD version number.
Commit by rubidium :: r11330 /trunk/ (6 files in 4 dirs): wrote:-Add: OTTD version checking for NewGRFs. This allows NewGRFs to do something different for different versions of OpenTTD, like disabling it for too low versions or loading different graphics.
I figured I should use it in my GRF to disable an error message (action B). This works as expected in builds which support version checking, but gives me troubles in builds without it (i.e. < r11330).

Seems Action 7 Variable A1 evaluates as 'true' in builds without Action 7 Var A1 support, rendering it useless (to me). Is this normal behaviour, or am I doing something wrong?

Little example:

Code: Select all

-1 * 0 07 A1 04 \7> 41 2C 00 06 01
-1 * 0 0B 00 7F FF "Notice: This set requires OpenTTD r10549 or higher." 00
The first line of code checks the OTTD version number. The comparison value is set to 41 2C 00 06 (or 0.6.0 r11329). If the version number is higher than the one specified, the next sprite should be skipped.
Using r11339 it skips the error message as expected.
Using r11293 it _also_ skips the error message, and that's exactly what I don't want it to do.

If this normal behaviour, is there an other method to disable that error message in rxxxxx and up, and still having it displayed in versions < r10549?

Re: OpenTTD Version Check

Posted: 23 Oct 2007 01:11
by DaleStan
That is, I believe, as specified. Use of undefined variables causes the jump to be ignored. I think the appropriate solution is two action 7/9s:

Code: Select all

-1 * 0 07 A1 04 \7< \w10549 00 06 01
-1 * 0 07 A1 04 \7> \d0 01
-1 * 0 0B 00 7F FF "Notice: This set requires OpenTTD r10549 or higher." 00
This skips to the action B if A1 is defined and too small, and then skips over the action B if A1 is defined (and therefore sufficiently large).

Note that above I'm testing for the specified revision, not the first revision where A1 is defined. This is functionally equivalent, and, IMO, easier to follow.

Re: OpenTTD Version Check

Posted: 23 Oct 2007 07:30
by Wile E. Coyote
It's probably OT, but I haven't found nothing with search: which checks in Actions 7/9 are supported? Is it supported check is cargo type available?
(There is nothing in Wiki about Action 7/9 support; nothing is written, so I suppose there is no support for check above.)

Re: OpenTTD Version Check

Posted: 23 Oct 2007 10:53
by FooBar
Thanks for you reply, DaleStan, but that didn't work either. For some reason, older versions still skip the message.

By trial and error I came to this:

Code: Select all

-1 * 0 07 A1 04 \7< \w10548 00 06 01
-1 * 0 0B 00 7F FF "Notice: Version not detected." 00
This gives an error in r11339 (as expected) AND an error in r10166.

This got me thinking that var A1 could as well be a very big value in pre-r11330, possibly FF FF FF FF.

With that in mind, I tried this:

Code: Select all

-1 * 0 07 A1 04 \7= FF FF FF FF 01
-1 * 0 07 A1 04 \7> \w10548 00 06 01
-1 * 0 0B 00 7F FF "Notice: Version not detected." 00
So if A1 is undefined (or FF FF FF FF), the real check gets skipped resulting in an notice being displayed.
If A1 is defined (r11330 or higher), the real check is executed, resulting in the notice being skipped.


I attached a small grf containing this code. It does the wonderful job of determining if the OTTD version can be determined*. So it's pretty useless indeed, but it gives an idea on how to put var A1 to good use.

*) Does not work on OTTD versions without Action B support. Well, maybe it does, but it can't display the result.


@Wile E.
Are you looking in the NewGRF Specs Wiki? It's true that the OpenTTD Wiki doesn't have anything useful on creating GRFs.

Re: OpenTTD Version Check

Posted: 23 Oct 2007 11:04
by Wile E. Coyote
FooBar wrote:@Wile E.
Are you looking in the NewGRF Specs Wiki? It's true that the OpenTTD Wiki doesn't have anything useful on creating GRFs.
Yes, but there is also nothing about OTTD support (except, of course, var. A1).
I'm interested which <variable> and <condition-type> are supported, in this case especially <condition-type> \7c and \7C (testing availability of cargos).

EDIT: Here is example:

Code: Select all

 3063 * 9	 07 88 04 \7C "TOUR" 08 //is cargo labeled "TOUR" available (<condition-type> \7C)? If yes, skip next 8 sprites
 3064 * 7	 00 00 01 01 31 06 00   //those 8 sprites make vehicles carrying this cargo unavailable (their climate is set to 0)
 3065 * 7	 00 00 01 01 32 06 00
 3066 * 7	 00 00 01 01 33 06 00
 3067 * 7	 00 00 01 01 45 06 00
 3068 * 7	 00 00 01 01 48 06 00
 3069 * 7	 00 00 01 01 63 06 00
 3070 * 7	 00 00 01 01 64 06 00
 3071 * 7	 00 00 01 01 65 06 00
So, if OTTD don't recognizes <condition-type> \7C, it simply ignores sprite 3063, and goes ahead. Thus following 8 vehicles will be no available even if cargo labeled "TOUR" is present.

Re: OpenTTD Version Check

Posted: 23 Oct 2007 11:31
by Rubidium
What version of OpenTTD are you talking about in this case? Because it should be working in current trunk, or basically everything since newcargos has been implemented. It will, however, not work in "old" (read: 0.5.3) versions where newcargos is not implemented.

Re: OpenTTD Version Check

Posted: 23 Oct 2007 11:52
by Wile E. Coyote
:oops: Sorry, I forgot to state version, it's Nightly 11255.

Re: OpenTTD Version Check

Posted: 24 Oct 2007 20:31
by Rubidium
It is actually implemented. Maybe the implementation is broken. What does it do when you pass it the inverse of "TOUR", i.e. "RUOT"?

Re: OpenTTD Version Check

Posted: 25 Oct 2007 07:38
by Wile E. Coyote
I've just downloaded new Nightly (11339) and I'll check everything and inform you.

EDIT: I checked with both "TOUR" and "RUOT" labels. In both cases there were no vehicles appear, so it seems that check is skipped. I must note that under Patch everything is OK.