tron@2186: /* $Id$ */ tron@2186: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1299: #include "debug.h" tron@2484: #include "macros.h" tron@1306: #include "namegen.h" truelight@833: #include "table/namegen.h" peter1138@4919: #include "string.h" truelight@0: tron@996: static inline uint32 SeedChance(int shift_by, int max, uint32 seed) truelight@0: { tron@2484: return (GB(seed, shift_by, 16) * max) >> 16; tron@996: } tron@996: pasky@1447: static inline uint32 SeedModChance(int shift_by, int max, uint32 seed) pasky@1447: { pasky@1447: /* This actually gives *MUCH* more even distribution of the values pasky@1447: * than SeedChance(), which is absolutely horrible in that. If pasky@1447: * you do not believe me, try with i.e. the Czech town names, pasky@1447: * compare the words (nicely visible on prefixes) generated by pasky@1447: * SeedChance() and SeedModChance(). Do not get dicouraged by the pasky@1447: * never-use-modulo myths, which hold true only for the linear pasky@1447: * congruential generators (and Random() isn't such a generator). pasky@1447: * --pasky */ pasky@1447: // TODO: Perhaps we should use it for all the name generators? --pasky pasky@1447: return (seed >> shift_by) % max; pasky@1447: } pasky@1447: tron@996: static inline int32 SeedChanceBias(int shift_by, int max, uint32 seed, int bias) tron@996: { tron@996: return SeedChance(shift_by, max + bias, seed) - bias; truelight@0: } truelight@0: tron@1109: static void ReplaceWords(const char *org, const char *rep, char *buf) truelight@833: { tron@1107: if (strncmp(buf, org, 4) == 0) strncpy(buf, rep, 4); truelight@833: } truelight@0: peter1138@4919: static byte MakeEnglishOriginalTownName(char *buf, uint32 seed, const char *last) truelight@0: { truelight@0: int i; truelight@0: truelight@833: //null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); truelight@0: truelight@833: // optional first segment tron@996: i = SeedChanceBias(0, lengthof(name_original_english_1), seed, 50); tron@996: if (i >= 0) peter1138@4919: strecat(buf, name_original_english_1[i], last); truelight@0: truelight@833: //mandatory middle segments peter1138@4919: strecat(buf, name_original_english_2[SeedChance(4, lengthof(name_original_english_2), seed)], last); peter1138@4919: strecat(buf, name_original_english_3[SeedChance(7, lengthof(name_original_english_3), seed)], last); peter1138@4919: strecat(buf, name_original_english_4[SeedChance(10, lengthof(name_original_english_4), seed)], last); peter1138@4919: strecat(buf, name_original_english_5[SeedChance(13, lengthof(name_original_english_5), seed)], last); truelight@111: truelight@833: //optional last segment tron@996: i = SeedChanceBias(15, lengthof(name_original_english_6), seed, 60); tron@996: if (i >= 0) peter1138@4919: strecat(buf, name_original_english_6[i], last); truelight@0: truelight@833: if (buf[0] == 'C' && (buf[1] == 'e' || buf[1] == 'i')) truelight@833: buf[0] = 'K'; truelight@833: tron@1107: ReplaceWords("Cunt", "East", buf); tron@1107: ReplaceWords("Slag", "Pits", buf); tron@1107: ReplaceWords("Slut", "Edin", buf); tron@1107: //ReplaceWords("Fart", "Boot", buf); tron@1107: ReplaceWords("Drar", "Quar", buf); tron@1107: ReplaceWords("Dreh", "Bash", buf); tron@1107: ReplaceWords("Frar", "Shor", buf); tron@1107: ReplaceWords("Grar", "Aber", buf); tron@1107: ReplaceWords("Brar", "Over", buf); tron@1107: ReplaceWords("Wrar", "Inve", buf); truelight@833: truelight@833: return 0; truelight@0: } truelight@0: truelight@0: peter1138@4919: static byte MakeEnglishAdditionalTownName(char *buf, uint32 seed, const char *last) truelight@833: { truelight@833: int i; truelight@0: truelight@833: //null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); truelight@0: truelight@833: // optional first segment tron@996: i = SeedChanceBias(0, lengthof(name_additional_english_prefix), seed, 50); tron@996: if (i >= 0) peter1138@4919: strecat(buf,name_additional_english_prefix[i], last); truelight@0: tron@996: if (SeedChance(3, 20, seed) >= 14) { peter1138@4919: strecat(buf, name_additional_english_1a[SeedChance(6, lengthof(name_additional_english_1a), seed)], last); tron@993: } else { peter1138@4919: strecat(buf, name_additional_english_1b1[SeedChance(6, lengthof(name_additional_english_1b1), seed)], last); peter1138@4919: strecat(buf, name_additional_english_1b2[SeedChance(9, lengthof(name_additional_english_1b2), seed)], last); tron@996: if (SeedChance(11, 20, seed) >= 4) { peter1138@4919: strecat(buf, name_additional_english_1b3a[SeedChance(12, lengthof(name_additional_english_1b3a), seed)], last); tron@993: } else { peter1138@4919: strecat(buf, name_additional_english_1b3b[SeedChance(12, lengthof(name_additional_english_1b3b), seed)], last); truelight@833: } truelight@833: } truelight@0: peter1138@4919: strecat(buf, name_additional_english_2[SeedChance(14, lengthof(name_additional_english_2), seed)], last); truelight@833: truelight@833: //optional last segment tron@996: i = SeedChanceBias(15, lengthof(name_additional_english_3), seed, 60); tron@996: if (i >= 0) peter1138@4919: strecat(buf, name_additional_english_3[i], last); truelight@833: tron@1107: ReplaceWords("Cunt", "East", buf); tron@1107: ReplaceWords("Slag", "Pits", buf); tron@1107: ReplaceWords("Slut", "Edin", buf); tron@1107: ReplaceWords("Fart", "Boot", buf); tron@1107: ReplaceWords("Drar", "Quar", buf); tron@1107: ReplaceWords("Dreh", "Bash", buf); tron@1107: ReplaceWords("Frar", "Shor", buf); tron@1107: ReplaceWords("Grar", "Aber", buf); tron@1107: ReplaceWords("Brar", "Over", buf); tron@1107: ReplaceWords("Wrar", "Stan", buf); truelight@833: truelight@833: return 0; truelight@833: } truelight@0: peter1138@4919: static byte MakeAustrianTownName(char *buf, uint32 seed, const char *last) truelight@0: { truelight@833: int i, j = 0; peter1138@4919: strecpy(buf, "", last); truelight@0: truelight@0: // Bad, Maria, Gross, ... tron@996: i = SeedChanceBias(0, lengthof(name_austrian_a1), seed, 15); peter1138@4919: if (i >= 0) strecat(buf, name_austrian_a1[i], last); truelight@833: tron@996: i = SeedChance(4, 6, seed); tron@993: if (i >= 4) { truelight@833: // Kaisers-kirchen peter1138@4919: strecat(buf, name_austrian_a2[SeedChance( 7, lengthof(name_austrian_a2), seed)], last); peter1138@4919: strecat(buf, name_austrian_a3[SeedChance(13, lengthof(name_austrian_a3), seed)], last); tron@993: } else if (i >= 2) { truelight@833: // St. Johann peter1138@4919: strecat(buf, name_austrian_a5[SeedChance( 7, lengthof(name_austrian_a5), seed)], last); peter1138@4919: strecat(buf, name_austrian_a6[SeedChance( 9, lengthof(name_austrian_a6), seed)], last); truelight@833: j = 1; // More likely to have a " an der " or " am " tron@993: } else { truelight@833: // Zell peter1138@4919: strecat(buf, name_austrian_a4[SeedChance( 7, lengthof(name_austrian_a4), seed)], last); truelight@0: } truelight@0: tron@996: i = SeedChance(1, 6, seed); tron@993: if (i >= 4 - j) { truelight@833: // an der Donau (rivers) peter1138@4919: strecat(buf, name_austrian_f1[SeedChance(4, lengthof(name_austrian_f1), seed)], last); peter1138@4919: strecat(buf, name_austrian_f2[SeedChance(5, lengthof(name_austrian_f2), seed)], last); tron@993: } else if (i >= 2 - j) { truelight@833: // am Dachstein (mountains) peter1138@4919: strecat(buf, name_austrian_b1[SeedChance(4, lengthof(name_austrian_b1), seed)], last); peter1138@4919: strecat(buf, name_austrian_b2[SeedChance(5, lengthof(name_austrian_b2), seed)], last); truelight@0: } truelight@0: truelight@0: return 0; truelight@0: } truelight@0: peter1138@4919: static byte MakeGermanTownName(char *buf, uint32 seed, const char *last) truelight@0: { tron@992: uint i; tron@992: uint seed_derivative; truelight@0: truelight@833: //null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); truelight@833: tron@996: seed_derivative = SeedChance(7, 28, seed); tron@992: tron@992: //optional prefix tron@992: if (seed_derivative == 12 || seed_derivative == 19) { tron@996: i = SeedChance(2, lengthof(name_german_pre), seed); peter1138@4919: strecat(buf,name_german_pre[i], last); darkvater@4: } truelight@0: truelight@833: // mandatory middle segments including option of hardcoded name pasky@1422: i = SeedChance(3, lengthof(name_german_real) + lengthof(name_german_1), seed); pasky@1422: if (i < lengthof(name_german_real)) { peter1138@4919: strecat(buf,name_german_real[i], last); tron@993: } else { peter1138@4919: strecat(buf, name_german_1[i - lengthof(name_german_real)], last); tron@992: tron@996: i = SeedChance(5, lengthof(name_german_2), seed); peter1138@4919: strecat(buf, name_german_2[i], last); truelight@833: } truelight@833: tron@992: // optional suffix tron@992: if (seed_derivative == 24) { tron@996: i = SeedChance(9, tron@992: lengthof(name_german_4_an_der) + lengthof(name_german_4_am), seed); tron@992: if (i < lengthof(name_german_4_an_der)) { peter1138@4919: strecat(buf, name_german_3_an_der[0], last); peter1138@4919: strecat(buf, name_german_4_an_der[i], last); truelight@833: } else { peter1138@4919: strecat(buf, name_german_3_am[0], last); peter1138@4919: strecat(buf, name_german_4_am[i - lengthof(name_german_4_an_der)], last); truelight@833: } truelight@833: } truelight@833: return 0; truelight@833: } truelight@0: peter1138@4919: static byte MakeSpanishTownName(char *buf, uint32 seed, const char *last) truelight@833: { peter1138@4919: strecpy(buf, name_spanish_real[SeedChance(0, lengthof(name_spanish_real), seed)], last); truelight@833: return 0; truelight@833: } truelight@0: peter1138@4919: static byte MakeFrenchTownName(char *buf, uint32 seed, const char *last) truelight@833: { peter1138@4919: strecpy(buf, name_french_real[SeedChance(0, lengthof(name_french_real), seed)], last); truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakeSillyTownName(char *buf, uint32 seed, const char *last) truelight@833: { peter1138@4919: strecpy(buf, name_silly_1[SeedChance( 0, lengthof(name_silly_1), seed)], last); peter1138@4919: strecat(buf, name_silly_2[SeedChance(16, lengthof(name_silly_2), seed)], last); truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakeSwedishTownName(char *buf, uint32 seed, const char *last) truelight@833: { truelight@833: int i; truelight@833: truelight@833: //null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); truelight@833: truelight@833: // optional first segment tron@996: i = SeedChanceBias(0, lengthof(name_swedish_1), seed, 50); tron@996: if (i >= 0) peter1138@4919: strecat(buf, name_swedish_1[i], last); truelight@0: truelight@833: // mandatory middle segments including option of hardcoded name tron@996: if (SeedChance(4, 5, seed) >= 3) { peter1138@4919: strecat(buf, name_swedish_2[SeedChance( 7, lengthof(name_swedish_2), seed)], last); tron@993: } else { peter1138@4919: strecat(buf, name_swedish_2a[SeedChance( 7, lengthof(name_swedish_2a), seed)], last); peter1138@4919: strecat(buf, name_swedish_2b[SeedChance(10, lengthof(name_swedish_2b), seed)], last); peter1138@4919: strecat(buf, name_swedish_2c[SeedChance(13, lengthof(name_swedish_2c), seed)], last); truelight@833: } truelight@0: peter1138@4919: strecat(buf, name_swedish_3[SeedChance(16, lengthof(name_swedish_3), seed)], last); truelight@833: truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakeDutchTownName(char *buf, uint32 seed, const char *last) truelight@833: { truelight@833: int i; truelight@833: truelight@833: //null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); truelight@833: truelight@833: // optional first segment tron@996: i = SeedChanceBias(0, lengthof(name_dutch_1), seed, 50); tron@996: if (i >= 0) peter1138@4919: strecat(buf, name_dutch_1[i], last); truelight@833: truelight@833: // mandatory middle segments including option of hardcoded name tron@996: if (SeedChance(6, 9, seed) > 4) { peter1138@4919: strecat(buf, name_dutch_2[SeedChance( 9, lengthof(name_dutch_2), seed)], last); tron@993: } else { peter1138@4919: strecat(buf, name_dutch_3[SeedChance( 9, lengthof(name_dutch_3), seed)], last); peter1138@4919: strecat(buf, name_dutch_4[SeedChance(12, lengthof(name_dutch_4), seed)], last); truelight@833: } peter1138@4919: strecat(buf, name_dutch_5[SeedChance(15, lengthof(name_dutch_5), seed)], last); truelight@833: truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakeFinnishTownName(char *buf, uint32 seed, const char *last) truelight@833: { truelight@833: //null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); truelight@833: truelight@833: // Select randomly if town name should consists of one or two parts. tron@996: if (SeedChance(0, 15, seed) >= 10) { peter1138@4919: strecat(buf, name_finnish_real[SeedChance(2, lengthof(name_finnish_real), seed)], last); tron@4077: } else if (SeedChance(0, 15, seed) >= 5) { tron@4077: // A two-part name by combining one of name_finnish_1 + "la"/"lä" tron@4077: // The reason for not having the contents of name_finnish_{1,2} in the same table is tron@4077: // that the ones in name_finnish_2 are not good for this purpose. bjarni@3106: uint sel = SeedChance( 0, lengthof(name_finnish_1), seed); peter1138@4919: char *end; peter1138@4919: strecat(buf, name_finnish_1[sel], last); peter1138@4919: end = &buf[strlen(buf)-1]; peter1138@4919: if (*end == 'i') peter1138@4919: *end = 'e'; bjarni@3106: if (strstr(buf, "a") || strstr(buf, "o") || strstr(buf, "u") || bjarni@3106: strstr(buf, "A") || strstr(buf, "O") || strstr(buf, "U")) bjarni@3106: { peter1138@4919: strecat(buf, "la", last); bjarni@3106: } else { peter1138@4919: strecat(buf, "lä", last); bjarni@3106: } tron@4077: } else { tron@4077: // A two-part name by combining one of name_finnish_{1,2} + name_finnish_3. tron@4077: // Why aren't name_finnish_{1,2} just one table? See above. bjarni@3106: uint sel = SeedChance(2, bjarni@3106: lengthof(name_finnish_1) + lengthof(name_finnish_2), seed); bjarni@3106: if (sel >= lengthof(name_finnish_1)) { peter1138@4919: strecat(buf, name_finnish_2[sel-lengthof(name_finnish_1)], last); bjarni@3106: } else { peter1138@4919: strecat(buf, name_finnish_1[sel], last); bjarni@3106: } peter1138@4919: strecat(buf, name_finnish_3[SeedChance(10, lengthof(name_finnish_3), seed)], last); truelight@833: } truelight@833: truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakePolishTownName(char *buf, uint32 seed, const char *last) truelight@833: { tron@959: uint i; tron@959: uint j; truelight@833: truelight@833: //null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); truelight@833: truelight@833: // optional first segment tron@996: i = SeedChance(0, tron@993: lengthof(name_polish_2_o) + lengthof(name_polish_2_m) + tron@993: lengthof(name_polish_2_f) + lengthof(name_polish_2_n), tron@993: seed); tron@996: j = SeedChance(2, 20, seed); truelight@833: truelight@833: tron@993: if (i < lengthof(name_polish_2_o)) { peter1138@4919: strecat(buf, name_polish_2_o[SeedChance(3, lengthof(name_polish_2_o), seed)], last); tron@993: } else if (i < lengthof(name_polish_2_m) + lengthof(name_polish_2_o)) { truelight@833: if (j < 4) peter1138@4919: strecat(buf, name_polish_1_m[SeedChance(5, lengthof(name_polish_1_m), seed)], last); truelight@833: peter1138@4919: strecat(buf, name_polish_2_m[SeedChance(7, lengthof(name_polish_2_m), seed)], last); truelight@833: truelight@833: if (j >= 4 && j < 16) peter1138@4919: strecat(buf, name_polish_3_m[SeedChance(10, lengthof(name_polish_3_m), seed)], last); tron@993: } else if (i < lengthof(name_polish_2_f) + lengthof(name_polish_2_m) + lengthof(name_polish_2_o)) { truelight@833: if (j < 4) peter1138@4919: strecat(buf, name_polish_1_f[SeedChance(5, lengthof(name_polish_1_f), seed)], last); truelight@833: peter1138@4919: strecat(buf, name_polish_2_f[SeedChance(7, lengthof(name_polish_2_f), seed)], last); truelight@833: truelight@833: if (j >= 4 && j < 16) peter1138@4919: strecat(buf, name_polish_3_f[SeedChance(10, lengthof(name_polish_3_f), seed)], last); tron@993: } else { truelight@833: if (j < 4) peter1138@4919: strecat(buf, name_polish_1_n[SeedChance(5, lengthof(name_polish_1_n), seed)], last); truelight@833: peter1138@4919: strecat(buf, name_polish_2_n[SeedChance(7, lengthof(name_polish_2_n), seed)], last); truelight@833: truelight@833: if (j >= 4 && j < 16) peter1138@4919: strecat(buf, name_polish_3_n[SeedChance(10, lengthof(name_polish_3_n), seed)], last); truelight@833: } truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakeCzechTownName(char *buf, uint32 seed, const char *last) truelight@833: { pasky@1425: /* Probability of prefixes/suffixes */ pasky@1425: /* 0..11 prefix, 12..13 prefix+suffix, 14..17 suffix, 18..31 nothing */ pasky@1425: int prob_tails; pasky@1425: bool do_prefix, do_suffix, dynamic_subst; pasky@1425: /* IDs of the respective parts */ tron@1473: int prefix = 0, ending = 0, suffix = 0; tron@1473: uint postfix = 0; tron@1473: uint stem; pasky@1425: /* The select criteria. */ tron@1473: CzechGender gender; tron@1473: CzechChoose choose; tron@1473: CzechAllow allow; pasky@1425: pasky@1425: // 1:3 chance to use a real name. pasky@1447: if (SeedModChance(0, 4, seed) == 0) { peter1138@4919: strecpy(buf, name_czech_real[SeedModChance(4, lengthof(name_czech_real), seed)], last); pasky@1425: return 0; pasky@1425: } pasky@1425: pasky@1425: // NUL terminates the string for strcat() peter1138@4919: strecpy(buf, "", last); pasky@1425: pasky@1447: prob_tails = SeedModChance(2, 32, seed); pasky@1425: do_prefix = prob_tails < 12; pasky@1425: do_suffix = prob_tails > 11 && prob_tails < 17; pasky@1425: pasky@1447: if (do_prefix) prefix = SeedModChance(5, lengthof(name_czech_adj) * 12, seed) / 12; pasky@1447: if (do_suffix) suffix = SeedModChance(7, lengthof(name_czech_suffix), seed); pasky@1425: // 3:1 chance 3:1 to use dynamic substantive tron@1473: stem = SeedModChance(9, tron@1473: lengthof(name_czech_subst_full) + 3 * lengthof(name_czech_subst_stem), tron@1473: seed); tron@1473: if (stem < lengthof(name_czech_subst_full)) { pasky@1425: // That was easy! pasky@1425: dynamic_subst = false; pasky@1425: gender = name_czech_subst_full[stem].gender; pasky@1425: choose = name_czech_subst_full[stem].choose; pasky@1425: allow = name_czech_subst_full[stem].allow; pasky@1425: } else { pasky@1425: unsigned int map[lengthof(name_czech_subst_ending)]; pasky@1425: int ending_start = -1, ending_stop = -1; pasky@1425: int i; pasky@1425: pasky@1425: // Load the substantive pasky@1425: dynamic_subst = true; pasky@1425: stem -= lengthof(name_czech_subst_full); pasky@1425: stem %= lengthof(name_czech_subst_stem); pasky@1425: gender = name_czech_subst_stem[stem].gender; pasky@1425: choose = name_czech_subst_stem[stem].choose; pasky@1425: allow = name_czech_subst_stem[stem].allow; pasky@1425: pasky@1425: // Load the postfix (1:1 chance that a postfix will be inserted) pasky@1447: postfix = SeedModChance(14, lengthof(name_czech_subst_postfix) * 2, seed); pasky@1425: pasky@1425: if (choose & CZC_POSTFIX) { pasky@1425: // Always get a real postfix. pasky@1425: postfix %= lengthof(name_czech_subst_postfix); pasky@1425: } pasky@1425: if (choose & CZC_NOPOSTFIX) { pasky@1425: // Always drop a postfix. pasky@1425: postfix += lengthof(name_czech_subst_postfix); pasky@1425: } tron@4077: if (postfix < lengthof(name_czech_subst_postfix)) { pasky@1425: choose |= CZC_POSTFIX; tron@4077: } else { pasky@1425: choose |= CZC_NOPOSTFIX; tron@4077: } pasky@1425: pasky@1425: // Localize the array segment containing a good gender pasky@1425: for (ending = 0; ending < (int) lengthof(name_czech_subst_ending); ending++) { tron@1473: const CzechNameSubst *e = &name_czech_subst_ending[ending]; pasky@1425: tron@1473: if (gender == CZG_FREE || tron@1473: (gender == CZG_NFREE && e->gender != CZG_SNEUT && e->gender != CZG_PNEUT) || tron@1473: gender == e->gender) { pasky@1425: if (ending_start < 0) pasky@1425: ending_start = ending; pasky@1425: pasky@1425: } else if (ending_start >= 0) { pasky@1425: ending_stop = ending - 1; pasky@1425: break; pasky@1425: } pasky@1425: } pasky@1425: if (ending_stop < 0) { pasky@1425: // Whoa. All the endings matched. pasky@1425: ending_stop = ending - 1; pasky@1425: } pasky@1425: pasky@1425: // Make a sequential map of the items with good mask pasky@1425: i = 0; pasky@1425: for (ending = ending_start; ending <= ending_stop; ending++) { tron@1473: const CzechNameSubst *e = &name_czech_subst_ending[ending]; pasky@1425: pasky@1425: if ((e->choose & choose) == choose && (e->allow & allow) != 0) pasky@1425: map[i++] = ending; pasky@1425: } pasky@1425: assert(i > 0); pasky@1425: pasky@1425: // Load the ending pasky@1447: ending = map[SeedModChance(16, i, seed)]; pasky@1425: // Override possible CZG_*FREE; this must be a real gender, pasky@1425: // otherwise we get overflow when modifying the adjectivum. pasky@1425: gender = name_czech_subst_ending[ending].gender; pasky@1425: assert(gender != CZG_FREE && gender != CZG_NFREE); pasky@1425: } pasky@1425: pasky@1425: if (do_prefix && (name_czech_adj[prefix].choose & choose) != choose) { pasky@1425: // Throw away non-matching prefix. pasky@1425: do_prefix = false; pasky@1425: } pasky@1425: pasky@1425: // Now finally construct the name pasky@1425: pasky@1425: if (do_prefix) { tron@1473: CzechPattern pattern = name_czech_adj[prefix].pattern; truelight@4321: size_t endpos; pasky@1425: peter1138@4919: strecat(buf, name_czech_adj[prefix].name, last); pasky@1425: endpos = strlen(buf) - 1; peter1138@5108: /* Find the first character in a UTF-8 sequence */ peter1138@5108: while (GB(buf[endpos], 6, 2) == 2) endpos--; pasky@1425: if (gender == CZG_SMASC && pattern == CZP_PRIVL) { pasky@1425: /* -ovX -> -uv */ pasky@1425: buf[endpos - 2] = 'u'; pasky@1425: assert(buf[endpos - 1] == 'v'); pasky@1425: buf[endpos] = '\0'; pasky@1425: } else { peter1138@5108: strecpy(buf + endpos, name_czech_patmod[gender][pattern], last); pasky@1425: } pasky@1425: peter1138@4919: strecat(buf, " ", last); pasky@1425: } pasky@1425: pasky@1425: if (dynamic_subst) { peter1138@4919: strecat(buf, name_czech_subst_stem[stem].name, last); tron@1473: if (postfix < lengthof(name_czech_subst_postfix)) { pasky@1426: const char *poststr = name_czech_subst_postfix[postfix]; pasky@1426: const char *endstr = name_czech_subst_ending[ending].name; truelight@4321: size_t postlen, endlen; pasky@1425: pasky@1426: postlen = strlen(poststr); pasky@1426: endlen = strlen(endstr); pasky@1426: assert(postlen > 0 && endlen > 0); pasky@1426: pasky@1425: // Kill the "avava" and "Jananna"-like cases tron@1473: if (postlen < 2 || postlen > endlen || ( tron@1473: (poststr[1] != 'v' || poststr[1] != endstr[1]) && tron@1473: poststr[2] != endstr[1]) tron@1473: ) { truelight@4321: size_t buflen; peter1138@4919: strecat(buf, poststr, last); pasky@1426: buflen = strlen(buf); pasky@1426: pasky@1426: // k-i -> c-i, h-i -> z-i pasky@1426: if (endstr[0] == 'i') { tron@1473: switch (buf[buflen - 1]) { tron@1473: case 'k': buf[buflen - 1] = 'c'; break; tron@1473: case 'h': buf[buflen - 1] = 'z'; break; tron@1473: default: break; tron@1473: } pasky@1426: } pasky@1426: } pasky@1425: } peter1138@4919: strecat(buf, name_czech_subst_ending[ending].name, last); pasky@1425: } else { peter1138@4919: strecat(buf, name_czech_subst_full[stem].name, last); pasky@1425: } pasky@1425: pasky@1425: if (do_suffix) { peter1138@4919: strecat(buf, " ", last); peter1138@4919: strecat(buf, name_czech_suffix[suffix], last); pasky@1425: } pasky@1425: truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakeRomanianTownName(char *buf, uint32 seed, const char *last) truelight@833: { peter1138@4919: strecpy(buf, name_romanian_real[SeedChance(0, lengthof(name_romanian_real), seed)], last); truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakeSlovakTownName(char *buf, uint32 seed, const char *last) truelight@833: { peter1138@4919: strecpy(buf, name_slovak_real[SeedChance(0, lengthof(name_slovak_real), seed)], last); truelight@833: return 0; truelight@833: } truelight@833: peter1138@4919: static byte MakeNorwegianTownName(char *buf, uint32 seed, const char *last) miham@948: { peter1138@4919: strecpy(buf, "", last); miham@958: miham@958: // Use first 4 bit from seed to decide whether or not this town should miham@958: // have a real name 3/16 chance. Bit 0-3 tron@996: if (SeedChance(0, 15, seed) < 3) { miham@958: // Use 7bit for the realname table index. Bit 4-10 peter1138@4919: strecat(buf, name_norwegian_real[SeedChance(4, lengthof(name_norwegian_real), seed)], last); tron@993: } else { miham@958: // Use 7bit for the first fake part. Bit 4-10 peter1138@4919: strecat(buf, name_norwegian_1[SeedChance(4, lengthof(name_norwegian_1), seed)], last); miham@958: // Use 7bit for the last fake part. Bit 11-17 peter1138@4919: strecat(buf, name_norwegian_2[SeedChance(11, lengthof(name_norwegian_2), seed)], last); miham@958: } miham@958: miham@948: return 0; miham@948: } miham@948: peter1138@4919: static byte MakeHungarianTownName(char *buf, uint32 seed, const char *last) truelight@833: { tron@959: uint i; truelight@833: truelight@833: //null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); truelight@833: tron@996: if (SeedChance(12, 15, seed) < 3) { peter1138@4919: strecat(buf, name_hungarian_real[SeedChance(0, lengthof(name_hungarian_real), seed)], last); tron@993: } else { truelight@833: // optional first segment tron@996: i = SeedChance(3, lengthof(name_hungarian_1) * 3, seed); tron@992: if (i < lengthof(name_hungarian_1)) peter1138@4919: strecat(buf, name_hungarian_1[i], last); truelight@833: truelight@833: // mandatory middle segments peter1138@4919: strecat(buf, name_hungarian_2[SeedChance(3, lengthof(name_hungarian_2), seed)], last); peter1138@4919: strecat(buf, name_hungarian_3[SeedChance(6, lengthof(name_hungarian_3), seed)], last); truelight@833: truelight@833: // optional last segment tron@996: i = SeedChance(10, lengthof(name_hungarian_4) * 3, seed); tron@996: if (i < lengthof(name_hungarian_4)) { peter1138@4919: strecat(buf, name_hungarian_4[i], last); truelight@0: } darkvater@4: } truelight@0: truelight@0: return 0; truelight@0: } truelight@0: peter1138@4919: static byte MakeSwissTownName(char *buf, uint32 seed, const char *last) darkvater@1030: { peter1138@4919: strecpy(buf, name_swiss_real[SeedChance(0, lengthof(name_swiss_real), seed)], last); darkvater@1030: return 0; darkvater@1030: } darkvater@1030: peter1138@4919: static byte MakeDanishTownName(char *buf, uint32 seed, const char *last) Darkvater@2431: { Darkvater@2431: int i; Darkvater@2431: Darkvater@2431: // null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); Darkvater@2431: Darkvater@2431: // optional first segment Darkvater@2431: i = SeedChanceBias(0, lengthof(name_danish_1), seed, 50); Darkvater@2431: if (i >= 0) peter1138@4919: strecat(buf, name_danish_1[i], last); Darkvater@2431: Darkvater@2431: // middle segments removed as this algorithm seems to create much more realistic names peter1138@4919: strecat(buf, name_danish_2[SeedChance( 7, lengthof(name_danish_2), seed)], last); peter1138@4919: strecat(buf, name_danish_3[SeedChance(16, lengthof(name_danish_3), seed)], last); Darkvater@2431: Darkvater@2431: return 0; Darkvater@2431: } Darkvater@2431: peter1138@4919: static byte MakeTurkishTownName(char *buf, uint32 seed, const char *last) celestar@3698: { celestar@3698: uint i; celestar@3698: celestar@3698: // null terminates the string for strcat peter1138@4919: strecpy(buf, "", last); celestar@3698: celestar@3698: if ((i = SeedModChance(0, 5, seed)) == 0) { peter1138@4919: strecat(buf, name_turkish_prefix[SeedModChance( 2, lengthof(name_turkish_prefix), seed)], last); celestar@3698: celestar@3698: // middle segment peter1138@4919: strecat(buf, name_turkish_middle[SeedModChance( 4, lengthof(name_turkish_middle), seed)], last); celestar@3698: celestar@3698: // optional suffix celestar@3698: if (SeedModChance(0, 7, seed) == 0) { peter1138@4919: strecat(buf, name_turkish_suffix[SeedModChance( 10, lengthof(name_turkish_suffix), seed)], last); celestar@3698: } celestar@3698: } else { celestar@3698: if (i == 1 || i == 2) { peter1138@4919: strecat(buf, name_turkish_prefix[SeedModChance( 2, lengthof(name_turkish_prefix), seed)], last); peter1138@4919: strecat(buf, name_turkish_suffix[SeedModChance( 4, lengthof(name_turkish_suffix), seed)], last); celestar@3698: } else { peter1138@4919: strecat(buf, name_turkish_real[SeedModChance( 4, lengthof(name_turkish_real), seed)], last); celestar@3698: } celestar@3698: } celestar@3698: return 0; celestar@3698: } celestar@3698: belugas@4148: static const char *mascul_femin_italian[] = { belugas@4148: "o", belugas@4148: "a", belugas@4148: }; belugas@4148: peter1138@4919: static byte MakeItalianTownName(char *buf, uint32 seed, const char *last) peter1138@4919: { peter1138@4919: strecpy(buf, "", last); belugas@4143: belugas@4148: if (SeedModChance(0, 6, seed) == 0) { // real city names peter1138@4919: strecat(buf, name_italian_real[SeedModChance(4, lengthof(name_italian_real), seed)], last); belugas@4143: } else { belugas@4148: uint i; belugas@4148: belugas@4148: if (SeedModChance(0, 8, seed) == 0) { // prefix peter1138@4919: strecat(buf, name_italian_pref[SeedModChance(11, lengthof(name_italian_pref), seed)], last); belugas@4143: } belugas@4143: belugas@4148: i = SeedChance(0, 2, seed); belugas@4143: if (i == 0) { // masculine form peter1138@4919: strecat(buf, name_italian_1m[SeedModChance(4, lengthof(name_italian_1m), seed)], last); belugas@4148: } else { // feminine form peter1138@4919: strecat(buf, name_italian_1f[SeedModChance(4, lengthof(name_italian_1f), seed)], last); belugas@4143: } belugas@4143: belugas@4148: if (SeedModChance(3, 3, seed) == 0) { peter1138@4919: strecat(buf, name_italian_2[SeedModChance(11, lengthof(name_italian_2), seed)], last); peter1138@4919: strecat(buf,mascul_femin_italian[i], last); belugas@4143: } else { peter1138@4919: strecat(buf, name_italian_2i[SeedModChance(16, lengthof(name_italian_2i), seed)], last); belugas@4143: } belugas@4143: belugas@4143: if (SeedModChance(15, 4, seed) == 0) { belugas@4148: if (SeedModChance(5, 2, seed) == 0) { // generic suffix peter1138@4919: strecat(buf, name_italian_3[SeedModChance(4, lengthof(name_italian_3), seed)], last); belugas@4148: } else { // river name suffix peter1138@4919: strecat(buf, name_italian_river1[SeedModChance(4, lengthof(name_italian_river1), seed)], last); peter1138@4919: strecat(buf, name_italian_river2[SeedModChance(16, lengthof(name_italian_river2), seed)], last); belugas@4143: } belugas@4143: } belugas@4143: } belugas@4143: belugas@4143: return 0; belugas@4143: } belugas@4143: peter1138@4919: static byte MakeCatalanTownName(char *buf, uint32 seed, const char *last) peter1138@4919: { peter1138@4919: strecpy(buf, "", last); bjarni@4312: bjarni@4312: if (SeedModChance(0, 3, seed) == 0) { // real city names peter1138@4919: strecat(buf, name_catalan_real[SeedModChance(4, lengthof(name_catalan_real), seed)], last); bjarni@4312: } else { bjarni@4312: uint i; bjarni@4441: bjarni@4312: if (SeedModChance(0, 2, seed) == 0) { // prefix peter1138@4919: strecat(buf, name_catalan_pref[SeedModChance(11, lengthof(name_catalan_pref), seed)], last); bjarni@4312: } bjarni@4441: bjarni@4441: i = SeedChance(0, 2, seed); bjarni@4441: if (i == 0) { // masculine form peter1138@4919: strecat(buf, name_catalan_1m[SeedModChance(4, lengthof(name_catalan_1m), seed)], last); peter1138@4919: strecat(buf, name_catalan_2m[SeedModChance(11, lengthof(name_catalan_2m), seed)], last); bjarni@4441: } else { // feminine form peter1138@4919: strecat(buf, name_catalan_1f[SeedModChance(4, lengthof(name_catalan_1f), seed)], last); peter1138@4919: strecat(buf, name_catalan_2f[SeedModChance(11, lengthof(name_catalan_2f), seed)], last); bjarni@4441: } bjarni@4312: bjarni@4312: bjarni@4441: if (SeedModChance(15, 5, seed) == 0) { bjarni@4441: if (SeedModChance(5, 2, seed) == 0) { // generic suffix peter1138@4919: strecat(buf, name_catalan_3[SeedModChance(4, lengthof(name_catalan_3), seed)], last); bjarni@4441: } else { // river name suffix peter1138@4919: strecat(buf, name_catalan_river1[SeedModChance(4, lengthof(name_catalan_river1), seed)], last); bjarni@4312: } bjarni@4312: } bjarni@4312: } bjarni@4312: bjarni@4312: return 0; bjarni@4312: } bjarni@4312: bjarni@4312: bjarni@4312: tron@993: TownNameGenerator * const _town_name_generators[] = tron@993: { truelight@833: MakeEnglishOriginalTownName, truelight@0: MakeFrenchTownName, truelight@0: MakeGermanTownName, truelight@833: MakeEnglishAdditionalTownName, truelight@0: MakeSpanishTownName, truelight@0: MakeSillyTownName, truelight@0: MakeSwedishTownName, truelight@0: MakeDutchTownName, truelight@0: MakeFinnishTownName, truelight@0: MakePolishTownName, tron@428: MakeSlovakTownName, miham@948: MakeNorwegianTownName, truelight@0: MakeHungarianTownName, darkvater@233: MakeAustrianTownName, dominik@264: MakeRomanianTownName, dominik@264: MakeCzechTownName, darkvater@1030: MakeSwissTownName, Darkvater@2431: MakeDanishTownName, celestar@3698: MakeTurkishTownName, belugas@4143: MakeItalianTownName, bjarni@4312: MakeCatalanTownName, truelight@0: }; darkvater@4: truelight@833: // DO WE NEED THIS ANY MORE? darkvater@4: #define FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z) darkvater@4: darkvater@4: uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type) darkvater@4: { darkvater@4: switch (old_town_name_type) { darkvater@4: case 0: case 3: /* English, American */ rubidium@4434: /* Already OK */ darkvater@4: return townnameparts; tron@993: darkvater@4: case 1: /* French */ rubidium@4434: /* For some reason 86 needs to be subtracted from townnameparts rubidium@4434: * 0000 0000 0000 0000 0000 0000 1111 1111 */ pasky@1422: return FIXNUM(townnameparts - 86, lengthof(name_french_real), 0); tron@993: darkvater@4: case 2: /* German */ Darkvater@5568: DEBUG(misc, 0, "German Townnames are buggy (%d)", townnameparts); darkvater@4: return townnameparts; tron@993: darkvater@4: case 4: /* Latin-American */ rubidium@4434: /* 0000 0000 0000 0000 0000 0000 1111 1111 */ pasky@1422: return FIXNUM(townnameparts, lengthof(name_spanish_real), 0); tron@993: darkvater@4: case 5: /* Silly */ rubidium@4434: /* NUM_SILLY_1 - lower 16 bits rubidium@4434: * NUM_SILLY_2 - upper 16 bits without leading 1 (first 8 bytes) rubidium@4434: * 1000 0000 2222 2222 0000 0000 1111 1111 */ tron@2549: return FIXNUM(townnameparts, lengthof(name_silly_1), 0) | FIXNUM(GB(townnameparts, 16, 8), lengthof(name_silly_2), 16); darkvater@4: } darkvater@4: return 0; darkvater@4: }