BaseBug.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from intelligine.core.exceptions import BodyPartAlreadyExist
  2. from intelligine.synergy.object.Transportable import Transportable
  3. from intelligine.cst import ALIVE, ATTACKABLE, COL_ALIVE
  4. from intelligine.simulation.object.brain.Brain import Brain
  5. class BaseBug(Transportable):
  6. _body_parts = {}
  7. def __init__(self, collection, context):
  8. super().__init__(collection, context)
  9. context.metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
  10. context.metas.collections.add(self.get_id(), COL_ALIVE)
  11. context.metas.value.set(COLONY, self.get_id(), collection.get_id())
  12. self._life_points = 10
  13. self._movements_count = -1
  14. self._brain = self._get_brain_instance()
  15. self._parts = {}
  16. self._init_parts()
  17. def _init_parts(self):
  18. for body_part_name in self._body_parts:
  19. self._set_body_part(body_part_name, self._body_parts[body_part_name](self, self._context))
  20. def _set_body_part(self, name, body_part, replace=False):
  21. if name in self._parts and not replace:
  22. raise BodyPartAlreadyExist()
  23. self._parts[name] = body_part
  24. def get_body_part(self, name):
  25. return self._parts[name]
  26. def hurted(self, points):
  27. self._life_points -= points
  28. def get_life_points(self):
  29. return self._life_points
  30. def set_position(self, point):
  31. super().set_position(point)
  32. self._movements_count += 1
  33. def get_movements_count(self):
  34. return self._movements_count
  35. def _get_brain_instance(self):
  36. return Brain(self._context, self)
  37. def get_brain(self):
  38. return self._brain