<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://www.tt-wiki.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Supercheese</id>
	<title>TTWiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://www.tt-wiki.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Supercheese"/>
	<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/wiki/Special:Contributions/Supercheese"/>
	<updated>2026-05-02T04:10:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=NMLTutorial/Train_four_part_refit&amp;diff=8583</id>
		<title>NMLTutorial/Train four part refit</title>
		<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=NMLTutorial/Train_four_part_refit&amp;diff=8583"/>
		<updated>2012-09-15T19:35:12Z</updated>

		<summary type="html">&lt;p&gt;Supercheese: /* What&amp;#039;s going to happen */ There is a way to charge for refits, but it has some issues&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NMLTutorial}}&lt;br /&gt;
&#039;&#039;The example used here is from the [http://dev.openttdcoop.org/projects/nml/repository/show/examples NML source]. The code for this was originally written in NFO by DJNekkid for the 2cc Trainset and rewritten in NML by Hirundo. The graphics used in the example are by Purno. Code and graphics are both licensed according to the GPL v2 or later. The code has been modified for the purpose of this tutorial&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This continues the [[NMLTutorial/Train three part articulated|third part]] of the train example. The three part EMU will be made refittable to a four part EMU.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What&#039;s going to happen ==&lt;br /&gt;
A lot of things need to be added to make this train refittable between three and four parts.&lt;br /&gt;
&lt;br /&gt;
The method used to do this is actually the other way round than the user will think from the behaviour ingame. The train will be changed to a four part EMU. For the (default) three part refit one of these four parts will be hidden. A lot of switches will be used to make the train look right, make it have the correct capacity, power, weight, running costs and tractive effort.&lt;br /&gt;
&lt;br /&gt;
There are some drawbacks to this method. There is a way to charge the player for the extra vehicle part, but it has some issues, and we shall not bother with it here (if you want more details, feel free to check out [http://www.tt-forums.net/viewtopic.php?f=26&amp;amp;t=62672#p1046538 the source code of the Fake Subways GRF]). Also autoreplacing will be difficult, as there&#039;s no way for the user to select which vehicle length they want. For that reason the author of this tutorial thinks making two different vehicles and having both available from the purchase menu is a better solution, but this method is a good illustration for some of the more advanced features of NML. It&#039;s up to you to decide which implementation you think is best for your vehicles.&lt;br /&gt;
&lt;br /&gt;
What we&#039;ll be doing:&lt;br /&gt;
* Add the refit option;&lt;br /&gt;
* Make the graphics work;&lt;br /&gt;
* Add callbacks to supply the correct vehicle properties;&lt;br /&gt;
* Make the purchase menu display the correct values.&lt;br /&gt;
&lt;br /&gt;
== Refit option ==&lt;br /&gt;
The refit option will be added by means of the &amp;quot;cargo subtype&amp;quot;. This allows to split each cargo into multiple entities which can be assigned different properties by means of other callbacks.&lt;br /&gt;
&lt;br /&gt;
The first step towards this is defining names for these separate entries using the &amp;lt;code&amp;gt;cargo_subtype_text&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback]. This callback requires the use of a switch, so reference a switch from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        cargo_subtype_text:           sw_icm_cargo_subtype_text;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The switch itself will use the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable]. This variable starts at 0 and will be increased by 1 until the callback returns &amp;lt;code&amp;gt;CB_RESULT_NO_MORE_ARTICULATED_PARTS&amp;lt;/code&amp;gt;. Return strings to use as cargo subtype. Each returned string will be a separate cargo subtype:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_cargo_subtype_text, cargo_subtype) {&lt;br /&gt;
    0: return string(STR_ICM_SUBTYPE_3_PART);&lt;br /&gt;
    1: return string(STR_ICM_SUBTYPE_4_PART);&lt;br /&gt;
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This adds two cargo subtypes. Also add these strings to the language file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
STR_ICM_SUBTYPE_3_PART       : (3 parts)&lt;br /&gt;
STR_ICM_SUBTYPE_4_PART       : (4 parts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Graphics ==&lt;br /&gt;
The graphics defined previously were for a three part vehicle. Now we have to make this into a four part vehicle and hide one wagon for the three part refit.&lt;br /&gt;
&lt;br /&gt;
=== Four part articulated vehicle ===&lt;br /&gt;
In order to make the vehicle four parts, the articulated vehicle callback switch needs to be changed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_articulated_part, extra_callback_info1) {&lt;br /&gt;
    /* Add three articulated parts, for a total of four */&lt;br /&gt;
    1 .. 3: return item_icm;&lt;br /&gt;
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is done by changing the value range from &amp;lt;code&amp;gt;1 .. 2&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;1 .. 3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Start/stop callback ===&lt;br /&gt;
The start/stop callback checking the vehicle length needs to be changed as well. If we still want a maximum of four EMUs, the maximum length will now be 4 * 4 instead of 4 * 3. This means changing the switch for this callback:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_start_stop, num_vehs_in_consist) {&lt;br /&gt;
    /* Vehicles may be coupled to a maximum of 4 units (12-16 cars) */&lt;br /&gt;
    1 .. 16: return CB_RESULT_NO_TEXT;&lt;br /&gt;
    return string(STR_ICM_CANNOT_START);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is done by changing the value range from &amp;lt;code&amp;gt;1 .. 12&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;1 .. 16&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Graphics ===&lt;br /&gt;
Now that the vehicle is four parts, the default graphics switch needs to be changed as well to allow for two middle parts instead of one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics, position_in_consist % 4) {&lt;br /&gt;
    0:      set_icm_front_lighted;&lt;br /&gt;
    3:      set_icm_rear_lighted;&lt;br /&gt;
    sw_icm_graphics_middle;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of modulo 3 we&#039;re now taking modulo 4. And the value for the rear vehicle part was changed from 2 to 3. For the middle parts, we also need to hide the one of the wagons for the three part EMU. Therefore we can&#039;t directly reference the spriteset but need an extra intermediate switch block.&lt;br /&gt;
&lt;br /&gt;
The extra switch block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics_middle, ((position_in_consist % 4) == 2) &amp;amp;&amp;amp; (cargo_subtype == 0)) {&lt;br /&gt;
    1: set_icm_invisible;&lt;br /&gt;
    set_icm_middle;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Even an expression this advanced can be used for switch block decision. Here we again check the position of the vehicle part, but also which cargo subtype is used for this vehicle. If it is the three part EMU (cargo subtype 0) AND it is the third vehicle part (position 2 counting from 0), we hide this vehicle part by displaying no graphics for it. In all other cases we display the regular middle part.&lt;br /&gt;
&lt;br /&gt;
=== Vehicle length ===&lt;br /&gt;
If you were to encode the result so far as a NewGRF, you end up with a three part train that has a big gap between the second and last part. This is because it&#039;s essentially still a four part vehicle, just with no graphics for the third part. This can be solved by changing the length of the two middle parts. If we make the second part (7/8) long and the third part (1/8), both together are a full wagon length, completely hiding the invisible third part.&lt;br /&gt;
&lt;br /&gt;
This is done by means of the &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback], referencing a switch block as we first need to differentiate between the two cargo subtypes and then by the position in consist. Reference the switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        length:              sw_icm_shorten_vehicle;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we get the two switch blocks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
/* --- Shorten vehicle callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_shorten_3_part_vehicle, position_in_consist % 4) {&lt;br /&gt;
    /* In the three part version, shorten the 2nd vehicle to 7/8 and the 3rd to 1/8&lt;br /&gt;
     * The rear (1/8) part is then made invisisble */&lt;br /&gt;
    1: return 7;&lt;br /&gt;
    2: return 1;&lt;br /&gt;
    return 8;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_shorten_vehicle, cargo_subtype) {&lt;br /&gt;
    0: sw_icm_shorten_3_part_vehicle;&lt;br /&gt;
    return 8; // 4-part vehicle needs no shortening&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second of these switch blocks (called first from the graphics block) differentiates between the two cargo subtypes. For subtype 0 (three part vehicle) we need to do the shortenings and reference the first switch block. For the four part vehicle we need no shortening, so directly return to &amp;quot;shorten&amp;quot; to full length.&lt;br /&gt;
&lt;br /&gt;
The first switch again makes a decision based on the &amp;lt;code&amp;gt;position_in_consist&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable] we&#039;ve seen several times now. As said, the second part will be shortened to (7/8), the third part to (1/8) and the front and back part are kept full length (8/8).&lt;br /&gt;
&lt;br /&gt;
Now the vehicle looks good in both refits.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Vehicle properties ==&lt;br /&gt;
Both refits still have identical properties. Surely the four part EMU has a higher capacity. We&#039;ll also change the running costs, power, weight and tractive effort depending on the refit chosen. This is all done by callbacks. You can find the available vehicle callbacks [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks here], with the second table especially on callbacks that change certain properties.&lt;br /&gt;
&lt;br /&gt;
=== Running cost factor ===&lt;br /&gt;
You can easily imagine that the longer vehicle will be more expensive to run. The three part has a running cost factor of 100, the four part will get a factor of 150. This requires adding the &amp;lt;code&amp;gt;running_cost_factor&amp;lt;/code&amp;gt; callback to the graphics block. From there we can link to a switch block and base the decision on the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable]. A different method as shown below is not to use a switch block but to make the decision directly from the graphics block using a conditional assignment. We&#039;ve used a conditional assignment [[Train_single_engine#Templates|before]] in one of the template blocks.&lt;br /&gt;
&lt;br /&gt;
Add to the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        running_cost_factor:          return (cargo_subtype == 1) ? 150 : 100;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; is 1 (the four part vehicle), a running cost factor of 150 is used. Otherwise, a factor of 100 is used. If you&#039;d rather used a switch block then that&#039;s up to you. Just reference one from the graphics block instead of the conditional assignment and use the switch block to make the decision based on the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
=== Cargo capacity ===&lt;br /&gt;
The cargo capacity is 36 passengers per unit. Now the three part EMU will have a capacity that is too high, because it technically is a four part EMU with one part hidden. We need to give this hidden part 0 capacity.&lt;br /&gt;
&lt;br /&gt;
This is done by the &amp;lt;code&amp;gt;cargo_capacity&amp;lt;/code&amp;gt; callback. If the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; is 0 and the &amp;lt;code&amp;gt;position_in_consist&amp;lt;/code&amp;gt; is the third part, we give it 0 capacity. Else it will get 36 capacity. Also this can be done directly from the graphics block, using a slightly more advanced conditional assignment. Of course you could again have used a switch block here, but there&#039;s no need for that in this case.&lt;br /&gt;
&lt;br /&gt;
Add to the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
cargo_capacity:               return (cargo_subtype == 0) &amp;amp;&amp;amp; ((position_in_consist % 4) == 2) ? 0 : 36;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Power ===&lt;br /&gt;
The power of the four part vehicle will be higher. Let&#039;s use a switch block this time. Of course a conditional assignment could be used here, but compare this example with the running cost factor yourself. The callback used here is called &amp;lt;code&amp;gt;power&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Reference the switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        power:                        sw_icm_power;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The switch block itself will again make a decision based on the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; variable. The callback must return the vehicle power in horsepower (imperial) and this must be an integer value. Because we know the power in kW, a little calculation is needed which NML can do for you. Returning the integer is done by the &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; function that turns a (decimal) number into an integer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_power, cargo_subtype) {&lt;br /&gt;
    0: return int(1260 / 0.7457); // kW -&amp;gt; hp&lt;br /&gt;
    return int(1890 / 0.7457); // kW -&amp;gt; hp&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Weight ===&lt;br /&gt;
Of course you could have done the calculation yourself and put the rounded values in the switch block. That we&#039;ll do for the weight of the vehicle. The callback used here is called &amp;lt;code&amp;gt;weight&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Again, reference the switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
weight:                       sw_icm_weight;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The switch block itself will again make a decision based on the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; variable. The weight here must be specified in tons:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_weight, cargo_subtype) {&lt;br /&gt;
    0: return 144; //ton, 3 part train&lt;br /&gt;
    return 192; //ton, 4 part train&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tractive effort coefficient===&lt;br /&gt;
The last property to sort out is the tractive effort. The callback used here is called &amp;lt;code&amp;gt;tractive_effort_coefficient&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Again, reference the switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        tractive_effort_coefficient:  sw_icm_te;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the switch block we&#039;ll actually calculate the tractive effort coefficient:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_te, cargo_subtype) {&lt;br /&gt;
    /* Base TE coefficient = 0.3&lt;br /&gt;
     * 3 parts: 4/12 of weight on driving wheels&lt;br /&gt;
     * 4 parts: 6/16 of weight on driving wheels */&lt;br /&gt;
    0: return int(0.3 * 255 / 3);&lt;br /&gt;
    return int(0.3 * 255 * 3 / 8);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The technical background of the tractive effort coefficient is that it must be supplied as value between 0 and 255, with 255 equal to 100%. The tractive effort coefficient itself is calculated by multiplying the friction coefficient (see [http://en.wikipedia.org/wiki/Rail_adhesion Wikipedia] for it&#039;s meaning) with the percentage of weight that is on driven wheels. I this case we use a friction of 30%. In real life the three part vehicle has 12 axles of which 4 powered. The four part vehicle has 16 axles of which 6 powered. Assuming an equal distribution of weight along the length of the vehicle, the three part vehicle has 33.3% of it&#039;s weight on powered wheels. The four part vehicle has 37.5% of it&#039;s weight on powered wheels. Multiply both by the friction coefficient and the factor of 255 and you have the tractive effort coefficient.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;If you don&#039;t provide a tractive effort coefficient, the game will assume a friction coefficient of 0.3 and all axles powered. A tractive effort coefficient of 100% you&#039;ll only get with 100% friction and and all axles powered. This is unrealistic for railroads but can be used for maglev when there actually is no contact between vehicle and guideway.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Purchase menu ==&lt;br /&gt;
With all these callbacks we&#039;ve sort of broken the display of properties in the purchase menu. This is because the &amp;lt;code&amp;gt;position_in_consist&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable] is not available in the purchase menu and &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; variable is always 0 in the purchase menu. The latter can be to our advantage if we want to display the properties of the shorter refit, but the other needs some fixing.&lt;br /&gt;
&lt;br /&gt;
=== Running cost factor ===&lt;br /&gt;
This callback was only based on &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt;, so no fixing needed here.&lt;br /&gt;
&lt;br /&gt;
=== Cargo capacity ===&lt;br /&gt;
The capacity used both variables, so some fixing is in order here. We want to display 36*3 as capacity. Because capacity is defined per unit and our vehicle is technically four units, we need to divide this over four units: 36*3/4. Add the &amp;lt;code&amp;gt;purchase_cargo_capacity&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback] to the graphics block and return this value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        purchase_cargo_capacity:      return 36 * 3 / 4;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Power, weight and tractive effort coefficient ===&lt;br /&gt;
Luckily, these are also only based on the cargo subtype variable, so no fixing needed. If you wanted a different value to be displayed in the purchase menu, you&#039;d use the &amp;lt;code&amp;gt;purchase_power&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;purchase_weight&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;purchase_tractive_effort_coefficient&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callbacks] to do this. And if you want to know, the running cost factor would logically use the &amp;lt;code&amp;gt;purchase_running_cost_factor&amp;lt;/code&amp;gt; callback.&lt;br /&gt;
&lt;br /&gt;
=== Additional text ===&lt;br /&gt;
We want to inform the user that this train has an option to refit it into a four part version and that the properties shown are for the three part version. For this we&#039;ll use the &amp;lt;code&amp;gt;additional_text&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback] which we also used in the tram example. It can directly return a string from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        additional_text:              return string(STR_ICM_ADDITIONAL_TEXT);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also don&#039;t forget to add this string to the language file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
STR_ICM_ADDITIONAL_TEXT      :Choose between 3- and 4-part EMU via refit{}Stated values are for the 3-part variant, the 4-part version has 33% more capacity and 50% more power and running cost.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This means our vehicle now works like it should with the two refits. Encode it into a NewGRF if you like.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Total code so far ==&lt;br /&gt;
When put in the correct order, this should now encode as a working NewGRF. The total code so far:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap; max-height: 200px; overflow:scroll&amp;quot;&amp;gt;&lt;br /&gt;
/* Define grf */&lt;br /&gt;
grf {&lt;br /&gt;
    grfid: &amp;quot;NML\00&amp;quot;;&lt;br /&gt;
    /* GRF name and description strings are defined in the lang files */&lt;br /&gt;
    name: string(STR_GRF_NAME);&lt;br /&gt;
    desc: string(STR_GRF_DESC);&lt;br /&gt;
    /* This is the first version, start numbering at 0. */&lt;br /&gt;
    version: 0;&lt;br /&gt;
    min_compatible_version: 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Define a rail type table,&lt;br /&gt;
 * this allows referring to railtypes&lt;br /&gt;
 * irrespective of the grfs loaded.&lt;br /&gt;
 */&lt;br /&gt;
railtypetable {&lt;br /&gt;
    ELRL&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Basic template for 4 vehicle views */&lt;br /&gt;
template tmpl_vehicle_basic(x, y) {&lt;br /&gt;
    // arguments x, y: coordinates of top-left corner of first sprite&lt;br /&gt;
    [x,      y,  8, 24,  -3, -12] //xpos ypos xsize ysize xrel yrel&lt;br /&gt;
    [x +  9, y, 22, 20, -14, -12]&lt;br /&gt;
    [x + 32, y, 32, 16, -16, -12]&lt;br /&gt;
    [x + 65, y, 22, 20,  -6, -12]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Template for a vehicle with only 4 views (symmetric) */&lt;br /&gt;
template tmpl_vehicle_4_views(num) {&lt;br /&gt;
    // argument num: Index in the graphics file, assuming vertical ordering of vehicles&lt;br /&gt;
    tmpl_vehicle_basic(1, 1 + 32 * num)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Template for a vehicle with 8 views (non-symmetric) */&lt;br /&gt;
template tmpl_vehicle_8_views(num, reversed) {&lt;br /&gt;
    // argument num: Index in the graphics file, assuming vertical ordering of vehicles&lt;br /&gt;
    // argument reversed: Reverse visible orientation of vehicle, if set to 1&lt;br /&gt;
    tmpl_vehicle_basic(reversed ? 89 : 1, 1 + 32 * num)&lt;br /&gt;
    tmpl_vehicle_basic(reversed ? 1 : 89, 1 + 32 * num)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Template for a single vehicle sprite */&lt;br /&gt;
template tmpl_vehicle_single(num, xsize, ysize, xoff, yoff) {&lt;br /&gt;
    [1, 1 + 32 * num, xsize, ysize, xoff, yoff]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Define the spritesets, these allow referring to these sprites later on */&lt;br /&gt;
spriteset (set_icm_front_lighted, &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_8_views(0, 0) }&lt;br /&gt;
spriteset (set_icm_rear_lighted,  &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_8_views(1, 1) }&lt;br /&gt;
spriteset (set_icm_front,         &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_8_views(2, 0) }&lt;br /&gt;
spriteset (set_icm_rear,          &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_8_views(3, 1) }&lt;br /&gt;
spriteset (set_icm_middle,        &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_4_views(4)    }&lt;br /&gt;
spriteset (set_icm_purchase,      &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_single(5, 53, 14, -25, -10) }&lt;br /&gt;
spriteset (set_icm_invisible,     &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_single(6,  1,  1,   0,   0) }&lt;br /&gt;
&lt;br /&gt;
/* --- Graphics callback  --- */&lt;br /&gt;
&lt;br /&gt;
/* In the 3-part version, the 3rd car is invisible */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics_middle, ((position_in_consist % 4) == 2) &amp;amp;&amp;amp; (cargo_subtype == 0)) {&lt;br /&gt;
    1: set_icm_invisible;&lt;br /&gt;
    set_icm_middle;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Choose between front, middle and back parts */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics, position_in_consist % 4) {&lt;br /&gt;
    0:      set_icm_front_lighted;&lt;br /&gt;
    3:      set_icm_rear_lighted;&lt;br /&gt;
    set_icm_middle;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Cargo subtype text --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_cargo_subtype_text, cargo_subtype) {&lt;br /&gt;
    0: return string(STR_ICM_SUBTYPE_3_PART);&lt;br /&gt;
    1: return string(STR_ICM_SUBTYPE_4_PART);&lt;br /&gt;
    return CB_RESULT_NO_TEXT;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Articulated part callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_articulated_part, extra_callback_info1) {&lt;br /&gt;
    /* Add three articulated parts, for a total of four */&lt;br /&gt;
    1 .. 3: return item_icm;&lt;br /&gt;
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Start/stop callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_start_stop, num_vehs_in_consist) {&lt;br /&gt;
    /* Vehicles may be coupled to a maximum of 4 units (12-16 cars) */&lt;br /&gt;
    1 .. 16: return CB_RESULT_NO_TEXT;&lt;br /&gt;
    return string(STR_ICM_CANNOT_START);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Wagon attach callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_can_attach_wagon, vehicle_type_id) {&lt;br /&gt;
    /* SELF refers to the wagon here, check that it&#039;s an ICM */&lt;br /&gt;
    item_icm: return CB_RESULT_ATTACH_ALLOW;&lt;br /&gt;
    return string(STR_ICM_CANNOT_ATTACH_OTHER);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Shorten vehicle callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_shorten_3_part_vehicle, position_in_consist % 4) {&lt;br /&gt;
    /* In the three part version, shorten the 2nd vehicle to 7/8 and the 3rd to 1/8&lt;br /&gt;
     * The rear (1/8) part is then made invisisble */&lt;br /&gt;
    1: return 7;&lt;br /&gt;
    2: return 1;&lt;br /&gt;
    return 8;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_shorten_vehicle, cargo_subtype) {&lt;br /&gt;
    0: sw_icm_shorten_3_part_vehicle;&lt;br /&gt;
    return 8; // 4-part vehicle needs no shortening&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Power, weight and TE are all applied to the front vehicle only */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_power, cargo_subtype) {&lt;br /&gt;
    0: return int(1260 / 0.7457); // kW -&amp;gt; hp&lt;br /&gt;
    return int(1890 / 0.7457); // kW -&amp;gt; hp&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_weight, cargo_subtype) {&lt;br /&gt;
    0: return 144; //ton, 3 part train&lt;br /&gt;
    return 192; //ton, 4 part train&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_te, cargo_subtype) {&lt;br /&gt;
    /* Base TE coefficient = 0.3&lt;br /&gt;
     * 3 parts: 4/12 of weight on driving wheels&lt;br /&gt;
     * 4 parts: 6/16 of weight on driving wheels */&lt;br /&gt;
    0: return int(0.3 * 255 / 3);&lt;br /&gt;
    return int(0.3 * 255 * 3 / 8);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Define the actual train */&lt;br /&gt;
item(FEAT_TRAINS, item_icm) {&lt;br /&gt;
    /* Define properties first, make sure to set all of them */&lt;br /&gt;
    property {&lt;br /&gt;
        name:                         string(STR_ICM_NAME);&lt;br /&gt;
        // not available in toyland:&lt;br /&gt;
        climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); &lt;br /&gt;
        introduction_date:            date(1983, 1, 1);&lt;br /&gt;
        model_life:                   VEHICLE_NEVER_EXPIRES;&lt;br /&gt;
        vehicle_life:                 30;&lt;br /&gt;
        reliability_decay:            20;&lt;br /&gt;
        refittable_cargo_classes:     bitmask(CC_PASSENGERS);&lt;br /&gt;
        non_refittable_cargo_classes: bitmask();&lt;br /&gt;
        // refitting is done via cargo classes only, no cargo types need explicit enabling/disabling&lt;br /&gt;
        // It&#039;s an intercity train, loading is relatively slow:&lt;br /&gt;
        loading_speed:                6; &lt;br /&gt;
        cost_factor:                  45;&lt;br /&gt;
        running_cost_factor:          100; // Changed by callback&lt;br /&gt;
        sprite_id:                    SPRITE_ID_NEW_TRAIN;&lt;br /&gt;
        speed:                        141 km/h; // actually 140, but there are rounding errors&lt;br /&gt;
        misc_flags:                   bitmask(TRAIN_FLAG_2CC, TRAIN_FLAG_MU);&lt;br /&gt;
        refit_cost:                   0; //refit costs don&#039;t apply to subcargo display &lt;br /&gt;
        // callback flags are not set manually&lt;br /&gt;
        track_type:                   ELRL; // from rail type table&lt;br /&gt;
        ai_special_flag:              AI_FLAG_PASSENGER;&lt;br /&gt;
        power:                        1260 kW; // Changed by CB&lt;br /&gt;
        running_cost_base:            RUNNING_COST_ELECTRIC;&lt;br /&gt;
        dual_headed:                  0;&lt;br /&gt;
        cargo_capacity:               36; // per part, changed by callback&lt;br /&gt;
        weight:                       144 ton; // Total, changed by callback&lt;br /&gt;
        ai_engine_rank:               0; // not intended to be used by the ai&lt;br /&gt;
        engine_class:                 ENGINE_CLASS_ELECTRIC;&lt;br /&gt;
        extra_power_per_wagon:        0 kW;&lt;br /&gt;
        // 4/12 of weight on driving wheels, with a default friction coefficient of 0.3:&lt;br /&gt;
        tractive_effort_coefficient:  0.3 / 3; // changed by callback&lt;br /&gt;
        air_drag_coefficient:         0.06;&lt;br /&gt;
        shorten_vehicle:              SHORTEN_TO_8_8;&lt;br /&gt;
        // Overridden by callback to disable for non-powered wagons:&lt;br /&gt;
        visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_ELECTRIC, 2, DISABLE_WAGON_POWER);&lt;br /&gt;
        extra_weight_per_wagon:       0 ton;&lt;br /&gt;
        bitmask_vehicle_info:         0;&lt;br /&gt;
    }&lt;br /&gt;
    /* Define graphics and callbacks&lt;br /&gt;
     * Setting all callbacks is not needed, only define what is used */&lt;br /&gt;
    graphics {&lt;br /&gt;
        default:                      sw_icm_graphics;&lt;br /&gt;
        purchase:                     set_icm_purchase;&lt;br /&gt;
        cargo_subtype_text:           sw_icm_cargo_subtype_text;&lt;br /&gt;
        additional_text:              return string(STR_ICM_ADDITIONAL_TEXT);&lt;br /&gt;
        start_stop:                   sw_icm_start_stop;&lt;br /&gt;
        articulated_part:             sw_icm_articulated_part;&lt;br /&gt;
        can_attach_wagon:             sw_icm_can_attach_wagon;&lt;br /&gt;
        running_cost_factor:          return (cargo_subtype == 1) ? 150 : 100;&lt;br /&gt;
        /* Capacity is per part */&lt;br /&gt;
        cargo_capacity:               return (cargo_subtype == 0) &amp;amp;&amp;amp; ((position_in_consist % 4) == 2) ? 0 : 36;&lt;br /&gt;
        /* In the purchase menu, we want to show the capacity for the three-part version,&lt;br /&gt;
         * i.e. divide the capacity of three cars across four */&lt;br /&gt;
        purchase_cargo_capacity:      return 36 * 3 / 4;&lt;br /&gt;
        length:                       sw_icm_shorten_vehicle;&lt;br /&gt;
        /* Only the front vehicle has power */&lt;br /&gt;
        power:                        sw_icm_power;&lt;br /&gt;
        /* Only the front vehicle has weight */&lt;br /&gt;
        weight:                       sw_icm_weight;&lt;br /&gt;
        /* Only the front vehicle has TE */&lt;br /&gt;
        tractive_effort_coefficient:  sw_icm_te;&lt;br /&gt;
        /* Only 1/3 of the weight is on the driving weels. */&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Language file so far ===&lt;br /&gt;
english.lng now contains this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap; max-height: 200px; overflow:scroll&amp;quot;&amp;gt;&lt;br /&gt;
##grflangid 0x01&lt;br /&gt;
&lt;br /&gt;
STR_GRF_NAME                 :NML Example NewGRF: Train&lt;br /&gt;
STR_GRF_DESC                 :{ORANGE}NML Example NewGRF: Train{}{BLACK}This NewGRF is intended to provide a coding example for the high-level NewGRF-coding language NML.{}Original graphics by {SILVER}Purno, {BLACK}coding by {SILVER}DJNekkid.{}{BLACK}This NewGRF defines a Dutch EMU, the ICM &#039;Koploper&#039;.&lt;br /&gt;
&lt;br /&gt;
STR_ICM_NAME                 :ICM &#039;Koploper&#039; (Electric)&lt;br /&gt;
STR_ICM_ADDITIONAL_TEXT      :Choose between 3- and 4-part EMU via refit{}Stated values are for the 3-part variant, the 4-part version has 33% more capacity and 50% more power and running cost.&lt;br /&gt;
STR_ICM_SUBTYPE_3_PART       : (3 parts)&lt;br /&gt;
STR_ICM_SUBTYPE_4_PART       : (4 parts)&lt;br /&gt;
STR_ICM_CANNOT_START         :... train too long (max. 4 coupled EMUs).&lt;br /&gt;
STR_ICM_CANNOT_ATTACH_OTHER  :... only other ICMs can be attached to ICM.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you like, this train is done. If you like to continue, you can learn about GRF parameters and then we&#039;ll add a parameter setting to display this train in either 1cc, 2cc or real life colours.&lt;br /&gt;
&lt;br /&gt;
{{NMLTutorialNavbar|Train three part articulated|Parameters}}&lt;/div&gt;</summary>
		<author><name>Supercheese</name></author>
	</entry>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=NMLTutorial/Train_four_part_refit&amp;diff=8581</id>
		<title>NMLTutorial/Train four part refit</title>
		<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=NMLTutorial/Train_four_part_refit&amp;diff=8581"/>
		<updated>2012-09-10T01:37:11Z</updated>

		<summary type="html">&lt;p&gt;Supercheese: /* What&amp;#039;s going to happen */ Fixing typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NMLTutorial}}&lt;br /&gt;
&#039;&#039;The example used here is from the [http://dev.openttdcoop.org/projects/nml/repository/show/examples NML source]. The code for this was originally written in NFO by DJNekkid for the 2cc Trainset and rewritten in NML by Hirundo. The graphics used in the example are by Purno. Code and graphics are both licensed according to the GPL v2 or later. The code has been modified for the purpose of this tutorial&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This continues the [[NMLTutorial/Train three part articulated|third part]] of the train example. The three part EMU will be made refittable to a four part EMU.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What&#039;s going to happen ==&lt;br /&gt;
A lot of things need to be added to make this train refittable between three and four parts.&lt;br /&gt;
&lt;br /&gt;
The method used to do this is actually the other way round than the user will think from the behaviour ingame. The train will be changed to a four part EMU. For the (default) three part refit one of these four parts will be hidden. A lot of switches will be used to make the train look right, make it have the correct capacity, power, weight, running costs and tractive effort.&lt;br /&gt;
&lt;br /&gt;
There are some drawbacks to this method. There&#039;s no way to charge the user for puchasing the extra vehicle part. Also autoreplacing will be difficult, as there&#039;s no way for the user to select which vehicle length they want. For that reason the author of this tutorial thinks making two different vehicles and having both available from the purchase menu is a better solution, but this method is a good illustration for some of the more advanced features of NML. It&#039;s up to you to decide which implementation you think is best for your vehicles.&lt;br /&gt;
&lt;br /&gt;
What we&#039;ll be doing:&lt;br /&gt;
* Add the refit option;&lt;br /&gt;
* Make the graphics work;&lt;br /&gt;
* Add callbacks to supply the correct vehicle properties;&lt;br /&gt;
* Make the purchase menu display the correct values.&lt;br /&gt;
&lt;br /&gt;
== Refit option ==&lt;br /&gt;
The refit option will be added by means of the &amp;quot;cargo subtype&amp;quot;. This allows to split each cargo into multiple entities which can be assigned different properties by means of other callbacks.&lt;br /&gt;
&lt;br /&gt;
The first step towards this is defining names for these separate entries using the &amp;lt;code&amp;gt;cargo_subtype_text&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback]. This callback requires the use of a switch, so reference a switch from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        cargo_subtype_text:           sw_icm_cargo_subtype_text;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The switch itself will use the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable]. This variable starts at 0 and will be increased by 1 until the callback returns &amp;lt;code&amp;gt;CB_RESULT_NO_MORE_ARTICULATED_PARTS&amp;lt;/code&amp;gt;. Return strings to use as cargo subtype. Each returned string will be a separate cargo subtype:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_cargo_subtype_text, cargo_subtype) {&lt;br /&gt;
    0: return string(STR_ICM_SUBTYPE_3_PART);&lt;br /&gt;
    1: return string(STR_ICM_SUBTYPE_4_PART);&lt;br /&gt;
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This adds two cargo subtypes. Also add these strings to the language file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
STR_ICM_SUBTYPE_3_PART       : (3 parts)&lt;br /&gt;
STR_ICM_SUBTYPE_4_PART       : (4 parts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Graphics ==&lt;br /&gt;
The graphics defined previously were for a three part vehicle. Now we have to make this into a four part vehicle and hide one wagon for the three part refit.&lt;br /&gt;
&lt;br /&gt;
=== Four part articulated vehicle ===&lt;br /&gt;
In order to make the vehicle four parts, the articulated vehicle callback switch needs to be changed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_articulated_part, extra_callback_info1) {&lt;br /&gt;
    /* Add three articulated parts, for a total of four */&lt;br /&gt;
    1 .. 3: return item_icm;&lt;br /&gt;
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is done by changing the value range from &amp;lt;code&amp;gt;1 .. 2&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;1 .. 3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Start/stop callback ===&lt;br /&gt;
The start/stop callback checking the vehicle length needs to be changed as well. If we still want a maximum of four EMUs, the maximum length will now be 4 * 4 instead of 4 * 3. This means changing the switch for this callback:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_start_stop, num_vehs_in_consist) {&lt;br /&gt;
    /* Vehicles may be coupled to a maximum of 4 units (12-16 cars) */&lt;br /&gt;
    1 .. 16: return CB_RESULT_NO_TEXT;&lt;br /&gt;
    return string(STR_ICM_CANNOT_START);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is done by changing the value range from &amp;lt;code&amp;gt;1 .. 12&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;1 .. 16&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Graphics ===&lt;br /&gt;
Now that the vehicle is four parts, the default graphics switch needs to be changed as well to allow for two middle parts instead of one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics, position_in_consist % 4) {&lt;br /&gt;
    0:      set_icm_front_lighted;&lt;br /&gt;
    3:      set_icm_rear_lighted;&lt;br /&gt;
    sw_icm_graphics_middle;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of modulo 3 we&#039;re now taking modulo 4. And the value for the rear vehicle part was changed from 2 to 3. For the middle parts, we also need to hide the one of the wagons for the three part EMU. Therefore we can&#039;t directly reference the spriteset but need an extra intermediate switch block.&lt;br /&gt;
&lt;br /&gt;
The extra switch block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics_middle, ((position_in_consist % 4) == 2) &amp;amp;&amp;amp; (cargo_subtype == 0)) {&lt;br /&gt;
    1: set_icm_invisible;&lt;br /&gt;
    set_icm_middle;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Even an expression this advanced can be used for switch block decision. Here we again check the position of the vehicle part, but also which cargo subtype is used for this vehicle. If it is the three part EMU (cargo subtype 0) AND it is the third vehicle part (position 2 counting from 0), we hide this vehicle part by displaying no graphics for it. In all other cases we display the regular middle part.&lt;br /&gt;
&lt;br /&gt;
=== Vehicle length ===&lt;br /&gt;
If you were to encode the result so far as a NewGRF, you end up with a three part train that has a big gap between the second and last part. This is because it&#039;s essentially still a four part vehicle, just with no graphics for the third part. This can be solved by changing the length of the two middle parts. If we make the second part (7/8) long and the third part (1/8), both together are a full wagon length, completely hiding the invisible third part.&lt;br /&gt;
&lt;br /&gt;
This is done by means of the &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback], referencing a switch block as we first need to differentiate between the two cargo subtypes and then by the position in consist. Reference the switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        length:              sw_icm_shorten_vehicle;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we get the two switch blocks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
/* --- Shorten vehicle callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_shorten_3_part_vehicle, position_in_consist % 4) {&lt;br /&gt;
    /* In the three part version, shorten the 2nd vehicle to 7/8 and the 3rd to 1/8&lt;br /&gt;
     * The rear (1/8) part is then made invisisble */&lt;br /&gt;
    1: return 7;&lt;br /&gt;
    2: return 1;&lt;br /&gt;
    return 8;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_shorten_vehicle, cargo_subtype) {&lt;br /&gt;
    0: sw_icm_shorten_3_part_vehicle;&lt;br /&gt;
    return 8; // 4-part vehicle needs no shortening&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second of these switch blocks (called first from the graphics block) differentiates between the two cargo subtypes. For subtype 0 (three part vehicle) we need to do the shortenings and reference the first switch block. For the four part vehicle we need no shortening, so directly return to &amp;quot;shorten&amp;quot; to full length.&lt;br /&gt;
&lt;br /&gt;
The first switch again makes a decision based on the &amp;lt;code&amp;gt;position_in_consist&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable] we&#039;ve seen several times now. As said, the second part will be shortened to (7/8), the third part to (1/8) and the front and back part are kept full length (8/8).&lt;br /&gt;
&lt;br /&gt;
Now the vehicle looks good in both refits.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Vehicle properties ==&lt;br /&gt;
Both refits still have identical properties. Surely the four part EMU has a higher capacity. We&#039;ll also change the running costs, power, weight and tractive effort depending on the refit chosen. This is all done by callbacks. You can find the available vehicle callbacks [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks here], with the second table especially on callbacks that change certain properties.&lt;br /&gt;
&lt;br /&gt;
=== Running cost factor ===&lt;br /&gt;
You can easily imagine that the longer vehicle will be more expensive to run. The three part has a running cost factor of 100, the four part will get a factor of 150. This requires adding the &amp;lt;code&amp;gt;running_cost_factor&amp;lt;/code&amp;gt; callback to the graphics block. From there we can link to a switch block and base the decision on the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable]. A different method as shown below is not to use a switch block but to make the decision directly from the graphics block using a conditional assignment. We&#039;ve used a conditional assignment [[Train_single_engine#Templates|before]] in one of the template blocks.&lt;br /&gt;
&lt;br /&gt;
Add to the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        running_cost_factor:          return (cargo_subtype == 1) ? 150 : 100;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; is 1 (the four part vehicle), a running cost factor of 150 is used. Otherwise, a factor of 100 is used. If you&#039;d rather used a switch block then that&#039;s up to you. Just reference one from the graphics block instead of the conditional assignment and use the switch block to make the decision based on the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
=== Cargo capacity ===&lt;br /&gt;
The cargo capacity is 36 passengers per unit. Now the three part EMU will have a capacity that is too high, because it technically is a four part EMU with one part hidden. We need to give this hidden part 0 capacity.&lt;br /&gt;
&lt;br /&gt;
This is done by the &amp;lt;code&amp;gt;cargo_capacity&amp;lt;/code&amp;gt; callback. If the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; is 0 and the &amp;lt;code&amp;gt;position_in_consist&amp;lt;/code&amp;gt; is the third part, we give it 0 capacity. Else it will get 36 capacity. Also this can be done directly from the graphics block, using a slightly more advanced conditional assignment. Of course you could again have used a switch block here, but there&#039;s no need for that in this case.&lt;br /&gt;
&lt;br /&gt;
Add to the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
cargo_capacity:               return (cargo_subtype == 0) &amp;amp;&amp;amp; ((position_in_consist % 4) == 2) ? 0 : 36;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Power ===&lt;br /&gt;
The power of the four part vehicle will be higher. Let&#039;s use a switch block this time. Of course a conditional assignment could be used here, but compare this example with the running cost factor yourself. The callback used here is called &amp;lt;code&amp;gt;power&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Reference the switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        power:                        sw_icm_power;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The switch block itself will again make a decision based on the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; variable. The callback must return the vehicle power in horsepower (imperial) and this must be an integer value. Because we know the power in kW, a little calculation is needed which NML can do for you. Returning the integer is done by the &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; function that turns a (decimal) number into an integer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_power, cargo_subtype) {&lt;br /&gt;
    0: return int(1260 / 0.7457); // kW -&amp;gt; hp&lt;br /&gt;
    return int(1890 / 0.7457); // kW -&amp;gt; hp&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Weight ===&lt;br /&gt;
Of course you could have done the calculation yourself and put the rounded values in the switch block. That we&#039;ll do for the weight of the vehicle. The callback used here is called &amp;lt;code&amp;gt;weight&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Again, reference the switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
weight:                       sw_icm_weight;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The switch block itself will again make a decision based on the &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; variable. The weight here must be specified in tons:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_weight, cargo_subtype) {&lt;br /&gt;
    0: return 144; //ton, 3 part train&lt;br /&gt;
    return 192; //ton, 4 part train&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tractive effort coefficient===&lt;br /&gt;
The last property to sort out is the tractive effort. The callback used here is called &amp;lt;code&amp;gt;tractive_effort_coefficient&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Again, reference the switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        tractive_effort_coefficient:  sw_icm_te;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the switch block we&#039;ll actually calculate the tractive effort coefficient:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_te, cargo_subtype) {&lt;br /&gt;
    /* Base TE coefficient = 0.3&lt;br /&gt;
     * 3 parts: 4/12 of weight on driving wheels&lt;br /&gt;
     * 4 parts: 6/16 of weight on driving wheels */&lt;br /&gt;
    0: return int(0.3 * 255 / 3);&lt;br /&gt;
    return int(0.3 * 255 * 3 / 8);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The technical background of the tractive effort coefficient is that it must be supplied as value between 0 and 255, with 255 equal to 100%. The tractive effort coefficient itself is calculated by multiplying the friction coefficient (see [http://en.wikipedia.org/wiki/Rail_adhesion Wikipedia] for it&#039;s meaning) with the percentage of weight that is on driven wheels. I this case we use a friction of 30%. In real life the three part vehicle has 12 axles of which 4 powered. The four part vehicle has 16 axles of which 6 powered. Assuming an equal distribution of weight along the length of the vehicle, the three part vehicle has 33.3% of it&#039;s weight on powered wheels. The four part vehicle has 37.5% of it&#039;s weight on powered wheels. Multiply both by the friction coefficient and the factor of 255 and you have the tractive effort coefficient.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;If you don&#039;t provide a tractive effort coefficient, the game will assume a friction coefficient of 0.3 and all axles powered. A tractive effort coefficient of 100% you&#039;ll only get with 100% friction and and all axles powered. This is unrealistic for railroads but can be used for maglev when there actually is no contact between vehicle and guideway.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Purchase menu ==&lt;br /&gt;
With all these callbacks we&#039;ve sort of broken the display of properties in the purchase menu. This is because the &amp;lt;code&amp;gt;position_in_consist&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable] is not available in the purchase menu and &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt; variable is always 0 in the purchase menu. The latter can be to our advantage if we want to display the properties of the shorter refit, but the other needs some fixing.&lt;br /&gt;
&lt;br /&gt;
=== Running cost factor ===&lt;br /&gt;
This callback was only based on &amp;lt;code&amp;gt;cargo_subtype&amp;lt;/code&amp;gt;, so no fixing needed here.&lt;br /&gt;
&lt;br /&gt;
=== Cargo capacity ===&lt;br /&gt;
The capacity used both variables, so some fixing is in order here. We want to display 36*3 as capacity. Because capacity is defined per unit and our vehicle is technically four units, we need to divide this over four units: 36*3/4. Add the &amp;lt;code&amp;gt;purchase_cargo_capacity&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback] to the graphics block and return this value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        purchase_cargo_capacity:      return 36 * 3 / 4;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Power, weight and tractive effort coefficient ===&lt;br /&gt;
Luckily, these are also only based on the cargo subtype variable, so no fixing needed. If you wanted a different value to be displayed in the purchase menu, you&#039;d use the &amp;lt;code&amp;gt;purchase_power&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;purchase_weight&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;purchase_tractive_effort_coefficient&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callbacks] to do this. And if you want to know, the running cost factor would logically use the &amp;lt;code&amp;gt;purchase_running_cost_factor&amp;lt;/code&amp;gt; callback.&lt;br /&gt;
&lt;br /&gt;
=== Additional text ===&lt;br /&gt;
We want to inform the user that this train has an option to refit it into a four part version and that the properties shown are for the three part version. For this we&#039;ll use the &amp;lt;code&amp;gt;additional_text&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback] which we also used in the tram example. It can directly return a string from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
        additional_text:              return string(STR_ICM_ADDITIONAL_TEXT);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also don&#039;t forget to add this string to the language file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
STR_ICM_ADDITIONAL_TEXT      :Choose between 3- and 4-part EMU via refit{}Stated values are for the 3-part variant, the 4-part version has 33% more capacity and 50% more power and running cost.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This means our vehicle now works like it should with the two refits. Encode it into a NewGRF if you like.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Total code so far ==&lt;br /&gt;
When put in the correct order, this should now encode as a working NewGRF. The total code so far:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap; max-height: 200px; overflow:scroll&amp;quot;&amp;gt;&lt;br /&gt;
/* Define grf */&lt;br /&gt;
grf {&lt;br /&gt;
    grfid: &amp;quot;NML\00&amp;quot;;&lt;br /&gt;
    /* GRF name and description strings are defined in the lang files */&lt;br /&gt;
    name: string(STR_GRF_NAME);&lt;br /&gt;
    desc: string(STR_GRF_DESC);&lt;br /&gt;
    /* This is the first version, start numbering at 0. */&lt;br /&gt;
    version: 0;&lt;br /&gt;
    min_compatible_version: 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Define a rail type table,&lt;br /&gt;
 * this allows referring to railtypes&lt;br /&gt;
 * irrespective of the grfs loaded.&lt;br /&gt;
 */&lt;br /&gt;
railtypetable {&lt;br /&gt;
    ELRL&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Basic template for 4 vehicle views */&lt;br /&gt;
template tmpl_vehicle_basic(x, y) {&lt;br /&gt;
    // arguments x, y: coordinates of top-left corner of first sprite&lt;br /&gt;
    [x,      y,  8, 24,  -3, -12] //xpos ypos xsize ysize xrel yrel&lt;br /&gt;
    [x +  9, y, 22, 20, -14, -12]&lt;br /&gt;
    [x + 32, y, 32, 16, -16, -12]&lt;br /&gt;
    [x + 65, y, 22, 20,  -6, -12]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Template for a vehicle with only 4 views (symmetric) */&lt;br /&gt;
template tmpl_vehicle_4_views(num) {&lt;br /&gt;
    // argument num: Index in the graphics file, assuming vertical ordering of vehicles&lt;br /&gt;
    tmpl_vehicle_basic(1, 1 + 32 * num)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Template for a vehicle with 8 views (non-symmetric) */&lt;br /&gt;
template tmpl_vehicle_8_views(num, reversed) {&lt;br /&gt;
    // argument num: Index in the graphics file, assuming vertical ordering of vehicles&lt;br /&gt;
    // argument reversed: Reverse visible orientation of vehicle, if set to 1&lt;br /&gt;
    tmpl_vehicle_basic(reversed ? 89 : 1, 1 + 32 * num)&lt;br /&gt;
    tmpl_vehicle_basic(reversed ? 1 : 89, 1 + 32 * num)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Template for a single vehicle sprite */&lt;br /&gt;
template tmpl_vehicle_single(num, xsize, ysize, xoff, yoff) {&lt;br /&gt;
    [1, 1 + 32 * num, xsize, ysize, xoff, yoff]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Define the spritesets, these allow referring to these sprites later on */&lt;br /&gt;
spriteset (set_icm_front_lighted, &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_8_views(0, 0) }&lt;br /&gt;
spriteset (set_icm_rear_lighted,  &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_8_views(1, 1) }&lt;br /&gt;
spriteset (set_icm_front,         &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_8_views(2, 0) }&lt;br /&gt;
spriteset (set_icm_rear,          &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_8_views(3, 1) }&lt;br /&gt;
spriteset (set_icm_middle,        &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_4_views(4)    }&lt;br /&gt;
spriteset (set_icm_purchase,      &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_single(5, 53, 14, -25, -10) }&lt;br /&gt;
spriteset (set_icm_invisible,     &amp;quot;gfx/icm.png&amp;quot;) { tmpl_vehicle_single(6,  1,  1,   0,   0) }&lt;br /&gt;
&lt;br /&gt;
/* --- Graphics callback  --- */&lt;br /&gt;
&lt;br /&gt;
/* In the 3-part version, the 3rd car is invisible */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics_middle, ((position_in_consist % 4) == 2) &amp;amp;&amp;amp; (cargo_subtype == 0)) {&lt;br /&gt;
    1: set_icm_invisible;&lt;br /&gt;
    set_icm_middle;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Choose between front, middle and back parts */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics, position_in_consist % 4) {&lt;br /&gt;
    0:      set_icm_front_lighted;&lt;br /&gt;
    3:      set_icm_rear_lighted;&lt;br /&gt;
    set_icm_middle;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Cargo subtype text --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_cargo_subtype_text, cargo_subtype) {&lt;br /&gt;
    0: return string(STR_ICM_SUBTYPE_3_PART);&lt;br /&gt;
    1: return string(STR_ICM_SUBTYPE_4_PART);&lt;br /&gt;
    return CB_RESULT_NO_TEXT;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Articulated part callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_articulated_part, extra_callback_info1) {&lt;br /&gt;
    /* Add three articulated parts, for a total of four */&lt;br /&gt;
    1 .. 3: return item_icm;&lt;br /&gt;
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Start/stop callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_start_stop, num_vehs_in_consist) {&lt;br /&gt;
    /* Vehicles may be coupled to a maximum of 4 units (12-16 cars) */&lt;br /&gt;
    1 .. 16: return CB_RESULT_NO_TEXT;&lt;br /&gt;
    return string(STR_ICM_CANNOT_START);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Wagon attach callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_can_attach_wagon, vehicle_type_id) {&lt;br /&gt;
    /* SELF refers to the wagon here, check that it&#039;s an ICM */&lt;br /&gt;
    item_icm: return CB_RESULT_ATTACH_ALLOW;&lt;br /&gt;
    return string(STR_ICM_CANNOT_ATTACH_OTHER);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* --- Shorten vehicle callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_shorten_3_part_vehicle, position_in_consist % 4) {&lt;br /&gt;
    /* In the three part version, shorten the 2nd vehicle to 7/8 and the 3rd to 1/8&lt;br /&gt;
     * The rear (1/8) part is then made invisisble */&lt;br /&gt;
    1: return 7;&lt;br /&gt;
    2: return 1;&lt;br /&gt;
    return 8;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_shorten_vehicle, cargo_subtype) {&lt;br /&gt;
    0: sw_icm_shorten_3_part_vehicle;&lt;br /&gt;
    return 8; // 4-part vehicle needs no shortening&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Power, weight and TE are all applied to the front vehicle only */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_power, cargo_subtype) {&lt;br /&gt;
    0: return int(1260 / 0.7457); // kW -&amp;gt; hp&lt;br /&gt;
    return int(1890 / 0.7457); // kW -&amp;gt; hp&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_weight, cargo_subtype) {&lt;br /&gt;
    0: return 144; //ton, 3 part train&lt;br /&gt;
    return 192; //ton, 4 part train&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_te, cargo_subtype) {&lt;br /&gt;
    /* Base TE coefficient = 0.3&lt;br /&gt;
     * 3 parts: 4/12 of weight on driving wheels&lt;br /&gt;
     * 4 parts: 6/16 of weight on driving wheels */&lt;br /&gt;
    0: return int(0.3 * 255 / 3);&lt;br /&gt;
    return int(0.3 * 255 * 3 / 8);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Define the actual train */&lt;br /&gt;
item(FEAT_TRAINS, item_icm) {&lt;br /&gt;
    /* Define properties first, make sure to set all of them */&lt;br /&gt;
    property {&lt;br /&gt;
        name:                         string(STR_ICM_NAME);&lt;br /&gt;
        // not available in toyland:&lt;br /&gt;
        climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); &lt;br /&gt;
        introduction_date:            date(1983, 1, 1);&lt;br /&gt;
        model_life:                   VEHICLE_NEVER_EXPIRES;&lt;br /&gt;
        vehicle_life:                 30;&lt;br /&gt;
        reliability_decay:            20;&lt;br /&gt;
        refittable_cargo_classes:     bitmask(CC_PASSENGERS);&lt;br /&gt;
        non_refittable_cargo_classes: bitmask();&lt;br /&gt;
        // refitting is done via cargo classes only, no cargo types need explicit enabling/disabling&lt;br /&gt;
        // It&#039;s an intercity train, loading is relatively slow:&lt;br /&gt;
        loading_speed:                6; &lt;br /&gt;
        cost_factor:                  45;&lt;br /&gt;
        running_cost_factor:          100; // Changed by callback&lt;br /&gt;
        sprite_id:                    SPRITE_ID_NEW_TRAIN;&lt;br /&gt;
        speed:                        141 km/h; // actually 140, but there are rounding errors&lt;br /&gt;
        misc_flags:                   bitmask(TRAIN_FLAG_2CC, TRAIN_FLAG_MU);&lt;br /&gt;
        refit_cost:                   0; //refit costs don&#039;t apply to subcargo display &lt;br /&gt;
        // callback flags are not set manually&lt;br /&gt;
        track_type:                   ELRL; // from rail type table&lt;br /&gt;
        ai_special_flag:              AI_FLAG_PASSENGER;&lt;br /&gt;
        power:                        1260 kW; // Changed by CB&lt;br /&gt;
        running_cost_base:            RUNNING_COST_ELECTRIC;&lt;br /&gt;
        dual_headed:                  0;&lt;br /&gt;
        cargo_capacity:               36; // per part, changed by callback&lt;br /&gt;
        weight:                       144 ton; // Total, changed by callback&lt;br /&gt;
        ai_engine_rank:               0; // not intended to be used by the ai&lt;br /&gt;
        engine_class:                 ENGINE_CLASS_ELECTRIC;&lt;br /&gt;
        extra_power_per_wagon:        0 kW;&lt;br /&gt;
        // 4/12 of weight on driving wheels, with a default friction coefficient of 0.3:&lt;br /&gt;
        tractive_effort_coefficient:  0.3 / 3; // changed by callback&lt;br /&gt;
        air_drag_coefficient:         0.06;&lt;br /&gt;
        shorten_vehicle:              SHORTEN_TO_8_8;&lt;br /&gt;
        // Overridden by callback to disable for non-powered wagons:&lt;br /&gt;
        visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_ELECTRIC, 2, DISABLE_WAGON_POWER);&lt;br /&gt;
        extra_weight_per_wagon:       0 ton;&lt;br /&gt;
        bitmask_vehicle_info:         0;&lt;br /&gt;
    }&lt;br /&gt;
    /* Define graphics and callbacks&lt;br /&gt;
     * Setting all callbacks is not needed, only define what is used */&lt;br /&gt;
    graphics {&lt;br /&gt;
        default:                      sw_icm_graphics;&lt;br /&gt;
        purchase:                     set_icm_purchase;&lt;br /&gt;
        cargo_subtype_text:           sw_icm_cargo_subtype_text;&lt;br /&gt;
        additional_text:              return string(STR_ICM_ADDITIONAL_TEXT);&lt;br /&gt;
        start_stop:                   sw_icm_start_stop;&lt;br /&gt;
        articulated_part:             sw_icm_articulated_part;&lt;br /&gt;
        can_attach_wagon:             sw_icm_can_attach_wagon;&lt;br /&gt;
        running_cost_factor:          return (cargo_subtype == 1) ? 150 : 100;&lt;br /&gt;
        /* Capacity is per part */&lt;br /&gt;
        cargo_capacity:               return (cargo_subtype == 0) &amp;amp;&amp;amp; ((position_in_consist % 4) == 2) ? 0 : 36;&lt;br /&gt;
        /* In the purchase menu, we want to show the capacity for the three-part version,&lt;br /&gt;
         * i.e. divide the capacity of three cars across four */&lt;br /&gt;
        purchase_cargo_capacity:      return 36 * 3 / 4;&lt;br /&gt;
        length:                       sw_icm_shorten_vehicle;&lt;br /&gt;
        /* Only the front vehicle has power */&lt;br /&gt;
        power:                        sw_icm_power;&lt;br /&gt;
        /* Only the front vehicle has weight */&lt;br /&gt;
        weight:                       sw_icm_weight;&lt;br /&gt;
        /* Only the front vehicle has TE */&lt;br /&gt;
        tractive_effort_coefficient:  sw_icm_te;&lt;br /&gt;
        /* Only 1/3 of the weight is on the driving weels. */&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Language file so far ===&lt;br /&gt;
english.lng now contains this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap; max-height: 200px; overflow:scroll&amp;quot;&amp;gt;&lt;br /&gt;
##grflangid 0x01&lt;br /&gt;
&lt;br /&gt;
STR_GRF_NAME                 :NML Example NewGRF: Train&lt;br /&gt;
STR_GRF_DESC                 :{ORANGE}NML Example NewGRF: Train{}{BLACK}This NewGRF is intended to provide a coding example for the high-level NewGRF-coding language NML.{}Original graphics by {SILVER}Purno, {BLACK}coding by {SILVER}DJNekkid.{}{BLACK}This NewGRF defines a Dutch EMU, the ICM &#039;Koploper&#039;.&lt;br /&gt;
&lt;br /&gt;
STR_ICM_NAME                 :ICM &#039;Koploper&#039; (Electric)&lt;br /&gt;
STR_ICM_ADDITIONAL_TEXT      :Choose between 3- and 4-part EMU via refit{}Stated values are for the 3-part variant, the 4-part version has 33% more capacity and 50% more power and running cost.&lt;br /&gt;
STR_ICM_SUBTYPE_3_PART       : (3 parts)&lt;br /&gt;
STR_ICM_SUBTYPE_4_PART       : (4 parts)&lt;br /&gt;
STR_ICM_CANNOT_START         :... train too long (max. 4 coupled EMUs).&lt;br /&gt;
STR_ICM_CANNOT_ATTACH_OTHER  :... only other ICMs can be attached to ICM.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you like, this train is done. If you like to continue, you can learn about GRF parameters and then we&#039;ll add a parameter setting to display this train in either 1cc, 2cc or real life colours.&lt;br /&gt;
&lt;br /&gt;
{{NMLTutorialNavbar|Train three part articulated|Parameters}}&lt;/div&gt;</summary>
		<author><name>Supercheese</name></author>
	</entry>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=NMLTutorial/Road_vehicle_32_bit_sprites&amp;diff=8446</id>
		<title>NMLTutorial/Road vehicle 32 bit sprites</title>
		<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=NMLTutorial/Road_vehicle_32_bit_sprites&amp;diff=8446"/>
		<updated>2012-06-26T18:19:57Z</updated>

		<summary type="html">&lt;p&gt;Supercheese: /* Spritesets */ Add missing slash in &amp;lt;/code&amp;gt; tag&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NMLTutorial}}&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve seen that you can add 32 bit sprites, let&#039;s do that with an example. In fact we&#039;re going to pick up halfway down the road vehicle example from the beginning of this tutorial. We&#039;ll continue with what we had at the end of [[NMLTutorial/Road vehicle graphics|this page]].&lt;br /&gt;
&lt;br /&gt;
== Example graphics ==&lt;br /&gt;
We&#039;ll be adding 32 bit graphics for the normal zoom level, including a recolour mask. From there we&#039;ll give you some pointers on how to add sprites for other zoom levels and you can easily fill in the rest yourself. So let&#039;s look at the graphics, shall we?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First, let&#039;s have a look again at the 8 bit sprites we already have for our road vehicle.&lt;br /&gt;
[[Image:Flatbed truck 1 goods.png|frame|none|Empty flatbed truck sprites and flatbed trucks sprites loaded with a container]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The 32 bit sprites are similar to the 8 bit sprites. The main difference is that to indicate transparancy you must use the real transparency of PNG files. If you use the blue background for transparency in 32 bit sprites, you&#039;ll get just that: a blue background. You may also use the alpha channel for semi-transparent pixels.&lt;br /&gt;
[[Image:Flatbed truck 1 goods 32.png|frame|none|Empty flatbed truck sprites and flatbed trucks sprites loaded with a container in 32 bit.]]&lt;br /&gt;
Note that the sprite background is actually transparent. We&#039;ve made the borders around the sprites blue, so that we can actually see where the indivual sprites are. This is not mandatory; as it doesn&#039;t end up in the game, you could have made it any other colour, even transparent if you like. We&#039;ll put this file in the &#039;&#039;gfx&#039;&#039; folder with the regular 8 bit sprites and name it &#039;&#039;flatbed_truck_1_goods_32.png‎&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now even if you use the exact colours from the palette, this won&#039;t enable company colours in 32 bit sprites. For this you have to provide an additional 8 bit mask sprite, which does use the exact palette colours. Ingame, this mask is overlayed on top of the regular 32 bit sprites, which will give you a company-coloured vehicle. Note that the mask sprites need to be in exactly the same position as the regular 32 bit sprites, as they will use the same offsets!&lt;br /&gt;
[[Image:Flatbed_truck_1_goods_mask.png|frame|none|The mask file to go with the previous 32 bit graphics]]&lt;br /&gt;
As we&#039;re now drawing in 8 bit again, we also have to use the magic blue to incidate transparent backgrounds! Also this file goes in the &#039;&#039;gfx&#039;&#039; directory and we&#039;ll name it &#039;&#039;flatbed_truck_1_goods_mask.png&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Spritesets ==&lt;br /&gt;
For the regular 8 bit sprites we have two spritesets in our NML code. Let&#039;s have a look at those again:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
//graphics definition&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_empty, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    //left_x, upper_y, width, height, offset_x, offset_y&lt;br /&gt;
    [ 0,      0,        8,    18,      -3,       -10]&lt;br /&gt;
    [ 16,     0,       20,    16,     -14,        -7]&lt;br /&gt;
    [ 48,     0,       28,    12,     -14,        -6]&lt;br /&gt;
    [ 96,     0,       20,    16,      -6,        -7]&lt;br /&gt;
    [ 128,    0,        8,    18,      -3,       -10]&lt;br /&gt;
    [ 144,    0,       20,    16,     -14,        -7]&lt;br /&gt;
    [ 176,    0,       28,    12,     -14,        -6]&lt;br /&gt;
    [ 224,    0,       20,    16,      -6,        -7]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_full, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    //left_x, upper_y, width, height, offset_x, offset_y&lt;br /&gt;
    [ 260,    0,        8,    18,      -3,      -10]&lt;br /&gt;
    [ 276,    0,       20,    16,     -14,       -7]&lt;br /&gt;
    [ 308,    0,       28,    12,     -14,       -6]&lt;br /&gt;
    [ 356,    0,       20,    16,      -6,       -7]&lt;br /&gt;
    [ 388,    0,        8,    18,      -3,      -10]&lt;br /&gt;
    [ 404,    0,       20,    16,     -14,       -7]&lt;br /&gt;
    [ 436,    0,       28,    12,     -14,       -6]&lt;br /&gt;
    [ 484,    0,       20,    16,      -6,       -7]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To define our 32 bit sprites, we have to define an &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; block to go with each of the spriteset blocks. The identifiers will be the same, we&#039;ll indicate that we have normal zoom sprites via &amp;lt;code&amp;gt;ZOOM_LEVEL_NORMAL&amp;lt;/code&amp;gt; and that the sprites are 32 bit via &amp;lt;code&amp;gt;BIT_DEPTH_32BPP&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We&#039;ll also reference the new graphics files. As the 32 bit sprites and the mask sprites belong together, they go together in in the same &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; block. Let&#039;s look at the first line of that block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_empty, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The positions, sizes and offsets of 32 bit sprites are incidentally the same as for the 8 bit sprites. Coincidence? Of course not, this will just save us a lot of trouble, as now we can simply copy these from the 8 bit sprites. This will give us the following &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; block for the first set of sprites:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_empty, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    //left_x, upper_y, width, height, offset_x, offset_y&lt;br /&gt;
    [ 0,      0,        8,    18,      -3,       -10]&lt;br /&gt;
    [ 16,     0,       20,    16,     -14,        -7]&lt;br /&gt;
    [ 48,     0,       28,    12,     -14,        -6]&lt;br /&gt;
    [ 96,     0,       20,    16,      -6,        -7]&lt;br /&gt;
    [ 128,    0,        8,    18,      -3,       -10]&lt;br /&gt;
    [ 144,    0,       20,    16,     -14,        -7]&lt;br /&gt;
    [ 176,    0,       28,    12,     -14,        -6]&lt;br /&gt;
    [ 224,    0,       20,    16,      -6,        -7]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is good practice to place the &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; block right after the &amp;lt;code&amp;gt;spriteset&amp;lt;/code&amp;gt; block it belongs to. Let&#039;s do that and at the same time fill in the other &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
//graphics definition&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_empty, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    //left_x, upper_y, width, height, offset_x, offset_y&lt;br /&gt;
    [ 0,      0,        8,    18,      -3,       -10]&lt;br /&gt;
    [ 16,     0,       20,    16,     -14,        -7]&lt;br /&gt;
    [ 48,     0,       28,    12,     -14,        -6]&lt;br /&gt;
    [ 96,     0,       20,    16,      -6,        -7]&lt;br /&gt;
    [ 128,    0,        8,    18,      -3,       -10]&lt;br /&gt;
    [ 144,    0,       20,    16,     -14,        -7]&lt;br /&gt;
    [ 176,    0,       28,    12,     -14,        -6]&lt;br /&gt;
    [ 224,    0,       20,    16,      -6,        -7]&lt;br /&gt;
}&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_empty, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    //left_x, upper_y, width, height, offset_x, offset_y&lt;br /&gt;
    [ 0,      0,        8,    18,      -3,       -10]&lt;br /&gt;
    [ 16,     0,       20,    16,     -14,        -7]&lt;br /&gt;
    [ 48,     0,       28,    12,     -14,        -6]&lt;br /&gt;
    [ 96,     0,       20,    16,      -6,        -7]&lt;br /&gt;
    [ 128,    0,        8,    18,      -3,       -10]&lt;br /&gt;
    [ 144,    0,       20,    16,     -14,        -7]&lt;br /&gt;
    [ 176,    0,       28,    12,     -14,        -6]&lt;br /&gt;
    [ 224,    0,       20,    16,      -6,        -7]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_full, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    //left_x, upper_y, width, height, offset_x, offset_y&lt;br /&gt;
    [ 260,    0,        8,    18,      -3,      -10]&lt;br /&gt;
    [ 276,    0,       20,    16,     -14,       -7]&lt;br /&gt;
    [ 308,    0,       28,    12,     -14,       -6]&lt;br /&gt;
    [ 356,    0,       20,    16,      -6,       -7]&lt;br /&gt;
    [ 388,    0,        8,    18,      -3,      -10]&lt;br /&gt;
    [ 404,    0,       20,    16,     -14,       -7]&lt;br /&gt;
    [ 436,    0,       28,    12,     -14,       -6]&lt;br /&gt;
    [ 484,    0,       20,    16,      -6,       -7]&lt;br /&gt;
}&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_full, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    //left_x, upper_y, width, height, offset_x, offset_y&lt;br /&gt;
    [ 260,    0,        8,    18,      -3,      -10]&lt;br /&gt;
    [ 276,    0,       20,    16,     -14,       -7]&lt;br /&gt;
    [ 308,    0,       28,    12,     -14,       -6]&lt;br /&gt;
    [ 356,    0,       20,    16,      -6,       -7]&lt;br /&gt;
    [ 388,    0,        8,    18,      -3,      -10]&lt;br /&gt;
    [ 404,    0,       20,    16,     -14,       -7]&lt;br /&gt;
    [ 436,    0,       28,    12,     -14,       -6]&lt;br /&gt;
    [ 484,    0,       20,    16,      -6,       -7]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And that&#039;s really all there is to defining 32 bit sprites!&lt;br /&gt;
&lt;br /&gt;
== Templates ==&lt;br /&gt;
Can we also template 32 bit graphics, I hear you ask? Well certainly, they&#039;re no different than 8 bit sprites in that respect. Let&#039;s go back to where we&#039;ve [[NMLTutorial/Road_vehicle_graphics_template|templated our example road vehicle]]. Because we were smart enough to keep the same positions, sizes and offsets for both our 8 bit and 32 bit sprites, we can simply use the same template we made earlier. This template was called &amp;lt;code&amp;gt;tmpl_truck&amp;lt;/code&amp;gt; and has template parameters for the top left position of the first of eight sprites.&lt;br /&gt;
&lt;br /&gt;
When first using this template, we simply replaced all the numbers inside the spriteset blocks with a call to the template, and ended up with this:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
//graphics definition&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_empty, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(0, 0)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_full, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(260, 0)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For our &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; blocks we can do the same, there&#039;s really nothing to it:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
//graphics definition&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_empty, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(0, 0)&lt;br /&gt;
}&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_empty, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(0, 0)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_full, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(260, 0)&lt;br /&gt;
}&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_full, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(260, 0)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the first line of the blocks remains the same, we just replace the content with the template call.&lt;br /&gt;
&lt;br /&gt;
== Other zoom levels ==&lt;br /&gt;
For each additional zoom level, you simply add additional &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; blocks. Because of the different sprite sizes and offsets, you do have to create an additional template for each additional zoom level. If you order the sprites in a standardized way in your png files, you can keep reusing templates as we&#039;ve done before.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume we have 32 bit graphics for the 4x zoom in level. The &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; for these sprites will be similar, but you specify the different zoom level (in this case) via &amp;lt;code&amp;gt;ZOOM_LEVEL_IN_4X&amp;lt;/code&amp;gt; and reference the template you have made for sprites of this zoom level. For the first set of sprites you then get this additional &amp;lt;code&amp;gt;alternative_sprites&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_empty, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck_zi4(0, 0)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the total set of blocks:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:darkblue; white-space: pre-wrap&amp;quot;&amp;gt;&lt;br /&gt;
//graphics definition&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_empty, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(0, 0)&lt;br /&gt;
}&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_empty, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(0, 0)&lt;br /&gt;
}&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_empty, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck_zi4(0, 0)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
spriteset(spriteset_flatbed_truck_1_goods_full, &amp;quot;gfx/flatbed_truck_1_goods.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(260, 0)&lt;br /&gt;
}&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_full, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck(260, 0)&lt;br /&gt;
}&lt;br /&gt;
alternative_sprites(spriteset_flatbed_truck_1_goods_full, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP, &amp;quot;flatbed_truck_1_goods_32.png&amp;quot;, &amp;quot;flatbed_truck_1_goods_mask.png&amp;quot;) {&lt;br /&gt;
    tmpl_truck_zi4(260, 0)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And with that we end this example of adding 32 bit sprites to your road vehicle NewGRF. Of course, the same method as used here also applies to providing 32 bit alternatives for any other &amp;lt;code&amp;gt;spriteset&amp;lt;/code&amp;gt; you may have. Only thing left for you to skip is a useless conclusion :) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{NMLTutorialNavbar|32 bit sprites|Conclusion}}&lt;/div&gt;</summary>
		<author><name>Supercheese</name></author>
	</entry>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=User:FooBar/Generic_NewGRF_Readme&amp;diff=8001</id>
		<title>User:FooBar/Generic NewGRF Readme</title>
		<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=User:FooBar/Generic_NewGRF_Readme&amp;diff=8001"/>
		<updated>2012-01-22T22:17:14Z</updated>

		<summary type="html">&lt;p&gt;Supercheese: Fixing numbering issues; hope you don&amp;#039;t mind!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an attempt at a generic layout for NewGRF readmes. It provides you with a layout to use, has several sections pre-filled and suggestions on what to put in the other. It is aimed to serve as:&lt;br /&gt;
* a template that you can modify for your own NewGRF;&lt;br /&gt;
* an optimized order of sections for used with the OpenTTD readme viewer (i.e. gameplay related stuff first);&lt;br /&gt;
* a checklist to see if you have all important bits covered in your readme;&lt;br /&gt;
* inspiration in case you want to write your own readme.&lt;br /&gt;
&lt;br /&gt;
Feel free to use this as basis for the readme of your NewGRF. The only thing I ask is that your NewGRF is released under the GNU General Public Licence 2.0 or 3.0 or higher (your choice which one/combination exactly). This example itself is licensed GNU GPL v2+.&lt;br /&gt;
&lt;br /&gt;
What you have to do yourself is of course fill in the missing pieces. Don&#039;t forget to set the correct game version requirements and update the urls in the contact information section. Many predefined bits are aimed at hosting your NewGRF at the [http://dev.openttdcoop.org/ #openttdcoop DevZone], but you can just modify that if you&#039;re not hosting your grf there.&lt;br /&gt;
&lt;br /&gt;
==Readme.txt==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{{GRF_TITLE}}&lt;br /&gt;
===================================&lt;br /&gt;
&amp;lt;one-line description of what the grf does&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----------&lt;br /&gt;
0 Contents&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
1   About&lt;br /&gt;
2   General information&lt;br /&gt;
    2.1  Requirements&lt;br /&gt;
    2.2  Installation&lt;br /&gt;
    2.3  Parameter settings&lt;br /&gt;
    2.4  Usage&lt;br /&gt;
3   Known issues&lt;br /&gt;
4   Background information&lt;br /&gt;
5   Frequently Asked Questions&lt;br /&gt;
6   Credits&lt;br /&gt;
7   Contact information&lt;br /&gt;
    7.1  Bug reports&lt;br /&gt;
    7.2  Other problems&lt;br /&gt;
    7.3  General enquiries&lt;br /&gt;
8   License&lt;br /&gt;
9   Obtaining the source&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-------&lt;br /&gt;
1 About&lt;br /&gt;
-------&lt;br /&gt;
&lt;br /&gt;
&amp;lt;one or two paragraphs what this grf is about, what it contains and what it does&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{GRF_TITLE}}&lt;br /&gt;
MD5Hash:  {{GRF_MD5}}&lt;br /&gt;
Version:  {{REPO_REVISION}}&lt;br /&gt;
GRF ID:   {{GRF_ID}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---------------------&lt;br /&gt;
2 General information&lt;br /&gt;
---------------------&lt;br /&gt;
&lt;br /&gt;
2.1 Requirements&lt;br /&gt;
----------------&lt;br /&gt;
- OpenTTD &amp;lt;1.2.0&amp;gt; or nightly r&amp;lt;22723&amp;gt;&lt;br /&gt;
- TTDPatch nightly r&amp;lt;2200&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2.2 Installation&lt;br /&gt;
----------------&lt;br /&gt;
OpenTTD:&lt;br /&gt;
  see http://wiki.openttd.org/NewGRF&lt;br /&gt;
  This NewGRF is available from the ingame Online Content&lt;br /&gt;
&lt;br /&gt;
TTDPatch:&lt;br /&gt;
  see http://www.tt-wiki.net/wiki/NewGraphicsInstallation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2.3 Parameter settings&lt;br /&gt;
----------------------&lt;br /&gt;
&amp;lt;some notes on what settings are available&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the parameters before starting a new game. Once started they &lt;br /&gt;
cannot be changed any longer.&lt;br /&gt;
&lt;br /&gt;
Useful details if you need to set the parameters manually in the&lt;br /&gt;
configuration file:&lt;br /&gt;
&lt;br /&gt;
  1st parameter: &amp;lt;description&amp;gt;&lt;br /&gt;
  0: &amp;lt;what this value does&amp;gt;&lt;br /&gt;
  1: &amp;lt;what this value does&amp;gt;&lt;br /&gt;
  2: &amp;lt;what this value does&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  2nd parameter: &amp;lt;description&amp;gt;&lt;br /&gt;
  0: &amp;lt;what this value does&amp;gt;&lt;br /&gt;
  1: &amp;lt;what this value does&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2.4 Usage&lt;br /&gt;
---------&lt;br /&gt;
&amp;lt;some notes on how to use this NewGRF&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--------------&lt;br /&gt;
3 Known issues&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
&amp;lt;list of known issues in this release&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
4 Background information&lt;br /&gt;
------------------------&lt;br /&gt;
&lt;br /&gt;
&amp;lt;in this section you can give some background information on the&lt;br /&gt;
contents of this NewGRF&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----------------------------&lt;br /&gt;
5 Frequently Asked Questions&lt;br /&gt;
----------------------------&lt;br /&gt;
&lt;br /&gt;
Q: Why is it that...?&lt;br /&gt;
A: No reason.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---------&lt;br /&gt;
6 Credits&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
Graphics:&lt;br /&gt;
- &amp;lt;artist 1&amp;gt;&lt;br /&gt;
- &amp;lt;artist 2&amp;gt;&lt;br /&gt;
- &amp;lt;artist 3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
- &amp;lt;coder 1&amp;gt;&lt;br /&gt;
- &amp;lt;coder 2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Translations:&lt;br /&gt;
- &amp;lt;translator 1&amp;gt;&lt;br /&gt;
- &amp;lt;translator 2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Makefile system:&lt;br /&gt;
- &amp;lt;usually planetmaker&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---------------------&lt;br /&gt;
7 Contact information&lt;br /&gt;
---------------------&lt;br /&gt;
&lt;br /&gt;
7.1 Bug reports&lt;br /&gt;
---------------&lt;br /&gt;
Please report any bugs you find at&lt;br /&gt;
  bug tracker: http://dev.openttdcoop.org/projects/&amp;lt;projectname&amp;gt;/issues&lt;br /&gt;
  or forum topic: http://www.tt-forums.net/viewtopic.php?t=&amp;lt;00000&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always included a detailed description of the bug, preferrably with&lt;br /&gt;
screenshot and savegame. Also state the exact game version you&#039;re using, &lt;br /&gt;
as well as the version of this NewGRF.&lt;br /&gt;
&lt;br /&gt;
If you have a savegame that includes NewGRFs not available on OpenTTD&#039;s &lt;br /&gt;
Online Content, then please try to reproduce the bug in a new game &lt;br /&gt;
which has all NewGRFs easily accessible.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using a patched version of the game, please try to reproduce&lt;br /&gt;
the bug on an official game build. If you can&#039;t reproduce the bug, then&lt;br /&gt;
don&#039;t report it here but in the forum topic of the patch(pack) instead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7.2 Other problems&lt;br /&gt;
------------------&lt;br /&gt;
If you have any problems using this NewGRF that are not covered in the &lt;br /&gt;
Frequently Asked Questions above, then you can ask your questions in the&lt;br /&gt;
forum topic: http://www.tt-forums.net/viewtopic.php?t=&amp;lt;00000&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7.3 General enquiries&lt;br /&gt;
---------------------&lt;br /&gt;
&lt;br /&gt;
If you have any queries that cannot be asked in the forum topic, then&lt;br /&gt;
contact &amp;lt;username&amp;gt; via Private Message at www.tt-forums.net or send&lt;br /&gt;
an email to &amp;lt;name&amp;gt; at &amp;lt;email address&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---------&lt;br /&gt;
8 License&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
&amp;lt;name of the NewGRF&amp;gt; - &amp;lt;short description&amp;gt;&lt;br /&gt;
Copyright (C) &amp;lt;year&amp;gt; &amp;lt;list of authors or team name&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This program is free software; you can redistribute it and/or modify&lt;br /&gt;
it under the terms of the GNU General Public License as published by&lt;br /&gt;
the Free Software Foundation; either version 2 of the License, or&lt;br /&gt;
(at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
This program is distributed in the hope that it will be useful,&lt;br /&gt;
but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
You should have received a copy of the GNU General Public License along&lt;br /&gt;
with this program; if not, write to the Free Software Foundation, Inc.,&lt;br /&gt;
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----------------------&lt;br /&gt;
9 Obtaining the source&lt;br /&gt;
----------------------&lt;br /&gt;
&lt;br /&gt;
The source code can be obtained from the #openttdcoop DevZone&lt;br /&gt;
via source browser:&lt;br /&gt;
    http://dev.openttdcoop.org/projects/&amp;lt;projectname&amp;gt;/repository&lt;br /&gt;
or via mercurial checkout:&lt;br /&gt;
    hg clone http://hg.openttdcoop.org/&amp;lt;projectname&amp;gt;&lt;br /&gt;
or via a source bundle download (releases only):&lt;br /&gt;
    http://bundles.openttdcoop.org/&amp;lt;projectname&amp;gt;/&lt;br /&gt;
&lt;br /&gt;
How to build from source and the requirements for that are included &lt;br /&gt;
with the source in the file /docs/building_from_source.txt.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Supercheese</name></author>
	</entry>
</feed>