the unit name generation could with different locales call get_random()...

...a different number of times. This lead to different names and traits. 
Changed to call random a fixed number of times which fixes the traits.
The names are still wrong and still cause OOS errors but these should
not be fatal (Fixes bug #9472 partly)
This commit is contained in:
Mark de Wever 2007-07-21 14:55:13 +00:00
parent f920c9eabf
commit 6bffa4fd81
3 changed files with 22 additions and 1 deletions

View file

@ -7,6 +7,9 @@ Version 1.3.5+svn:
variable (bug #9555)
* the automatic unit description used a non-MP safe way, this has been
fixed
* the unit name generation could with different locales call get_random() a
different number of times. This lead to different names and traits.
Changed to call random a fixed number of times which fixes the traits.
* miscellaneous and bug fixes
* various code cleanups
* proper handling of description autogeneration for per level [effect] on

View file

@ -16,6 +16,9 @@ Version 1.3.5+svn:
* The random starting time of day setting is will now be remembered.
* Fixed a bug which could lead to the map in the lobby to become invisible.
* Fixed an OOS which happened when a unit was recruited.
* Fixed an OOS which was caused by different traits. This only happened if
the players use different languages. A related problem which causes the
names to differ and also cause OOS errors hasn't been fixed yet.
* Unit changes and balancing

View file

@ -53,13 +53,28 @@ static wide_string markov_generate_name(const markov_prefix_map& prefixes, size_
wide_string prefix, res;
// Since this function is called from several translation domains it can
// be a translation has a different markov_prefix_map which means
// get_random is called a different number of times. To avoid that problem
// we load a vector with those items. This is a kind of klugdge since when
// we bail out at 'if(c == 0)' the names of the units differ and thus we
// still have an OOS. The main difference with this change only the names
// differ and not the traits which causes real problems due to different
// stats.
std::vector<int> random(max_len);
size_t j = 0;
for(; j < max_len; ++j) {
random[j] = get_random();
}
j = 0;
while(res.size() < max_len) {
const markov_prefix_map::const_iterator i = prefixes.find(prefix);
if(i == prefixes.end() || i->second.empty()) {
return res;
}
const wchar_t c = i->second[get_random()%i->second.size()];
const wchar_t c = i->second[random[j++]%i->second.size()];
if(c == 0) {
return res;
}