truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" truelight@0: truelight@833: #include "table/namegen.h" truelight@0: tron@996: static inline uint32 SeedChance(int shift_by, int max, uint32 seed) truelight@0: { tron@996: return ((uint16)(seed >> shift_by) * max) >> 16; tron@996: } tron@996: 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: truelight@833: static byte MakeEnglishOriginalTownName(byte *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: truelight@833: static byte MakeEnglishAdditionalTownName(byte *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: truelight@0: static byte MakeAustrianTownName(byte *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: truelight@0: static byte MakeGermanTownName(byte *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 tron@996: i = SeedChance(3, lengthof(name_german_hardcoded) + lengthof(name_german_1), seed); tron@992: if (i < lengthof(name_german_hardcoded)) { truelight@833: strcat(buf,name_german_hardcoded[i]); tron@993: } else { tron@992: strcat(buf, name_german_1[i - lengthof(name_german_hardcoded)]); 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: truelight@833: static byte MakeSpanishTownName(byte *buf, uint32 seed) truelight@833: { tron@996: strcpy(buf, name_spanish_1[SeedChance(0, lengthof(name_spanish_1), seed)]); truelight@833: return 0; truelight@833: } truelight@0: truelight@833: static byte MakeFrenchTownName(byte *buf, uint32 seed) truelight@833: { tron@996: strcpy(buf, name_french_1[SeedChance(0, lengthof(name_french_1), seed)]); truelight@833: return 0; truelight@833: } truelight@833: truelight@833: static byte MakeSillyTownName(byte *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: truelight@833: static byte MakeSwedishTownName(byte *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: truelight@833: static byte MakeDutchTownName(byte *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: truelight@833: static byte MakeFinnishTownName(byte *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) { tron@996: strcat(buf, name_finnish_1[SeedChance( 2, lengthof(name_finnish_1), seed)]); tron@993: } else { tron@996: strcat(buf, name_finnish_2a[SeedChance( 2, lengthof(name_finnish_2a), seed)]); tron@996: strcat(buf, name_finnish_2b[SeedChance(10, lengthof(name_finnish_2b), seed)]); truelight@833: } truelight@833: truelight@833: return 0; truelight@833: } truelight@833: truelight@833: static byte MakePolishTownName(byte *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: truelight@833: static byte MakeCzechTownName(byte *buf, uint32 seed) truelight@833: { tron@996: strcpy(buf, name_czech_1[SeedChance(0, lengthof(name_czech_1), seed)]); truelight@833: return 0; truelight@833: } truelight@833: truelight@833: static byte MakeRomanianTownName(byte *buf, uint32 seed) truelight@833: { tron@996: strcpy(buf, name_romanian_1[SeedChance(0, lengthof(name_romanian_1), seed)]); truelight@833: return 0; truelight@833: } truelight@833: truelight@833: static byte MakeSlovakTownName(byte *buf, uint32 seed) truelight@833: { tron@996: strcpy(buf, name_slovakish_1[SeedChance(0, lengthof(name_slovakish_1), seed)]); truelight@833: return 0; truelight@833: } truelight@833: miham@948: static byte MakeNorwegianTownName(byte *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: truelight@833: static byte MakeHungarianTownName(byte *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: darkvater@1030: static byte MakeSwissTownName(byte *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: 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, 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 */ truelight@833: return FIXNUM(townnameparts - 86, lengthof(name_french_1), 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 */ truelight@833: return FIXNUM(townnameparts, lengthof(name_spanish_1), 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 */ truelight@833: return FIXNUM(townnameparts, lengthof(name_silly_1), 0) | FIXNUM(((townnameparts >> 16)&0xFF), lengthof(name_silly_2), 16); darkvater@4: } darkvater@4: return 0; darkvater@4: }