Difference between revisions of "Variable Vehicle ID"

From TTWiki
Jump to navigationJump to search
m (5 revisions)
 
(Reformat and update)
Line 1: Line 1:
 
'''''How to implement grfs with variable vehicle IDs'''''
 
 
=Variable Vehicle ID=
 
 
 
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.
 
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.
 
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 [[Action6|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.
+
The way to do this is via [[grfspecs:Action6|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:
 
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:
   
<pre>-+...+-
+
<pre>...
 
newgrf/mytrain.grf 18
 
 
...</pre>
-+newgrf/mytrain.grf 18+-
 
 
-+...+-</pre>
 
   
Then you want this parameter, 18, to be used as vehicle ID. &nbsp;For that, you have to use action 6 to change the action 0, action 3 and (if used) action 4 defining that vehicle.
+
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==
 
==Changing Action 0==
Line 24: Line 17:
 
The action 0 data (after sprite number and length) is defined like this:
 
The action 0 data (after sprite number and length) is defined like this:
   
-+00 &lt;feature&gt; &lt;num-props&gt; &lt;num-info&gt; &lt;id&gt; ...+-
+
<tt>00 <feature> <num-props> <num-info> <id> ...</tt>
   
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. &nbsp;So it might look like this:
+
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:
   
<pre>-+ &nbsp;34 5 &nbsp; 06 <span style='color:red'>00</span> 01 <span style='color:blue'>04</span> FF+- (action 6, parameter <span style='color:red'>0</span>, size 1=byte, change byte <span style='color:blue'>4</span>)
+
<tt> 34 5 06 <span style='color:red'>00</span> 01 <span style='color:blue'>04</span> FF</tt> (action 6, parameter <span style='color:red'>0</span>, size 1=byte, change byte <span style='color:blue'>4</span>)
   
-+35 (13) &nbsp; 00 00 01 08 <span style='color:blue'>02</span> ...+- (the action 0 to change; the byte to change is in blue; use the actual length of your action 0 of course)</pre>
+
<tt>35 (13) 00 00 01 08 <span style='color:blue'>02</span> ...</tt> (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&amp;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.
+
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==
 
==Changing Action 3==
Line 38: Line 31:
 
This works just the same for action 3 as it did for action 2, which is defined as
 
This works just the same for action 3 as it did for action 2, which is defined as
   
-+03 &lt;feature&gt; &lt;n-id&gt; &lt;ids...&gt;+-
+
<tt>03 <feature> <n-id> <ids...></tt>
   
 
Normally, you only have one ID here, so the only byte you need to change with action 6 is the third one, like this:
 
Normally, you only have one ID here, so the only byte you need to change with action 6 is the third one, like this:
   
<pre>-+ 41 5 &nbsp;06 <span style='color:red'>00</span> 01 <span style='color:blue'>03</span> FF+-
+
<tt> 41 5 06 <span style='color:red'>00</span> 01 <span style='color:blue'>03</span> FF</tt>
   
-+42 &nbsp;(8) &nbsp; 03 00 01 <span style='color:blue'>02</span> ...+-</pre>
+
<tt>42 (8) 03 00 01 <span style='color:blue'>02</span> ...</tt>
   
Again you can just copy&amp;paste; this action 6, as long as your action 3 only changes a single vehicle.
+
Again you can just copy and paste; this action 6, as long as your action 3 only changes a single vehicle.
   
 
==Changing Action 4==
 
==Changing Action 4==
Line 52: Line 45:
 
Action 4 is defined as
 
Action 4 is defined as
   
-+ 04 &lt;feature&gt; &lt;language-id&gt; &lt;num-ent&gt; &lt;offset&gt; &lt;text&gt;+-
+
<tt> 04 <feature> <language-id> <num-ent> <offset> <text></tt>
   
 
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:
 
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:
   
<pre>-+43 &nbsp;5 &nbsp;06 <span style='color:red'>00</span> 01 <span style='color:blue'>04</span> FF+-
+
<tt>43 5 06 <span style='color:red'>00</span> 01 <span style='color:blue'>04</span> FF</tt>
   
-+44 &nbsp;(25) &nbsp;04 00 1F 01 <span style='color:blue'>02</span> ...+-</pre>
+
<tt>44 (25) 04 00 1F 01 <span style='color:blue'>02</span> ...</tt>
   
And that's it. &nbsp;Just copy&amp;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.
+
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.
  +
[[Category:Tutorials]][[Category:GRF Tutorial]]

Revision as of 17:09, 30 July 2011

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.