(svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.

This commit is contained in:
rubidium 2007-07-12 07:55:35 +00:00
parent be822ef976
commit bbe5d876cf

View File

@ -44,20 +44,20 @@ IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
static uint GetClosestWaterDistance(TileIndex tile, bool water) static uint GetClosestWaterDistance(TileIndex tile, bool water)
{ {
TileIndex t; TileIndex t;
uint best_dist; int best_dist;
for (t = 1; t < MapSize(); t++) { for (t = 0; t < MapSize(); t++) {
if (IsTileType(t, MP_WATER) == water) break; if (IsTileType(t, MP_WATER) == water) break;
} }
best_dist = DistanceManhattan(tile, t); best_dist = DistanceManhattan(tile, t);
for (; t < MapSize(); t++) { for (; t < MapSize(); t++) {
uint dist = DistanceManhattan(tile, t); int dist = DistanceManhattan(tile, t);
if (dist < best_dist) { if (dist < best_dist) {
if (IsTileType(t, MP_WATER) == water) best_dist = dist; if (IsTileType(t, MP_WATER) == water) best_dist = dist;
} else { } else {
/* When the Y distance between the current row and the 'source' tile /* When the Y distance between the current row and the 'source' tile
* is larger than the best distance, we've found the best distance */ * 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)) { if (TileX(tile) > TileX(t)) {
/* We can safely skip this many tiles; from here all tiles have a /* We can safely skip this many tiles; from here all tiles have a
* higher or equal distance than the best distance */ * higher or equal distance than the best distance */
@ -66,7 +66,7 @@ static uint GetClosestWaterDistance(TileIndex tile, bool water)
} else { } else {
/* We can safely skip this many tiles; up to here all tiles have a /* We can safely skip this many tiles; up to here all tiles have a
* higher or equal distance than the best distance */ * higher or equal distance than the best distance */
t += best_dist - dist; t += max(best_dist - dist, 0);
continue; continue;
} }
} }