# Path: compositecore.py
# class Leaf(Component):
#     """
#     Abstract leaf class of composite design pattern.
# 
#     Component classes of leaf type should inherit from this class.
#     """
# 
#     def __init__(self):
#         super(Leaf, self).__init__()
# 
#     def get_relative_of_type(self, component_type):
#         return self.parent.get_child_or_ancestor(component_type)
# 
#     def has_relative_of_type(self, component_type):
#         return self.parent.has_child_or_ancestor(component_type)
# 
# Path: position.py
# class DungeonLevel(Leaf):
#     """
#     Composites holding this is in a DungeonLevel.
#     """
#     def __init__(self):
#         super(DungeonLevel, self).__init__()
#         self.component_type = "dungeon_level"
#         self._value = None
#         self.last_dungeon_level = None
# 
#     @property
#     def value(self):
#         """
#         Gets the dungeon_level the entity is currently in.
#         """
#         return self._value
# 
#     @value.setter
#     def value(self, new_dungeon_level):
#         """
#         Sets current dungeon_level of the entity.
#         Also updates the visibility/solidity of the dungeon_level tiles.
#         """
#         if not self._value is new_dungeon_level:
#             old_dungeon_level = self._value
#             self._value = new_dungeon_level
#             self._signal_dungeon_level_changed()
#             if(not old_dungeon_level is None and
#                self.has_sibling("actor")):
#                 old_dungeon_level.remove_actor_if_present(self.parent)
#                 self.last_dungeon_level = old_dungeon_level
#         if self.last_dungeon_level is None:
#             self.last_dungeon_level = new_dungeon_level
# 
#     def _signal_dungeon_level_changed(self):
#         """
#         Is called when dungeon level has changed.
#         """
#         if self.has_parent() and not self.value is None:
#             self.parent.send_message(CompositeMessage.DUNGEON_LEVEL_CHANGED)
#             if self.has_sibling("actor"):
#                 self.value.add_actor_if_not_present(self.parent)
#             if self.has_sibling("is_dungeon_feature"):
#                 self.value.add_dungeon_feature_if_not_present(self.parent)
# 
#     def on_parent_changed(self):
#         """
#         When the parent changes try to add it to the dungeon.
#         """
#         self._signal_dungeon_level_changed()
# 
# Path: stats.py
# def max_instances_of_composite_on_tile(composite):
#     return GamePieceTypes.MAX_INSTANCES_ON_TILE[composite.game_piece_type.value]
# 
# class IntelligenceLevel(DataPoint):
#     MINDLESS = 0
#     PLANT = 1
#     ANIMAL = 2
#     NORMAL = 3
#     HIGH = 4
# 
# Path: statusflags.py
# class StatusFlags(Leaf):
#     """
#     Composites holding this has status flags, describing their behaviour.
#     """
#     INVISIBILE = 0
#     SEE_INVISIBILITY = 1
#     FLYING = 2
#     IS_ALIVE = 3
#     CAN_OPEN_DOORS = 4
#     HAS_HEART = 5
# 
#     def __init__(self, status_flags=[]):
#         super(StatusFlags, self).__init__()
#         self.component_type = "status_flags"
#         self._status_flags = set(status_flags)
#         self._temp_status_flags = set()
# 
#     def has_status(self, status):
#         """
#         Returns True if parent entity has the status given.
#         """
#         if not self.next is None:
#             return (status in self._status_flags or
#                     status in self._temp_status_flags or
#                     next.has_status(status))
#         else:
#             return (status in self._status_flags or
#                     status in self._temp_status_flags)
# 
#     def add_temp_status(self, status):
#         """
#         Adds a temporary status that will be removed the next tick.
#         """
#         self._temp_status_flags.add(status)
# 
#     def before_tick(self, time):
#         self._temp_status_flags = set()


import random
import Status
import direction
import geometry
import trigger
from compositecore import Leaf
from position import DungeonLevel
from stats import max_instances_of_composite_on_tile, IntelligenceLevel
from statusflags import StatusFlags
        entity = (self.parent.dungeon_level.value.get_tile(position).get_first_entity())
        if self.parent.has("melee_attacker") and entity:
            return self.parent.melee_attacker.try_hit(entity)

    def try_move_or_bump(self, position):
        """
        Tries to move the entity to a position.

        If there is a unfriendly entity in the way hit it instead.
        If there is a door in the way try to open it.
        If an action is taken return True otherwise return False.

        Args:
            position (int, int): The position the entity tries to move to.
        Returns:
            Energy spent
        """
        if self.try_bump_terrain(position):
            return self.parent.movement_speed.value
        if self.try_attack(position):
            return self.parent.melee_speed.value
        if self._try_move_to_destination(position):
            return self.parent.movement_speed.value
        return 0


def is_tile_dangerous(tile, entity):
    if entity.intelligence.value == IntelligenceLevel.PLANT:
        return False  # Low intelligence ch
    cloud = tile.get_first_cloud()

# Path: compositecore.py
# class Leaf(Component):
#     """
#     Abstract leaf class of composite design pattern.
# 
#     Component classes of leaf type should inherit from this class.
#     """
# 
#     def __init__(self):
#         super(Leaf, self).__init__()
# 
#     def get_relative_of_type(self, component_type):
#         return self.parent.get_child_or_ancestor(component_type)
# 
#     def has_relative_of_type(self, component_type):
#         return self.parent.has_child_or_ancestor(component_type)
# 
# Path: position.py
# class DungeonLevel(Leaf):
#     """
#     Composites holding this is in a DungeonLevel.
#     """
#     def __init__(self):
#         super(DungeonLevel, self).__init__()
#         self.component_type = "dungeon_level"
#         self._value = None
#         self.last_dungeon_level = None
# 
#     @property
#     def value(self):
#         """
#         Gets the dungeon_level the entity is currently in.
#         """
#         return self._value
# 
#     @value.setter
#     def value(self, new_dungeon_level):
#         """
#         Sets current dungeon_level of the entity.
#         Also updates the visibility/solidity of the dungeon_level tiles.
#         """
#         if not self._value is new_dungeon_level:
#             old_dungeon_level = self._value
#             self._value = new_dungeon_level
#             self._signal_dungeon_level_changed()
#             if(not old_dungeon_level is None and
#                self.has_sibling("actor")):
#                 old_dungeon_level.remove_actor_if_present(self.parent)
#                 self.last_dungeon_level = old_dungeon_level
#         if self.last_dungeon_level is None:
#             self.last_dungeon_level = new_dungeon_level
# 
#     def _signal_dungeon_level_changed(self):
#         """
#         Is called when dungeon level has changed.
#         """
#         if self.has_parent() and not self.value is None:
#             self.parent.send_message(CompositeMessage.DUNGEON_LEVEL_CHANGED)
#             if self.has_sibling("actor"):
#                 self.value.add_actor_if_not_present(self.parent)
#             if self.has_sibling("is_dungeon_feature"):
#                 self.value.add_dungeon_feature_if_not_present(self.parent)
# 
#     def on_parent_changed(self):
#         """
#         When the parent changes try to add it to the dungeon.
#         """
#         self._signal_dungeon_level_changed()
# 
# Path: stats.py
# def max_instances_of_composite_on_tile(composite):
#     return GamePieceTypes.MAX_INSTANCES_ON_TILE[composite.game_piece_type.value]
# 
# class IntelligenceLevel(DataPoint):
#     MINDLESS = 0
#     PLANT = 1
#     ANIMAL = 2
#     NORMAL = 3
#     HIGH = 4
# 
# Path: statusflags.py
# class StatusFlags(Leaf):
#     """
#     Composites holding this has status flags, describing their behaviour.
#     """
#     INVISIBILE = 0
#     SEE_INVISIBILITY = 1
#     FLYING = 2
#     IS_ALIVE = 3
#     CAN_OPEN_DOORS = 4
#     HAS_HEART = 5
# 
#     def __init__(self, status_flags=[]):
#         super(StatusFlags, self).__init__()
#         self.component_type = "status_flags"
#         self._status_flags = set(status_flags)
#         self._temp_status_flags = set()
# 
#     def has_status(self, status):
#         """
#         Returns True if parent entity has the status given.
#         """
#         if not self.next is None:
#             return (status in self._status_flags or
#                     status in self._temp_status_flags or
#                     next.has_status(status))
#         else:
#             return (status in self._status_flags or
#                     status in self._temp_status_flags)
# 
#     def add_temp_status(self, status):
#         """
#         Adds a temporary status that will be removed the next tick.
#         """
#         self._temp_status_flags.add(status)
# 
#     def before_tick(self, time):
#         self._temp_status_flags = set()


# Path: mover.py
import random
import Status
import direction
import geometry
import trigger
from compositecore import Leaf
from position import DungeonLevel
from stats import max_instances_of_composite_on_tile, IntelligenceLevel
from statusflags import StatusFlags

        entity = (self.parent.dungeon_level.value.get_tile(position).get_first_entity())
        if self.parent.has("melee_attacker") and entity:
            return self.parent.melee_attacker.try_hit(entity)

    def try_move_or_bump(self, position):
        """
        Tries to move the entity to a position.

        If there is a unfriendly entity in the way hit it instead.
        If there is a door in the way try to open it.
        If an action is taken return True otherwise return False.

        Args:
            position (int, int): The position the entity tries to move to.
        Returns:
            Energy spent
        """
        if self.try_bump_terrain(position):
            return self.parent.movement_speed.value
        if self.try_attack(position):
            return self.parent.melee_speed.value
        if self._try_move_to_destination(position):
            return self.parent.movement_speed.value
        return 0


def is_tile_dangerous(tile, entity):
    if entity.intelligence.value == IntelligenceLevel.PLANT:
        return False  # Low intelligence ch
    cloud = tile.get_first_cloud()

    if tile.get_terrain().has("is_chasm") and not entity.status_flags.has_status(StatusFlags.FLYING):