31 grfid(t->townnamegrfid),
34 if (t->townnamegrfid != 0 && GetGRFTownName(t->townnamegrfid) == NULL) {
37 this->
type = SPECSTR_TOWNNAME_ENGLISH;
53 if (par->
grfid == 0) {
54 int64 args_array[1] = { townnameparts };
59 return GRFTownNameGenerate(buff, par->
grfid, par->
type, townnameparts, last);
73 return GetTownName(buff, &par, t->townnameparts, last);
95 if (town_names != NULL) {
96 if (town_names->find(buf1) != town_names->end())
return false;
97 town_names->insert(buf1);
103 const char *buf = t->
name;
108 if (strcmp(buf1, buf) == 0)
return false;
135 for (
int i = 1000; i != 0; i--) {
157 return (
GB(seed, shift_by, 16) * max) >> 16;
179 return (seed >> shift_by) %
max;
193 return SeedChance(shift_by, max + bias, seed) - bias;
205 assert(strlen(org) == 4 && strlen(rep) == 4 && strlen(buf) >= 4);
206 if (strncmp(buf, org, 4) == 0) memcpy(buf, rep, 4);
241 if (i >= 0) buf =
strecpy(buf, _name_original_english_1[i], last);
251 if (i >= 0) buf =
strecpy(buf, _name_original_english_6[i], last);
254 if (orig[0] ==
'C' && (orig[1] ==
'e' || orig[1] ==
'i')) {
258 assert(buf - orig >= 4);
277 if (i >= 0) buf =
strecpy(buf, _name_additional_english_prefix[i], last);
295 if (i >= 0) buf =
strecpy(buf, _name_additional_english_3[i], last);
297 assert(buf - orig >= 4);
314 if (i >= 0) buf =
strecpy(buf, _name_austrian_a1[i], last);
338 }
else if (i >= 2 - j) {
356 uint seed_derivative =
SeedChance(7, 28, seed);
359 if (seed_derivative == 12 || seed_derivative == 19) {
361 buf =
strecpy(buf, _name_german_pre[i], last);
366 if (i <
lengthof(_name_german_real)) {
367 buf =
strecpy(buf, _name_german_real[i], last);
369 buf =
strecpy(buf, _name_german_1[i -
lengthof(_name_german_real)], last);
372 buf =
strecpy(buf, _name_german_2[i], last);
376 if (seed_derivative == 24) {
378 if (i <
lengthof(_name_german_4_an_der)) {
379 buf =
strecpy(buf, _name_german_3_an_der[0], last);
380 buf =
strecpy(buf, _name_german_4_an_der[i], last);
382 buf =
strecpy(buf, _name_german_3_am[0], last);
383 buf =
strecpy(buf, _name_german_4_am[i -
lengthof(_name_german_4_an_der)], last);
440 if (i >= 0) buf =
strecpy(buf, _name_swedish_1[i], last);
467 if (i >= 0) buf =
strecpy(buf, _name_dutch_1[i], last);
503 buf =
strecpy(buf, _name_finnish_1[sel], last);
506 if (*end ==
'i') *end =
'e';
507 if (strstr(orig,
"a") != NULL || strstr(orig,
"o") != NULL || strstr(orig,
"u") != NULL ||
508 strstr(orig,
"A") != NULL || strstr(orig,
"O") != NULL || strstr(orig,
"U") != NULL) {
509 buf =
strecpy(buf,
"la", last);
511 buf =
strecpy(buf,
"l\xC3\xA4", last);
519 if (sel >=
lengthof(_name_finnish_1)) {
520 buf =
strecpy(buf, _name_finnish_2[sel -
lengthof(_name_finnish_1)], last);
522 buf =
strecpy(buf, _name_finnish_1[sel], last);
547 if (i <
lengthof(_name_polish_2_o)) {
558 if (j >= 4 && j < 16) {
572 if (j >= 4 && j < 16) {
585 if (j >= 4 && j < 16) {
606 const char *orig = buf;
611 bool do_prefix = prob_tails < 12;
612 bool do_suffix = prob_tails > 11 && prob_tails < 17;
616 int prefix = 0, ending = 0, suffix = 0;
631 if (stem <
lengthof(_name_czech_subst_full)) {
633 dynamic_subst =
false;
634 gender = _name_czech_subst_full[stem].gender;
635 choose = _name_czech_subst_full[stem].choose;
636 allow = _name_czech_subst_full[stem].allow;
638 uint map[
lengthof(_name_czech_subst_ending)];
639 int ending_start = -1, ending_stop = -1;
642 dynamic_subst =
true;
643 stem -=
lengthof(_name_czech_subst_full);
644 stem %=
lengthof(_name_czech_subst_stem);
645 gender = _name_czech_subst_stem[stem].gender;
646 choose = _name_czech_subst_stem[stem].choose;
647 allow = _name_czech_subst_stem[stem].allow;
652 if (choose & CZC_POSTFIX) {
654 postfix %=
lengthof(_name_czech_subst_postfix);
656 if (choose & CZC_NOPOSTFIX) {
658 postfix +=
lengthof(_name_czech_subst_postfix);
660 if (postfix <
lengthof(_name_czech_subst_postfix)) {
661 choose |= CZC_POSTFIX;
663 choose |= CZC_NOPOSTFIX;
667 for (ending = 0; ending < (int)
lengthof(_name_czech_subst_ending); ending++) {
670 if (gender == CZG_FREE ||
671 (gender == CZG_NFREE && e->gender != CZG_SNEUT && e->gender != CZG_PNEUT) ||
672 gender == e->gender) {
673 if (ending_start < 0) {
674 ending_start = ending;
676 }
else if (ending_start >= 0) {
677 ending_stop = ending - 1;
681 if (ending_stop < 0) {
683 ending_stop = ending - 1;
688 for (ending = ending_start; ending <= ending_stop; ending++) {
691 if ((e->choose & choose) == choose && (e->allow & allow) != 0) {
701 gender = _name_czech_subst_ending[ending].gender;
702 assert(gender != CZG_FREE && gender != CZG_NFREE);
705 if (do_prefix && (_name_czech_adj[prefix].choose & choose) != choose) {
712 CzechPattern pattern = _name_czech_adj[prefix].pattern;
714 buf =
strecpy(buf, _name_czech_adj[prefix].name, last);
716 char *endpos = buf - 1;
718 while (
GB(*endpos, 6, 2) == 2) endpos--;
720 if (gender == CZG_SMASC && pattern == CZP_PRIVL) {
721 assert(endpos >= orig + 2);
724 assert(*(endpos - 1) ==
'v');
727 assert(endpos >= orig);
728 endpos =
strecpy(endpos, _name_czech_patmod[gender][pattern], last);
731 buf =
strecpy(endpos,
" ", last);
735 buf =
strecpy(buf, _name_czech_subst_stem[stem].name, last);
736 if (postfix <
lengthof(_name_czech_subst_postfix)) {
737 const char *poststr = _name_czech_subst_postfix[postfix];
738 const char *endstr = _name_czech_subst_ending[ending].name;
740 size_t postlen = strlen(poststr);
741 size_t endlen = strlen(endstr);
742 assert(postlen > 0 && endlen > 0);
745 if (postlen < 2 || postlen > endlen ||
746 ((poststr[1] !=
'v' || poststr[1] != endstr[1]) &&
747 poststr[2] != endstr[1])) {
748 buf =
strecpy(buf, poststr, last);
751 if (endstr[0] ==
'i') {
752 switch (*(buf - 1)) {
753 case 'k': *(buf - 1) =
'c';
break;
754 case 'h': *(buf - 1) =
'z';
break;
760 buf =
strecpy(buf, _name_czech_subst_ending[ending].name, last);
762 buf =
strecpy(buf, _name_czech_subst_full[stem].name, last);
767 buf =
strecpy(buf, _name_czech_suffix[suffix], last);
836 if (i <
lengthof(_name_hungarian_1)) buf =
strecpy(buf, _name_hungarian_1[i], last);
844 if (i <
lengthof(_name_hungarian_4)) {
845 buf =
strecpy(buf, _name_hungarian_4[i], last);
874 if (i >= 0) buf =
strecpy(buf, _name_danish_1[i], last);
933 static const char *
const mascul_femin_italian[] = {
951 buf =
strecpy(buf, mascul_femin_italian[i], last);
1057 assert(lang <
lengthof(_town_name_generators));
1066 if (last >= buf + par->
min)
return par->
proc(buf, last, seed);
1069 par->
proc(buffer, buffer + par->
min, seed);
1071 return strecpy(buf, buffer, last);
Functions related to OTTD's strings.
static char * MakeDanishTownName(char *buf, const char *last, uint32 seed)
Generates Danish town name from given seed.
static char * MakeHungarianTownName(char *buf, const char *last, uint32 seed)
Generates Hungarian town name from given seed.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static char * MakePolishTownName(char *buf, const char *last, uint32 seed)
Generates Polish town name from given seed.
bool VerifyTownName(uint32 r, const TownNameParams *par, TownNames *town_names)
Verifies the town name is valid and unique.
static uint32 SeedModChance(byte shift_by, int max, uint32 seed)
Generates a number from given seed.
static const TownNameGeneratorParams _town_name_generators[]
Town name generators.
Definition of structures used for generating town names.
Namepart tables for the town name generator.
Contains pointer to generator and minimum buffer size (not incl.
bool GenerateTownName(uint32 *townnameparts, TownNames *town_names)
Generates valid town name.
TownNameParams(byte town_name)
Initializes this struct from language ID.
#define lastof(x)
Get the last element of an fixed size array.
Functions related to world/map generation.
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
static T max(const T a, const T b)
Returns the maximum of two values.
Functions related to laying out the texts.
static char * MakeDutchTownName(char *buf, const char *last, uint32 seed)
Generates Dutch town name from given seed.
static char * MakeCatalanTownName(char *buf, const char *last, uint32 seed)
Generates Catalan town name from given seed.
uint16 type
town name style
char * GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
static char * MakeRomanianTownName(char *buf, const char *last, uint32 seed)
Generates Romanian town name from given seed.
Pseudo random number generator.
byte min
minimum number of characters that need to be printed for generator to work correctly ...
Functions related to low-level strings.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
char * GetTownName(char *buff, const TownNameParams *par, uint32 townnameparts, const char *last)
Fills buffer with specified town name.
static char * MakeItalianTownName(char *buf, const char *last, uint32 seed)
Generates Italian town name from given seed.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
static char * MakeSlovakTownName(char *buf, const char *last, uint32 seed)
Generates Slovak town name from given seed.
static void ReplaceWords(const char *org, const char *rep, char *buf)
Replaces a string beginning in 'org' with 'rep'.
TownNameGenerator * proc
generator itself
static char * MakeAustrianTownName(char *buf, const char *last, uint32 seed)
Generates Austrian town name from given seed.
static char * MakeSwissTownName(char *buf, const char *last, uint32 seed)
Generates Swiss town name from given seed.
static char * MakeEnglishOriginalTownName(char *buf, const char *last, uint32 seed)
Generates English (Original) town name from given seed.
char * TownNameGenerator(char *buf, const char *last, uint32 seed)
Type for all town name generator functions.
#define lengthof(x)
Return the length of an fixed size array.
static void ReplaceEnglishWords(char *buf, bool original)
Replaces english curses and ugly letter combinations by nicer ones.
static char * MakeGermanTownName(char *buf, const char *last, uint32 seed)
Generates German town name from given seed.
bool _generating_world
Whether we are generating the map or not.
static int32 SeedChanceBias(byte shift_by, int max, uint32 seed, int bias)
Generates a number from given seed.
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
static char * MakeSpanishTownName(char *buf, const char *last, uint32 seed)
Generates Latin-American town name from given seed.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static char * MakeSillyTownName(char *buf, const char *last, uint32 seed)
Generates Silly town name from given seed.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
byte town_name
the town name generator used for town names
char * name
Custom town name. If NULL, the town was not renamed and uses the generated name.
static void ReduceLineCache()
Reduce the size of linecache if necessary to prevent infinite growth.
Struct holding a parameters used to generate town name.
char * GenerateTownNameString(char *buf, const char *last, size_t lang, uint32 seed)
Generates town name from given seed.
static const uint MAX_LENGTH_TOWN_NAME_CHARS
The maximum length of a town name in characters including '\0'.
static char * MakeSwedishTownName(char *buf, const char *last, uint32 seed)
Generates Swedish town name from given seed.
static char * MakeEnglishAdditionalTownName(char *buf, const char *last, uint32 seed)
Generates English (Additional) town name from given seed.
static char * MakeCzechTownName(char *buf, const char *last, uint32 seed)
Generates Czech town name from given seed.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static uint32 SeedChance(byte shift_by, int max, uint32 seed)
Generates a number from given seed.
uint32 grfid
newgrf ID (0 if not used)
static char * MakeFinnishTownName(char *buf, const char *last, uint32 seed)
Generates Finnish town name from given seed.
static char * MakeFrenchTownName(char *buf, const char *last, uint32 seed)
Generates French town name from given seed.
static char * MakeNorwegianTownName(char *buf, const char *last, uint32 seed)
Generates Norwegian town name from given seed.
static char * MakeTurkishTownName(char *buf, const char *last, uint32 seed)
Generates Turkish town name from given seed.