1
0
Fork 0

(svn r13367) -Codechange: Allow CircularTileSearch function to return the tile where search has been successful, or INVALID_TILE if it has not

release/0.7
belugas 2008-06-03 02:20:27 +00:00
parent 00851610e1
commit b0ada3fbbf
4 changed files with 14 additions and 8 deletions

View File

@ -995,7 +995,7 @@ static void ChopLumberMillTrees(Industry *i)
if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed
if (CircularTileSearch(tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles to search if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles to search
i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
} }

View File

@ -258,7 +258,7 @@ uint DistanceFromEdge(TileIndex tile)
* Although it really is a square search... * Although it really is a square search...
* Every tile will be tested by means of the callback function proc, * 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. * 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 size: number of tiles per side of the desired search area
* @param proc: callback testing function pointer. * @param proc: callback testing function pointer.
* @param data to be passed to the callback function. Depends on the implementation * @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 proc != NULL
* @pre size > 0 * @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; uint n, x, y;
DiagDirection dir; DiagDirection dir;
@ -274,14 +274,17 @@ bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, ui
assert(proc != NULL); assert(proc != NULL);
assert(size > 0); assert(size > 0);
x = TileX(tile); x = TileX(*tile);
y = TileY(tile); y = TileY(*tile);
if (size % 2 == 1) { if (size % 2 == 1) {
/* If the length of the side is uneven, the center has to be checked /* 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 */ * separately, as the pattern of uneven sides requires to go around the center */
n = 2; 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, /* If tile test is not successful, get one tile down and left,
* ready for a test in first circle around center tile */ * 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--) { for (j = n; j != 0; j--) {
if (x <= MapMaxX() && y <= MapMaxY() && ///< Is the tile within the map? if (x <= MapMaxX() && y <= MapMaxY() && ///< Is the tile within the map?
proc(TileXY(x, y), data)) { ///< Is the callback successful? proc(TileXY(x, y), data)) { ///< Is the callback successful?
*tile = TileXY(x, y);
return true; ///< then stop the search 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; x += _tileoffs_by_dir[DIR_W].x;
y += _tileoffs_by_dir[DIR_W].y; y += _tileoffs_by_dir[DIR_W].y;
} }
*tile = INVALID_TILE;
return false; return false;
} }

View File

@ -391,7 +391,7 @@ typedef bool TestTileOnSearchProc(TileIndex tile, uint32 data);
/** /**
* Searches for some cirumstances of a tile around a given tile with a helper function. * Searches for some cirumstances of a tile around a given tile with a helper function.
*/ */
bool CircularTileSearch(TileIndex tile, uint size, TestTileOnSearchProc proc, uint32 data); bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, uint32 data);
/** /**
* Get a random tile out of a given seed. * Get a random tile out of a given seed.

View File

@ -2193,7 +2193,7 @@ static void TownActionBuildStatue(Town *t)
{ {
TileIndex tile = t->xy; TileIndex tile = t->xy;
if (CircularTileSearch(tile, 9, SearchTileForStatue, t->index)) { if (CircularTileSearch(&tile, 9, SearchTileForStatue, t->index)) {
SetBit(t->statues, _current_player); // Once found and built, "inform" the Town SetBit(t->statues, _current_player); // Once found and built, "inform" the Town
} }
} }