* Clean up unnecessary RoadBits of a planned tile. * @param tile current tile * @param org_rb planned RoadBits * @return optimised RoadBits */
| 57 | * @return optimised RoadBits |
| 58 | */ |
| 59 | RoadBits 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 |
no test coverage detected