diff options
author | frosch <frosch@openttd.org> | 2009-02-25 21:29:50 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-02-25 21:29:50 +0000 |
commit | 8ebe68b01b4d033bde4b8082461891959d8fc4a2 (patch) | |
tree | b564a00f660cd32d8c8f6fbeca4fd2642c760312 /src | |
parent | 751a9bdf0a84666d37a05d7e2c92dfbc135a134a (diff) | |
download | openttd-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')
-rw-r--r-- | src/disaster_cmd.cpp | 10 | ||||
-rw-r--r-- | src/industry_cmd.cpp | 4 | ||||
-rw-r--r-- | src/landscape.cpp | 8 | ||||
-rw-r--r-- | src/newgrf_commons.cpp | 2 | ||||
-rw-r--r-- | src/station_cmd.cpp | 56 | ||||
-rw-r--r-- | src/tree_cmd.cpp | 9 | ||||
-rw-r--r-- | src/unmovable_cmd.cpp | 5 |
7 files changed, 37 insertions, 57 deletions
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index 5205aa076..8ef01cf95 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -682,10 +682,12 @@ static void DisasterTick_Big_Ufo_Destroyer(Vehicle *v) EV_EXPLOSION_SMALL); } - BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) - tile = TILE_MASK(tile); - DisasterClearSquare(tile); - END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3)) + for (int dy = -3; dy < 3; dy++) { + for (int dx = -3; dx < 3; dx++) { + TileIndex tile = TileAddWrap(v->tile, dx, dy); + if (tile != INVALID_TILE) DisasterClearSquare(tile); + } + } } } diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index a8fe22914..f4d559bb2 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -928,7 +928,7 @@ static void PlantFarmField(TileIndex tile, IndustryID industry) /* check the amount of bad tiles */ count = 0; BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) - cur_tile = TILE_MASK(cur_tile); + TILE_ASSERT(cur_tile); count += IsBadFarmFieldTile(cur_tile); END_TILE_LOOP(cur_tile, size_x, size_y, tile) if (count * 2 >= size_x * size_y) return; @@ -940,7 +940,7 @@ static void PlantFarmField(TileIndex tile, IndustryID industry) /* make field */ BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) - cur_tile = TILE_MASK(cur_tile); + TILE_ASSERT(cur_tile); if (!IsBadFarmFieldTile2(cur_tile)) { MakeField(cur_tile, field_type, industry); SetClearCounter(cur_tile, counter); diff --git a/src/landscape.cpp b/src/landscape.cpp index 998a552d4..15d70bbfd 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -830,8 +830,8 @@ static void CreateDesertOrRainForest() for (data = _make_desert_or_rainforest_data; data != endof(_make_desert_or_rainforest_data); ++data) { - TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data)); - if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break; + TileIndex t = AddTileIndexDiffCWrap(tile, *data); + if (t != INVALID_TILE && (TileHeight(t) >= 4 || IsTileType(t, MP_WATER))) break; } if (data == endof(_make_desert_or_rainforest_data)) SetTropicZone(tile, TROPICZONE_DESERT); @@ -848,8 +848,8 @@ static void CreateDesertOrRainForest() for (data = _make_desert_or_rainforest_data; data != endof(_make_desert_or_rainforest_data); ++data) { - TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data)); - if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break; + TileIndex t = AddTileIndexDiffCWrap(tile, *data); + if (t != INVALID_TILE && IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break; } if (data == endof(_make_desert_or_rainforest_data)) SetTropicZone(tile, TROPICZONE_RAINFOREST); diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index b96d6aedf..266d801ac 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -292,7 +292,7 @@ TileIndex GetNearbyTile(byte parameter, TileIndex tile) /* Swap width and height depending on axis for railway stations */ if (IsRailwayStationTile(tile) && GetRailStationAxis(tile) == AXIS_Y) Swap(x, y); - /* Make sure we never roam outside of the map */ + /* Make sure we never roam outside of the map, better wrap in that case */ return TILE_MASK(tile + TileDiffXY(x, y)); } 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) diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 763eeb3c7..3eb3ae158 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -174,9 +174,9 @@ static void DoPlaceMoreTrees(TileIndex tile) int x = GB(r, 0, 5) - 16; int y = GB(r, 8, 5) - 16; uint dist = abs(x) + abs(y); - TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y)); + TileIndex cur_tile = TileAddWrap(tile, x, y); - if (dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) { + if (cur_tile != INVALID_TILE && dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) { PlaceTree(cur_tile, r); } } @@ -212,7 +212,8 @@ static void PlaceTreeAtSameHeight(TileIndex tile, uint height) uint32 r = Random(); int x = GB(r, 0, 5) - 16; int y = GB(r, 8, 5) - 16; - TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y)); + TileIndex cur_tile = TileAddWrap(tile, x, y); + if (cur_tile == INVALID_TILE) continue; /* Keep in range of the existing tree */ if (abs(x) + abs(y) > 16) continue; @@ -735,7 +736,7 @@ void OnTick_Trees() /* place a tree at a random spot */ r = Random(); - tile = TILE_MASK(r); + tile = RandomTileSeed(r); if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { PlantTreesOnTile(tile, tree, 0, 0); } diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp index 04be24e2d..a3f5b5117 100644 --- a/src/unmovable_cmd.cpp +++ b/src/unmovable_cmd.cpp @@ -452,10 +452,11 @@ void GenerateUnmovables() MakeLighthouse(tile); IncreaseGeneratingWorldProgress(GWP_UNMOVABLE); lighthouses_to_build--; - assert(tile == TILE_MASK(tile)); + TILE_ASSERT(tile); break; } - tile = TILE_MASK(tile + TileOffsByDiagDir(dir)); + tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir)); + if (tile == INVALID_TILE) break; } } } |