# Path: intelligine/core/exceptions.py
# class BodyPartAlreadyExist(BodyException):
#     pass
# 
# Path: intelligine/synergy/object/Transportable.py
# class Transportable(SynergyObject):
# 
#     def __init__(self, collection, context):
#         super().__init__(collection, context)
#         self._carried_by = None
#         context.metas.states.add(self.get_id(), TRANSPORTABLE)
#         self._is_carried = False
# 
#     def set_carried_by(self, obj):
#         if obj is not None:
#             assert self._carried_by is None
#             self._carried_by = obj
#             self._context.metas.states.remove(self.get_id(), TRANSPORTABLE)
#         else:
#             assert self._carried_by is not None
#             self._carried_by = None
#             self._context.metas.states.add(self.get_id(), TRANSPORTABLE)
# 
#     def is_carried(self):
#         if self._carried_by:
#             return True
#         return False
# 
#     def get_what_carry(self):
#         return self
# 
#     def is_takable(self):
#         return not self.is_carried()
# 
#     def set_is_carried(self, is_carried, by_obj):
#         self._is_carried = bool(is_carried)
#         if self._is_carried:
#             self._context.metas.value.set(CARRIED_BY, self.get_id(), by_obj.get_id())
#         else:
#             self._context.metas.value.unset(CARRIED_BY, self.get_id())
# 
# Path: intelligine/cst.py
# COL_ALIVE = IncrementedNamedInt.get('intelligine.col.alive')
# 
# COLONY = IncrementedNamedInt.get('intelligine.colony')
# 
# ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
# 
# BRAIN = IncrementedNamedInt.get('intelligine.brain')
# 
# Path: intelligine/simulation/object/brain/Brain.py
# class Brain():
# 
#     _brain_parts = {}
# 
#     def __init__(self, context, host):
#         self._context = context
#         self._host = host
#         self._parts = {}
#         self._init_parts()
# 
#     def _init_parts(self):
#         for brain_part_name in self._brain_parts:
#             self._parts[brain_part_name] = self._brain_parts[brain_part_name](self)
#         self._context.metas.value.set(BRAIN_SCHEMA, self._host.__class__, self._brain_parts)
# 
#     def get_part(self, name):
#         return self._parts[name]
# 
#     def get_context(self):
#         return self._context
# 
#     def get_host(self):
#         return self._host
# 
# Path: intelligine/cst.py
# ALIVE = IncrementedNamedInt.get('intelligine.alive')
# 
# ATTACKABLE = IncrementedNamedInt.get('intelligine.attackable')


from intelligine.core.exceptions import BodyPartAlreadyExist
from intelligine.synergy.object.Transportable import Transportable
from intelligine.cst import COL_ALIVE, COLONY, ACTION_DIE, BRAIN
from intelligine.simulation.object.brain.Brain import Brain
from intelligine.cst import ALIVE, ATTACKABLE
from synergine.core.Signals import Signals


class BaseBug(Transportable):

    _body_parts = {}
    _brain_class = Brain

    def __init__(self, collection, context):
        super().__init__(collection, context)
        context.metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
        context.metas.collections.add(self.get_id(), COL_ALIVE)
        context.metas.value.set(COLONY, self.get_id(), collection.get_id())
        self._life_points = 10
        self._alive = True
        self._movements_count = -1
        self._brain = self._brain_class(self._context, self)
        self._context.metas.value.set(BRAIN, self.__class__, self._brain_class)
        self._parts = {}
        self._init_parts()

    def die(self):
        self._set_alive(False)
        self._remove_state(ALIVE)

# Path: intelligine/core/exceptions.py
# class BodyPartAlreadyExist(BodyException):
#     pass
# 
# Path: intelligine/synergy/object/Transportable.py
# class Transportable(SynergyObject):
# 
#     def __init__(self, collection, context):
#         super().__init__(collection, context)
#         self._carried_by = None
#         context.metas.states.add(self.get_id(), TRANSPORTABLE)
#         self._is_carried = False
# 
#     def set_carried_by(self, obj):
#         if obj is not None:
#             assert self._carried_by is None
#             self._carried_by = obj
#             self._context.metas.states.remove(self.get_id(), TRANSPORTABLE)
#         else:
#             assert self._carried_by is not None
#             self._carried_by = None
#             self._context.metas.states.add(self.get_id(), TRANSPORTABLE)
# 
#     def is_carried(self):
#         if self._carried_by:
#             return True
#         return False
# 
#     def get_what_carry(self):
#         return self
# 
#     def is_takable(self):
#         return not self.is_carried()
# 
#     def set_is_carried(self, is_carried, by_obj):
#         self._is_carried = bool(is_carried)
#         if self._is_carried:
#             self._context.metas.value.set(CARRIED_BY, self.get_id(), by_obj.get_id())
#         else:
#             self._context.metas.value.unset(CARRIED_BY, self.get_id())
# 
# Path: intelligine/cst.py
# COL_ALIVE = IncrementedNamedInt.get('intelligine.col.alive')
# 
# COLONY = IncrementedNamedInt.get('intelligine.colony')
# 
# ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
# 
# BRAIN = IncrementedNamedInt.get('intelligine.brain')
# 
# Path: intelligine/simulation/object/brain/Brain.py
# class Brain():
# 
#     _brain_parts = {}
# 
#     def __init__(self, context, host):
#         self._context = context
#         self._host = host
#         self._parts = {}
#         self._init_parts()
# 
#     def _init_parts(self):
#         for brain_part_name in self._brain_parts:
#             self._parts[brain_part_name] = self._brain_parts[brain_part_name](self)
#         self._context.metas.value.set(BRAIN_SCHEMA, self._host.__class__, self._brain_parts)
# 
#     def get_part(self, name):
#         return self._parts[name]
# 
#     def get_context(self):
#         return self._context
# 
#     def get_host(self):
#         return self._host
# 
# Path: intelligine/cst.py
# ALIVE = IncrementedNamedInt.get('intelligine.alive')
# 
# ATTACKABLE = IncrementedNamedInt.get('intelligine.attackable')


# Path: intelligine/synergy/object/BaseBug.py
from intelligine.core.exceptions import BodyPartAlreadyExist
from intelligine.synergy.object.Transportable import Transportable
from intelligine.cst import COL_ALIVE, COLONY, ACTION_DIE, BRAIN
from intelligine.simulation.object.brain.Brain import Brain
from intelligine.cst import ALIVE, ATTACKABLE
from synergine.core.Signals import Signals



class BaseBug(Transportable):

    _body_parts = {}
    _brain_class = Brain

    def __init__(self, collection, context):
        super().__init__(collection, context)
        context.metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
        context.metas.collections.add(self.get_id(), COL_ALIVE)
        context.metas.value.set(COLONY, self.get_id(), collection.get_id())
        self._life_points = 10
        self._alive = True
        self._movements_count = -1
        self._brain = self._brain_class(self._context, self)
        self._context.metas.value.set(BRAIN, self.__class__, self._brain_class)
        self._parts = {}
        self._init_parts()

    def die(self):
        self._set_alive(False)
        self._remove_state(ALIVE)

        self._remove_state(ATTACKABLE)