diff options
author | belugas <belugas@openttd.org> | 2006-11-17 23:01:58 +0000 |
---|---|---|
committer | belugas <belugas@openttd.org> | 2006-11-17 23:01:58 +0000 |
commit | c26dc76a7d40884c5f57014cecff5e4aff3261ba (patch) | |
tree | cb862a03cf34020ff230c133372a4be330d3a917 /town_cmd.c | |
parent | bd129cf6bf59d62896fec327a3b5677f74bbb606 (diff) | |
download | openttd-c26dc76a7d40884c5f57014cecff5e4aff3261ba.tar.xz |
(svn r7198) -Codechange: Implement a circular tile search function.
Just provide the number of tiles per side, a pointer to a test function, the tile to start searching and voila.
Fixes [FS#364] by removing a lengthy and suboptimal random search pattern.
Thanks Rubidium.
Diffstat (limited to 'town_cmd.c')
-rw-r--r-- | town_cmd.c | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/town_cmd.c b/town_cmd.c index d9bc799ae..20be3354a 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -1476,39 +1476,27 @@ static bool DoBuildStatueOfCompany(TileIndex tile) return true; } +/** + * Search callback function for TownActionBuildStatue + * @param data that is passed by the caller. In this case, nothing + * @result of the test + */ +static bool SearchTileForStatue(TileIndex tile, uint32 data) +{ + return DoBuildStatueOfCompany(tile); +} + +/** + * Perform a 9x9 tiles circular search from the center of the town + * in order to find a free tile to place a statue + * @param t town to search in + */ static void TownActionBuildStatue(Town* t) { - // Layouted as an outward spiral - static const TileIndexDiffC _statue_tiles[] = { - {-1, 0}, - { 0, 1}, - { 1, 0}, { 1, 0}, - { 0,-1}, { 0,-1}, - {-1, 0}, {-1, 0}, {-1, 0}, - { 0, 1}, { 0, 1}, { 0, 1}, - { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, - { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, - {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, - { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, - { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, - { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, - {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, - { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, - { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, - { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, - {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, - { 0, 0} - }; TileIndex tile = t->xy; - const TileIndexDiffC *p; - for (p = _statue_tiles; p != endof(_statue_tiles); ++p) { - if (DoBuildStatueOfCompany(tile)) { - SETBIT(t->statues, _current_player); - return; - } - tile = TILE_ADD(tile, ToTileIndexDiff(*p)); - } + if (CircularTileSearch(tile, 9, SearchTileForStatue, 0)) + SETBIT(t->statues, _current_player); ///< Once found and built, "inform" the Town } static void TownActionFundBuildings(Town* t) |