def render_name(): # parse all *.cfg files in data/namegen for file in os.listdir(get_data('namegen')) : if file.find('.cfg') > 0 : libtcod.namegen_parse(get_data(os.path.join('namegen',file))) # get the sets list ng_sets=libtcod.namegen_get_sets() test_sets = ("Rogue Dungeon Rooms", "Rogue Names") for test_set in test_sets: print ("=" * 40) print(test_set) print ("=" * 40) for i in range(20): ng_names = libtcod.namegen_generate(test_set) print(ng_names) assert False for ng_set in ng_sets: print("="*40) print(f"{ng_set}") print("=" * 40) for i in range(10): ng_names = libtcod.namegen_generate(ng_set) print(ng_names)
def generate_npc(type, dungeon_level=1, point=None, upgrade_chance=98): global names if (type == Species.GOBLIN): npc = goblin(point) elif (type == Species.ORC): npc = orc(point) elif (type == Species.TROLL): npc = troll(point) if not npc: print(f"No {type} for NPC?") return None if not names: tcod.namegen_parse(resource_path("data/names.txt")) names = True npc.base_name = tcod.namegen_generate(npc.base_name) npc_level = (dungeon_level - 1) + randint(-1, 1) if npc_level > 1: npc.level.random_level_up(npc_level - 1) dice = randint(1, 100) if (dice >= upgrade_chance): upgrade_npc(npc) npc.level.random_level_up(1) tweak_npc(npc) return npc
def load_history_data(file_name: str): """ Use libtcod library to load in the name generation configuration :param file_name: the name of the config file that you want to load """ # Create path for the file that we are going to load data_folder = Path(__file__).resolve().parent file_to_open = data_folder / "data" / "themes" / file_name libtcod.namegen_parse(str(file_to_open))
def CivGen( Races, Govern ): # -------------------------------------------------------------------- * CIV GEN * ---------------------------------------------------------------------------------- Civs = [] for x in range(CIVILIZED_CIVS): tcod.namegen_parse("./dist/namegen/jice_fantasy.cfg") Name = tcod.namegen_generate("Fantasy male") tcod.namegen_destroy() Name += " Civilization" Race = Races[randint(0, len(Races) - 1)] # Gets stuck here while Race.Form != "civilized": Race = Races[randint(0, len(Races) - 1)] Government = Govern[randint(0, len(Govern) - 1)] Color = Palette[randint(0, len(Palette) - 1)] Flag = FlagGenerator(Color) # Initialize Civ Civs.append(Civ(Race, Name, Government, Color, Flag, 0)) for a in range(TRIBAL_CIVS): tcod.namegen_parse("./dist/namegen/jice_fantasy.cfg") Name = tcod.namegen_generate("Fantasy male") tcod.namegen_destroy() Name += " Tribe" Race = Races[randint(0, len(Races) - 1)] while Race.Form != "tribal": Race = Races[randint(0, len(Races) - 1)] Government = GovernmentType("Tribal", "*PLACE HOLDER*", 2, 50, 0) Color = tcod.Color(randint(0, 255), randint(0, 255), randint(0, 255)) Flag = FlagGenerator(Color) # Initialize Civ Civs.append(Civ(Race, Name, Government, Color, Flag, 0)) print("- Civs Generated -") return Civs
def potion_description(item): global potion_random_details description = potion_descriptions.get(item.base_name) if not description: if not potion_random_details: tcod.namegen_parse(resource_path("data/liquids.txt")) potion_random_details = True description = {} description['container'] = tcod.namegen_generate('potion_container') description['liquid_color'] = tcod.namegen_generate('potion_colours') description['liquid_type'] = tcod.namegen_generate('potion_texture') potion_descriptions[item.base_name] = description item.add_component( IdentifiablePotion(container=description['container'], liquid_color=description['liquid_color'], liquid_type=description['liquid_type']), "identifiable") return item
def game_init(): '''Function inits the game window and pygame''' #init pygame pygame.init() pygame.key.set_repeat(200, 70) libtcodpy.namegen_parse('assets\\namegen\\mingos_demon.cfg') try: game.prefs_load() except: globalvars.PREFS = data.struc_Prefs() globalvars.SURFACE_MAIN = pygame.display.set_mode( (constants.CAM_WIDTH, constants.CAM_HEIGHT)) globalvars.SURFACE_MAP = pygame.Surface( (constants.MAP_WIDTH * constants.CELL_WIDTH, constants.MAP_HEIGHT * constants.CELL_HEIGHT)) globalvars.CAMERA = camera.obj_Camera() globalvars.ASSETS = assets.obj_Assets() globalvars.RANDOM_ENGINE = random.SystemRandom() globalvars.FOV_CALC = True globalvars.CLOCK = pygame.time.Clock()
for k, v in mood_mod.items(): attrs_range[k] = tuple(a + b for a, b in zip(attrs_range[k], v)) for k, v in align_mod.items(): attrs_range[k] = tuple(a + b for a, b in zip(attrs_range[k], v)) for k, v in prof_mod.items(): attrs_range[k] = tuple(a + b for a, b in zip(attrs_range[k], v)) attributes = { k: rnd.randrange(max(1, v[0]), max(2, v[0] + 1, v[1])) for k, v in attrs_range.items() } return cls(attributes) tcod.namegen_parse('data/names/name_tcod_structures.dat') class Character: def __init__(self, name: str = "", surname: str = "", nickname: str = "", sex: Sex = None, img="", attributes=None, alignment: Alignment = None, prof_name="civilian", juice: int = 0, mood_mod: Dict[str, int] = {}, inventory=()) -> None:
def place_entities(self, room, entities): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level) # Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) monster_chances = { 'orc': 80, 'rat': 60, 'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level) } item_chances = { 'healing_potion': 35, 'sword': from_dungeon_level([[5, 4]], self.dungeon_level), 'shield': from_dungeon_level([[15, 8]], self.dungeon_level), 'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level) } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) orc_hp = from_dungeon_level([[20, 1], [25, 6], [60, 15]], self.dungeon_level) orc_strength = from_dungeon_level([[4, 1], [6, 6], [8, 15]], self.dungeon_level) troll_hp = from_dungeon_level([[30, 1], [36, 6], [40, 15]], self.dungeon_level) troll_strength = from_dungeon_level( [[8, 1], [10, 6], [12, 15]], self.dungeon_level) libtcodpy.namegen_parse('data/mingos_demon.cfg') name_bool = randint(0, 1) male_name = libtcodpy.namegen_generate('demon male') female_name = libtcodpy.namegen_generate('demon female') if monster_choice == 'orc': fighter_component = Fighter(hp=orc_hp, defense=0, strength=orc_strength, dexterity=0, intelligence=0, charisma=0, xp=35) ai_component = BasicMonster() monster = Entity(x, y, 'O', libtcodpy.Color(27, 105, 0), '{0}'.format(male_name if name_bool == 0 else female_name), blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'troll': fighter_component = Fighter(hp=troll_hp, defense=2, strength=troll_strength, dexterity=0, intelligence=0, charisma=0, xp=100) ai_component = BasicMonster() monster = Entity(x, y, 'T', libtcodpy.Color(27, 105, 0), '{0}'.format(male_name if name_bool == 0 else female_name), blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) else: fighter_component = Fighter(hp=4, defense=0, strength=2, dexterity=0, intelligence=0, charisma=0, xp=10) ai_component = BasicMonster() monster = Entity(x, y, 'R', libtcodpy.Color(27, 105, 0), '{0}'.format(male_name if name_bool == 0 else female_name), blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', libtcodpy.Color(105, 69, 255), 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', libtcodpy.light_cyan), damage=25, radius=3) item = Entity(x, y, '#', libtcodpy.Color(186, 251, 24), 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, strength_bonus=3) item = Entity(x, y, '/', libtcodpy.sky, 'Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, '[', libtcodpy.Color(138, 20, 0), 'Shield', equippable=equippable_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', libtcodpy.light_cyan)) item = Entity(x, y, '#', libtcodpy.Color(186, 251, 24), 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) else: item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, '#', libtcodpy.Color(186, 251, 24), 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item)
def test_namegen_parse(): libtcodpy.namegen_parse('libtcod/data/namegen/jice_celtic.cfg') assert libtcodpy.namegen_generate('Celtic female') assert libtcodpy.namegen_get_sets() libtcodpy.namegen_destroy()
def game_initialize(): # disable scaling of windows ctypes.windll.user32.SetProcessDPIAware() os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" # initialize Pygame pygame.init() pygame.display.set_caption("Roguelike") pygame.key.set_repeat(50, 100) try: preferences_load() except: config.PREFERENCES = Preferences() tcod.namegen_parse("data/namegen/jice_celtic.cfg") # looks for resolution of the display of the user info = pygame.display.Info() screen_width, screen_height = info.current_w, info.current_h from src import constants constants.CAMERA_WIDTH = int( round(screen_width * constants.CAMERA_WIDTH_FRACT)) constants.CAMERA_HEIGHT = int( round(screen_height * constants.CAMERA_HEIGHT_FRACT)) rest_of_screen_w = screen_width - constants.CAMERA_WIDTH constants.RECT_WHOLE_SCREEN = pygame.Rect(0, 0, screen_width, screen_height) config.ROUND_COUNTER = 0 config.SURFACE_MAIN = pygame.display.set_mode( (screen_width, screen_height), pygame.NOFRAME | pygame.DOUBLEBUF) config.SURFACE_MAP = pygame.Surface( (constants.MAP_WIDTH * constants.CELL_WIDTH, max(screen_height, constants.MAP_HEIGHT * constants.CELL_HEIGHT))) config.SURFACE_MINI_MAP = pygame.Surface( (rest_of_screen_w, rest_of_screen_w)) config.SURFACE_INFO = pygame.Surface((rest_of_screen_w, screen_height)) config.SURFACE_MESSAGES = pygame.Surface( (int(constants.CAMERA_WIDTH / 2), constants.NUM_MESSAGES * 100)) render_helper.fill_surfaces() config.ASSETS = assets.Assets() config.CAMERA = camera.Camera(width=constants.CAMERA_WIDTH, height=constants.CAMERA_HEIGHT, cell_width=constants.CELL_WIDTH, cell_height=constants.CELL_HEIGHT, map_width=constants.MAP_WIDTH, map_height=constants.MAP_HEIGHT, screen_topleft=(0, 0)) config.MINI_MAP_CAMERA = camera.Camera( width=rest_of_screen_w - 50, height=rest_of_screen_w - 50, cell_width=constants.MINI_MAP_CELL_WIDTH, cell_height=constants.MINI_MAP_CELL_HEIGHT, map_width=constants.MAP_WIDTH, map_height=constants.MAP_HEIGHT, screen_topleft=(constants.CAMERA_WIDTH, 0)) config.CLOCK = pygame.time.Clock() config.FOV_CALCULATE = True config.CONSOLE = Textfield(config.SURFACE_MAIN, pygame.Rect(5, constants.CAMERA_HEIGHT - 30, int(constants.CAMERA_WIDTH / 1.2), 25), "console", constants.COLOR_GREY, constants.COLOR_WHITE, constants.COLOR_YELLOW_DARK_GOLD, focus_key=pygame.K_o) setup_gui(rest_of_screen_w)
def main(): screen_width = 80 screen_height = 80 player = Entity(int(screen_width / 2), int(screen_height / 2), 'x', libtcod.red, libtcod.black, ' ', 1.86, 36, 'X') entities = get_world() + [player] libtcod.console_set_custom_font('data/fonts/terminal12x12_gs_ro.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_CP437) root_console = libtcod.console_init_root(screen_width, screen_height, 'BGJS: Worldbuilding', False, libtcod.RENDERER_SDL2, order="F") console = libtcod.console_new(screen_width, screen_height) key = libtcod.Key() mouse = libtcod.Mouse() for file in os.listdir("data/namegen"): if file.find(".cfg") > 0: libtcod.namegen_parse(os.path.join("data/namegen", file)) sets = libtcod.namegen_get_sets() world_name = libtcod.namegen_generate(sets[0]) while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) render_all(console, entities, screen_width, screen_height) libtcod.console_flush() clear_all(console, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') if move: dx, dy = move player.move(dx, dy) #FIXME: This is super inefficient but it is a product of game jam for entity in entities: if (entity.info != ' '): if (player.x == entity.x and player.y == entity.y): console.print_frame(64, 0, 16, 64, '', True, 13) console.print(65, 2, world_name, libtcod.sepia, libtcod.black, libtcod.LEFT) console.print(65, 5, entity.char, entity.fg_color, entity.bg_color, libtcod.LEFT) console.print(65, 7, entity.info, libtcod.white, libtcod.black, libtcod.LEFT) console.print(65, 9, 'Height: ' + str(entity.height) + 'm', libtcod.white, libtcod.black, libtcod.LEFT) console.print(65, 12, 'Temp: ' + str(entity.temp) + ' C', libtcod.white, libtcod.black, libtcod.LEFT) console.print(65, 15, 'Magic Source:', libtcod.white, libtcod.black, libtcod.LEFT) console.print(65, 17, entity.magic, entity.fg_color, entity.bg_color, libtcod.LEFT) console.print(65, 20, book, entity.fg_color, libtcod.black, libtcod.LEFT) console.print(65, 45, compass, libtcod.sepia, libtcod.black, libtcod.LEFT) if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
import generator '''This function initializes the main window, and pygame. ''' pygame.init() pygame.key.set_repeat(200, 75) # Initialize Preferences try: game.preferences_load() except: globalvars.PREFERENCES = data.StrucPreferences() libtcod.namegen_parse('data/namegen/jice_celtic.cfg') # SURFACE_MAIN is the display surface, a special surface that serves as the # root console of the whole game. Anything that appears in the game must be # drawn to this console before it will appear. globalvars.SURFACE_MAIN = pygame.display.set_mode( (constants.CAMERA_WIDTH, constants.CAMERA_HEIGHT)) globalvars.SURFACE_MAP = pygame.Surface( (constants.MAP_WIDTH * constants.CELL_WIDTH, constants.MAP_HEIGHT * constants.CELL_HEIGHT)) globalvars.CAMERA = camera.ObjCamera() # ASSETS stores the games assets globalvars.ASSETS = assets.ObjAssets()
def load_name_generators(): for f in os.listdir("names"): if f.find(".cfg") != -1: tcod.namegen_parse(os.path.join("names",f))