Browse Source

combat mode in state

Bastien Sevajol 5 years ago
parent
commit
cab804b9d1

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

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

+ 2 - 1
opencombat/const.py View File

@@ -8,7 +8,8 @@ FLAG_URSS = 'FLAG_URSS'
8 8
 
9 9
 SIDE = 'SIDE'
10 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 14
 DE_COLOR = (0, 81, 211)
14 15
 URSS_COLOR = (204, 0, 0)

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

@@ -7,7 +7,7 @@ from opencombat.user_action import UserAction
7 7
 from synergine2_xyz.move.intention import MoveToIntention
8 8
 
9 9
 from opencombat.const import COLLECTION_ALIVE
10
-from opencombat.const import COMBAT_MODE_DEFENSE
10
+from opencombat.const import COMBAT_MODE_DEFEND
11 11
 from opencombat.simulation.base import BaseSubject
12 12
 from opencombat.simulation.move import MoveBehaviour
13 13
 from opencombat.simulation.move import MoveWithRotationBehaviour
@@ -29,7 +29,7 @@ class TileSubject(BaseSubject):
29 29
         COLLECTION_ALIVE,
30 30
     ]
31 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 33
     behaviour_selector_class = TileBehaviourSelector
34 34
 
35 35
     direction = shared.create_self('direction', 0)

+ 9 - 0
opencombat/state.py View File

@@ -67,6 +67,9 @@ class State(object):
67 67
         subject.direction = float(
68 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 74
         properties_element = subject_element.find('properties')
72 75
         decode_properties_map = self._get_decode_properties_map()
@@ -152,6 +155,12 @@ class StateDumper(object):
152 155
             direction_element = etree.SubElement(subject_element, 'direction')
153 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 164
             properties_element = etree.SubElement(
156 165
                 subject_element,
157 166
                 'properties',

+ 4 - 5
opencombat/state.xsd View File

@@ -23,11 +23,10 @@
23 23
         </xs:sequence>
24 24
     </xs:complexType>
25 25
 
26
-    <xs:simpleType name="modetype" final="restriction">
26
+    <xs:simpleType name="combatmodetype" final="restriction">
27 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 30
         </xs:restriction>
32 31
     </xs:simpleType>
33 32
 
@@ -60,7 +59,7 @@
60 59
             <xs:element name="type" type="xs:string" minOccurs="1" />
61 60
             <xs:element name="position" type="positiontype" minOccurs="1"/>
62 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 63
             <xs:element name="properties" type="propertiestype" minOccurs="1"/>
65 64
         </xs:sequence>
66 65
     </xs:complexType>

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

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

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

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

+ 5 - 0
tests/test_state.py View File

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