summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp51
1 files changed, 17 insertions, 34 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 2668ded0f..33a8c09e0 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1788,33 +1788,20 @@ static const byte _numof_industry_table[NB_DIFFICULTY_LEVEL][NB_NUMOFINDUSTRY] =
* of random industries during game creation
* @param type IndustryType of the desired industry
* @param amount of industries that need to be built */
-static void PlaceInitialIndustry(IndustryType type, int amount)
+static void PlaceInitialIndustry(IndustryType type, uint amount)
{
- /* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the
- * _numof_industry_table. newgrf can specify a big amount */
- int num = (amount > NB_NUMOFINDUSTRY) ? amount : _numof_industry_table[_settings_game.difficulty.number_industries][amount];
- const IndustrySpec *ind_spc = GetIndustrySpec(type);
-
- /* These are always placed next to the coastline, so we scale by the perimeter instead. */
- num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
-
- if (_settings_game.difficulty.number_industries != 0) {
- CompanyID old_company = _current_company;
- _current_company = OWNER_NONE;
- assert(num > 0);
-
- do {
- uint i;
+ CompanyID old_company = _current_company;
+ _current_company = OWNER_NONE;
- IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
+ for (; amount > 0; amount--) {
+ IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
- for (i = 0; i < 2000; i++) {
- if (CreateNewIndustry(RandomTile(), type) != NULL) break;
- }
- } while (--num);
-
- _current_company = old_company;
+ for (uint i = 0; i < 2000; i++) {
+ if (CreateNewIndustry(RandomTile(), type) != NULL) break;
+ }
}
+
+ _current_company = old_company;
}
/** This function will create ramdon industries during game creation.
@@ -1826,6 +1813,9 @@ void GenerateIndustries()
IndustryType it;
const IndustrySpec *ind_spc;
+ uint industry_counts[NUM_INDUSTRYTYPES];
+ memset(industry_counts, 0, sizeof(industry_counts));
+
/* Find the total amount of industries */
if (_settings_game.difficulty.number_industries > 0) {
for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
@@ -1841,10 +1831,11 @@ void GenerateIndustries()
/* once the chance of appearance is determind, it have to be scaled by
* the difficulty level. The "chance" in question is more an index into
* the _numof_industry_table,in fact */
- int num = (chance > NB_NUMOFINDUSTRY) ? chance : _numof_industry_table[_settings_game.difficulty.number_industries][chance];
+ uint num = (chance > NB_NUMOFINDUSTRY) ? chance : _numof_industry_table[_settings_game.difficulty.number_industries][chance];
/* These are always placed next to the coastline, so we scale by the perimeter instead. */
num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
+ industry_counts[it] = num;
i += num;
}
}
@@ -1854,16 +1845,8 @@ void GenerateIndustries()
if (_settings_game.difficulty.number_industries > 0) {
for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
- /* Once the number of industries has been determined, let's really create them.
- * The test for chance allows us to try create industries that are available only
- * for this landscape.
- * @todo : Do we really have to pass chance as un-scaled value, since we've already
- * processed that scaling above? No, don't think so. Will find a way. */
- ind_spc = GetIndustrySpec(it);
- if (ind_spc->enabled && ind_spc->num_table > 0) {
- chance = ind_spc->appear_creation[_settings_game.game_creation.landscape];
- if (chance > 0) PlaceInitialIndustry(it, chance);
- }
+ /* Once the number of industries has been determined, let's really create them. */
+ if (industry_counts[it] > 0) PlaceInitialIndustry(it, industry_counts[it]);
}
}
}