|
libtcod
|
#include <namegen.hpp>
Static Public Member Functions | |
| static void | parse (const char *filename, TCODRandom *random=NULL) |
| In order to be able to generate names, the name generator needs to be fed proper data. | |
| static void | destroy (void) |
| To release the resources used by a name generator, you may call: This will free all memory used by the generator. | |
| static char * | generate (char *name, bool allocate=false) |
| 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. | |
| static std::string | generate (const char *name, bool allocate=false) |
| static char * | generateCustom (char *name, char *rule, bool allocate=false) |
| It is also possible to generate a name using custom generation rules. | |
| static std::string | generateCustom (const char *name, const char *rule, bool allocate=false) |
| static TCOD_list_t | getSets (void) |
| If you wish to check the syllable set names that are currently available, you may call: This will create a list with all the available syllable set names. | |
This tool allows one to generate random names out of custom made syllable sets.
|
static |
To release the resources used by a name generator, you may call: This will free all memory used by the generator.
In order to generate a name again, you have to parse a file again.
|
static |
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.
| name | The structure name you wish to refer to, for instance, "celtic female". For more about how structure names work, please refer to those chapters. |
| allocate | Whether memory should be allocated for the output or not. |
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')
|
static |
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.
| name | The structure name you wish to refer to, for instance, "celtic female". For more about how structure names work, please refer to those chapters. |
| rule | The name generation rule. See this chapter for more details. |
| allocate | Whether memory should be allocated for the output or not. |
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')
|
static |
If you wish to check the syllable 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 |
In order to be able to generate names, the name generator needs to be fed proper data.
It will then be ready to generate random names defined in the file(s) it is fed. Syllable set parsing is achieved via the following. Note 1: Each file will be parsed once only. If, for some reason, you would like to parse the same file twice, you will need to destroy the generator first, which will empty the list of parsed files along with erasing all the data retrieved from those files.
Note 2: The generator can be fed data multiple times if you have it in separate files. Just make sure the structure names in them aren't duplicated, otherwise they will be silently ignored.
Note 3: In the C++ version, you are not obliged to specify the random number generator. If you skip it in the function call, the generator will assume you would like to use an instance of the default generator.
static void TCODNameGenerator::parse(string filename) static void TCODNameGenerator::parse(string filename, TCODRandom random)
| filename | The file where the desired syllable set is saved, along with its relative path, for instance, "data/names.txt". |
| random | A random number generator object. Use NULL for the default random number generator |
TCODNamegen::parse("data/names.txt",TCODRandom::getInstance()); TCODNamegen::parse("data/names2.txt");