<?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=Frosch</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=Frosch"/>
	<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/wiki/Special:Contributions/Frosch"/>
	<updated>2026-05-02T04:10:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=NMLTutorial/Train_recolour&amp;diff=8960</id>
		<title>NMLTutorial/Train recolour</title>
		<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=NMLTutorial/Train_recolour&amp;diff=8960"/>
		<updated>2013-12-08T13:40:56Z</updated>

		<summary type="html">&lt;p&gt;Frosch: fix nml 0.2-&amp;gt;0.3&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 and concludes the [[NMLTutorial/Train four part refit|fourth part]] of the train example. A parameter setting will be added (with a GUI for OpenTTD) to allow choosing between 1cc, 2cc or real life colours for our train. And we&#039;ll do some further visual improvements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== GRF Parameter setting ==&lt;br /&gt;
The GRF parameter setting will allow choosing between 1cc, 2cc or real life colours. This is done by adding a param block to the grf block. In this param block one (named) parameter will be defined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example&amp;quot;&amp;gt;&lt;br /&gt;
    param {&lt;br /&gt;
        /* There is one parameter, which can be used to alter the colour scheme */&lt;br /&gt;
        param_colour_scheme {&lt;br /&gt;
            type: int;&lt;br /&gt;
            name: string(STR_PARAM_COLOUR_SCHEME_NAME);&lt;br /&gt;
            desc: string(STR_PARAM_COLOUR_SCHEME_DESC);&lt;br /&gt;
            /* There are currently three possible values:&lt;br /&gt;
             * - 1cc&lt;br /&gt;
             * - 2cc (default)&lt;br /&gt;
             * - real-world&lt;br /&gt;
             */&lt;br /&gt;
            min_value: 0;&lt;br /&gt;
            max_value: 2;&lt;br /&gt;
            def_value: 1;&lt;br /&gt;
            names: {&lt;br /&gt;
                0: string(STR_PARAM_COLOUR_SCHEME_1CC);&lt;br /&gt;
                1: string(STR_PARAM_COLOUR_SCHEME_2CC);&lt;br /&gt;
                2: string(STR_PARAM_COLOUR_SCHEME_REAL);&lt;br /&gt;
            };&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The GRF parameter is named &amp;lt;code&amp;gt;param_colour_scheme&amp;lt;/code&amp;gt;. This identifier needs to be unique and can be used elsewhere in the code to make decisions upon. Because we want three possible values, the GRF parameter needs to be of the integer type. The boolean type wouldn&#039;t work, as that only allows two possible values (on and off). The minimum value will be 0, the maximum 2 (resulting in three possible values 0, 1 and 2) and the default (in OpenTTD, TTDPatch always defaults to 0) will be 1. Strings are defined for the GRF parameter name and description. Each GRF parameter value will also get custom strings to display the settings rather than just numbers.&lt;br /&gt;
&lt;br /&gt;
This means we have to add these strings to the language file as well:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example&amp;quot;&amp;gt;&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_NAME :Colour scheme&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_DESC :Select the type of colour scheme to use&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_1CC  :One company colour&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_2CC  :Two company colours&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_REAL :Real-world colours&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Colour mapping callback ==&lt;br /&gt;
This only added the parameter setting, but it doesn&#039;t do anything yet. We&#039;ll use the &amp;lt;code&amp;gt;colour_mapping&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback]. This callback allows recolouring a sprite using, well errr, recolour sprites. This is a slightly complicated callback, but the first step is easy. Reference a switch block from the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example&amp;quot;&amp;gt;&lt;br /&gt;
        colour_mapping:               sw_icm_colour_mapping;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The switch block itself we&#039;ll just give to you, attempting to explain what it does afterwards. If you don&#039;t understand how this switch block works, just copy it or ignore the callback altogether. Try yourself at some more easy NewGRFs first to get the hang of NML and come back to this later.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example&amp;quot;&amp;gt;&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_colour_mapping, param_colour_scheme) {&lt;br /&gt;
    /* Emulate 1cc by making the first colour always yellow, this looks much better (and more realistic) */&lt;br /&gt;
    0: return palette_2cc(COLOUR_YELLOW, company_colour1);&lt;br /&gt;
    /* Use realistic colours, i.e. yellow + dark blue */&lt;br /&gt;
    2: return palette_2cc(COLOUR_YELLOW, COLOUR_DARK_BLUE);&lt;br /&gt;
    /* Use the default, i.e. 2 company colours */&lt;br /&gt;
    return base_sprite_2cc + CB_RESULT_COLOUR_MAPPING_ADD_CC;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision of this switch block is made on the &amp;lt;code&amp;gt;param_colour_scheme&amp;lt;/code&amp;gt;. The name of this variable is what we gave to it when defining the param block, so that&#039;s how you use a predefined GRF parameter. The values this GRF parameter can have are those defined in the same param block, so these values can be used as range in the switch block. It&#039;s useful to consider one value as default here, in case a user manages to make a setting outside the range of the minimum and maximum GRF parameter setting.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;colour_mapping&amp;lt;/code&amp;gt; needs to return the sprite number of a recolour sprite. We&#039;ll be using the default recolour sprites for this and NML has some functions and variables to retrieve these sprite numbers for you. You can find more about that in the [http://newgrf-specs.tt-wiki.net/wiki/NML:List_of_default_colour_translation_palettes NML Documentation].&lt;br /&gt;
; 1cc (&amp;lt;code&amp;gt;param_colour_scheme&amp;lt;/code&amp;gt; == 0)&lt;br /&gt;
: Here we use the &amp;lt;code&amp;gt;palette_2cc&amp;lt;/code&amp;gt; function even though we only want 1cc. To make the train look better we make one of the two company colours yellow rather than keeping the normal company colour range, using the &amp;lt;code&amp;gt;COLOUR_YELLOW&amp;lt;/code&amp;gt; from the default [http://newgrf-specs.tt-wiki.net/wiki/NML:List_of_default_colour_translation_palettes#Company_colour_helper_functions colour constants]. The other company colour will depend on what first company colour the user has selected, which we&#039;ll get from the &amp;lt;code&amp;gt;company_colour1&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables vehicle variable].&lt;br /&gt;
; real life colours (&amp;lt;code&amp;gt;param_colour_scheme&amp;lt;/code&amp;gt; == 2)&lt;br /&gt;
: The real life colours of this Dutch NS train are blue and yellow. We can force the train to be recoloured in these colours regardless of the company colours selected by the user. This is similar to the 1cc recolour from above, but now we return two specific colours rather than depend on the company colour variable.&lt;br /&gt;
; 2cc (default)&lt;br /&gt;
: This is what will be used as default if the GRF parameter setting is not equal to 0 or 2. Here a different way of returning the recolour sprite is used. The sprite number of the first 2cc recolour sprite can be found with the &amp;lt;code&amp;gt;base_sprite_2cc&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:General#General_variables variable]. Add &amp;lt;code&amp;gt;CB_RESULT_COLOUR_MAPPING_ADD_CC&amp;lt;/code&amp;gt; to this (see the [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback description]) to find the company colours used.&lt;br /&gt;
&lt;br /&gt;
With that the GRF parameter setting to choose the vehicle colours is done.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Visual effect ==&lt;br /&gt;
The train currently has a visual effect (electric spark) on all parts of the vehicle, but only the first part has a pantograph. We can limit the effect to only this first part by using the &amp;lt;code&amp;gt;visual_effect_and_powered&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_callbacks callback]. Making a decision only 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 can do this using a conditional assignment directly from the graphics block without the need for a switch block:&lt;br /&gt;
&lt;br /&gt;
Add to the graphics block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example&amp;quot;&amp;gt;&lt;br /&gt;
        visual_effect_and_powered:    return (position_in_consist % 4 == 0) ?&lt;br /&gt;
                                          visual_effect_and_powered(VISUAL_EFFECT_ELECTRIC, 2, DISABLE_WAGON_POWER) :&lt;br /&gt;
                                          visual_effect_and_powered(VISUAL_EFFECT_DISABLE, 0, DISABLE_WAGON_POWER);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the first part of the vehicle we return the electric spark [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Train_properties visual effect] with an offset of 2 and not making this a powered wagon. For all other parts we disable the visual effect (offset doesn&#039;t matter now) and also not make this a powered wagon.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lights out ==&lt;br /&gt;
There&#039;s one more thing that can be improved about this train. We still have not used the sprites that show no lights at the front and rear of the train. It would be nice if two EMUs are coupled that there are no lights on where the coupling is, only at the front and back.&lt;br /&gt;
&lt;br /&gt;
For this we have to change the graphics switch block, not referencing the spritesets for back and front directly, but using an intermediate switch block to decide if we want lights or not.&lt;br /&gt;
&lt;br /&gt;
Change the current switch block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example&amp;quot;&amp;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:      sw_icm_graphics_front;&lt;br /&gt;
    3:      sw_icm_graphics_rear;&lt;br /&gt;
    sw_icm_graphics_middle;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This now links to two additional switch blocks, one for the front and one for the rear:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example&amp;quot;&amp;gt;&lt;br /&gt;
/* Only the frontmost vehicle should have its lights on */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics_front, position_in_consist) {&lt;br /&gt;
    0: set_icm_front_lighted;&lt;br /&gt;
    set_icm_front;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Only the rearmost vehicle should have red lights */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics_rear, position_in_consist_from_end) {&lt;br /&gt;
    0: set_icm_rear_lighted;&lt;br /&gt;
    set_icm_rear;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case of the front part, we make 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]. If it&#039;s the very first of the consist, show front lights, otherwise show no front lights for further connected EMUs.&lt;br /&gt;
&lt;br /&gt;
In case of the last part, we make a decision based on the &amp;lt;code&amp;gt;position_in_consist_from_end&amp;lt;/code&amp;gt; [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Vehicle_variables variable]. This counts exactly opposite than &amp;lt;code&amp;gt;position_in_consist&amp;lt;/code&amp;gt;, now starting from the back. If it&#039;s the very last of the consist, show rear lights, otherwise show no rear lights for further connected EMUs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Total code ==&lt;br /&gt;
When put in the correct order, this should now encode as a working NewGRF. The total code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example small&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;
    /* Define user-configurable parameters */&lt;br /&gt;
    param {&lt;br /&gt;
        /* There is one parameter, which can be used to alter the colour scheme */&lt;br /&gt;
        param_colour_scheme {&lt;br /&gt;
            type: int;&lt;br /&gt;
            name: string(STR_PARAM_COLOUR_SCHEME_NAME);&lt;br /&gt;
            desc: string(STR_PARAM_COLOUR_SCHEME_DESC);&lt;br /&gt;
            /* There are currently three possible values:&lt;br /&gt;
             * - 1cc&lt;br /&gt;
             * - 2cc (default)&lt;br /&gt;
             * - real-world&lt;br /&gt;
             */&lt;br /&gt;
            min_value: 0;&lt;br /&gt;
            max_value: 2;&lt;br /&gt;
            def_value: 1;&lt;br /&gt;
            names: {&lt;br /&gt;
                0: string(STR_PARAM_COLOUR_SCHEME_1CC);&lt;br /&gt;
                1: string(STR_PARAM_COLOUR_SCHEME_2CC);&lt;br /&gt;
                2: string(STR_PARAM_COLOUR_SCHEME_REAL);&lt;br /&gt;
            };&lt;br /&gt;
        }&lt;br /&gt;
    }&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;
/* Only the frontmost vehicle should have its lights on */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics_front, position_in_consist) {&lt;br /&gt;
    0: set_icm_front_lighted;&lt;br /&gt;
    set_icm_front;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Only the rearmost vehicle should have red lights */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_graphics_rear, position_in_consist_from_end) {&lt;br /&gt;
    0: set_icm_rear_lighted;&lt;br /&gt;
    set_icm_rear;&lt;br /&gt;
}&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:      sw_icm_graphics_front;&lt;br /&gt;
    3:      sw_icm_graphics_rear;&lt;br /&gt;
    sw_icm_graphics_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;
/* --- Colour mapping callback  --- */&lt;br /&gt;
switch(FEAT_TRAINS, SELF, sw_icm_colour_mapping, param_colour_scheme) {&lt;br /&gt;
    /* Emulate 1cc by making the first colour always yellow, this looks much better (and more realistic) */&lt;br /&gt;
    0: return palette_2cc(COLOUR_YELLOW, company_colour1);&lt;br /&gt;
    /* Use realistic colours, i.e. yellow + dark blue */&lt;br /&gt;
    2: return palette_2cc(COLOUR_YELLOW, COLOUR_DARK_BLUE);&lt;br /&gt;
    /* Use the default, i.e. 2 company colours */&lt;br /&gt;
    return base_sprite_2cc + CB_RESULT_COLOUR_MAPPING_ADD_CC;&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;
        colour_mapping:               sw_icm_colour_mapping;&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;
        /* Only the front vehicle has a visual effect */&lt;br /&gt;
        visual_effect_and_powered:    return (position_in_consist % 4 == 0) ?&lt;br /&gt;
                                          visual_effect_and_powered(VISUAL_EFFECT_ELECTRIC, 2, DISABLE_WAGON_POWER) :&lt;br /&gt;
                                          visual_effect_and_powered(VISUAL_EFFECT_DISABLE, 0, DISABLE_WAGON_POWER);&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;
        //purchase_power:               return int(1260 / 0.7457); // kW -&amp;gt; hp&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;
=== The complete language file ===&lt;br /&gt;
english.lng now contains this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;example small&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_PARAM_COLOUR_SCHEME_NAME :Colour scheme&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_DESC :Select the type of colour scheme to use&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_1CC  :One company colour&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_2CC  :Two company colours&lt;br /&gt;
STR_PARAM_COLOUR_SCHEME_REAL :Real-world colours&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;
Now our train is really completed and that makes this the end of the train example.&lt;br /&gt;
&lt;br /&gt;
{{NMLTutorialNavbar|Parameters|Object}}&lt;/div&gt;</summary>
		<author><name>Frosch</name></author>
	</entry>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=NMLTutorial/Train_four_part_refit&amp;diff=8959</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=8959"/>
		<updated>2013-12-08T13:37:15Z</updated>

		<summary type="html">&lt;p&gt;Frosch: c&amp;amp;p error between cargo subtypes and artic parts&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_TEXT&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_TEXT;&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;
== 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>Frosch</name></author>
	</entry>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=Callbacks_Tutorial&amp;diff=623</id>
		<title>Callbacks Tutorial</title>
		<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=Callbacks_Tutorial&amp;diff=623"/>
		<updated>2009-06-21T15:04:44Z</updated>

		<summary type="html">&lt;p&gt;Frosch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Tutorial on using callbacks&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Callbacks in Graphics Files=&lt;br /&gt;
&lt;br /&gt;
Since TTDPatch 2.0.1 alpha 11, it is possible to use callbacks, in which the graphics files can influence how TTDPatch features work. This is a lot more sophisticated than simply using action 0 to choose various settings, in that callbacks can use the full capabilities of variational and random action 2 entries.&lt;br /&gt;
&lt;br /&gt;
-=How it works=-&lt;br /&gt;
&lt;br /&gt;
When the patch wants to use the value of certain properties, it can ask the graphics file what value to use, instead of simply looking it up in the table set by action 0. It does this if the corresponding callback bit has been set in the vehicle&#039;s action 0 properties. Then, the following happens:&lt;br /&gt;
* The patch sets the current callback ID, variable 0C, according to what callback it is&lt;br /&gt;
* Then, the patch starts at the vehicle&#039;s action 3 entry and finds the initial action 2 number to use&lt;br /&gt;
* The patch then follows the chain of variational/random action 2 entries&lt;br /&gt;
* The set-id of the final action 2 is used as result for the callback&lt;br /&gt;
&lt;br /&gt;
Because callbacks are different from regular vehicle graphics, the last action 2 in the chain must have a set-id with bit 15 set (e.g. XX 80 to return XX), which is invalid for regular graphics. &amp;amp;nbsp;Therefore, at least one action 2 in the chain must check the variable 0C, to decide whether this is a callback or the determination of graphics.&lt;br /&gt;
&lt;br /&gt;
-=How to define callbacks=-&lt;br /&gt;
&lt;br /&gt;
There are several things you have to do to get callbacks to work.&lt;br /&gt;
# If necessary, enable the callback. For vehicles, set the callback bit in the [[Action0|action 0]] property for the vehicle which should use callbacks (props 1E, 17, 12 or 14 depending on vehicle type)&lt;br /&gt;
# Set a default for the value that the callback modifies, e.g. set prop 07 when using the load amount callback&lt;br /&gt;
# Define an [[Action3|action 3]] for the vehicle if it doesn&#039;t have one already&lt;br /&gt;
# Add a [[VariationalAction2|variational action 2]] that checks the callback variable 0C for the value of the callback. See the description of a variational action 2 to find what values those are.&lt;br /&gt;
# Variable 0C should be accessed as a word. Even when the callbacks IDs you want to test are below 0xFF.&lt;br /&gt;
# This variational action 2 has to return a callback result (set-id with bit 15 set) when in a callback, or a regular set-id when not in a callback&lt;br /&gt;
# Make sure that the &amp;amp;quot;default&amp;amp;quot; of the var. 0C check (corresponding to unknown callbacks) points to a regular action 2 instead of one that returns callback results, ideally using the same action 2 as in the non-callback case. This way, unknown callbacks will fail instead of returning valid, but wrong, results.&lt;br /&gt;
&lt;br /&gt;
As explained above, a callback result is something like -+06 80+- (with 06 being used as value of the callback), instead of a regular set-id that would be for example -+04 00+-.&lt;br /&gt;
&lt;br /&gt;
-=Examples=-&lt;br /&gt;
&lt;br /&gt;
Be aware that following examples don&#039;t result into 100% complete newgrfs, but instead concentrate on the most important code features. E.g., in the given [[Action0Trains|action0s]] you&#039;d have to add even more properties to get a well-working newgrf, or, in case an example describes only one vehicle in detail, references to other vehicles, e.g. a locomotive, are given in a symbolic form (&amp;amp;quot;xx&amp;amp;quot;, &amp;amp;quot;nn&amp;amp;quot;) rather than implementing it in detail and giving correct veh-IDs or c-IDs.&lt;br /&gt;
&lt;br /&gt;
-=Example1: using Callback 33 (new sounds)=-&lt;br /&gt;
&lt;br /&gt;
The first example is a simple application. It will set new sounds for a locomotive by using [[Callbacks#Sound_effect_callback_33_|callback 33]]. The new sounds will be supplied by two .wav files using [[Action11|action 11]]. Newly defined sounds will start from slot 73 (49h), numbers 0 - 48h being original TTD sounds. The type of event (under which circumstances a particular sound should be played) is read from variable 10.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;~pp~&lt;br /&gt;
&lt;br /&gt;
0 * 4 &amp;amp;nbsp; &amp;amp;nbsp;0F 00 00 00&lt;br /&gt;
&lt;br /&gt;
// add an action 08&lt;br /&gt;
&lt;br /&gt;
1 * 8 &amp;amp;nbsp; &amp;amp;nbsp;08 02 xx xx xx xx 00 00&lt;br /&gt;
&lt;br /&gt;
// set engine (00) to use new sprites, enable for callback 33&lt;br /&gt;
&lt;br /&gt;
2 * 9 &amp;amp;nbsp; &amp;amp;nbsp;00 00 02 01 00&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;12 FD &amp;amp;nbsp; &amp;amp;nbsp;// use new sprites&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;1E 80 &amp;amp;nbsp; &amp;amp;nbsp;// enable CB 33&lt;br /&gt;
&lt;br /&gt;
// define sound files, first available slot being 49h&lt;br /&gt;
&lt;br /&gt;
3 * 3 &amp;amp;nbsp; &amp;amp;nbsp;11 02 00&lt;br /&gt;
&lt;br /&gt;
4 ** C:\ttdlx\newgrf\sprites\start.wav &amp;amp;nbsp; &amp;amp;nbsp;// 49: whistle (departure)&lt;br /&gt;
&lt;br /&gt;
5 ** C:\ttdlx\newgrf\sprites\tunnel.wav &amp;amp;nbsp; &amp;amp;nbsp;// 4A: whistle (in tunnel)&lt;br /&gt;
&lt;br /&gt;
// engine sprites go here&lt;br /&gt;
&lt;br /&gt;
6 * 4 &amp;amp;nbsp; &amp;amp;nbsp;01 00 01 04&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// 4 sprites for engine&lt;br /&gt;
&lt;br /&gt;
// c-ID 0 use above set of sprites&lt;br /&gt;
&lt;br /&gt;
11 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 00 01 01 00 00 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// engine&lt;br /&gt;
&lt;br /&gt;
// sound events are read from var10:&lt;br /&gt;
&lt;br /&gt;
12 * 18 &amp;amp;nbsp; &amp;amp;nbsp;02 00 01 81 10 00 FF 02&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;49 80 01 01 &amp;amp;nbsp; &amp;amp;nbsp;// whistle: departure&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;4A 80 02 02 &amp;amp;nbsp; &amp;amp;nbsp;// whistle: in tunnel&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;00 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// else CB fail&lt;br /&gt;
&lt;br /&gt;
// switch between callback and graphics branch&lt;br /&gt;
&lt;br /&gt;
13 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 02 85 0C 00 FF FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;01 00 33 00 33 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB 33, set sound&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;00 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// graphics&lt;br /&gt;
&lt;br /&gt;
14 * 7 &amp;amp;nbsp; &amp;amp;nbsp;03 00 01 00 00 02 00 &amp;amp;nbsp; &amp;amp;nbsp;// engine&lt;br /&gt;
&lt;br /&gt;
~/pp~&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-=Example2: using Callbacks 12, 15, and 19=-&lt;br /&gt;
&lt;br /&gt;
Suppose you want to build passenger coaches with both first and second class, having different livery and capacity, loading amount, and additional text suffixes. For this to work we&#039;ll need callbacks [[Callbacks#Load_amount_callback_12_|12 (load amount]]), [[Callbacks#Refitted_capacity_callback_15_|15 (refitted capacity]]) and [[Callbacks#Cargo_Subtype_Display_19_|19 (cargo subtype display]]):&lt;br /&gt;
&lt;br /&gt;
In addition, we&#039;ll use the feature [[VarAction2Vehicles|&amp;amp;quot;refit to same cargo type&amp;amp;quot;]] to be able to change livery, loading amount and capacity deliberately, even if coaches carry only one type of cargo, namely &amp;amp;quot;passengers&amp;amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the .nfo, the actual &amp;amp;quot;refitting&amp;amp;quot; is done by referencing variable F2, which holds how many times a vehicle was refitted to the same cargo type. In game, there will be two entries generated in the refit menu containing these text suffixes generated by an [[Action4|action 4]]. Namely &amp;amp;quot;passengers (1st class)&amp;amp;quot; and &amp;amp;quot;passengers (2nd class)&amp;amp;quot; from which to choose the desired type of coach. Likewise, load amount and capacity are linked to variable F2 as well and will be changed accordingly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;~pp~&lt;br /&gt;
&lt;br /&gt;
0 * 4 &amp;amp;nbsp; &amp;amp;nbsp;15 00 00 00&lt;br /&gt;
&lt;br /&gt;
// add an action 08&lt;br /&gt;
&lt;br /&gt;
1 * 8 &amp;amp;nbsp; &amp;amp;nbsp;08 02 xx xx xx xx 00 00&lt;br /&gt;
&lt;br /&gt;
// define additional text suffixes&lt;br /&gt;
&lt;br /&gt;
2 * 0 &amp;amp;nbsp; &amp;amp;nbsp;04 00 1F 02 00 D0&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;quot; (1st class)&amp;amp;quot; 00 &amp;amp;nbsp; &amp;amp;nbsp;// D000 = &amp;amp;quot;1st class&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;quot; (2nd class)&amp;amp;quot; 00 &amp;amp;nbsp; &amp;amp;nbsp;// D001 = &amp;amp;quot;2nd class&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
// set coach (1B) to use new sprites,&lt;br /&gt;
&lt;br /&gt;
// enable for callbacks 12, 15 and 19&lt;br /&gt;
&lt;br /&gt;
3 * 9 &amp;amp;nbsp; &amp;amp;nbsp;00 00 02 01 1B&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;12 FD &amp;amp;nbsp; &amp;amp;nbsp;// use new sprites&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;1E 2C &amp;amp;nbsp; &amp;amp;nbsp;// enable CB 12, 15 and 19&lt;br /&gt;
&lt;br /&gt;
// coach sprites go here&lt;br /&gt;
&lt;br /&gt;
4 * 4 &amp;amp;nbsp; &amp;amp;nbsp;01 00 02 04&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// 4 sprites for 1st class coach&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// 4 sprites for 2nd class coach&lt;br /&gt;
&lt;br /&gt;
// c-IDs 0..1 use above set of sprites&lt;br /&gt;
&lt;br /&gt;
13 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 00 01 01 00 00 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// 1st class&lt;br /&gt;
&lt;br /&gt;
14 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 01 01 01 01 00 01 00 &amp;amp;nbsp; &amp;amp;nbsp;// 2nd class&lt;br /&gt;
&lt;br /&gt;
// next 4 pseudo sprites are checking var F2,&lt;br /&gt;
&lt;br /&gt;
// thus constituting the two refitting possibilities:&lt;br /&gt;
&lt;br /&gt;
// [1st class, 48 passengers, load amount = 6] &amp;amp;nbsp;and&lt;br /&gt;
&lt;br /&gt;
// [2nd class, 56 passengers, load amount = 8]&lt;br /&gt;
&lt;br /&gt;
// set load amount&lt;br /&gt;
&lt;br /&gt;
15 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 02 81 F2 00 FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;06 80 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// 1st class = 6/tick&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;08 80 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// 2nd class = 8/tick&lt;br /&gt;
&lt;br /&gt;
// set refitted capacity&lt;br /&gt;
&lt;br /&gt;
16 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 03 81 F2 00 FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;30 80 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// 1st class = 48 pass&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;38 80 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// 2nd class = 56 pass&lt;br /&gt;
&lt;br /&gt;
// set text suffixes&lt;br /&gt;
&lt;br /&gt;
17 * 18 &amp;amp;nbsp; &amp;amp;nbsp;02 00 04 81 F2 00 FF 02&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;00 80 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// &amp;amp;quot;1st class&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;01 80 01 01 &amp;amp;nbsp; &amp;amp;nbsp;// &amp;amp;quot;2nd class&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;FF 80&lt;br /&gt;
&lt;br /&gt;
// set livery&lt;br /&gt;
&lt;br /&gt;
18 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 05 81 F2 00 FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;00 00 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// 1st class&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;01 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// 2nd class&lt;br /&gt;
&lt;br /&gt;
// switch between callbacks and graphics branch&lt;br /&gt;
&lt;br /&gt;
19 * 22 &amp;amp;nbsp; &amp;amp;nbsp;02 00 06 85 0C 00 FF FF 03&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;02 00 12 00 12 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB12, set load amount&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;03 00 15 00 15 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB15, set refit capacity&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;04 00 19 00 19 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB19, set text suffix&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;05 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// graphics&lt;br /&gt;
&lt;br /&gt;
20 * 7 &amp;amp;nbsp; &amp;amp;nbsp;03 00 01 1B 00 06 00 &amp;amp;nbsp; &amp;amp;nbsp;// coach&lt;br /&gt;
&lt;br /&gt;
~/pp~&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-=Example3: &amp;amp;nbsp;using callbacks 11 (wagon length) and 16 (articulated engine)=-&lt;br /&gt;
&lt;br /&gt;
This example will demonstrate how to use [[Callbacks#Articulated_engine_callback_16_|callback 16]] for designing &amp;amp;quot;articulated vehicles&amp;amp;quot;, e.g. locomotives with tenders. We&#039;ll set up two locomotives using two different tenders: &amp;amp;lt;engine1&amp;amp;gt; will use a standard short &amp;amp;lt;tender1&amp;amp;gt; and &amp;amp;lt;engine2&amp;amp;gt; will use the even shorter &amp;amp;lt;tender2&amp;amp;gt; by applying &amp;amp;nbsp;[[Callbacks#Wagon_length_callback_11_|callback 11]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;~pp~&lt;br /&gt;
&lt;br /&gt;
0 * 4 &amp;amp;nbsp; &amp;amp;nbsp;34 00 00 00&lt;br /&gt;
&lt;br /&gt;
// add an action 08&lt;br /&gt;
&lt;br /&gt;
1 * 8 &amp;amp;nbsp; &amp;amp;nbsp;08 02 xx xx xx xx 00 00&lt;br /&gt;
&lt;br /&gt;
// set the generic tender (2D) to use new sprites,&lt;br /&gt;
&lt;br /&gt;
// enable for callback 11&lt;br /&gt;
&lt;br /&gt;
2 * 13 &amp;amp;nbsp; &amp;amp;nbsp;00 00 04 01 2D&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;06 00 &amp;amp;nbsp; &amp;amp;nbsp;// don&#039;t show up in menu&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;12 FD &amp;amp;nbsp; &amp;amp;nbsp;// use new sprites&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;1E 02 &amp;amp;nbsp; &amp;amp;nbsp;// enable CB 11&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;21 02 &amp;amp;nbsp; &amp;amp;nbsp;// make shorter by 25%&lt;br /&gt;
&lt;br /&gt;
// tender sprites go here&lt;br /&gt;
&lt;br /&gt;
3 * 4 &amp;amp;nbsp; &amp;amp;nbsp;01 00 02 08&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// 8 sprites for tender1&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// 8 sprites for tender2&lt;br /&gt;
&lt;br /&gt;
// Cargo-ids 0..1 use above set of sprites&lt;br /&gt;
&lt;br /&gt;
20 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 F0 01 01 00 00 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// tender1 (F0)&lt;br /&gt;
&lt;br /&gt;
21 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 00 01 01 01 00 01 00 &amp;amp;nbsp; &amp;amp;nbsp;// tender2&lt;br /&gt;
&lt;br /&gt;
// tender2 (F1) is shorter&lt;br /&gt;
&lt;br /&gt;
22 * 18 &amp;amp;nbsp; &amp;amp;nbsp;02 00 F1 85 0C 00 FF FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;03 80 11 00 11 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB11: make shorter by 37.5%&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;00 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// graphics&lt;br /&gt;
&lt;br /&gt;
23 * 7 &amp;amp;nbsp; &amp;amp;nbsp;03 00 01 2D 00 F0 00 &amp;amp;nbsp; &amp;amp;nbsp;// standard tender&lt;br /&gt;
&lt;br /&gt;
// set two engines (00 and 01) to use new sprites,&lt;br /&gt;
&lt;br /&gt;
// enable for callback 16&lt;br /&gt;
&lt;br /&gt;
24 * 11 &amp;amp;nbsp; &amp;amp;nbsp;00 00 02 02 00&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;12 FD FD &amp;amp;nbsp; &amp;amp;nbsp;// use new sprites&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;1E 10 10 &amp;amp;nbsp; &amp;amp;nbsp;// enable CB 16&lt;br /&gt;
&lt;br /&gt;
// engine sprites go here&lt;br /&gt;
&lt;br /&gt;
25 * 4 &amp;amp;nbsp; &amp;amp;nbsp;01 00 02 08&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// 8 sprites for engine1&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// 8 sprites for engine2&lt;br /&gt;
&lt;br /&gt;
// Cargo-ids 0..1 use above set of sprites&lt;br /&gt;
&lt;br /&gt;
42 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 00 01 01 00 00 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// engine1&lt;br /&gt;
&lt;br /&gt;
43 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 01 01 01 01 00 01 00 &amp;amp;nbsp; &amp;amp;nbsp;// engine2&lt;br /&gt;
&lt;br /&gt;
// &amp;amp;lt;engine1&amp;amp;gt; uses standard &amp;amp;lt;tender1&amp;amp;gt;&lt;br /&gt;
&lt;br /&gt;
// engine is articulated, so show either engine (00) or tender (F0)&lt;br /&gt;
&lt;br /&gt;
44 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 02 81 41 00 01 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;00 00 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// engine1&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;F0 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// tender1&lt;br /&gt;
&lt;br /&gt;
// set articulated CB&lt;br /&gt;
&lt;br /&gt;
45 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 03 81 10 00 FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;2D 80 01 01 &amp;amp;nbsp; &amp;amp;nbsp;// add tender (2D)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;FF 80 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// end of articulated vehicle&lt;br /&gt;
&lt;br /&gt;
// Switch between callback and graphics branch&lt;br /&gt;
&lt;br /&gt;
46 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 04 85 0C 00 FF FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;03 00 16 00 16 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB16, handle it&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;02 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// graphics&lt;br /&gt;
&lt;br /&gt;
47 * 7 &amp;amp;nbsp; &amp;amp;nbsp;03 00 01 00 00 04 00 &amp;amp;nbsp; &amp;amp;nbsp;// engine1 with tender1&lt;br /&gt;
&lt;br /&gt;
// &amp;amp;lt;engine2&amp;amp;gt; uses shorter &amp;amp;lt;tender2&amp;amp;gt;&lt;br /&gt;
&lt;br /&gt;
// engine is articulated, so show either engine (01) or tender (F1)&lt;br /&gt;
&lt;br /&gt;
48 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 02 81 41 00 01 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;01 00 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// engine2&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;F1 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// tender2&lt;br /&gt;
&lt;br /&gt;
// switch between callback and graphics branch&lt;br /&gt;
&lt;br /&gt;
49 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 04 85 0C 00 FF FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;03 00 16 00 16 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB 16, handle it&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// (same as for &amp;amp;lt;engine1&amp;amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;02 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// graphics&lt;br /&gt;
&lt;br /&gt;
50 * 7 &amp;amp;nbsp; &amp;amp;nbsp;03 00 01 01 00 04 00 &amp;amp;nbsp; &amp;amp;nbsp;// engine2&lt;br /&gt;
&lt;br /&gt;
51 * 7 &amp;amp;nbsp;03 00 81 2D 00 F1 00 &amp;amp;nbsp; &amp;amp;nbsp;// override with tender2&lt;br /&gt;
&lt;br /&gt;
~/pp~&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-=Example4: using Callbacks 10, 16, 1D and 23=-&lt;br /&gt;
&lt;br /&gt;
This example explains how to use [[Callbacks#Articulated_engine_callback_10_|callbacks 10 (power]]), [[Callbacks#Articulated_engine_callback_16_|16 (articulated]]),&lt;br /&gt;
&lt;br /&gt;
[[Callbacks#Articulated_engine_callback_1D_|1D (engine attach]]), and [[Callbacks#Articulated_engine_callback_23_|23 (additional text in menu]]) to construct a four-part EMU.&lt;br /&gt;
&lt;br /&gt;
The EMU is composed from the same building block, an electric rail car (veh-ID = 62). In addition, it should be allowed to link three of these four-part EMUs, i.e. a full consist may contain 12 rail cars in total.&lt;br /&gt;
&lt;br /&gt;
For sake of realism, no &amp;amp;quot;foreign&amp;amp;quot; vehicles should be allowed to be attached to the EMU. This is achieved by checking the veh-ID from [[VarAction2Vehicles|variable C6]]. Appropriate error messages will be generated if there&#039;s something wrong, either with number or with type of added vehicles.&lt;br /&gt;
&lt;br /&gt;
Please notice that CBs 1D and 23 do not need a bit set in action0&#039;s property 1E.&lt;br /&gt;
&lt;br /&gt;
Furthermore, it is shown how to make an explicit menu entry for such an EMU. For this to work, we need an extra sprite depicting not the single rail car but the complete four-part EMU. Because this sprite will be used only inside the buying menu, the corresponding sprite block needs only this single sprite for the horizontal direction. All other directions are not needed and hence we don&#039;t have to include sprites for them.&lt;br /&gt;
&lt;br /&gt;
Also, the variable action2 chain for the menu entry need references for callbacks 16 and 23. The latter is used to place the text of additional information into the menu entry, and CB 16 is needed to get the capacity of the four-part EMU to show up correctly in the buying menu.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;~pp~&lt;br /&gt;
&lt;br /&gt;
0 * 4 &amp;amp;nbsp; &amp;amp;nbsp;39 00 00 00&lt;br /&gt;
&lt;br /&gt;
// add an action 08&lt;br /&gt;
&lt;br /&gt;
1 * 8 &amp;amp;nbsp; &amp;amp;nbsp;08 02 xx xx xx xx 00 00&lt;br /&gt;
&lt;br /&gt;
// CB 1D error messages&lt;br /&gt;
&lt;br /&gt;
2 * 0 &amp;amp;nbsp; &amp;amp;nbsp;04 00 81 02 20 D0&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;quot; (wrong number of cars)&amp;amp;quot; 00 &amp;amp;nbsp; &amp;amp;nbsp;// D020&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;quot; (wrong type of car)&amp;amp;quot; 00 &amp;amp;nbsp; &amp;amp;nbsp;// D021&lt;br /&gt;
&lt;br /&gt;
// CB 23 additional text for menu&lt;br /&gt;
&lt;br /&gt;
3 * 0 &amp;amp;nbsp; &amp;amp;nbsp;04 00 81 01 22 D0&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;0d 91 &amp;amp;quot;4-part EMU for commuter service.&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;quot; (Links max 12 parts)&amp;amp;quot; 00&lt;br /&gt;
&lt;br /&gt;
// set rail car (62) to use new sprites,&lt;br /&gt;
&lt;br /&gt;
// enable for callbacks 10 and 16&lt;br /&gt;
&lt;br /&gt;
4 * 11 &amp;amp;nbsp; &amp;amp;nbsp;00 00 03 01 62&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;12 FD &amp;amp;nbsp; &amp;amp;nbsp;// use new sprites&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;19 30 &amp;amp;nbsp; &amp;amp;nbsp;// electric traction&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;1E 11 &amp;amp;nbsp; &amp;amp;nbsp;// enable CBs 10 and 16&lt;br /&gt;
&lt;br /&gt;
//----------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
// the &amp;amp;quot;train&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
//----------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
// all rail car sprites go here&lt;br /&gt;
&lt;br /&gt;
5 * 4 &amp;amp;nbsp; &amp;amp;nbsp;01 00 04 08&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// sprites for 1st car&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// sprites for 2nd car&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// sprites for 3rd car&lt;br /&gt;
&lt;br /&gt;
[...] &amp;amp;nbsp; &amp;amp;nbsp;// sprites for 4th car&lt;br /&gt;
&lt;br /&gt;
// c-IDs 0..3 use above set of sprites&lt;br /&gt;
&lt;br /&gt;
38 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 00 01 01 00 00 00 00 &amp;amp;nbsp; &amp;amp;nbsp;// 1st car&lt;br /&gt;
&lt;br /&gt;
39 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 01 01 01 01 00 01 00 &amp;amp;nbsp; &amp;amp;nbsp;// 2nd car&lt;br /&gt;
&lt;br /&gt;
40 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 02 01 01 02 00 02 00 &amp;amp;nbsp; &amp;amp;nbsp;// 3rd car&lt;br /&gt;
&lt;br /&gt;
41 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 03 01 01 03 00 03 00 &amp;amp;nbsp; &amp;amp;nbsp;// 4th car&lt;br /&gt;
&lt;br /&gt;
// determine which car we are at. AND-ing the number of vehicles&lt;br /&gt;
&lt;br /&gt;
// in consist is more efficient as a &amp;amp;quot;modulo-4&amp;amp;quot; operation would be.&lt;br /&gt;
&lt;br /&gt;
42 * 22 &amp;amp;nbsp; &amp;amp;nbsp;02 00 04 81 40 00 03 03&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;03 00 03 03 &amp;amp;nbsp; &amp;amp;nbsp;// 4th car&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;02 00 02 02 &amp;amp;nbsp; &amp;amp;nbsp;// 3rd car&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;01 00 01 01 &amp;amp;nbsp; &amp;amp;nbsp;// 2nd car&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;00 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// 1st car&lt;br /&gt;
&lt;br /&gt;
// set CB 16 (articulated vehicle)&lt;br /&gt;
&lt;br /&gt;
43 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 05 81 10 00 FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;62 80 01 03 &amp;amp;nbsp; &amp;amp;nbsp;// 3 additional parts of veh-ID 62&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;FF 80 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// end articulated vehicle&lt;br /&gt;
&lt;br /&gt;
// set CB 1D (engine attach)&lt;br /&gt;
&lt;br /&gt;
// allow only 3 * EMU (= 12 cars) in total&lt;br /&gt;
&lt;br /&gt;
44 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 06 82 40 10 FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;FE 80 00 09 &amp;amp;nbsp; &amp;amp;nbsp;// allow adding of max 8 cars&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;20 80 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// error: &amp;amp;quot;wrong number of cars&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
// allow only EMU to attach itself, nothing else&lt;br /&gt;
&lt;br /&gt;
45 * 14 &amp;amp;nbsp; &amp;amp;nbsp;02 00 07 81 C6 00 FF 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;06 00 62 62 &amp;amp;nbsp; &amp;amp;nbsp;// allow&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;21 80 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// error: &amp;amp;quot;wrong type of car&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
// only car1 and, if exist, 5 and 9 should be sparking&lt;br /&gt;
&lt;br /&gt;
// we&#039;re using a modulo-4 operation -&amp;amp;gt; 80-FF-00-04&lt;br /&gt;
&lt;br /&gt;
46 * 16 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;02 00 08 81 40 80 FF 00 04 01&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;33 80 01 01 &amp;amp;nbsp; &amp;amp;nbsp;// sparks&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;40 80 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// no sparks&lt;br /&gt;
&lt;br /&gt;
// switch between callback and graphics branch&lt;br /&gt;
&lt;br /&gt;
47 * 22 &amp;amp;nbsp; &amp;amp;nbsp;02 00 09 85 0C 00 FF FF 03&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;05 00 16 00 16 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB16, handle it&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;07 00 1D 00 1D 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB 1D, handle it&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;08 00 10 00 10 00 &amp;amp;nbsp; &amp;amp;nbsp;// is CB 10, handle it&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;04 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// graphics&lt;br /&gt;
&lt;br /&gt;
//----------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
// menu entry&lt;br /&gt;
&lt;br /&gt;
//----------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
48 * 4 &amp;amp;nbsp; &amp;amp;nbsp;01 00 01 04&lt;br /&gt;
&lt;br /&gt;
49 * 1 &amp;amp;nbsp; &amp;amp;nbsp;00&lt;br /&gt;
&lt;br /&gt;
50 * 1 &amp;amp;nbsp; &amp;amp;nbsp;00&lt;br /&gt;
&lt;br /&gt;
51 C:\ttdlx\newgrf\sprites\emu.pcx 226 120 01 15 91 -27 -11&lt;br /&gt;
&lt;br /&gt;
52 * 1 &amp;amp;nbsp; &amp;amp;nbsp;00&lt;br /&gt;
&lt;br /&gt;
53 * 9 &amp;amp;nbsp; &amp;amp;nbsp;02 00 00 01 01 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
// switch between callback and graphics branch&lt;br /&gt;
&lt;br /&gt;
54 * 18 &amp;amp;nbsp; &amp;amp;nbsp;02 00 01 85 0C 00 FF FF 02&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;05 00 16 00 16 00 &amp;amp;nbsp; &amp;amp;nbsp;// CB 16 (for capacity calculation)&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;22 80 23 00 23 00 &amp;amp;nbsp; &amp;amp;nbsp;// CB 23, show additional text&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;00 00 &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;// graphics&lt;br /&gt;
&lt;br /&gt;
55 * 10 &amp;amp;nbsp; &amp;amp;nbsp;03 00 01 62 01 FF 01 00 09 00&lt;br /&gt;
&lt;br /&gt;
~/pp~&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Frosch</name></author>
	</entry>
</feed>