BaseBug.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. self._life_points = 10
  12. self._movements_count = -1
  13. self._brain = self._get_brain_instance()
  14. self._parts = {}
  15. self._init_parts()
  16. def _init_parts(self):
  17. for body_part_name in self._body_parts:
  18. self._set_body_part(body_part_name, self._body_parts[body_part_name](self, self._context))
  19. def _set_body_part(self, name, body_part, replace=False):
  20. if name in self._parts and not replace:
  21. raise BodyPartAlreadyExist()
  22. self._parts[name] = body_part
  23. def get_body_part(self, name):
  24. return self._parts[name]
  25. def hurted(self, points):
  26. self._life_points -= points
  27. def get_life_points(self):
  28. return self._life_points
  29. def set_position(self, point):
  30. super().set_position(point)
  31. self._movements_count += 1
  32. def get_movements_count(self):
  33. return self._movements_count
  34. def _get_brain_instance(self):
  35. return Brain(self._context, self)
  36. def get_brain(self):
  37. return self._brain