Browse Source

combat mode in state

Bastien Sevajol 6 years ago
parent
commit
cab804b9d1

+ 6 - 6
maps/001/state1.xml View File

8
             <type>opencombat.simulation.subject.ManSubject</type>
8
             <type>opencombat.simulation.subject.ManSubject</type>
9
             <position>72,7</position>
9
             <position>72,7</position>
10
             <direction>90</direction>
10
             <direction>90</direction>
11
-            <mode>standup</mode>
11
+            <combat_mode>COMBAT_MODE_DEFEND</combat_mode>
12
             <properties>
12
             <properties>
13
                 <item>
13
                 <item>
14
                     <key>SELECTION_COLOR_RGB</key>
14
                     <key>SELECTION_COLOR_RGB</key>
28
             <type>opencombat.simulation.subject.ManSubject</type>
28
             <type>opencombat.simulation.subject.ManSubject</type>
29
             <position>72,9</position>
29
             <position>72,9</position>
30
             <direction>90</direction>
30
             <direction>90</direction>
31
-            <mode>standup</mode>
31
+            <combat_mode>COMBAT_MODE_DEFEND</combat_mode>
32
             <properties>
32
             <properties>
33
                 <item>
33
                 <item>
34
                     <key>SELECTION_COLOR_RGB</key>
34
                     <key>SELECTION_COLOR_RGB</key>
48
             <type>opencombat.simulation.subject.ManSubject</type>
48
             <type>opencombat.simulation.subject.ManSubject</type>
49
             <position>72,11</position>
49
             <position>72,11</position>
50
             <direction>90</direction>
50
             <direction>90</direction>
51
-            <mode>standup</mode>
51
+            <combat_mode>COMBAT_MODE_DEFEND</combat_mode>
52
             <properties>
52
             <properties>
53
                 <item>
53
                 <item>
54
                     <key>SELECTION_COLOR_RGB</key>
54
                     <key>SELECTION_COLOR_RGB</key>
68
             <type>opencombat.simulation.subject.ManSubject</type>
68
             <type>opencombat.simulation.subject.ManSubject</type>
69
             <position>58,54</position>
69
             <position>58,54</position>
70
             <direction>270</direction>
70
             <direction>270</direction>
71
-            <mode>hiding</mode>
71
+            <combat_mode>hiding</combat_mode>
72
             <properties>
72
             <properties>
73
                 <item>
73
                 <item>
74
                     <key>SELECTION_COLOR_RGB</key>
74
                     <key>SELECTION_COLOR_RGB</key>
88
             <type>opencombat.simulation.subject.ManSubject</type>
88
             <type>opencombat.simulation.subject.ManSubject</type>
89
             <position>58,56</position>
89
             <position>58,56</position>
90
             <direction>270</direction>
90
             <direction>270</direction>
91
-            <mode>hiding</mode>
91
+            <combat_mode>hiding</combat_mode>
92
             <properties>
92
             <properties>
93
                 <item>
93
                 <item>
94
                     <key>SELECTION_COLOR_RGB</key>
94
                     <key>SELECTION_COLOR_RGB</key>
108
             <type>opencombat.simulation.subject.ManSubject</type>
108
             <type>opencombat.simulation.subject.ManSubject</type>
109
             <position>58,58</position>
109
             <position>58,58</position>
110
             <direction>270</direction>
110
             <direction>270</direction>
111
-            <mode>hiding</mode>
111
+            <combat_mode>hiding</combat_mode>
112
             <properties>
112
             <properties>
113
                 <item>
113
                 <item>
114
                     <key>SELECTION_COLOR_RGB</key>
114
                     <key>SELECTION_COLOR_RGB</key>

+ 2 - 1
opencombat/const.py View File

8
 
8
 
9
 SIDE = 'SIDE'
9
 SIDE = 'SIDE'
10
 COMBAT_MODE = 'COMBAT_MODE'
10
 COMBAT_MODE = 'COMBAT_MODE'
11
-COMBAT_MODE_DEFENSE = 'COMBAT_MODE_DEFENSE'
11
+COMBAT_MODE_DEFEND = 'COMBAT_MODE_DEFEND'
12
+COMBAT_MODE_HIDE = 'COMBAT_MODE_HIDE'
12
 
13
 
13
 DE_COLOR = (0, 81, 211)
14
 DE_COLOR = (0, 81, 211)
14
 URSS_COLOR = (204, 0, 0)
15
 URSS_COLOR = (204, 0, 0)

+ 2 - 2
opencombat/simulation/subject.py View File

7
 from synergine2_xyz.move.intention import MoveToIntention
7
 from synergine2_xyz.move.intention import MoveToIntention
8
 
8
 
9
 from opencombat.const import COLLECTION_ALIVE
9
 from opencombat.const import COLLECTION_ALIVE
10
-from opencombat.const import COMBAT_MODE_DEFENSE
10
+from opencombat.const import COMBAT_MODE_DEFEND
11
 from opencombat.simulation.base import BaseSubject
11
 from opencombat.simulation.base import BaseSubject
12
 from opencombat.simulation.move import MoveBehaviour
12
 from opencombat.simulation.move import MoveBehaviour
13
 from opencombat.simulation.move import MoveWithRotationBehaviour
13
 from opencombat.simulation.move import MoveWithRotationBehaviour
29
         COLLECTION_ALIVE,
29
         COLLECTION_ALIVE,
30
     ]
30
     ]
31
     visible_opponent_ids = shared.create_self('visible_opponent_ids', lambda: [])
31
     visible_opponent_ids = shared.create_self('visible_opponent_ids', lambda: [])
32
-    combat_mode = shared.create_self('combat_mode', COMBAT_MODE_DEFENSE)
32
+    combat_mode = shared.create_self('combat_mode', COMBAT_MODE_DEFEND)
33
     behaviour_selector_class = TileBehaviourSelector
33
     behaviour_selector_class = TileBehaviourSelector
34
 
34
 
35
     direction = shared.create_self('direction', 0)
35
     direction = shared.create_self('direction', 0)

+ 9 - 0
opencombat/state.py View File

67
         subject.direction = float(
67
         subject.direction = float(
68
             get_text_xml_element(subject_element, 'direction'),
68
             get_text_xml_element(subject_element, 'direction'),
69
         )
69
         )
70
+        # TODO BS 2018-06-20: Maybe need apply this mode no ?
71
+        subject.combat_mode = \
72
+            get_text_xml_element(subject_element, 'combat_mode')
70
 
73
 
71
         properties_element = subject_element.find('properties')
74
         properties_element = subject_element.find('properties')
72
         decode_properties_map = self._get_decode_properties_map()
75
         decode_properties_map = self._get_decode_properties_map()
152
             direction_element = etree.SubElement(subject_element, 'direction')
155
             direction_element = etree.SubElement(subject_element, 'direction')
153
             direction_element.text = str(subject.direction)
156
             direction_element.text = str(subject.direction)
154
 
157
 
158
+            combat_mode_element = etree.SubElement(
159
+                subject_element,
160
+                'combat_mode',
161
+            )
162
+            combat_mode_element.text = str(subject.combat_mode)
163
+
155
             properties_element = etree.SubElement(
164
             properties_element = etree.SubElement(
156
                 subject_element,
165
                 subject_element,
157
                 'properties',
166
                 'properties',

+ 4 - 5
opencombat/state.xsd View File

23
         </xs:sequence>
23
         </xs:sequence>
24
     </xs:complexType>
24
     </xs:complexType>
25
 
25
 
26
-    <xs:simpleType name="modetype" final="restriction">
26
+    <xs:simpleType name="combatmodetype" final="restriction">
27
         <xs:restriction base="xs:string">
27
         <xs:restriction base="xs:string">
28
-            <xs:enumeration value="standup"/>
29
-            <xs:enumeration value="defending"/>
30
-            <xs:enumeration value="hiding"/>
28
+            <xs:enumeration value="COMBAT_MODE_DEFEND"/>
29
+            <xs:enumeration value="COMBAT_MODE_HIDE"/>
31
         </xs:restriction>
30
         </xs:restriction>
32
     </xs:simpleType>
31
     </xs:simpleType>
33
 
32
 
60
             <xs:element name="type" type="xs:string" minOccurs="1" />
59
             <xs:element name="type" type="xs:string" minOccurs="1" />
61
             <xs:element name="position" type="positiontype" minOccurs="1"/>
60
             <xs:element name="position" type="positiontype" minOccurs="1"/>
62
             <xs:element name="direction" type="directiontype" minOccurs="1"/>
61
             <xs:element name="direction" type="directiontype" minOccurs="1"/>
63
-            <xs:element name="mode" type="modetype" minOccurs="1"/>
62
+            <xs:element name="combat_mode" type="combatmodetype" minOccurs="1"/>
64
             <xs:element name="properties" type="propertiestype" minOccurs="1"/>
63
             <xs:element name="properties" type="propertiestype" minOccurs="1"/>
65
         </xs:sequence>
64
         </xs:sequence>
66
     </xs:complexType>
65
     </xs:complexType>

+ 2 - 2
tests/fixtures/state_error_schema.xml View File

8
             <type>opencombat.simulation.subject.ManSubject</type>
8
             <type>opencombat.simulation.subject.ManSubject</type>
9
             <position>1,1</position>
9
             <position>1,1</position>
10
             <direction>90</direction>
10
             <direction>90</direction>
11
-            <mode>standup</mode>
11
+            <combat_mode>COMBAT_MODE_DEFEND</combat_mode>
12
         </subject>
12
         </subject>
13
         <subjectFOO>
13
         <subjectFOO>
14
             <type>opencombat.simulation.subject.ManSubject</type>
14
             <type>opencombat.simulation.subject.ManSubject</type>
15
             <position>10,10</position>
15
             <position>10,10</position>
16
             <direction>270</direction>
16
             <direction>270</direction>
17
-            <mode>hiding</mode>
17
+            <combat_mode>hiding</combat_mode>
18
         </subjectFOO>
18
         </subjectFOO>
19
     </subjects>
19
     </subjects>
20
 </state>
20
 </state>

+ 2 - 2
tests/fixtures/state_ok.xml View File

8
             <type>opencombat.simulation.subject.ManSubject</type>
8
             <type>opencombat.simulation.subject.ManSubject</type>
9
             <position>1,1</position>
9
             <position>1,1</position>
10
             <direction>90</direction>
10
             <direction>90</direction>
11
-            <mode>standup</mode>
11
+            <combat_mode>COMBAT_MODE_DEFEND</combat_mode>
12
             <properties>
12
             <properties>
13
                 <item>
13
                 <item>
14
                     <key>SELECTION_COLOR_RGB</key>
14
                     <key>SELECTION_COLOR_RGB</key>
28
             <type>opencombat.simulation.subject.ManSubject</type>
28
             <type>opencombat.simulation.subject.ManSubject</type>
29
             <position>10,10</position>
29
             <position>10,10</position>
30
             <direction>270</direction>
30
             <direction>270</direction>
31
-            <mode>hiding</mode>
31
+            <combat_mode>COMBAT_MODE_HIDE</combat_mode>
32
             <properties>
32
             <properties>
33
                 <item>
33
                 <item>
34
                     <key>SELECTION_COLOR_RGB</key>
34
                     <key>SELECTION_COLOR_RGB</key>

+ 5 - 0
tests/test_state.py View File

111
     assert 90.0 == state.subjects[0].direction
111
     assert 90.0 == state.subjects[0].direction
112
     assert 270.0 == state.subjects[1].direction
112
     assert 270.0 == state.subjects[1].direction
113
 
113
 
114
+    assert 'COMBAT_MODE_DEFEND' == state.subjects[0].combat_mode
115
+    assert 'COMBAT_MODE_HIDE' == state.subjects[1].combat_mode
116
+
114
     assert {
117
     assert {
115
                'SELECTION_COLOR_RGB': (204, 0, 0),
118
                'SELECTION_COLOR_RGB': (204, 0, 0),
116
                'FLAG': 'FLAG_URSS',
119
                'FLAG': 'FLAG_URSS',
139
             <type>opencombat.simulation.subject.ManSubject</type>
142
             <type>opencombat.simulation.subject.ManSubject</type>
140
             <position>10,11</position>
143
             <position>10,11</position>
141
             <direction>42</direction>
144
             <direction>42</direction>
145
+            <combat_mode>COMBAT_MODE_DEFEND</combat_mode>
142
             <properties>
146
             <properties>
143
                 <item>
147
                 <item>
144
                     <key>SELECTION_COLOR_RGB</key>
148
                     <key>SELECTION_COLOR_RGB</key>
158
             <type>opencombat.simulation.subject.ManSubject</type>
162
             <type>opencombat.simulation.subject.ManSubject</type>
159
             <position>16,8</position>
163
             <position>16,8</position>
160
             <direction>197</direction>
164
             <direction>197</direction>
165
+            <combat_mode>COMBAT_MODE_DEFEND</combat_mode>
161
             <properties>
166
             <properties>
162
                 <item>
167
                 <item>
163
                     <key>SELECTION_COLOR_RGB</key>
168
                     <key>SELECTION_COLOR_RGB</key>