Page 1 of 11

Adding new vehicle graphics

Posted: 23 Jan 2003 06:14
by Patchman
** Updated July 16 2003 for TTDPatch 2.0 **

Latest document describing new vehicle .grf files is now available here:
http://www.ttdpatch.net/src/newgrf.txt

Update on July 16 2003:
Note: In 2.0, it is required to use a correct action 8 entry in your graphics files. It also must be grf version 2, or it will not be accepted. Please update your graphics files or they won't load under 2.0, beta or not.

Also, it is no longer possible to override vehicle names using ttdpttxt.dat. The new mechanism to do this is explained here: http://www.tt-forums.net/viewtopic.php?p=88377#88377

Older information

Since TTDPatch 1.9.1 alpha 6, it is possible to add new vehicle graphics to the game, similar to the new ships by Michael Blunck, but now this is also possible for trains, road vehicles and planes.

Unlike simply changing the existing graphics, adding new ones is a bit more complicated, however.

I wrote a very technical explanation which is part of the source code .zip file, and I'll also attach the current version here.

I'm attaching three example files as well, one for each vehicle type, which you can decode with GRFCodec, and try to understand how they work after reading the newgrf.txt file.

Here's a very brief summary:
  1. Copy the lines from the TRG1.NFO file for the vehicle type you want to modify. Pick a vehicle that's closest in size and shape to what you want to add.
  2. Paste these into a new .NFO file; perhaps a copy of one of the example .NFO files attached here.
  3. Add the first special sprites, don't worry about the numbers yet
  4. Add an action 0 to at least set that vehicle's sprite to FD for trains or FF for everything else
  5. Add an action 1, after which you paste the copied .NFO strings from trg1.nfo
  6. Add one or more action 2 entries
  7. Add one action 3 entry for each different vehicle
  8. Run renum.pl on it, or count the sprites yourself
  9. Encode it with GRFCodec
  10. Copy it to the newgrf folder in your TTD directory
  11. add the line "newgrf/yourfile.grf" to newgrf.txt, where "yourfile" is your .grf file name
  12. Try it! Hopefully it works...
Oh, and you also need to turn on "newtrains" (-T), "newrvs" (-XR) and/or "newplanes" (-XP) to enable new graphics for these vehicle types.

Update on January 13 2003:

I have changed the format of the new graphics files slightly, to allow for random graphics and variational graphics (which are like random graphics but deterministic). These changes apply to alpha 13 and higher. In alpha 12, the format of action 0 changed slightly; for trains, a missing property has been inserted ( 18 ), which changed the numbers for properties for sound/graphics effect type to 19, and sorting to 1A.

Please read the changes in action 2 and 3 if you want to use randomized or variational graphics, as well as wagon overrides.

Randomized graphics means a wagon for example will have several different graphics set, and one set will be chosen randomly. At your option, the graphics will be randomized again when the wagon is receives the next load and/or enters a depot.

Variational graphics are graphics that depend on variables, such as current date/year or the vehicle age or speed. These are a set of different graphics like random graphics, but they aren't chosen randomly, and instead determined by the variables.

Finally, wagon override means that you can specify graphics for certain wagons, which will only be used when attached to a specific engine. For example, you could make an ICE engine that forces the regular passenger wagon to look like an ICE wagon, but only when actually connected to the ICE engine.

Please have a look at the attached files to see how all of this works.

Update on January 14 2003:
I had to change the definition of random cargo ID lists, please insert one byte, according to the updated newgrf.txt.

Update on January 23 2003:
In alpha 16, the format of actions 4 and 6 changed slightly.

For action 4, I introduced an additional byte that allows you to specify the language of the name. That way, you can have several action 4 entries for each vehicle, one for each language (or several languages, if you so choose).

Action 6 now has a different terminator byte. Instead of 00, the last byte must now be FF, so as to allow the use of parameter number 0 more than once. Currently, this action is backward compatible (i.e. "00" will work too), but I will remove the compatibility soon, so please update your graphics files and change the final byte of all action 6 entries to "FF".

Update on February 2 2003:
In alpha 21, I've changed the meanings of some properties of the road vehicles, and added a few new ones.

Prop. 12 is now the setting of the sound effect, can have values 17, 19 or 1A for regular vehicles and 3C or 3E for toyland vehicles.

This moved the former prop. 12 and 13 down one slot. So prop. 13 is now the power, and prop. 14 is the weight.

Prop. 15 is new, and sets the top speed if "rvpower on" is used. This value is given in units of mph*0.8, and can thus go to 320 mph or 511 km/h. If unset, the value of the regular top speed, prop. 08 is used. Always set prop. 08 too if you change prop. 15

Prop. 16 is also new, and works like prop. 10 for the ships. It allows you to make road vehicles refittable, and choose the cargo types that the vehicle can be refitted to. The refitting works similar to the trains (i.e. the refit button replaces the "reverse" button), but the road vehicles use the ship refitting mechanism instead of the planes. To enable this, there is no new switch, just "newrvs on" is enough.

Update on February 24 2003:
Alpha 28 adds action 8, which specifies a unique ID for each GRF file. It will be mandatory to specify this in one of the coming alpha versions. This ID will be used to identify .grf files and allow the game to only load the graphics that were active when a game was saved.

Additionally, action 7 is now more versatile, because it can also check the climate, as well as skipping the rest of the file without you having to count all the remaining sprites. See the updated sprites.txt for more info.

Update on February 27 2003:
Removed the attachment here, instead I'll just link to the latest version on the source code page. That'll always be the most up-to-date document.

Posted: 23 Jan 2003 06:48
by spaceman-spiff
[serious] ANY OT WILL BE DELETED [/serious]
Thanks for the new topic, the old one was broken !

Posted: 23 Jan 2003 07:11
by SHADOW-XIII
Great thanks Patchman :bow:
Now I know how to do it :mrgreen:

Train

Posted: 23 Jan 2003 19:28
by Dinges
I have made a new train for TTD, but i don't know how to write a name, could someone say how I must do it?

Re: Train

Posted: 23 Jan 2003 19:39
by SHADOW-XIII
Dinges wrote:I have made a new train for TTD, but i don't know how to write a name, could someone say how I must do it?
You should take a look at Josef files (he posted info 3-4 posts earlier)
this is a port from newgrf.txt:
The following actions can be specified:

Action What it does
0 Change vehicle info (like TTD Alter)
1 Define new sprite block
2 Define new cargo ID: mapping of cargo type and load status to sprite
3 Define vehicle to cargo ID mapping
4 Define new vehicle names
5 New graphics such as pre-signals and overhead wires
6 Apply newgrf.txt parameter to following sprite data
7 Skip following sprites if condition is true

Posted: 24 Jan 2003 13:27
by Dinges
I know how to do it, but when I type a name I get an error with GRFcodec that there's something wrong.

Here's de line:

15 * 6 04 00 02 01 00 mytrain0

Is this correct?

04 -action 4
00 -train
02 -language
01 -total vehicles
00 -first vevicle
mytrain0 -The name

Posted: 24 Jan 2003 13:32
by SHADOW-XIII
Data is <veh-type> <language-id> <num-veh> <offset> <data...>

B veh-type see action 0
B language-id language ID (see below)
B num-veh number of vehicles which are getting a new name
B offset number of the first vehicle that gets a new name
S data new names, each of them zero-terminated, after
which the next name begins.

S at vehicle name means this is String ... you must study this file closer ... try to get how example works ... I can't say anything more cuz I dont start creating my own new vehicles

Posted: 24 Jan 2003 13:45
by Dinges
This does not answar my question, Everythings okay until I add the line.

But thanks anyway

Posted: 24 Jan 2003 14:58
by Patchman
You have to specify the individual bytes of the string in hex notation, with 00 at the end. Example:

Code: Select all

   15 * 11	 04 02 04 01 05 48 65 6C 6C 6F 00
This sets the name to "Hello".

Posted: 24 Jan 2003 15:16
by SHADOW-XIII
Patchman wrote:You have to specify the individual bytes of the string in hex notation, with 00 at the end. Example:

Code: Select all

   15 * 11	 04 02 04 01 05 48 65 6C 6C 6F 00
This sets the name to "Hello".
Now I get it to :mrgreen: but have you any tool to easy converting String (or a single letter) to Hex

Posted: 24 Jan 2003 15:58
by Dinges
Thank you, Patchman I will try it and see if it works (It will).

Posted: 24 Jan 2003 16:02
by Patchman
If you have Perl, use this command line:

Code: Select all

perl -le "print map {sprintf '%02X ', ord} split //, qq(@ARGV).v0" Vehicle name
Substitute the actual vehicle name, of course. That's what I use, but I'm sure there are many, many other tools.

Posted: 27 Jan 2003 23:12
by mp3Pro
what if you dont have perl?
is there a hex editor or something else that would work?

Posted: 27 Jan 2003 23:14
by SHADOW-XIII
You must find it yourself :mrgreen:

Posted: 27 Jan 2003 23:56
by Patchman
Most hex editors will do fine. Just type the name in a .txt file, and look at it in the hex editor.

However, Perl is free, so you could just download it too :)
http://www.perl.com, http://www.activestate.com, http://www.cygwin.com and many more.

Posted: 28 Jan 2003 00:20
by mp3Pro
Thanx Patchman , I'll check it out

Posted: 29 Jan 2003 07:58
by uzurpator
I have read the documents explaining how to add a new vehicle and I must admit. I don't understand a darn thing ;)

I want to add my trucks to the game and remodel current. I have drawn 7 sets of vehicles (for three climates altogather - temprate, winter and desert) and i will extract the 3 original This will give me 10 truck models -each reffittable for all cargoes. I want to use 1- vehicle ID's and free rest for future uses. Question - how to do it?

What should the format of the nfo file be (clear hints please like
0 *
1 * action something (data)
2 sprites for coal
3 * action something other
4 sprites for mail

and so on.

Posted: 30 Jan 2003 01:11
by Patchman
I suggest you have a look at the cargoset.grf and see how it's done there, and how it works. Try to understand each pseudo-sprite and what it does. If you have a specific question, feel free to ask, of course. I can't possibly write more than I have in newgrf.txt... unless you have a specific question.

You can have only one sprite block (action 1) for each vehicle, but several vehicles can share the same sprite block. You'd put the sprite block in the .nfo file, then an action 2 for each vehicle's cargo type, then an action 3 for each vehicle, in the simplest case. Of course you also need an action 0 to set the sprite ID of the vehicles to FD (trains) or FF (everything else).

Posted: 31 Jan 2003 07:46
by uzurpator
OK. I got some questions.

I more or less understand how it works. But now:
My idea is to use a single vehicle ID and make the vehicle reffittable to all cargoes. We are speaking of trucks for now. Afair it is impossible to add 100+ trucks to the game, no matter how much I will try.

1. In action 0 ships and airpalnes have the "reffittable" flag. Trucks dont have that (sadly). So can I make reffittable truck?

2. action 1 specifies sprite block. If i understand correctly - i have to point to graph file, show coords to the sprites etc. Also i have to specify full 8 image set for each cargo (loaded or unloaded) and each set of 8 is a single sprite block and amount of them is specifed by action 1
namely
3 * 4 01 01 10 08
3rd line, pseudosprite of 4 bytle length.
Action 1, for road vehicles, 16 sprite blocks of 8 sprites each
right?

3. Action 2. Now my questions.
It merely specifies to which cargo sprite-block should be assigned for loaded and unloaded state.

42 * 13 02 01 00 02 02 00 00 01 00 00 00 01 00
action 2 for truck, 2 states for loading, two states for movement, and corresponding to them sprite block num 00 00 and 01 00 (lsb).

Now should I make a list of action 2 for each cargo this vehicle is supposed to be reffited like this?
40 * 13 02 01 00 02 02 00 00 01 00 00 00 01 00
41 * 13 02 01 01 02 02 02 00 03 00 02 00 03 00
42 * 13 02 01 02 02 02 04 00 05 00 04 00 05 00
and then make corresponding action 3 for each cargo ID specified or.. or what? How to make the refitability?

Posted: 31 Jan 2003 14:47
by Patchman
Adam K. wrote:1. In action 0 ships and airpalnes have the "reffittable" flag. Trucks dont have that (sadly). So can I make reffittable truck?
Not yet... this is something I have yet to build into the patch.
2. action 1 specifies sprite block. If i understand correctly - i have to point to graph file, show coords to the sprites etc. Also i have to specify full 8 image set for each cargo (loaded or unloaded) and each set of 8 is a single sprite block and amount of them is specifed by action 1
namely
3 * 4 01 01 10 08
3rd line, pseudosprite of 4 bytle length.
Action 1, for road vehicles, 16 sprite blocks of 8 sprites each
right?
Yes, that's right.
3. Action 2. Now my questions.
It merely specifies to which cargo sprite-block should be assigned for loaded and unloaded state.

42 * 13 02 01 00 02 02 00 00 01 00 00 00 01 00
action 2 for truck, 2 states for loading, two states for movement, and corresponding to them sprite block num 00 00 and 01 00 (lsb).
Yes, if you don't want it to look different while it's being loaded.
Now should I make a list of action 2 for each cargo this vehicle is supposed to be reffited like this?
40 * 13 02 01 00 02 02 00 00 01 00 00 00 01 00
41 * 13 02 01 01 02 02 02 00 03 00 02 00 03 00
42 * 13 02 01 02 02 02 04 00 05 00 04 00 05 00
Something like this, yes, although you probably want to use the same sprite for the empty state. Unless the truck should look different when empty for each cargo type.
and then make corresponding action 3 for each cargo ID specified or.. or what?
You make one action 3 for each truck, and there you list its cargo types and associate it with the action 2 cargo IDs.
How to make the refitability?
That doesn't work, yet. Unfortunately...

I shouldn't be too hard to do, but I haven't had the time yet.