# Path: monsteractor.py
# class TryPutToSleep(Leaf):
#     def __init__(self):
#         super(TryPutToSleep, self).__init__()
#         self.component_type = "try_put_to_sleep"
# 
#     def first_tick(self, time):
#         if self.parent_may_sleep():
#             self.parent.set_child(SleepingEntity())
#         self.parent.remove_component(self)
# 
#     def parent_may_sleep(self):
#         return self.parent.status_flags.has_status(StatusFlags.IS_ALIVE)
# 
# Path: monstertables.py
# class DungeonTableItem(object):
#     def __init__(self, creator):
# def filter_monster_table_by_depth(table, depth):
# def from_table_pick_n_items_for_depth(table, n, depth, game_state):
# 
# Path: tools.py
# def time_it(name, func):
#     start = time.clock()
#     result = func()
#     elapsed = time.clock() - start
#     print name + ": " + str(elapsed)
#     return result


import random
import dungeongenerator
import spawner
from monsteractor import TryPutToSleep
from monstertables import from_table_pick_n_items_for_depth, dungeon_table, dungeon_equipment_table, dungeon_usable_item_table
from tools import time_it
        dungeon_level = time_it("dungeon_level_generation",
                                (lambda: dungeongenerator.generate_dungeon_floor(size, depth)))
        minimum_monsters = int(4 + depth * 1.2)
        monsters_to_spawn = random.randrange(minimum_monsters, minimum_monsters + 3)
        monsters = from_table_pick_n_items_for_depth(dungeon_table, monsters_to_spawn,
                                                     depth, self.game_state)
        print monsters
        for monster in monsters:
            sleep_chance = 0.25
            if sleep_chance > random.random():
                monster.set_child(TryPutToSleep())
            spawner.place_piece_on_random_walkable_tile(monster, dungeon_level)

        if depth == (len(self._dungeon_levels) - 1):
            jericho = monster.new_jericho(self.game_state)
            spawner.place_piece_on_random_walkable_tile(jericho, dungeon_level)

        place_items_in_dungeon(dungeon_level, self.game_state)

        #dungeon_level.print_statistics()

        dungeon_level.dungeon = self
        return dungeon_level


def place_items_in_dungeon(dungeon_level, game_state):
    spawner.place_health_potions(dungeon_level, game_state)
    equipments = from_table_pick_n_items_for_depth(dungeon_equipment_table,
                                                   random.randrange(int(2 + dungeon_level.depth * 0.5)),
                                                   dungeon_level.depth, game_state)

# Path: monsteractor.py
# class TryPutToSleep(Leaf):
#     def __init__(self):
#         super(TryPutToSleep, self).__init__()
#         self.component_type = "try_put_to_sleep"
# 
#     def first_tick(self, time):
#         if self.parent_may_sleep():
#             self.parent.set_child(SleepingEntity())
#         self.parent.remove_component(self)
# 
#     def parent_may_sleep(self):
#         return self.parent.status_flags.has_status(StatusFlags.IS_ALIVE)
# 
# Path: monstertables.py
# class DungeonTableItem(object):
#     def __init__(self, creator):
# def filter_monster_table_by_depth(table, depth):
# def from_table_pick_n_items_for_depth(table, n, depth, game_state):
# 
# Path: tools.py
# def time_it(name, func):
#     start = time.clock()
#     result = func()
#     elapsed = time.clock() - start
#     print name + ": " + str(elapsed)
#     return result


# Path: dungeon.py
import random
import dungeongenerator
import spawner
from monsteractor import TryPutToSleep
from monstertables import from_table_pick_n_items_for_depth, dungeon_table, dungeon_equipment_table, dungeon_usable_item_table
from tools import time_it

        dungeon_level = time_it("dungeon_level_generation",
                                (lambda: dungeongenerator.generate_dungeon_floor(size, depth)))
        minimum_monsters = int(4 + depth * 1.2)
        monsters_to_spawn = random.randrange(minimum_monsters, minimum_monsters + 3)
        monsters = from_table_pick_n_items_for_depth(dungeon_table, monsters_to_spawn,
                                                     depth, self.game_state)
        print monsters
        for monster in monsters:
            sleep_chance = 0.25
            if sleep_chance > random.random():
                monster.set_child(TryPutToSleep())
            spawner.place_piece_on_random_walkable_tile(monster, dungeon_level)

        if depth == (len(self._dungeon_levels) - 1):
            jericho = monster.new_jericho(self.game_state)
            spawner.place_piece_on_random_walkable_tile(jericho, dungeon_level)

        place_items_in_dungeon(dungeon_level, self.game_state)

        #dungeon_level.print_statistics()

        dungeon_level.dungeon = self
        return dungeon_level


def place_items_in_dungeon(dungeon_level, game_state):
    spawner.place_health_potions(dungeon_level, game_state)
    equipments = from_table_pick_n_items_for_depth(dungeon_equipment_table,
                                                   random.randrange(int(2 + dungeon_level.depth * 0.5)),
                                                   dungeon_level.depth, game_state)

    usable_items = from_table_pick_n_items_for_depth(dungeon_usable_item_table,