Ant.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from intelligine.synergy.object.Bug import Bug
  2. from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
  3. COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, COL_FIGHTER
  4. class Ant(Bug):
  5. def __init__(self, collection, context):
  6. super().__init__(collection, context)
  7. context.metas.states.add_list(self.get_id(), [TRANSPORTER, ATTACKER])
  8. context.metas.collections.add_list(self.get_id(), [COL_TRANSPORTER,
  9. COL_TRANSPORTER_NOT_CARRYING,
  10. COL_FIGHTER])
  11. self._carried = []
  12. self._last_pheromones_points = {}
  13. def put_carry(self, obj, position=None):
  14. if position is None:
  15. position = self._get_position()
  16. self._carried.remove(obj)
  17. obj.set_position(position)
  18. self._context.metas.states.remove(self.get_id(), CARRYING)
  19. def get_carried(self):
  20. # TODO: cas ou plusieurs ?
  21. return self._carried[0]
  22. def carry(self, obj):
  23. self._carried.append(obj)
  24. self._context.metas.states.add(self.get_id(), CARRYING)
  25. def is_carrying(self):
  26. if len(self._carried):
  27. return True
  28. return False
  29. # TODO: Est-ce ici que doit etre ce code ?
  30. def set_position(self, position):
  31. super().set_position(position)
  32. if self.is_carrying():
  33. for obj_carried in self._carried:
  34. obj_carried.set_position(position)
  35. def get_last_pheromone_point(self, pheromone_name):
  36. if pheromone_name in self._last_pheromones_points:
  37. return self._last_pheromones_points[pheromone_name]
  38. return self._start_position
  39. def set_last_pheromone_point(self, pheromone_name, position):
  40. self._last_pheromones_points[pheromone_name] = position