<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://newgrf-specs.tt-wiki.net/index.php?action=history&amp;feed=atom&amp;title=User%3AAndrew350%2FNML%3ATramtypes</id>
	<title>User:Andrew350/NML:Tramtypes - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://newgrf-specs.tt-wiki.net/index.php?action=history&amp;feed=atom&amp;title=User%3AAndrew350%2FNML%3ATramtypes"/>
	<link rel="alternate" type="text/html" href="https://newgrf-specs.tt-wiki.net/index.php?title=User:Andrew350/NML:Tramtypes&amp;action=history"/>
	<updated>2026-04-21T08:43:13Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://newgrf-specs.tt-wiki.net/index.php?title=User:Andrew350/NML:Tramtypes&amp;diff=3920&amp;oldid=prev</id>
		<title>Andrew350: initial conversion to tramtypes (from roadtypes)</title>
		<link rel="alternate" type="text/html" href="https://newgrf-specs.tt-wiki.net/index.php?title=User:Andrew350/NML:Tramtypes&amp;diff=3920&amp;oldid=prev"/>
		<updated>2019-12-22T11:22:14Z</updated>

		<summary type="html">&lt;p&gt;initial conversion to tramtypes (from roadtypes)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{NMLNavPropVarCB}}&lt;br /&gt;
&lt;br /&gt;
Tramtypes can only be defined in OpenTTD {{ottd|1.10}} or later. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Tramtype IDs==&lt;br /&gt;
Tramtypes and Roadtypes share a pool of 64 IDs. Either feature can use as many IDs as needed (i.e. it is not limited to 32 per type), but both features combined are limited to 64 in total. NewGRF-local IDs may freely be chosen, but must be in the 0..63 range. If other tramtype/tramtype GRFs are loaded, it may be that there are not enough slots available. To prevent your entire NewGRF from being deactivated with the &amp;#039;Attempt to use invalid ID&amp;#039;-error, you can use the following code:&lt;br /&gt;
&lt;br /&gt;
 if (tramtype_available(&amp;quot;LABL&amp;quot;) || loading_stage == LOADING_STAGE_RESERVE)&lt;br /&gt;
     ... item definition ...&lt;br /&gt;
 } else if (loading_stage == LOADING_STAGE_ACTIVATE) {&lt;br /&gt;
     ... warning / error ...&lt;br /&gt;
 }&lt;br /&gt;
The warning / error is optional, but can be used to inform the user about the missing tramtypes.&lt;br /&gt;
&lt;br /&gt;
== Vehicle and Tramtype availability ==&lt;br /&gt;
&lt;br /&gt;
Vehicle and tramtype availability and compatibility is influenced by multiple properties.&lt;br /&gt;
Generally, the vehicle defines which tramtype it is, and the tramtypes define the compatibility between each other.&lt;br /&gt;
* Remember that the road vehicle flag &amp;#039;ROADVEH_FLAG_TRAM&amp;#039; must be set in order for a road vehicle to be considered a tram.&lt;br /&gt;
* A vehicle exists, if its tramtype (tram vehicle property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;track_type&amp;lt;/code&amp;gt;) is defined. Otherwise the vehicle is disabled.&lt;br /&gt;
* When a vehicle is introduced, it always introduces its tramtype (tram vehicle property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;track_type&amp;lt;/code&amp;gt;).&lt;br /&gt;
* A tramtype is introduced, if at least one of the following conditions is met:&lt;br /&gt;
** A vehicle is introduced, that references the tramtype (tram vehicle property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;track_type&amp;lt;/code&amp;gt;).&lt;br /&gt;
** Another tramtype is introduced, that references the tramtype via the introduced tramtype list (tramtype property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;introduces_tramtype_list&amp;lt;/code&amp;gt;).&lt;br /&gt;
** The introduction date (tramtype property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;introduction_date&amp;lt;/code&amp;gt;) is passed and all required tramtypes (tramtype property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;requires_tramtype_list &amp;lt;/code&amp;gt;) are available.&lt;br /&gt;
&lt;br /&gt;
Via tramtype property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;powered_tramtype_list&amp;lt;/code&amp;gt; multiple tramtypes can be defined, which shall be considered equivalent to a tramtype.&lt;br /&gt;
This affects the interpretation of tram vehicle property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;track_type&amp;lt;/code&amp;gt;. If tram vehicle property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;track_type&amp;lt;/code&amp;gt; references an undefined tramtype, then&lt;br /&gt;
tramtype property &amp;lt;code style=&amp;quot;color:green&amp;quot;&amp;gt;powered_tramtype_list&amp;lt;/code&amp;gt; is checked for all defined tramtypes, whether the vehicle can be reassigned to some other tramtype.&lt;br /&gt;
Otherwise the vehicle is disabled.&lt;br /&gt;
&lt;br /&gt;
==Tramtype properties==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;t&amp;quot;&lt;br /&gt;
! property&lt;br /&gt;
! value range&lt;br /&gt;
! comment&lt;br /&gt;
|-&lt;br /&gt;
| label&lt;br /&gt;
| 4-byte string&lt;br /&gt;
| names of default tram types: &amp;quot;RAIL&amp;quot; and &amp;quot;ELRL&amp;quot;. See the [[TramtypeLabels|List of tramtype labels]] in the NewGRF Specs for currently defined custom labels.&lt;br /&gt;
|-&lt;br /&gt;
| introduction_date&lt;br /&gt;
| date(yyyy,mm,dd)&lt;br /&gt;
| Valid range for yyyy is 0 ... 5000000.&lt;br /&gt;
|-&lt;br /&gt;
| name&lt;br /&gt;
| string&lt;br /&gt;
| Name of this tramtype&lt;br /&gt;
|-&lt;br /&gt;
| toolbar_caption&lt;br /&gt;
| string&lt;br /&gt;
| Caption of the build tram toolbar. In earlier versions this is the same as the &amp;#039;name&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| menu_text&lt;br /&gt;
| string&lt;br /&gt;
| Shown in the dropdown menu for all tramtypes&lt;br /&gt;
|-&lt;br /&gt;
| build_window_caption&lt;br /&gt;
| string&lt;br /&gt;
| Caption of the build vehicle window&lt;br /&gt;
|-&lt;br /&gt;
| autoreplace_text&lt;br /&gt;
| string&lt;br /&gt;
| String for the autoreplace window&lt;br /&gt;
|-&lt;br /&gt;
| new_engine_text&lt;br /&gt;
| string&lt;br /&gt;
| String for the &amp;quot;We have invented a new &amp;amp;lt;tram type&amp;amp;gt; engine&amp;quot; news message&lt;br /&gt;
|-&lt;br /&gt;
| powered_tramtype_list&lt;br /&gt;
| list of tramtype labels&lt;br /&gt;
| Provide a list of tram types that tram vehicles of this type are powered on, e.g. [&amp;quot;RAIL&amp;quot;, &amp;quot;ELRL&amp;quot;]. Note that there is no difference between &amp;quot;powered&amp;quot; and &amp;quot;compatible&amp;quot; for tramtypes&lt;br /&gt;
|-&lt;br /&gt;
| tramtype_flags&lt;br /&gt;
| bitmask(TRAMTYPE_FLAG_XXX, ...)&lt;br /&gt;
|&lt;br /&gt;
;CATENARY&lt;br /&gt;
:Enable catenary&lt;br /&gt;
;NO_LEVEL_CROSSING&lt;br /&gt;
:Disable level crossings&lt;br /&gt;
;NO_HOUSES&lt;br /&gt;
:Disallows house construction&lt;br /&gt;
|-&lt;br /&gt;
| construction_cost&lt;br /&gt;
| 0 ... 65525&lt;br /&gt;
| Per piece of track as multiplier to PR_BUILD_ROAD base cost. Default cost factors are 8 and 16 for RAIL and ELRL, respectively.&lt;br /&gt;
|-&lt;br /&gt;
| speed_limit&lt;br /&gt;
| 0 ... 65525 km/h (speed units)&lt;br /&gt;
| A speed limit of 0 means unlimited speed&lt;br /&gt;
|-&lt;br /&gt;
| map_colour&lt;br /&gt;
| 0 ... 255&lt;br /&gt;
| Entry in the colour palette.&lt;br /&gt;
|-&lt;br /&gt;
| requires_tramtype_list&lt;br /&gt;
| list of tramtype labels&lt;br /&gt;
| List of tram types that need to be available to the company of the player for this tram type to be introduced at (or after) the introduction date. This limit does not apply when the tram type is introduced by the introduction of a vehicle.&lt;br /&gt;
|-&lt;br /&gt;
| introduces_tramtype_list&lt;br /&gt;
| list of tramtype labels&lt;br /&gt;
| List of tram types that get introduced when this tram type is introduced. For example, to make sure that when a fast tram type is introduced the slow variant exists.&lt;br /&gt;
|-&lt;br /&gt;
| sort_order&lt;br /&gt;
| 0 ... 255&lt;br /&gt;
| Number which defines the sort order among tram types. If this entry is not defined, it gets assigned sort order n*10+7 for the n-th tramtype.&lt;br /&gt;
|-&lt;br /&gt;
| maintenance_cost&lt;br /&gt;
| 0 ... 255&lt;br /&gt;
| Maintenance cost factor for each piece of tram of this tramtype. Default cost factors are 16 and 24 for RAIL and ELRL, respectively.&lt;br /&gt;
|-&lt;br /&gt;
| alternative_tramtype_list&lt;br /&gt;
| list of tramtype labels&lt;br /&gt;
| List of tram types which this tram type will act as fallback for, if the corresponding tram type is not defined separately&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Sort order===&lt;br /&gt;
&lt;br /&gt;
The sort_order influences the sort order of the drop down lists with tram types. Default values are as follows:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;t&amp;quot;&lt;br /&gt;
! Value&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| 07&lt;br /&gt;
| normal tram&lt;br /&gt;
|-&lt;br /&gt;
| 17&lt;br /&gt;
| electrified tram&lt;br /&gt;
|-&lt;br /&gt;
| n7&lt;br /&gt;
| tramtype #n&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Thus the tram type that (internally) gets index 8 will get a default value of 87. These defaults are to keep the ordering when this property is not supported as they were.&lt;br /&gt;
&lt;br /&gt;
==Tramtype variables==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;t&amp;quot;&lt;br /&gt;
! name&lt;br /&gt;
! value range&lt;br /&gt;
! comment&lt;br /&gt;
|-&lt;br /&gt;
| terrain_type&lt;br /&gt;
| TILETYPE_NORMAL, TILETYPE_DESERT, TILETYPE_RAIN_FOREST, TILETYPE_SNOW&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| level_crossing_status&lt;br /&gt;
| LEVEL_CROSSING_CLOSED, LEVEL_CROSSING_OPEN&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| build_date&lt;br /&gt;
| 0 .. 5000000&lt;br /&gt;
| for depots only: build date of the depot in days since 0&lt;br /&gt;
|-&lt;br /&gt;
| town_zone&lt;br /&gt;
| [[NML:List of town zones|town zone]]&lt;br /&gt;
| Town zone of the tile&lt;br /&gt;
|-&lt;br /&gt;
| random_bits&lt;br /&gt;
|&lt;br /&gt;
| 2 pseudo random bits&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Tramtype callbacks==&lt;br /&gt;
&lt;br /&gt;
For tram types a number of callbacks are used to define tram type graphics. Each should refer to a sprite set containing the relevant sprites. Refer to the [[#Example sprites|example sprites]] or the example tramtype grf in the NML repository, for an example on what sprites are needed in what order.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;t&amp;quot;&lt;br /&gt;
! callbacks&lt;br /&gt;
! number of sprites&lt;br /&gt;
! meaning&lt;br /&gt;
|-&lt;br /&gt;
| gui&lt;br /&gt;
| 12&lt;br /&gt;
| 6 gui icons, 6 cursors&lt;br /&gt;
|-&lt;br /&gt;
| track_overlay&amp;lt;ref name=leftout&amp;gt;Either all or none of these sprites should be provided.&amp;lt;/ref&amp;gt;&lt;br /&gt;
| 19&lt;br /&gt;
| 11 track combinations, 4 slopes, and 4 dead ends. These sprites are required&lt;br /&gt;
|-&lt;br /&gt;
| underlay&amp;lt;ref name=leftout /&amp;gt;&lt;br /&gt;
| 19&lt;br /&gt;
| 11 track combinations, 4 slopes, and 4 dead ends. These sprites are required&lt;br /&gt;
|-&lt;br /&gt;
| tunnels&amp;lt;ref name=leftout /&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| 1 sprite for each direction. Sprite is overlay for tram in existing tunnel graphics. The original ground sprite is drawn, then the overlay, then possibly a tram vehicle and the original tunnel head is drawn over the top. This keeps compatibility with different landscape types. Sprite order: SW, NW, NE, SE.&lt;br /&gt;
|-&lt;br /&gt;
| catenary_front&lt;br /&gt;
| 29&lt;br /&gt;
| 11 track combinations, 4 slopes, 4 dead ends, 4 tunnels, 2 bridge middle, 4 bridge ramps&lt;br /&gt;
|-&lt;br /&gt;
| catenary_back&lt;br /&gt;
| 29&lt;br /&gt;
| 11 track combinations, 4 slopes, 4 dead ends, 4 tunnels (unused), 2 bridge middle, 4 bridge ramps&lt;br /&gt;
|-&lt;br /&gt;
| bridge_surfaces&amp;lt;ref name=leftout /&amp;gt;&lt;br /&gt;
| 6&lt;br /&gt;
| 2 bridge middle, 4 bridge ramps&lt;br /&gt;
|-&lt;br /&gt;
| depots&lt;br /&gt;
| 6&lt;br /&gt;
| If not present, the default depot sprites (depending on catenary flag) plus track overlay are drawn.&lt;br /&gt;
If present, the depot sprites are expected to include track overlay graphics.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
|-&lt;br /&gt;
| tunnel_overlay&amp;lt;ref name=tunnel_overlay&amp;gt;Above &amp;#039;all or none&amp;#039; sprites must be supplied, if these sprites are to be used.&amp;lt;/ref&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| If this callback is defined, tunnels for this tramtype will be drawn differently. First, a grass underlay base sprite is drawn, then the &amp;#039;tunnels&amp;#039;-sprite. Next, tram vehicle sprites if applicable and then a grass overlay and finally the sprite from this type (tunnel_overlay). The grass sprites are defined in the base set and do not contain any parts of the tracks or portal, so these have to be fully provided by the tramtype sprites.&lt;br /&gt;
* &amp;lt;code style:darkgreen&amp;gt;getbits(extra_callback_info1, 0, 8)&amp;lt;/code&amp;gt;: 0 for normal tunnels, without any extra features (like tracks above). All other values are reserved for future extensions.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
Note that there is no &amp;quot;default graphics&amp;quot; callback.&lt;br /&gt;
&lt;br /&gt;
===Example sprites===&lt;br /&gt;
==== gui ====&lt;br /&gt;
&lt;br /&gt;
[[File:Nrt_gui.png]]&lt;br /&gt;
&lt;br /&gt;
==== underlay ====&lt;br /&gt;
&lt;br /&gt;
[[File:Nrt_underlay.png]]&lt;br /&gt;
&lt;br /&gt;
==== overlay ====&lt;br /&gt;
&lt;br /&gt;
[[File:Nrt_overlay.png]]&lt;br /&gt;
&lt;br /&gt;
==== catenary_front ====&lt;br /&gt;
&lt;br /&gt;
[[File:Nrt_catenary_front.png]]&lt;br /&gt;
&lt;br /&gt;
==== catenary_back ====&lt;br /&gt;
&lt;br /&gt;
[[File:Nrt_catenary_back.png]]&lt;br /&gt;
&lt;br /&gt;
==== depots ====&lt;br /&gt;
&lt;br /&gt;
[[File:Nrt_depot.png]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&lt;br /&gt;
|-&lt;br /&gt;
!Sprite Number&lt;br /&gt;
!Usage&lt;br /&gt;
|-&lt;br /&gt;
|0&lt;br /&gt;
| &amp;amp;nbsp; &amp;amp;nbsp;NE wall for SE-entry depot.&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| &amp;amp;nbsp; &amp;amp;nbsp;Depot building for SE-entry depot.&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| &amp;amp;nbsp; &amp;amp;nbsp;NW wall for SW-entry depot.&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| &amp;amp;nbsp; &amp;amp;nbsp;Depot building for SW-entry depot.&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| &amp;amp;nbsp; &amp;amp;nbsp;Depot building for NE-entry depot.&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| &amp;amp;nbsp; &amp;amp;nbsp;Depot building for NW-entry depot.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== bridge_surfaces ====&lt;br /&gt;
&lt;br /&gt;
[[File:Nrt_bridge.png]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
==== tunnel_overlay ====&lt;br /&gt;
&lt;br /&gt;
If this callback is defined, tunnels for this tramtype will be drawn differently.&lt;br /&gt;
&lt;br /&gt;
First, a grass underlay base sprite is drawn, then the &amp;#039;tunnels&amp;#039;-sprite. Next, tram vehicle sprites if applicable and then a grass overlay and finally the sprite from this callback. The grass sprites are defined in the base set and do not contain any parts of the tracks or portal, so these have to be fully provided by the tramtype sprites.&lt;br /&gt;
&lt;br /&gt;
Illustration: [[File:TramtypeTunnelExample.png]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example code===&lt;br /&gt;
&lt;br /&gt;
A typical implementation for tramtypes can look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:blue&amp;quot;&amp;gt;&lt;br /&gt;
 item(FEAT_TRAMTYPES, dctram, 0x01) {&lt;br /&gt;
     property {&lt;br /&gt;
         label:                      &amp;quot;DCTM&amp;quot;;&lt;br /&gt;
         name:                       string(STR_DC_TRAM);&lt;br /&gt;
         menu_text:                  string(STR_DC_TRAM);&lt;br /&gt;
         build_window_caption:       string(STR_BUILD_CAPTION);&lt;br /&gt;
         autoreplace_text:           string(STR_AUTOREPLACE);&lt;br /&gt;
         new_engine_text:            string(STR_NEW_ENGINE);&lt;br /&gt;
         powered_tramtype_list:      [&amp;quot;DCTM&amp;quot;,&amp;quot;ELRL&amp;quot;];                          // These trams are compatible with other electric trams&lt;br /&gt;
         tramtype_flags:             bitmask(TRAMTYPE_FLAG_CATENARY);          // These tramways require catenary&lt;br /&gt;
         construction_cost:          24;                                       // Electric tramways are pricey&lt;br /&gt;
         speed_limit:                50 km/h;&lt;br /&gt;
     }&lt;br /&gt;
     graphics {&lt;br /&gt;
         underlay:        ground_switch_underlay;    // defines the tramtrack underlay&lt;br /&gt;
         overlay:         track_overlay_switch;      // defines the tramtrack overlay&lt;br /&gt;
         tunnels:         tunnel_switch;             // defines the track drawn on a tunnel tile&lt;br /&gt;
         depots:          depot_switch;              // defines the depot sprites&lt;br /&gt;
         bridge_surfaces: bridge_terrain_switch;     // defines the overlay drawn over bridges depending on climate&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The switches and graphics blocks are defined in the usual way as described in sections [[NML:Switch|switches]], [[NML:Random switch|random switches]] and [[NML:Graphics|graphics block]] sections.&lt;/div&gt;</summary>
		<author><name>Andrew350</name></author>
	</entry>
</feed>