Help for coding a vehicle refit GRF

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
a.locritani
Engineer
Engineer
Posts: 111
Joined: 08 Feb 2007 11:59
Skype: a.locritani
Location: Italy

Help for coding a vehicle refit GRF

Post by a.locritani »

Hi. I'm trying to understand how to code a GRF that improve all default vehicles in order to let them haul new cargos, so you don't need a train set or similar to play with new industries. I'd like to made it functional in both TTDPatch and OTTD

Now, first I have to understand exactly how to do it, so I started reading the wiki and looking in a similar grf of PikkaBird (old wagons, new cargo) in order to better understand. But now I have some doubt: can you please help me?

excluding first pseudo-sprites I found

Code: Select all

    2 * 16	 00 00 03 01 1D 28 10 00 29 01 00 1D 40 20 00 00
this is a coal wagon with a refitting option to transport bulk cargos (28 10 00) excluding fruit and Grain/Wheat/Maize (1D 40 20 00 00) and I understand it (or at least I hope I'm understanding right) but still have a question: why excluding passenger (29 01 00)? aren't they excluded automatically because are not a bulk cargo? and should I add after 29 the liquid cargo code (so excluding bulk and liquid cargos, as fertilizer)?

second question: this line repeats itself for all coal wagons (standard, monorail) but not for maglev wagon but still maglev coal wagon can be refitted, in OTTD. Why?

and finally, third question: why after these codelines a callback and several action 2/action 3 are needed?

Code: Select all

   29 * 122	 00 00 01 74 00 1E 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
	 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
	 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
	 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
   30 * 4	 01 00 01 00
   31 * 9	 02 00 AA 01 01 00 00 00 00
   32 * 14	 02 00 00 81 0C 00 FF 01 28 80 15 15 AA 00
   33 * 7	 03 00 01 1B 00 00 00
   34 * 14	 02 00 00 81 0C 00 FF 01 2D 80 15 15 AA 00
   35 * 7	 03 00 01 39 00 00 00
   36 * 14	 02 00 00 81 0C 00 FF 01 2F 80 15 15 AA 00
   37 * 7	 03 00 01 59 00 00 00
   38 * 14	 02 00 00 81 0C 00 FF 01 1E 80 15 15 AA 00
   39 * 7	 03 00 01 1C 00 00 00
   40 * 14	 02 00 00 81 0C 00 FF 01 23 80 15 15 AA 00
   41 * 7	 03 00 01 3A 00 00 00
   42 * 14	 02 00 00 81 0C 00 FF 01 25 80 15 15 AA 00
   43 * 7	 03 00 01 5A 00 00 00
   44 * 14	 02 00 00 81 0C 00 FF 01 14 80 15 15 AA 00
   45 * 7	 03 00 01 25 00 00 00
   46 * 14	 02 00 00 81 0C 00 FF 01 19 80 15 15 AA 00
   47 * 7	 03 00 01 43 00 00 00
   48 * 14	 02 00 00 81 0C 00 FF 01 1B 80 15 15 AA 00
   49 * 7	 03 00 01 63 00 00 00
   50 * 14	 02 00 00 81 0C 00 FF 01 19 80 15 15 AA 00
   51 * 7	 03 00 01 20 00 00 00
   52 * 14	 02 00 00 81 0C 00 FF 01 1E 80 15 15 AA 00
   53 * 7	 03 00 01 3E 00 00 00
   54 * 14	 02 00 00 81 0C 00 FF 01 20 80 15 15 AA 00
   55 * 7	 03 00 01 5E 00 00 00
I've tried to figure it out looking at the wiki, but I still don't understand. and also, what are those callback? I read about it on wiki and also on wikipedia (in general terms) but i'm still missing something.

Thanks in advance
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Help for coding a vehicle refit GRF

Post by PikkaBird »

Sorry for the late reply, I only just saw this post.
a.locritani wrote:this is a coal wagon with a refitting option to transport bulk cargos (28 10 00) excluding fruit and Grain/Wheat/Maize (1D 40 20 00 00) and I understand it (or at least I hope I'm understanding right)
Correct.
but still have a question: why excluding passenger (29 01 00)? aren't they excluded automatically because are not a bulk cargo? and should I add after 29 the liquid cargo code (so excluding bulk and liquid cargos, as fertilizer)?
After George decided that "Tourists" should be passengers + express cargo, we had a situation where goods vehicles were refittable to tourists. Consequently, I've made it a habit to explicitly exclude passengers from any non-passenger vehicle.

Otherwise, I try to use prop 29 as little as possible, to make sure that there'll always be at least one vehicle that can carry any cargo. My aim with oldwagons-newcargos was maximum compatibility, rather than realism.
second question: this line repeats itself for all coal wagons (standard, monorail) but not for maglev wagon but still maglev coal wagon can be refitted, in OTTD. Why?
The refittability for the maglev coal wagon (5B) is set in sprite 8. Sprites 2 through 10 set the same refittability for the coal, iron ore and copper ore wagons for all three rail types.
and finally, third question: why after these codelines a callback and several action 2/action 3 are needed?
I needed to use a capacity callback (callback 15) for the passenger, mail, valuables and goods vehicles. Without the callback, (O)TTD applies a capacity multiplier when fitting to or from those four cargos.

Code: Select all

// Automatically generated by GRFCODEC. Do not modify!
// (Info version 7)
// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
    0 * 4	 37 00 00 00

    1 * 133	 08 07 44 44 F0 00 "Old Wagons with New Cargos 1.1" 00 "Allows the default trains to be refit to haul new cargos"  0D
    0D
    90 "http://users.tt-forums.net/pikka/wiki/" 00

    // hopper - 1D 23 28 ; 3B 41 46 ; 5B 61 66
                           //  vv
    2 * 16	 00 00 03 01 1D 28 10 00 29 01 00 1D 40 20 00 00
    3 * 16	 00 00 03 01 23 28 10 00 29 01 00 1D 40 20 00 00
    4 * 16	 00 00 03 01 28 28 10 00 29 01 00 1D 40 20 00 00
    5 * 16	 00 00 03 01 3B 28 10 00 29 01 00 1D 40 20 00 00
    6 * 16	 00 00 03 01 41 28 10 00 29 01 00 1D 40 20 00 00
    7 * 16	 00 00 03 01 46 28 10 00 29 01 00 1D 40 20 00 00
    8 * 16	 00 00 03 01 5B 28 10 00 29 01 00 1D 40 20 00 00
    9 * 16	 00 00 03 01 61 28 10 00 29 01 00 1D 40 20 00 00
   10 * 16	 00 00 03 01 66 28 10 00 29 01 00 1D 40 20 00 00

    // tanker - 1E 29 ; 3C 47 ; 5C 67
                           //  vv
   11 * 16	 00 00 03 01 1E 28 40 00 29 01 00 1D 00 00 00 00
   12 * 16	 00 00 03 01 29 28 40 00 29 01 00 1D 00 00 00 00
   13 * 16	 00 00 03 01 3C 28 40 00 29 01 00 1D 00 00 00 00
   14 * 16	 00 00 03 01 47 28 40 00 29 01 00 1D 00 00 00 00
   15 * 16	 00 00 03 01 5C 28 40 00 29 01 00 1D 00 00 00 00
   16 * 16	 00 00 03 01 67 28 40 00 29 01 00 1D 00 00 00 00

    // Goods - 20 3E 5E
                           //  vv
   17 * 16	 00 00 03 01 20 28 A4 00 29 01 00 1D 10 00 00 00
   18 * 16	 00 00 03 01 3E 28 A4 00 29 01 00 1D 10 00 00 00
   19 * 16	 00 00 03 01 5E 28 A4 00 29 01 00 1D 10 00 00 00

    // Pax - 1B 39 59
                           //  vv
   20 * 16	 00 00 03 01 1B 28 01 00 29 00 00 1D 00 00 00 00
   21 * 16	 00 00 03 01 39 28 01 00 29 00 00 1D 00 00 00 00
   22 * 16	 00 00 03 01 59 28 01 00 29 00 00 1D 00 00 00 00

    // Mail - 1C 3A 5A
                           //  vv
   23 * 16	 00 00 03 01 1C 28 02 00 29 01 00 1D 00 00 00 00
   24 * 16	 00 00 03 01 3A 28 02 00 29 01 00 1D 00 00 00 00
   25 * 16	 00 00 03 01 5A 28 02 00 29 01 00 1D 00 00 00 00

    // Arm - 25 43 63
                           //  vv
   26 * 16	 00 00 03 01 1C 28 08 00 29 01 00 1D 00 00 00 00
   27 * 16	 00 00 03 01 3A 28 08 00 29 01 00 1D 00 00 00 00
   28 * 16	 00 00 03 01 5A 28 08 00 29 01 00 1D 00 00 00 00

   29 * 122	 00 00 01 74 00 1E 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
                                   08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
                                   08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
                                   08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
                                   08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
                                   08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
                                   08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
                                   08 08 08 08

   30 * 4	 01 00 01 00 // dummy graphic 
   31 * 9	 02 00 AA 01 01 00 00 00 00

// passenger capacity callback

   32 * 14	 02 00 00 81 0C 00 FF 01 \b40 80 15 15 AA 00 // capacity callback
   33 * 7	 03 00 01 1B 00 00 00

   34 * 14	 02 00 00 81 0C 00 FF 01 \b45 80 15 15 AA 00 // capacity callback
   35 * 7	 03 00 01 39 00 00 00

   36 * 14	 02 00 00 81 0C 00 FF 01 \b47 80 15 15 AA 00 // capacity callback
   37 * 7	 03 00 01 59 00 00 00

// mail capacity callback

   38 * 14	 02 00 00 81 0C 00 FF 01 \b30 80 15 15 AA 00 // capacity callback
   39 * 7	 03 00 01 1C 00 00 00

   40 * 14	 02 00 00 81 0C 00 FF 01 \b35 80 15 15 AA 00 // capacity callback
   41 * 7	 03 00 01 3A 00 00 00

   42 * 14	 02 00 00 81 0C 00 FF 01 \b37 80 15 15 AA 00 // capacity callback
   43 * 7	 03 00 01 5A 00 00 00

// armour capacity callback

   44 * 14	 02 00 00 81 0C 00 FF 01 \b20 80 15 15 AA 00 // capacity callback
   45 * 7	 03 00 01 25 00 00 00

   46 * 14	 02 00 00 81 0C 00 FF 01 \b25 80 15 15 AA 00 // capacity callback
   47 * 7	 03 00 01 43 00 00 00

   48 * 14	 02 00 00 81 0C 00 FF 01 \b27 80 15 15 AA 00 // capacity callback
   49 * 7	 03 00 01 63 00 00 00

// goods capacity callback

   50 * 14	 02 00 00 81 0C 00 FF 01 \b25 80 15 15 AA 00 // capacity callback
   51 * 7	 03 00 01 20 00 00 00

   52 * 14	 02 00 00 81 0C 00 FF 01 \b30 80 15 15 AA 00 // capacity callback
   53 * 7	 03 00 01 3E 00 00 00

   54 * 14	 02 00 00 81 0C 00 FF 01 \b32 80 15 15 AA 00 // capacity callback
   55 * 7	 03 00 01 5E 00 00 00
a.locritani
Engineer
Engineer
Posts: 111
Joined: 08 Feb 2007 11:59
Skype: a.locritani
Location: Italy

Re: Help for coding a vehicle refit GRF

Post by a.locritani »

oh, thanks Pikkabird! Now all is a bit clearer. thank you, thank you very much. Now I'll try to fully understand it, starting from your comments. Thanks again.
a.locritani
Engineer
Engineer
Posts: 111
Joined: 08 Feb 2007 11:59
Skype: a.locritani
Location: Italy

Re: Help for coding a vehicle refit GRF

Post by a.locritani »

after reading and studying and re-reading and re-studing :wink: your post i'm still locked :roll:
you said that this is a capacity callback

Code: Select all

32 * 14    02 00 00 81 0C 00 FF 01 \b40 80 15 15 AA 00 // capacity callback
and I interpret it as a variactional action 2. Is this right?
assuming it's right, I decode it in this way

Code: Select all

02 action 2
00 valid for trains
00 action 2 ID (action 3 refers to it)
81 refer to lowest byte ...
0c of callback id
now i'm lost... according to wiki, the following digits shoul be a varadjust value, in order to do some computation (shift,add,divide,multiply,module) on the variable
so FF should be the shift-mask and so it should right-shift variable by 31 bits (1F) and also make available a shift-and-add-modulo adjustment (80+20+10).
is it right? because i'm start feeling uncomfortable, because I presume (in wrong way?) that \b40 should be number of passenger, so I'm probably misunderstanding what FF means, because there are missing bytes...

thanks for you patience
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Help for coding a vehicle refit GRF

Post by michael blunck »

a.locritani wrote:the following digits shoul be a varadjust value, in order to do some computation (shift,add,divide,multiply,module) on the variable so FF should be the shift-mask
No. "FF" is the AND mask. "00" denotes how many bits to shift. I.e.:

Code: Select all

32 * 14    02 00 00 81 0C 00 FF 01 
                           \b40 80 15 15 // is CB 15, return "40" (hex)
                            AA 00        // graphics
I presume (in wrong way?) that \b40 should be number of passenger,
That´s right. The callback returns 40h (64 dec).

HTH
regards
Michael
Image
a.locritani
Engineer
Engineer
Posts: 111
Joined: 08 Feb 2007 11:59
Skype: a.locritani
Location: Italy

Re: Help for coding a vehicle refit GRF

Post by a.locritani »

Thanks, Michael.
\b40 should be 40 (dec) that is 28 hex. this is also the real capacity of passenger car.

also, I presume that \b40 80 is the result of callback (number + 80, to denote a callback return). the previous 01 is, quoting the wiki, "Number of different ranges of the value". is 15 15 the range? so, min and max extremes of range? i think so.

so if i understand correctly the whole sequences, it says that if I call the refit callback (which code is 15) I obtain 40 (dec), otherwise I obtain a "dummy graphic" (so I obtain nothing). Using the following action3 I apply this "property" to a wagon.

Now, this is valid if I refit to/from passenger,mail,valuables and goods (as pikka said). If i refit to other cargos, capacity is retained unchanged (ie: 1 ton of coal = 1 ton of other cargo)?

Thanks a lot
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Help for coding a vehicle refit GRF

Post by michael blunck »

a.locritani wrote:I presume that \b40 80 is the result of callback (number + 80, to denote a callback return).
Yes.
the previous 01 is, quoting the wiki, "Number of different ranges of the value". is 15 15 the range? so, min and max extremes of range? i think so.
Correct.
so if i understand correctly the whole sequences, it says that if I call the refit callback (which code is 15) I obtain 40 (dec), otherwise I obtain a "dummy graphic" (so I obtain nothing). Using the following action3 I apply this "property" to a wagon.
Not quite. First you check variable C0 which will give you the number of the active callback (if any) and then you branch according to the number of that CB (e.g. 15) and handle it, or, if no callback is flagged (or one that you don´t handle), you proceed with the graphics branch (which lets any other CB fail automatically, because a normal c-ID hasn´t set bit15). I.e.:

Code: Select all

32 * 14	02 00 00 81 0C 00 FF 01 
            40 80 15 15	// is CB 15, handle it: return "40" (hex)
            AA 00	      // graphics, resp all other CBs fail. 
Now, this is valid if I refit to/from passenger,mail,valuables and goods (as pikka said). If i refit to other cargos, capacity is retained unchanged (ie: 1 ton of coal = 1 ton of other cargo)?
Well, ton is ton. OTOH, space would be decisive as well: you won´t load 30 tons of wool into a small box car. That´s why you may use CB15 to set capacity according to cargo type. I.e.:

Code: Select all

// livestock
32 * 14    02 00 01 81 0C 00 FF 01 
            08 80 15 15	// 8 pieces of livestock
            00 00	      // graphics. 

// goods
33 * 14	02 00 02 81 0C 00 FF 01
            14 80 15 15	// 20 crates of goods
            00 00		   // graphics. 

// wood
34 * 14	02 00 03 81 0C 00 FF 01 
            04 80 15 15	// 4 tons of wood
            00 00		   // graphics. 

35 * 16	03 00 01 02 03 
            04 01 00	// livestock
            05 02 00	// goods
            07 03 00	// wood 
            00 00	   // other
And read this one.

HTH
regards
Michael
Image
a.locritani
Engineer
Engineer
Posts: 111
Joined: 08 Feb 2007 11:59
Skype: a.locritani
Location: Italy

Re: Help for coding a vehicle refit GRF

Post by a.locritani »

thanks, i've already read tutorial you suggest me but maybe i should re-read it. :roll:
thanks for all your help :bow:
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Help for coding a vehicle refit GRF

Post by michael blunck »

a.locritani wrote:thanks, i've already read tutorial you suggest me but maybe i should re-read it. :roll:
I´ve added a couple of new examples, so this may be indeed a good idea.

regards
Michael
Image
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: No registered users and 10 guests