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

Function CanFollowRoad

src/town_cmd.cpp:1751–1785  ·  view source on GitHub ↗

* Checks whether a road can be followed or is a dead end, that can not be extended to the next tile. * This only checks trivial but often cases. * @param tile Start tile for road. * @param dir Direction for road to follow or build. * @return true If road is or can be connected in the specified direction. */

Source from the content-addressed store, hash-verified

1749 * @return true If road is or can be connected in the specified direction.
1750 */
1751static bool CanFollowRoad(TileIndex tile, DiagDirection dir, TownExpandModes modes)
1752{
1753 TileIndex target_tile = tile + TileOffsByDiagDir(dir);
1754 if (!IsValidTile(target_tile)) return false;
1755 if (HasTileWaterGround(target_tile)) return false;
1756
1757 RoadBits target_rb = GetTownRoadBits(target_tile);
1758 if (TownAllowedToBuildRoads(modes)) {
1759 /* Check whether a road connection exists or can be build. */
1760 switch (GetTileType(target_tile)) {
1761 case MP_ROAD:
1762 return target_rb != ROAD_NONE;
1763
1764 case MP_STATION:
1765 return IsDriveThroughStopTile(target_tile);
1766
1767 case MP_TUNNELBRIDGE:
1768 return GetTunnelBridgeTransportType(target_tile) == TRANSPORT_ROAD;
1769
1770 case MP_HOUSE:
1771 case MP_INDUSTRY:
1772 case MP_OBJECT:
1773 return false;
1774
1775 default:
1776 /* Checked for void and water earlier */
1777 return true;
1778 }
1779 } else {
1780 /* Check whether a road connection already exists,
1781 * and it leads somewhere else. */
1782 RoadBits back_rb = DiagDirToRoadBits(ReverseDiagDir(dir));
1783 return (target_rb & back_rb) != 0 && (target_rb & ~back_rb) != 0;
1784 }
1785}
1786
1787/**
1788 * Try to grow a town at a given road tile.

Callers 1

GrowTownAtRoadFunction · 0.85

Calls 10

TileOffsByDiagDirFunction · 0.85
IsValidTileFunction · 0.85
HasTileWaterGroundFunction · 0.85
GetTownRoadBitsFunction · 0.85
TownAllowedToBuildRoadsFunction · 0.85
GetTileTypeFunction · 0.85
IsDriveThroughStopTileFunction · 0.85
DiagDirToRoadBitsFunction · 0.85
ReverseDiagDirFunction · 0.85

Tested by

no test coverage detected