NOTE: Due to recent changes in the newobjects specifications and the addition of OpenTTD support, the coding guide
WILL BE REVISED, just as soon as I get around to it.
NOTE: IT IS ASSUMED THAT THE CODER IS FAMILIAR WITH GRF NFO CODING.
THIS TUTORIAL IS MERELY A STRATEGY GUIDE FOR CODING NEWOBJECTS.
TTDPatch.cfg (minimum r2330) must have newobjects
on
Rather than repeat a lot of information that is available elsewhere, I have extensively commented the nfo file which includes links to the appropriate TTDPatch wiki Action discussion ... simply copy and paste into your browser's address line.
Anybody familiar with house, industry and/or station coding should be comfortable with this presentation.
The Action0 property 08 is a special case and is discussed in the following post.
The sprites are coloured and numbered cubes which will aid in recognizing how it all goes together.
NOTE: The code below has benefited from a little revision suggested (with thanks

) by Michael Blunck and eis_os.
In the Action 0 properties 09 and 0A, D4 was changed to D0.
In the Action 4, "Ð[text]" was changed to D0 "[text]".
Code: Select all
// Automatically generated by GRFCODEC. Do not modify!
// (Info version 7)
// Escapes: 2+ = 71 = D= = DR 2- = 70 = D+ = DF 2< = 7= = D- = DC 2> = 7! = Du* = DM 2u< = 7< = D* = DnF 2u> = 7> = Du<< = DnC 2/ = 7G = D<< = DO 2% = 7g = D& 2u/ = 7gG = D| 2u% = 7GG = Du/ 2* = 7gg = D/ 2& = 7c = Du% 2| = 7C = D% 2^ 2sto = 2s 2rst = 2r 2+ 2ror = 2rot
// Newobject Tutorial nfo file by Walter E. Bamberger
// With the assistance of Lakie who shall receive cookies
// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
0 * 4 47 00 00 00
//=====================================================================================
// NOTE: IT IS ASSUMED THAT THE CODER IS FAMILIAR WITH GRF NFO CODING.
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=NewGraphicsSpecs
// THIS TUTORIAL IS MERELY A STRATEGY GUIDE FOR CODING NEWOBJECTS.
// TDPatch.cfg (r2321) must have newobjects on
//=====================================================================================
// Action 8 Define GRF ID, Name and Description
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=Action8
// <sprite-number> * <length> 08 <version> <grf-id> <name> <description>
1 * 63 08 07 "WB" 99 10 "Wally's Newobjects Tutorial v1.2" 00 "© 2010 Walter Bamberger" 00
//=====================================================================================
//All of the code in this file is freely available from the TTDPatch NewGraphicsSpecs pages and may be copied and/or modified at will.
//The cube graphics were created by me but they are very generic and the pcx file may be copied and/or modified at will.
//Credit would be nice but is not required.
//=====================================================================================
// Action 0 Defining new graphics feature properties
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=Action0
// Properties link: http://wiki.ttdpatch.net/tiki-index.php?page=Action0Objects
// <Sprite-number> * <Length> 00 <Feature> <Num-props> <Num-info> <Id> (<Property <New-info>)...
2 * 161 00 0F 09 07 00
08 "CUBE" "CBX2" "CBX2" "CBX3" "CBX3" "CBXX" "CBXX"
09 00 D0 02 D0 02 D0 05 D0 05 D0 08 D0 08 D0
0A 01 D0 03 D0 04 D0 06 D0 07 D0 09 D0 0A D0
0B 01 01 01 01 01 01 01
0C 11 12 21 13 31 22 33
0D 0C 0C 0C 0C 0C 0C 0C
0E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
10 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//=====================================================================================
// Object
// Action 1 Define a set of real sprites
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=Action1
// <Sprite-number> * <Length> 01 <feature> <num-sets> <num-ent>
3 * 4 01 0F 09 01
// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
4 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 80 8 09 64 64 -31 -33 // 0 0
5 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 160 8 09 64 64 -31 -33 // 0 1
6 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 240 8 09 64 64 -31 -33 // 0 2
7 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 320 8 09 64 64 -31 -33 // 1 0
8 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 400 8 09 64 64 -31 -33 // 1 1
9 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 480 8 09 64 64 -31 -33 // 1 2
10 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 560 8 09 64 64 -31 -33 // 2 0
11 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 640 8 09 64 64 -31 -33 // 2 1
12 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 720 8 09 64 64 -31 -33 // 2 2
// Action 2 for object
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=Action2HousesIndustryTiles
// <Sprite-number> * <Length> 02 <Feature> <set-id> 00 <groundsprite> <buildingsprite> <xoffset> <yoffset> <xextent> <yextent> <zextent>
13 * 17 02 0F 00 00 8D 0F 00 00 00 80 00 80 00 00 0F 0F E5 // 0 0
14 * 17 02 0F 01 00 8D 0F 00 00 01 80 00 80 00 00 0F 0F E5 // 0 1
15 * 17 02 0F 02 00 8D 0F 00 00 02 80 00 80 00 00 0F 0F E5 // 0 2
16 * 17 02 0F 03 00 8D 0F 00 00 03 80 00 80 00 00 0F 0F E5 // 1 0
17 * 17 02 0F 04 00 8D 0F 00 00 04 80 00 80 00 00 0F 0F E5 // 1 1
18 * 17 02 0F 05 00 8D 0F 00 00 05 80 00 80 00 00 0F 0F E5 // 1 2
19 * 17 02 0F 06 00 8D 0F 00 00 06 80 00 80 00 00 0F 0F E5 // 2 0
20 * 17 02 0F 07 00 8D 0F 00 00 07 80 00 80 00 00 0F 0F E5 // 2 1
21 * 17 02 0F 08 00 8D 0F 00 00 08 80 00 80 00 00 0F 0F E5 // 2 2
//=====================================================================================
// Menu
// Action 1 Define a set of real sprites
22 * 4 01 0F 07 01
23 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 80 96 09 64 64 -31 -33 // Single
24 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 160 96 09 64 64 -31 -33 // E-W x 2
25 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 240 96 09 64 64 -31 -33 // N-S x 2
26 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 320 96 09 64 64 -31 -33 // E-W x 3
27 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 400 96 09 64 64 -31 -33 // N-S x 3
28 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 480 96 09 64 64 -31 -33 // 2 x 2
29 C:\MPS\_tools\grfcodec\sprites/NewObjTutw.pcx 560 96 09 64 64 -31 -33 // 3 x 3
// Action 2 for menu
// <Sprite-number> * <Length> 02 <Feature> <set-id> 00 <groundsprite> <buildingsprite> <xoffset> <yoffset> <xextent> <yextent> <zextent>
30 * 17 02 0F 09 00 00 80 00 80 00 00 00 00 00 00 00 00 00 // Single
31 * 17 02 0F 0A 00 01 80 00 80 00 00 00 00 00 00 00 00 00 // E-W x 2
32 * 17 02 0F 0B 00 02 80 00 80 00 00 00 00 00 00 00 00 00 // N-S x 2
33 * 17 02 0F 0C 00 03 80 00 80 00 00 00 00 00 00 00 00 00 // E-W x 3
34 * 17 02 0F 0D 00 04 80 00 80 00 00 00 00 00 00 00 00 00 // N-S x 3
35 * 17 02 0F 0E 00 05 80 00 80 00 00 00 00 00 00 00 00 00 // 2 x 2
36 * 17 02 0F 0F 00 06 80 00 80 00 00 00 00 00 00 00 00 00 // 3 x 3
//=====================================================================================
// varAction2 - Assemble sprites
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=VariationalAction2
// Variables link: http://wiki.ttdpatch.net/tiki-index.php?page=VarAction2Objects
// <Sprite-number> * <Length> 02 <feature> <set-id> <type> <variable> <varadjust> <nvar> (<set-id> <low-range> <high-range>){n} <default>
// The default sprite is always built first and is used for placing the object on the map.
// The numbers atop the cube sprites correspond to the coordinates listed below.
// Single
// Single cube - No assembly required
// E-W x 2
37 * 14 02 0F 10 81 40 10 FF 01
01 00 01 01
00 00
// N-S x 2
38 * 14 02 0F 11 81 40 10 FF 01
03 00 10 10
00 00
// E-W x 3
39 * 18 02 0F 12 81 40 10 FF 02
01 00 01 01
02 00 02 02
00 00
// N-S x 3
40 * 18 02 0F 13 81 40 10 FF 02
03 00 10 10
06 00 20 20
00 00
// 2 x 2
41 * 22 02 0F 14 81 40 10 FF 03
01 00 01 01
03 00 10 10 04 00 11 11
00 00
// 3 x 3
42 * 42 02 0F 15 81 40 10 FF 08
01 00 01 01 02 00 02 02
03 00 10 10 04 00 11 11 05 00 12 12
06 00 20 20 07 00 21 21 08 00 22 22
00 00
//=====================================================================================
// varAction 2 - Callback 149 returns
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=Callbacks#Land_slope_check_149_
// <Sprite-number> * <Length> 02 <feature> <set-id> <type> <variable> <varadjust> <nvar> (<set-id> <low-range> <high-range>){n} <default>
43 * 18 02 0F 16 81 10 00 FF 02 00 80 00 00 00 80 01 0E 09 80 // Single
44 * 18 02 0F 17 81 10 00 FF 02 00 80 00 00 00 80 01 0E 0A 80 // N-S x 2
45 * 18 02 0F 18 81 10 00 FF 02 00 80 00 00 00 80 01 0E 0B 80 // E-W x 2
46 * 18 02 0F 19 81 10 00 FF 02 00 80 00 00 00 80 01 0E 0C 80 // N-S x 3
47 * 18 02 0F 1A 81 10 00 FF 02 00 80 00 00 00 80 01 0E 0D 80 // E-W x 3
48 * 18 02 0F 1B 81 10 00 FF 02 00 80 00 00 00 80 01 0E 0E 80 // 2 x 2
49 * 18 02 0F 1C 81 10 00 FF 02 00 80 00 00 00 80 01 0E 0F 80 // 3 x 3
//=====================================================================================
// Action 2 - Return to graphics
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=Action2
// <Sprite-number> * <Length> 02 <feature> <set-id> <num-ent1> <num-ent2> <entries...>
50 * 17 02 0F 1D 85 0C 00 FF FF 01 16 00 49 01 49 01 09 00 // Single
51 * 17 02 0F 1E 85 0C 00 FF FF 01 17 00 49 01 49 01 0A 00 // N-S x 2
52 * 17 02 0F 1F 85 0C 00 FF FF 01 18 00 49 01 49 01 0B 00 // E-W x 2
53 * 17 02 0F 20 85 0C 00 FF FF 01 19 00 49 01 49 01 0C 00 // N-S x 3
54 * 17 02 0F 21 85 0C 00 FF FF 01 1A 00 49 01 49 01 0D 00 // E-W x 3
55 * 17 02 0F 22 85 0C 00 FF FF 01 1B 00 49 01 49 01 0E 00 // 2 x 2
56 * 17 02 0F 23 85 0C 00 FF FF 01 1C 00 49 01 49 01 0F 00 // 3 x 3
//=====================================================================================
// Action 3 Associate with graphics set IDs
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=Action3
// <Sprite-number> * <Length> 03 <feature> <n-id> <ids...> <num-cid> (<cargo-type> <cid>)... <def-cid>
// THE FOLLOWING WARNING SHOULD BE IGNORED
//!!Warning (142): <num-cid> must be 0 for this feature.
57 * 10 03 0F 01 00 01 FF 1D 00 00 00 // Single
58 * 10 03 0F 01 01 01 FF 1E 00 10 00 // N-S x 2
59 * 10 03 0F 01 02 01 FF 1F 00 11 00 // E-W x 2
60 * 10 03 0F 01 03 01 FF 20 00 12 00 // N-S x 3
61 * 10 03 0F 01 04 01 FF 21 00 13 00 // E-W x 3
62 * 10 03 0F 01 05 01 FF 22 00 14 00 // 2 x 2
63 * 10 03 0F 01 06 01 FF 23 00 15 00 // 3 x 3
//=====================================================================================
// Action 4 Define vehicle names or other texts
// Link: http://wiki.ttdpatch.net/tiki-index.php?page=Action4
// <Sprite-number> * <Length> 04 <feature> <language-id> <num-ent> <offset> <text>
64 * 11 04 48 FF 01 00 D0 "Cube" 00
65 * 18 04 48 FF 01 01 D0 "Single Cube" 00
66 * 14 04 48 FF 01 02 D0 "2 Cubes" 00
67 * 18 04 48 FF 02 03 D0 "E - W" 00 "N - S" 00
68 * 14 04 48 FF 01 05 D0 "3 Cubes" 00
69 * 18 04 48 FF 02 06 D0 "E - W" 00 "N - S" 00
70 * 18 04 48 FF 01 08 DO "Multi Cubes" 00
71 * 18 04 48 FF 02 09 D0 "2 x 2" 00 "3 x 3" 00
Here are the sprite sheet for the cubes and the grf for you to preview: