FS#1753 - Incorrect operation of varaction 2 var.68 for stations

Attached to Project: OpenTTD
Opened by Martin (mart3p) - Thursday, 07 February 2008, 16:45 GMT
Type Bug
Category NewGRF → NewStations
Status Closed
Assigned To No-one
Operating System All
Severity Medium
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


There is a problem with variational action 2 var. 68 for stations. The attached test grf and the screenshot of its use in both TTDPatch and OpenTTD, demonstrate the problem. The screenshot was taken from 0.6.0-beta3 but I also tested with r11838 and it is the same.

The test grf is intended to display a red line on the edge of a platform if there is another platform alongside. This should end up with a pair of red lines between adjacent platforms. As the screenshot shows, this works correctly in TTDPatch but fails in OpenTTD.

The problem seems to be that the x and y components of the tile offset (the parameter for var. 68) are reversed. The grf spec. says "The high nibble contains the amount to move sideways (between platforms), the low one is the amount to move along the platform. Negative offsets move northwards, positive ones southwards." So, for a platform on the X-axis, this means the high nibble should be the Y offset and the low nibble the X offset.

The code from newgrf_commons.cpp:

TileIndex GetNearbyTile(byte parameter, TileIndex tile)
int8 x = GB(parameter, 0, 4);
int8 y = GB(parameter, 4, 4);
/* Swap width and height depending on axis for railway stations */
if (IsRailwayStationTile(tile) && GetRailStationAxis(tile) == AXIS_X) Swap(x, y);

So x is set to the low nibble, y to the high nibble, but then for a station on the X-axis, they are swapped. This swap should occur when the station is on the Y-axis.

It seems this has been incorrect since support for var. 68 for stations was added at r11679.
This task depends upon

Closed by  Peter Nelson (peter1138)
Monday, 11 February 2008, 11:21 GMT
Reason for closing:  Fixed
Additional comments about closing:  Fixed in r12108