* Checks if a town road can be continued into the next tile. * Road vehicle stations, bridges, and tunnels are fine, as long as they are facing the right direction. * * @param t The current town * @param tile The tile where the road would be built * @param road_dir The direction of the road * @return true if the road can be continued, else false */
| 1264 | * @return true if the road can be continued, else false |
| 1265 | */ |
| 1266 | static bool CanRoadContinueIntoNextTile(const Town *t, const TileIndex tile, const DiagDirection road_dir) |
| 1267 | { |
| 1268 | const TileIndexDiff delta = TileOffsByDiagDir(road_dir); // +1 tile in the direction of the road |
| 1269 | TileIndex next_tile = tile + delta; // The tile beyond which must be connectable to the target tile |
| 1270 | RoadBits rcmd = DiagDirToRoadBits(ReverseDiagDir(road_dir)); |
| 1271 | RoadType rt = GetTownRoadType(); |
| 1272 | |
| 1273 | /* Before we try anything, make sure the tile is on the map and not the void. */ |
| 1274 | if (!IsValidTile(next_tile)) return false; |
| 1275 | |
| 1276 | /* If the next tile is a bridge or tunnel, allow if it's continuing in the same direction. */ |
| 1277 | if (IsTileType(next_tile, MP_TUNNELBRIDGE)) { |
| 1278 | return GetTunnelBridgeTransportType(next_tile) == TRANSPORT_ROAD && GetTunnelBridgeDirection(next_tile) == road_dir; |
| 1279 | } |
| 1280 | |
| 1281 | /* If the next tile is a station, allow if it's a road station facing the proper direction. Otherwise return false. */ |
| 1282 | if (IsTileType(next_tile, MP_STATION)) { |
| 1283 | /* If the next tile is a road station, allow if it can be entered by the new tunnel/bridge, otherwise disallow. */ |
| 1284 | if (IsDriveThroughStopTile(next_tile)) return GetDriveThroughStopAxis(next_tile) == DiagDirToAxis(road_dir); |
| 1285 | if (IsBayRoadStopTile(next_tile)) return GetBayRoadStopDir(next_tile) == ReverseDiagDir(road_dir); |
| 1286 | return false; |
| 1287 | } |
| 1288 | |
| 1289 | /* If the next tile is a road depot, allow if it's facing the right way. */ |
| 1290 | if (IsTileType(next_tile, MP_ROAD)) { |
| 1291 | return IsRoadDepot(next_tile) && GetRoadDepotDirection(next_tile) == ReverseDiagDir(road_dir); |
| 1292 | } |
| 1293 | |
| 1294 | /* If the next tile is a railroad track, check if towns are allowed to build level crossings. |
| 1295 | * If level crossing are not allowed, reject the construction. Else allow DoCommand to determine if the rail track is buildable. */ |
| 1296 | if (IsTileType(next_tile, MP_RAILWAY) && !_settings_game.economy.allow_town_level_crossings) return false; |
| 1297 | |
| 1298 | /* If a road tile can be built, the construction is allowed. */ |
| 1299 | return Command<CMD_BUILD_ROAD>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, next_tile, rcmd, rt, DRD_NONE, t->index).Succeeded(); |
| 1300 | } |
| 1301 | |
| 1302 | /** |
| 1303 | * Grows the town with a bridge. |
no test coverage detected