OpenTTD Source: src/townname.cpp File Reference

OpenTTD Source 15.0-beta1

Typedefs | Functions | Variables
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.

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

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

Referenced by GenerateTowns().

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

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

References GetTownName().

## ◆ 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(), GetTownName(), 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 SeedChance(), 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 SeedChance(), and 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 StringBuilder::CurrentIndex(), GB(), StringBuilder::RemoveElementsFromBack(), and 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 SeedChance(), 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 SeedChance(), 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(), ReplaceEnglishWords(), SeedChance(), 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(), ReplaceEnglishWords(), SeedChance(), 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.

References SeedChance().

## ◆ 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 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 SeedChance(), and 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 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.

References SeedChance().

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

References SeedChance().

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

References SeedChance().

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

References SeedChance().

## ◆ 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 SeedChance(), 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.

References SeedChance().

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

Referenced by MakeEnglishAdditionalTownName(), and MakeEnglishOriginalTownName().

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