diff options
author | belugas <belugas@openttd.org> | 2007-04-09 01:43:29 +0000 |
---|---|---|
committer | belugas <belugas@openttd.org> | 2007-04-09 01:43:29 +0000 |
commit | ec03c72afbed2d9be94ade6a342d4c81bec3d311 (patch) | |
tree | cc2aa58d4f2fde8cfafcd0aa1d72377f8c85655c /src | |
parent | 93acc50678dd571e7c8bd3ff167825d342ee6419 (diff) | |
download | openttd-ec03c72afbed2d9be94ade6a342d4c81bec3d311.tar.xz |
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
Diffstat (limited to 'src')
-rw-r--r-- | src/industry_cmd.cpp | 54 | ||||
-rw-r--r-- | src/table/build_industry.h | 69 |
2 files changed, 34 insertions, 89 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index bfa21881a..084304640 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1551,16 +1551,16 @@ static const byte _numof_industry_table[4][12] = { {0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, //high }; +/** This function is the one who really do the creation work + * 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) { int num = _numof_industry_table[_opt.diff.number_industries][amount]; - if (type == IT_OIL_REFINERY || type == IT_OIL_RIG) { - /* These are always placed next to the coastline, so we scale by the perimeter instead. */ - num = ScaleByMapSize1D(num); - } else { - num = ScaleByMapSize(num); - } + /* These are always placed next to the coastline, so we scale by the perimeter instead. */ + num = (type == IT_OIL_REFINERY || type == IT_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); if (_opt.diff.number_industries != 0) { PlayerID old_player = _current_player; @@ -1581,31 +1581,45 @@ static void PlaceInitialIndustry(IndustryType type, int amount) } } +/** This function will create ramdon industries during game creation. + * It will scale the amount of industries by map size as well as difficulty level */ void GenerateIndustries() { - const byte *b; uint i = 0; + uint8 chance; + IndustryType it; + const IndustrySpec *ind_spc; /* Find the total amount of industries */ - b = _industry_create_table[_opt.landscape]; - do { - int num = _numof_industry_table[_opt.diff.number_industries][b[0]]; + for (it = IT_COAL_MINE; it < IT_END; it++) { + int num; + + ind_spc = GetIndustrySpec(it); + chance = ind_spc->appear_creation[_opt.landscape]; + + if (chance > 0) { + /* 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 */ + num = _numof_industry_table[_opt.diff.number_industries][chance]; - if (b[1] == IT_OIL_REFINERY || b[1] == IT_OIL_RIG) { /* These are always placed next to the coastline, so we scale by the perimeter instead. */ - num = ScaleByMapSize1D(num); - } else { - num = ScaleByMapSize(num); + num = (it == IT_OIL_REFINERY || it == IT_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); + i += num; } + } - i += num; - } while ( (b+=2)[0] != 0); SetGeneratingWorldProgress(GWP_INDUSTRY, i); - b = _industry_create_table[_opt.landscape]; - do { - PlaceInitialIndustry(b[1], b[0]); - } while ( (b+=2)[0] != 0); + for (it = IT_COAL_MINE; it < IT_END; 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. */ + chance = GetIndustrySpec(it)->appear_creation[_opt.landscape]; + if (chance > 0) PlaceInitialIndustry(it, chance); + }; } /* Change industry production or do closure */ diff --git a/src/table/build_industry.h b/src/table/build_industry.h index 3bf30584b..ce78dfa4b 100644 --- a/src/table/build_industry.h +++ b/src/table/build_industry.h @@ -1418,75 +1418,6 @@ static const IndustrySpec _industry_specs[] = { }; #undef MK - -static const byte _industry_create_table_0[] = { - 4, 4, - 5, 3, - 5, 2, - 8, 0, - 5, 1, - 4, 11, - 5, 18, - 9, 9, - 5, 8, - 5, 6, - 0 -}; - -static const byte _industry_create_table_1[] = { - 4, 4, - 5, 3, - 5, 14, - 8, 0, - 5, 1, - 5, 11, - 5, 13, - 9, 9, - 4, 15, - 5, 7, - 6, 16, - 0 -}; - -static const byte _industry_create_table_2[] = { - 4, 4, - 5, 11, - 5, 16, - 4, 13, - 4, 17, - 4, 10, - 4, 19, - 4, 20, - 4, 21, - 8, 22, - 4, 13, - 4, 23, - 2, 24, - 0 -}; - -static const byte _industry_create_table_3[] = { - 5, 26, - 5, 27, - 4, 28, - 5, 29, - 4, 30, - 5, 31, - 5, 32, - 4, 33, - 5, 34, - 5, 35, - 4, 36, - 0 -}; - -static const byte * const _industry_create_table[4] = { - _industry_create_table_0, - _industry_create_table_1, - _industry_create_table_2, - _industry_create_table_3, -}; - /** Writes the properties of a industry tile into the IndustryTileSpec struct. * @param c1 first type of cargo accepted for this tile * @param c2 second cargo |