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

Function AdvanceSignalAutoFill

src/rail_cmd.cpp:1196–1238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1194}
1195
1196static bool AdvanceSignalAutoFill(TileIndex &tile, Trackdir &trackdir, bool remove)
1197{
1198 /* We only process starting tiles of tunnels or bridges so jump to the other end before moving further. */
1199 if (IsTileType(tile, MP_TUNNELBRIDGE)) tile = GetOtherTunnelBridgeEnd(tile);
1200
1201 tile = AddTileIndexDiffCWrap(tile, _trackdelta[trackdir]);
1202 if (tile == INVALID_TILE) return false;
1203
1204 /* Check for track bits on the new tile */
1205 TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0));
1206
1207 if (TracksOverlap(TrackdirBitsToTrackBits(trackdirbits))) return false;
1208 trackdirbits &= TrackdirReachesTrackdirs(trackdir);
1209
1210 /* No track bits, must stop */
1211 if (trackdirbits == TRACKDIR_BIT_NONE) return false;
1212
1213 /* Get the first track dir */
1214 trackdir = RemoveFirstTrackdir(&trackdirbits);
1215
1216 /* Any left? It's a junction so we stop */
1217 if (trackdirbits != TRACKDIR_BIT_NONE) return false;
1218
1219 switch (GetTileType(tile)) {
1220 case MP_RAILWAY:
1221 if (IsRailDepot(tile)) return false;
1222 if (!remove && HasSignalOnTrack(tile, TrackdirToTrack(trackdir))) return false;
1223 break;
1224
1225 case MP_ROAD:
1226 if (!IsLevelCrossing(tile)) return false;
1227 break;
1228
1229 case MP_TUNNELBRIDGE: {
1230 if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false;
1231 if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false;
1232 break;
1233 }
1234
1235 default: return false;
1236 }
1237 return true;
1238}
1239
1240/**
1241 * Build many signals by dragging; AutoSignals

Callers 1

CmdSignalTrackHelperFunction · 0.85

Calls 15

IsTileTypeFunction · 0.85
GetOtherTunnelBridgeEndFunction · 0.85
AddTileIndexDiffCWrapFunction · 0.85
GetTileTrackStatusFunction · 0.85
TracksOverlapFunction · 0.85
TrackdirBitsToTrackBitsFunction · 0.85
TrackdirReachesTrackdirsFunction · 0.85
RemoveFirstTrackdirFunction · 0.85
GetTileTypeFunction · 0.85
IsRailDepotFunction · 0.85
HasSignalOnTrackFunction · 0.85

Tested by

no test coverage detected