diff --git a/src/map.cpp b/src/map.cpp index 696d024be7..efb5168cbf 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -227,96 +227,6 @@ uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir) } } -/** - * Function performing a search around a center tile and going outward, thus in circle. - * Although it really is a square search... - * Every tile will be tested by means of the callback function proc, - * which will determine if yes or no the given tile meets criteria of search. - * @param tile to start the search from. Upon completion, it will return the tile matching the search - * @param size: number of tiles per side of the desired search area - * @param proc: callback testing function pointer. - * @param user_data to be passed to the callback function. Depends on the implementation - * @return result of the search - * @pre proc != nullptr - * @pre size > 0 - */ -bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data) -{ - assert(proc != nullptr); - assert(size > 0); - - if (size % 2 == 1) { - /* If the length of the side is uneven, the center has to be checked - * separately, as the pattern of uneven sides requires to go around the center */ - if (proc(*tile, user_data)) return true; - if (size < 2) return false; - - /* If tile test is not successful, get one tile up, - * ready for a test in first circle around center tile */ - *tile = TileAddByDir(*tile, DIR_N); - return CircularTileSearch(tile, size / 2, 1, 1, proc, user_data); - } else { - return CircularTileSearch(tile, size / 2, 0, 0, proc, user_data); - } -} - -/** - * Generalized circular search allowing for rectangles and a hole. - * Function performing a search around a center rectangle and going outward. - * The center rectangle is left out from the search. To do a rectangular search - * without a hole, set either h or w to zero. - * Every tile will be tested by means of the callback function proc, - * which will determine if yes or no the given tile meets criteria of search. - * @param tile to start the search from. Upon completion, it will return the tile matching the search. - * This tile should be directly north of the hole (if any). - * @param radius How many tiles to search outwards. Note: This is a radius and thus different - * from the size parameter of the other CircularTileSearch function, which is a diameter. - * @param w the width of the inner rectangle - * @param h the height of the inner rectangle - * @param proc callback testing function pointer. - * @param user_data to be passed to the callback function. Depends on the implementation - * @return result of the search - * @pre proc != nullptr - * @pre radius > 0 - */ -bool CircularTileSearch(TileIndex *tile, uint radius, uint w, uint h, TestTileOnSearchProc proc, void *user_data) -{ - assert(proc != nullptr); - assert(radius > 0); - - uint x = TileX(*tile) + w + 1; - uint y = TileY(*tile); - - const uint extent[DIAGDIR_END] = { w, h, w, h }; - - for (uint n = 0; n < radius; n++) { - for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { - /* Is the tile within the map? */ - for (uint j = extent[dir] + n * 2 + 1; j != 0; j--) { - if (x < Map::SizeX() && y < Map::SizeY()) { - TileIndex t = TileXY(x, y); - /* Is the callback successful? */ - if (proc(t, user_data)) { - /* Stop the search */ - *tile = t; - return true; - } - } - - /* Step to the next 'neighbour' in the circular line */ - x += _tileoffs_by_diagdir[dir].x; - y += _tileoffs_by_diagdir[dir].y; - } - } - /* Jump to next circle to test */ - x += _tileoffs_by_dir[DIR_W].x; - y += _tileoffs_by_dir[DIR_W].y; - } - - *tile = INVALID_TILE; - return false; -} - /** * Finds the distance for the closest tile with water/land given a tile * @param tile the tile to find the distance too diff --git a/src/map_func.h b/src/map_func.h index 370099b43f..e1929c2f91 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -632,18 +632,6 @@ inline DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to) } } -/** - * A callback function type for searching tiles. - * - * @param tile The tile to test - * @param user_data additional data for the callback function to use - * @return A boolean value, depend on the definition of the function. - */ -typedef bool TestTileOnSearchProc(TileIndex tile, void *user_data); - -bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data); -bool CircularTileSearch(TileIndex *tile, uint radius, uint w, uint h, TestTileOnSearchProc proc, void *user_data); - /** * Get a random tile out of a given seed. * @param r the random 'seed' diff --git a/src/tests/tilearea.cpp b/src/tests/tilearea.cpp index 85c7b50acb..2821c5bfde 100644 --- a/src/tests/tilearea.cpp +++ b/src/tests/tilearea.cpp @@ -33,18 +33,6 @@ static void TestSpiralTileSequence(TileCoord center, uint diameter, std::span bool { - reinterpret_cast *>(user_data)->push_back(tile); - return false; - }, &result); - REQUIRE(result.size() == expected.size()); - for (size_t i = 0; i < result.size(); ++i) { - CHECK(TileX(result[i]) == expected[i].x); - CHECK(TileY(result[i]) == expected[i].y); - } } static void TestSpiralTileSequence(TileCoord start_north, uint radius, uint w, uint h, std::span expected) @@ -60,18 +48,6 @@ static void TestSpiralTileSequence(TileCoord start_north, uint radius, uint w, u CHECK(TileX(result[i]) == expected[i].x); CHECK(TileY(result[i]) == expected[i].y); } - - result.clear(); - CircularTileSearch(&tile, radius, w, h, - +[](TileIndex tile, void *user_data) -> bool { - reinterpret_cast *>(user_data)->push_back(tile); - return false; - }, &result); - REQUIRE(result.size() == expected.size()); - for (size_t i = 0; i < result.size(); ++i) { - CHECK(TileX(result[i]) == expected[i].x); - CHECK(TileY(result[i]) == expected[i].y); - } } TEST_CASE("SpiralTileSequence - minimum")