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

Function IsNeighbourRoadTile

src/town_cmd.cpp:1043–1067  ·  view source on GitHub ↗

* Check for parallel road inside a given distance. * Assuming a road from (tile - TileOffsByDiagDir(dir)) to tile, * is there a parallel road left or right of it within distance dist_multi? * * @param tile The current tile. * @param dir The target direction. * @param dist_multi The distance multiplier. * @return true if there is a parallel road. */

Source from the content-addressed store, hash-verified

1041 * @return true if there is a parallel road.
1042 */
1043static bool IsNeighbourRoadTile(TileIndex tile, const DiagDirection dir, uint dist_multi)
1044{
1045 if (!IsValidTile(tile)) return false;
1046
1047 /* Lookup table for the used diff values */
1048 const TileIndexDiff tid_lt[3] = {
1049 TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT)),
1050 TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT)),
1051 TileOffsByDiagDir(ReverseDiagDir(dir)),
1052 };
1053
1054 dist_multi = (dist_multi + 1) * 4;
1055 for (uint pos = 4; pos < dist_multi; pos++) {
1056 /* Go (pos / 4) tiles to the left or the right */
1057 TileIndexDiff cur = tid_lt[(pos & 1) ? 0 : 1] * (pos / 4);
1058
1059 /* Use the current tile as origin, or go one tile backwards */
1060 if (pos & 2) cur += tid_lt[2];
1061
1062 /* Test for roadbit parallel to dir and facing towards the middle axis */
1063 if (IsValidTile(tile + cur) &&
1064 GetTownRoadBits(TileAdd(tile, cur)) & DiagDirToRoadBits((pos & 2) ? dir : ReverseDiagDir(dir))) return true;
1065 }
1066 return false;
1067}
1068
1069/**
1070 * Check if a Road is allowed on a given tile.

Callers 1

IsRoadAllowedHereFunction · 0.85

Calls 7

IsValidTileFunction · 0.85
TileOffsByDiagDirFunction · 0.85
ChangeDiagDirFunction · 0.85
ReverseDiagDirFunction · 0.85
GetTownRoadBitsFunction · 0.85
DiagDirToRoadBitsFunction · 0.85
TileAddFunction · 0.70

Tested by

no test coverage detected