summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-11-09 11:20:36 +0000
committertruelight <truelight@openttd.org>2007-11-09 11:20:36 +0000
commit71f443cbdc78fb806da2b069e316e08df9ec6015 (patch)
tree12f45587236438b68102fe83b4600510d013d39e /src/town_cmd.cpp
parent3e8493c851fc8555483e8ff713b5274ef0fe6463 (diff)
downloadopenttd-71f443cbdc78fb806da2b069e316e08df9ec6015.tar.xz
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index f243228f7..e04fccadb 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -895,26 +895,26 @@ static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
*
* @param t The current town
* @param tile The current tile
- * @param rcmd The RoadBits which are possible on this tile
+ * @param bridge_dir The valid direction in which to grow a bridge
* @return true if a bridge has been build else false
*/
-static bool GrowTownWithBridge(const Town *t, TileIndex tile, RoadBits rcmd)
+static bool GrowTownWithBridge(const Town *t, TileIndex tile, DiagDirection bridge_dir)
{
- DiagDirection bridge_dir; // The direction of a bridge we maybe want to build
+ assert(bridge_dir < DIAGDIR_END);
- /* Determine direction of slope,
- * and build a road if not a special slope. */
- switch (GetTileSlope(tile, NULL)) {
- case SLOPE_SW: bridge_dir = DIAGDIR_NE; break;
- case SLOPE_SE: bridge_dir = DIAGDIR_NW; break;
- case SLOPE_NW: bridge_dir = DIAGDIR_SE; break;
- case SLOPE_NE: bridge_dir = DIAGDIR_SW; break;
-
- default: return false;
- }
+ const Slope slope = GetTileSlope(tile, NULL);
+ if (slope == SLOPE_FLAT) return false; // no slope, no bridge
- /* Check if the bridge will be compatible to the RoadBits */
- if (!(rcmd & DiagDirToRoadBits(ReverseDiagDir(bridge_dir)))) return false;
+ /* Make sure the direction is compatible with the slope.
+ * If any of the following bits match, the slope is forbidden for
+ * that diagdir. Total of 5 slopes per direction.
+ * 0 -> 0b1100
+ * 1 -> 0b0110
+ * 2 -> 0b0011
+ * 3 -> 0b1001
+ * 0xCC is 0b11001100, so we just shift it right with
+ * the direction to get the forbidden slope mask. */
+ if (HASBITS(slope & 0x0F, 0xCC >> bridge_dir)) return false;
/* We are in the right direction */
uint32 bridge_length = 0; // This value stores the length of the possible bridge
@@ -1120,7 +1120,10 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
rcmd = CleanUpRoadBits(tile, rcmd);
if (rcmd == ROAD_NONE) return;
- if (GrowTownWithBridge(t1, tile, rcmd)) return;
+ /* Only use the target direction for bridges to ensure they're connected.
+ * The target_dir is as computed previously according to town layout, so
+ * it will match it perfectly. */
+ if (GrowTownWithBridge(t1, tile, target_dir)) return;
GrowTownWithRoad(t1, tile, rcmd);
}