-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpq_namegen.py
285 lines (257 loc) · 10.9 KB
/
pq_namegen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
"""
pq_namegen.py - A bunch of random name and flavor generators
for Percival's Quest.
I don't claim to have created ANY of these, though for most
of them I translated them to python. (I guess I can take credit
for the God generator, though that really belongs to Lovecraft et al...)
I found these scattered across the far corners of the internet
and appropriated them for my RPG. Sadly, in most cases I don't
remember where I found them, so I can't give credit. HOWEVER,
the monster description generator was kindly provided by the
bodacious Swordgleam over at ChaoticShiny.com (which website has
the most awesome set of generators ever).
"""
#
# pq_namegen.py
# part of Percival's Quest RPG
import random
import json
#generate a sandwich!
def sandgen(n=1):
"""Generates a random sandwich"""
such = random.choice([random.sample((' a beautiful', ' a delicious',
' an elegant', ' a fantastic', ' a mesmerizing', ' an enchanting',
' an amazing', ' a fabulous', ' a deadly', ' an adventurous',
' an ambitious', ' a brave', ' a creative', ' a discreet',
' an exuberant', ' a faithful', ' a friendly', ' a gentle',
' a damn good', ' an imaginative', ' an intellectual', ' a loving',
' a loyal', 'a modest', ' a neat', ' an optimistic', ' a jovial',
' a kick-ass', ' a healthy', ' a passionate', ' a pioneering',
' a plucky', ' a philosophical', ' a quirky', ' a reliable',
' a sincere', ' a thoughtful', ' a terrific', ' an understated',
' a vivacious', ' a wonderful', ' a xenophilic', ' a youthful',
' a zany'), n) for i in range(6)])
topping = random.choice([random.sample(('avocado', 'lettuce', 'tomato',
'mozzarella cheese', 'bacon', 'spam', 'peanut butter', 'bratwurst',
'cruelty-free PETA-approved fake guinea-pig', 'digital', 'cucumber',
'tofu', '-if slightly burnt-', 'recursive', 'banana', 'ice-cream',
'ham&jam', 'tuna', 'double cheese', 'olive', '..erm.. just',
'self-made', 'generic', 'sand', 'witch', 'two-hander'), n) \
for i in range(6)])
sandwich = [such[i] + ' ' + topping[i] + ' sandwich' for i in range(n)]
if n == 1:
return sandwich[0]
return sandwich
#A simple name generator using scrabble distribution
consonants = [('b', 2), ('c', 2), ('ch', 1), ('d', 4), ('f', 2),
('g', 3), ('h', 2), ('j', 1), ('k', 1), ('l', 4), ('m', 2),
('n', 6), ('p', 2), ('q', 1), ('qu', 1), ('r', 6), ('s', 4),
('t', 6), ('v', 2), ('w', 2), ('x', 1), ('z', 1),]
vowels = [('a', 9), ('e', 12), ('i', 9), ('o', 8), ('u', 4), ('y', 2)]
def selection(table):
"""Select one letter from the appropriate table."""
if type(table[-1]) is not type(0):
s = 0
for i in range(len(table)):
s += table[i][1]
table.append(s)
else:
s = table[-1]
# now the selection
n = random.randrange(s) + 1
for i in range(len(table) - 1):
n -= table[i][1]
if n <= 0:
return table[i][0]
# should not happen
return ''
def simple_namegen(minsyl = 1, maxsyl = 3, n = 1):
"""Name generator using scrabble letter distribution"""
names = []
for j in range(0, n):
numsyl = random.randint(minsyl, maxsyl)
word = []
for i in range(numsyl):
flag = 0
if random.randrange(100) < 60:
word.append(selection(consonants))
flag = 1
word.append(selection(vowels))
if not flag or random.randrange(100) < 40:
word.append(selection(consonants))
names.append("".join(word))
if n == 1:
return names[0]
return names
###A name generator which grabs from dicelog.com
def web_namegen(minsyl = 1, maxsyl = 3, n = 1):
"""Grab a randgen name from dicelog.com"""
import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://dicelog.com/yaf/rpc")
return proxy.names(minsyl, maxsyl, n)
###A syllable agglutinator namegen for dragons
dragonname = (('Vi', 'Ig', 'R', 'Ci', 'Ni', 'Ba', 'Be', 'Bi', 'Bre', 'Bry',
'Ca', 'Ce', 'Che', 'Ci', 'Co', 'Col', 'Cu', 'Da', 'De', 'Do', 'Du', 'Em',
'Fe', 'Fi', 'Ga', 'Gi', 'He', 'He', 'Ho', 'In', 'Ir', 'Ith', 'Je', 'Ji',
'Ka', 'Ke', 'Ki', 'Ko', 'Ky', 'Le', 'Li', 'Lo', 'Lu', 'Ly', 'Ma', 'Me',
'Mo', 'Mi', 'Mne', 'My', 'Na', 'Ne', 'No', 'Pa', 'Pe', 'Po', 'Que', 'Qui',
'Quo', 'Ra', 'Re', 'Rho', 'Ri', 'Ro', 'Ru', 'Ry', 'Sa', 'Se', 'Sha', 'She',
'Sho', 'Shu', 'Si', 'So', 'Ste', 'Su', 'Sy', 'Tae', 'Ta', 'Te', 'Ti', 'To',
'Tu', 'Ty', 'Va', 'Ve', 'Vo', 'Ze', 'Zi', 'Ju', 'Hi', 'Fu', 'Bri', 'Oh',
'Gre', 'Gra', 'Av', 'Rha', 'Um', 'Hu', 'Nv', 'Ap', 'As', 'At', 'Fa', 'Fra',
'Cor', 'Cul', 'Dal', 'Dar', 'Mer', 'Mar'),
('ar', 'al', 'am', 'ath', 'an', 'ad', 'bi', 'el', 'en', 'lu', 'ta', 'thy',
'th', 'ir', 'il', 'ith', 'in', 're', 'ri', 'ro', 'ra', 'rth', 'rro', 'gh',
'ga', 'li', 'lth', 'lla', 'la', 'si', 'sa', 'lo', 'vo', 'na', 'nth', 'ni',
'nnu', 'no', 'nno', 'ne', 'yo', 'yd', 'oth', 'dre', 'do', 'de', 'da', 'du',
'mma', 'mro', 'mi', 'sso', 'ssi', 'zz', 'ze', 'vu', 'nni', 'ja', 'us',
'zo', 'lle'))
def dragon_namegen(minsyl = 2, maxsyl = 4, n = 1):
"""Agglutinate syllables into a draconic name."""
names = []
for i in range(n):
word = [random.choice([random.choice(dragonname[0]) \
for k in range(6)])]
numsyl = random.randint(minsyl, maxsyl)
for j in range(0, numsyl):
word.append(random.choice([random.choice(dragonname[1]) \
for k in range(6)]))
names.append("".join(word))
if n == 1:
return names[0]
return names
###Artifact generator!
def artygen(n = 1):
"""Generate a powerful artifact."""
with open('data/pq_artifact_dict.json') as f:
arty = json.load(f)
artifact = []
for k in range(n):
artifact_pieces = []
for i in arty:
artifact_pieces.append(random.choice([random.choice(i) \
for j in range(6)]))
artifact.append(' '.join(artifact_pieces))
if n == 1:
return artifact[0]
return artifact
#MONSTER DESCRIPTION GENERATOR, courtesy of the awesome
#Swordgleam from ChaoticShiny.com!
def monster_gen(n = 1):
"""Generate a monster description"""
with open('data/pq_monster_description_dict.json') as f:
monster_description = json.load(f)
monster = []
for kk in range(n):
sz = random.choice(monster_description['size'])
#ty0 = random.randint(0, len(monster_description['type'] - 1))
typ = random.choice(monster_description['type'])
if random.randint(0, 1):
', '.join([typ, random.choice([x for x in \
monster_description['type'] if x != typ])])
th = random.choice(monster_description['thing'])
lv = random.choice(monster_description['lives'])
pl = random.choice(monster_description['place'])
desc1 = 'This '+' '.join([sz, typ, th, lv, 'in', pl + '.'])
if random.randint(0, 1):
hw = random.choice(monster_description['how'])
pt = 'its prey, which includes'
z = random.randint(1, 3)
if z > 1:
pr = ''
for i in range(z):
pr += random.choice([x for x in \
monster_description['prey'] if x not in pr]) + ', '
else: pr = random.choice(monster_description['prey'])
pr += 'and ' + random.choice([x for x \
in monster_description['prey'] if x not in pr])
desc2 = ' '.join(['It', hw, pt, pr + '.'])
desc = ' '.join([desc1, desc2])
else: desc = desc1
pt = 'It attacks with'
matk = random.choice(monster_description['mattack'])
z = 0
if random.randint(0, 2) != 1: z += 1
if random.randint(0, 5) == 1: z += 1
atk = ''
for i in range(z):
atk += random.choice([x for x in monster_description['attack'] \
if x not in atk]) + ', '
atk += 'and '+random.choice([x for x in monster_description['attack'] \
if x not in atk])
if not atk.startswith('and'):
matk += ', '
desc = ' '.join([desc, pt, matk, atk + '.'])
if random.randint(0, 2) == 1:
desc = ' '.join([desc, 'It', \
random.choice(monster_description['dis']), \
random.choice(monster_description['weak']) + '.'])
if random.randint(0, 9) > 5:
hl = random.choice(monster_description['hl'])
if random.randint(0, 5) == 1:
grp = 'alone'
else:
r1 = random.randint(1, 5)
r2 = random.randint(1, 20) + r1
grp = ' '.join(['in', \
random.choice(monster_description['group']), 'of', \
'-'.join([str(r1), str(r2)])])
desc = ' '.join([desc, 'They', hl, grp + '.'])
if random.randint(0, 9) > 5:
desc = ' '.join([desc, random.choice(monster_description['rumor']),
random.choice(monster_description['rumor2']) + '.'])
monster.append(desc)
if n == 1:
return monster[0]
return monster
#Tavern name generator!
def taverngen(n = 1, longname = False):
"""Generate a random tavern"""
with open('data/pq_taverns_tuple.json') as f:
taverns = json.load(f)
tavern = []
for kk in range(n):
pick = random.choice([random.choice(taverns[0]) for i in range(6)])
pick += random.choice([random.choice(taverns[1]) for i in range(6)])
if longname:
pick += random.choice([random.choice(taverns[2]) \
for i in range(6)])
tavern.append(pick)
if n == 1:
return tavern[0]
return tavern
#riddle generator, using wordlock chest riddles from betrayal at krondor
def riddlegen(n = 1):
"""Grab a riddle from the database!"""
with open('data/pq_riddle_dict.json') as f:
riddles = json.load(f)
riddle = []
for i in range(n):
answer = random.choice([random.choice(riddles.keys()) \
for j in range(6)])
text = riddles[answer]
riddle.append((answer, text))
if n == 1:
riddle = riddle[0]
return riddle
#generate a random set of numbers, as a string
def numgen(l = 4, n = 1):
"""Create a string of digits of length l"""
number = []
for i in range(n):
answer = ''
for j in range(l):
answer += str(random.randint(0, 9))
number.append(answer)
if n == 1:
number = number[0]
return number
#produce a random deity from the Lovecraft mythos
def godgen(n = 1):
"""Grab a god name from the database!"""
with open('data/pq_gods_tuple.json') as f:
gods = json.load(f)
god = random.choice([random.sample(gods, n) for j in range(6)])
if type(god) is list and len(god) == 1:
return god[0]
return god