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" 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: tron@1307: static byte MakeEnglishOriginalTownName(char *buf, uint32 seed) truelight@0: { truelight@0: int i; truelight@0: truelight@833: //null terminates the string for strcat truelight@833: strcpy(buf, ""); truelight@0: truelight@833: // optional first segment tron@996: i = SeedChanceBias(0, lengthof(name_original_english_1), seed, 50); tron@996: if (i >= 0) truelight@833: strcat(buf,name_original_english_1[i]); truelight@0: truelight@833: //mandatory middle segments tron@996: strcat(buf, name_original_english_2[SeedChance(4, lengthof(name_original_english_2), seed)]); tron@996: strcat(buf, name_original_english_3[SeedChance(7, lengthof(name_original_english_3), seed)]); tron@996: strcat(buf, name_original_english_4[SeedChance(10, lengthof(name_original_english_4), seed)]); tron@996: strcat(buf, name_original_english_5[SeedChance(13, lengthof(name_original_english_5), seed)]); truelight@111: truelight@833: //optional last segment tron@996: i = SeedChanceBias(15, lengthof(name_original_english_6), seed, 60); tron@996: if (i >= 0) truelight@833: strcat(buf, name_original_english_6[i]); 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: tron@1307: static byte MakeEnglishAdditionalTownName(char *buf, uint32 seed) truelight@833: { truelight@833: int i; truelight@0: truelight@833: //null terminates the string for strcat truelight@833: strcpy(buf, ""); truelight@0: truelight@833: // optional first segment tron@996: i = SeedChanceBias(0, lengthof(name_additional_english_prefix), seed, 50); tron@996: if (i >= 0) truelight@833: strcat(buf,name_additional_english_prefix[i]); truelight@0: tron@996: if (SeedChance(3, 20, seed) >= 14) { tron@996: strcat(buf, name_additional_english_1a[SeedChance(6, lengthof(name_additional_english_1a), seed)]); tron@993: } else { tron@996: strcat(buf, name_additional_english_1b1[SeedChance(6, lengthof(name_additional_english_1b1), seed)]); tron@996: strcat(buf, name_additional_english_1b2[SeedChance(9, lengthof(name_additional_english_1b2), seed)]); tron@996: if (SeedChance(11, 20, seed) >= 4) { tron@996: strcat(buf, name_additional_english_1b3a[SeedChance(12, lengthof(name_additional_english_1b3a), seed)]); tron@993: } else { tron@996: strcat(buf, name_additional_english_1b3b[SeedChance(12, lengthof(name_additional_english_1b3b), seed)]); truelight@833: } truelight@833: } truelight@0: tron@996: strcat(buf, name_additional_english_2[SeedChance(14, lengthof(name_additional_english_2), seed)]); truelight@833: truelight@833: //optional last segment tron@996: i = SeedChanceBias(15, lengthof(name_additional_english_3), seed, 60); tron@996: if (i >= 0) truelight@833: strcat(buf, name_additional_english_3[i]); 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: tron@1307: static byte MakeAustrianTownName(char *buf, uint32 seed) truelight@0: { truelight@833: int i, j = 0; truelight@833: strcpy(buf, ""); truelight@0: truelight@0: // Bad, Maria, Gross, ... tron@996: i = SeedChanceBias(0, lengthof(name_austrian_a1), seed, 15); truelight@833: if (i >= 0) strcat(buf, name_austrian_a1[i]); truelight@833: tron@996: i = SeedChance(4, 6, seed); tron@993: if (i >= 4) { truelight@833: // Kaisers-kirchen tron@996: strcat(buf, name_austrian_a2[SeedChance( 7, lengthof(name_austrian_a2), seed)]); tron@996: strcat(buf, name_austrian_a3[SeedChance(13, lengthof(name_austrian_a3), seed)]); tron@993: } else if (i >= 2) { truelight@833: // St. Johann tron@996: strcat(buf, name_austrian_a5[SeedChance( 7, lengthof(name_austrian_a5), seed)]); tron@996: strcat(buf, name_austrian_a6[SeedChance( 9, lengthof(name_austrian_a6), seed)]); truelight@833: j = 1; // More likely to have a " an der " or " am " tron@993: } else { truelight@833: // Zell tron@996: strcat(buf, name_austrian_a4[SeedChance( 7, lengthof(name_austrian_a4), seed)]); truelight@0: } truelight@0: tron@996: i = SeedChance(1, 6, seed); tron@993: if (i >= 4 - j) { truelight@833: // an der Donau (rivers) tron@996: strcat(buf, name_austrian_f1[SeedChance(4, lengthof(name_austrian_f1), seed)]); tron@996: strcat(buf, name_austrian_f2[SeedChance(5, lengthof(name_austrian_f2), seed)]); tron@993: } else if (i >= 2 - j) { truelight@833: // am Dachstein (mountains) tron@996: strcat(buf, name_austrian_b1[SeedChance(4, lengthof(name_austrian_b1), seed)]); tron@996: strcat(buf, name_austrian_b2[SeedChance(5, lengthof(name_austrian_b2), seed)]); truelight@0: } truelight@0: truelight@0: return 0; truelight@0: } truelight@0: tron@1307: static byte MakeGermanTownName(char *buf, uint32 seed) truelight@0: { tron@992: uint i; tron@992: uint seed_derivative; truelight@0: truelight@833: //null terminates the string for strcat truelight@833: strcpy(buf, ""); 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); truelight@833: strcat(buf,name_german_pre[i]); 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)) { pasky@1422: strcat(buf,name_german_real[i]); tron@993: } else { pasky@1422: strcat(buf, name_german_1[i - lengthof(name_german_real)]); tron@992: tron@996: i = SeedChance(5, lengthof(name_german_2), seed); tron@992: strcat(buf, name_german_2[i]); 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)) { tron@992: strcat(buf, name_german_3_an_der[0]); tron@992: strcat(buf, name_german_4_an_der[i]); truelight@833: } else { tron@992: strcat(buf, name_german_3_am[0]); tron@992: strcat(buf, name_german_4_am[i - lengthof(name_german_4_an_der)]); truelight@833: } truelight@833: } truelight@833: return 0; truelight@833: } truelight@0: tron@1307: static byte MakeSpanishTownName(char *buf, uint32 seed) truelight@833: { pasky@1422: strcpy(buf, name_spanish_real[SeedChance(0, lengthof(name_spanish_real), seed)]); truelight@833: return 0; truelight@833: } truelight@0: tron@1307: static byte MakeFrenchTownName(char *buf, uint32 seed) truelight@833: { pasky@1422: strcpy(buf, name_french_real[SeedChance(0, lengthof(name_french_real), seed)]); truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakeSillyTownName(char *buf, uint32 seed) truelight@833: { tron@996: strcpy(buf, name_silly_1[SeedChance( 0, lengthof(name_silly_1), seed)]); tron@996: strcat(buf, name_silly_2[SeedChance(16, lengthof(name_silly_2), seed)]); truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakeSwedishTownName(char *buf, uint32 seed) truelight@833: { truelight@833: int i; truelight@833: truelight@833: //null terminates the string for strcat truelight@833: strcpy(buf, ""); truelight@833: truelight@833: // optional first segment tron@996: i = SeedChanceBias(0, lengthof(name_swedish_1), seed, 50); tron@996: if (i >= 0) truelight@833: strcat(buf, name_swedish_1[i]); truelight@0: truelight@833: // mandatory middle segments including option of hardcoded name tron@996: if (SeedChance(4, 5, seed) >= 3) { tron@996: strcat(buf, name_swedish_2[SeedChance( 7, lengthof(name_swedish_2), seed)]); tron@993: } else { tron@996: strcat(buf, name_swedish_2a[SeedChance( 7, lengthof(name_swedish_2a), seed)]); tron@996: strcat(buf, name_swedish_2b[SeedChance(10, lengthof(name_swedish_2b), seed)]); tron@996: strcat(buf, name_swedish_2c[SeedChance(13, lengthof(name_swedish_2c), seed)]); truelight@833: } truelight@0: tron@996: strcat(buf, name_swedish_3[SeedChance(16, lengthof(name_swedish_3), seed)]); truelight@833: truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakeDutchTownName(char *buf, uint32 seed) truelight@833: { truelight@833: int i; truelight@833: truelight@833: //null terminates the string for strcat truelight@833: strcpy(buf, ""); truelight@833: truelight@833: // optional first segment tron@996: i = SeedChanceBias(0, lengthof(name_dutch_1), seed, 50); tron@996: if (i >= 0) truelight@833: strcat(buf, name_dutch_1[i]); truelight@833: truelight@833: // mandatory middle segments including option of hardcoded name tron@996: if (SeedChance(6, 9, seed) > 4) { tron@996: strcat(buf, name_dutch_2[SeedChance( 9, lengthof(name_dutch_2), seed)]); tron@993: } else { tron@996: strcat(buf, name_dutch_3[SeedChance( 9, lengthof(name_dutch_3), seed)]); tron@996: strcat(buf, name_dutch_4[SeedChance(12, lengthof(name_dutch_4), seed)]); truelight@833: } tron@996: strcat(buf, name_dutch_5[SeedChance(15, lengthof(name_dutch_5), seed)]); truelight@833: truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakeFinnishTownName(char *buf, uint32 seed) truelight@833: { truelight@833: //null terminates the string for strcat truelight@833: strcpy(buf, ""); truelight@833: truelight@833: // Select randomly if town name should consists of one or two parts. tron@996: if (SeedChance(0, 15, seed) >= 10) { pasky@1422: strcat(buf, name_finnish_real[SeedChance( 2, lengthof(name_finnish_real), seed)]); tron@993: } else { pasky@1422: strcat(buf, name_finnish_1[SeedChance( 2, lengthof(name_finnish_1), seed)]); pasky@1422: strcat(buf, name_finnish_2[SeedChance(10, lengthof(name_finnish_2), seed)]); truelight@833: } truelight@833: truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakePolishTownName(char *buf, uint32 seed) truelight@833: { tron@959: uint i; tron@959: uint j; truelight@833: truelight@833: //null terminates the string for strcat truelight@833: strcpy(buf, ""); 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)) { tron@996: strcat(buf, name_polish_2_o[SeedChance(3, lengthof(name_polish_2_o), seed)]); tron@993: } else if (i < lengthof(name_polish_2_m) + lengthof(name_polish_2_o)) { truelight@833: if (j < 4) tron@996: strcat(buf, name_polish_1_m[SeedChance(5, lengthof(name_polish_1_m), seed)]); truelight@833: tron@996: strcat(buf, name_polish_2_m[SeedChance(7, lengthof(name_polish_2_m), seed)]); truelight@833: truelight@833: if (j >= 4 && j < 16) tron@996: strcat(buf, name_polish_3_m[SeedChance(10, lengthof(name_polish_3_m), seed)]); 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) tron@996: strcat(buf, name_polish_1_f[SeedChance(5, lengthof(name_polish_1_f), seed)]); truelight@833: tron@996: strcat(buf, name_polish_2_f[SeedChance(7, lengthof(name_polish_2_f), seed)]); truelight@833: truelight@833: if (j >= 4 && j < 16) tron@996: strcat(buf, name_polish_3_f[SeedChance(10, lengthof(name_polish_3_f), seed)]); tron@993: } else { truelight@833: if (j < 4) tron@996: strcat(buf, name_polish_1_n[SeedChance(5, lengthof(name_polish_1_n), seed)]); truelight@833: tron@996: strcat(buf, name_polish_2_n[SeedChance(7, lengthof(name_polish_2_n), seed)]); truelight@833: truelight@833: if (j >= 4 && j < 16) tron@996: strcat(buf, name_polish_3_n[SeedChance(10, lengthof(name_polish_3_n), seed)]); truelight@833: } truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakeCzechTownName(char *buf, uint32 seed) 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) { pasky@1447: strcpy(buf, name_czech_real[SeedModChance(4, lengthof(name_czech_real), seed)]); pasky@1425: return 0; pasky@1425: } pasky@1425: pasky@1425: // NUL terminates the string for strcat() pasky@1425: strcpy(buf, ""); 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@1473: if (postfix < lengthof(name_czech_subst_postfix)) pasky@1425: choose |= CZC_POSTFIX; pasky@1425: else pasky@1425: choose |= CZC_NOPOSTFIX; 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; pasky@1425: int endpos; pasky@1425: pasky@1425: strcat(buf, name_czech_adj[prefix].name); pasky@1425: endpos = strlen(buf) - 1; 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 { pasky@1425: buf[endpos] = name_czech_patmod[gender][pattern]; pasky@1425: } pasky@1425: pasky@1425: strcat(buf, " "); pasky@1425: } pasky@1425: pasky@1425: if (dynamic_subst) { pasky@1425: strcat(buf, name_czech_subst_stem[stem].name); 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; pasky@1425: int 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: ) { tron@1473: uint buflen; pasky@1426: strcat(buf, poststr); 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: } pasky@1425: strcat(buf, name_czech_subst_ending[ending].name); pasky@1425: } else { pasky@1425: strcat(buf, name_czech_subst_full[stem].name); pasky@1425: } pasky@1425: pasky@1425: if (do_suffix) { pasky@1425: strcat(buf, " "); pasky@1425: strcat(buf, name_czech_suffix[suffix]); pasky@1425: } pasky@1425: truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakeRomanianTownName(char *buf, uint32 seed) truelight@833: { pasky@1422: strcpy(buf, name_romanian_real[SeedChance(0, lengthof(name_romanian_real), seed)]); truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakeSlovakTownName(char *buf, uint32 seed) truelight@833: { pasky@1422: strcpy(buf, name_slovak_real[SeedChance(0, lengthof(name_slovak_real), seed)]); truelight@833: return 0; truelight@833: } truelight@833: tron@1307: static byte MakeNorwegianTownName(char *buf, uint32 seed) miham@948: { miham@948: strcpy(buf, ""); 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 tron@996: strcat(buf, name_norwegian_real[SeedChance(4, lengthof(name_norwegian_real), seed)]); tron@993: } else { miham@958: // Use 7bit for the first fake part. Bit 4-10 tron@996: strcat(buf, name_norwegian_1[SeedChance(4, lengthof(name_norwegian_1), seed)]); miham@958: // Use 7bit for the last fake part. Bit 11-17 tron@996: strcat(buf, name_norwegian_2[SeedChance(11, lengthof(name_norwegian_2), seed)]); miham@958: } miham@958: miham@948: return 0; miham@948: } miham@948: tron@1307: static byte MakeHungarianTownName(char *buf, uint32 seed) truelight@833: { tron@959: uint i; truelight@833: truelight@833: //null terminates the string for strcat truelight@833: strcpy(buf, ""); truelight@833: tron@996: if (SeedChance(12, 15, seed) < 3) { tron@996: strcat(buf, name_hungarian_real[SeedChance(0, lengthof(name_hungarian_real), seed)]); 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)) truelight@833: strcat(buf, name_hungarian_1[i]); truelight@833: truelight@833: // mandatory middle segments tron@996: strcat(buf, name_hungarian_2[SeedChance(3, lengthof(name_hungarian_2), seed)]); tron@996: strcat(buf, name_hungarian_3[SeedChance(6, lengthof(name_hungarian_3), seed)]); 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)) { truelight@833: strcat(buf, name_hungarian_4[i]); truelight@0: } darkvater@4: } truelight@0: truelight@0: return 0; truelight@0: } truelight@0: tron@1307: static byte MakeSwissTownName(char *buf, uint32 seed) darkvater@1030: { darkvater@1030: strcpy(buf, name_swiss_real[SeedChance(0, lengthof(name_swiss_real), seed)]); darkvater@1030: return 0; darkvater@1030: } darkvater@1030: Darkvater@2431: static byte MakeDanishTownName(char *buf, uint32 seed) Darkvater@2431: { Darkvater@2431: int i; Darkvater@2431: Darkvater@2431: // null terminates the string for strcat Darkvater@2431: strcpy(buf, ""); Darkvater@2431: Darkvater@2431: // optional first segment Darkvater@2431: i = SeedChanceBias(0, lengthof(name_danish_1), seed, 50); Darkvater@2431: if (i >= 0) Darkvater@2431: strcat(buf, name_danish_1[i]); Darkvater@2431: Darkvater@2431: // middle segments removed as this algorithm seems to create much more realistic names Darkvater@2431: strcat(buf, name_danish_2[SeedChance( 7, lengthof(name_danish_2), seed)]); Darkvater@2431: strcat(buf, name_danish_3[SeedChance(16, lengthof(name_danish_3), seed)]); Darkvater@2431: Darkvater@2431: return 0; Darkvater@2431: } Darkvater@2431: 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, 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 */ darkvater@4: /* Already OK */ darkvater@4: return townnameparts; tron@993: darkvater@4: case 1: /* French */ darkvater@4: /* For some reason 86 needs to be subtracted from townnameparts truelight@833: * 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@65: DEBUG(misc, 0) ("German Townnames are buggy... (%d)", townnameparts); darkvater@4: return townnameparts; tron@993: darkvater@4: case 4: /* Latin-American */ darkvater@4: /* 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 */ darkvater@4: /* NUM_SILLY_1 - lower 16 bits truelight@833: * NUM_SILLY_2 - upper 16 bits without leading 1 (first 8 bytes) truelight@833: * 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: }