(svn r11305) -Codechange: randomise layout when building an industry ingame
authorglx
Sat, 20 Oct 2007 00:20:23 +0000
changeset 7760 d10e2e25cd5f
parent 7759 eb8f1b5b2883
child 7761 babce6309d79
(svn r11305) -Codechange: randomise layout when building an industry ingame
src/industry_cmd.cpp
--- a/src/industry_cmd.cpp	Sat Oct 20 00:09:39 2007 +0000
+++ b/src/industry_cmd.cpp	Sat Oct 20 00:20:23 2007 +0000
@@ -1582,8 +1582,6 @@
  */
 CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	int num;
-	const IndustryTileTable * const *itt;
 	const IndustrySpec *indspec;
 
 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
@@ -1608,8 +1606,7 @@
 			 * is nothing we can really do about that. */
 			if (Random() <= indspec->prospecting_chance) {
 				for (int i = 0; i < 5000; i++) {
-					uint tilespec_index = RandomRange(indspec->num_table);
-					const Industry *ind = CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, tilespec_index);
+					const Industry *ind = CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, RandomRange(indspec->num_table));
 					if (ind != NULL) {
 						SetDParam(0, indspec->name);
 						if (indspec->new_industry_text > STR_LAST_STRINGID) {
@@ -1626,12 +1623,14 @@
 			}
 		}
 	} else {
-		num = indspec->num_table;
-		itt = indspec->table;
+		int count = indspec->num_table;
+		const IndustryTileTable * const *itt = indspec->table;
+		int num = RandomRange(count);
 
 		_error_message = STR_0239_SITE_UNSUITABLE;
 		do {
-			if (--num < 0) return CMD_ERROR;
+			if (--count < 0) return CMD_ERROR;
+			if (--num < 0) num = indspec->num_table - 1;
 		} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
 
 		if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;