From 44495f8dba07184a2364b030ad257ac933e8ae36 Mon Sep 17 00:00:00 2001 From: planetmaker Date: Mon, 7 Feb 2011 20:47:06 +0000 Subject: (svn r22011) -Codechange: Rename a few variables and enhance code clearity --- src/industry_cmd.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3-70-g09d2