免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 发帖

GRF制作教程汉化

本帖系文涛武略发表于2008-8的旧帖

GRF制作教程汉化
Preliminaries
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?

什么是.GRF文件

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.

正如你发现TTD可以通过补丁来加载新的图形文件,这些扩展的.grf文件放在NEWGRF目录中

These .grf files are made by the 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 pallete ) In this tutorial we won't look at those 2 file types yet, at first we shall try to explain the basics.

这些.grf文件是由the GRFcodec生成的,这个程序用来合并.pcx 文件和.nfo文件(链接到george的关于绘制.pcx的教程),在这个教程里,我们将首先解决基本的,而不是以上两个文件的说明。

The GRFCodec and the GRFWizard

程序GRFCodec 和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

正如前面所说的,一个.grf文件是由GRFCodec生成的,这个程序包包括了3个程序:
1、GRFCodec :转换.grf,包括编译和反编译;
2、GRFDiff:比较两个grf文件,并将不同之处写入GRD文件;
3、GRFMerge:读取GRD文件并合并到GRF文件中。

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.

当你第一次运行GRFWizard时,你必须为它指定codec的路径。当你弄完这一切后,你就可以编译你自己定义的sprites了(sprites就是缩小比例的建筑/运输工具的图样)或者反编译别人的grf文件。

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.

当你想要编译grf文件,你需要指定哪个grf文件需要编译,第二步就告诉程序你将.nfo和.pcx文件放在哪里了。这些文件需要同样的名字,例如:aaa.nfo和aaa.pcx

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.

如果你想要完全地编译新图形图像文件,你可以编译一个“假冒的”grf文件,仅仅生成一个.txt文件,并将它的名字改成你想要得到的grf文件名。
如果你反编译一个.grf文件,生成的.nfo和.pcx文件将被解压到grfcodec\sprites目录下。

Hex 十六进制
some sort of text here to explain why you need to understand hex?


以下文字是解释了为什么你需要了解十六进制,后面的不用翻译了吧?最简单的是就windows下的计算器。

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 thats almost like normal counting! ) 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)
收藏 分享

文涛武略 发表于 2008-5-28 16:37
NFO Filesnfo文件

The fundamental files that control your new graphics are the .nfo and the .pcx file. The .pcx file contains the actual drawings, and the .nfo file the instructions what to do with them.

你的grf文件是由.nfo和.pcx构成。.pcx文件是图形文件而.nfo文件是用于告诉程序怎么使用.pcx文件

To get started开始

To draw a new train, you first need a base from which to start working. Since you probably aren't familiar with all the intricacies yet, it's best to copy one of TTD's vehicles and then draw your own graphics. Basically, you follow these steps:

要绘制一个新的火车,你首先需要一个基础模型来开始工作。可能你不是太熟悉,最好的方法是拷贝一个ttd的运输工具,然后来绘制你自己的图形。你要按照以下的基本步骤来

  • Extract TTD's trg1r.grf (or trg1.grf for the DOS version)
  • Look through trg1r.pcx for a vehicle similar to the one you're going to make
  • Copy the corresponding data from the .nfo file into your own file
  • Encode and decode again your own file
1、解压TTD中的trg1r.grf(或者dos版本中的trg1.grf)
2、在trg1r.pcx中查找一个与你想要绘制图形相似的运输工具
3、从.nfo文件中拷贝相应的数据到你自己的文件中
4、编译或者反编译你的文件

Now to look at these steps in a bit more details.
现在来详细解释一下

1. Extract TTD's trg1r.grf1、解压ttd的trg1r.grf

First of all, you need to download grfcodec and unzip it into your TTD folder. Then you open a DOS command window. If you are using Windows 2000 or Windows XP you can open a DOS command window by typing cmd in the execute option in the start menu. When you see the command window run grfcodec like this:

首先,你需要下载grfcodec并解压到你的ttd目录中,然后打开一个dos命令行窗口。如果你使用win2000或者xp,你可以通过“开始”菜单中的“运行”,输入“CMD”命令,然后你输入以下命令

cd C:\TTD (change to your TTD folder)
grfcodec -d trg1r.grf (decode trg1r.grf; use trg1.grf for the DOS version of TTD)


This will make a new folder called sprites, and will put trg1r.pcx and trg1r.nfo in it.

以上命令会生成个新的目录,/sprites,并生成trg1r.pcx和trg1r.nfo文件

You can also use GRFWizard with grfcodec. It will add a user interface to grfcodec. Just follow the options in the wizard to decode a .grf file, it will also add a sprites folder and generate the .nfo and .pcx files.

你也可以使用grfwizard,它将为grfcodec添加一个用户界面。通过反编译一个.grf文件,它也会添加一个sprites目录和生成.pcx、.nfo文件。

2. Look through trg1r.pcx2、查看trg1r.pcx

You now open trg1r.pcx from the sprites folder. There are many graphics programs to view and edit .pcx files.
你现在可以在sprites目录打开trg1r.pcx文件,有很多程序可以查看和编辑.pcx文件。

Look for a vehicle that is similar to the one you want to make. For example, if you want to make a train engine with 8 views, you can use the SH 125. So you go looking for its graphics in trg1r.pcx. For the SH 125, you'll find them at numbers 2941 to 2948 (those are the little numbers above the images). Write down those numbers. For example, this is what it might look like:

找到一个与你想要绘制的图形相似的运输工具。例如,你想要绘制一个火车头的8方向图,你可以查看SH 125。对于SH 125来讲,你可以看到他们的数字为2941到2948(在相应图像上的小数字)。如图所示

[img=http://wiki.ttdpatch.net/img/wiki_up//sh125.png]img/wiki_up//sh125.png[/img]


3. Copy the corresponding data from the .nfo file into your own file3、从.nfo文件中拷贝相应的数据到你自己的文件中

So now that we know what sprites to base the graphics on, we need to copy those into a new file. Open the trg1r.nfo file in a text editor, for example Notepad. Also, open another .nfo file for your own graphics, say for example "mytrain.nfo".

现在,我们知道了相应的图形对应的数字,我们需要拷贝这些数据到新的文件里。用文本编辑器打开trg1r.nfo,例如 notepad。同样的,创建一个名为“mytrain.nfo”的文件。

Now, copy and paste the first three lines beginning with "//" to your mytrain.nfo file. While they may look like comments, they are actually important.

现在,拷贝粘贴前三行包括"//"的字段到mytrain.nfo文件中。看起来只是注释,其实它们很重要。

In the next step, find the lines beginning with the sprite numbers you're written down in the previous step. In the example above, we'd find the lines with numbers 2941 to 2948. Copy those eight (or however many) lines to your mytrain.nfo file as well.

接下来,找到你刚才记下的几个数字的那几行,拷贝到mytrain.nfo文件中。

4. Encode and decode again your own file编译和反编译你的文件

Now we want to make our own .grf file. Unfortunately, grfcodec is a bit picky and will complain loudly if your lines are not numbered properly. To make grfcodec shut up, you have to go through your .nfo file, and change the numbers at the beginning of the lines to go from 0 to 7.

现在我们要生成自己的.grf文件了。不幸的是,grfcodec有一点讲究,并且会大声的报警,如果你的语句不是正确的。为了让编译通过,你要检查你的.nfo文件,并把每段开头的几个数字,改成0-7

At this point, your .nfo file should look something like this:
修改后的文件如下所示:

// Automatically generated by GRFCODEC. Do not modify!
// (Info version 6)
// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
0 C:\TTD\SPRITES\trg1.pcx 530 10664 01 18 8 -3 -10
1 C:\TTD\SPRITES\trg1.pcx 546 10664 09 15 20 -14 -6
2 C:\TTD\SPRITES\trg1.pcx 578 10664 01 12 28 -14 -6
3 C:\TTD\SPRITES\trg1.pcx 626 10664 09 16 20 -4 -8
4 C:\TTD\SPRITES\trg1.pcx 658 10664 01 18 8 -3 -10
5 C:\TTD\SPRITES\trg1.pcx 674 10664 09 16 20 -14 -7
6 C:\TTD\SPRITES\trg1.pcx 706 10664 01 12 28 -14 -6
7 C:\TTD\SPRITES\trg1.pcx 754 10664 09 15 20 -4 -7


Now run grfcodec again, first to encode and then to decode your file. This creates mytrain.pcx and changes your .nfo to refer to that copy of the sprites:

现在重新运行grfcodec,首先编译和反编译你的文件。将会生成mytrain.pcx并修改你的.nfo来指向你拷贝你的sprites。

grfcodec -e mytrain.grf (encode your mytrain.grf file)
grfcodec -d mytrain.grf -p 2 (decode your mytrain.grf file again)


Leave off the "-p 2" if you're working with the DOS graphics instead of the Windows graphics.
“-p 2”命令开关是用来生成DOS版本的grf

Good job!做得好

Now you have your own mytrain.grf file with the corresponding mytrain.nfo and mytrain.pcx files. We'll use this as a base for making these graphics TTDPatch compatible.

现在你将有自己的.grf文件了,我们通过这个基本方法来生成ttdpatch适用的grf文件。

Note that you can't yet take your mytrain.grf file and put it in TTDPatch's newgrfw.cfg file yet, because it doesn't have the necessary information to allow TTDPatch to know what to do with it.

注意,你仍然不能在游戏中调用它,因为它没有必须的信息来让ttdpatch知道该怎么运用它。

However, you can go ahead and edit the graphics in mytrain.pcx to your liking and make them look like your train.
然而,你可以不断修改.pcx文件里的图形来更加完善。

Once you're ready, go on to the next section.
当你准备好后,进入下一单元。

文涛武略 发表于 2008-5-28 17:24
The First Vehicle第一个运输工具

This section of the tutorial takes the rudimentary mytrain.grf file you made in the previous step, and turns it into a .grf file usable by TTDPatch.

本单元介绍了如何将上一步中生成的.grf文件转换成ttdpatch可用的.grf文件。

Here's what you have to do:
这里,我们将做的是

  • Figure out "pseudosprites"
  • Add the special first pseudosprite
  • Give your file an GRFID
  • Add an "action 1" to introduce your vehicle graphics
  • Use actions 2 and 3 to link your graphics to a vehicle in TTD
  • Adjust the first pseudosprite again, and renumber all sprites
  • Encode and add to newgrf(w).cfg
1、弄明白"假sprites"
2、添加特殊的第一个"假sprite"
3、标注grfid
4、增加"action 1 "来介绍你的grf文件
5、使用action2和3来使你的图形连接ttd里相应的运输工具
6、调整第一个假sprits,并重新编号所有的spirtes
7、编译并添加到游戏里。

TOP

  • Figure out "pseudosprites"
  • Add the special first pseudosprite
  • Give your file an GRFID
  • Add an "action 1" to introduce your vehicle graphics
  • Use actions 2 and 3 to link your graphics to a vehicle in TTD
  • Adjust the first pseudosprite again, and renumber all sprites
  • Encode and add to newgrf(w).cfg
1、弄明白"假sprites"
2、添加特殊的第一个"假sprite"
3、标注grfid
4、增加"action 1 "来介绍你的grf文件
5、使用action2和3来使你的图形连接ttd里相应的运输工具
6、调整第一个假sprits,并重新编号所有的spirtes
7、编译并添加到游戏里。

Now let's look at this in more detail.
现在来详细介绍每个步骤

1) Figure out pseudosprites1、弄明白"假sprites"

If you've looked through trg1r.nfo, you may have noticed that some entries look different to the usual ones.
如果你查看trg1r.nfo时,你可以注意到一些段落与普遍的要些差别

Usual entry:
普通段落

24 C:\TTD\SPRITES\trg1r.pcx 450 8 01 9 7 0 0

This one is different:
不同的:

771 * 17 10 00 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 EF EF EF


The first one refers to an image in the PCX file. The second one is some additional data that's not an image. These types of entries are called "pseudosprites", and in TTDPatch .grf files they are used to give TTDPatch information what it should do with the graphics in the file.

第一个段落,是指向pcx中的一个图形,第二个段落是一些额外的数据,并不是一个图形。这些段落就叫“假sprites”,在ttdpatch中,.grf文件给予ttdpatch信息来让ttd运行这些图形。

Here's what you have to know:
这里,我们需要知道

  • The first number is the well-known sprite number, simply counting entries from the beginning of the file
  • Then follows an asterisk "*", where you would normally have the PCX filename
  • Then there's another number, which is the length of the following data
  • And finally the actual data, as a bunch of hex codes
第一个数字就是通常说的spirte编号,简单的计录从文件开始的段落数
紧接着的“*”和你通常的pcx文件名,
然后是另一个数字,就是接下来的数据“长度”
最后一串数字就是实际使用的数据。

So, that's what you have to know about pseudosprites for now. Let's get started...
至此,以上就是解释了什么叫“假sprite”,让我们开始吧。

2) Add the special first pseudosprite添加特殊的第一个“假sprite”

For TTDPatch graphics files, the first entry in the .nfo is special, and tells TTDPatch how many lines the file has. Since we don't yet know how big it will be, we add it but don't put any useful data in.

在.grf文件中,.nfo文件的第一个段落是特殊的,是为了告诉ttdpatch,该文件中有多少行。因此,在我们仍然不知道文件有多大时,我们添加它但不放入有用的数据。

Here's what you do: in your mytrain.nfo file, after the comment lines (those that begin with "//"), but before the first entry, insert the following line:

这里,你要在你的.nfo文件中,在注释行("//"开头的)后面和第一段落前面,插入以下行:

0 * 4 00 00 00 00


3) Give your file an GRFID3、标注grfid

Apart from the first line which we've added in the previous step, TTDPatch .nfo files are organized by "actions". These actions tell TTDPatch what to do with the graphics in your file. In our specific case, we need to tell TTDPatch to use those graphics for a train engine.

除开上一步我们添加的第一行外,TTDPATCH的.nfo文件通常是由“actions”组成。这些“actions”(后面翻译将改成脚本了)告诉ttdpatch怎么运行你文件里的图形。在本教程中,我们需要告诉ttdpatch使用这些图形用作一个火车头。

Before you go any further, just let me make clear what the different ID's mean that we will refer to. Here's a table:

在你深入研究前,请让我解释不同的ID意味着我们的指向,如下表所示:

ID TypePurpose
Vehicle IDA generic vehicle/station/building slot whose properties can be defined using an Action 0. A Cargo ID can be associated with this using Action 3.
set ID (called cargo ID for vehicles)A ID asociated with one or more Spritesets using an Action 2. Can be asociated with a Vehicle ID using Action 3.
SpritesetA value unique to each Action 1. Defines a set of 8/4 views i.e. a set of sprites. Is in an action 2
GRFIDA word value used to differentiate between different grf files. This should be globally unique!

ID 类型目的
运输工具 ID通过使用脚本0来定义运输工具/站台/建筑的统一接口。货物ID通过使用脚本3来产生联系
固定ID (运输货物类型的ID)
一个ID通过使用脚本2来与一个或多个sprites产生联系。通过使用脚本3来与运输工具的ID产生联系。
Spriteset对应脚本1中的一个唯一值
A value unique to each Action 1. Defines a set of 8/4 views i.e. a set of sprites. Is in an action 2
GRFID一个唯一值用来区别不同的grf文件。


Just keep that in mind and refer to it later on.
Now, lets continue.

记住以上信息并明白后面示例的意义。
现在继续

The first step to do that is by using an Action 8, which gives your file an GRFID, and allows people to turn it on or off in the GRF Status Window.

第一步,使用脚本8,赋予你的.grf文件一个grfid,然后允许玩家在游戏中开启和关闭

You have to choose the GRFID yourself. To find a good GRFID to use, for example use the initials of your first and last name, plus two numbers.

你必须自己选择一个grfid。例如最好的方法就是使用你姓名的首字母,加2个数字。

For example, for this tutorial, we'll use the initials "TW". In addition, we need two numbers to identify the file. These you can pick however you like, you'll use them to distinguish different graphics files made by you. Those will have the same initials, but must get different GRFIDs, so you pick different numbers. For example, here we pick 3 and 5.

例如,在本教程中,我们将使用"TW"。另外,我们需要2个数字来表明文件身份。数字可以是你喜欢的,你可以区别你自己的不同文件。这样,不同grf文件的grfid拥有相同的首字母,但必须拥有不同的grfid,所以你必须使用不同的数字。例如,这里我们选择了3和5

This means we get the following GRFID:
这样,我们得到以下的grfid

"TW" 03 05



You may also write the initials as hex codes. If you aren't familiar with hex codes, you can use the Hex Converter to help you. Simply enter your initials and click convert, and then write down the hex codes. This is more complicated, so very few people do it, but the result would be the following equivalent GRFID:

54 57 03 05

你也可以将缩写字母以十六进制的方式表达。如果你不熟悉十六进制,你可以使用转换器来帮助你。只需要输入你的字母,点击转换就可以了。这个结构很复杂,所以很少人用,但结果是一样的。

This form is the official form for a GRFID, and should be used in all non-.nfo contexts. In .nfos, you may use whichever form you prefer.

这个是指定的grfid方式,并被使用在非.nfo环境中。在.nfo文件中,你可以使用你更喜欢的。

The 54 57 are the hex codes for "TW". In both cases, 03 and 05 are the numbers we've picked, written in hex.

54 57 是"TW"的十六进制表达式,同时,03 05是我们选择的数字,也是以十六进制表达的。

Therefore, you insert the following line immediately after the line which you've added in the previous step:
1 * 8 08 06 "TW" 03 05 00 00

因些,你将以下表达方式插入在上一步中我们建立的行之前。

This gives your graphics file the GRFID. This action 8 must always be present in your files, and it must be one of the first lines. If you don't have an action 8, TTDPatch will complain about "invalid sprites" or an "incorrect version", and refuse to load your file.

这样你的grf文件就有了grfid,脚本8必须出现在你的文件里,而且必须是第一行。如果你没有定义脚本8,TTDPATCH将会报错,并拒绝加载你的文件。

You can optionally give your file also a name and a description or copyright info, but that's beyond the scope of this tutorial. Check the docs for action 8 for more details.

你也可以通过脚本8来定义一个名字和一个描述或者版权信息。以上已经超出了本教程的范围,请参考脚本8

TOP

4) Add an action 1
添加脚本1

Right, so now the file has an GRFID. In the next step, we need to tell TTDPatch that there will be a bunch of graphics in this file. You might think that that's obvious, but nothing is obvious to computers, so we have to tell it.

现在,文件有了grfid。下一步,我们需要告诉ttdpatch,文件中有一系列的图形。这是必须的。

This happens through an Action 1 entry, that tells TTDPatch there will be one or more sets of graphics in the file. In our case it looks like this:
2 * 4 01 00 01 08

通过脚本1的段落,就能告诉TTDpatch有一个或多个系列的图形在这个文件里,在我们的教程里,表达如下:

Add this line right after the above action 8. It's worth decoding what this line means. you can just read it from the left to the right. We have the following:

在脚本8定义行之后添加上面那行,该行的表达意义可以参考下表

CodeMeaning
01Action 1
00Feature 0, meaning trains
01One set of graphics
08Each set has eight views


代码意义
01脚本1
00特征 0, 代表火车
01一个系列的图片
08每个系列有8个视角



For more details on these, in particular to see what "features" there are, check the Action 1 docs.

请参考脚本1的文档,来明白特征的意义及相关的细节。

After this follow the eight lines with the actual graphics that we already have in the .nfo file. So at this point your file should look something like this:

现在,接下来的8行就是我们已经保存在.nfo文件中的,如下所示:

// Automatically generated by GRFCODEC. Do not modify!
// (Info version 6)
// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
0 * 4 00 00 00 00
1 * 8 08 06 "TW" 03 05 00 00
2 * 4 01 00 01 08
0 C:\TTD\SPRITES\mytrain.pcx 66 8 01 18 8 -3 -10
1 C:\TTD\SPRITES\mytrain.pcx 82 8 09 15 20 -14 -6
2 C:\TTD\SPRITES\mytrain.pcx 114 8 01 12 28 -14 -6
3 C:\TTD\SPRITES\mytrain.pcx 162 8 09 16 20 -4 -8
4 C:\TTD\SPRITES\mytrain.pcx 194 8 01 18 8 -3 -10
5 C:\TTD\SPRITES\mytrain.pcx 210 8 09 16 20 -14 -7
6 C:\TTD\SPRITES\mytrain.pcx 242 8 01 12 28 -14 -6
7 C:\TTD\SPRITES\mytrain.pcx 290 8 09 15 20 -4 -7


However, if you're doing this for one of your files, you have to choose your own GRFID of course because 54 57 03 05 is reserved for the file we're making in this tutorial.

然而,你需要修改grfid,因为54 57 03 05是教程专用的。

5) Using actions 2 and 3
使用脚本2和3

At this point, TTDPatch knows the GRFID of your file, and it has loaded the graphics for it. The only thing that remains to be done is linking these graphics to one of TTD's vehicles. Note that you can't add new vehicles as such, you can only replace existing ones. This means that you also have to decide which one to replace, so you have to find out the vehicle ID of that vehicle. Since we've based the graphics on the SH 125 here, we might as well replace that one, although you're free to use whichever vehicle you want. There's a list of vehicle IDs here. You can pick any train number from the list, don't forget to convert the number to hex.
Warning: You can only replace trains with trains and ships with ships and so on.

这时,TTDpatch已经知道你的grf文件的grfid了,并且加载了图形。剩下的就是将这些图形与ttd里的运输工具产生替换。注意,你不能添加新的运输工具,你只能替换已有的。这就意味着你可以考虑替换哪一个,因此你需要找出该运输工具的ID。既然我们基于的SH 125,我们最好是替换它,虽然你有自由选择权。这里有一个运输工具ID的列表,你可以从列表中找到一个,别忘了把ID转换成十六进制。
警告:你只能火车替换火车,轮船替换轮船等等。

To associate graphics with a vehicle, we use Action 2 and Action 3. Action 2 is called a "cargo ID", because it contains various states of animation of one particular cargo. This isn't really important for the train engine we're making, but for example wagons may be able to carry different cargos that should also look differently.

通过脚本2和3,可以将图形与一个运输工具联系起来。脚本2被叫做“货物ID",因为它包含了不同状态下的特定货物的动画。这对我们要生成的火车头来说不是特别重要,但例如绘制车厢时就能运输不同的货物而且也看起来不同。

TOP

For our train engine, we define one cargo ID like this:
11 * 9 02 00 00 01 01 00 00 00 00

对于我们的火车头,我们定义一个货物id如下:

This is already getting a bit complicated, so let's look at it in detail:

看起来很复杂,我们列表来看细节:


CodesMeaning
02Action 2
00Feature 00, meaning trains
00We define Cargo ID 0 (the first number available)
01There is only one set of graphics we have while in motion
01And also only one set while loading
00 00Use the first set while in motion
00 00And also while loading/unloading

代码含义
02脚本2
00特征00 ,代表火车
00我们定义货物 ID 0 (第一个可用的数字)
01在运行中,我们只有一个系列的图形
01在装载时也只有一个系列的图形
00 00在运行中,使用第一个系列
00 00在装/卸载中也使用第一个系列


Instead of cargo ID 0, we could have defined any other number, but it makes sense to start with the first number.

我们可以定义货物ID用其它的数字而不是0,但第一个数字起作用。

Regarding the number of sets, it's possible to show various states of animation depending on how full the vehicle is, and whether it's in motion or whether it's loading or unloading. However, for train engines that's unimportant, so we'll forget about it for now.

就系列的数字而言,它可以展示不同状态下的动画不表示该运输工具的满载情况或者是否在运行或者是否在装/卸载。然后,对火车头来讲,这不重要。所以我们现在要忘掉它。

The last sets of two 00 codes tells TTDPatch which sprite-sets to use, referring to the most recent action 1. Since we've only had one set there, and sets are numbered starting from 0, that means we have set 0. We put down the set number 00, followed by another 00 because TTDPatch needs that. If we were using set 1, it would be 01 00.

最后的代码设置为00 00 来告诉TTDPatch使用哪一个sprite系列,指向最近的脚本1。既然我们这里只有一个系列,并且编号从0开始的。因为记为00,紧跟的00 是因为ttdpatch需要它。如果我们需要使用系列1,将是01 00

This is our cargo ID definition. Now we attach this cargo ID to the vehicle using action 3. The SH 125 has vehicle ID 22, or 16 in hex, so we use the following:
12 * 7 03 00 01 16 00 00 00

这是我们的货物id定义,现在我们通过脚本3给这个运输工具赋予货物id,SH 125 的运输工具ID是22,十六进制为16,因此我们这样写:

Again in more detail:
代码含义如下:

代码含义
03脚本 3
00特征 00, 代表火车
01对一个运输工具附加以下图片
16运输工具的 ID是 16 (十六进制)
00没有定义特殊的货物图形
00 00在任何情况下都使用货物ID为0

We could give the same graphics to several vehicles, but that's usually not useful. For wagons, we could also define various cargo IDs and attach them depending on what cargo the wagon carries, but for engines that doesn't matter and so we just use cargo ID 0. Again the first 00 refers to cargo ID 0, and the second 00 is required because TTDPatch needs it.

我们可以对几个运输工具使用同样的图形,但通常没有用。对车厢来讲,我们可以定义多个货物ID并对运输不同的货物时附加不同的图形。但对火车头来讲,就不重要了,所以我们只使用货物ID0。第一个00指向货物ID0,第二个00是TTDPATCH需要的。(通常以00结尾)

At this point, we only need one more action: we need to tell TTDPatch to actually use these new graphics. Action 3 only says if the vehicle uses new graphics, then these are what it should use. To actually make it use new graphics we use Action 0, like this:
13 * 7 00 00 01 01 16 12 FD

现在,我们只需要再加一个脚本,我们需要告诉TTDpatch来使用这些新图形。脚本3仅仅定义了是否使用新图形,如果要使它能使用,我们使用脚本0,如下所示:

In more detail:
代码含义:

CodeMeaning
00Action 0
00Feature 0, meaning trains
01We set one property
01For one vehicle
16Starting at vehicle 16
12We set property 12 (sprite type)
FDAnd we set it to FD

代码含义
00脚本0
00特征0, 代表火车
01定义一个属性
01对一个运输工具
16从运输工具ID 16开始
12设置属性12 (sprite 类型)
FD属性参数设置为 FD


We could set more than one property to give the vehicle for example different power and speed, but for now we only want to see the new graphics, and for trains that means we need to set property 12 to FD, which tells TTDPatch to use new graphics for this vehicle ID. For the other property, check the action 0 docs.

我们可以对运输工具设置多个属性,例如不同的动力和速度,但现在我们只是设置替换图形,对火车而言,我们需要设置属性12 为FD,将告诉TTDpatch对这个ID的运输工具来使用新的图形,其它属性,请查看脚本0的文档

6) Adjust and renumber
调整和重编号

Now we're basically done, we told TTDPatch what graphics to use for what vehicle. We only need to renumber the file and adjust the first pseudosprite. So you go through all the entries, make sure they start at zero and that the following number increases by one. In this case, the last number ends up being 13.

现在,基础的已经做完了,我们告诉了TTDpatch使用什么图形来替换什么运输工具。我们只需要对文件重编号和调整第一个假sprite。因此你检查所有的段落,确认编号从0开始,后面每一段落的数字是递增的。在本文中,最后的编号为13。

Now we have to adjust the first entry, because it needs to tell TTDPatch how many lines to expect for the rest of the file. Since the last line is 13, we set it to 13, but we have to write it in hex in little endian format. 13 in hex is D, which has to have zeroes added from the left to make eight digits, or 0000000D. Now you cut these into groups of two (00 00 00 0D) and write them in the opposite order (0D 00 00 00). That's what you put in the first entry.

现在我们要调整第一段落,因为需要告诉ttdpatch剩余有多少行。既然有13行,我们设置为13,但是我们必须使用十六进制的D来表示13。因为需要增加0来满足8位数,例如0000000D。现在将它们按两位一组分隔开来(00 00 00 0D),然后反过来写(0D 00 00 00),这就是你第一段落的内容。

Now your mytrain.nfo file is done, and it should look like this:
现在,你的.nfo文件做好了,应该像如下所示:

// Automatically generated by GRFCODEC. Do not modify!
// (Info version 6)
// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
0 * 4 0D 00 00 00
1 * 8 08 06 "TW" 03 05 00 00
2 * 4 01 00 01 08
3 C:\TTD\SPRITES\mytrain.pcx 66 8 01 18 8 -3 -10
4 C:\TTD\SPRITES\mytrain.pcx 82 8 09 15 20 -14 -6
5 C:\TTD\SPRITES\mytrain.pcx 114 8 01 12 28 -14 -6
6 C:\TTD\SPRITES\mytrain.pcx 162 8 09 16 20 -4 -8
7 C:\TTD\SPRITES\mytrain.pcx 194 8 01 18 8 -3 -10
8 C:\TTD\SPRITES\mytrain.pcx 210 8 09 16 20 -14 -7
9 C:\TTD\SPRITES\mytrain.pcx 242 8 01 12 28 -14 -6
10 C:\TTD\SPRITES\mytrain.pcx 290 8 09 15 20 -4 -7
11 * 9 02 00 00 01 01 00 00 00 00
12 * 7 03 00 01 16 00 00 00
13 * 7 00 00 01 01 16 12 FD

TOP

7) Encode and add
编译和增加

Now all we have to do is encode the file:

现在,我们要做的就是编译文件

grfcodec -e mytrain.grf


and then add it to newgrf(w).cfg to test it!

然后添加到游戏中测试

Make sure to check the GRF Status Window to see that your file is enabled. If not, click on its red flag and then click "apply". If you get any error messages, write down the sprite number that's incorrect, and then fix the mistake in the corresponding line in the mytrain.nfo file.

请检查grf状态窗口,看看你的grf是否能用。如果不能,请检查红色标记,然后选择运用。如果你得到错误信息,记下错误sprite的数字,然后修正.nfo文件里相应的行。

Further reading
更多

Basically, now you know most of what's needed to make your own graphics. Further details can be found in the GRFActionsDetailed page, which tells you everything about all the actions there are.

基本上,你已经知道了编译文件中绝大多数需要注意的地方。更多的细节可以查看grfactionsdetailed。

The next few sections will cover in some more detail the most common tasks for making new graphics, but other than that you're on your own now!

接下来的单元将

[ 本帖最后由 文涛武略 于 2008-5-28 19:30 编辑 ]

TOP

Action 0脚本0

Defining new graphics feature properties

定义新图形特征和属性

What does it do?

它是怎么工作

Action 0 is similar to TTDAlter in that it changes the feature properties of 'features', i.e. vehicles, stations, bridges, houses and more. That means that you can change properties like:

脚本0有点类似于TTDAlter,改变“特征”属性,运输工具、站台、桥梁、房屋等等的“特征属性”。也就是说,你可以来用修改以下属性:

  • vehicle introduction date
  • top speed
  • wagon capacity
and many more.

运输工具的信息、最高速度,车厢容量,以及更多

Format

格式

The data for Action 0 looks as follows:

脚本0的数据如下所示:

<Sprite-number> * <Length> 00 <Feature> <Num-props> <Num-info> <Id> (<Property <New-info>)...

Here is a short overview of what every term means:
下表是每一个代码的含义

ElementSizeDescription
<Sprite-number> decA sequential sprite number
<Length> decThe total number of bytes in the action
00 BAction type. In this case, 00
<Feature> BWhich type of feature you would like to change
<Num-props> BHow many properties you would like to change per vehicle or station
<Num-info> BHow many vehicles/stations you would like to change
<Id> B*The ID of the first vehicle/station to change
<Property> BWhat property to change for each vehicle/station
<New-info> VThe new value of the property


代码数据类型描述
<Sprite-number> decsprite编号
<Length> dec在这个脚本的数据总量
00 B在本例中,定义为脚本0
<Feature> B你想要修改哪类特征
<Num-props> B你想要修改一个站台/运输工具的多少个属性
<Num-info> B你想要修改多少个站台/运输工具
<Id> B*第一个要修改的站台/运输工具的ID
<Property> B每个站台/运输工具的哪一个属性需要修改
<New-info> V修改后的属性值


You can put an Action 0 anywhere after Action 8 in the GRF file.

你可以将在脚本8之后的任何地方放置脚本0

The <Id> is an extended byte since 2.0.1 alpha 61, to support the definition of >255 sound effects.

从ttdpatch2.01.alpha 61 后,id字段被扩展用以支持>255的音效定义

Filling in the terms
填充代码

Sprite-numberAction 0 can appear anywhere in the GRF file, so set it to the sprite number you are currently at.

脚本0可以出现在grf文件的任何地方,所以将它设置为你目前所在行的编号

LengthThe total number of bytes in Action 0. Start counting from <Action>, the bit that sets the pseudo-sprite to act as the specified action.

脚本0中的总字节数,从<action>计算起,该位被设置成假sprite用来使脚本起作用

ActionThe type of action this pseudo-sprites defines. It should be 00 here because we want this pseudo-sprite to act as Action 0.

假sprite定义的脚本类型,这里我们需要设置00为假sprite来使脚本0起作用

FeatureThis sets the type of feature that you wish to change. Set it to:
本代码设置你想要修改的特征,设置如下:

00 for trains    火车
01 for road vehicles    汽车
02 for ships       轮船
03 for planes        飞机
04 for stations       站台
05 for canals        隧道
06 for bridges      桥梁
07 for houses (see defaults)   房屋(查看默认)
08 for global variables     全局变量
09 for industry tiles (see defaults)   
0A for industries (see defaults)     工业
0B for cargos (see defaults)    货物
0C for sound effects       音效
0D for airports (No official properties)   机场(非官方属性)
0E for signals (Action 0 is not valid for this feature)  信号灯(脚本0不可用在这个特征上)
0F for newobjects  新事物

Note that the above list is the master list for all actions where not stated otherwise.
(不会翻译)

TOP

Num-propsThis is the number of properties that you wish to change per vehicle or station. Note: even if you wish to set the same properties to the same value for different vehicles then you must still repeat the properties and their values for each vehicle.

这个数字定义了你想要修改的每个站台或者运输工具的属性。注意:即便你想要将不同运输工具的同一属性设置成同一个值,你也必须重复对每一个运输工具的设置

Num-infoSimply the number of vehicles that you will change using this action 0.

你想通过脚本0来修改的运输工具数量

IdThe Vehicle ID of the first vehicle or station to change. If num-info is greater than one, this vehicle/station and the following vehicles/stations will be changed.

你想要修改的第一个运输工具或站台的ID。如果数量大于一个的话,这个运输工具/站台和接下来的一个运输工具/站台将会被改变。

PropertyThe number of the property that will be changed. This and the New-info section are repeated as many times as there are properties to set; in total, there are <num-props> property bytes.
See relevant sub-section (links at the bottom) for more details.

这个数字是你将要修改的属性值。这和New-info字段一直重复到有多少个需要修改的属性值。这就是<num-pros>里设置的值。

New-infoThe new information that will replace the previous information for the specified property. This is a variable size; dependent upon the property. Each property byte is followed by <num-info> new-info sections.

新的信息将会取代指定属性的预定义信息。这是一个可变的数组,取决于属性,跟在<num-info>字段后。

The appropriate \b, \w, and \d escape sequences can be quite useful for most <new-info>s. See the discussion of escape sequences for further information.

适当的使用\b,\w和\d对更多的<new-info>有好处(排版顺序),请查看相关的讨论。

Features and properties
特征和属性

Each feature has its own very specific properties. These are explained in detail in the pages listed below:

每一个特征都有自己指定的属性,如下所示:

    Action0General - Action 0 properties common to all vehicle types   脚本0中所有运输工具类型的通用属性Action0Trains - Action 0 properties for trains  脚本0中火车的属性Action0RoadVehicles - Action 0 properties for road vehicles  脚本0中汽车的属性Action0Ships - Action 0 properties for ships  脚本0中轮船的属性Action0Planes - Action 0 properties for planes  脚本0中飞机的属性Action0Stations - Action 0 properties for new stations 脚本0中新站台的属性Action0Canals - Action 0 - Properties for canals / rivers 脚本0中隧道/河流的属性Action0Bridges - Defining properties of bridges 桥梁的属性定义Action0Houses - Action 0 properties of houses 脚本0中房屋的属性
    • DefaultHouseProps - Default property values for TTD's houses ttd中房屋的默认属性
    Action0GeneralVariables - Action 0 properties for general variables 脚本0中全局变量的属性Action0IndustryTiles - Action 0 properties for industry tiles 脚本0中Action0Industries - Action 0 properties for industries 脚本0中工业的属性Action0Cargos - Action 0 properties for cargo types 脚本0的货物类型的属性
    • CargoDefaultProps - Default property values for TTD's cargo types TTD中默认的货物类型属性
    Action0SoundEffects - Action 0 properties for new sound effects 脚本0中新音效的属性
  • Action0Objects - Action 0 properties for new objects 脚本0中新事物的属性

You will also find the minimum GRF version (in Action 8) that supports this property, or alternatively if the property was introduced between version changes, the patch version number that you can check with Action 7.

你也可以找到最低版本的grf(在脚本8中)来支持这个属性或者在脚本7中找到可选的替代这些的版本。

Example
例如

For examples please see the action 0 entries for each feature.

请查看脚本0的链接来获得详情

TOP

Action 0 - General properties for all vehicle types
脚本0-所有运输工具类型的通用属性

Defining properties of vehicles.

运输工具的属性定义

Introduction
The four vehicle types (trains, road vehicles, ships and planes) all have some common properties, which are described here.

介绍
四种运输工具(火车、汽车、轮船和飞机)都有一些共同的属性,如下所述:

Properties

NumberVersionSizeDescription
00Wdate of introduction
02Breliability decay speed
03Bvehicle life in years
04Bmodel life in years
06Bclimate availability
072Bload amount

属性

序号版本大小描述
00W引入日期(感觉像是提前通知的试用时间)
02B可靠性的衰减速度
03B寿命
04B(好像是制造日期)
06B适用的气候类型
072B装载量


Properties 00 to 06 only apply to new games, or when using Cht: ResetVehicles.

属性00-06只在新游戏里生效,或者使用作弊命令(TTDPATCH中)。

Description

描述

Date of introduction
引入日期

The date is specified as number of days since 1920 where TTD counts 365,25 days in a year. It will have a random number from 0 to 511 days added to it at the start of every new game, or after using "Cht: ResetVehicles". Note that TTD stops updating vehicle type data after the game ends in 2050, so all dates of introduction should be no later than in 2044, to ensure that all vehicle types can be introduced and reach their maximum reliability.

这个日期详述了一个天数,从1920年起,每一年为365.25天。在新开始一个游戏或者使用作弊命令时,将会随机增加0-511天在这个数上。注意,ttd会在2050后停止更新车辆类型,因此这个日期不能晚于2044年。以保证这个运输工具能引入且达到最大的可靠性。

If the property value is 729 (2D9h) or less, i.e. before 1922, the random number is not added and the vehicle is introduced at exactly the given date.

如果这个数小于等于729(2D9H),例如,在1922年前,这个数字就不再增加随机数了。

The \w<date> escape sequence is especially useful here. See the discussion of escape sequences for further information.

命令\w<日期>特别有用,请参考相关教程为获取更多的信息。

Reliability decay speed
可靠性的衰减速度

The reliability decay speed is set when a new vehicle is bought, and specifies how quickly the reliability decays after servicing. The initial TTD default for all vehicles is 20. If a vehicle goes without servicing for a long time, or if it gets very, very old, this number increases, meaning faster decay and more breakdowns. Larger numbers mean faster decay, smaller number slower decay. If set to 0, reliability never decreases in normal operation.

当一个运输工具购买以后,可靠性的衰减速度决定了该运输工具在维修后的可靠性衰减程序,

Vehicle life
运输工具的寿命

The number of years before a particular vehicle is considered too old and needs replacing,

决定了特定运输工具需要更新的年限。

Model life
模型年限

The number of years that this model can be bought in the game (if PersistentEngines is off). Usually this should be at least twice or three times as long as the vehicle life. When starting a new game, a random amount between 31 months and 17 years is added to this as well.

这个数字定义了这个运输工具可以购买的时间(如果ttdpatch里的某个开关为关的话,openttd里好像是车辆永不过期)。通常这个数字应该是运输工具寿命的2-3倍。当开始一个新游戏时,一个随机在31个月-17年的数字将会被加入这个数里。

If the early retirement property (26/1B/16/16) is not set, the model life works like this:

如果最早退役属性(26/1B/16/16)没有设置,模型年限将按以下方式运行:

PhaseDurationReliability
17 to 38 monthsincreases from 48-73% to 75-100%
2prop. 04 less 8 yearsstays constant at peak, 75-100%
310 to 20.5 yearsdecreases from peak to 25-50%

阶段持续时间可靠性
17 -38月由 48-73% 增加到 75-100%
24- 8年保持在 75-100%
310 -20.5年衰减到 25-50%


(the ranges in time and reliability are randomized at the start of each game)

时间和可靠性的范围在新游戏生成时随机生成。

At the end of phase 3, the model is retired and removed from the purchase list. Note that when the model reliability starts dropping in phase 3, so does the reliability of every single vehicle of this make in the game.

在阶段3之后,模型退役并从购买列表中移除。注意,当模型可靠性在第三阶段开始下降时,每一个由些模型制造的运输工具都会降低可靠性。

If persistentengines is on, the model never gets to within two years of the end of phase 2, it is kept in phase 2 as long as at least one vehicle of this make is in the game.

如果持续车头为开启的话,模型将不会到达阶段2的末两年,每一个由此模型制造的运输工具将保持在第2阶段

If the early retirement property is set, the vehicle is retired this many years before the end of phase 2 (can be negative if desired), but not if persistentengines would keep the model alive.

不会翻了

Climate availability
气候

This is a bit mask of the climates in which this model is available. Simply add the values for the climates:

模型在该气候不可用时,该字段设置了隐藏属性,仅仅添加以下值

BitValueClimate
01Temperate
12Arctic
24Tropical
38Toyland

气候
01温带
12寒带
24沙漠
38玩具



For example, 1+2+4 = 07 would make a vehicle available in all climates except Toyland.

例如:1+2+4=07将使一个运输可以在除玩具外的所有气候中使用。

Load amount
装载量

This is the amount of cargo transferred per unit of time if using gradualloading. The default is 5 for trains and road vehicles, 10 for ships and 20 for aircraft.

如果使用渐进装载的话,这个量是每单位时间货物的装载量。火车和汽车默认为5,轮船是10,飞机是20

TOP

提示: 作者被禁止或删除 内容自动屏蔽

TOP

返回列表