Mercurial > hg > openttd
changeset 15028:6dff4411ba79 draft
(svn r19643) -Fix (r19120): Industry generation failed for large maps and lots of industry types.
author | frosch <frosch@openttd.org> |
---|---|
date | Fri, 16 Apr 2010 21:21:54 +0000 |
parents | ae76e71c4d4e |
children | d10cef0ba461 |
files | src/core/random_func.cpp src/core/random_func.hpp src/industry_cmd.cpp |
diffstat | 3 files changed, 5 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/random_func.cpp +++ b/src/core/random_func.cpp @@ -57,6 +57,7 @@ uint DoRandomRange(uint max, int line, const char *file) { + assert(max <= UINT16_MAX); return GB(DoRandom(line, file), 0, 16) * max >> 16; } #endif /* RANDOM_DEBUG */
--- a/src/core/random_func.hpp +++ b/src/core/random_func.hpp @@ -99,8 +99,9 @@ return _random.Next(); } - static FORCEINLINE uint32 RandomRange(uint16 max) + static FORCEINLINE uint32 RandomRange(uint max) { + assert(max <= UINT16_MAX); return _random.Next(max); } #endif
--- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1923,7 +1923,8 @@ /* Add the remaining industries according to their probabilities */ for (uint i = 0; i < total_amount; i++) { - uint32 r = RandomRange(total_prob); + /* RandomRange() can only deal with 16 bit, which is not enough here. */ + uint32 r = ((uint64)Random() * (uint64)total_prob) >> 32; IndustryType it = 0; while (it < NUM_INDUSTRYTYPES && r >= industry_probs[it]) { r -= industry_probs[it];