Planeshift
namegenerator.h
Go to the documentation of this file.
1 /*
2 * namegenerator.h by Andrew Mann <amann tccgi.com>
3 *
4 * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 
19 #ifndef __NAMEGENERATOR_H__
20 #define __NAMEGENERATOR_H__
21 
22 
23 #include <csutil/parray.h>
24 #include <csutil/randomgen.h>
25 
26 struct iObjectRegistry;
27 
33 /* Name generation functions.
34  * These classes allow for generation of random names.
35  *
36  * The current implementation uses a table of phonetic spellings for the english language.
37  *
38  * Usage:
39  *
40  * Create a new NameGenerationSystem() after the database connection has been established.
41  * Call NameGenerationSystem::GenerateName(TYPE,csString *namebuffer,max_low,max_high).
42  * On return, the passed csString will be filled with the name as requested.
43  *
44  * The type should be one of the enum below. Currently:
45  * NAMEGENERATOR_FEMALE_FIRST_NAME
46  * NAMEGENERATOR_MALE_FIRST_NAME
47  * NAMEGENERATOR_FAMILY_NAME
48  *
49  * max_low and max_high are not hard maximums. Rather, a random number is picked between low and high. As name generation progresses, if
50  * the length of the name exceeds this number, and ending sequence is added. The resulting string will be 1-9 characters longer than the
51  * number picked.
52  *
53  * Some rough guidelines and notes:
54  *
55  * Male names seem to come out much better when shorter. Try max_low = 3 and max_high = 5 for male first names.
56  * Female names seem to work well with max_low=7 max_high=7 .
57  * Surnames (family names) work ok with 8,10 .
58  *
59  *
60  *
61  */
62 
63 
64 /* This implementation works by classifying phonetic bits according to 5 properties:
65  * Likelyness to begin a name
66  * Likelyness to end a name
67  * Likelyness to appear in the middle of a name
68  * Begins in a vowel
69  * Ends in a vowel
70  *
71  * The last two properties are not strictly tied to vowels, but generally follow that pattern. They help the name generator
72  * decide which sequences can appear next to each other without resulting in unpronouncable names.
73  *
74  * The first three values are determined by running a list of a particular type of name (male first names for example) through a
75  * filter that searches for occurances of each phonetic bit and adjusts the weight accordingly.
76  * The current filter is written in perl.
77  *
78  */
79 
80 
81 
82 enum {
87 };
88 
89 
90 #define PHONIC_PREJOINER 0x01
91 #define PHONIC_POSTJOINER 0x02
92 
93 
95 {
96 public:
97  PhonicEntry();
98  PhonicEntry(char *ph,float b_p,float e_p,float m_p,unsigned int fl);
99  ~PhonicEntry();
100 
101 public:
102  char phonic[6];
104  unsigned int flags;
105 };
106 
107 
109 {
110 public:
111  NameGenerator(iDocumentNode* node);
112  ~NameGenerator();
113 
114  void GenerateName(csString &namebuffer,int length_low,int length_high);
115 
116 private:
117  float begin_total,end_total,prejoin_total,nonprejoin_total;
118  int entry_count;
119  csPDelArray<PhonicEntry> entries;
120  csRandomGen *randomgen;
121 
122  PhonicEntry *GetRandomBeginner();
123  PhonicEntry *GetRandomEnder(bool prejoiner);
124  PhonicEntry *GetRandomPreJoiner();
125  PhonicEntry *GetRandomNonPreJoiner();
126 
127 };
128 
130 {
131 public:
134 
138  bool LoadDatabase( iObjectRegistry* objectReg );
142  void GenerateName(int generator_type,csString &namebuffer,int length_low,int length_high);
143 
144 private:
145  NameGenerator *generators[NAMEGENERATOR_MAX];
146 };
147 
150 #endif
151 
float middle_probability
float begin_probability
float end_probability
char phonic[6]
unsigned int flags