Ant.py 2.1KB

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