TransportBrainPart.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from intelligine.cst import MODE, TYPE
  2. from intelligine.simulation.object.brain.part.BrainPart import BrainPart
  3. class TransportBrainPart(BrainPart):
  4. _mode_matches = {}
  5. _types_matches = {}
  6. @classmethod
  7. def _match_with_mode(cls, context, object_id, concerned_object_id):
  8. move_mode = context.metas.value.get(MODE, object_id)
  9. for takable_type in cls._mode_matches[move_mode]:
  10. if context.metas.list.have(TYPE, concerned_object_id, takable_type, allow_empty=True):
  11. return True
  12. return False
  13. @classmethod
  14. def _objects_types_match(cls, context, object_a_id, object_b_id):
  15. """
  16. Retourne vrai si un des type de l'objet b se trouve dans la lise de type définis dans _types_matches pour
  17. l'un des types de l'objet a.
  18. :param context:
  19. :param object_a_id:
  20. :param object_b_id:
  21. :return: bool
  22. """
  23. object_a_types = context.metas.list.get(TYPE, object_a_id)
  24. object_b_types = context.metas.list.get(TYPE, object_b_id)
  25. for object_a_type in object_a_types:
  26. if object_a_type in cls._types_matches:
  27. wanted_types = cls._types_matches[object_a_type]
  28. for object_b_type in object_b_types:
  29. if object_b_type in wanted_types:
  30. return True
  31. return False