29 grfid(t->townnamegrfid),
32 if (t->townnamegrfid != 0 && GetGRFTownName(t->townnamegrfid) ==
nullptr) {
35 this->
type = SPECSTR_TOWNNAME_ENGLISH;
51 if (par->
grfid == 0) {
52 int64 args_array[1] = { townnameparts };
57 return GRFTownNameGenerate(buff, par->
grfid, par->
type, townnameparts, last);
71 return GetTownName(buff, &par, t->townnameparts, last);
93 if (town_names !=
nullptr) {
94 if (town_names->find(buf1) != town_names->end())
return false;
95 town_names->insert(buf1);
100 const char *buf = t->name;
101 if (buf ==
nullptr) {
105 if (strcmp(buf1, buf) == 0)
return false;
132 for (
int i = 1000; i != 0; i--) {
154 return (
GB(seed, shift_by, 16) * max) >> 16;
176 return (seed >> shift_by) %
max;
190 return SeedChance(shift_by, max + bias, seed) - bias;
202 assert(strlen(org) == 4 && strlen(rep) == 4 && strlen(buf) >= 4);
203 if (strncmp(buf, org, 4) == 0) memcpy(buf, rep, 4);
238 if (i >= 0) buf =
strecpy(buf, _name_original_english_1[i], last);
248 if (i >= 0) buf =
strecpy(buf, _name_original_english_6[i], last);
251 if (orig[0] ==
'C' && (orig[1] ==
'e' || orig[1] ==
'i')) {
255 assert(buf - orig >= 4);
274 if (i >= 0) buf =
strecpy(buf, _name_additional_english_prefix[i], last);
292 if (i >= 0) buf =
strecpy(buf, _name_additional_english_3[i], last);
294 assert(buf - orig >= 4);
311 if (i >= 0) buf =
strecpy(buf, _name_austrian_a1[i], last);
335 }
else if (i >= 2 - j) {
353 uint seed_derivative =
SeedChance(7, 28, seed);
356 if (seed_derivative == 12 || seed_derivative == 19) {
358 buf =
strecpy(buf, _name_german_pre[i], last);
363 if (i <
lengthof(_name_german_real)) {
364 buf =
strecpy(buf, _name_german_real[i], last);
366 buf =
strecpy(buf, _name_german_1[i -
lengthof(_name_german_real)], last);
369 buf =
strecpy(buf, _name_german_2[i], last);
373 if (seed_derivative == 24) {
375 if (i <
lengthof(_name_german_4_an_der)) {
376 buf =
strecpy(buf, _name_german_3_an_der[0], last);
377 buf =
strecpy(buf, _name_german_4_an_der[i], last);
379 buf =
strecpy(buf, _name_german_3_am[0], last);
380 buf =
strecpy(buf, _name_german_4_am[i -
lengthof(_name_german_4_an_der)], last);
437 if (i >= 0) buf =
strecpy(buf, _name_swedish_1[i], last);
464 if (i >= 0) buf =
strecpy(buf, _name_dutch_1[i], last);
500 buf =
strecpy(buf, _name_finnish_1[sel], last);
503 if (*end ==
'i') *end =
'e';
504 if (strstr(orig,
"a") !=
nullptr || strstr(orig,
"o") !=
nullptr || strstr(orig,
"u") !=
nullptr ||
505 strstr(orig,
"A") !=
nullptr || strstr(orig,
"O") !=
nullptr || strstr(orig,
"U") !=
nullptr) {
506 buf =
strecpy(buf,
"la", last);
508 buf =
strecpy(buf,
"l\xC3\xA4", last);
516 if (sel >=
lengthof(_name_finnish_1)) {
517 buf =
strecpy(buf, _name_finnish_2[sel -
lengthof(_name_finnish_1)], last);
519 buf =
strecpy(buf, _name_finnish_1[sel], last);
544 if (i <
lengthof(_name_polish_2_o)) {
555 if (j >= 4 && j < 16) {
569 if (j >= 4 && j < 16) {
582 if (j >= 4 && j < 16) {
603 const char *orig = buf;
608 bool do_prefix = prob_tails < 12;
609 bool do_suffix = prob_tails > 11 && prob_tails < 17;
613 int prefix = 0, ending = 0, suffix = 0;
628 if (stem <
lengthof(_name_czech_subst_full)) {
630 dynamic_subst =
false;
631 gender = _name_czech_subst_full[stem].gender;
632 choose = _name_czech_subst_full[stem].choose;
633 allow = _name_czech_subst_full[stem].allow;
635 uint map[
lengthof(_name_czech_subst_ending)];
636 int ending_start = -1, ending_stop = -1;
639 dynamic_subst =
true;
640 stem -=
lengthof(_name_czech_subst_full);
641 stem %=
lengthof(_name_czech_subst_stem);
642 gender = _name_czech_subst_stem[stem].gender;
643 choose = _name_czech_subst_stem[stem].choose;
644 allow = _name_czech_subst_stem[stem].allow;
649 if (choose & CZC_POSTFIX) {
651 postfix %=
lengthof(_name_czech_subst_postfix);
653 if (choose & CZC_NOPOSTFIX) {
655 postfix +=
lengthof(_name_czech_subst_postfix);
657 if (postfix <
lengthof(_name_czech_subst_postfix)) {
658 choose |= CZC_POSTFIX;
660 choose |= CZC_NOPOSTFIX;
664 for (ending = 0; ending < (int)
lengthof(_name_czech_subst_ending); ending++) {
667 if (gender == CZG_FREE ||
668 (gender == CZG_NFREE && e->gender != CZG_SNEUT && e->gender != CZG_PNEUT) ||
669 gender == e->gender) {
670 if (ending_start < 0) {
671 ending_start = ending;
673 }
else if (ending_start >= 0) {
674 ending_stop = ending - 1;
678 if (ending_stop < 0) {
680 ending_stop = ending - 1;
685 for (ending = ending_start; ending <= ending_stop; ending++) {
688 if ((e->choose & choose) == choose && (e->allow & allow) != 0) {
698 gender = _name_czech_subst_ending[ending].gender;
699 assert(gender != CZG_FREE && gender != CZG_NFREE);
702 if (do_prefix && (_name_czech_adj[prefix].choose & choose) != choose) {
709 CzechPattern pattern = _name_czech_adj[prefix].pattern;
711 buf =
strecpy(buf, _name_czech_adj[prefix].name, last);
713 char *endpos = buf - 1;
715 while (
GB(*endpos, 6, 2) == 2) endpos--;
717 if (gender == CZG_SMASC && pattern == CZP_PRIVL) {
718 assert(endpos >= orig + 2);
721 assert(*(endpos - 1) ==
'v');
724 assert(endpos >= orig);
725 endpos =
strecpy(endpos, _name_czech_patmod[gender][pattern], last);
728 buf =
strecpy(endpos,
" ", last);
732 buf =
strecpy(buf, _name_czech_subst_stem[stem].name, last);
733 if (postfix <
lengthof(_name_czech_subst_postfix)) {
734 const char *poststr = _name_czech_subst_postfix[postfix];
735 const char *endstr = _name_czech_subst_ending[ending].name;
737 size_t postlen = strlen(poststr);
738 size_t endlen = strlen(endstr);
739 assert(postlen > 0 && endlen > 0);
742 if (postlen < 2 || postlen > endlen ||
743 ((poststr[1] !=
'v' || poststr[1] != endstr[1]) &&
744 poststr[2] != endstr[1])) {
745 buf =
strecpy(buf, poststr, last);
748 if (endstr[0] ==
'i') {
749 switch (*(buf - 1)) {
750 case 'k': *(buf - 1) =
'c';
break;
751 case 'h': *(buf - 1) =
'z';
break;
757 buf =
strecpy(buf, _name_czech_subst_ending[ending].name, last);
759 buf =
strecpy(buf, _name_czech_subst_full[stem].name, last);
764 buf =
strecpy(buf, _name_czech_suffix[suffix], last);
833 if (i <
lengthof(_name_hungarian_1)) buf =
strecpy(buf, _name_hungarian_1[i], last);
841 if (i <
lengthof(_name_hungarian_4)) {
842 buf =
strecpy(buf, _name_hungarian_4[i], last);
871 if (i >= 0) buf =
strecpy(buf, _name_danish_1[i], last);
930 static const char *
const mascul_femin_italian[] = {
948 buf =
strecpy(buf, mascul_femin_italian[i], last);
1054 assert(lang <
lengthof(_town_name_generators));
1063 if (last >= buf + par->
min)
return par->
proc(buf, last, seed);
1066 par->
proc(buffer, buffer + par->
min, seed);
1068 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.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
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
static void ReduceLineCache()
Reduce the size of linecache if necessary to prevent infinite growth.
Struct holding 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.