|
@@ -8,6 +8,7 @@ from synergine2.config import Config
|
8
|
8
|
from synergine2.log import get_logger
|
9
|
9
|
|
10
|
10
|
from opencombat.simulation.base import TileStrategySimulation
|
|
11
|
+from opencombat.simulation.subject import TileSubject
|
11
|
12
|
from opencombat.strategy.team.model import TeamModel
|
12
|
13
|
from opencombat.strategy.team.stash import TeamStash
|
13
|
14
|
from opencombat.strategy.unit.stash import UnitStash
|
|
@@ -15,6 +16,56 @@ from opencombat.util import get_class_from_string_path, pretty_xml
|
15
|
16
|
from opencombat.xml import XmlValidator
|
16
|
17
|
|
17
|
18
|
|
|
19
|
+class Troop(object):
|
|
20
|
+ def __init__(
|
|
21
|
+ self,
|
|
22
|
+ config: Config,
|
|
23
|
+ state_root: Element,
|
|
24
|
+ simulation: TileStrategySimulation,
|
|
25
|
+ ) -> None:
|
|
26
|
+ self._config = config
|
|
27
|
+ self._state_root = state_root
|
|
28
|
+ self._subjects = None # type: typing.List[TileSubject]
|
|
29
|
+ self._simulation = simulation
|
|
30
|
+ self._builder = TroopClassBuilder(config)
|
|
31
|
+
|
|
32
|
+ @property
|
|
33
|
+ def subjects(self) -> typing.List[TileSubject]:
|
|
34
|
+ if self._subjects is None:
|
|
35
|
+ self._subjects = self.get_computed_subjects()
|
|
36
|
+
|
|
37
|
+ return self._subjects
|
|
38
|
+
|
|
39
|
+ def get_computed_subjects(self) -> typing.List[TileSubject]:
|
|
40
|
+ units_file_path = self._config.get(
|
|
41
|
+ 'global.units',
|
|
42
|
+ 'opencombat/strategy/units.xml',
|
|
43
|
+ )
|
|
44
|
+ teams_file_path = self._config.get(
|
|
45
|
+ 'global.teams',
|
|
46
|
+ 'opencombat/strategy/teams.xml',
|
|
47
|
+ )
|
|
48
|
+
|
|
49
|
+ team_stash = self._builder.get_team_stash(
|
|
50
|
+ units_file_path,
|
|
51
|
+ teams_file_path,
|
|
52
|
+ )
|
|
53
|
+
|
|
54
|
+ # Parse team, build Subjects
|
|
55
|
+ subjects = [] # type: typing.List[TileSubject]
|
|
56
|
+ for troop in self._state_root.findall('troop'):
|
|
57
|
+ country = troop.attrib['country']
|
|
58
|
+ team_id = troop.attrib['team_id']
|
|
59
|
+ team = team_stash.get_team(team_id, country)
|
|
60
|
+
|
|
61
|
+ for unit in team.units:
|
|
62
|
+ subject = unit.class_(self._config, self._simulation)
|
|
63
|
+ subjects.append(subject)
|
|
64
|
+
|
|
65
|
+ # TODO BS 2018-06-25: place subjects on map, set side, color, etc
|
|
66
|
+ return subjects
|
|
67
|
+
|
|
68
|
+
|
18
|
69
|
class TroopDumper(object):
|
19
|
70
|
def __init__(
|
20
|
71
|
self,
|
|
@@ -126,7 +177,7 @@ class TroopLoader(object):
|
126
|
177
|
|
127
|
178
|
schema_file_path = self._config.get(
|
128
|
179
|
'global.troop_schema',
|
129
|
|
- 'opencombat/strategy/troop.xsd',
|
|
180
|
+ 'opencombat/strategy/troops.xsd',
|
130
|
181
|
)
|
131
|
182
|
self._xml_validator = XmlValidator(
|
132
|
183
|
config,
|