<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://www.tt-wiki.net/index.php?action=history&amp;feed=atom&amp;title=NMLTutorial%2FRoad_vehicle_item_definition</id>
	<title>NMLTutorial/Road vehicle item definition - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.tt-wiki.net/index.php?action=history&amp;feed=atom&amp;title=NMLTutorial%2FRoad_vehicle_item_definition"/>
	<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=NMLTutorial/Road_vehicle_item_definition&amp;action=history"/>
	<updated>2026-04-29T08:52:21Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=NMLTutorial/Road_vehicle_item_definition&amp;diff=7611&amp;oldid=prev</id>
		<title>FooBar: initial version at 0</title>
		<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=NMLTutorial/Road_vehicle_item_definition&amp;diff=7611&amp;oldid=prev"/>
		<updated>2011-08-22T21:43:37Z</updated>

		<summary type="html">&lt;p&gt;initial version at 0&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 21:43, 22 August 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 111:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 111:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    name: string(STR_GRF_NAME);&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    name: string(STR_GRF_NAME);&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    desc: string(STR_GRF_DESC);&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    desc: string(STR_GRF_DESC);&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    version: &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1&lt;/del&gt;;&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    version: &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;0&lt;/ins&gt;;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    min_compatible_version: &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1&lt;/del&gt;;&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    min_compatible_version: &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;0&lt;/ins&gt;;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>FooBar</name></author>
	</entry>
	<entry>
		<id>https://www.tt-wiki.net/index.php?title=NMLTutorial/Road_vehicle_item_definition&amp;diff=7601&amp;oldid=prev</id>
		<title>FooBar: item definition for road vehicle example</title>
		<link rel="alternate" type="text/html" href="https://www.tt-wiki.net/index.php?title=NMLTutorial/Road_vehicle_item_definition&amp;diff=7601&amp;oldid=prev"/>
		<updated>2011-08-22T20:00:50Z</updated>

		<summary type="html">&lt;p&gt;item definition for road vehicle example&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{NMLTutorial}}&lt;br /&gt;
&amp;#039;&amp;#039;The example used here is from the NML source. The code for this was originally written by Terkhen and planetmaker. The graphics used in the example are by DanMack and Zephyris. Code and graphics are both licensed according to the GPL v2 or later. The code has been modified for the purpose of this tutorial&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This continues the [[NMLTutorial/Road vehicle|first part]] of the road vehicle example. Let&amp;#039;s define ourselves a road vehicle!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Item block ==&lt;br /&gt;
In order to define a road vehicle, we need an item block. For this item&amp;#039;s [http://newgrf-specs.tt-wiki.net/wiki/NML:Features feature] we of course set &amp;lt;code&amp;gt;FEAT_ROADVEHS&amp;lt;/code&amp;gt; to define a road vehicle. We also give the vehicle item identifier a name: &amp;#039;&amp;#039;item_flatbed_truck_1&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The NML code for this looks as follows:&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;
/* Define the road vehicle */&lt;br /&gt;
item(FEAT_ROADVEHS, item_flatbed_truck_1) {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That wasn&amp;#039;t too complicated, was it? Of course the item block is still empty, so let&amp;#039;s fill it.&lt;br /&gt;
&lt;br /&gt;
=== Property block ===&lt;br /&gt;
What properties are available for road vehicles must be looked up in the NML Documentation in two tables. One table has [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Properties_common_to_all_vehicle_types properites common to all vehicle types] (i.e. trains, road vehicles, ships and planes) and a second table has [http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles#Road_vehicle_properties road vehicle specific properties]. Properties from both tables can go in the same property block and their order of appearance doesn&amp;#039;t matter.&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll not explain every property here, as you can easily look them up. Here&amp;#039;s a full set of properties for the example road vehicle:&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;
    property {&lt;br /&gt;
        /* Properties common to all vehicle types */&lt;br /&gt;
        name:                           string(STR_NAME_FLATBED_TRUCK_1);&lt;br /&gt;
        climates_available:             bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);&lt;br /&gt;
        introduction_date:              date(1926,01,01);&lt;br /&gt;
        model_life:                     65;&lt;br /&gt;
        /* retire_early not set, use default retirement behaviour */&lt;br /&gt;
        vehicle_life:                   15;&lt;br /&gt;
        reliability_decay:              20;&lt;br /&gt;
        refittable_cargo_classes:       bitmask(CC_PIECE_GOODS, CC_EXPRESS);&lt;br /&gt;
        non_refittable_cargo_classes:   bitmask(CC_PASSENGERS, CC_REFRIGERATED);&lt;br /&gt;
        loading_speed:                  5;&lt;br /&gt;
        cost_factor:                    108;&lt;br /&gt;
        running_cost_factor:            90;&lt;br /&gt;
        /* cargo_age_period is left at default */&lt;br /&gt;
&lt;br /&gt;
        /* RV-specific properties */&lt;br /&gt;
        sprite_id:                      SPRITE_ID_NEW_ROADVEH; //enable new graphics&lt;br /&gt;
        speed:                          48 km/h;&lt;br /&gt;
        misc_flags:                     bitmask(ROADVEH_FLAG_2CC);&lt;br /&gt;
        refit_cost:                     0; // Refitting is free&lt;br /&gt;
        /* callback_flags are not set, no need to manually enable callbacks */&lt;br /&gt;
        running_cost_base:              RUNNING_COST_ROADVEH;&lt;br /&gt;
        power:                          120 hp;&lt;br /&gt;
        weight:                         9.5 ton;&lt;br /&gt;
        /* TE and air drag coefficient is left at default */&lt;br /&gt;
        cargo_capacity:                 20;&lt;br /&gt;
        sound_effect:                   SOUND_BUS_START_PULL_AWAY;&lt;br /&gt;
        /* Visual effect is left at default (no effect) */&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Units ====&lt;br /&gt;
For some property values you need to supply a unit. The NML Documentation has a [http://newgrf-specs.tt-wiki.net/wiki/NML:Units list of units] which you can use for speed, power and weight. That way, you don&amp;#039;t have to do any calculations on these values and just use the units you&amp;#039;re comfortable with. NML will do the calculation for you, and you may for instance even specify the speed of one vehicle in km/h and that of the other vehicle in mph.&lt;br /&gt;
&lt;br /&gt;
==== Functions ====&lt;br /&gt;
For some property values you are required to use a function. The NML Documentation has a [http://newgrf-specs.tt-wiki.net/wiki/NML:Builtin_functions list of builtin functions], but whether you actually need a function is listed in the &amp;#039;&amp;#039;value range&amp;#039;&amp;#039; column of the properties tables. Most of these functions are self-explanatory.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;bitmask()&amp;#039;&amp;#039;&amp;#039; function however is important enough to address seperately. Some properties can have a list of options that you want. For instance, for the refittable_cargo_classes you can provide a list of cargo classes you want the vehicle to be refittable to. This list is encoded in a bitmask using the bitmask function.&lt;br /&gt;
* If you want one or more options available for the specific bitmask, use the bitmask() function.&lt;br /&gt;
* If you want all, put them all in the bitmask, or use the ALL_ value available for some properties &amp;#039;&amp;#039;without&amp;#039;&amp;#039; the bitmask() function.&lt;br /&gt;
&lt;br /&gt;
==== Cargos ====&lt;br /&gt;
When defining which cargos a vehicle can carry, you can use cargo classes or cargo labels. Cargo classes combine a group of cargos into one class. Cargo labels refer to a single specific cargo.&lt;br /&gt;
If you set what cargo a vehicle can carry, &amp;#039;&amp;#039;&amp;#039;always use cargo classes&amp;#039;&amp;#039;&amp;#039;. Use cargo labels only to define exceptions to these classes or to provide special graphics for specific cargos. We&amp;#039;ll see about these special graphics later. Note that when using cargo labels you need a cargotable definition. More about the cargotable later when we get to cargo-dependent graphics for the road vehicle.&lt;br /&gt;
&lt;br /&gt;
=== Graphics block ===&lt;br /&gt;
The graphics block links the item definition to the graphics definition. For now, we&amp;#039;ll limit ourselves to one livery for the truck and no specific purchase menu sprite (these are generally not needed for non-articulated vehicles). This means we only have a &amp;#039;&amp;#039;default&amp;#039;&amp;#039; &amp;quot;callback&amp;quot;:&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;
    /* Define graphics */&lt;br /&gt;
    graphics {&lt;br /&gt;
        default: spritegroup_flatbed_truck_1_goods; // use a goods container for a (loaded) flatbed truck&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells NML to look in the spritegroup with the identifier &amp;lt;code&amp;gt;spritegroup_flatbed_truck_1_goods&amp;lt;/code&amp;gt; for the graphics for this vehicle. More about spritegroups on the next page.&lt;br /&gt;
&lt;br /&gt;
Whatever identifier you choose here is again up to you. It&amp;#039;s recommended to start it with &amp;#039;&amp;#039;spritegroup_&amp;#039;&amp;#039; so you know directly from the identifier that it links to a spritegroup block. That way you don&amp;#039;t need an additional comment for that.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Expanding the language file ==&lt;br /&gt;
You may have noticed the &amp;lt;code&amp;gt;string(STR_NAME_FLATBED_TRUCK_1)&amp;lt;/code&amp;gt; value for the vehicle name in the property. This means that we also need to define this particular string in the language file. Open the language file and add the string:&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;
##grflangid 0x01&lt;br /&gt;
&lt;br /&gt;
# GRF name and description&lt;br /&gt;
STR_GRF_NAME             :NML Example NewGRF: Road Vehicle&lt;br /&gt;
STR_GRF_DESC             :{ORANGE}NML Example NewGRF: Road Vehicle{}{BLACK}This NewGRF is intended to provide a coding example for the high-level NewGRF-coding language NML.{}Original graphics by {SILVER}DanMack, Zephyris, {BLACK}coding by {SILVER}Terkhen, planetmaker.{}{BLACK}This NewGRF defines first-generation flatbed truck.&lt;br /&gt;
&lt;br /&gt;
# vehicle names&lt;br /&gt;
STR_NAME_FLATBED_TRUCK_1 :Flatbed Truck MkI&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== The complete code so far ==&lt;br /&gt;
The complete NML file so far will look like this. Don&amp;#039;t forget to update your language file if you haven&amp;#039;t done that yet; it should look as the one directly above.&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 the grf&lt;br /&gt;
grf {&lt;br /&gt;
    grfid: &amp;quot;NML\03&amp;quot;;&lt;br /&gt;
    name: string(STR_GRF_NAME);&lt;br /&gt;
    desc: string(STR_GRF_DESC);&lt;br /&gt;
    version: 1;&lt;br /&gt;
    min_compatible_version: 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Define the road vehicle */&lt;br /&gt;
item(FEAT_ROADVEHS, item_flatbed_truck_1) {&lt;br /&gt;
    property {&lt;br /&gt;
        /* Properties common to all vehicle types */&lt;br /&gt;
        name:                           string(STR_NAME_FLATBED_TRUCK_1);&lt;br /&gt;
        climates_available:             bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);&lt;br /&gt;
        introduction_date:              date(1926,01,01);&lt;br /&gt;
        model_life:                     65;&lt;br /&gt;
        /* retire_early not set, use default retirement behaviour */&lt;br /&gt;
        vehicle_life:                   15;&lt;br /&gt;
        reliability_decay:              20;&lt;br /&gt;
        refittable_cargo_classes:       bitmask(CC_PIECE_GOODS, CC_EXPRESS);&lt;br /&gt;
        non_refittable_cargo_classes:   bitmask(CC_PASSENGERS, CC_REFRIGERATED);&lt;br /&gt;
        loading_speed:                  5;&lt;br /&gt;
        cost_factor:                    108;&lt;br /&gt;
        running_cost_factor:            90;&lt;br /&gt;
        /* cargo_age_period is left at default */&lt;br /&gt;
&lt;br /&gt;
        /* RV-specific properties */&lt;br /&gt;
        sprite_id:                      SPRITE_ID_NEW_ROADVEH; //enable new graphics&lt;br /&gt;
        speed:                          48 km/h;&lt;br /&gt;
        misc_flags:                     bitmask(ROADVEH_FLAG_2CC);&lt;br /&gt;
        refit_cost:                     0; // Refitting is free&lt;br /&gt;
        /* callback_flags are not set, no need to manually enable callbacks */&lt;br /&gt;
        running_cost_base:              RUNNING_COST_ROADVEH;&lt;br /&gt;
        power:                          120 hp;&lt;br /&gt;
        weight:                         9.5 ton;&lt;br /&gt;
        /* TE and air drag coefficient is left at default */&lt;br /&gt;
        cargo_capacity:                 20;&lt;br /&gt;
        sound_effect:                   SOUND_BUS_START_PULL_AWAY;&lt;br /&gt;
        /* Visual effect is left at default (no effect) */&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /* Define graphics */&lt;br /&gt;
    graphics {&lt;br /&gt;
        default: spritegroup_flatbed_truck_1_goods; // use a goods container for a (loaded) flatbed truck&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This concludes the item definition for the road vehicle. Continue to learn about adding graphics and after that you&amp;#039;ll see how to add the graphics for the road vehicle.&lt;br /&gt;
&lt;br /&gt;
{{NMLTutorialNavbar|Item|Spriteset and spritegroup}}&lt;/div&gt;</summary>
		<author><name>FooBar</name></author>
	</entry>
</feed>