Variable Vehicle ID

From TTWiki
Jump to navigationJump to search

One problem with many new graphics files is that some files overwrite the same vehicle ID, so they can't normally be used at the same time.

For files with only a few vehicles, it may be feasible to allow them to make the vehicle IDs variable, so that the user can change it such that it doesn't conflict with other active sets.

The way to do this is via action 6, which modifies the action following it from a parameter in the newgrf(w).cfg. Read that page if you're not familiar with action 6 yet.

For example, say you're making a file called mytrain.grf. With using action 6, it may be entered in the newgrf(w).cfg file like this:

...
newgrf/mytrain.grf 18
...

Then you want this parameter, 18, to be used as vehicle ID. For that, you have to use action 6 to change the action 0, action 3 and (if used) action 4 defining that vehicle.

Changing Action 0

The action 0 data (after sprite number and length) is defined like this:

00 <feature> <num-props> <num-info> <id> ...

So you see, the ID is byte number 4. This means we want action 6 to change byte 4 of the action 0 line using newgrf(w).cfg parameter 0, and since action 6 always changes the following sprite, it must come immediately before that action 0. So it might look like this:

34 5 06 00 01 04 FF (action 6, parameter 0, size 1=byte, change byte 4)

35 (13) 00 00 01 08 02 ... (the action 0 to change; the byte to change is in blue; use the actual length of your action 0 of course)

Note that you can just copy and paste; the action 6 from the example, it will work for all action 0's that follow it (since the ID byte is always in the same place). If you want to use a different parameter from newgrf(w).cfg (instead of the first one), change the red byte to the parameter number.

Changing Action 3

This works just the same for action 3 as it did for action 2, which is defined as

03 <feature> <n-id> <ids...>

Normally, you only have one ID here, so the only byte you need to change with action 6 is the third one, like this:

41 5 06 00 01 03 FF

42 (8) 03 00 01 02 ...

Again you can just copy and paste; this action 6, as long as your action 3 only changes a single vehicle.

Changing Action 4

Action 4 is defined as

04 <feature> <language-id> <num-ent> <offset> <text>

so here, the vehicle is defined through the offset, which is byte 4 (just as in the action 0 case), so you'll use this action 6:

43 5 06 00 01 04 FF

44 (25) 04 00 1F 01 02 ...

And that's it. Just copy and paste; the appropriate action 6 line for your file, put them just before the action 0, 3 and 4 and you can have your .grf use a user-specified vehicle ID.