MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetRailContinuationInfo

Function GetRailContinuationInfo

src/newgrf_station.cpp:197–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196
197static uint32_t GetRailContinuationInfo(TileIndex tile)
198{
199 /* Tile offsets and exit dirs for X axis */
200 static const Direction x_dir[8] = { DIR_SW, DIR_NE, DIR_SE, DIR_NW, DIR_S, DIR_E, DIR_W, DIR_N };
201 static const DiagDirection x_exits[8] = { DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SW, DIAGDIR_NE };
202
203 /* Tile offsets and exit dirs for Y axis */
204 static const Direction y_dir[8] = { DIR_SE, DIR_NW, DIR_SW, DIR_NE, DIR_S, DIR_W, DIR_E, DIR_N };
205 static const DiagDirection y_exits[8] = { DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_NW };
206
207 Axis axis = GetRailStationAxis(tile);
208
209 /* Choose appropriate lookup table to use */
210 const Direction *dir = axis == AXIS_X ? x_dir : y_dir;
211 const DiagDirection *diagdir = axis == AXIS_X ? x_exits : y_exits;
212
213 uint32_t res = 0;
214 uint i;
215
216 for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) {
217 TileIndex neighbour_tile = tile + TileOffsByDir(*dir);
218 TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(neighbour_tile, TRANSPORT_RAIL, 0));
219 if (trackbits != TRACK_BIT_NONE) {
220 /* If there is any track on the tile, set the bit in the second byte */
221 SetBit(res, i + 8);
222
223 /* With tunnels and bridges the tile has tracks, but they are not necessarily connected
224 * with the next tile because the ramp is not going in the right direction. */
225 if (IsTileType(neighbour_tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(neighbour_tile) != *diagdir) {
226 continue;
227 }
228
229 /* If any track reaches our exit direction, set the bit in the lower byte */
230 if (trackbits & DiagdirReachesTracks(*diagdir)) SetBit(res, i);
231 }
232 }
233
234 return res;
235}
236
237
238/* Station Resolver Functions */

Callers 1

GetVariableMethod · 0.85

Calls 8

GetRailStationAxisFunction · 0.85
TileOffsByDirFunction · 0.85
TrackStatusToTrackBitsFunction · 0.85
GetTileTrackStatusFunction · 0.85
SetBitFunction · 0.85
IsTileTypeFunction · 0.85
GetTunnelBridgeDirectionFunction · 0.85
DiagdirReachesTracksFunction · 0.85

Tested by

no test coverage detected