namegen.c
changeset 4919 9a5b9becf31e
parent 4441 b73b7b960c74
child 5108 aeaef6fe53b7
equal deleted inserted replaced
4918:7700309b4e59 4919:9a5b9becf31e
     4 #include "openttd.h"
     4 #include "openttd.h"
     5 #include "debug.h"
     5 #include "debug.h"
     6 #include "macros.h"
     6 #include "macros.h"
     7 #include "namegen.h"
     7 #include "namegen.h"
     8 #include "table/namegen.h"
     8 #include "table/namegen.h"
       
     9 #include "string.h"
     9 
    10 
    10 static inline uint32 SeedChance(int shift_by, int max, uint32 seed)
    11 static inline uint32 SeedChance(int shift_by, int max, uint32 seed)
    11 {
    12 {
    12 	return (GB(seed, shift_by, 16) * max) >> 16;
    13 	return (GB(seed, shift_by, 16) * max) >> 16;
    13 }
    14 }
    34 static void ReplaceWords(const char *org, const char *rep, char *buf)
    35 static void ReplaceWords(const char *org, const char *rep, char *buf)
    35 {
    36 {
    36 	if (strncmp(buf, org, 4) == 0) strncpy(buf, rep, 4);
    37 	if (strncmp(buf, org, 4) == 0) strncpy(buf, rep, 4);
    37 }
    38 }
    38 
    39 
    39 static byte MakeEnglishOriginalTownName(char *buf, uint32 seed)
    40 static byte MakeEnglishOriginalTownName(char *buf, uint32 seed, const char *last)
    40 {
    41 {
    41 	int i;
    42 	int i;
    42 
    43 
    43 	//null terminates the string for strcat
    44 	//null terminates the string for strcat
    44 	strcpy(buf, "");
    45 	strecpy(buf, "", last);
    45 
    46 
    46 	// optional first segment
    47 	// optional first segment
    47 	i = SeedChanceBias(0, lengthof(name_original_english_1), seed, 50);
    48 	i = SeedChanceBias(0, lengthof(name_original_english_1), seed, 50);
    48 	if (i >= 0)
    49 	if (i >= 0)
    49 		strcat(buf,name_original_english_1[i]);
    50 		strecat(buf, name_original_english_1[i], last);
    50 
    51 
    51 	//mandatory middle segments
    52 	//mandatory middle segments
    52 	strcat(buf, name_original_english_2[SeedChance(4,  lengthof(name_original_english_2), seed)]);
    53 	strecat(buf, name_original_english_2[SeedChance(4,  lengthof(name_original_english_2), seed)], last);
    53 	strcat(buf, name_original_english_3[SeedChance(7,  lengthof(name_original_english_3), seed)]);
    54 	strecat(buf, name_original_english_3[SeedChance(7,  lengthof(name_original_english_3), seed)], last);
    54 	strcat(buf, name_original_english_4[SeedChance(10, lengthof(name_original_english_4), seed)]);
    55 	strecat(buf, name_original_english_4[SeedChance(10, lengthof(name_original_english_4), seed)], last);
    55 	strcat(buf, name_original_english_5[SeedChance(13, lengthof(name_original_english_5), seed)]);
    56 	strecat(buf, name_original_english_5[SeedChance(13, lengthof(name_original_english_5), seed)], last);
    56 
    57 
    57 	//optional last segment
    58 	//optional last segment
    58 	i = SeedChanceBias(15, lengthof(name_original_english_6), seed, 60);
    59 	i = SeedChanceBias(15, lengthof(name_original_english_6), seed, 60);
    59 	if (i >= 0)
    60 	if (i >= 0)
    60 		strcat(buf, name_original_english_6[i]);
    61 		strecat(buf, name_original_english_6[i], last);
    61 
    62 
    62 	if (buf[0] == 'C' && (buf[1] == 'e' || buf[1] == 'i'))
    63 	if (buf[0] == 'C' && (buf[1] == 'e' || buf[1] == 'i'))
    63 		buf[0] = 'K';
    64 		buf[0] = 'K';
    64 
    65 
    65 	ReplaceWords("Cunt", "East", buf);
    66 	ReplaceWords("Cunt", "East", buf);
    75 
    76 
    76 	return 0;
    77 	return 0;
    77 }
    78 }
    78 
    79 
    79 
    80 
    80 static byte MakeEnglishAdditionalTownName(char *buf, uint32 seed)
    81 static byte MakeEnglishAdditionalTownName(char *buf, uint32 seed, const char *last)
    81 {
    82 {
    82 	int i;
    83 	int i;
    83 
    84 
    84 	//null terminates the string for strcat
    85 	//null terminates the string for strcat
    85 	strcpy(buf, "");
    86 	strecpy(buf, "", last);
    86 
    87 
    87 	// optional first segment
    88 	// optional first segment
    88 	i = SeedChanceBias(0, lengthof(name_additional_english_prefix), seed, 50);
    89 	i = SeedChanceBias(0, lengthof(name_additional_english_prefix), seed, 50);
    89 	if (i >= 0)
    90 	if (i >= 0)
    90 		strcat(buf,name_additional_english_prefix[i]);
    91 		strecat(buf,name_additional_english_prefix[i], last);
    91 
    92 
    92 	if (SeedChance(3, 20, seed) >= 14) {
    93 	if (SeedChance(3, 20, seed) >= 14) {
    93 		strcat(buf, name_additional_english_1a[SeedChance(6, lengthof(name_additional_english_1a), seed)]);
    94 		strecat(buf, name_additional_english_1a[SeedChance(6, lengthof(name_additional_english_1a), seed)], last);
    94 	} else {
    95 	} else {
    95 		strcat(buf, name_additional_english_1b1[SeedChance(6, lengthof(name_additional_english_1b1), seed)]);
    96 		strecat(buf, name_additional_english_1b1[SeedChance(6, lengthof(name_additional_english_1b1), seed)], last);
    96 		strcat(buf, name_additional_english_1b2[SeedChance(9, lengthof(name_additional_english_1b2), seed)]);
    97 		strecat(buf, name_additional_english_1b2[SeedChance(9, lengthof(name_additional_english_1b2), seed)], last);
    97 		if (SeedChance(11, 20, seed) >= 4) {
    98 		if (SeedChance(11, 20, seed) >= 4) {
    98 			strcat(buf, name_additional_english_1b3a[SeedChance(12, lengthof(name_additional_english_1b3a), seed)]);
    99 			strecat(buf, name_additional_english_1b3a[SeedChance(12, lengthof(name_additional_english_1b3a), seed)], last);
    99 		} else {
   100 		} else {
   100 			strcat(buf, name_additional_english_1b3b[SeedChance(12, lengthof(name_additional_english_1b3b), seed)]);
   101 			strecat(buf, name_additional_english_1b3b[SeedChance(12, lengthof(name_additional_english_1b3b), seed)], last);
   101 		}
   102 		}
   102 	}
   103 	}
   103 
   104 
   104 	strcat(buf, name_additional_english_2[SeedChance(14, lengthof(name_additional_english_2), seed)]);
   105 	strecat(buf, name_additional_english_2[SeedChance(14, lengthof(name_additional_english_2), seed)], last);
   105 
   106 
   106 	//optional last segment
   107 	//optional last segment
   107 	i = SeedChanceBias(15, lengthof(name_additional_english_3), seed, 60);
   108 	i = SeedChanceBias(15, lengthof(name_additional_english_3), seed, 60);
   108 	if (i >= 0)
   109 	if (i >= 0)
   109 		strcat(buf, name_additional_english_3[i]);
   110 		strecat(buf, name_additional_english_3[i], last);
   110 
   111 
   111 	ReplaceWords("Cunt", "East", buf);
   112 	ReplaceWords("Cunt", "East", buf);
   112 	ReplaceWords("Slag", "Pits", buf);
   113 	ReplaceWords("Slag", "Pits", buf);
   113 	ReplaceWords("Slut", "Edin", buf);
   114 	ReplaceWords("Slut", "Edin", buf);
   114 	ReplaceWords("Fart", "Boot", buf);
   115 	ReplaceWords("Fart", "Boot", buf);
   120 	ReplaceWords("Wrar", "Stan", buf);
   121 	ReplaceWords("Wrar", "Stan", buf);
   121 
   122 
   122 	return 0;
   123 	return 0;
   123 }
   124 }
   124 
   125 
   125 static byte MakeAustrianTownName(char *buf, uint32 seed)
   126 static byte MakeAustrianTownName(char *buf, uint32 seed, const char *last)
   126 {
   127 {
   127 	int i, j = 0;
   128 	int i, j = 0;
   128 	strcpy(buf, "");
   129 	strecpy(buf, "", last);
   129 
   130 
   130 	// Bad, Maria, Gross, ...
   131 	// Bad, Maria, Gross, ...
   131 	i = SeedChanceBias(0, lengthof(name_austrian_a1), seed, 15);
   132 	i = SeedChanceBias(0, lengthof(name_austrian_a1), seed, 15);
   132 	if (i >= 0) strcat(buf, name_austrian_a1[i]);
   133 	if (i >= 0) strecat(buf, name_austrian_a1[i], last);
   133 
   134 
   134 	i = SeedChance(4, 6, seed);
   135 	i = SeedChance(4, 6, seed);
   135 	if (i >= 4) {
   136 	if (i >= 4) {
   136 		// Kaisers-kirchen
   137 		// Kaisers-kirchen
   137 		strcat(buf, name_austrian_a2[SeedChance( 7, lengthof(name_austrian_a2), seed)]);
   138 		strecat(buf, name_austrian_a2[SeedChance( 7, lengthof(name_austrian_a2), seed)], last);
   138 		strcat(buf, name_austrian_a3[SeedChance(13, lengthof(name_austrian_a3), seed)]);
   139 		strecat(buf, name_austrian_a3[SeedChance(13, lengthof(name_austrian_a3), seed)], last);
   139 	} else if (i >= 2) {
   140 	} else if (i >= 2) {
   140 		// St. Johann
   141 		// St. Johann
   141 		strcat(buf, name_austrian_a5[SeedChance( 7, lengthof(name_austrian_a5), seed)]);
   142 		strecat(buf, name_austrian_a5[SeedChance( 7, lengthof(name_austrian_a5), seed)], last);
   142 		strcat(buf, name_austrian_a6[SeedChance( 9, lengthof(name_austrian_a6), seed)]);
   143 		strecat(buf, name_austrian_a6[SeedChance( 9, lengthof(name_austrian_a6), seed)], last);
   143 		j = 1; // More likely to have a " an der " or " am "
   144 		j = 1; // More likely to have a " an der " or " am "
   144 	} else {
   145 	} else {
   145 		// Zell
   146 		// Zell
   146 		strcat(buf, name_austrian_a4[SeedChance( 7, lengthof(name_austrian_a4), seed)]);
   147 		strecat(buf, name_austrian_a4[SeedChance( 7, lengthof(name_austrian_a4), seed)], last);
   147 	}
   148 	}
   148 
   149 
   149 	i = SeedChance(1, 6, seed);
   150 	i = SeedChance(1, 6, seed);
   150 	if (i >= 4 - j) {
   151 	if (i >= 4 - j) {
   151 		// an der Donau (rivers)
   152 		// an der Donau (rivers)
   152 		strcat(buf, name_austrian_f1[SeedChance(4, lengthof(name_austrian_f1), seed)]);
   153 		strecat(buf, name_austrian_f1[SeedChance(4, lengthof(name_austrian_f1), seed)], last);
   153 		strcat(buf, name_austrian_f2[SeedChance(5, lengthof(name_austrian_f2), seed)]);
   154 		strecat(buf, name_austrian_f2[SeedChance(5, lengthof(name_austrian_f2), seed)], last);
   154 	} else if (i >= 2 - j) {
   155 	} else if (i >= 2 - j) {
   155 		// am Dachstein (mountains)
   156 		// am Dachstein (mountains)
   156 		strcat(buf, name_austrian_b1[SeedChance(4, lengthof(name_austrian_b1), seed)]);
   157 		strecat(buf, name_austrian_b1[SeedChance(4, lengthof(name_austrian_b1), seed)], last);
   157 		strcat(buf, name_austrian_b2[SeedChance(5, lengthof(name_austrian_b2), seed)]);
   158 		strecat(buf, name_austrian_b2[SeedChance(5, lengthof(name_austrian_b2), seed)], last);
   158 	}
   159 	}
   159 
   160 
   160 	return 0;
   161 	return 0;
   161 }
   162 }
   162 
   163 
   163 static byte MakeGermanTownName(char *buf, uint32 seed)
   164 static byte MakeGermanTownName(char *buf, uint32 seed, const char *last)
   164 {
   165 {
   165 	uint i;
   166 	uint i;
   166 	uint seed_derivative;
   167 	uint seed_derivative;
   167 
   168 
   168 	//null terminates the string for strcat
   169 	//null terminates the string for strcat
   169 	strcpy(buf, "");
   170 	strecpy(buf, "", last);
   170 
   171 
   171 	seed_derivative = SeedChance(7, 28, seed);
   172 	seed_derivative = SeedChance(7, 28, seed);
   172 
   173 
   173 	//optional prefix
   174 	//optional prefix
   174 	if (seed_derivative == 12 || seed_derivative == 19) {
   175 	if (seed_derivative == 12 || seed_derivative == 19) {
   175 		i = SeedChance(2, lengthof(name_german_pre), seed);
   176 		i = SeedChance(2, lengthof(name_german_pre), seed);
   176 		strcat(buf,name_german_pre[i]);
   177 		strecat(buf,name_german_pre[i], last);
   177 	}
   178 	}
   178 
   179 
   179 	// mandatory middle segments including option of hardcoded name
   180 	// mandatory middle segments including option of hardcoded name
   180 	i = SeedChance(3, lengthof(name_german_real) + lengthof(name_german_1), seed);
   181 	i = SeedChance(3, lengthof(name_german_real) + lengthof(name_german_1), seed);
   181 	if (i < lengthof(name_german_real)) {
   182 	if (i < lengthof(name_german_real)) {
   182 		strcat(buf,name_german_real[i]);
   183 		strecat(buf,name_german_real[i], last);
   183 	} else {
   184 	} else {
   184 		strcat(buf, name_german_1[i - lengthof(name_german_real)]);
   185 		strecat(buf, name_german_1[i - lengthof(name_german_real)], last);
   185 
   186 
   186 		i = SeedChance(5, lengthof(name_german_2), seed);
   187 		i = SeedChance(5, lengthof(name_german_2), seed);
   187 		strcat(buf, name_german_2[i]);
   188 		strecat(buf, name_german_2[i], last);
   188 	}
   189 	}
   189 
   190 
   190 	// optional suffix
   191 	// optional suffix
   191 	if (seed_derivative == 24) {
   192 	if (seed_derivative == 24) {
   192 		i = SeedChance(9,
   193 		i = SeedChance(9,
   193 			lengthof(name_german_4_an_der) + lengthof(name_german_4_am), seed);
   194 			lengthof(name_german_4_an_der) + lengthof(name_german_4_am), seed);
   194 		if (i < lengthof(name_german_4_an_der)) {
   195 		if (i < lengthof(name_german_4_an_der)) {
   195 			strcat(buf, name_german_3_an_der[0]);
   196 			strecat(buf, name_german_3_an_der[0], last);
   196 			strcat(buf, name_german_4_an_der[i]);
   197 			strecat(buf, name_german_4_an_der[i], last);
   197 		} else {
   198 		} else {
   198 			strcat(buf, name_german_3_am[0]);
   199 			strecat(buf, name_german_3_am[0], last);
   199 			strcat(buf, name_german_4_am[i - lengthof(name_german_4_an_der)]);
   200 			strecat(buf, name_german_4_am[i - lengthof(name_german_4_an_der)], last);
   200 		}
   201 		}
   201 	}
   202 	}
   202 	return 0;
   203 	return 0;
   203 }
   204 }
   204 
   205 
   205 static byte MakeSpanishTownName(char *buf, uint32 seed)
   206 static byte MakeSpanishTownName(char *buf, uint32 seed, const char *last)
   206 {
   207 {
   207 	strcpy(buf, name_spanish_real[SeedChance(0, lengthof(name_spanish_real), seed)]);
   208 	strecpy(buf, name_spanish_real[SeedChance(0, lengthof(name_spanish_real), seed)], last);
   208 	return 0;
   209 	return 0;
   209 }
   210 }
   210 
   211 
   211 static byte MakeFrenchTownName(char *buf, uint32 seed)
   212 static byte MakeFrenchTownName(char *buf, uint32 seed, const char *last)
   212 {
   213 {
   213 	strcpy(buf, name_french_real[SeedChance(0, lengthof(name_french_real), seed)]);
   214 	strecpy(buf, name_french_real[SeedChance(0, lengthof(name_french_real), seed)], last);
   214 	return 0;
   215 	return 0;
   215 }
   216 }
   216 
   217 
   217 static byte MakeSillyTownName(char *buf, uint32 seed)
   218 static byte MakeSillyTownName(char *buf, uint32 seed, const char *last)
   218 {
   219 {
   219 	strcpy(buf, name_silly_1[SeedChance( 0, lengthof(name_silly_1), seed)]);
   220 	strecpy(buf, name_silly_1[SeedChance( 0, lengthof(name_silly_1), seed)], last);
   220 	strcat(buf, name_silly_2[SeedChance(16, lengthof(name_silly_2), seed)]);
   221 	strecat(buf, name_silly_2[SeedChance(16, lengthof(name_silly_2), seed)], last);
   221 	return 0;
   222 	return 0;
   222 }
   223 }
   223 
   224 
   224 static byte MakeSwedishTownName(char *buf, uint32 seed)
   225 static byte MakeSwedishTownName(char *buf, uint32 seed, const char *last)
   225 {
   226 {
   226 	int i;
   227 	int i;
   227 
   228 
   228 	//null terminates the string for strcat
   229 	//null terminates the string for strcat
   229 	strcpy(buf, "");
   230 	strecpy(buf, "", last);
   230 
   231 
   231 	// optional first segment
   232 	// optional first segment
   232 	i = SeedChanceBias(0, lengthof(name_swedish_1), seed, 50);
   233 	i = SeedChanceBias(0, lengthof(name_swedish_1), seed, 50);
   233 	if (i >= 0)
   234 	if (i >= 0)
   234 		strcat(buf, name_swedish_1[i]);
   235 		strecat(buf, name_swedish_1[i], last);
   235 
   236 
   236 	// mandatory middle segments including option of hardcoded name
   237 	// mandatory middle segments including option of hardcoded name
   237 	if (SeedChance(4, 5, seed) >= 3) {
   238 	if (SeedChance(4, 5, seed) >= 3) {
   238 		strcat(buf, name_swedish_2[SeedChance( 7, lengthof(name_swedish_2), seed)]);
   239 		strecat(buf, name_swedish_2[SeedChance( 7, lengthof(name_swedish_2), seed)], last);
   239 	} else {
   240 	} else {
   240 		strcat(buf, name_swedish_2a[SeedChance( 7, lengthof(name_swedish_2a), seed)]);
   241 		strecat(buf, name_swedish_2a[SeedChance( 7, lengthof(name_swedish_2a), seed)], last);
   241 		strcat(buf, name_swedish_2b[SeedChance(10, lengthof(name_swedish_2b), seed)]);
   242 		strecat(buf, name_swedish_2b[SeedChance(10, lengthof(name_swedish_2b), seed)], last);
   242 		strcat(buf, name_swedish_2c[SeedChance(13, lengthof(name_swedish_2c), seed)]);
   243 		strecat(buf, name_swedish_2c[SeedChance(13, lengthof(name_swedish_2c), seed)], last);
   243 	}
   244 	}
   244 
   245 
   245 	strcat(buf, name_swedish_3[SeedChance(16, lengthof(name_swedish_3), seed)]);
   246 	strecat(buf, name_swedish_3[SeedChance(16, lengthof(name_swedish_3), seed)], last);
   246 
   247 
   247 	return 0;
   248 	return 0;
   248 }
   249 }
   249 
   250 
   250 static byte MakeDutchTownName(char *buf, uint32 seed)
   251 static byte MakeDutchTownName(char *buf, uint32 seed, const char *last)
   251 {
   252 {
   252 	int i;
   253 	int i;
   253 
   254 
   254 	//null terminates the string for strcat
   255 	//null terminates the string for strcat
   255 	strcpy(buf, "");
   256 	strecpy(buf, "", last);
   256 
   257 
   257 	// optional first segment
   258 	// optional first segment
   258 	i = SeedChanceBias(0, lengthof(name_dutch_1), seed, 50);
   259 	i = SeedChanceBias(0, lengthof(name_dutch_1), seed, 50);
   259 	if (i >= 0)
   260 	if (i >= 0)
   260 		strcat(buf, name_dutch_1[i]);
   261 		strecat(buf, name_dutch_1[i], last);
   261 
   262 
   262 	// mandatory middle segments including option of hardcoded name
   263 	// mandatory middle segments including option of hardcoded name
   263 	if (SeedChance(6, 9, seed) > 4) {
   264 	if (SeedChance(6, 9, seed) > 4) {
   264 		strcat(buf, name_dutch_2[SeedChance( 9, lengthof(name_dutch_2), seed)]);
   265 		strecat(buf, name_dutch_2[SeedChance( 9, lengthof(name_dutch_2), seed)], last);
   265 	} else {
   266 	} else {
   266 		strcat(buf, name_dutch_3[SeedChance( 9, lengthof(name_dutch_3), seed)]);
   267 		strecat(buf, name_dutch_3[SeedChance( 9, lengthof(name_dutch_3), seed)], last);
   267 		strcat(buf, name_dutch_4[SeedChance(12, lengthof(name_dutch_4), seed)]);
   268 		strecat(buf, name_dutch_4[SeedChance(12, lengthof(name_dutch_4), seed)], last);
   268 	}
   269 	}
   269 	strcat(buf, name_dutch_5[SeedChance(15, lengthof(name_dutch_5), seed)]);
   270 	strecat(buf, name_dutch_5[SeedChance(15, lengthof(name_dutch_5), seed)], last);
   270 
   271 
   271 	return 0;
   272 	return 0;
   272 }
   273 }
   273 
   274 
   274 static byte MakeFinnishTownName(char *buf, uint32 seed)
   275 static byte MakeFinnishTownName(char *buf, uint32 seed, const char *last)
   275 {
   276 {
   276 	//null terminates the string for strcat
   277 	//null terminates the string for strcat
   277 	strcpy(buf, "");
   278 	strecpy(buf, "", last);
   278 
   279 
   279 	// Select randomly if town name should consists of one or two parts.
   280 	// Select randomly if town name should consists of one or two parts.
   280 	if (SeedChance(0, 15, seed) >= 10) {
   281 	if (SeedChance(0, 15, seed) >= 10) {
   281 		strcat(buf, name_finnish_real[SeedChance( 2, lengthof(name_finnish_real), seed)]);
   282 		strecat(buf, name_finnish_real[SeedChance(2, lengthof(name_finnish_real), seed)], last);
   282 	} else if (SeedChance(0, 15, seed) >= 5) {
   283 	} else if (SeedChance(0, 15, seed) >= 5) {
   283 		// A two-part name by combining one of name_finnish_1 + "la"/"lä"
   284 		// A two-part name by combining one of name_finnish_1 + "la"/"lä"
   284 		// The reason for not having the contents of name_finnish_{1,2} in the same table is
   285 		// The reason for not having the contents of name_finnish_{1,2} in the same table is
   285 		// that the ones in name_finnish_2 are not good for this purpose.
   286 		// that the ones in name_finnish_2 are not good for this purpose.
   286 		uint sel = SeedChance( 0, lengthof(name_finnish_1), seed);
   287 		uint sel = SeedChance( 0, lengthof(name_finnish_1), seed);
   287 		char *last;
   288 		char *end;
   288 		strcat(buf, name_finnish_1[sel]);
   289 		strecat(buf, name_finnish_1[sel], last);
   289 		last = &buf[strlen(buf)-1];
   290 		end = &buf[strlen(buf)-1];
   290 		if (*last == 'i')
   291 		if (*end == 'i')
   291 			*last = 'e';
   292 			*end = 'e';
   292 		if (strstr(buf, "a") || strstr(buf, "o") || strstr(buf, "u") ||
   293 		if (strstr(buf, "a") || strstr(buf, "o") || strstr(buf, "u") ||
   293 			strstr(buf, "A") || strstr(buf, "O") || strstr(buf, "U"))
   294 			strstr(buf, "A") || strstr(buf, "O") || strstr(buf, "U"))
   294 		{
   295 		{
   295 			strcat(buf, "la");
   296 			strecat(buf, "la", last);
   296 		} else {
   297 		} else {
   297 			strcat(buf, "lä");
   298 			strecat(buf, "lä", last);
   298 		}
   299 		}
   299 	} else {
   300 	} else {
   300 		// A two-part name by combining one of name_finnish_{1,2} + name_finnish_3.
   301 		// A two-part name by combining one of name_finnish_{1,2} + name_finnish_3.
   301 		// Why aren't name_finnish_{1,2} just one table? See above.
   302 		// Why aren't name_finnish_{1,2} just one table? See above.
   302 		uint sel = SeedChance(2,
   303 		uint sel = SeedChance(2,
   303 			lengthof(name_finnish_1) + lengthof(name_finnish_2), seed);
   304 			lengthof(name_finnish_1) + lengthof(name_finnish_2), seed);
   304 		if (sel >= lengthof(name_finnish_1)) {
   305 		if (sel >= lengthof(name_finnish_1)) {
   305 			strcat(buf, name_finnish_2[sel-lengthof(name_finnish_1)]);
   306 			strecat(buf, name_finnish_2[sel-lengthof(name_finnish_1)], last);
   306 		} else {
   307 		} else {
   307 			strcat(buf, name_finnish_1[sel]);
   308 			strecat(buf, name_finnish_1[sel], last);
   308 		}
   309 		}
   309 		strcat(buf, name_finnish_3[SeedChance(10, lengthof(name_finnish_3), seed)]);
   310 		strecat(buf, name_finnish_3[SeedChance(10, lengthof(name_finnish_3), seed)], last);
   310 	}
   311 	}
   311 
   312 
   312 	return 0;
   313 	return 0;
   313 }
   314 }
   314 
   315 
   315 static byte MakePolishTownName(char *buf, uint32 seed)
   316 static byte MakePolishTownName(char *buf, uint32 seed, const char *last)
   316 {
   317 {
   317 	uint i;
   318 	uint i;
   318 	uint j;
   319 	uint j;
   319 
   320 
   320 	//null terminates the string for strcat
   321 	//null terminates the string for strcat
   321 	strcpy(buf, "");
   322 	strecpy(buf, "", last);
   322 
   323 
   323 	// optional first segment
   324 	// optional first segment
   324 	i = SeedChance(0,
   325 	i = SeedChance(0,
   325 		lengthof(name_polish_2_o) + lengthof(name_polish_2_m) +
   326 		lengthof(name_polish_2_o) + lengthof(name_polish_2_m) +
   326 		lengthof(name_polish_2_f) + lengthof(name_polish_2_n),
   327 		lengthof(name_polish_2_f) + lengthof(name_polish_2_n),
   327 		seed);
   328 		seed);
   328 	j = SeedChance(2, 20, seed);
   329 	j = SeedChance(2, 20, seed);
   329 
   330 
   330 
   331 
   331 	if (i < lengthof(name_polish_2_o)) {
   332 	if (i < lengthof(name_polish_2_o)) {
   332 		strcat(buf, name_polish_2_o[SeedChance(3, lengthof(name_polish_2_o), seed)]);
   333 		strecat(buf, name_polish_2_o[SeedChance(3, lengthof(name_polish_2_o), seed)], last);
   333 	} else if (i < lengthof(name_polish_2_m) + lengthof(name_polish_2_o)) {
   334 	} else if (i < lengthof(name_polish_2_m) + lengthof(name_polish_2_o)) {
   334 		if (j < 4)
   335 		if (j < 4)
   335 			strcat(buf, name_polish_1_m[SeedChance(5, lengthof(name_polish_1_m), seed)]);
   336 			strecat(buf, name_polish_1_m[SeedChance(5, lengthof(name_polish_1_m), seed)], last);
   336 
   337 
   337 		strcat(buf, name_polish_2_m[SeedChance(7, lengthof(name_polish_2_m), seed)]);
   338 		strecat(buf, name_polish_2_m[SeedChance(7, lengthof(name_polish_2_m), seed)], last);
   338 
   339 
   339 		if (j >= 4 && j < 16)
   340 		if (j >= 4 && j < 16)
   340 			strcat(buf, name_polish_3_m[SeedChance(10, lengthof(name_polish_3_m), seed)]);
   341 			strecat(buf, name_polish_3_m[SeedChance(10, lengthof(name_polish_3_m), seed)], last);
   341 	} else if (i < lengthof(name_polish_2_f) + lengthof(name_polish_2_m) + lengthof(name_polish_2_o)) {
   342 	} else if (i < lengthof(name_polish_2_f) + lengthof(name_polish_2_m) + lengthof(name_polish_2_o)) {
   342 		if (j < 4)
   343 		if (j < 4)
   343 			strcat(buf, name_polish_1_f[SeedChance(5, lengthof(name_polish_1_f), seed)]);
   344 			strecat(buf, name_polish_1_f[SeedChance(5, lengthof(name_polish_1_f), seed)], last);
   344 
   345 
   345 		strcat(buf, name_polish_2_f[SeedChance(7, lengthof(name_polish_2_f), seed)]);
   346 		strecat(buf, name_polish_2_f[SeedChance(7, lengthof(name_polish_2_f), seed)], last);
   346 
   347 
   347 		if (j >= 4 && j < 16)
   348 		if (j >= 4 && j < 16)
   348 			strcat(buf, name_polish_3_f[SeedChance(10, lengthof(name_polish_3_f), seed)]);
   349 			strecat(buf, name_polish_3_f[SeedChance(10, lengthof(name_polish_3_f), seed)], last);
   349 	} else {
   350 	} else {
   350 		if (j < 4)
   351 		if (j < 4)
   351 			strcat(buf, name_polish_1_n[SeedChance(5, lengthof(name_polish_1_n), seed)]);
   352 			strecat(buf, name_polish_1_n[SeedChance(5, lengthof(name_polish_1_n), seed)], last);
   352 
   353 
   353 		strcat(buf, name_polish_2_n[SeedChance(7, lengthof(name_polish_2_n), seed)]);
   354 		strecat(buf, name_polish_2_n[SeedChance(7, lengthof(name_polish_2_n), seed)], last);
   354 
   355 
   355 		if (j >= 4 && j < 16)
   356 		if (j >= 4 && j < 16)
   356 			strcat(buf, name_polish_3_n[SeedChance(10, lengthof(name_polish_3_n), seed)]);
   357 			strecat(buf, name_polish_3_n[SeedChance(10, lengthof(name_polish_3_n), seed)], last);
   357 	}
   358 	}
   358 	return 0;
   359 	return 0;
   359 }
   360 }
   360 
   361 
   361 static byte MakeCzechTownName(char *buf, uint32 seed)
   362 static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
   362 {
   363 {
   363 	/* Probability of prefixes/suffixes */
   364 	/* Probability of prefixes/suffixes */
   364 	/* 0..11 prefix, 12..13 prefix+suffix, 14..17 suffix, 18..31 nothing */
   365 	/* 0..11 prefix, 12..13 prefix+suffix, 14..17 suffix, 18..31 nothing */
   365 	int prob_tails;
   366 	int prob_tails;
   366 	bool do_prefix, do_suffix, dynamic_subst;
   367 	bool do_prefix, do_suffix, dynamic_subst;
   373 	CzechChoose choose;
   374 	CzechChoose choose;
   374 	CzechAllow allow;
   375 	CzechAllow allow;
   375 
   376 
   376 	// 1:3 chance to use a real name.
   377 	// 1:3 chance to use a real name.
   377 	if (SeedModChance(0, 4, seed) == 0) {
   378 	if (SeedModChance(0, 4, seed) == 0) {
   378 		strcpy(buf, name_czech_real[SeedModChance(4, lengthof(name_czech_real), seed)]);
   379 		strecpy(buf, name_czech_real[SeedModChance(4, lengthof(name_czech_real), seed)], last);
   379 		return 0;
   380 		return 0;
   380 	}
   381 	}
   381 
   382 
   382 	// NUL terminates the string for strcat()
   383 	// NUL terminates the string for strcat()
   383 	strcpy(buf, "");
   384 	strecpy(buf, "", last);
   384 
   385 
   385 	prob_tails = SeedModChance(2, 32, seed);
   386 	prob_tails = SeedModChance(2, 32, seed);
   386 	do_prefix = prob_tails < 12;
   387 	do_prefix = prob_tails < 12;
   387 	do_suffix = prob_tails > 11 && prob_tails < 17;
   388 	do_suffix = prob_tails > 11 && prob_tails < 17;
   388 
   389 
   475 
   476 
   476 	if (do_prefix) {
   477 	if (do_prefix) {
   477 		CzechPattern pattern = name_czech_adj[prefix].pattern;
   478 		CzechPattern pattern = name_czech_adj[prefix].pattern;
   478 		size_t endpos;
   479 		size_t endpos;
   479 
   480 
   480 		strcat(buf, name_czech_adj[prefix].name);
   481 		strecat(buf, name_czech_adj[prefix].name, last);
   481 		endpos = strlen(buf) - 1;
   482 		endpos = strlen(buf) - 1;
   482 		if (gender == CZG_SMASC && pattern == CZP_PRIVL) {
   483 		if (gender == CZG_SMASC && pattern == CZP_PRIVL) {
   483 			/* -ovX -> -uv */
   484 			/* -ovX -> -uv */
   484 			buf[endpos - 2] = 'u';
   485 			buf[endpos - 2] = 'u';
   485 			assert(buf[endpos - 1] == 'v');
   486 			assert(buf[endpos - 1] == 'v');
   486 			buf[endpos] = '\0';
   487 			buf[endpos] = '\0';
   487 		} else {
   488 		} else {
   488 			buf[endpos] = name_czech_patmod[gender][pattern];
   489 			buf[endpos] = name_czech_patmod[gender][pattern];
   489 		}
   490 		}
   490 
   491 
   491 		strcat(buf, " ");
   492 		strecat(buf, " ", last);
   492 	}
   493 	}
   493 
   494 
   494 	if (dynamic_subst) {
   495 	if (dynamic_subst) {
   495 		strcat(buf, name_czech_subst_stem[stem].name);
   496 		strecat(buf, name_czech_subst_stem[stem].name, last);
   496 		if (postfix < lengthof(name_czech_subst_postfix)) {
   497 		if (postfix < lengthof(name_czech_subst_postfix)) {
   497 			const char *poststr = name_czech_subst_postfix[postfix];
   498 			const char *poststr = name_czech_subst_postfix[postfix];
   498 			const char *endstr = name_czech_subst_ending[ending].name;
   499 			const char *endstr = name_czech_subst_ending[ending].name;
   499 			size_t postlen, endlen;
   500 			size_t postlen, endlen;
   500 
   501 
   506 			if (postlen < 2 || postlen > endlen || (
   507 			if (postlen < 2 || postlen > endlen || (
   507 						(poststr[1] != 'v' || poststr[1] != endstr[1]) &&
   508 						(poststr[1] != 'v' || poststr[1] != endstr[1]) &&
   508 						poststr[2] != endstr[1])
   509 						poststr[2] != endstr[1])
   509 					) {
   510 					) {
   510 				size_t buflen;
   511 				size_t buflen;
   511 				strcat(buf, poststr);
   512 				strecat(buf, poststr, last);
   512 				buflen = strlen(buf);
   513 				buflen = strlen(buf);
   513 
   514 
   514 				// k-i -> c-i, h-i -> z-i
   515 				// k-i -> c-i, h-i -> z-i
   515 				if (endstr[0] == 'i') {
   516 				if (endstr[0] == 'i') {
   516 					switch (buf[buflen - 1]) {
   517 					switch (buf[buflen - 1]) {
   519 						default: break;
   520 						default: break;
   520 					}
   521 					}
   521 				}
   522 				}
   522 			}
   523 			}
   523 		}
   524 		}
   524 		strcat(buf, name_czech_subst_ending[ending].name);
   525 		strecat(buf, name_czech_subst_ending[ending].name, last);
   525 	} else {
   526 	} else {
   526 		strcat(buf, name_czech_subst_full[stem].name);
   527 		strecat(buf, name_czech_subst_full[stem].name, last);
   527 	}
   528 	}
   528 
   529 
   529 	if (do_suffix) {
   530 	if (do_suffix) {
   530 		strcat(buf, " ");
   531 		strecat(buf, " ", last);
   531 		strcat(buf, name_czech_suffix[suffix]);
   532 		strecat(buf, name_czech_suffix[suffix], last);
   532 	}
   533 	}
   533 
   534 
   534 	return 0;
   535 	return 0;
   535 }
   536 }
   536 
   537 
   537 static byte MakeRomanianTownName(char *buf, uint32 seed)
   538 static byte MakeRomanianTownName(char *buf, uint32 seed, const char *last)
   538 {
   539 {
   539 	strcpy(buf, name_romanian_real[SeedChance(0, lengthof(name_romanian_real), seed)]);
   540 	strecpy(buf, name_romanian_real[SeedChance(0, lengthof(name_romanian_real), seed)], last);
   540 	return 0;
   541 	return 0;
   541 }
   542 }
   542 
   543 
   543 static byte MakeSlovakTownName(char *buf, uint32 seed)
   544 static byte MakeSlovakTownName(char *buf, uint32 seed, const char *last)
   544 {
   545 {
   545 	strcpy(buf, name_slovak_real[SeedChance(0, lengthof(name_slovak_real), seed)]);
   546 	strecpy(buf, name_slovak_real[SeedChance(0, lengthof(name_slovak_real), seed)], last);
   546 	return 0;
   547 	return 0;
   547 }
   548 }
   548 
   549 
   549 static byte MakeNorwegianTownName(char *buf, uint32 seed)
   550 static byte MakeNorwegianTownName(char *buf, uint32 seed, const char *last)
   550 {
   551 {
   551 	strcpy(buf, "");
   552 	strecpy(buf, "", last);
   552 
   553 
   553 	// Use first 4 bit from seed to decide whether or not this town should
   554 	// Use first 4 bit from seed to decide whether or not this town should
   554 	// have a real name 3/16 chance.  Bit 0-3
   555 	// have a real name 3/16 chance.  Bit 0-3
   555 	if (SeedChance(0, 15, seed) < 3) {
   556 	if (SeedChance(0, 15, seed) < 3) {
   556 		// Use 7bit for the realname table index.  Bit 4-10
   557 		// Use 7bit for the realname table index.  Bit 4-10
   557 		strcat(buf, name_norwegian_real[SeedChance(4, lengthof(name_norwegian_real), seed)]);
   558 		strecat(buf, name_norwegian_real[SeedChance(4, lengthof(name_norwegian_real), seed)], last);
   558 	} else {
   559 	} else {
   559 		// Use 7bit for the first fake part.  Bit 4-10
   560 		// Use 7bit for the first fake part.  Bit 4-10
   560 		strcat(buf, name_norwegian_1[SeedChance(4, lengthof(name_norwegian_1), seed)]);
   561 		strecat(buf, name_norwegian_1[SeedChance(4, lengthof(name_norwegian_1), seed)], last);
   561 		// Use 7bit for the last fake part.  Bit 11-17
   562 		// Use 7bit for the last fake part.  Bit 11-17
   562 		strcat(buf, name_norwegian_2[SeedChance(11, lengthof(name_norwegian_2), seed)]);
   563 		strecat(buf, name_norwegian_2[SeedChance(11, lengthof(name_norwegian_2), seed)], last);
   563 	}
   564 	}
   564 
   565 
   565 	return 0;
   566 	return 0;
   566 }
   567 }
   567 
   568 
   568 static byte MakeHungarianTownName(char *buf, uint32 seed)
   569 static byte MakeHungarianTownName(char *buf, uint32 seed, const char *last)
   569 {
   570 {
   570 	uint i;
   571 	uint i;
   571 
   572 
   572 	//null terminates the string for strcat
   573 	//null terminates the string for strcat
   573 	strcpy(buf, "");
   574 	strecpy(buf, "", last);
   574 
   575 
   575 	if (SeedChance(12, 15, seed) < 3) {
   576 	if (SeedChance(12, 15, seed) < 3) {
   576 		strcat(buf, name_hungarian_real[SeedChance(0, lengthof(name_hungarian_real), seed)]);
   577 		strecat(buf, name_hungarian_real[SeedChance(0, lengthof(name_hungarian_real), seed)], last);
   577 	} else {
   578 	} else {
   578 		// optional first segment
   579 		// optional first segment
   579 		i = SeedChance(3, lengthof(name_hungarian_1) * 3, seed);
   580 		i = SeedChance(3, lengthof(name_hungarian_1) * 3, seed);
   580 		if (i < lengthof(name_hungarian_1))
   581 		if (i < lengthof(name_hungarian_1))
   581 			strcat(buf, name_hungarian_1[i]);
   582 			strecat(buf, name_hungarian_1[i], last);
   582 
   583 
   583 		// mandatory middle segments
   584 		// mandatory middle segments
   584 		strcat(buf, name_hungarian_2[SeedChance(3, lengthof(name_hungarian_2), seed)]);
   585 		strecat(buf, name_hungarian_2[SeedChance(3, lengthof(name_hungarian_2), seed)], last);
   585 		strcat(buf, name_hungarian_3[SeedChance(6, lengthof(name_hungarian_3), seed)]);
   586 		strecat(buf, name_hungarian_3[SeedChance(6, lengthof(name_hungarian_3), seed)], last);
   586 
   587 
   587 		// optional last segment
   588 		// optional last segment
   588 		i = SeedChance(10, lengthof(name_hungarian_4) * 3, seed);
   589 		i = SeedChance(10, lengthof(name_hungarian_4) * 3, seed);
   589 		if (i < lengthof(name_hungarian_4)) {
   590 		if (i < lengthof(name_hungarian_4)) {
   590 			strcat(buf, name_hungarian_4[i]);
   591 			strecat(buf, name_hungarian_4[i], last);
   591 		}
   592 		}
   592 	}
   593 	}
   593 
   594 
   594 	return 0;
   595 	return 0;
   595 }
   596 }
   596 
   597 
   597 static byte MakeSwissTownName(char *buf, uint32 seed)
   598 static byte MakeSwissTownName(char *buf, uint32 seed, const char *last)
   598 {
   599 {
   599 	strcpy(buf, name_swiss_real[SeedChance(0, lengthof(name_swiss_real), seed)]);
   600 	strecpy(buf, name_swiss_real[SeedChance(0, lengthof(name_swiss_real), seed)], last);
   600 	return 0;
   601 	return 0;
   601 }
   602 }
   602 
   603 
   603 static byte MakeDanishTownName(char *buf, uint32 seed)
   604 static byte MakeDanishTownName(char *buf, uint32 seed, const char *last)
   604 {
   605 {
   605 	int i;
   606 	int i;
   606 
   607 
   607 	// null terminates the string for strcat
   608 	// null terminates the string for strcat
   608 	strcpy(buf, "");
   609 	strecpy(buf, "", last);
   609 
   610 
   610 	// optional first segment
   611 	// optional first segment
   611 	i = SeedChanceBias(0, lengthof(name_danish_1), seed, 50);
   612 	i = SeedChanceBias(0, lengthof(name_danish_1), seed, 50);
   612 	if (i >= 0)
   613 	if (i >= 0)
   613 		strcat(buf, name_danish_1[i]);
   614 		strecat(buf, name_danish_1[i], last);
   614 
   615 
   615 	// middle segments removed as this algorithm seems to create much more realistic names
   616 	// middle segments removed as this algorithm seems to create much more realistic names
   616 	strcat(buf, name_danish_2[SeedChance( 7, lengthof(name_danish_2), seed)]);
   617 	strecat(buf, name_danish_2[SeedChance( 7, lengthof(name_danish_2), seed)], last);
   617 	strcat(buf, name_danish_3[SeedChance(16, lengthof(name_danish_3), seed)]);
   618 	strecat(buf, name_danish_3[SeedChance(16, lengthof(name_danish_3), seed)], last);
   618 
   619 
   619 	return 0;
   620 	return 0;
   620 }
   621 }
   621 
   622 
   622 static byte MakeTurkishTownName(char *buf, uint32 seed)
   623 static byte MakeTurkishTownName(char *buf, uint32 seed, const char *last)
   623 {
   624 {
   624 	uint i;
   625 	uint i;
   625 
   626 
   626 	// null terminates the string for strcat
   627 	// null terminates the string for strcat
   627 	strcpy(buf, "");
   628 	strecpy(buf, "", last);
   628 
   629 
   629 	if ((i = SeedModChance(0, 5, seed)) == 0) {
   630 	if ((i = SeedModChance(0, 5, seed)) == 0) {
   630 		strcat(buf, name_turkish_prefix[SeedModChance( 2, lengthof(name_turkish_prefix), seed)]);
   631 		strecat(buf, name_turkish_prefix[SeedModChance( 2, lengthof(name_turkish_prefix), seed)], last);
   631 
   632 
   632 		// middle segment
   633 		// middle segment
   633 		strcat(buf, name_turkish_middle[SeedModChance( 4, lengthof(name_turkish_middle), seed)]);
   634 		strecat(buf, name_turkish_middle[SeedModChance( 4, lengthof(name_turkish_middle), seed)], last);
   634 
   635 
   635 		// optional suffix
   636 		// optional suffix
   636 		if (SeedModChance(0, 7, seed) == 0) {
   637 		if (SeedModChance(0, 7, seed) == 0) {
   637 			strcat(buf, name_turkish_suffix[SeedModChance( 10, lengthof(name_turkish_suffix), seed)]);
   638 			strecat(buf, name_turkish_suffix[SeedModChance( 10, lengthof(name_turkish_suffix), seed)], last);
   638 		}
   639 		}
   639 	} else {
   640 	} else {
   640 		if (i == 1 || i == 2) {
   641 		if (i == 1 || i == 2) {
   641 			strcat(buf, name_turkish_prefix[SeedModChance( 2, lengthof(name_turkish_prefix), seed)]);
   642 			strecat(buf, name_turkish_prefix[SeedModChance( 2, lengthof(name_turkish_prefix), seed)], last);
   642 			strcat(buf, name_turkish_suffix[SeedModChance( 4, lengthof(name_turkish_suffix), seed)]);
   643 			strecat(buf, name_turkish_suffix[SeedModChance( 4, lengthof(name_turkish_suffix), seed)], last);
   643 		} else {
   644 		} else {
   644 			strcat(buf, name_turkish_real[SeedModChance( 4, lengthof(name_turkish_real), seed)]);
   645 			strecat(buf, name_turkish_real[SeedModChance( 4, lengthof(name_turkish_real), seed)], last);
   645 		}
   646 		}
   646 	}
   647 	}
   647 	return 0;
   648 	return 0;
   648 }
   649 }
   649 
   650 
   650 static const char *mascul_femin_italian[] = {
   651 static const char *mascul_femin_italian[] = {
   651 	"o",
   652 	"o",
   652 	"a",
   653 	"a",
   653 };
   654 };
   654 
   655 
   655 static byte MakeItalianTownName(char *buf, uint32 seed) {
   656 static byte MakeItalianTownName(char *buf, uint32 seed, const char *last)
   656 
   657 {
   657 	strcpy(buf, "");
   658 	strecpy(buf, "", last);
   658 
   659 
   659 	if (SeedModChance(0, 6, seed) == 0) { // real city names
   660 	if (SeedModChance(0, 6, seed) == 0) { // real city names
   660 		strcat(buf, name_italian_real[SeedModChance(4, lengthof(name_italian_real), seed)]);
   661 		strecat(buf, name_italian_real[SeedModChance(4, lengthof(name_italian_real), seed)], last);
   661 	} else {
   662 	} else {
   662 		uint i;
   663 		uint i;
   663 
   664 
   664 		if (SeedModChance(0, 8, seed) == 0) { // prefix
   665 		if (SeedModChance(0, 8, seed) == 0) { // prefix
   665 			strcat(buf, name_italian_pref[SeedModChance(11, lengthof(name_italian_pref), seed)]);
   666 			strecat(buf, name_italian_pref[SeedModChance(11, lengthof(name_italian_pref), seed)], last);
   666 		}
   667 		}
   667 
   668 
   668 		i = SeedChance(0, 2, seed);
   669 		i = SeedChance(0, 2, seed);
   669 		if (i == 0) { // masculine form
   670 		if (i == 0) { // masculine form
   670 			strcat(buf, name_italian_1m[SeedModChance(4, lengthof(name_italian_1m), seed)]);
   671 			strecat(buf, name_italian_1m[SeedModChance(4, lengthof(name_italian_1m), seed)], last);
   671 		} else { // feminine form
   672 		} else { // feminine form
   672 			strcat(buf, name_italian_1f[SeedModChance(4, lengthof(name_italian_1f), seed)]);
   673 			strecat(buf, name_italian_1f[SeedModChance(4, lengthof(name_italian_1f), seed)], last);
   673 		}
   674 		}
   674 
   675 
   675 		if (SeedModChance(3, 3, seed) == 0) {
   676 		if (SeedModChance(3, 3, seed) == 0) {
   676 			strcat(buf, name_italian_2[SeedModChance(11, lengthof(name_italian_2), seed)]);
   677 			strecat(buf, name_italian_2[SeedModChance(11, lengthof(name_italian_2), seed)], last);
   677 			strcat(buf,mascul_femin_italian[i]);
   678 			strecat(buf,mascul_femin_italian[i], last);
   678 		} else {
   679 		} else {
   679 			strcat(buf, name_italian_2i[SeedModChance(16, lengthof(name_italian_2i), seed)]);
   680 			strecat(buf, name_italian_2i[SeedModChance(16, lengthof(name_italian_2i), seed)], last);
   680 		}
   681 		}
   681 
   682 
   682 		if (SeedModChance(15, 4, seed) == 0) {
   683 		if (SeedModChance(15, 4, seed) == 0) {
   683 			if (SeedModChance(5, 2, seed) == 0) { // generic suffix
   684 			if (SeedModChance(5, 2, seed) == 0) { // generic suffix
   684 				strcat(buf, name_italian_3[SeedModChance(4, lengthof(name_italian_3), seed)]);
   685 				strecat(buf, name_italian_3[SeedModChance(4, lengthof(name_italian_3), seed)], last);
   685 			} else { // river name suffix
   686 			} else { // river name suffix
   686 				strcat(buf, name_italian_river1[SeedModChance(4, lengthof(name_italian_river1), seed)]);
   687 				strecat(buf, name_italian_river1[SeedModChance(4, lengthof(name_italian_river1), seed)], last);
   687 				strcat(buf, name_italian_river2[SeedModChance(16, lengthof(name_italian_river2), seed)]);
   688 				strecat(buf, name_italian_river2[SeedModChance(16, lengthof(name_italian_river2), seed)], last);
   688 			}
   689 			}
   689 		}
   690 		}
   690 	}
   691 	}
   691 
   692 
   692 	return 0;
   693 	return 0;
   693 }
   694 }
   694 
   695 
   695 static byte MakeCatalanTownName(char *buf, uint32 seed) {
   696 static byte MakeCatalanTownName(char *buf, uint32 seed, const char *last)
   696 
   697 {
   697 	strcpy(buf, "");
   698 	strecpy(buf, "", last);
   698 
   699 
   699 	if (SeedModChance(0, 3, seed) == 0) { // real city names
   700 	if (SeedModChance(0, 3, seed) == 0) { // real city names
   700 		strcat(buf, name_catalan_real[SeedModChance(4, lengthof(name_catalan_real), seed)]);
   701 		strecat(buf, name_catalan_real[SeedModChance(4, lengthof(name_catalan_real), seed)], last);
   701 	} else {
   702 	} else {
   702 		uint i;
   703 		uint i;
   703 
   704 
   704 		if (SeedModChance(0, 2, seed) == 0) { // prefix
   705 		if (SeedModChance(0, 2, seed) == 0) { // prefix
   705 			strcat(buf, name_catalan_pref[SeedModChance(11, lengthof(name_catalan_pref), seed)]);
   706 			strecat(buf, name_catalan_pref[SeedModChance(11, lengthof(name_catalan_pref), seed)], last);
   706 		}
   707 		}
   707 
   708 
   708 		i = SeedChance(0, 2, seed);
   709 		i = SeedChance(0, 2, seed);
   709 		if (i == 0) { // masculine form
   710 		if (i == 0) { // masculine form
   710 			strcat(buf, name_catalan_1m[SeedModChance(4, lengthof(name_catalan_1m), seed)]);
   711 			strecat(buf, name_catalan_1m[SeedModChance(4, lengthof(name_catalan_1m), seed)], last);
   711 			strcat(buf, name_catalan_2m[SeedModChance(11, lengthof(name_catalan_2m), seed)]);
   712 			strecat(buf, name_catalan_2m[SeedModChance(11, lengthof(name_catalan_2m), seed)], last);
   712 		} else { // feminine form
   713 		} else { // feminine form
   713 			strcat(buf, name_catalan_1f[SeedModChance(4, lengthof(name_catalan_1f), seed)]);
   714 			strecat(buf, name_catalan_1f[SeedModChance(4, lengthof(name_catalan_1f), seed)], last);
   714 			strcat(buf, name_catalan_2f[SeedModChance(11, lengthof(name_catalan_2f), seed)]);
   715 			strecat(buf, name_catalan_2f[SeedModChance(11, lengthof(name_catalan_2f), seed)], last);
   715 		}
   716 		}
   716 
   717 
   717 
   718 
   718 		if (SeedModChance(15, 5, seed) == 0) {
   719 		if (SeedModChance(15, 5, seed) == 0) {
   719 			if (SeedModChance(5, 2, seed) == 0) { // generic suffix
   720 			if (SeedModChance(5, 2, seed) == 0) { // generic suffix
   720 				strcat(buf, name_catalan_3[SeedModChance(4, lengthof(name_catalan_3), seed)]);
   721 				strecat(buf, name_catalan_3[SeedModChance(4, lengthof(name_catalan_3), seed)], last);
   721 			} else { // river name suffix
   722 			} else { // river name suffix
   722 				strcat(buf, name_catalan_river1[SeedModChance(4, lengthof(name_catalan_river1), seed)]);
   723 				strecat(buf, name_catalan_river1[SeedModChance(4, lengthof(name_catalan_river1), seed)], last);
   723 			}
   724 			}
   724 		}
   725 		}
   725 	}
   726 	}
   726 
   727 
   727 	return 0;
   728 	return 0;