Example #1
0
    def grow_thicket(self, center_x, center_y, map_obj, flora_data=fungi):
        flora_choices = weight_factor(flora_data)
        flora_choice = random_choice_from_dict(flora_choices)
        plant_info = flora_data[flora_choice]

        self.thickets.append({
            'center': (center_x, center_y),
            'plant': flora_choice,
        })

        min_radius = flora_data.get('min_thicket_radius', 0)
        max_radius = flora_data.get('max_thicket_radius', 5)
        thicket_radius = randint(min_radius, max_radius)
        for distance in range(thicket_radius):
            chance_for_plant = distance * 20
            for dx in range(-distance, distance):
                dy = int(pow(distance * distance - dx * dx, 0.5))
                dys = [-dy, dy]
                for dy in dys:
                    if randint(0, 100) < chance_for_plant:
                        continue
                    x = center_x + dx
                    y = center_y + dy
                    if not map_obj.is_void(
                            x, y) and not map_obj.tiles[x][y].static_entities:
                        map_obj.tiles[x][y].place_static_entity(
                            self.plant(x, y, plant_info))
Example #2
0
    def grow_cave_entrance_zone(self, cave, zones):
        wall_plant_choices = weight_factor(entrance_plants['wall'])
        ground_plant_choices = weight_factor(entrance_plants['ground'])

        for entrance_zone in zones:
            center_x, center_y = entrance_zone['center']
            for x, y in entrance_zone['coords']:
                if cave.tiles[x][y].static_entities:
                    continue

                distance_from_center = math.sqrt(
                    pow(center_x - x, 2) + pow(center_y - y, 2))
                chance_for_growth = distance_from_center * 2
                if randint(0, 100) < chance_for_growth:
                    continue

                if cave.is_blocked(x, y):
                    plant_info = entrance_plants['wall'][
                        random_choice_from_dict(wall_plant_choices)]
                else:
                    plant_info = entrance_plants['ground'][
                        random_choice_from_dict(ground_plant_choices)]

                char = plant_info['char']
                base_name = plant_info['name']
                name = plant_info['display_name']
                color = plant_info['color']
                if type(color) == list:
                    color = choice(color)
                if plant_info.get('bloom_factor'):
                    if randint(1, 100) <= plant_info['bloom_factor']:
                        color = plant_info['flower_color']
                        name = 'Blooming {0}'.format(name)

                plant = Entity(x,
                               y,
                               char=char,
                               color=color,
                               name=name,
                               base_name=base_name,
                               render_order=RenderOrder.GROUND_FLORA)
                cave.tiles[x][y].place_static_entity(plant)
Example #3
0
    def populate_by_type(self, points, monster_type, entities):
        monster_list = {}
        for name, monster in self.monsters.items():
            if monster_type in monster['types']:
                monster_list[name] = monster

        monster_chances = weight_factor(monster_list)
        for x, y in points:
            monster_choice = random_choice_from_dict(monster_chances)
            monster = self.get_monster(x, y, monster_choice)
            entities.append(monster)
Example #4
0
    def choose_plant(self, tile_shadowed):
        plant_choices = one_tile_plant_choices.copy()
        if tile_shadowed:
            plant_choices.update(weight_factor(fungi))
            plant_choices.update({k: (v // 3) for k, v in saplings.items()})
            plant_choices.update({k: (v * 2) for k, v in soil.items()})
        else:
            plant_choices.update(saplings)
            plant_choices.update(soil)

        return random_choice_from_dict(plant_choices)
Example #5
0
    def populate_room(self, room, dungeon_level, entities):
        max_monsters_per_room = from_dungeon_level(max_monsters_per_room_weights, dungeon_level)
        number_of_monsters = randint(0, max_monsters_per_room)
        monster_chances = weight_factor(monsters, dungeon_level)

        for _ in range(number_of_monsters):
            # Choose a random location in room
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)
            if not entities.find_by_point(x, y):
                monster_choice = random_choice_from_dict(monster_chances)
                monster = self.get_monster(x, y, monster_choice)
                entities.append(monster)
Example #6
0
    def fill_room(self, room, dungeon_level, entities):
        max_items_per_room = from_dungeon_level(max_items_per_room_weights, dungeon_level)
        number_of_items = randint(0, max_items_per_room)
        item_chances = weight_factor(items, dungeon_level)

        for _ in range(number_of_items):
            # Choose a random location in room
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)
            if not entities.find_by_point(x, y):
                item_choice = random_choice_from_dict(item_chances)
                item = self.get_item(x, y, item_choice)
                entities.append(item)
Example #7
0
    def generate_location(self):
        location_choice = random_choice_from_dict(weight_factor(self.locations))
        location = self.locations[location_choice]

        location_type = random_choice_from_dict(location['types'])
        if location_choice == 'temple':
            name = '{0} of the {1}'.format(location_type, choice(location['names']))
        elif location_choice == 'settlement':
            name = '{0} {1} {2}'.format(choice(location['first_names']), choice(location['last_names']), location_type).strip()

        landmark = self.generate_landmark(name, location_choice, location_type)
        location = GameMap(map_vars.width, map_vars.height, map_creator=ForestMap(5, landmark=landmark))
        return location
Example #8
0
    def populate(self, forest, entities):
        number_of_monsters = round(math.pow(forest.width * forest.height,
                                            0.25))
        monster_chances = weight_factor(monsters)

        for _ in range(number_of_monsters):
            # Choose a random location in room
            x = randint(0, forest.width - 1)
            y = randint(0, forest.height - 1)
            if not forest.is_blocked(x, y) and not entities.find_by_point(
                    x, y):
                monster_choice = random_choice_from_dict(monster_chances)
                monster = self.get_monster(x, y, monster_choice)
                entities.append(monster)
Example #9
0
    def populate_cave(self, cave, entities):
        max_monsters = from_dungeon_level(max_monsters_per_level_weights, cave.dungeon_level)
        number_of_monsters = randint(0, max_monsters)
        monster_chances = weight_factor(monsters, cave.dungeon_level)

        if cave.map_creator.twilight_zone:
            zone = cave.map_creator.twilight_zone
        elif cave.map_creator.dark_zone:
            zone = cave.map_creator.dark_zone

        for _ in range(number_of_monsters):
            x, y = choice(tuple(zone))
            if not entities.find_by_point(x, y):
                monster_choice = random_choice_from_dict(monster_chances)
                monster = self.get_monster(x, y, monster_choice)
                entities.append(monster)
Example #10
0
    def choose_encounter(self):
        possible_encounters = self.possible_encounters()
        if not possible_encounters:
            return False

        challenge = choice(list(EncounterChallenge))

        encounter_choices = weight_factor(possible_encounters)
        encounter_choice = random_choice_from_dict(encounter_choices)
        encounter_conf = possible_encounters[encounter_choice]

        self.encounter = encounter_conf['class'](
            encounter_choice,
            challenge=challenge,
            **encounter_conf['parameters'])
        return True
    def generate_location(self):
        location_choice = random_choice_from_dict(weight_factor(
            self.locations))
        location = self.locations[location_choice]

        location_type = random_choice_from_dict(location['types'])
        if location_choice == 'city':
            name = 'Remains of {0} of the city of {1}'.format(
                location_type, choice(location['names']))
        elif location_choice == 'cave':
            name = '{0} of {1}'.format(location_type,
                                       choice(location['names'])).strip()
            landmark = Landmark(name, location_choice, location_type)
            return GameMap(map_vars.width,
                           map_vars.height,
                           map_creator=CaveMap(landmark=landmark))

        landmark = Landmark(name, location_choice, location_type)
        location = GameMap(map_vars.width,
                           map_vars.height,
                           map_creator=DungeonMap(10, 3, 5, landmark=landmark))
        return location
Example #12
0
        'name': 'Salix',
        'weight_factor': 5,
    },
    'bird_cherry': {
        'color': tcod.Color(64, 58, 40),
        'name': 'Prunus',
        'weight_factor': 5,
    },
    'lemon': {
        'color': tcod.Color(64, 89, 20),
        'name': 'Citrus',
        'weight_factor': 5,
    },
}

tree_choices = weight_factor(trees)

one_tile_plants = {
    # angiosperms
    'aposeris': {
        'color': tcod.Color(87, 237, 80),
        'flower_color': tcod.Color(238, 238, 88),
        'name': 'Aposeris',
        'lifeform': 'Sprout',
        'char': ';',
        'weight_factor': 40,
        'bloom_factor': 5,
    },
    'astrancia': {
        'color': tcod.Color(27, 176, 19),
        'flower_color': tcod.Color(215, 29, 2),