subject.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # coding: utf-8
  2. import typing
  3. from synergine2.simulation import SubjectBehaviourSelector, SubjectBehaviour
  4. from opencombat.const import COLLECTION_ALIVE
  5. from opencombat.const import COMBAT_MODE_DEFENSE
  6. from opencombat.simulation.base import BaseSubject
  7. from opencombat.simulation.behaviour import MoveToBehaviour
  8. from opencombat.simulation.behaviour import EngageOpponent
  9. from opencombat.simulation.behaviour import LookAroundBehaviour
  10. from synergine2.share import shared
  11. class TileBehaviourSelector(SubjectBehaviourSelector):
  12. def reduce_behaviours(
  13. self,
  14. behaviours: typing.Dict[typing.Type[SubjectBehaviour], object],
  15. ) -> typing.Dict[typing.Type[SubjectBehaviour], object]:
  16. return behaviours
  17. class TileSubject(BaseSubject):
  18. start_collections = [
  19. COLLECTION_ALIVE,
  20. ]
  21. behaviours_classes = [
  22. MoveToBehaviour,
  23. LookAroundBehaviour,
  24. EngageOpponent,
  25. ]
  26. visible_opponent_ids = shared.create_self('visible_opponent_ids', lambda: [])
  27. combat_mode = shared.create_self('combat_mode', COMBAT_MODE_DEFENSE)
  28. behaviour_selector_class = TileBehaviourSelector
  29. def __init__(self, *args, **kwargs):
  30. super().__init__(*args, **kwargs)
  31. self._walk_ref_time = float(self.config.resolve('game.move.walk_ref_time'))
  32. self._run_ref_time = float(self.config.resolve('game.move.run_ref_time'))
  33. self._crawl_ref_time = float(self.config.resolve('game.move.crawl_ref_time'))
  34. @property
  35. def global_move_coeff(self) -> float:
  36. return 1
  37. @property
  38. def run_duration(self) -> float:
  39. return self._run_ref_time * self.global_move_coeff
  40. @property
  41. def walk_duration(self) -> float:
  42. return self._walk_ref_time * self.global_move_coeff
  43. @property
  44. def crawl_duration(self) -> float:
  45. return self._crawl_ref_time * self.global_move_coeff
  46. class ManSubject(TileSubject):
  47. pass
  48. class TankSubject(TileSubject):
  49. def __init__(self, *args, **kwargs) -> None:
  50. super().__init__(*args, **kwargs)
  51. # TODO BS 2018-01-26: This coeff will be dependent of real
  52. # unit type (tiger 2, etc)
  53. self._global_move_coeff = self.config.resolve(
  54. 'game.move.subject.tank1.global_move_coeff',
  55. 3,
  56. )
  57. @property
  58. def global_move_coeff(self) -> float:
  59. return self._global_move_coeff