summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-02-06 20:51:24 +0000
committerfrosch <frosch@openttd.org>2009-02-06 20:51:24 +0000
commit6f9d6ffe80774a7667bb3a0efafe97ede09ed764 (patch)
tree09664d4e29e323642a12928c61cab60540f71c9c
parent78fc8aa93c448a091a05e0f213c7aa31b448dc4f (diff)
downloadopenttd-6f9d6ffe80774a7667bb3a0efafe97ede09ed764.tar.xz
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
-rw-r--r--src/town_cmd.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 5c7e35a94..eafae3425 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -716,13 +716,14 @@ static RoadBits GetTownRoadBits(TileIndex tile)
}
/**
- * Check if certain neighboring tiles have a road in a specific direction
+ * Check for parallel road inside a given distance.
+ * Assuming a road from (tile - TileOffsByDiagDir(dir)) to tile,
+ * is there a parallel road left or right of it within distance dist_multi?
*
* @param tile curent tile
* @param dir target direction
* @param dist_multi distance multiplyer
- * @return true if one of the neighboring tiles at the
- * given distance is a road tile else false
+ * @return true if there is a parallel road
*/
static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dist_multi)
{
@@ -735,21 +736,15 @@ static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dis
TileOffsByDiagDir(ReverseDiagDir(dir)),
};
- /* We add 1 to the distance because we want to get 1 for
- * the min distance multiplyer and not 0.
- * Therefore we start at 4. The 4 is used because
- * there are 4 tiles per distance step to check. */
dist_multi = (dist_multi + 1) * 4;
for (uint pos = 4; pos < dist_multi; pos++) {
- TileIndexDiff cur = 0;
- /* For each even value of pos add the right TileIndexDiff
- * for each uneven value the left TileIndexDiff
- * for each with 2nd bit set (2,3,6,7,..) add the reversed TileIndexDiff */
- cur += tid_lt[(pos & 1) ? 0 : 1];
- if (pos & 2) cur += tid_lt[2];
+ /* Go (pos / 4) tiles to the left or the right */
+ TileIndexDiff cur = tid_lt[(pos & 1) ? 0 : 1] * (pos / 4);
- cur = (uint)(pos / 4) * cur; // Multiply for the fitting distance
+ /* Use the current tile as origin, or go one tile backwards */
+ if (pos & 2) cur += tid_lt[2];
+ /* Test for roadbit parallel to dir and facing towards the middle axis */
if (IsValidTile(tile + cur) &&
GetTownRoadBits(TILE_ADD(tile, cur)) & DiagDirToRoadBits((pos & 2) ? dir : ReverseDiagDir(dir))) return true;
}