summaryrefslogtreecommitdiff
path: root/src/industry_cmd.cpp
diff options
context:
space:
mode:
authorplanetmaker <planetmaker@openttd.org>2011-02-07 20:47:06 +0000
committerplanetmaker <planetmaker@openttd.org>2011-02-07 20:47:06 +0000
commit44495f8dba07184a2364b030ad257ac933e8ae36 (patch)
treed60aeb9357605ddc83e6650f54fb339f31d703c1 /src/industry_cmd.cpp
parent64280e63fbfc36fd01f06ca3b8948d10db80c742 (diff)
downloadopenttd-44495f8dba07184a2364b030ad257ac933e8ae36.tar.xz
(svn r22011) -Codechange: Rename a few variables and enhance code clearity
Diffstat (limited to 'src/industry_cmd.cpp')
-rw-r--r--src/industry_cmd.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 406ee085a..98e75cbd8 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1781,17 +1781,19 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
cur_company.Restore();
}
} else {
- int count = indspec->num_table;
- int num = GB(p1, 8, 8);
- if (num >= count) return CMD_ERROR;
+ int num_layouts = indspec->num_table;
+ int layout = GB(p1, 8, 8);
+ if (layout >= num_layouts) return CMD_ERROR;
CommandCost ret = CommandCost(STR_ERROR_SITE_UNSUITABLE);
- do {
- if (--count < 0) return ret;
- if (--num < 0) num = indspec->num_table - 1;
- ret = CreateNewIndustryHelper(tile, it, flags, indspec, num, random_var8f, random_initial_bits, _current_company, IACT_USERCREATION, &ind);
- } while (ret.Failed());
+ /* Check subsequently each layout, starting with the given layout in p1 */
+ for (int i = 0; i < num_layouts; i++) {
+ layout = (layout + 1) % num_layouts;
+ ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, _current_company, IACT_USERCREATION, &ind);
+ if (ret.Succeeded()) break;
+ }
+ /* If it still failed, there's no suitable layout to build here, return the error */
if (ret.Failed()) return ret;
}