This is TikiWiki 1.9.2 -Sirius- © 2002–2005 by the Tiki community Fri 03 of Sep, 2010 [09:43 UTC]
TTDPatch Site

Action7

Conditionally skip sprites or jump to label Deutsch print
history

Action 7 & Action 9

Conditionally skip sprites or jump to label

Description

These two actions allow you to skip a specified number or all following sprites in this .grf file. This can be used to have, for example, climate-specific graphics, patch-version checks and error messages, and deactivating in the presence of other active .grf files.

Format

The data looks as follows:

<sprite-number> * <length> [07/09] <variable> <varsize> <condition-type> <value> <num-sprites>



ElementSizeDescription
<sprite-number>decA sequential sprite number
<length>decThe total number of bytes in the action
07/09BAction type. In this case, 07 or 09
<variable>BWhich variable to base the decision on
<varsize>BHow many bytes to read from the variable
<condition-type>BWhat condition to check
<value>VValue to compare with (size equals <varsize>)
<num-sprites>BHow many sprites to skip


Filling in the terms

sprite-number

The current sprite number.

length

The total number of bytes in this action 7 or 9.

action

The type of action this pseudo-sprites defines. It is either 07 or 09, depending if you are using action 7 or action 9.

Both have identical format, the only difference is whether sprites will be skipped during the initialisation of the TTDPatch graphics system, or only when the .grf file becomes active.

Action 9 is always executed, both during initialisation and activation, but action 7 is executed only during activation.

Depending on the action(s) you want to skip, you cannot always use both actions. If in doubt, use action 7 except to skip an action 6 or F. You must not skip an action 2 at all unless skipping the entire rest of the file. Instead, skip the action 3 that refers to it.

Here's a table showing this whole action 7/9 issue:

Action to skipwith 7with 9notes
0 (new props)yesyes
1 (sprite blk)yesyes
2 (cargo ID)n/a*no* skip the corresponding action 3 instead
3 (veh ID map)yes*no* can't skip a livery override without skipping the main engine action 3 as well
4 (veh names)yesno
5 (sprite blk)yesyes
6 (apply param)n/a*yes* "yes" since 2.0.1 alpha 51
7 (skip sprite)yesyes
8 (GRF ID)yesyes
9 (skip sprite)yes*yes* not during initialization, of course
A (repl.sprite)yesyes
B (error msg)yesyes
C (NOP)yesyes
D (set param)yes*yes* not if parameter will be used in action 6 (except for 2.0.1 alpha 51 and higher)
E (deact.GRFs)yesyes
F (town names)n/ayes
10 (goto labels)n/ano
11 (sound fx)n/ano
12 (glyphs)yesyes


Yes=safe to skip
No=not safe to skip, will break the grf file or TTDPatch
N/A=not applicable; it won't break anything, but it won't actually be skipped either (in other words, its definitions will continue to be used)

variable

This sets the variable to base the decision on. It can be either one of the GRF parameters (see action 6), or a built-in patch variable. If it's a GRF parameter that wasn't specified in the newgrf(w).cfg file, or variable 88 with a GRFID that doesn't exist, the action 7 or 9 is ignored and no sprites are skipped, the only exception being condition type 0A which will skip the sprites if the GRFID doesn't exist as well.

VariableSizeDescription
81Bcurrent year (count from 1920, max. 2175 even with eternalgame)
83BCurrent climate: 00 = temp, 01 = arctic, 02 = trop, 03 = toyland
84DGRF loading stage, see below
85BTTDPatch flags: only for bit tests
86BRoad traffic side: bit 4 clear=left, set=right
884*BChecks specified GRFID (see condition-types below)
8BDTTDPatch version, see below
8DBTTD version, 0=DOS, 1=Windows
8EBY-Offset for train sprites
8F4*BRail track type cost factors
92BGame mode, 0 in title screen, 1 in game and 2 in editor
93DTile refresh offset to left
94DTile refresh offset to right
95DTile refresh offset upwards
96DTile refresh offset downwards
9ADHas always all bits set; you can use this to make unconditional jumps
9DDTTD Platform, 0=TTDPatch, 1=OpenTTD
A1DOpenTTD version, see below.
A2DDifficulty level: 00= easy, 01=medium, 02=hard, 03=custom, since r12449 for OpenTTD and r1857 for TTDPatch
A3DCurrent date(4); long format, since r13376 in OpenTTD and r2048 in TTDPatch
A4DCurrent year(4); long format, year zero based since r13376 in OpenTTD and r2048 in TTDPatch


Note 1: All other parameter values greater than 80 (hexadecimal) are reserved and must not be used in action 7 or 9.
Note 2: The value of variable 88 can only be tested with the GRFID tests.
Note 3: The tile refresh offsets are available from 2.0.1 alpha 39. See Action D for more details on their use.
Note 4: OpenTTD doesn't report the current date and year but the date and year the game was loaded. The reason lies in the fact that it was seen that use of this variable leads to desyncs in network games.

Variable 84 is a BYTE variable up to TTDPatch 2.5r1220. Its lower byte (bits 0..7) are 0 for the post-load and GRF initialization stages and 01 for all other stages. The remaining bits are a bitmask, and including the lower byte have the following meaning:

BitMeaning
0Set after the "Initialization" stage completes
1..7Always clear
8Set during the "Reserve" stage only
9Set during the "Activate" stage only
10Set during the "Test" stage only


Variable 8B has the following format: MMmrbbbb (though encoded in little endian as bb bb mr MM)

ElementMeaningValue
MMmajorFirst number of the TTDPatch version
mminorSecond number of the TTDPatch version
rrevisionThird number of the TTDPatch version*
bbbbbuildAlpha/beta version number times ten (up to an including 2.5 beta 5), SVN revision (from 2.5 beta 5 r418 on)


Examples
VersionVariable 8BElements
1.9.1 alpha 50019101F4 MM=01, m=9, r=1, bbbb=50*10=01F4
2.0 beta 402040028MM=02, m=0, r=4*, bbbb=4*10=0028
2.0 final02070046MM=02, m=0, r=7*, bbbb=70=0046
2.0 rev 102070050MM=02, m=0, r=7*, bbbb=80=0050
2.0.1 alpha 3020A001EMM=02, m=0, r=10*, bbbb=3*10=001E
2.5 beta 202500014MM=02, m=5, r=0, bbbb=2*10=0014
2.5 rev63102500631MM=02, m=5, r=0, bbbb=631=0631


* For 2.0, r=7 and for 2.0.1 series, r=10 due to an oversight which used r=1..4 for 2.0 beta 1..4.

To detect versions from 2.5 rev419 and up correctly, check that var. 8B is 02500419 or higher, or replace 0419 with the actual required revision (using the revision number as hex digits). Because SVN revisions are shared with other patch branches, it is important to check the actual patch version as well as the SVN revision.


Variable A1 has the following format: Mmrbbbbb (though encoded in little endian as bb bb rb Mm). This variable has only a usefull meaning when variable 9D is 1 (OpenTTD). This variable can be used since OpenTTD r11330.

ElementMeaningValue
MmajorFirst number of the OpenTTD version
mminorSecond number of the OpenTTD version
rrevisionThird number of the OpenTTD version
bbbbbbuildSubversion revision of a build leading towards a release. When a final release is done 80000h is set.

The presence of 80000h (bit 19 set) means that a release always has a higher version number than any builds leading to that release.

Examples
VersionVariable A1Elements
0.6.0 r1133006002C42M=0, m=6, r=0, bbbbb=11330=2C42
0.6.0 (release)06080000M=0, m=6, r=0, bbbbb=0=80000 (due to release)


varsize

For GRF parameters, this is the same as <param-size> in action 6. For built-in variables, it depends on the variable, see the above table.

For bit tests, this size is ignored. Value must be a BYTE for bit tests, no matter what the size of the variable being tested.

Since r1384 it is possible to set this to 8 bytes with Variable 88 thus allowing the use of a bit mask. This is useful for if only a few bits change over several grfs.

condition-type

There are several conditions you can choose from to test against. This has an escape sequence for each valid value. See the discussion of escape sequences for further information on escape sequences in general. For your convenience they are summed up in yet another table:

Condition typeEscapeDescription
00\71Test for bit given by value being set
01\70Test for bit given by value being clear
02\7=Parameter is equal to value
03\7!Parameter is not equal to value
04\7<Parameter is less than value
05\7>Parameter is greater than value
06\7GGRF ID (see action 8) is active (for variable 88 only)
07\7gGRF ID is not active (for variable 88 only)
08\7gGGRF ID is not active yet but will be activated (variable 88 only)
09\7GGGRF ID is or will be active (variable 88 only)
0A\7ggGRF ID is not nor will it be active (variable 88 only)
0B\7cCargo type is not available (variable is ignored)*
0C\7CCargo type is available (variable is ignored)*
0D Rail type label is not defined (variable is ignored)**
0E Rail type label is defined (variable is ignored)**

Note that for the characters, a capital letter means available, and a lowercase character means not available. For the two character GRFid sequences, the first character is its current state, and the second is its future state.

* Prior to r11358, OTTD will skip these checks with variable 88.
** Only in OpenTTD since r15418.

The tests for variable 88 depend on the current GRF Loading Stage, the order GRFs are loaded, and of course whether they are present or were disabled (by themself or by other GRFs). Consider two GRFs A and B (loaded in that order):

Condition |                Initialisation                 |             Reservation/Activation            |
          |    A testing for B    |    B testing for A    |    A testing for B    |    B testing for A    |
----------+-----------------------+-----------------------+-----------------------+-----------------------|
06  \7G   | always false          | always false          | always false          | A not disabled?       |
07  \7g   | always true           | always true           | always true           | A disabled?           |
08  \7gG  | always false          | A not (yet) disabled? | B not (yet) disabled? | always false          |
09  \7GG  | always false          | A not (yet) disabled? | B not (yet) disabled? | A not disabled?       |
0A  \7gg  | B (already) disabled? | A (already) disabled? | B (already) disabled? | A disabled?           |

"Disabled" and "not present" are the same in this context.

value

This term is what the variable is compared to. Its size is given by <varsize>.

For bit tests (condition types 00 or 01), it must always be a single BYTE for bit tests and specifies the bit to test.

For conditions 0B and (since 2.0.1 alpha 72) 0C, the variable given is ignored (but must be a valid variable nonetheless), the varsize must be 4 and the value must be the cargo label to check for. If no cargo with this label is defined in case of condition 0B, the given number of sprites are skipped. For condition 0C, the sprites are skipped if the cargo label has been defined. Both tests work irrespective of the order of .grf files in newgrf(w).cfg; the cargo is considered to be available even if it is defined by a later grf file. For this to work correctly, you must not skip a cargo definition with conditions 0B or 0C.

Since r1384, setting varsize to 8, changes value slightly, the first 4 bytes are the value (generalised grfid), and the next 4 bytes are a bit mask for the grfids to check. Please note you should make sure any masked bits are also not in the grfid to check, as value to check against is not currently masked.

num-sprites

This element sets how many sprites will be skipped if the condition is true. If num-sprites is zero, the entire rest of the .grf file will be skipped, otherwise exactly that many sprites will be skipped. If this causes action 8 to be skipped, the .grf file will be deemed inactive.

If the condition is false, processing continues at the following sprite.

Starting from TTDPatch 2.0.1 alpha 49, it is possible to jump to a certain position in the grf file by defining labels with action 10. If num-sprites is the number of a label defined somewhere in the file, then processing of the grf file resumes with the sprite following the label, instead of skipping that many sprites. This is the only way to skip more than 255 sprites at once.

Since 2.0.1 alpha 70, duplicate labels are fully supported. The jump will always be to the first matching label that follows. If no matching label follows, the first matching label in the file will be used instead.

Note that it is generally not safe to skip backwards, i.e. to an earlier position. While the patch will happily do that, you will get strange results if certain actions are repeated. Only action 0, 6, 7, 9, C and D are reasonably safe to execute more than once.

Example

Let's start with an easy Action 7:

47 * 6 07 83 01 03 00 00

What does this Action 7 tells TTDPatch to do with the fictional .grf file?

ByteMeaning
47<sprite-number>
6<length> of the action in bytes; start counting at 07 (<action>)
07<action>: sets this pseudo-sprite to function as action 7
83<variable> 83 refers to the 4 different climates
01<varsize>: amount of bytes to compare; a single byte for the climate
03<condition-type> 03 means skip if the variable is not equal to the <value>
00<value> 00 equals temperate climate for this variable
00<num-sprites> 00 means to skip the whole .grf file if the condition is true, i.e. for all climates except temperate in this case


Therefore, this action 7 skips the rest of the file if it is being loaded in a climate other than the temperate climate.


Patch version check

Due to action 7 being skipped during initalization, and action B severity bit 7 not working before 2.0.1 alpha 66, the best way to check for the required patch version is the following sequence:
   // Check for 2.0.1 alpha 57, skip action B if present
1 * 9       09 8B 04 05 39 02 0A 02 01
   // Abort with fatal action B if not (during its first activation)
2 * 19      0B 03 1F 00 32 2E 30 2E 31 20 61 6C 70 68 61 20 35 37 00
   // Action 8
3 * ...     08 06 ...
   // Skip rest of file if not 2.0.1 alpha 57,
   // to prevent meaningless "invalid sprite" errors
4 * 9       09 8B 04 04 3A 02 0A 02 00

This way the GRF Status entry shows the proper error message as well as the correct name and description because the action 8 is still being processed during initialization, and all unknown sprites are skipped so that the "invalid sprites" error message is not shown first (or else it would become the permanent message shown in the GRF Status Window).


Unconditional jump

Var 9A always has all bits set, so to make an unconditional jump you can use a bit test:
1 * 7   07 9A 01 00 00 01
resp.
1 * 7   07 9A 01 \71 00 01

What this does is that it checks if bit 0 from the first byte of variable 9A is set (which it always is), so the sprite which you put after this action 7 is always skipped.

Created by: system last modification: Thursday 01 of July, 2010 [13:39:53 UTC] by planetmaker


Menu
[ Execution time: 0.30 secs ]   [ Memory usage: 11.26MB ]   [ 87 database queries used ]   [ GZIP Enabled ]   [ Server load: 1.39 ]