The m4nfo User manual and Technical Report

Road and Tram types

Defining properties for and handling of road and tram types

Introduction

The code for road and tram types consists of three parts:

The definition sets the feature properties of the road/tram type like its label, related texts, speedlimit, etc. Please note that a road/tram type definition may only occur after a prior grfinit() function call for the newGRF file.

The road/tram type's performance functions are used to group sets of graphics sprites from a previous spriteblock(), or to evaluate game-intrinsic variables, and make both of them accessible to the road/tram type's activation function.

The road/tram type activation instantiates the road/tram type by finally assigning graphics sets to a particular road/tram type element (icon, road/tram underlay, tunnel, catenary, ...). This is done by supplying a block of special functions handling references and road/tram type elements to the road/tram type's activation. See below.

Functions

FunctionMeaning
defineroadtype/definetramtype(<Label>, <block>)Road/tram type definition
makeroadtype/maketramtype(<Label>, <block>)Road/tram type activation

Description

defineroadtype/definetramtype(<Label>, <block>)

This function defines a road/tram type. Its parameters are the road/tram type's label and a block of property-defining functions, where the relative position of the property functions is irrelevant.

Please note that the label has to be quoted like this: {HWAY}.

Road/tram type IDs are newGRF local, with an ID to label mapping. Therefore, to modify an existing road/tram type, specify its label in defineroadtype/definetramtype(). To create a new road/tram type, again just specify its label in defineroadtype/definetramtype(). If a label clashes with another newGRF, then one newGRF will end up modifying the properties instead of creating a new road/tram type. At the time being, there are 63 road/track IDs available (0 .. 62).

Reserved labels for default road/tram types are: ROAD (default road), ELRD (electrified road), RAIL (default tram), ELRL (electrified tram).

Example (defining new road type 'HWAY'):
deftxt(rt_tool,
	US, "Motorway construction",
	UK, "Motorway construction",
	D, "Autobahnbau",
	F, UTF8 "Construction autoroutière",
	E, UTF8 "ConstruccĂ­on de carreteras",
)

...

defineroadtype({HWAY},
	toolbartext(rt_tool)
	menutext(rt_menu)
	vehwindowtext(rt_window)
	autoreplacetext(rt_autoreplace)
	newenginetext(rt_engine)
	powered_list({"ROAD"})
	roadtypeflags(RT_HOUS)
	costfactor(100)
	speedlimit(130 km/h)
	mapcolour(170)
)

makeroadtype/maketramtype(<Label>, <block>)

This function activates a previously defined road/tram type. Its parameters are the road/tram type's label and a block of special road/tram type feature-associated functions:

FunctionMeaning
link(<ref()>, <road/tram_type_element>)Linking a chain of graphics or variable dependencies to a specific road/tram type element
default(<ref()>)Default chain to use with this road/tram type

Road/tram type elements assign certain types of graphics defined by their associated chains:

Road/tram type elementSprite typeNum spritesUsage
RT_ICONIcons and cursors[*]124 road/tram directions, autoroad, depot, convert road/tram. First all icons, then all cursors
RT_OLAYRoad/tram track overlays [*]1911 combinations, 4 slope pieces, and 4 dead ends. Sprites should contain only the the road/tram track, with no landscape
RT_ULAYUnderlay[*]19same as RT_OLAY
RT_WIRECatenary wire2911 track combinations, 4 slopes, 4 dead ends, 4 tunnels, 2 middle bridge, and 4 bridge ramps
RT_PYLNCatenary pylons29same as above, only tunnels unused
RT_BRDGBridge surfaces[*]62 middle bridge, and 4 bridge ramps
RT_DEPODepots62 sprites for each southern view, 1 sprite for each northern view, following the original layout for depot sprites
RT_STOPRoad stop4overlays for drive-in road stops

[*] These sprites must be provided, the others may be left out if not needed.

Depot sprites:

Sprite numberUsage
0NE wall for SE-entry depot
1Depot building for SE-entry
2NW wall for SW-entry depot
3Depot building for SW-entry
4Depot building for NE-entry
5Depot building for NW-entry

Examples

makeroadtype(HWAY,
	link(ref(7), RT_ICON)  // icons and cursors
	link(ref(11), RT_OLAY) // track overlays for junctions and PBS
	link(ref(2), RT_ULAY)  // track underlays
	link(ref(4), RT_BRDG)  // bridge surfaces
	link(ref(8), RT_DEPO)  // depot sprites
	link(ref(10), RT_PYLN) // catenary pylons
	link(ref(9), RT_WIRE)  // catenary wires
	default(cbfail())      // s.b.
)

The default would be used for road/tram type callbacks. However, since there are currently no callbacks for road/tram types it should always result in a callback failure.