summaryrefslogtreecommitdiff
path: root/main_gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'main_gui.c')
-rw-r--r--main_gui.c38
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);
}