Preliminaries

From TTWiki
Jump to navigationJump to search

NOTE TO AUTHORS: Read the LocalStyleGuide, otherwise the page may be rolled back to the last well-commented edit. (This applies everywhere, not just on the pages that mention it.)

To write:

  • explain GRFCodec / GRFWizard
  • explain hex codes: specific examples using Windows calculator, ideally with screenshots
  • maybe: explain DOS/Windows version and how to convert between them
  • other things?

What's a .GRF file?

As you probably already found out ttd can load new graphics files with help of the patch. These files have the extension .grf and are located in the newgrf folder.

These .grf files are made by GRFcodec, this program merges a .pcx file and a .nfo file. (links to george his tut now, but I think on top of that page should be an explanation about pcx files and their palette) In this tutorial we won't look at those 2 file types yet, at first we shall try to explain the basics.

The GRFCodec and the GRFWizard

Like said before a .grf file is a file made by the GRFCodec. The codec is a package of 3 programs:

  1. GRFCodec: Convert a GRF into an editable PCX file and vice versa
  2. GRFDiff: Compare two GRF files for differences, and write only the differences to a GRD file
  3. GRFMerge: Take a GRD file and merge it back into the GRF file

In this tutorial we will only use the first program, if you want more info about the other programs look here.

The GRFCodec is a command line program. This means it's option are only been set in the command line, there is no nice user interface. For the nice interface you can download the GRFWizard This program is really helpful. Be warned though for the GRFWizard to work you need the GRFCodec too.

When you run the GRFWizard for the first time you have to point it to the codec, when you have done this everything is really straight forward, you can encode your homemade sprites (sprites are the little drawings that represent one side of a building/vehicle) or you can decode a grf from someone else.

When you want to encode graphics you have to point the wizard which grf file you want to encode the 2nd step is to tell it in which you placed the NFO and PCX. All these file should have the same name.

If you want to encode totally new graphics you have to make a "fake" grf. Just make a new txt file and rename it to the grf you want to encode.

If you choose to decode a grf, the nfo and pcx will be extracted to a map called sprites in the in the folder where you placed the grfcodec in.

Hex

Unless noted clearly (yes, there are a very few exceptions), assume that all the code on these pages is in hex.

hex [heks]

  1. verb - to bewitch; practice witchcraft on
  2. adjective - of or pertaining to a numbering system that uses 16 as the radix, employing the numerals 0 through 9 and representing digits greater than 9 with the letters A through F.
  3. adjective - relating to or encoded in a hexadecimal system, esp. for use by a digital computer.

The guts of your computer consist of a bunch of circuits connecting processor chips, memory chips and a bunch of other stuff.

Each chip consists of a bunch of switches that are off (0) or on (1). A series of switches would look something like this: 1001 0001 1110 0101. This is called binary code. A program that you run on your PC reads and/or writes this code. Unless you are a computer genius, mathematician or a nerd, you would probably need definition 1 above to make this work. Consequently, several people from the aforementioned group devised a way for chips to understand a more manageable numbering system called hex (Definitions 2 and 3 above). They called it Assembly Language, probably because it assembles something called a program. TTDX and TTDPatch are programs. They are written in Assembly Language. This is why you need hex to code an nfo code for your new graphics.

HEX is a way of counting. You normally count from 1 till 9 and then go to 10,11 etc. In HEX it works a bit differently: you count from 0 till 9 but then you go one with A, B,C,D,E,F. So 1 till 9 is just 1 till 9, but then it gets funky A=10, B=11, C=12 and so one till F= 15. when you reach F you just do like you would do normally, you start at 0 again but now with a 1 in front thus 10 (gee that's almost like normal counting! :P) so 10=16 If you want a better understandable explanation visit this link.

Now it would be rather uneasy if you have to count it all by yourself (or at least for me being of the lazy generation) so you can use the windows calculator for that.

If you open it it take any hex, so you have to go to scientific. Just open view and click on scientific mode.

If you did it correctly it will look like this:

(sorry I had to eat, I will see this page later on again)

(He's been out to lunch since last modification: Monday 24 of October, 2005 [20:31:32] by dmccoy. Icon eek.gif Meanwhile I have added a reason why you need hex to the hex section. Icon cool.gif)

Hopefully the document on these pages will help you to avoid resorting to hex definition 1 too often.