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

Function CleanUpRoadBits

src/road.cpp:59–115  ·  view source on GitHub ↗

* Clean up unnecessary RoadBits of a planned tile. * @param tile current tile * @param org_rb planned RoadBits * @return optimised RoadBits */

Source from the content-addressed store, hash-verified

57 * @return optimised RoadBits
58 */
59RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
60{
61 if (!IsValidTile(tile)) return ROAD_NONE;
62 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
63 const TileIndex neighbour_tile = TileAddByDiagDir(tile, dir);
64
65 /* Get the Roadbit pointing to the neighbour_tile */
66 const RoadBits target_rb = DiagDirToRoadBits(dir);
67
68 /* If the roadbit is in the current plan */
69 if (org_rb & target_rb) {
70 bool connective = false;
71 const RoadBits mirrored_rb = MirrorRoadBits(target_rb);
72
73 if (IsValidTile(neighbour_tile)) {
74 switch (GetTileType(neighbour_tile)) {
75 /* Always connective ones */
76 case MP_CLEAR: case MP_TREES:
77 connective = true;
78 break;
79
80 /* The conditionally connective ones */
81 case MP_TUNNELBRIDGE:
82 case MP_STATION:
83 case MP_ROAD:
84 if (IsNormalRoadTile(neighbour_tile)) {
85 /* Always connective */
86 connective = true;
87 } else {
88 const RoadBits neighbour_rb = GetAnyRoadBits(neighbour_tile, RTT_ROAD) | GetAnyRoadBits(neighbour_tile, RTT_TRAM);
89
90 /* Accept only connective tiles */
91 connective = (neighbour_rb & mirrored_rb) != ROAD_NONE;
92 }
93 break;
94
95 case MP_RAILWAY:
96 connective = IsPossibleCrossing(neighbour_tile, DiagDirToAxis(dir));
97 break;
98
99 case MP_WATER:
100 /* Check for real water tile */
101 connective = !IsWater(neighbour_tile);
102 break;
103
104 /* The definitely not connective ones */
105 default: break;
106 }
107 }
108
109 /* If the neighbour tile is inconnective, remove the planned road connection to it */
110 if (!connective) org_rb ^= target_rb;
111 }
112 }
113
114 return org_rb;
115}
116

Callers 2

GrowTownInTileFunction · 0.85
TileLoop_RoadFunction · 0.85

Calls 10

IsValidTileFunction · 0.85
TileAddByDiagDirFunction · 0.85
DiagDirToRoadBitsFunction · 0.85
MirrorRoadBitsFunction · 0.85
GetTileTypeFunction · 0.85
IsNormalRoadTileFunction · 0.85
GetAnyRoadBitsFunction · 0.85
IsPossibleCrossingFunction · 0.85
DiagDirToAxisFunction · 0.85
IsWaterFunction · 0.85

Tested by

no test coverage detected