(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.
This commit is contained in:
38
main_gui.c
38
main_gui.c
@@ -1564,28 +1564,26 @@ static bool AnyTownExists(void)
|
||||
|
||||
extern Industry *CreateNewIndustry(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)
|
||||
{
|
||||
return CreateNewIndustry(tile, data) != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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 false;
|
||||
return CircularTileSearch(tile, 9, SearchTileForIndustry, type);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user