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

Function CanConnectToRoad

src/road_cmd.cpp:937–949  ·  view source on GitHub ↗

* Checks whether a road or tram connection can be found when building a new road or tram. * @param tile Tile at which the road being built will end. * @param rt Roadtype of the road being built. * @param dir Direction that the road is following. * @return True if the next tile at dir direction is suitable for being connected directly by a second roadbit at the end of the road being built. */

Source from the content-addressed store, hash-verified

935 * @return True if the next tile at dir direction is suitable for being connected directly by a second roadbit at the end of the road being built.
936 */
937static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir)
938{
939 tile += TileOffsByDiagDir(dir);
940 if (!IsValidTile(tile) || !MayHaveRoad(tile)) return false;
941
942 RoadTramType rtt = GetRoadTramType(rt);
943 RoadType existing = GetRoadType(tile, rtt);
944 if (existing == INVALID_ROADTYPE) return false;
945 if (!HasPowerOnRoad(existing, rt) && !HasPowerOnRoad(rt, existing)) return false;
946
947 RoadBits bits = GetAnyRoadBits(tile, rtt, false);
948 return (bits & DiagDirToRoadBits(ReverseDiagDir(dir))) != 0;
949}
950
951/**
952 * Build a long piece of road.

Callers 1

CmdBuildLongRoadFunction · 0.85

Calls 9

TileOffsByDiagDirFunction · 0.85
IsValidTileFunction · 0.85
MayHaveRoadFunction · 0.85
GetRoadTramTypeFunction · 0.85
GetRoadTypeFunction · 0.85
HasPowerOnRoadFunction · 0.85
GetAnyRoadBitsFunction · 0.85
DiagDirToRoadBitsFunction · 0.85
ReverseDiagDirFunction · 0.85

Tested by

no test coverage detected