def process_string(s = ''): result = s.strip() rng = ng_names[random.randrange(0, len(ng_names))] #first parse name with random one while result.find("__name__") > 0: result = result.replace("__name__", libtcod.namegen_generate(rng), 1) rng = ng_towns[random.randrange(0, len(ng_towns))] while result.find("__city__") > 0: result = result.replace("__city__", libtcod.namegen_generate(rng), 1) rng = ng_towns[random.randrange(0, len(ng_towns))] while result.find("__village__") > 0: result = result.replace("__village__", libtcod.namegen_generate(rng), 1) rng = ng_demons[random.randrange(0, len(ng_demons))] while result.find("__demon__") > 0: result = result.replace("__demon__", libtcod.namegen_generate(rng), 1) #now parse age, making any next __age__ occurance to be more than previous start_age = 7 while result.find("__age__") > 0: rand_age = random.randrange(start_age, start_age + 7) result = result.replace("__age__", str(rand_age), 1) start_age = rand_age while result.find("djective__") > 0: rand1, rand2 = random.randrange(0, len(adjs)), random.randrange(0, len(adjs)) result = result.replace("__Adjective__", adjs[rand1].strip().capitalize(), 1) result = result.replace("__adjective__", adjs[rand1].strip(), 1) while result.find("oun__") > 0: rand1, rand2 = random.randrange(0, len(nns)), random.randrange(0, len(nns)) result = result.replace("__Noun__", nns[rand1].strip().capitalize(), 1) result = result.replace("__noun__", nns[rand2].strip(), 1) while result.find("rofession__") > 0: rand1, rand2 = random.randrange(0, len(profs)), random.randrange(0, len(profs)) result = result.replace("__Profession__", profs[rand1].strip().capitalize(), 1) result = result.replace("__profession__", profs[rand2].strip(), 1) while result.find("__skill__") > 0 or result.find("__Skill__") > 0: rand1, rand2 = random.randrange(0, len(skls)), random.randrange(0, len(skls)) result = result.replace("__Skill__", skls[rand1].strip().capitalize(), 1) result = result.replace("__skill__", skls[rand2].strip(), 1) return result
def __create_name_gen(prefix, statics): static_names_gen = [] ng_sets = [] global name_gens for name_gen in name_gens: if name_gen.startswith(prefix.strip()): ng_sets.append(name_gen) if statics is not None: names_list = map(lambda x: x.strip().replace('_', ' '), statics.strip().split(' ')) random.shuffle(names_list) static_names_gen = itertools.cycle(names_list) while True: if roll(1, 8) == 8 and statics is not None: name = static_names_gen.next() yield name name = libtcod.namegen_generate(choice(ng_sets)) yield name