SmellAction.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from intelligine.core.exceptions import BestMoleculeHere
  2. from intelligine.cst import POINT_SMELL, POINTS_SMELL, MOLECULES_INFOS, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG, \
  3. PHEROMON_DIR_EXPLO
  4. from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
  5. from intelligine.simulation.molecule.Evaporation import Evaporation
  6. from intelligine.simulation.molecule.Molecule import Molecule
  7. from intelligine.synergy.event.smell.SmellEvent import SmellEvent
  8. from synergine.synergy.event.Action import Action
  9. class SmellAction(Action):
  10. _listen = SmellEvent
  11. @classmethod
  12. def cycle_pre_run(cls, context, synergy_manager):
  13. evaporation = Evaporation(context, molecules_include_types=[SMELL_FOOD, SMELL_EGG])
  14. evaporation.remove()
  15. def run(self, obj, context, synergy_manager):
  16. points_distances = self._parameters['points_distances']
  17. smell_type = obj.get_smell()
  18. for smell_point in points_distances:
  19. distance = points_distances[smell_point]
  20. molecule = Molecule(MOLECULES_DIRECTION, smell_type, distance)
  21. try:
  22. DirectionMolecule.appose(context, smell_point, molecule)
  23. except BestMoleculeHere:
  24. pass # TODO: Pas l'inverse ? A voir apres avoir fix la disparition.
  25. #
  26. # current_point_smell = points_distances[smell_point]
  27. # where_to_put_smells = context.metas.value.get(POINT_SMELL, smell_point, allow_empty=True, empty_value={})
  28. #
  29. #
  30. # if smell_type not in where_to_put_smells:
  31. # where_to_put_smells[smell_type] = current_point_smell
  32. # else:
  33. # where_to_put_smell = where_to_put_smells[smell_type]
  34. # if current_point_smell < where_to_put_smell:
  35. # where_to_put_smells[smell_type] = where_to_put_smell
  36. #
  37. # context.metas.value.set(POINT_SMELL, smell_point, where_to_put_smells)
  38. # context.metas.list.add(POINTS_SMELL, POINTS_SMELL, smell_point, assert_not_in=False)