OpenTTD Source 20241224-master-gf74b0cf984
|
Town name generators. More...
#include "stdafx.h"
#include "string_func.h"
#include "townname_type.h"
#include "town.h"
#include "strings_func.h"
#include "core/random_func.hpp"
#include "genworld.h"
#include "gfx_layout.h"
#include "strings_internal.h"
#include "table/townname.h"
#include "safeguards.h"
Go to the source code of this file.
Typedefs | |
typedef void | TownNameGenerator(StringBuilder &builder, uint32_t seed) |
Type for all town name generator functions. | |
Functions | |
static void | GetTownName (StringBuilder &builder, const TownNameParams *par, uint32_t townnameparts) |
Fills builder with specified town name. | |
std::string | GetTownName (const TownNameParams *par, uint32_t townnameparts) |
Get the town name for the given parameters and parts. | |
void | GetTownName (StringBuilder &builder, const Town *t) |
Fills builder with town's name. | |
std::string | GetTownName (const Town *t) |
Get the name of the given town. | |
bool | VerifyTownName (uint32_t r, const TownNameParams *par, TownNames *town_names) |
Verifies the town name is valid and unique. | |
bool | GenerateTownName (Randomizer &randomizer, uint32_t *townnameparts, TownNames *town_names) |
Generates valid town name. | |
static uint32_t | SeedChance (uint8_t shift_by, size_t max, uint32_t seed) |
Generates a number from given seed. | |
static uint32_t | SeedModChance (uint8_t shift_by, size_t max, uint32_t seed) |
Generates a number from given seed. | |
static int32_t | SeedChanceBias (uint8_t shift_by, size_t max, uint32_t seed, int bias) |
Generates a number from given seed. | |
static void | ReplaceWords (const char *org, const char *rep, StringBuilder &builder, size_t start) |
Replaces a string beginning in 'org' with 'rep'. | |
static void | ReplaceEnglishWords (StringBuilder &builder, size_t start, bool original) |
Replaces english curses and ugly letter combinations by nicer ones. | |
static void | MakeEnglishOriginalTownName (StringBuilder &builder, uint32_t seed) |
Generates English (Original) town name from given seed. | |
static void | MakeEnglishAdditionalTownName (StringBuilder &builder, uint32_t seed) |
Generates English (Additional) town name from given seed. | |
static void | MakeAustrianTownName (StringBuilder &builder, uint32_t seed) |
Generates Austrian town name from given seed. | |
static void | MakeGermanTownName (StringBuilder &builder, uint32_t seed) |
Generates German town name from given seed. | |
static void | MakeSpanishTownName (StringBuilder &builder, uint32_t seed) |
Generates Latin-American town name from given seed. | |
static void | MakeFrenchTownName (StringBuilder &builder, uint32_t seed) |
Generates French town name from given seed. | |
static void | MakeSillyTownName (StringBuilder &builder, uint32_t seed) |
Generates Silly town name from given seed. | |
static void | MakeSwedishTownName (StringBuilder &builder, uint32_t seed) |
Generates Swedish town name from given seed. | |
static void | MakeDutchTownName (StringBuilder &builder, uint32_t seed) |
Generates Dutch town name from given seed. | |
static void | MakeFinnishTownName (StringBuilder &builder, uint32_t seed) |
Generates Finnish town name from given seed. | |
static void | MakePolishTownName (StringBuilder &builder, uint32_t seed) |
Generates Polish town name from given seed. | |
static void | MakeCzechTownName (StringBuilder &builder, uint32_t seed) |
Generates Czech town name from given seed. | |
static void | MakeRomanianTownName (StringBuilder &builder, uint32_t seed) |
Generates Romanian town name from given seed. | |
static void | MakeSlovakTownName (StringBuilder &builder, uint32_t seed) |
Generates Slovak town name from given seed. | |
static void | MakeNorwegianTownName (StringBuilder &builder, uint32_t seed) |
Generates Norwegian town name from given seed. | |
static void | MakeHungarianTownName (StringBuilder &builder, uint32_t seed) |
Generates Hungarian town name from given seed. | |
static void | MakeSwissTownName (StringBuilder &builder, uint32_t seed) |
Generates Swiss town name from given seed. | |
static void | MakeDanishTownName (StringBuilder &builder, uint32_t seed) |
Generates Danish town name from given seed. | |
static void | MakeTurkishTownName (StringBuilder &builder, uint32_t seed) |
Generates Turkish town name from given seed. | |
static void | MakeItalianTownName (StringBuilder &builder, uint32_t seed) |
Generates Italian town name from given seed. | |
static void | MakeCatalanTownName (StringBuilder &builder, uint32_t seed) |
Generates Catalan town name from given seed. | |
void | GenerateTownNameString (StringBuilder &builder, size_t lang, uint32_t seed) |
Generates town name from given seed. | |
Variables | |
static TownNameGenerator * | _town_name_generators [] |
Town name generators. | |
Town name generators.
Definition in file townname.cpp.
typedef void TownNameGenerator(StringBuilder &builder, uint32_t seed) |
Type for all town name generator functions.
builder | The builder to write the name to. |
seed | The seed of the town name. |
Definition at line 979 of file townname.cpp.
bool GenerateTownName | ( | Randomizer & | randomizer, |
uint32_t * | townnameparts, | ||
TownNames * | town_names | ||
) |
Generates valid town name.
randomizer | the source of random data for generating the name |
townnameparts | if a name is generated, it's stored there |
town_names | if a name is generated, check its uniqueness with the set |
Definition at line 136 of file townname.cpp.
References _settings_game, GameSettings::game_creation, Randomizer::Next(), Layouter::ReduceLineCache(), GameCreationSettings::town_name, and VerifyTownName().
Referenced by GenerateTowns().
void GenerateTownNameString | ( | StringBuilder & | builder, |
size_t | lang, | ||
uint32_t | seed | ||
) |
Generates town name from given seed.
builder | string builder to write to |
lang | town name language |
seed | generation seed |
Definition at line 1013 of file townname.cpp.
References _town_name_generators.
std::string GetTownName | ( | const Town * | t | ) |
Get the name of the given town.
t | The town to get the name for. |
Definition at line 89 of file townname.cpp.
References GetTownName().
std::string GetTownName | ( | const TownNameParams * | par, |
uint32_t | townnameparts | ||
) |
Get the town name for the given parameters and parts.
par | Town name parameters. |
townnameparts | 'Encoded' town name. |
Definition at line 65 of file townname.cpp.
References GetTownName().
void GetTownName | ( | StringBuilder & | builder, |
const Town * | t | ||
) |
Fills builder with town's name.
builder | String builder. |
t | The town to get the name from. |
Definition at line 78 of file townname.cpp.
References GetTownName().
|
static |
Fills builder with specified town name.
builder | The string builder. |
par | Town name parameters. |
townnameparts | 'Encoded' town name. |
Definition at line 48 of file townname.cpp.
References GetStringWithArgs(), TownNameParams::grfid, and TownNameParams::type.
Referenced by GetTownName(), GetTownName(), GetTownName(), and VerifyTownName().
|
static |
Generates Austrian town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 319 of file townname.cpp.
References SeedChance(), and SeedChanceBias().
|
static |
Generates Catalan town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 944 of file townname.cpp.
References SeedChance(), and SeedModChance().
|
static |
Generates Czech town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 589 of file townname.cpp.
References StringBuilder::CurrentIndex(), GB(), StringBuilder::RemoveElementsFromBack(), and SeedModChance().
|
static |
Generates Danish town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 847 of file townname.cpp.
References SeedChance(), and SeedChanceBias().
|
static |
Generates Dutch town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 458 of file townname.cpp.
References SeedChance(), and SeedChanceBias().
|
static |
Generates English (Additional) town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 283 of file townname.cpp.
References StringBuilder::CurrentIndex(), ReplaceEnglishWords(), SeedChance(), and SeedChanceBias().
|
static |
Generates English (Original) town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 250 of file townname.cpp.
References StringBuilder::CurrentIndex(), ReplaceEnglishWords(), SeedChance(), and SeedChanceBias().
|
static |
Generates Finnish town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 481 of file townname.cpp.
References StringBuilder::CurrentIndex(), and SeedChance().
|
static |
Generates French town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 411 of file townname.cpp.
References SeedChance().
|
static |
Generates German town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 360 of file townname.cpp.
References SeedChance().
|
static |
Generates Hungarian town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 808 of file townname.cpp.
References SeedChance().
|
static |
Generates Italian town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 898 of file townname.cpp.
References SeedChance(), and SeedModChance().
|
static |
Generates Norwegian town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 786 of file townname.cpp.
References SeedChance().
|
static |
Generates Polish town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 527 of file townname.cpp.
References SeedChance().
|
static |
Generates Romanian town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 764 of file townname.cpp.
References SeedChance().
|
static |
Generates Silly town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 422 of file townname.cpp.
References SeedChance().
|
static |
Generates Slovak town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 775 of file townname.cpp.
References SeedChance().
|
static |
Generates Latin-American town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 400 of file townname.cpp.
References SeedChance().
|
static |
Generates Swedish town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 434 of file townname.cpp.
References SeedChance(), and SeedChanceBias().
|
static |
Generates Swiss town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 836 of file townname.cpp.
References SeedChance().
|
static |
Generates Turkish town name from given seed.
builder | string builder |
seed | town name seed |
Definition at line 864 of file townname.cpp.
References SeedModChance().
|
static |
Replaces english curses and ugly letter combinations by nicer ones.
builder | The builder with the town name |
start | The start index into the builder for the first town name |
original | English (Original) generator was used |
Definition at line 231 of file townname.cpp.
References ReplaceWords().
Referenced by MakeEnglishAdditionalTownName(), and MakeEnglishOriginalTownName().
|
static |
Replaces a string beginning in 'org' with 'rep'.
org | string to replace, has to be 4 characters long |
rep | string to be replaced with, has to be 4 characters long |
builder | string builder of the town name |
start | the start index within the builder for the town name |
Definition at line 218 of file townname.cpp.
References StringBuilder::CurrentIndex().
Referenced by ReplaceEnglishWords().
|
inlinestatic |
Generates a number from given seed.
shift_by | number of bits seed is shifted to the right |
max | generated number is in interval 0...max-1 |
seed | seed |
Definition at line 169 of file townname.cpp.
References GB().
Referenced by MakeAustrianTownName(), MakeCatalanTownName(), MakeDanishTownName(), MakeDutchTownName(), MakeEnglishAdditionalTownName(), MakeEnglishOriginalTownName(), MakeFinnishTownName(), MakeFrenchTownName(), MakeGermanTownName(), MakeHungarianTownName(), MakeItalianTownName(), MakeNorwegianTownName(), MakePolishTownName(), MakeRomanianTownName(), MakeSillyTownName(), MakeSlovakTownName(), MakeSpanishTownName(), MakeSwedishTownName(), MakeSwissTownName(), and SeedChanceBias().
|
inlinestatic |
Generates a number from given seed.
shift_by | number of bits seed is shifted to the right |
max | generated number is in interval -bias...max-1 |
seed | seed |
bias | minimum value that can be returned |
Definition at line 205 of file townname.cpp.
References SeedChance().
Referenced by MakeAustrianTownName(), MakeDanishTownName(), MakeDutchTownName(), MakeEnglishAdditionalTownName(), MakeEnglishOriginalTownName(), and MakeSwedishTownName().
|
inlinestatic |
Generates a number from given seed.
Uses different algorithm than SeedChance().
shift_by | number of bits seed is shifted to the right |
max | generated number is in interval 0...max-1 |
seed | seed |
Definition at line 182 of file townname.cpp.
Referenced by MakeCatalanTownName(), MakeCzechTownName(), MakeItalianTownName(), and MakeTurkishTownName().
bool VerifyTownName | ( | uint32_t | r, |
const TownNameParams * | par, | ||
TownNames * | town_names | ||
) |
Verifies the town name is valid and unique.
r | random bits |
par | town name parameters |
town_names | if a name is generated, check its uniqueness with the set |
Definition at line 103 of file townname.cpp.
References GetTownName(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Iterate(), MAX_LENGTH_TOWN_NAME_CHARS, and Utf8StringLength().
Referenced by CmdFoundTown(), and GenerateTownName().
|
static |
Town name generators.
Definition at line 982 of file townname.cpp.
Referenced by GenerateTownNameString().