* 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. */
| 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 | */ |
| 937 | static 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. |
no test coverage detected