diff options
author | belugas <belugas@openttd.org> | 2008-06-03 02:20:27 +0000 |
---|---|---|
committer | belugas <belugas@openttd.org> | 2008-06-03 02:20:27 +0000 |
commit | b0ada3fbbf25693675a18e3360657816ed5cf2ca (patch) | |
tree | 995aadb7b724c94354b6a56dab399357bd204c3c /src/map.cpp | |
parent | 00851610e1e64d8b5e759c425bfd4ddbf8f504ee (diff) | |
download | openttd-b0ada3fbbf25693675a18e3360657816ed5cf2ca.tar.xz |
(svn r13367) -Codechange: Allow CircularTileSearch function to return the tile where search has been successful, or INVALID_TILE if it has not
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/map.cpp b/src/map.cpp index 82a25f34c..640864c0a 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -258,7 +258,7 @@ uint DistanceFromEdge(TileIndex tile) * 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 + * @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 data to be passed to the callback function. Depends on the implementation @@ -266,7 +266,7 @@ uint DistanceFromEdge(TileIndex tile) * @pre proc != NULL * @pre size > 0 */ -bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, uint32 data) +bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, uint32 data) { uint n, x, y; DiagDirection dir; @@ -274,14 +274,17 @@ bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, ui assert(proc != NULL); assert(size > 0); - x = TileX(tile); - y = TileY(tile); + x = TileX(*tile); + y = TileY(*tile); 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 */ n = 2; - if (proc(TileXY(x, y), data)) return true; + if (proc(TileXY(x, y), data)) { + *tile = TileXY(x, y); + return true; + } /* If tile test is not successful, get one tile down and left, * ready for a test in first circle around center tile */ @@ -302,6 +305,7 @@ bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, ui for (j = n; j != 0; j--) { if (x <= MapMaxX() && y <= MapMaxY() && ///< Is the tile within the map? proc(TileXY(x, y), data)) { ///< Is the callback successful? + *tile = TileXY(x, y); return true; ///< then stop the search } @@ -314,5 +318,7 @@ bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, ui x += _tileoffs_by_dir[DIR_W].x; y += _tileoffs_by_dir[DIR_W].y; } + + *tile = INVALID_TILE; return false; } |