def make_story(): background = util.parseDes('background', Background)[0] parts = [] for part in (background.born, background.fillers, background.teachers): phraselist = map(lambda x: x.strip(), part.splitlines()) random.shuffle(phraselist) parts.append(phraselist) output = chain(*islice(izip(*parts), 0, 1)) result = textwrap.fill(' '.join(output),80) return process_string(result)
def require_for_nextgen(region, what, name=None, mapgenparm={}, unique=True): """ this method is used to issue requests for map_gen for certain features. For example a quest needs forest to be generated nearby - it should ask world to generate a forest for next map_gen. what - denotes a type of feature to be generated function returns the holder for requested feature. """ global gen_requests target = None while True: whats = util.parseDes(what, dungeon_generators.MapDef, 'rooms') target = random.choice(whats) if not unique: break if hasattr(target, 'id') and not getattr(target, 'id') in gen_requests.keys(): break request = dungeon_generators.FeatureRequest(target, mapgenparm) """ registers a new worldgen request""" if not gen_requests.has_key(region): gen_requests[region] = {} if not gen_requests[region].has_key(what): gen_requests[region][what] = [] gen_requests[region][what].append(request) return request
import string import textwrap import world import sys import os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) import util class Background(object): pass class WordsVocab(object): pass v = util.parseDes('words', WordsVocab)[0] adjectives = map(lambda x: x.strip() , v.adjectives_def.splitlines()) nouns = map(lambda x: x.strip() , v.nouns_def.splitlines()) professions = map(lambda x: x.strip() , v.professions_def.splitlines()) skills = map(lambda x: x.strip() , v.skills_def.splitlines()) random.shuffle(adjectives) random.shuffle(nouns) random.shuffle(professions) random.shuffle(skills) #here we substitute names into strings. #String can refer to following names # ${name} - random name not in global npc's names list # ${enemy} - one of bad NPCs you have to beat (antagonist) # ${adventurer} - just a reference to adventurer