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

Function RoadTypesAllowHouseHere

src/town_cmd.cpp:1466–1486  ·  view source on GitHub ↗

* Checks whether at least one surrounding road allows to build a house here. * * @param t The tile where the house will be built. * @return true if at least one surrounding roadtype allows building houses here. */

Source from the content-addressed store, hash-verified

1464 * @return true if at least one surrounding roadtype allows building houses here.
1465 */
1466static inline bool RoadTypesAllowHouseHere(TileIndex t)
1467{
1468 static const TileIndexDiffC tiles[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} };
1469 bool allow = false;
1470
1471 for (const auto &ptr : tiles) {
1472 TileIndex cur_tile = t + ToTileIndexDiff(ptr);
1473 if (!IsValidTile(cur_tile)) continue;
1474
1475 if (!(IsTileType(cur_tile, MP_ROAD) || IsAnyRoadStopTile(cur_tile))) continue;
1476 allow = true;
1477
1478 RoadType road_rt = GetRoadTypeRoad(cur_tile);
1479 if (road_rt != INVALID_ROADTYPE && !GetRoadTypeInfo(road_rt)->flags.Test(RoadTypeFlag::NoHouses)) return true;
1480 }
1481
1482 /* If no road was found surrounding the tile we can allow building the house since there is
1483 * nothing which forbids it, if a road was found but the execution reached this point, then
1484 * all the found roads don't allow houses to be built */
1485 return !allow;
1486}
1487
1488/** Test if town can grow road onto a specific tile.
1489 * @param tile Tile to build upon.

Callers 2

GrowTownInTileFunction · 0.85
CanBuildHouseHereFunction · 0.85

Calls 7

ToTileIndexDiffFunction · 0.85
IsValidTileFunction · 0.85
IsTileTypeFunction · 0.85
IsAnyRoadStopTileFunction · 0.85
GetRoadTypeRoadFunction · 0.85
GetRoadTypeInfoFunction · 0.85
TestMethod · 0.80

Tested by

no test coverage detected