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 "table/townname.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. | |
Functions | |
char * | GetTownName (char *buff, const TownNameParams *par, uint32 townnameparts, const char *last) |
Fills buffer with specified town name. | |
char * | GetTownName (char *buff, const Town *t, const char *last) |
Fills buffer with town's name. | |
bool | VerifyTownName (uint32 r, const TownNameParams *par) |
Verifies the town name is valid and unique. | |
bool | GenerateTownName (uint32 *townnameparts) |
Generates valid town name. | |
static uint32 | SeedChance (byte shift_by, int max, uint32 seed) |
Generates a number from given seed. | |
static uint32 | SeedModChance (byte shift_by, int max, uint32 seed) |
Generates a number from given seed. | |
static int32 | SeedChanceBias (byte shift_by, int max, uint32 seed, int bias) |
Generates a number from given seed. | |
static void | ReplaceWords (const char *org, const char *rep, char *buf) |
Replaces a string beginning in 'org' with 'rep'. | |
static void | ReplaceEnglishWords (char *buf, bool original) |
Replaces english curses and ugly letter combinations by nicer ones. | |
static char * | MakeEnglishOriginalTownName (char *buf, const char *last, uint32 seed) |
Generates English (Original) town name from given seed. | |
static char * | MakeEnglishAdditionalTownName (char *buf, const char *last, uint32 seed) |
Generates English (Additional) town name from given seed. | |
static char * | MakeAustrianTownName (char *buf, const char *last, uint32 seed) |
Generates Austrian town name from given seed. | |
static char * | MakeGermanTownName (char *buf, const char *last, uint32 seed) |
Generates German town name from given seed. | |
static char * | MakeSpanishTownName (char *buf, const char *last, uint32 seed) |
Generates Latin-American town name from given seed. | |
static char * | MakeFrenchTownName (char *buf, const char *last, uint32 seed) |
Generates French town name from given seed. | |
static char * | MakeSillyTownName (char *buf, const char *last, uint32 seed) |
Generates Silly town name from given seed. | |
static char * | MakeSwedishTownName (char *buf, const char *last, uint32 seed) |
Generates Swedish town name from given seed. | |
static char * | MakeDutchTownName (char *buf, const char *last, uint32 seed) |
Generates Dutch town name from given seed. | |
static char * | MakeFinnishTownName (char *buf, const char *last, uint32 seed) |
Generates Finnish town name from given seed. | |
static char * | MakePolishTownName (char *buf, const char *last, uint32 seed) |
Generates Polish town name from given seed. | |
static char * | MakeCzechTownName (char *buf, const char *last, uint32 seed) |
Generates Czech town name from given seed. | |
static char * | MakeRomanianTownName (char *buf, const char *last, uint32 seed) |
Generates Romanian town name from given seed. | |
static char * | MakeSlovakTownName (char *buf, const char *last, uint32 seed) |
Generates Slovak town name from given seed. | |
static char * | MakeNorwegianTownName (char *buf, const char *last, uint32 seed) |
Generates Norwegian town name from given seed. | |
static char * | MakeHungarianTownName (char *buf, const char *last, uint32 seed) |
Generates Hungarian town name from given seed. | |
static char * | MakeSwissTownName (char *buf, const char *last, uint32 seed) |
Generates Swiss town name from given seed. | |
static char * | MakeDanishTownName (char *buf, const char *last, uint32 seed) |
Generates Danish town name from given seed. | |
static char * | MakeTurkishTownName (char *buf, const char *last, uint32 seed) |
Generates Turkish town name from given seed. | |
static char * | MakeItalianTownName (char *buf, const char *last, uint32 seed) |
Generates Italian town name from given seed. | |
static char * | MakeCatalanTownName (char *buf, const char *last, uint32 seed) |
Generates Catalan town name from given seed. | |
char * | GenerateTownNameString (char *buf, const char *last, size_t lang, uint32 seed) |
Generates town name from given seed. | |
Variables | |
static const TownNameGeneratorParams | _town_name_generators [] |
Town name generators. |
Town name generators.
Definition in file townname.cpp.
typedef char* TownNameGenerator(char *buf, const char *last, uint32 seed) |
Type for all town name generator functions.
buf | The buffer to write the name to. | |
last | The last element of the buffer. | |
seed | The seed of the town name. |
Definition at line 998 of file townname.cpp.
bool GenerateTownName | ( | uint32 * | townnameparts | ) |
Generates valid town name.
townnameparts | if a name is generated, it's stored there |
Definition at line 112 of file townname.cpp.
References _settings_game, GameSettings::game_creation, GameCreationSettings::town_name, and VerifyTownName().
Referenced by GenerateTowns().
char* GenerateTownNameString | ( | char * | buf, | |
const char * | last, | |||
size_t | lang, | |||
uint32 | seed | |||
) |
Generates town name from given seed.
a language.
buf | output buffer | |
last | end of buffer | |
lang | town name language | |
seed | generation seed |
Definition at line 1040 of file townname.cpp.
References AllocaM, lengthof, TownNameGeneratorParams::min, TownNameGeneratorParams::proc, and strecpy().
Referenced by FormatString().
char* GetTownName | ( | char * | buff, | |
const TownNameParams * | par, | |||
uint32 | townnameparts, | |||
const char * | last | |||
) |
Fills buffer with specified town name.
buff | buffer start | |
par | town name parameters | |
townnameparts | 'encoded' town name | |
last | end of buffer |
Definition at line 48 of file townname.cpp.
References GetStringWithArgs(), TownNameParams::grfid, and TownNameParams::type.
Referenced by FormatString(), GetTownName(), and VerifyTownName().
char* GetTownName | ( | char * | buff, | |
const Town * | t, | |||
const char * | last | |||
) |
Fills buffer with town's name.
buff | buffer start | |
t | we want to get name of this town | |
last | end of buffer |
Definition at line 67 of file townname.cpp.
References GetTownName().
static char* MakeAustrianTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Austrian town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 295 of file townname.cpp.
References lengthof, SeedChance(), SeedChanceBias(), and strecpy().
static char* MakeCatalanTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Catalan town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 960 of file townname.cpp.
References lengthof, SeedChance(), SeedModChance(), and strecpy().
static char* MakeCzechTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Czech town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 584 of file townname.cpp.
References GB(), lengthof, SeedModChance(), and strecpy().
static char* MakeDanishTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Danish town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 855 of file townname.cpp.
References lengthof, SeedChance(), SeedChanceBias(), and strecpy().
static char* MakeDutchTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Dutch town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 448 of file townname.cpp.
References lengthof, SeedChance(), SeedChanceBias(), and strecpy().
static char* MakeEnglishAdditionalTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates English (Additional) town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 256 of file townname.cpp.
References lengthof, ReplaceEnglishWords(), SeedChance(), SeedChanceBias(), and strecpy().
static char* MakeEnglishOriginalTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates English (Original) town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 220 of file townname.cpp.
References lengthof, ReplaceEnglishWords(), SeedChance(), SeedChanceBias(), and strecpy().
static char* MakeFinnishTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Finnish town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 474 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeFrenchTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates French town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 394 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeGermanTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates German town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 339 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeHungarianTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Hungarian town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 813 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeItalianTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Italian town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 912 of file townname.cpp.
References lengthof, SeedChance(), SeedModChance(), and strecpy().
static char* MakeNorwegianTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Norwegian town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 789 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakePolishTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Polish town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 522 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeRomanianTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Romanian town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 765 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeSillyTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Silly town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 406 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeSlovakTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Slovak town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 777 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeSpanishTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Latin-American town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 382 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeSwedishTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Swedish town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 421 of file townname.cpp.
References lengthof, SeedChance(), SeedChanceBias(), and strecpy().
static char* MakeSwissTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Swiss town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 843 of file townname.cpp.
References lengthof, SeedChance(), and strecpy().
static char* MakeTurkishTownName | ( | char * | buf, | |
const char * | last, | |||
uint32 | seed | |||
) | [static] |
Generates Turkish town name from given seed.
buf | output buffer | |
seed | town name seed | |
last | end of buffer |
Definition at line 875 of file townname.cpp.
References lengthof, SeedModChance(), and strecpy().
static void ReplaceEnglishWords | ( | char * | buf, | |
bool | original | |||
) | [static] |
Replaces english curses and ugly letter combinations by nicer ones.
buf | buffer with town name | |
original | English (Original) generator was used |
Definition at line 200 of file townname.cpp.
References ReplaceWords().
Referenced by MakeEnglishAdditionalTownName(), and MakeEnglishOriginalTownName().
static void ReplaceWords | ( | const char * | org, | |
const char * | rep, | |||
char * | buf | |||
) | [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 | |
buf | buffer with string |
Definition at line 189 of file townname.cpp.
Referenced by ReplaceEnglishWords().
static uint32 SeedChance | ( | byte | shift_by, | |
int | max, | |||
uint32 | seed | |||
) | [inline, static] |
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 141 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().
static int32 SeedChanceBias | ( | byte | shift_by, | |
int | max, | |||
uint32 | seed, | |||
int | bias | |||
) | [inline, static] |
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 177 of file townname.cpp.
References SeedChance().
Referenced by MakeAustrianTownName(), MakeDanishTownName(), MakeDutchTownName(), MakeEnglishAdditionalTownName(), MakeEnglishOriginalTownName(), and MakeSwedishTownName().
static uint32 SeedModChance | ( | byte | shift_by, | |
int | max, | |||
uint32 | seed | |||
) | [inline, static] |
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 154 of file townname.cpp.
Referenced by MakeCatalanTownName(), MakeCzechTownName(), MakeItalianTownName(), and MakeTurkishTownName().
bool VerifyTownName | ( | uint32 | r, | |
const TownNameParams * | par | |||
) |
Verifies the town name is valid and unique.
r | random bits | |
par | town name parameters |
Definition at line 80 of file townname.cpp.
References GetTownName(), lastof, MAX_CHAR_LENGTH, MAX_LENGTH_TOWN_NAME_CHARS, and Utf8StringLength().
Referenced by CmdFoundTown(), and GenerateTownName().
const TownNameGeneratorParams _town_name_generators[] [static] |
{ { 4, MakeEnglishOriginalTownName}, { 0, MakeFrenchTownName}, { 0, MakeGermanTownName}, { 4, MakeEnglishAdditionalTownName}, { 0, MakeSpanishTownName}, { 0, MakeSillyTownName}, { 0, MakeSwedishTownName}, { 0, MakeDutchTownName}, { 8, MakeFinnishTownName}, { 0, MakePolishTownName}, { 0, MakeSlovakTownName}, { 0, MakeNorwegianTownName}, { 0, MakeHungarianTownName}, { 0, MakeAustrianTownName}, { 0, MakeRomanianTownName}, { 28, MakeCzechTownName}, { 0, MakeSwissTownName}, { 0, MakeDanishTownName}, { 0, MakeTurkishTownName}, { 0, MakeItalianTownName}, { 0, MakeCatalanTownName}, }
Town name generators.
Definition at line 1007 of file townname.cpp.