=== src/town_cmd.cpp ================================================================== --- src/town_cmd.cpp (/trunk) (revision 272) +++ src/town_cmd.cpp (/branch/new_town) (revision 272) @@ -874,8 +833,6 @@ { RoadBits rcmd; TileIndex tmptile; - DiagDirection i; - int j; TileIndex tile = *tile_ptr; TILE_ASSERT(tile); @@ -1045,18 +990,19 @@ /* Return if a water tile */ if (IsClearWaterTile(tile)) return; - /* Determine direction of slope, - * and build a road if not a special slope. */ - switch (GetTileSlope(tile, NULL)) { - case SLOPE_SW: i = DIAGDIR_NE; break; - case SLOPE_SE: i = DIAGDIR_NW; break; - case SLOPE_NW: i = DIAGDIR_SE; break; - case SLOPE_NE: i = DIAGDIR_SW; break; + DiagDirection bridge_dir; + rcmd = CleanUpRoadBits(tile, rcmd); + switch (rcmd) { + case ROAD_NONE: return; break; ///< If there are no more RoadBits further actions are needless. + + /* Determine direction of slope, + * and build a road if not a special slope. */ + case ROAD_NW: bridge_dir = DIAGDIR_SE; break; + case ROAD_SW: bridge_dir = DIAGDIR_NE; break; + case ROAD_SE: bridge_dir = DIAGDIR_NW; break; + case ROAD_NE: bridge_dir = DIAGDIR_SW; break; + default: build_road_and_exit: - rcmd = CleanUpRoadBits(tile, rcmd); - /* If there are no more Roadbits further stuff is unneeded */ - if (rcmd == ROAD_NONE) return; - if (CmdSucceeded(DoCommand(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) { @@ -1061,28 +1011,22 @@ return; } - /* Check if the bridge is in the right direction */ - if ((rcmd == ROAD_X && (i == DIAGDIR_NW || i == DIAGDIR_SE)) || - (rcmd == ROAD_Y && (i == DIAGDIR_NE || i == DIAGDIR_SW))) { - goto build_road_and_exit; - } + /* Don't build bridges on flat slopes */ + if (GetTileSlope(tile, NULL) == SLOPE_FLAT) goto build_road_and_exit; + /* Get the end of the bridge. */ + int dist = 0; tmptile = tile; - - /* Now it contains the direction of the slope */ - j = -11; // max 11 tile long bridges do { - if (++j == 0) - goto build_road_and_exit; - tmptile = TILE_MASK(tmptile + TileOffsByDiagDir(i)); + if (++dist >= 11) return; ///< max 11 tile long bridges + tmptile = TILE_MASK(tmptile + TileOffsByDiagDir(bridge_dir)); } while (IsClearWaterTile(tmptile)); - /* no water tiles in between? */ - if (j == -10) - goto build_road_and_exit; + /* No water tiles in between? */ + if (dist == 1) goto build_road_and_exit; /* Quit if it selecting an appropiate bridge type fails a large number of times. */ - j = 22; + dist = 22; { int32 bridge_len = GetBridgeLength(tile, tmptile); do { @@ -1094,7 +1038,7 @@ /* obviously, if building any bridge would fail, there is no need to try other bridge-types */ return; } - } while (--j != 0); + } while (--dist != 0); } }