OpenTTD Source  1.11.2
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 "table/townname.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  TownNameGeneratorParams
 Contains pointer to generator and minimum buffer size (not incl. More...
 

Typedefs

typedef char * TownNameGenerator(char *buf, const char *last, uint32 seed)
 Type for all town name generator functions. More...
 

Functions

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

Variables

static const TownNameGeneratorParams _town_name_generators []
 Town name generators. More...
 

Detailed Description

Town name generators.

Definition in file townname.cpp.

Typedef Documentation

◆ TownNameGenerator

typedef char* TownNameGenerator(char *buf, const char *last, uint32 seed)

Type for all town name generator functions.

Parameters
bufThe buffer to write the name to.
lastThe last element of the buffer.
seedThe seed of the town name.
Returns
The end of the filled buffer.

Definition at line 1012 of file townname.cpp.

Function Documentation

◆ GenerateTownName()

bool GenerateTownName ( uint32 *  townnameparts,
TownNames *  town_names 
)

Generates valid town name.

Parameters
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 119 of file townname.cpp.

References _generating_world, _settings_game, GameSettings::game_creation, Layouter::ReduceLineCache(), and GameCreationSettings::town_name.

◆ GenerateTownNameString()

char* GenerateTownNameString ( char *  buf,
const char *  last,
size_t  lang,
uint32  seed 
)

Generates town name from given seed.

Parameters
bufoutput buffer
lastend of buffer
langtown name language
seedgeneration seed
Returns
last character ('/0')

Definition at line 1054 of file townname.cpp.

References _town_name_generators, AllocaM, lengthof, TownNameGeneratorParams::min, TownNameGeneratorParams::proc, and strecpy().

◆ GetTownName() [1/2]

char* GetTownName ( char *  buff,
const Town t,
const char *  last 
)

Fills buffer with town's name.

Parameters
buffbuffer start
twe want to get name of this town
lastend of buffer
Returns
pointer to terminating '\0'

Definition at line 68 of file townname.cpp.

References GetTownName().

◆ GetTownName() [2/2]

char* GetTownName ( char *  buff,
const TownNameParams par,
uint32  townnameparts,
const char *  last 
)

Fills buffer with specified town name.

Parameters
buffbuffer start
partown name parameters
townnameparts'encoded' town name
lastend of buffer
Returns
pointer to terminating '\0'

Definition at line 49 of file townname.cpp.

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

Referenced by GetTownName(), and VerifyTownName().

◆ MakeAustrianTownName()

static char* MakeAustrianTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Austrian town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 307 of file townname.cpp.

References lengthof, and SeedChanceBias().

◆ MakeCatalanTownName()

static char* MakeCatalanTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Catalan town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 974 of file townname.cpp.

References SeedModChance(), and strecpy().

◆ MakeCzechTownName()

static char* MakeCzechTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Czech town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 596 of file townname.cpp.

References SeedModChance(), and strecpy().

◆ MakeDanishTownName()

static char* MakeDanishTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Danish town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 869 of file townname.cpp.

References lengthof, and SeedChanceBias().

◆ MakeDutchTownName()

static char* MakeDutchTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Dutch town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 460 of file townname.cpp.

References lengthof, and SeedChanceBias().

◆ MakeEnglishAdditionalTownName()

static char* MakeEnglishAdditionalTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates English (Additional) town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 268 of file townname.cpp.

References lengthof, and SeedChanceBias().

◆ MakeEnglishOriginalTownName()

static char* MakeEnglishOriginalTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates English (Original) town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 232 of file townname.cpp.

References lengthof, and SeedChanceBias().

◆ MakeFinnishTownName()

static char* MakeFinnishTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Finnish town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 486 of file townname.cpp.

References SeedChance(), and strecpy().

◆ MakeFrenchTownName()

static char* MakeFrenchTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates French town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 406 of file townname.cpp.

References strecpy().

◆ MakeGermanTownName()

static char* MakeGermanTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates German town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 351 of file townname.cpp.

References lengthof, and SeedChance().

◆ MakeHungarianTownName()

static char* MakeHungarianTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Hungarian town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 827 of file townname.cpp.

References SeedChance(), and strecpy().

◆ MakeItalianTownName()

static char* MakeItalianTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Italian town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 926 of file townname.cpp.

References SeedModChance(), and strecpy().

◆ MakeNorwegianTownName()

static char* MakeNorwegianTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Norwegian town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 803 of file townname.cpp.

References SeedChance(), and strecpy().

◆ MakePolishTownName()

static char* MakePolishTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Polish town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 534 of file townname.cpp.

References lengthof, and SeedChance().

◆ MakeRomanianTownName()

static char* MakeRomanianTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Romanian town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 779 of file townname.cpp.

References strecpy().

◆ MakeSillyTownName()

static char* MakeSillyTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Silly town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 418 of file townname.cpp.

References strecpy().

◆ MakeSlovakTownName()

static char* MakeSlovakTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Slovak town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 791 of file townname.cpp.

References strecpy().

◆ MakeSpanishTownName()

static char* MakeSpanishTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Latin-American town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 394 of file townname.cpp.

References strecpy().

◆ MakeSwedishTownName()

static char* MakeSwedishTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Swedish town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 433 of file townname.cpp.

References lengthof, and SeedChanceBias().

◆ MakeSwissTownName()

static char* MakeSwissTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Swiss town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 857 of file townname.cpp.

References strecpy().

◆ MakeTurkishTownName()

static char* MakeTurkishTownName ( char *  buf,
const char *  last,
uint32  seed 
)
static

Generates Turkish town name from given seed.

Parameters
bufoutput buffer
seedtown name seed
lastend of buffer

Definition at line 889 of file townname.cpp.

References SeedModChance(), and strecpy().

◆ ReplaceEnglishWords()

static void ReplaceEnglishWords ( char *  buf,
bool  original 
)
static

Replaces english curses and ugly letter combinations by nicer ones.

Parameters
bufbuffer with town name
originalEnglish (Original) generator was used

Definition at line 212 of file townname.cpp.

References ReplaceWords().

◆ ReplaceWords()

static void ReplaceWords ( const char *  org,
const char *  rep,
char *  buf 
)
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
bufbuffer with string

Definition at line 200 of file townname.cpp.

Referenced by ReplaceEnglishWords().

◆ SeedChance()

static uint32 SeedChance ( byte  shift_by,
int  max,
uint32  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 152 of file townname.cpp.

References GB().

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

◆ SeedChanceBias()

static int32 SeedChanceBias ( byte  shift_by,
int  max,
uint32  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 188 of file townname.cpp.

References SeedChance().

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

◆ SeedModChance()

static uint32 SeedModChance ( byte  shift_by,
int  max,
uint32  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 165 of file townname.cpp.

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

◆ VerifyTownName()

bool VerifyTownName ( uint32  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 82 of file townname.cpp.

References GetTownName(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Iterate(), lastof, MAX_CHAR_LENGTH, MAX_LENGTH_TOWN_NAME_CHARS, and Utf8StringLength().

Variable Documentation

◆ _town_name_generators

MakeTurkishTownName
static char * MakeTurkishTownName(char *buf, const char *last, uint32 seed)
Generates Turkish town name from given seed.
Definition: townname.cpp:889
MakeRomanianTownName
static char * MakeRomanianTownName(char *buf, const char *last, uint32 seed)
Generates Romanian town name from given seed.
Definition: townname.cpp:779
MakeDutchTownName
static char * MakeDutchTownName(char *buf, const char *last, uint32 seed)
Generates Dutch town name from given seed.
Definition: townname.cpp:460
MakeSwissTownName
static char * MakeSwissTownName(char *buf, const char *last, uint32 seed)
Generates Swiss town name from given seed.
Definition: townname.cpp:857
MakePolishTownName
static char * MakePolishTownName(char *buf, const char *last, uint32 seed)
Generates Polish town name from given seed.
Definition: townname.cpp:534
MakeGermanTownName
static char * MakeGermanTownName(char *buf, const char *last, uint32 seed)
Generates German town name from given seed.
Definition: townname.cpp:351
MakeSpanishTownName
static char * MakeSpanishTownName(char *buf, const char *last, uint32 seed)
Generates Latin-American town name from given seed.
Definition: townname.cpp:394
MakeCatalanTownName
static char * MakeCatalanTownName(char *buf, const char *last, uint32 seed)
Generates Catalan town name from given seed.
Definition: townname.cpp:974
MakeSillyTownName
static char * MakeSillyTownName(char *buf, const char *last, uint32 seed)
Generates Silly town name from given seed.
Definition: townname.cpp:418
MakeDanishTownName
static char * MakeDanishTownName(char *buf, const char *last, uint32 seed)
Generates Danish town name from given seed.
Definition: townname.cpp:869
MakeFrenchTownName
static char * MakeFrenchTownName(char *buf, const char *last, uint32 seed)
Generates French town name from given seed.
Definition: townname.cpp:406
MakeAustrianTownName
static char * MakeAustrianTownName(char *buf, const char *last, uint32 seed)
Generates Austrian town name from given seed.
Definition: townname.cpp:307
MakeSwedishTownName
static char * MakeSwedishTownName(char *buf, const char *last, uint32 seed)
Generates Swedish town name from given seed.
Definition: townname.cpp:433
MakeFinnishTownName
static char * MakeFinnishTownName(char *buf, const char *last, uint32 seed)
Generates Finnish town name from given seed.
Definition: townname.cpp:486
MakeEnglishOriginalTownName
static char * MakeEnglishOriginalTownName(char *buf, const char *last, uint32 seed)
Generates English (Original) town name from given seed.
Definition: townname.cpp:232
MakeCzechTownName
static char * MakeCzechTownName(char *buf, const char *last, uint32 seed)
Generates Czech town name from given seed.
Definition: townname.cpp:596
MakeHungarianTownName
static char * MakeHungarianTownName(char *buf, const char *last, uint32 seed)
Generates Hungarian town name from given seed.
Definition: townname.cpp:827
MakeSlovakTownName
static char * MakeSlovakTownName(char *buf, const char *last, uint32 seed)
Generates Slovak town name from given seed.
Definition: townname.cpp:791
MakeEnglishAdditionalTownName
static char * MakeEnglishAdditionalTownName(char *buf, const char *last, uint32 seed)
Generates English (Additional) town name from given seed.
Definition: townname.cpp:268
MakeItalianTownName
static char * MakeItalianTownName(char *buf, const char *last, uint32 seed)
Generates Italian town name from given seed.
Definition: townname.cpp:926
MakeNorwegianTownName
static char * MakeNorwegianTownName(char *buf, const char *last, uint32 seed)
Generates Norwegian town name from given seed.
Definition: townname.cpp:803