AntTakeBrainPart.py 1.4KB

12345678910111213141516171819202122232425262728293031323334
  1. from intelligine.simulation.object.brain.part.take.TakeBrainPart import TakeBrainPart
  2. from intelligine.synergy.object.ressource.Ressource import Resource
  3. from intelligine.cst import MOVE_MODE_EXPLO, MOVE_MODE, TYPE_RESOURCE_TRANSFORMABLE, \
  4. TYPE, MOVE_MODE_GOHOME, PHEROMON_DIR_EXPLO
  5. class AntTakeBrainPart(TakeBrainPart):
  6. # TODO: methode __nit_ pour la classe ?
  7. _take = {
  8. MOVE_MODE_EXPLO: [TYPE_RESOURCE_TRANSFORMABLE],
  9. }
  10. @classmethod
  11. def can_take(cls, context, object_id, object_to_take_id):
  12. if not cls._object_is_takable_type(context, object_id, object_to_take_id):
  13. return False
  14. return True
  15. @classmethod
  16. def _object_is_takable_type(cls, context, object_id, object_to_take_id):
  17. move_mode = context.metas.value.get(MOVE_MODE, object_id)
  18. for takable_type in cls._take[move_mode]:
  19. if context.metas.list.have(TYPE, takable_type, object_to_take_id, allow_empty=True):
  20. return True
  21. return False
  22. def done(self, obj, take_object, context):
  23. # TODO: Ranger ca ? Truc plus dynamique/configurable ?
  24. if isinstance(take_object, Resource):
  25. obj.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
  26. # TODO: set_last_pheromone_point ca devrait pas etre dans get_movement_pheromone_gland().appose() ?
  27. obj.set_last_pheromone_point(PHEROMON_DIR_EXPLO, obj.get_position())
  28. obj.get_movement_pheromone_gland().appose()