## NewGRF Road Stops Addition to NewGRF Specifications in JGR's Patchpack

This document describes the non-standard addition of the NewGRF road stops feature to the Official OpenTTD NewGRF Specifications, as implemented in this patchpack. This feature does not match OpenTTD PR #7955 in a number of key areas, this feature may not necessarily match implementations of NewGRF road stops in other patches, branches, etc. This feature as implemented here MAY also be present in other patchpacks.

See the NewGRF additions document for background information on additions to the NewGRF specifications.

A subset of the functionality listed below is also supported in a fork of NML, see the associated NML road stops and NML additions documents for more details.

NewGRFs which use this feature SHOULD use the feature testing mechanism to check whether the road stop feature and/or feature ID mapping is supported.

NewGRFs which use this feature MUST use the feature ID mapping mechanism to map the non-standard NewGRF road stop feature to a local feature ID.

This feature is indicated by the feature name: road_stops, version 1.
The feature name to use for feature ID mapping is road_stops.
Features/properties/variables which require a higher version will indicate the required version. Unless indicated otherwise these will fall back to doing nothing on versions which do not support them.

Sections:

- Action 0
- Action 2
- Variational Action 2
- Random Action 2
- Action 3
- Erata

### Action 0 - Road Stops

See the Action 0 Specification for background information.

Properties:

Number | Mappable name | Size in bytes | Description
--- | --- | --- | ---
08 | roadstop_class_id | 4 | Class ID
09 | roadstop_stop_type | 1 | Stop type availability
0A | roadstop_stop_name | 2 | Name
0B | roadstop_class_name | 2 | Class name
0C | roadstop_draw_mode | 1 | Draw mode
0D | roadstop_random_trigger_cargoes | 4 | Random trigger cargoes
0E | roadstop_animation_info | 2 | Animation info
0F | roadstop_animation_speed | 1 | Animation speed
10 | roadstop_animation_triggers | 2 | Animation triggers
11 | roadstop_callback_mask | 1 | Callback flags
12 | roadstop_general_flags | 4 | General flags
13 | roadstop_min_bridge_height | 6 | Minimum bridge heights
14 | roadstop_disallowed_bridge_pillars | 6 | Disallowed bridge pillars
15 | roadstop_cost_multipliers | 2 | Cost multipliers
16 | roadstop_height | 1 | Height (for build window)

#### Road stop class ID (08, or mappable property: roadstop_class_id)

This property sets the road stop class ID for this road stop ID.
This property must be used first before any other property for this road stop ID.
Two class names are pre-defined:

Name | Class ID | Meaning
--- | --- | ---
DFLT | 44 46 4C 54 | Default bus and lorry stops
WAYP | 57 41 59 50 | This class is used for road waypoints

All classes except WAYP are used for bus and/or lorry stops.
This functions the same way as station (feature 4) property 08.
The property length is 4 bytes.

#### Road stop type availability (09, or mappable property: roadstop_stop_type)

This property sets the road stop type availability, this is ignored for road stops in the WAYP class.
The property length is 1 byte. The format is:

Value | Meaning
--- | ---
0 | Passenger/bus stop
1 | Freight/lorry stop
2 | Both passenger/bus and freight/lorry stops

The default value is 2 (both bus and lorry stops).

#### Road stop name (0A, or mappable property: roadstop_stop_name)

This property sets the road stop name string ID.
The property length is 2 bytes. This should be a D8xx or DCxx string ID.

#### Road stop class name (0B, or mappable property: roadstop_class_name)

This property sets the road stop class name string ID.
The property length is 2 bytes. This should be a D8xx or DCxx string ID.

#### Road stop draw mode (0C, or mappable property: roadstop_draw_mode)

This property sets the road stop draw mode.
The property length is 1 byte. The format is:

Bit | Value | Meaning
--- | --- | ---
0 | 1 | Bay stops: Draw road type ground sprite
1 | 2 | Drive through stops: Draw road/tram type overlays
2 | 4 | Road waypoints: Draw sprite layout ground sprite on top of the underlying road (by default the sprite layout ground sprite is not used)

The default value is 3 (bits 0 and 1 both set).

#### Road stop random trigger cargoes (0D, or mappable property: roadstop_random_trigger_cargoes)

This property sets the cargo types for random triggers.
This functions the same way as station (feature 4) property 12.
This sets which cargo types should trigger re-randomizing. The cargo types are given as a bitmask of the bits from column 3 (type B) in CargoTypes. If nothing is set (the default), the no random triggers will happen, to conserve CPU time.
With GRF version 7 and above, the interpretation of bits changes. Instead of climate-dependent cargo slot numbers (type B), you have to set the bits of climate-independent cargo ID (type A).
The property length is 4 bytes.

#### Road stop animation info (0E, or mappable property: roadstop_animation_info)

This property sets the cargo types for random triggers.
This functions the same way as station (feature 4) property 16.
The low byte specifies the number of animation frames minus one, so 00 means 1 frame, 01 means 2 frames etc. The maximum number of frames is 256, although you can have some problems if your animation exceeds FD (253) frames. The high byte must be 0 for non-looping animations and 01 for looping animations. Every other value is reserved for future use. In addition, if the whole word contains FFFF, animation is turned off for this station (this is the default value). Since you can't have properties for individual station tiles, this property applies for every tile of the station. If you don't want to animate some tiles, you should check the current position during callback 140 and return FD if the current tile doesn't need to be animated. If you also need animations of different length per tile, you'll have to use callback 141 for that.
The property length is 2 bytes.

#### Road stop animation speed (0F, or mappable property: roadstop_animation_speed)

This property sets the cargo types for random triggers.
This functions the same way as station (feature 4) property 17.
This is the amount of time between switching frames. The default value is 2, which means the switch occurs every 108 milliseconds. Increasing this value by one doubles the wait, i.e. 3 will cause 216 ms delay, while 4 will pause 432 ms, and so on. The minimum is 0, which means the fastest possible animation, changing frames every game tick (27ms). The maximum is 16, which means 1769 seconds (approx. half an hour) delay. Settings above this value may cause strange behaviour.
The property length is 1 byte.

#### Road stop animation triggers (10, or mappable property: roadstop_animation_triggers)

This property sets the cargo types for random triggers.
This functions the same way as station (feature 4) property 18.
This is a bit mask of events that should trigger callback 140, allowing to change the animation state.

Bit | Value | Meaning | Happens on | Var 18
--- | --- | --- | --- | ---
0 | 1 | Road stop is built | newly built tile |
1 | 2 | New cargo arrives at station | all tiles | Bits 8..15 contain the triggering cargo type
2 | 4 | Cargo removed from station | all tiles | Bits 8..15 contain the triggering cargo type
3 | 8 | Road vehicle enters stop (starts loading/unloading) | tile where the vehicle is |
4 | 10 | Road vehicle leaves stop (done loading/unloading) | tile where the vehicle is |
5 | 20 | Road vehicle loads/unloads cargo | tile where the vehicle is |
6 | 40 | Every 250 ticks | all tiles |

For bits 1 and 2: bits 8..15 of var 18 contain the triggering cargo type. If your GRF has a cargo translation table, the cargo type will be an index in that table, or FFh if the cargo isn't in the table. If you don't have a cargo translation table, the cargo type will simply be the climate-dependent cargo type number.

#### Road stop callback flags (11, or mappable property: roadstop_callback_mask)

This property enables callbacks for this road stop type.
The property length is 1 byte. The format is:

Bit | Value | Variable 0C value | Callback
--- | --- | --- | ---
0 | 1 | 13 | Whether to make road stop available in construction window (non-zero callback return) or not (callback returns zero)
1 | 2 | 141 | Decide next animation frame
2 | 4 | 142 | Decide animation speed

Variable 0C value is what variable 0C will be set to, for checking it in the VarAction2 for callbacks.
The default value is 0 (no callbacks enabled).

#### Road stop general flags (12, or mappable property: roadstop_general_flags)

This property sets general flags for this road stop type.
The property length is 4 bytes. The format is:

Bit | Value | Meaning
--- | --- | ---
0 | 1 | Callback 141 needs random bits in variable 10
1 | 2 | Do not show one way road overlay sprites, this should only be set if different graphics are provided for the different one-way states using bits 0..1 of variable 50.
2 | 4 | Do not show catenary graphics.This requires road_stops, version 2.
3 | 8 | Only allow drive-through stops (not bay stops).This requires road_stops, version 2.
4 | 10 | Do not automatically build connecting road pieces.This requires road_stops, version 3.
5 | 20 | Only show in the road build menu (not tram).This requires road_stops, version 4.
6 | 40 | Only show in the tram build menu (not road).This requires road_stops, version 4.
7 | 80 | Use custom graphics for disabled road stop views.This requires road_stops, version 8.
8 | 100 | Read the road stop draw mode from variable 0x100, this overrides the roadstop_draw_mode property.This requires road_stops, version 9.

The default value is 0 (no flags enabled).

#### Road stop minimum bridge heights (13, or mappable property: roadstop_min_bridge_height)

This property allows or disallows building bridges over road stops.
The bridge height property defines minimum clearances required for a bridge for each of the 6 views/rotations (or 0 to not allow any bridge). Values are given in height level units (1 level == 8px).
Each height value is 1 byte, the total property length is 6 bytes.

#### Road stop disallowed bridge pillars (14, or mappable property: roadstop_disallowed_bridge_pillars)

This property describes which bridge pillars are not allowed on the road stop tile.
It consists of a set of pillar flags, for each of the 6 road stop views/rotations.
Each set of flags is 1 byte, the total property length is 6 bytes.
Each set of flags has the format described in the bridge_pillar_flags property section.

#### Road stop cost multipliers (15, or mappable property: roadstop_cost_multipliers)

This property sets the build and removal cost multipliers.
The first byte is the build cost multiplier.
The second byte is the removal cost multiplier.
The total property length is 2 bytes.
A value of 16 produces a build or removal cost the same as non-NewGRF road stops.

#### Road stop height (in the build window) (16, or mappable property: roadstop_height)

This property sets the height used to size the road stop build window previews.
The nominal height for the road stop preview is set to at least: 32 + "value of this property" * 8.
This similar to Object variable 16.
The total property length is 1 byte.
This requires road_stops, version 6.

The 6 road stop views/rotations are described below.

Views/rotation | Type | Description
--- | --- | ---
0 | Bay | Facing north-east
1 | Bay | Facing south-east
2 | Bay | Facing south-west
3 | Bay | Facing north-west
4 | Drive-through | X-axis: north-east to south-west
5 | Drive-through | Y-axis: north-west to south-east

### Action 2 - Road Stops

See the Action 2 Specification for background information.

Road stops use the special sprite layout format, the same as Action 2 features: 7 (house), 9 (industry tile), F (object), 11 (airport tile).

### Variational Action 2 - Road Stops

See the Variational Action 2 Specification for background information.

The parent scope for this feature is the road stop's station's town.

Variables:

Number | Mappable name | Description
--- | --- | ---
40 | roadstop_view | View/rotation
41 | roadstop_type | Stop type
42 | roadstop_terrain_type | Terrain type
43 | roadstop_road_type | Road type
44 | roadstop_tram_type | Tram type
45 | roadstop_town_zone | Town zone and Manhattan distance of town
46 | roadstop_town_distance_squared | Square of Euclidean distance of town
47 | roadstop_company_info | Player/company info
48 |  | Bitmask of accepted cargoes (BaseStation)
49 | roadstop_animation_frame | Current animation frame
50 | roadstop_misc_info | Miscellaneous info
60 |  | Amount of cargo waiting (BaseStation)
61 |  | Time since last cargo pickup (BaseStation)
62 |  | Rating of cargo (BaseStation)
63 |  | Time spent on route (BaseStation)
64 |  | Information about last vehicle picking cargo up (BaseStation)
65 |  | Amount of cargo acceptance (BaseStation)
66 | roadstop_animation_frame_nearby_tiles | Animation frame of nearby tile
67 | roadstop_land_info_nearby_tiles | Land info of nearby tiles
68 | roadstop_road_stop_info_nearby_tiles | Road stop info of nearby tiles
| roadstop_road_stop_info_nearby_tiles_v2 | Road stop info of nearby tiles (v2)
69 |  | Information about cargo accepted in the past (BaseStation)
6A | roadstop_road_stop_grfid_nearby_tiles | GRFID of nearby road stop tiles
6B | roadstop_road_info_nearby_tiles | Road info of nearby plain road tiles

#### Road stop view/rotation (40, or mappable variable: roadstop_view)

Bits 0 - 7 have the range 0 - 5, see the 6 road stop views/rotations
The remaining bits are reserved for future use and should be masked.

#### Road stop type (41, or mappable variable: roadstop_type)

Bits 0 - 7 have the values in the table below.

Value | Meaning
--- | ---
0 | Passenger/bus stop
1 | Freight/lorry stop
2 | Road waypoint

The remaining bits are reserved for future use and should be masked.

#### Road stop tile terrain type (42, or mappable variable: roadstop_terrain_type)

This has the same value as bits 0 - 15 of object (feature F) variable 41.

Bit | Meaning
--- | ---
0 - 7 | Terrain type: 0 - Normal 1 - Desert 2 - Rainforest 3 - On or above snowline
8 - 15 | Tile slope This requires road_stops, version 10.

#### Road stop road type (43, or mappable variable: roadstop_road_type)

This has the value of the (translated) roadtype the road stop is built on, or the current roadtype in the build GUI. If the roadtype has no entry in the roadtype translation table of the GRF, this value will be 0xFF. If no translation table is present, the raw value will be returned. Note: only exact matches of roadtypes are reported. If the translation table of the GRF does not contain the exact roadtype 0xFF is returned.
If the tile has no road at all (tram only) 0xFFFFFFFF is returned.

#### Road stop tram type (44, or mappable variable: roadstop_road_type)

This has the value of the (translated) tramtype the road stop is built on, or the current tramtype in the build GUI. If the tramtype has no entry in the tramtype translation table of the GRF, this value will be 0xFF. If no translation table is present, the raw value will be returned. Note: only exact matches of tramtypes are reported. If the translation table of the GRF does not contain the exact tramtype 0xFF is returned.
If the tile has no tram at all (road only) 0xFFFFFFFF is returned.

#### Town zone and Manhattan distance of town (45, or mappable variable: roadstop_town_zone)

The town used is the one associated with the station/waypoint (this is in the station/waypoint name by default).

Bits | Meaning
--- | ---
0 - 15 | Manhattan distance from town
16 - 24 | Town zone

The remaining bits are reserved for future use and should be masked.

#### Square of Euclidean distance of town (46, or mappable variable: roadstop_town_distance_squared)

The town used is the one associated with the station/waypoint (this is in the station/waypoint name by default).

#### Player/company info (47, or mappable variable: roadstop_company_info)

This has the same value as vehicle (features 0 - 3) variable 43.
The company used is the owner of the station/waypoint, not the owner of the underlying road and/or tram.

#### Current animation frame (49, or mappable variable: roadstop_animation_frame)

This has the same value as station (feature 4) variable 4A.

#### Miscellaneous road stop info (50, or mappable variable: roadstop_misc_info)

Bits | Meaning
--- | ---
0 - 1 | One-way road information: 0 - Two-way traffic 1 - West-bound only 2 - East-bound only 3 - No entry
2 - 3 | Inferred one-way road information, from examining the road layout: 0 - Two-way traffic 1 - West-bound only 2 - East-bound only 3 - No entry This requires road_stops, version 8.
4 | 1 if the road stop is being drawn in the build window This requires road_stops, version 9.

The remaining bits are reserved for future use and should be masked.

#### Animation frame of nearby tile (66, or mappable variable: roadstop_animation_frame_nearby_tiles)

This has the same value as station (feature 4) variable 66.

#### Land info of nearby tile (67, or mappable variable: roadstop_land_info_nearby_tiles)

This has the same value as industry tile (feature 9) variable 60.

#### Road stop of nearby tile (68, or mappable variable: roadstop_road_stop_info_nearby_tiles)

This has a similar value to station (feature 4) variable 68.

Bits | Meaning
--- | ---
0 - 7 | If the tile is defined in the current GRF, this is the lower 8 bits of the setID used in the definition. Otherwise, the content is undefined. Note that if this GRF has any road stop setIDs greater than 255, bits 24 - 31 need to be used as well. If the road_stops feature is not tested for, this is the entire setID, clamped to the range 0..255.
8 - 9 | 0 - The tile uses original TTD graphics 1 - The tile is defined in the current GRF 2 - The tile is defined in another GRF
10 | Set if the selected tile belongs to the current station, clear otherwise
11 | Clear if the selected tile has the same view/rotation, set if a different view/rotation
12 - 15 | View/rotation of the selected tile
16 - 19 | 0 - Passenger/bus stop 1 - Freight/lorry stop 2 - Road waypoint
20 | Set if the stop type (passenger/bus, freight/lorry or road waypoint) is the same as the current tile
21 - 22 | One-way road information of the selected tile: 0 - Two-way traffic 1 - North-bound only 2 - South-bound only 3 - No entry
24 - 31 | If the tile is defined in the current GRF, this is the upper 8 bits of the setID used in the definition. Otherwise, the content is undefined. This can be ignored if this GRF does not have any road stop setIDs greater than 255 (does not define more than 256 road stop types). This requires road_stops, version 7. If the road_stops feature is not tested for, this is set to 0.

The remaining bits are reserved for future use and should be masked.

#### Road stop of nearby tile v2 (mappable variable: roadstop_road_stop_info_nearby_tiles_v2)

This has a similar value to 68/roadstop_road_stop_info_nearby_tiles, above.

Bits | Meaning
--- | ---
0 - 15 | If the tile is defined in the current GRF, this is the setID used in the definition. Otherwise, the content is undefined.
16 - 17 | 0 - The tile uses original TTD graphics 1 - The tile is defined in the current GRF 2 - The tile is defined in another GRF
18 | Set if the selected tile belongs to the current station, clear otherwise
19 | Clear if the selected tile has the same view/rotation, set if a different view/rotation
20 - 23 | View/rotation of the selected tile
24 - 27 | 0 - Passenger/bus stop 1 - Freight/lorry stop 2 - Road waypoint
28 | Set if the stop type (passenger/bus, freight/lorry or road waypoint) is the same as the current tile
29 - 30 | One-way road information of the selected tile: 0 - Two-way traffic 1 - North-bound only 2 - South-bound only 3 - No entry

The remaining bits are reserved for future use and should be masked.
This requires road_stops, version 7.

#### GRFID of nearby road stop tile (6A, or mappable variable: roadstop_road_stop_grfid_nearby_tiles)

This has the same value as station (feature 4) variable 6A.

#### Road info of nearby plain road tiles (6B, or mappable variable: roadstop_road_info_nearby_tiles)

The returned value is 0xFFFFFFFF if the selected tile isn't a plain road tile.

Bits | Value | Meaning
--- | --- | ---
0 | 01 | North-west road piece is present
1 | 02 | South-west road piece is present
2 | 04 | South-east road piece is present
3 | 08 | North-east road piece is present
4 | 10 | North-west tram piece is present
5 | 20 | South-west tram piece is present
6 | 40 | South-east tram piece is present
7 | 80 | North-east tram piece is present
8 - 15 |  | Road piece and slope: (Same order as road sprites). 0 - 18: As above 0xFF: No road present
16 - 23 |  | Tram piece and slope: (Same order as road sprites). 0 - 18: As above 0xFF: No tram present

The remaining bits are reserved for future use and should be masked.
This requires road_stops, version 5.

### Random Action 2 - Road Stops

See the Random Action 2 Specification for background information.

Road stops have 16+8 random bits. Bits 0 to 15 are a property of the station as a whole, and bits 16 to 23 are different for each tile.

Bit | Value | Trigger
--- | --- | ---
0 | 01 | New cargo waiting
1 | 02 | No more cargo
2 | 04 | Road vehicle arrives (starts unloading/loading)
3 | 08 | Road vehicle leaves (done unloading & loading)
4 | 10 | Road vehicle loads or unloads cargo

Note that a road vehicle arrives trigger does not imply that the stop was previously empty, and a road vehicle leaves trigger does not imply that the stop is now empty.

Also note that none of the above triggers will actually trigger unless property 0D/roadstop_random_trigger_cargoes has at least one bit set.
Triggers 01 will be triggered for any of the cargo types set in property 0D/roadstop_random_trigger_cargoes, but trigger 02 will only be triggered if all of those cargo types have no more cargo waiting.
Triggers 04 and 08 are triggered no matter what cargo types the train transports, as long as property 0D/roadstop_random_trigger_cargoes is not zero.
Triggers 04, 08, and 10 only affect the tile on which they occur, as well as the random bits of the station, but not other tiles.

### Action 3 - Road Stops

See the Action 3 Specification for background information.

Road stops have the same Action 3 cargo-type values as feature 4 (station).

In feature name road_stops version 7 and later, the Action 3 ID field is an extended byte; GRFs may define more than 255 road stop types.
In versions 1 to 6 (inclusive), only 255 road stop types may be defined per GRF, and the extended byte format may not be used.

In vanilla OpenTTD 14.0 and later, the extended byte format may always be used.

### Erata

In feature name road_stops versions 1 to 5 (inclusive), mapped Action 0 properties which are unknown and should be ignored, instead generate an error on use.