Exemple #1
0
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)
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
def gen_skeleton(coords):
    x, y = coords
    creature_name = libtcodpy.namegen_generate("demon male")
    creature_com = actor.com_Creature(creature_name,
                                      base_atk=1,
                                      base_def=1,
                                      hp=1,
                                      death_function=death.death_monster)
    ai_com = ai.ai_Chase()
    skeleton = actor.obj_Actor(x,
                               y,
                               "skeleton",
                               animation_key="skeleton",
                               depth=constants.DEPTH_CREATURE,
                               creature=creature_com,
                               ai=ai_com)
    return skeleton
Exemple #6
0
    def generate_map(self, name="town"):
        """ For now, we generate a town where the school is at the top
            underneath there's a row of buildings
            underneath that there's a more compact row of houses
            to the left there's a column of farms (with houses)
            to the right along the building row there's the sea port
        """
        #TODO: name the roads using another generator (or q&d hack that glues way/street/drive/etc. to other names?)

        self.my_map = Map(width=MAP_WIDTH,
                          height=MAP_HEIGHT,
                          default_tile="grass")
        self.my_map.startX = 27
        self.my_map.startY = 31
        print("Breaking without changing default_tile to use a generator")
        self.my_map.townname = tcod.namegen_generate("mingos towns")
        self.my_map.name = "town"
        self.rects = []

        school = Building("school", 30, 20)

        self.placeSchool(school)

        shop_list = [
            Building("store", 10, 10),
            Building("tavern", 8, 8),
            Building("library", 6, 6),
            Building("blacksmith", 5, 10)
        ]

        random.shuffle(shop_list)

        self.placeShops(shop_list)
        homes = [Building("house{}".format(i + 1), 6, 6) for i in range(10)]
        self.placeHomes(homes)

        self.placeFarms(
            [Building("farm{}".format(i + 1), 15, 15) for i in range(3)])
        self.placeForest()

        self.placeBoundary()
        mapDict["town"] = self.my_map

        return self.my_map
Exemple #7
0
def gen_fire_elemental(coords):

    x, y = coords

    creature_name = libtcodpy.namegen_generate("demon male")
    creature_com = actor.com_Creature(creature_name,
                                      base_atk=4,
                                      base_def=0,
                                      hp=4,
                                      death_function=death.death_monster)
    ai_com = ai.ai_Chase()
    fire = actor.obj_Actor(x,
                           y,
                           "fire elemental",
                           animation_key="fire_elemental",
                           depth=constants.DEPTH_CREATURE,
                           creature=creature_com,
                           ai=ai_com)
    return fire
Exemple #8
0
def gen_healing_sprite(coords):
    x, y = coords
    creature_name = libtcodpy.namegen_generate("demon female")
    creature_com = actor.com_Creature(
        creature_name,
        base_atk=0,
        base_def=0,
        hp=1,
        death_function=death.death_healing_sprite)
    ai_com = ai.ai_Flee()
    item_com = actor.com_Item(use_function=magic.cast_heal, value=2)
    healing_sprite = actor.obj_Actor(x,
                                     y,
                                     "healing sprite",
                                     animation_key="healing_sprite",
                                     depth=constants.DEPTH_CREATURE,
                                     creature=creature_com,
                                     ai=ai_com,
                                     item=item_com)
    return healing_sprite
Exemple #9
0
def snake_cobra(coords):

    x, y = coords
    
    max_health = libtcod.random_get_int(0, 15, 20)
    base_attack = libtcod.random_get_int(0, 5, 8)
    
    creature_name = libtcod.namegen_generate('Celtic male')
    
    creature_com = actor.CompCreature(creature_name,death_function = death.snake, 
                                base_atk = base_attack, max_hp = max_health, xp = (max_health + base_attack)// 2)
    
    ai_com = ai.Chase()
    snake = actor.ObjActor(x, y, "Cobra", 
                    animation_key = "A_SNAKE_02", 
                    animation_speed = 1, 
                    creature = creature_com, 
                    ai= ai_com)
    
    return snake
Exemple #10
0
def mouse(coords):
    x, y = coords
    
    max_health = 1
    base_attack = 0
    
    creature_name = libtcod.namegen_generate('Celtic male')
    
    creature_com = actor.CompCreature(creature_name, death_function = death.mouse, 
                                base_atk = base_attack, max_hp = max_health, xp = -2, speed = 20)
    
    ai_com = ai.Flee()
    
    item_com = actor.CompItem(use_function = magic.cast_heal, value = 3)
    
    mouse = actor.ObjActor(x, y, "mouse", 
                    animation_key = "A_MOUSE", 
                    animation_speed = 1, 
                    creature = creature_com, 
                    ai= ai_com,
                    item = item_com)
    
    return mouse
Exemple #11
0
 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:
     self.sex = sex or rnd.choice([Sex.MALE.value, Sex.FEMALE.value])
     tmp_sex = self.sex if self.sex != Sex.UNKNOWN else rnd.choice(
         [Sex.MALE.value, Sex.FEMALE.value])
     self.name = name or tcod.namegen_generate_custom(tmp_sex, "$s")
     self.surname = surname or tcod.namegen_generate_custom(tmp_sex, "$e")
     self.nickname = nickname or tcod.namegen_generate("animal").title()
     self.age = rnd.choices([
         rnd.randrange(16, 21),
         rnd.randrange(21, 40),
         rnd.randrange(40, 80)
     ], [15, 70, 15])[0]
     self.img = img or rnd.choice(os.listdir(f"data/img/{self.sex}"))
     self.profession = prof_name
     p_mod = profession_mod(self.profession)
     # self.alignment = alignment or profession_align(self.profession)
     born_align = alignment or profession_align(self.profession)
     a_mod = alignment_mod(born_align)
     self.attributes = attributes or Attributes.random(
         a_mod, p_mod, mood_mod)
     self.inventory = inventory
     self.juice = juice or profession_juice(self.profession)
     self.offence = {}
     self.wounds = {}
     self.followers = []
Exemple #12
0
    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()
Exemple #14
0
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()
Exemple #15
0
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())
Exemple #16
0
    def get_random_history(theme: str) -> str:
        """
        A method for generating some random Lore based on the specified theme
        :param theme: the theme of Lore that you want to generate e.g. Room, Person
        :return: a string with the generated name
        """

        # Templates for generating different types of Lore themes
        templates = {
            "Room": (["Dungeon Rooms"], None),
            "Floor": (["Dungeon Floors"], [" of "], [
                "Historic Figure Names Male", "Historic Figure Names Female",
                "Region", "Town"
            ]),
            "Place": (["Town", "Wonders"], [" in "], ["Region"]),
            "Name": ([
                "Character Male", "Character Female", "Fantasy Male",
                "Fantasy Female"
            ], None),
            "Person":
            (["Name"], [" of "], ["Town", "Region", "Wonders", "Place"]),
            "Quest":
            (["Historic Figure Names Male", "Historic Figure Names Female"], [
                " and the battle of ", " and the Siege of ",
                " and the Quest for ", " and the journey to ",
                " and the destruction of ", " and the decimation of ",
                " and how they found ", " and how they discovered "
            ], ["Town", "Region", "Treasures", "Wonders", "Place"]),
            "PvP": ([
                "Historic Figure Names Male", "Historic Figure Names Female",
                "Person"
            ], [
                " and the murder of ", " and the death of ",
                " and the unmarriage of ", " and the betrayal of ",
                " and the hunt for ", " and the alliance with ",
                " and the usurping of ", " and the torment of ",
                ", the loyal servant of ", ", the sworn enemy of "
            ], [
                "Historic Figure Names Male", "Historic Figure Names Female",
                "Person"
            ]),
            "Treasure": (["Treasures"], [" of "], [
                "Historic Figure Names Male", "Historic Figure Names Female",
                "Region", "Town", "Wonders"
            ]),
            "Book": (["'"], [
                "The missing pages of ", "The forgotten passages of ",
                "The ancient Lore of ", "The lessons of ",
                "A cautionary tale of ", "The Tale of ", "The Saga of ",
                "An allegory of ", "The writings of ", "The story of ",
                "The book of "
            ], [
                "Quest", "Place", "Historic Figure Names Male",
                "Historic Figure Names Female", "Treasure", "PvP"
            ], ["'"], [" by "], ["Person"])
        }

        assert theme in templates, f'Cannot find {theme} in history templates'

        # See what name generate sets we have loaded
        ng_sets = libtcod.namegen_get_sets()

        # Get the name of the template that we want to expand
        template = templates.get(theme)

        text = ""

        # Loop through each segment in the template
        for aa in template:

            # If None segment keep looping to the next one
            if aa is None:
                continue
            # Otherwise...
            else:
                # Pick a random item from the segment
                a = random.choice(aa)

                # If the segment a template?  If so recursive call to expand the template
                if a in templates:
                    a_text = ThemeManager.get_random_history(a)
                # If it is in out name generation sets that we loaded then generate a name of this type
                elif a in ng_sets:
                    a_text = libtcod.namegen_generate(a).title()
                # Else just use the segment text itself!
                else:
                    a_text = a

                # Add whatever text we ended up with to our full text
                text += a_text

        # Tidy up by removing any duplicate whitespace
        return " ".join(text.split())