placement.py 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # coding: utf-8
  2. import typing
  3. from synergine2.config import Config
  4. from opencombat.const import SIDE
  5. from opencombat.simulation.base import TileStrategySimulation
  6. if typing.TYPE_CHECKING:
  7. from opencombat.simulation.subject import TileSubject
  8. class Placement(object):
  9. """
  10. Place troops on a map
  11. """
  12. def __init__(
  13. self,
  14. config: Config,
  15. simulation: TileStrategySimulation,
  16. ) -> None:
  17. self._config = config
  18. self._simulation = simulation
  19. def place(self) -> None:
  20. # For now it is an extremely simple way to do it
  21. subject_by_sides = {} # type: typing.Dict[str, typing.List[TileSubject]] # nopep8
  22. for subject in self._simulation.subjects:
  23. subject_by_sides.setdefault(subject.properties[SIDE], []).append(
  24. subject,
  25. )
  26. x, y = 0, 0
  27. for side, subjects in subject_by_sides.items():
  28. y += 2
  29. for subject in subjects:
  30. x += 2
  31. subject.position = (x, y)