From c26dc76a7d40884c5f57014cecff5e4aff3261ba Mon Sep 17 00:00:00 2001 From: belugas Date: Fri, 17 Nov 2006 23:01:58 +0000 Subject: (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. --- main_gui.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'main_gui.c') 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); } -- cgit v1.2.3-70-g09d2