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 /main_gui.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 'main_gui.c')
-rw-r--r-- | main_gui.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/main_gui.c b/main_gui.c index 11b33067e..edfafbe20 100644 --- a/main_gui.c +++ b/main_gui.c @@ -1564,28 +1564,26 @@ static bool AnyTownExists(void) extern Industry *CreateNewIndustry(TileIndex tile, int type); -static bool TryBuildIndustry(TileIndex tile, int type) +/** + * Search callback function for TryBuildIndustry + * @param tile to test + * @param data that is passed by the caller. In this case, the type of industry been tested + * @result of the operation + */ +static bool SearchTileForIndustry(TileIndex tile, uint32 data) { - int n; - - if (CreateNewIndustry(tile, type)) return true; - - n = 100; - do { - if (CreateNewIndustry(AdjustTileCoordRandomly(tile, 1), type)) return true; - } while (--n); - - n = 200; - do { - if (CreateNewIndustry(AdjustTileCoordRandomly(tile, 2), type)) return true; - } while (--n); - - n = 700; - do { - if (CreateNewIndustry(AdjustTileCoordRandomly(tile, 4), type)) return true; - } while (--n); + return CreateNewIndustry(tile, data) != NULL; +} - return false; +/** + * Perform a 9*9 tiles circular search around a tile + * in order to find a suitable zone to create the desired industry + * @param tile to start search for + * @param type of the desired industry + */ +static bool TryBuildIndustry(TileIndex tile, int type) +{ + return CircularTileSearch(tile, 9, SearchTileForIndustry, type); } |