OpenTTD Source  20241120-master-g6d3adc6169
townname.cpp File Reference

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. More...
 

Functions

static void GetTownName (StringBuilder &builder, const TownNameParams *par, uint32_t townnameparts)
 Fills builder with specified town name. More...
 
std::string GetTownName (const TownNameParams *par, uint32_t townnameparts)
 Get the town name for the given parameters and parts. More...
 
void GetTownName (StringBuilder &builder, const Town *t)
 Fills builder with town's name. More...
 
std::string GetTownName (const Town *t)
 Get the name of the given town. More...
 
bool VerifyTownName (uint32_t r, const TownNameParams *par, TownNames *town_names)
 Verifies the town name is valid and unique. More...
 
bool GenerateTownName (Randomizer &randomizer, uint32_t *townnameparts, TownNames *town_names)
 Generates valid town name. More...
 
static uint32_t SeedChance (uint8_t shift_by, size_t max, uint32_t seed)
 Generates a number from given seed. More...
 
static uint32_t SeedModChance (uint8_t shift_by, size_t max, uint32_t seed)
 Generates a number from given seed. More...
 
static int32_t SeedChanceBias (uint8_t shift_by, size_t max, uint32_t seed, int bias)
 Generates a number from given seed. More...
 
static void ReplaceWords (const char *org, const char *rep, StringBuilder &builder, size_t start)
 Replaces a string beginning in 'org' with 'rep'. More...
 
static void ReplaceEnglishWords (StringBuilder &builder, size_t start, bool original)
 Replaces english curses and ugly letter combinations by nicer ones. More...
 
static void MakeEnglishOriginalTownName (StringBuilder &builder, uint32_t seed)
 Generates English (Original) town name from given seed. More...
 
static void MakeEnglishAdditionalTownName (StringBuilder &builder, uint32_t seed)
 Generates English (Additional) town name from given seed. More...
 
static void MakeAustrianTownName (StringBuilder &builder, uint32_t seed)
 Generates Austrian town name from given seed. More...
 
static void MakeGermanTownName (StringBuilder &builder, uint32_t seed)
 Generates German town name from given seed. More...
 
static void MakeSpanishTownName (StringBuilder &builder, uint32_t seed)
 Generates Latin-American town name from given seed. More...
 
static void MakeFrenchTownName (StringBuilder &builder, uint32_t seed)
 Generates French town name from given seed. More...
 
static void MakeSillyTownName (StringBuilder &builder, uint32_t seed)
 Generates Silly town name from given seed. More...
 
static void MakeSwedishTownName (StringBuilder &builder, uint32_t seed)
 Generates Swedish town name from given seed. More...
 
static void MakeDutchTownName (StringBuilder &builder, uint32_t seed)
 Generates Dutch town name from given seed. More...
 
static void MakeFinnishTownName (StringBuilder &builder, uint32_t seed)
 Generates Finnish town name from given seed. More...
 
static void MakePolishTownName (StringBuilder &builder, uint32_t seed)
 Generates Polish town name from given seed. More...
 
static void MakeCzechTownName (StringBuilder &builder, uint32_t seed)
 Generates Czech town name from given seed. More...
 
static void MakeRomanianTownName (StringBuilder &builder, uint32_t seed)
 Generates Romanian town name from given seed. More...
 
static void MakeSlovakTownName (StringBuilder &builder, uint32_t seed)
 Generates Slovak town name from given seed. More...
 
static void MakeNorwegianTownName (StringBuilder &builder, uint32_t seed)
 Generates Norwegian town name from given seed. More...
 
static void MakeHungarianTownName (StringBuilder &builder, uint32_t seed)
 Generates Hungarian town name from given seed. More...
 
static void MakeSwissTownName (StringBuilder &builder, uint32_t seed)
 Generates Swiss town name from given seed. More...
 
static void MakeDanishTownName (StringBuilder &builder, uint32_t seed)
 Generates Danish town name from given seed. More...
 
static void MakeTurkishTownName (StringBuilder &builder, uint32_t seed)
 Generates Turkish town name from given seed. More...
 
static void MakeItalianTownName (StringBuilder &builder, uint32_t seed)
 Generates Italian town name from given seed. More...
 
static void MakeCatalanTownName (StringBuilder &builder, uint32_t seed)
 Generates Catalan town name from given seed. More...
 
void GenerateTownNameString (StringBuilder &builder, size_t lang, uint32_t seed)
 Generates town name from given seed. More...
 

Variables

static TownNameGenerator_town_name_generators []
 Town name generators. More...
 

Detailed Description

Town name generators.

Definition in file townname.cpp.

Typedef Documentation

◆ TownNameGenerator

typedef void TownNameGenerator(StringBuilder &builder, uint32_t seed)

Type for all town name generator functions.

Parameters
builderThe builder to write the name to.
seedThe seed of the town name.

Definition at line 979 of file townname.cpp.

Function Documentation

◆ GenerateTownName()

bool GenerateTownName ( Randomizer randomizer,
uint32_t *  townnameparts,
TownNames *  town_names 
)

Generates valid town name.

Parameters
randomizerthe source of random data for generating the name
townnamepartsif a name is generated, it's stored there
town_namesif a name is generated, check its uniqueness with the set
Returns
true iff a name was generated

Definition at line 136 of file townname.cpp.

References _settings_game, GameSettings::game_creation, Randomizer::Next(), Layouter::ReduceLineCache(), GameCreationSettings::town_name, and VerifyTownName().

◆ GenerateTownNameString()

void GenerateTownNameString ( StringBuilder builder,
size_t  lang,
uint32_t  seed 
)

Generates town name from given seed.

Parameters
builderstring builder to write to
langtown name language
seedgeneration seed

Definition at line 1013 of file townname.cpp.

References _town_name_generators.

◆ GetTownName() [1/4]

std::string GetTownName ( const Town t)

Get the name of the given town.

Parameters
tThe town to get the name for.
Returns
The town name.

Definition at line 89 of file townname.cpp.

References GetTownName().

◆ GetTownName() [2/4]

std::string GetTownName ( const TownNameParams par,
uint32_t  townnameparts 
)

Get the town name for the given parameters and parts.

Parameters
parTown name parameters.
townnameparts'Encoded' town name.
Returns
The town name.

Definition at line 65 of file townname.cpp.

◆ GetTownName() [3/4]

void GetTownName ( StringBuilder builder,
const Town t 
)

Fills builder with town's name.

Parameters
builderString builder.
tThe town to get the name from.

Definition at line 78 of file townname.cpp.

References GetTownName().

◆ GetTownName() [4/4]

static void GetTownName ( StringBuilder builder,
const TownNameParams par,
uint32_t  townnameparts 
)
static

Fills builder with specified town name.

Parameters
builderThe string builder.
parTown name parameters.
townnameparts'Encoded' town name.

Definition at line 48 of file townname.cpp.

References GetStringWithArgs(), TownNameParams::grfid, and TownNameParams::type.

Referenced by GetTownName(), and VerifyTownName().

◆ MakeAustrianTownName()

static void MakeAustrianTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Austrian town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 319 of file townname.cpp.

References SeedChanceBias().

◆ MakeCatalanTownName()

static void MakeCatalanTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Catalan town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 944 of file townname.cpp.

References SeedModChance().

◆ MakeCzechTownName()

static void MakeCzechTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Czech town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 589 of file townname.cpp.

References SeedModChance().

◆ MakeDanishTownName()

static void MakeDanishTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Danish town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 847 of file townname.cpp.

References SeedChanceBias().

◆ MakeDutchTownName()

static void MakeDutchTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Dutch town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 458 of file townname.cpp.

References SeedChanceBias().

◆ MakeEnglishAdditionalTownName()

static void MakeEnglishAdditionalTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates English (Additional) town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 283 of file townname.cpp.

References StringBuilder::CurrentIndex(), and SeedChanceBias().

◆ MakeEnglishOriginalTownName()

static void MakeEnglishOriginalTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates English (Original) town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 250 of file townname.cpp.

References StringBuilder::CurrentIndex(), and SeedChanceBias().

◆ MakeFinnishTownName()

static void MakeFinnishTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Finnish town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 481 of file townname.cpp.

References StringBuilder::CurrentIndex(), and SeedChance().

◆ MakeFrenchTownName()

static void MakeFrenchTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates French town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 411 of file townname.cpp.

◆ MakeGermanTownName()

static void MakeGermanTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates German town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 360 of file townname.cpp.

References SeedChance().

◆ MakeHungarianTownName()

static void MakeHungarianTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Hungarian town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 808 of file townname.cpp.

References SeedChance().

◆ MakeItalianTownName()

static void MakeItalianTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Italian town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 898 of file townname.cpp.

References SeedModChance().

◆ MakeNorwegianTownName()

static void MakeNorwegianTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Norwegian town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 786 of file townname.cpp.

References SeedChance().

◆ MakePolishTownName()

static void MakePolishTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Polish town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 527 of file townname.cpp.

References SeedChance().

◆ MakeRomanianTownName()

static void MakeRomanianTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Romanian town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 764 of file townname.cpp.

◆ MakeSillyTownName()

static void MakeSillyTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Silly town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 422 of file townname.cpp.

◆ MakeSlovakTownName()

static void MakeSlovakTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Slovak town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 775 of file townname.cpp.

◆ MakeSpanishTownName()

static void MakeSpanishTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Latin-American town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 400 of file townname.cpp.

◆ MakeSwedishTownName()

static void MakeSwedishTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Swedish town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 434 of file townname.cpp.

References SeedChanceBias().

◆ MakeSwissTownName()

static void MakeSwissTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Swiss town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 836 of file townname.cpp.

◆ MakeTurkishTownName()

static void MakeTurkishTownName ( StringBuilder builder,
uint32_t  seed 
)
static

Generates Turkish town name from given seed.

Parameters
builderstring builder
seedtown name seed

Definition at line 864 of file townname.cpp.

References SeedModChance().

◆ ReplaceEnglishWords()

static void ReplaceEnglishWords ( StringBuilder builder,
size_t  start,
bool  original 
)
static

Replaces english curses and ugly letter combinations by nicer ones.

Parameters
builderThe builder with the town name
startThe start index into the builder for the first town name
originalEnglish (Original) generator was used

Definition at line 231 of file townname.cpp.

References ReplaceWords().

◆ ReplaceWords()

static void ReplaceWords ( const char *  org,
const char *  rep,
StringBuilder builder,
size_t  start 
)
static

Replaces a string beginning in 'org' with 'rep'.

Parameters
orgstring to replace, has to be 4 characters long
repstring to be replaced with, has to be 4 characters long
builderstring builder of the town name
startthe start index within the builder for the town name

Definition at line 218 of file townname.cpp.

References StringBuilder::CurrentIndex().

Referenced by ReplaceEnglishWords().

◆ SeedChance()

static uint32_t SeedChance ( uint8_t  shift_by,
size_t  max,
uint32_t  seed 
)
inlinestatic

Generates a number from given seed.

Parameters
shift_bynumber of bits seed is shifted to the right
maxgenerated number is in interval 0...max-1
seedseed
Returns
seed transformed to a number from given range

Definition at line 169 of file townname.cpp.

References GB().

Referenced by MakeFinnishTownName(), MakeGermanTownName(), MakeHungarianTownName(), MakeNorwegianTownName(), MakePolishTownName(), and SeedChanceBias().

◆ SeedChanceBias()

static int32_t SeedChanceBias ( uint8_t  shift_by,
size_t  max,
uint32_t  seed,
int  bias 
)
inlinestatic

Generates a number from given seed.

Parameters
shift_bynumber of bits seed is shifted to the right
maxgenerated number is in interval -bias...max-1
seedseed
biasminimum value that can be returned
Returns
seed transformed to a number from given range

Definition at line 205 of file townname.cpp.

References SeedChance().

Referenced by MakeAustrianTownName(), MakeDanishTownName(), MakeDutchTownName(), MakeEnglishAdditionalTownName(), MakeEnglishOriginalTownName(), and MakeSwedishTownName().

◆ SeedModChance()

static uint32_t SeedModChance ( uint8_t  shift_by,
size_t  max,
uint32_t  seed 
)
inlinestatic

Generates a number from given seed.

Uses different algorithm than SeedChance().

Parameters
shift_bynumber of bits seed is shifted to the right
maxgenerated number is in interval 0...max-1
seedseed
Returns
seed transformed to a number from given range

Definition at line 182 of file townname.cpp.

Referenced by MakeCatalanTownName(), MakeCzechTownName(), MakeItalianTownName(), and MakeTurkishTownName().

◆ VerifyTownName()

bool VerifyTownName ( uint32_t  r,
const TownNameParams par,
TownNames *  town_names 
)

Verifies the town name is valid and unique.

Parameters
rrandom bits
partown name parameters
town_namesif a name is generated, check its uniqueness with the set
Returns
true iff name is valid and unique

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 GenerateTownName().

Variable Documentation

◆ _town_name_generators

TownNameGenerator* _town_name_generators[]
static
Initial value:
= {
}
static void MakeHungarianTownName(StringBuilder &builder, uint32_t seed)
Generates Hungarian town name from given seed.
Definition: townname.cpp:808
static void MakeCatalanTownName(StringBuilder &builder, uint32_t seed)
Generates Catalan town name from given seed.
Definition: townname.cpp:944
static void MakePolishTownName(StringBuilder &builder, uint32_t seed)
Generates Polish town name from given seed.
Definition: townname.cpp:527
static void MakeSlovakTownName(StringBuilder &builder, uint32_t seed)
Generates Slovak town name from given seed.
Definition: townname.cpp:775
static void MakeSwedishTownName(StringBuilder &builder, uint32_t seed)
Generates Swedish town name from given seed.
Definition: townname.cpp:434
static void MakeFrenchTownName(StringBuilder &builder, uint32_t seed)
Generates French town name from given seed.
Definition: townname.cpp:411
static void MakeItalianTownName(StringBuilder &builder, uint32_t seed)
Generates Italian town name from given seed.
Definition: townname.cpp:898
static void MakeNorwegianTownName(StringBuilder &builder, uint32_t seed)
Generates Norwegian town name from given seed.
Definition: townname.cpp:786
static void MakeCzechTownName(StringBuilder &builder, uint32_t seed)
Generates Czech town name from given seed.
Definition: townname.cpp:589
static void MakeGermanTownName(StringBuilder &builder, uint32_t seed)
Generates German town name from given seed.
Definition: townname.cpp:360
static void MakeDanishTownName(StringBuilder &builder, uint32_t seed)
Generates Danish town name from given seed.
Definition: townname.cpp:847
static void MakeEnglishOriginalTownName(StringBuilder &builder, uint32_t seed)
Generates English (Original) town name from given seed.
Definition: townname.cpp:250
static void MakeEnglishAdditionalTownName(StringBuilder &builder, uint32_t seed)
Generates English (Additional) town name from given seed.
Definition: townname.cpp:283
static void MakeFinnishTownName(StringBuilder &builder, uint32_t seed)
Generates Finnish town name from given seed.
Definition: townname.cpp:481
static void MakeSpanishTownName(StringBuilder &builder, uint32_t seed)
Generates Latin-American town name from given seed.
Definition: townname.cpp:400
static void MakeRomanianTownName(StringBuilder &builder, uint32_t seed)
Generates Romanian town name from given seed.
Definition: townname.cpp:764
static void MakeSillyTownName(StringBuilder &builder, uint32_t seed)
Generates Silly town name from given seed.
Definition: townname.cpp:422
static void MakeTurkishTownName(StringBuilder &builder, uint32_t seed)
Generates Turkish town name from given seed.
Definition: townname.cpp:864
static void MakeDutchTownName(StringBuilder &builder, uint32_t seed)
Generates Dutch town name from given seed.
Definition: townname.cpp:458
static void MakeSwissTownName(StringBuilder &builder, uint32_t seed)
Generates Swiss town name from given seed.
Definition: townname.cpp:836
static void MakeAustrianTownName(StringBuilder &builder, uint32_t seed)
Generates Austrian town name from given seed.
Definition: townname.cpp:319

Town name generators.

Definition at line 982 of file townname.cpp.

Referenced by GenerateTownNameString().