summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-12 07:55:35 +0000
committerrubidium <rubidium@openttd.org>2007-07-12 07:55:35 +0000
commitbbe5d876cf184713359e4d5e5fd2470eedb79dca (patch)
tree02fee42fdee0055a09f864663ce551843afc6071 /src
parentbe822ef9767392bff5f005e5d3f3a959016337db (diff)
downloadopenttd-bbe5d876cf184713359e4d5e5fd2470eedb79dca.tar.xz
(svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_industries.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 2c33259aa..3b6722125 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;
}
}