OpenTTD Source: src/townname.cpp File Reference

OpenTTD Source 14.0-beta1

Typedefs | Functions | Variables
townname.cpp File Reference
`#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 (byte shift_by, int max, uint32_t seed)
| Generates a number from given seed. More...
static uint32_t | SeedModChance (byte shift_by, int max, uint32_t seed)
| Generates a number from given seed. More...
static int32_t | SeedChanceBias (byte shift_by, int 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

  builder | The builder to write the name to.
  seed | The 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

  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

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

  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, and lengthof.

## ◆ GetTownName() [1/4]

std::string GetTownName | ( | const Town * | t | ) |

Get the name of the given town.

Parameters

  t | The 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

  par | Town 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

  builder | String builder.
  t | The 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

  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(), and VerifyTownName().

## ◆ MakeAustrianTownName()

static void MakeAustrianTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates Austrian town name from given seed.

Parameters

  builder | string builder
  seed | town name seed

Definition at line 319 of file townname.cpp.

References lengthof, and SeedChanceBias().

## ◆ MakeCatalanTownName()

static void MakeCatalanTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates Catalan town name from given seed.

Parameters

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town name seed

Definition at line 847 of file townname.cpp.

References lengthof, and SeedChanceBias().

## ◆ MakeDutchTownName()

static void MakeDutchTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates Dutch town name from given seed.

Parameters

  builder | string builder
  seed | town name seed

Definition at line 458 of file townname.cpp.

References lengthof, and SeedChanceBias().

## ◆ MakeEnglishAdditionalTownName()

static void MakeEnglishAdditionalTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates English (Additional) town name from given seed.

Parameters

  builder | string builder
  seed | town name seed

Definition at line 283 of file townname.cpp.

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

## ◆ MakeEnglishOriginalTownName()

static void MakeEnglishOriginalTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates English (Original) town name from given seed.

Parameters

  builder | string builder
  seed | town name seed

Definition at line 250 of file townname.cpp.

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

## ◆ MakeFinnishTownName()

static void MakeFinnishTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates Finnish town name from given seed.

Parameters

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town name seed

Definition at line 360 of file townname.cpp.

References lengthof, and SeedChance().

## ◆ MakeHungarianTownName()

static void MakeHungarianTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates Hungarian town name from given seed.

Parameters

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town name seed

Definition at line 527 of file townname.cpp.

References lengthof, and SeedChance().

## ◆ MakeRomanianTownName()

static void MakeRomanianTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates Romanian town name from given seed.

Parameters

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town name seed

Definition at line 434 of file townname.cpp.

References lengthof, and SeedChanceBias().

## ◆ MakeSwissTownName()

static void MakeSwissTownName | ( | StringBuilder & | builder,
|  | uint32_t | seed
| ) |  |
| static

Generates Swiss town name from given seed.

Parameters

  builder | string builder
  seed | town 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

  builder | string builder
  seed | town 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

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

## ◆ 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

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

## ◆ SeedChance()

static uint32_t SeedChance | ( | byte | shift_by,
|  | int | max,
|  | uint32_t | seed
| ) |  |
| inlinestatic

Generates a number from given seed.

Parameters

  shift_by | number of bits seed is shifted to the right
  max | generated number is in interval 0...max-1
  seed | seed

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 | ( | byte | shift_by,
|  | int | max,
|  | uint32_t | seed,
|  | int | bias
| ) |  |
| inlinestatic

Generates a number from given seed.

Parameters

  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

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 | ( | byte | shift_by,
|  | int | max,
|  | uint32_t | seed
| ) |  |
| inlinestatic

Generates a number from given seed.

Uses different algorithm than SeedChance().

Parameters

  shift_by | number of bits seed is shifted to the right
  max | generated number is in interval 0...max-1
  seed | seed

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

  r | random bits
  par | town name parameters
  town_names | if 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:
= {
MakeEnglishOriginalTownName,
MakeFrenchTownName,
MakeGermanTownName,
MakeEnglishAdditionalTownName,
MakeSpanishTownName,
MakeSillyTownName,
MakeSwedishTownName,
MakeDutchTownName,
MakeFinnishTownName,
MakePolishTownName,
MakeSlovakTownName,
MakeNorwegianTownName,
MakeHungarianTownName,
MakeAustrianTownName,
MakeRomanianTownName,
MakeCzechTownName,
MakeSwissTownName,
MakeDanishTownName,
MakeTurkishTownName,
MakeItalianTownName,
MakeCatalanTownName,
}

Town name generators.

Definition at line 982 of file townname.cpp.

Referenced by GenerateTownNameString().

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