summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-09-19 18:15:59 +0000
committerrubidium <rubidium@openttd.org>2007-09-19 18:15:59 +0000
commit1e7df4fb91c591903299c6785a4d34274f952eeb (patch)
tree13a06b1e987185a134a8dc385af565d4cb968122
parente9f9aa3d1cfa38ea470fd2b18ac7488c5421e6b1 (diff)
downloadopenttd-1e7df4fb91c591903299c6785a4d34274f952eeb.tar.xz
(svn r11130) -Fix [FS#1207]: towns build roads that weren't connected to any other road.
-rw-r--r--src/town_cmd.cpp50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index d192e1a28..7649f925a 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -814,32 +814,38 @@ static RoadBits GetTownRoadGridElement(Town* t, TileIndex tile, DiagDirection di
break;
}
- /* Skip slope optimisations */
+ /* Stop if the tile is not a part of the grid lines */
if (rcmd == ROAD_NONE) return rcmd;
- RoadBits rb_template;
- switch (GetTileSlope(tile, NULL)) {
- default: rb_template = ROAD_ALL; break;
- case SLOPE_W: rb_template = ROAD_NW | ROAD_SW; break;
- case SLOPE_SW: rb_template = ROAD_Y | ROAD_SW; break;
- case SLOPE_S: rb_template = ROAD_SE | ROAD_SW; break;
- case SLOPE_SE: rb_template = ROAD_X | ROAD_SE; break;
- case SLOPE_E: rb_template = ROAD_NE | ROAD_SE; break;
- case SLOPE_NE: rb_template = ROAD_Y | ROAD_NE; break;
- case SLOPE_N: rb_template = ROAD_NW | ROAD_NE; break;
- case SLOPE_NW: rb_template = ROAD_X | ROAD_NW; break;
- case SLOPE_STEEP_W:
- case SLOPE_STEEP_S:
- case SLOPE_STEEP_E:
- case SLOPE_STEEP_N:
- rb_template = (dir == DIAGDIR_NE || dir == DIAGDIR_SW) ? ROAD_X : ROAD_Y;
- break;
- }
+ /* Optimise only X-junctions */
+ if (COUNTBITS(rcmd) != 2) {
+ RoadBits rb_template;
+
+ switch (GetTileSlope(tile, NULL)) {
+ default: rb_template = ROAD_ALL; break;
+ case SLOPE_W: rb_template = ROAD_NW | ROAD_SW; break;
+ case SLOPE_SW: rb_template = ROAD_Y | ROAD_SW; break;
+ case SLOPE_S: rb_template = ROAD_SW | ROAD_SE; break;
+ case SLOPE_SE: rb_template = ROAD_X | ROAD_SE; break;
+ case SLOPE_E: rb_template = ROAD_SE | ROAD_NE; break;
+ case SLOPE_NE: rb_template = ROAD_Y | ROAD_NE; break;
+ case SLOPE_N: rb_template = ROAD_NE | ROAD_NW; break;
+ case SLOPE_NW: rb_template = ROAD_X | ROAD_NW; break;
+ case SLOPE_STEEP_W:
+ case SLOPE_STEEP_S:
+ case SLOPE_STEEP_E:
+ case SLOPE_STEEP_N:
+ rb_template = ROAD_NONE;
+ break;
+ }
- /* Check for the right growth dir */
- if (DiagDirToRoadBits(ReverseDiagDir(dir)) & (rcmd & rb_template)) return rb_template & rcmd;
+ /* Stop if the template is compatible to the growth dir */
+ if (DiagDirToRoadBits(ReverseDiagDir(dir)) & rb_template) return rb_template;
+ /* If not generate a straight road in the direction of the growth */
+ return DiagDirToRoadBits(dir) | DiagDirToRoadBits(ReverseDiagDir(dir));
+ }
- return (dir == DIAGDIR_NE || dir == DIAGDIR_SW) ? ROAD_X : ROAD_Y;
+ return rcmd;
}
/**