summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-09-04 12:09:12 +0000
committeralberth <alberth@openttd.org>2010-09-04 12:09:12 +0000
commit4f435d92565fae8c2ec01658b778602f0d791007 (patch)
tree06d881c0e0f4448489a90541ea6b3aff1620a166
parent21a80e0a0e3dfe590d8aa0acc366c9c57f16a9c9 (diff)
downloadopenttd-4f435d92565fae8c2ec01658b778602f0d791007.tar.xz
(svn r20738) -Codechange: Introduce a function for getting the number of industries that should be build.
-rw-r--r--src/industry_cmd.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index e7d52dd62..29cf766fe 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1881,14 +1881,25 @@ static uint16 GetIndustryGamePlayProbability(IndustryType it)
return chance;
}
-/** Number of industries on a 256x256 map */
-static const byte _numof_industry_table[] = {
- 0, // none
- 10, // very low
- 25, // low
- 55, // normal
- 80, // high
-};
+/**
+ * Get wanted number of industries on the map.
+ * @return Wanted number of industries at the map.
+ */
+static uint GetNumberOfIndustries()
+{
+ /* Number of industries on a 256x256 map. */
+ static const uint16 numof_industry_table[] = {
+ 0, // none
+ 10, // very low
+ 25, // low
+ 55, // normal
+ 80, // high
+ };
+
+ assert(_settings_game.difficulty.number_industries < lengthof(numof_industry_table));
+ uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_industries : 1;
+ return ScaleByMapSize(numof_industry_table[difficulty]);
+}
/**
* Advertise about a new industry opening.
@@ -1947,9 +1958,7 @@ static void PlaceInitialIndustry(IndustryType type, bool try_hard)
*/
void GenerateIndustries()
{
- assert(_settings_game.difficulty.number_industries < lengthof(_numof_industry_table));
- uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_industries : 1;
- uint total_amount = ScaleByMapSize(_numof_industry_table[difficulty]);
+ uint total_amount = GetNumberOfIndustries();
/* Do not create any industries? */
if (total_amount == 0) return;