SmellAction.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435
  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.move.MoveAction import MoveAction
  8. from intelligine.synergy.event.smell.SmellEvent import SmellEvent
  9. from synergine.synergy.event.Action import Action
  10. class SmellAction(Action):
  11. _listen = SmellEvent
  12. _depend = [MoveAction]
  13. @classmethod
  14. def cycle_pre_run(cls, context, synergy_manager):
  15. evaporation = Evaporation(context, molecules_include_types=[SMELL_FOOD, SMELL_EGG])
  16. evaporation.remove()
  17. def run(self, obj, context, synergy_manager):
  18. points_distances = self._parameters['points_distances']
  19. smell_type = obj.get_smell()
  20. for smell_point in points_distances:
  21. distance = points_distances[smell_point]
  22. molecule = Molecule(MOLECULES_DIRECTION, smell_type, distance)
  23. try:
  24. DirectionMolecule.appose(context, smell_point, molecule)
  25. except BestMoleculeHere:
  26. pass