@ -9,6 +9,20 @@ static inline uint32 SeedChance(int shift_by, int max, uint32 seed)
return ( ( uint16 ) ( seed > > shift_by ) * max ) > > 16 ;
}
static inline uint32 SeedModChance ( int shift_by , int max , uint32 seed )
{
/* This actually gives *MUCH* more even distribution of the values
* than SeedChance ( ) , which is absolutely horrible in that . If
* you do not believe me , try with i . e . the Czech town names ,
* compare the words ( nicely visible on prefixes ) generated by
* SeedChance ( ) and SeedModChance ( ) . Do not get dicouraged by the
* never - use - modulo myths , which hold true only for the linear
* congruential generators ( and Random ( ) isn ' t such a generator ) .
* - - pasky */
// TODO: Perhaps we should use it for all the name generators? --pasky
return ( seed > > shift_by ) % max ;
}
static inline int32 SeedChanceBias ( int shift_by , int max , uint32 seed , int bias )
{
return SeedChance ( shift_by , max + bias , seed ) - bias ;
@ -330,22 +344,22 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
enum CzechAllow allow ;
// 1:3 chance to use a real name.
if ( Seed Chance( 0 , 4 , seed ) = = 0 ) {
strcpy ( buf , name_czech_real [ Seed Chance( 1 , lengthof ( name_czech_real ) , seed ) ] ) ;
if ( Seed Mod Chance( 0 , 4 , seed ) = = 0 ) {
strcpy ( buf , name_czech_real [ Seed ModChance( 4 , lengthof ( name_czech_real ) , seed ) ] ) ;
return 0 ;
}
// NUL terminates the string for strcat()
strcpy ( buf , " " ) ;
prob_tails = Seed Chance( 2 , 32 , seed ) ;
prob_tails = Seed Mod Chance( 2 , 32 , seed ) ;
do_prefix = prob_tails < 12 ;
do_suffix = prob_tails > 11 & & prob_tails < 17 ;
if ( do_prefix ) prefix = Seed Chance( 5 , lengthof ( name_czech_adj ) , seed ) ;
if ( do_suffix ) suffix = Seed Chance( 7 , lengthof ( name_czech_suffix ) , seed ) ;
if ( do_prefix ) prefix = Seed Mod Chance( 5 , lengthof ( name_czech_adj ) * 12 , seed ) / 12 ;
if ( do_suffix ) suffix = Seed Mod Chance( 7 , lengthof ( name_czech_suffix ) , seed ) ;
// 3:1 chance 3:1 to use dynamic substantive
stem = Seed Chance( 9 , lengthof ( name_czech_subst_full )
stem = Seed Mod Chance( 9 , lengthof ( name_czech_subst_full )
+ 3 * lengthof ( name_czech_subst_stem ) ,
seed ) ;
if ( stem < ( int ) lengthof ( name_czech_subst_full ) ) {
@ -369,7 +383,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
allow = name_czech_subst_stem [ stem ] . allow ;
// Load the postfix (1:1 chance that a postfix will be inserted)
postfix = Seed Chance( 14 , lengthof ( name_czech_subst_postfix ) * 2 , seed ) ;
postfix = Seed Mod Chance( 14 , lengthof ( name_czech_subst_postfix ) * 2 , seed ) ;
if ( choose & CZC_POSTFIX ) {
// Always get a real postfix.
@ -415,7 +429,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed)
assert ( i > 0 ) ;
// Load the ending
ending = map [ Seed Chance( 16 , i , seed ) ] ;
ending = map [ Seed Mod Chance( 16 , i , seed ) ] ;
// Override possible CZG_*FREE; this must be a real gender,
// otherwise we get overflow when modifying the adjectivum.
gender = name_czech_subst_ending [ ending ] . gender ;