Changeset - r15018:e5877a75e843
[Not reviewed]
master
0 3 0
frosch - 14 years ago 2010-04-16 21:21:54
frosch@openttd.org
(svn r19643) -Fix (r19120): Industry generation failed for large maps and lots of industry types.
3 files changed with 5 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/core/random_func.cpp
Show inline comments
 
@@ -57,6 +57,7 @@ uint32 DoRandom(int line, const char *fi
 

	
 
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 */
src/core/random_func.hpp
Show inline comments
 
@@ -99,8 +99,9 @@ void SetRandomSeed(uint32 seed);
 
		return _random.Next();
 
	}
 

	
 
	static FORCEINLINE uint32 RandomRange(uint16 max)
 
	static FORCEINLINE uint32 RandomRange(uint max)
 
	{
 
		assert(max <= UINT16_MAX);
 
		return _random.Next(max);
 
	}
 
#endif
src/industry_cmd.cpp
Show inline comments
 
@@ -1923,7 +1923,8 @@ void GenerateIndustries()
 

	
 
	/* 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];
0 comments (0 inline, 0 general)