libtcoddocumentation

15.2. Generating a name

Generating a default name

The following will output a random name generated using one of the generation rules specified in the syllable set:
Should you choose to allocate memory for the output, you need to remember to deallocate it once you don't need the name anymore using the free() function. This applies to C++ as well (delete won't work - you have to use free()).

On the other hand, should you choose not to allocate memory, be aware that subsequent calls will overwrite the previously returned pointer, so make sure to copy the output using strcpy(), strdup() or other means of your choosing.

The name you specify needs to be in one of the files the generator has previously parsed (see Creating a generator). If such a name doesn't exist, a warning will be displayed and NULL will be returned.

static char * TCODNamegen::generate (char * name, bool allocate = false)

char * TCOD_namegen_generate (char * name, bool allocate)

namegen_generate (name, allocate = 0)

string TCODNameGenerator::generate (string name)

ParameterDescription
nameThe structure name you wish to refer to, for instance, "celtic female".
For more about how structure names work, please refer to those chapters.
allocateWhether memory should be allocated for the output or not.
Example:

TCODNamegen::parse("data/names.txt",TCODRandom::getInstance());
char
* myName = TCODNamegen::generate("fantasy female");

TCOD_namegen_parse("data/names.txt",TCOD_random_get_instance());
char
* my_name = TCOD_namegen_generate("Celtic male",false);

libtcod.namegen_parse('data/names.txt')
name = libtcod.namegen_generate('Nordic female')


Generating a custom name

It is also possible to generate a name using custom generation rules. This overrides the random choice of a generation rule from the syllable set. Please refer to chapter 16.5 to learn about the name generation rules syntax.

static char * TCODNamegen::generateCustom (char * name, char * rule, bool allocate = false)

char * TCOD_namegen_generate_custom (char * name, char * rule, bool allocate)

namegen_generate_custom (name, rule, allocate = 0)

string TCODNameGenerator::generateCustom (string name, string rule)

ParameterDescription
nameThe structure name you wish to refer to, for instance, "celtic female".
For more about how structure names work, please refer to those chapters.
ruleThe name generation rule. See this chapter for more details.
allocateWhether memory should be allocated for the output or not.
Example:

TCODNamegen::parse("data/names.txt",TCODRandom::getInstance());
char
* myName = TCODNamegen::generateCustom("Nordic male","$s$e");

TCOD_namegen_parse("data/names.txt",TCOD_random_get_instance());
char
* my_name = TCOD_namegen_generate_custom("Mesopotamian female","$s$e",false);

libtcod.namegen_parse('data/names.txt')
name = libtcod.namegen_generate_custom('Nordic female','$s$e')


Retrieving available set names

If you wish to check the sylable set names that are currently available, you may call:
This will create a list with all the available syllable set names. Remember to delete that list after you don't need it anymore!

static TCODList TCODNamegen::getSets ()

TCOD_list_t TCOD_namegen_get_sets ()

namegen_get_sets ()

static IEnumerable<string> TCODNameGenerator::getSets()