summaryrefslogtreecommitdiff
path: root/src/station_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-02-25 21:29:50 +0000
committerfrosch <frosch@openttd.org>2009-02-25 21:29:50 +0000
commit8ebe68b01b4d033bde4b8082461891959d8fc4a2 (patch)
treeb564a00f660cd32d8c8f6fbeca4fd2642c760312 /src/station_cmd.cpp
parent751a9bdf0a84666d37a05d7e2c92dfbc135a134a (diff)
downloadopenttd-8ebe68b01b4d033bde4b8082461891959d8fc4a2.tar.xz
(svn r15583) -Fix: Do not use TILE_MASK when you do not want to wrap around them map.
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r--src/station_cmd.cpp56
1 files changed, 16 insertions, 40 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 1facc4edf..8c3b1c737 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -124,7 +124,8 @@ static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp)
for (int dx = -3; dx <= 3; dx++) {
for (int dy = -3; dy <= 3; dy++) {
- if (cmp(TILE_MASK(tile + TileDiffXY(dx, dy)))) num++;
+ TileIndex t = TileAddWrap(tile, dx, dy);
+ if (t != INVALID_TILE && cmp(t)) num++;
}
}
@@ -2956,52 +2957,27 @@ void FindStationsAroundTiles(TileIndex tile, int w_prod, int h_prod, StationList
{
/* area to search = producer plus station catchment radius */
int max_rad = (_settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED);
- int w = w_prod + 2 * max_rad;
- int h = h_prod + 2 * max_rad;
- BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
- cur_tile = TILE_MASK(cur_tile);
- if (!IsTileType(cur_tile, MP_STATION)) continue;
+ for (int dy = -max_rad; dy < h_prod + max_rad; dy++) {
+ for (int dx = -max_rad; dx < w_prod + max_rad; dx++) {
+ TileIndex cur_tile = TileAddWrap(tile, dx, dy);
+ if (cur_tile == INVALID_TILE || !IsTileType(cur_tile, MP_STATION)) continue;
- Station *st = GetStationByTile(cur_tile);
+ Station *st = GetStationByTile(cur_tile);
- if (st->IsBuoy()) continue; // bouys don't accept cargo
+ if (st->IsBuoy()) continue; // bouys don't accept cargo
-
- if (_settings_game.station.modified_catchment) {
- /* min and max coordinates of the producer relative */
- const int x_min_prod = max_rad + 1;
- const int x_max_prod = max_rad + w_prod;
- const int y_min_prod = max_rad + 1;
- const int y_max_prod = max_rad + h_prod;
-
- int rad = st->GetCatchmentRadius();
-
- int x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur);
- if (w_cur < x_min_prod) {
- x_dist = x_min_prod - w_cur;
- } else if (w_cur > x_max_prod) {
- x_dist = w_cur - x_max_prod;
- }
-
- if (x_dist > rad) continue;
-
- int y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur);
- if (h_cur < y_min_prod) {
- y_dist = y_min_prod - h_cur;
- } else if (h_cur > y_max_prod) {
- y_dist = h_cur - y_max_prod;
+ if (_settings_game.station.modified_catchment) {
+ int rad = st->GetCatchmentRadius();
+ if (dx < -rad || dx >= rad + w_prod || dy < -rad || dy >= rad + h_prod) continue;
}
- if (y_dist > rad) continue;
+ /* Insert the station in the set. This will fail if it has
+ * already been added.
+ */
+ stations->Include(st);
}
-
- /* Insert the station in the set. This will fail if it has
- * already been added.
- */
- stations->Include(st);
-
- END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
+ }
}
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)