# Path: intelligine/cst.py
# CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
# 
# BRAIN_PART_PUT = IncrementedNamedInt.get('intelligine.brain.part.put')
# 
# COL_PUT_OUTSIDE = IncrementedNamedInt.get('intelligine.col.put_outside')
# 
# MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.explo')
# 
# Path: intelligine/synergy/event/transport/PutOutsideEvent.py
# class PutOutsideEvent(Event):
# 
#     _concern = COL_PUT_OUTSIDE
# 
#     def _prepare(self, object_id, context, parameters={}):
#         # TODO: DEV code ailleurs (._)
#         if AntMoveBrainPart._on_home_smell(context, object_id):
#             raise NotConcernedEvent()
# 
#         current_position = context.metas.value.get(POSITION, object_id)
#         around_positions = context.get_around_points_of(current_position)
# 
#         for around_position in around_positions:
#             # TODO DEV: ... ._
#             if AntPutBrainPart._position_have_free_space_around(context, around_position):
#                 if AntPutBrainPart._position_is_enought_place(context, around_position):
#                     # TODO: Constant ?
#                     parameters['position_to_put'] = around_position
#                     return parameters
# 
#         raise NotConcernedEvent()
# 
# Path: intelligine/synergy/event/transport/PutableAction.py
# class PutableAction(Action):
# 
#     _listen = PutableEvent
#     _depend = [MoveAction]
# 
#     def run(self, obj, context, synergy_manager):
#         obj_transported = obj.get_carried()
# 
#         if not self._parameters[PutableEvent.PARAM_PUT_TO]:
#             if self._parameters[PutableEvent.PARAM_HOME_FAIL]:
#                 obj.increment_put_fail_count()
#             raise ActionAborted()
# 
#         for position_to_put in self._parameters[PutableEvent.PARAM_PUT_TO]:
# 
#             #  TODO: re controle de si posable ? La position a été calculé
#             #  dans le process. Ce qui fait que la situation peut avoir changer.
#             # Soit: Recalculer d'office BrainPut.cant_put_at.. Soit le recalculer que si le hash
#             # de ce qu'il y a la a changer ?
# 
#             obj_transported.set_carried_by(None)
#             obj.put_carry(obj_transported, position_to_put)
#             context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
#             obj.reinit_put_fail_count()
# 
#             obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)
# 
#             # TODO: DEV
#             if isinstance(obj_transported, Food):
#                 #obj_transported.set_position((-1, 0, 0))
#                 obj_transported.transform_to_stocked()


from intelligine.cst import CANT_CARRY_STILL, BRAIN_PART_PUT, COL_PUT_OUTSIDE, MODE_EXPLO
from intelligine.synergy.event.transport.PutOutsideEvent import PutOutsideEvent
from intelligine.synergy.event.transport.PutableAction import PutableAction


class PutOutsideAction(PutableAction):
    _listen = PutOutsideEvent

    def run(self, obj, context, synergy_manager):
        # TODO: Refact avec pare,t
        obj_transported = obj.get_carried()
        obj_transported.set_carried_by(None)
        obj.put_carry(obj_transported, self._parameters['position_to_put'])
        context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
        obj.reinit_put_fail_count()

        #  obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)

# Path: intelligine/cst.py
# CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
# 
# BRAIN_PART_PUT = IncrementedNamedInt.get('intelligine.brain.part.put')
# 
# COL_PUT_OUTSIDE = IncrementedNamedInt.get('intelligine.col.put_outside')
# 
# MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.explo')
# 
# Path: intelligine/synergy/event/transport/PutOutsideEvent.py
# class PutOutsideEvent(Event):
# 
#     _concern = COL_PUT_OUTSIDE
# 
#     def _prepare(self, object_id, context, parameters={}):
#         # TODO: DEV code ailleurs (._)
#         if AntMoveBrainPart._on_home_smell(context, object_id):
#             raise NotConcernedEvent()
# 
#         current_position = context.metas.value.get(POSITION, object_id)
#         around_positions = context.get_around_points_of(current_position)
# 
#         for around_position in around_positions:
#             # TODO DEV: ... ._
#             if AntPutBrainPart._position_have_free_space_around(context, around_position):
#                 if AntPutBrainPart._position_is_enought_place(context, around_position):
#                     # TODO: Constant ?
#                     parameters['position_to_put'] = around_position
#                     return parameters
# 
#         raise NotConcernedEvent()
# 
# Path: intelligine/synergy/event/transport/PutableAction.py
# class PutableAction(Action):
# 
#     _listen = PutableEvent
#     _depend = [MoveAction]
# 
#     def run(self, obj, context, synergy_manager):
#         obj_transported = obj.get_carried()
# 
#         if not self._parameters[PutableEvent.PARAM_PUT_TO]:
#             if self._parameters[PutableEvent.PARAM_HOME_FAIL]:
#                 obj.increment_put_fail_count()
#             raise ActionAborted()
# 
#         for position_to_put in self._parameters[PutableEvent.PARAM_PUT_TO]:
# 
#             #  TODO: re controle de si posable ? La position a été calculé
#             #  dans le process. Ce qui fait que la situation peut avoir changer.
#             # Soit: Recalculer d'office BrainPut.cant_put_at.. Soit le recalculer que si le hash
#             # de ce qu'il y a la a changer ?
# 
#             obj_transported.set_carried_by(None)
#             obj.put_carry(obj_transported, position_to_put)
#             context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
#             obj.reinit_put_fail_count()
# 
#             obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)
# 
#             # TODO: DEV
#             if isinstance(obj_transported, Food):
#                 #obj_transported.set_position((-1, 0, 0))
#                 obj_transported.transform_to_stocked()


# Path: intelligine/synergy/event/transport/PutOutsideAction.py
from intelligine.cst import CANT_CARRY_STILL, BRAIN_PART_PUT, COL_PUT_OUTSIDE, MODE_EXPLO
from intelligine.synergy.event.transport.PutOutsideEvent import PutOutsideEvent
from intelligine.synergy.event.transport.PutableAction import PutableAction



class PutOutsideAction(PutableAction):
    _listen = PutOutsideEvent

    def run(self, obj, context, synergy_manager):
        # TODO: Refact avec pare,t
        obj_transported = obj.get_carried()
        obj_transported.set_carried_by(None)
        obj.put_carry(obj_transported, self._parameters['position_to_put'])
        context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
        obj.reinit_put_fail_count()

        #  obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)

        obj._remove_col(COL_PUT_OUTSIDE)