From 358758e33be74557d6d2fc850258e5986cff1afe Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 12 Jul 2007 07:55:35 +0000 Subject: [PATCH] (svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land. --- src/newgrf_industries.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 2c33259aa7..3b67221250 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -44,20 +44,20 @@ IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id) static uint GetClosestWaterDistance(TileIndex tile, bool water) { TileIndex t; - uint best_dist; - for (t = 1; t < MapSize(); t++) { + int best_dist; + for (t = 0; t < MapSize(); t++) { if (IsTileType(t, MP_WATER) == water) break; } best_dist = DistanceManhattan(tile, t); for (; t < MapSize(); t++) { - uint dist = DistanceManhattan(tile, t); + int dist = DistanceManhattan(tile, t); if (dist < best_dist) { if (IsTileType(t, MP_WATER) == water) best_dist = dist; } else { /* When the Y distance between the current row and the 'source' tile * is larger than the best distance, we've found the best distance */ - if (TileY(t) - TileY(tile) > best_dist) return best_dist; + if ((int)TileY(t) - (int)TileY(tile) > best_dist) break; if (TileX(tile) > TileX(t)) { /* We can safely skip this many tiles; from here all tiles have a * higher or equal distance than the best distance */ @@ -66,7 +66,7 @@ static uint GetClosestWaterDistance(TileIndex tile, bool water) } else { /* We can safely skip this many tiles; up to here all tiles have a * higher or equal distance than the best distance */ - t += best_dist - dist; + t += max(best_dist - dist, 0); continue; } }