Bastien Sevajol 6 years ago
parent
commit
3edec31a44

BIN
medias/images/actors/src/tank1.xcf View File


BIN
medias/images/actors/tank1.png View File


+ 18 - 0
opencombat/gui/actor.py View File

42
         subject: Subject,
42
         subject: Subject,
43
     ) -> None:
43
     ) -> None:
44
         super().__init__('actors/man.png', subject=subject, config=config)
44
         super().__init__('actors/man.png', subject=subject, config=config)
45
+
46
+
47
+class HeavyVehicle(Actor):
48
+    animation_image_paths = {
49
+        ANIMATION_WALK: [
50
+            'actors/tank1.png',
51
+        ],
52
+        ANIMATION_CRAWL: [
53
+            'actors/tank1.png',
54
+        ]
55
+    }
56
+
57
+    def __init__(
58
+        self,
59
+        config: Config,
60
+        subject: Subject,
61
+    ) -> None:
62
+        super().__init__('actors/tank1.png', subject=subject, config=config)

+ 11 - 15
opencombat/gui/base.py View File

40
 from opencombat.simulation.event import NoLongerVisibleOpponent
40
 from opencombat.simulation.event import NoLongerVisibleOpponent
41
 from opencombat.simulation.event import FireEvent
41
 from opencombat.simulation.event import FireEvent
42
 from opencombat.simulation.event import DieEvent
42
 from opencombat.simulation.event import DieEvent
43
-from opencombat.simulation.subject import TileSubject as ManSubject
43
+from opencombat.simulation.subject import ManSubject
44
+from opencombat.simulation.subject import TankSubject
44
 from opencombat.gui.actor import Man as ManActor
45
 from opencombat.gui.actor import Man as ManActor
46
+from opencombat.gui.actor import HeavyVehicle as HeavyVehicleActor
45
 
47
 
46
 
48
 
47
 class EditLayer(BaseEditLayer):
49
 class EditLayer(BaseEditLayer):
228
             self.subject_die,
230
             self.subject_die,
229
         )
231
         )
230
 
232
 
231
-        # configs / resources
232
-        self.move_duration_ref = float(self.config.resolve(
233
-            'game.move.walk_ref_time',
234
-        ))
235
-        self.move_fast_duration_ref = float(self.config.resolve(
236
-            'game.move.run_ref_time',
237
-        ))
238
-        self.move_crawl_duration_ref = float(self.config.resolve(
239
-            'game.move.crawl_ref_time',
240
-        ))
241
         self.dead_soldier_image = pyglet.resource.image(self.graphic_path_manager.path(
233
         self.dead_soldier_image = pyglet.resource.image(self.graphic_path_manager.path(
242
             'actors/man_d1.png',
234
             'actors/man_d1.png',
243
         ))
235
         ))
247
             ManSubject,
239
             ManSubject,
248
             SubjectMapper(self.config, ManActor),
240
             SubjectMapper(self.config, ManActor),
249
         )
241
         )
242
+        self.subject_mapper_factory.register_mapper(
243
+            TankSubject,
244
+            SubjectMapper(self.config, HeavyVehicleActor),
245
+        )
250
 
246
 
251
     def before_run(self) -> None:
247
     def before_run(self) -> None:
252
         from opencombat.gui.move import MoveActorInteraction
248
         from opencombat.gui.move import MoveActorInteraction
273
         if event.gui_action == UserAction.ORDER_MOVE:
269
         if event.gui_action == UserAction.ORDER_MOVE:
274
             animation = ANIMATION_WALK
270
             animation = ANIMATION_WALK
275
             cycle_duration = 2
271
             cycle_duration = 2
276
-            move_duration = self.move_duration_ref
277
         elif event.gui_action == UserAction.ORDER_MOVE_FAST:
272
         elif event.gui_action == UserAction.ORDER_MOVE_FAST:
278
             animation = ANIMATION_WALK
273
             animation = ANIMATION_WALK
279
             cycle_duration = 0.5
274
             cycle_duration = 0.5
280
-            move_duration = self.move_fast_duration_ref
281
         elif event.gui_action == UserAction.ORDER_MOVE_CRAWL:
275
         elif event.gui_action == UserAction.ORDER_MOVE_CRAWL:
282
             animation = ANIMATION_CRAWL
276
             animation = ANIMATION_CRAWL
283
             cycle_duration = 2
277
             cycle_duration = 2
284
-            move_duration = self.move_crawl_duration_ref
285
         else:
278
         else:
286
-            raise NotImplementedError()
279
+            raise NotImplementedError(
280
+                'Gui action {} unknown'.format(event.gui_action)
281
+            )
287
 
282
 
283
+        move_duration = event.move_duration
288
         move_action = MoveTo(new_world_position, move_duration)
284
         move_action = MoveTo(new_world_position, move_duration)
289
         actor.do(move_action)
285
         actor.do(move_action)
290
         actor.do(Animate(animation, duration=move_duration, cycle_duration=cycle_duration))
286
         actor.do(Animate(animation, duration=move_duration, cycle_duration=cycle_duration))

+ 25 - 14
opencombat/simulation/behaviour.py View File

19
 
19
 
20
 
20
 
21
 class MoveToBehaviour(BaseMoveToBehaviour):
21
 class MoveToBehaviour(BaseMoveToBehaviour):
22
-    def __init__(
23
-        self,
24
-        config: Config,
25
-        simulation: Simulation,
26
-        subject: Subject,
27
-    ) -> None:
28
-        super().__init__(config, simulation, subject)
29
-        self._walk_duration = float(self.config.resolve('game.move.walk_ref_time'))
30
-        self._run_duration = float(self.config.resolve('game.move.run_ref_time'))
31
-        self._crawl_duration = float(self.config.resolve('game.move.crawl_ref_time'))
32
-
33
     def is_terminated(self) -> bool:
22
     def is_terminated(self) -> bool:
34
         return COLLECTION_ALIVE not in self.subject.collections
23
         return COLLECTION_ALIVE not in self.subject.collections
35
 
24
 
36
     def _can_move_to_next_step(self, move_to_data: dict) -> bool:
25
     def _can_move_to_next_step(self, move_to_data: dict) -> bool:
37
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE:
26
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE:
38
-            return time.time() - move_to_data['last_intention_time'] >= self._walk_duration
27
+            return time.time() - move_to_data['last_intention_time'] >= \
28
+                   self.subject.walk_duration
29
+        if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
30
+            return time.time() - move_to_data['last_intention_time'] >= \
31
+                   self.subject.run_duration
32
+        if move_to_data['gui_action'] == UserAction.ORDER_MOVE_CRAWL:
33
+            return time.time() - move_to_data['last_intention_time'] >= \
34
+                   self.subject.crawl_duration
35
+
36
+        raise NotImplementedError(
37
+            'Gui action {} unknown'.format(move_to_data['gui_action'])
38
+        )
39
+
40
+    def get_move_duration(self, move_to_data: dict) -> float:
41
+        if move_to_data['gui_action'] == UserAction.ORDER_MOVE:
42
+            return self.subject.walk_duration
39
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
43
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
40
-            return time.time() - move_to_data['last_intention_time'] >= self._run_duration
44
+            return self.subject.run_duration
41
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_CRAWL:
45
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_CRAWL:
42
-            return time.time() - move_to_data['last_intention_time'] >= self._crawl_duration
46
+            return self.subject.crawl_duration
47
+
48
+        raise NotImplementedError(
49
+            'Gui action {} unknown'.format(move_to_data['gui_action'])
50
+        )
51
+
52
+    def finalize_event(self, move_to_data: dict, event: Event) -> None:
53
+        event.move_duration = self.get_move_duration(move_to_data)
43
 
54
 
44
 
55
 
45
 class LookAroundBehaviour(AliveSubjectBehaviour):
56
 class LookAroundBehaviour(AliveSubjectBehaviour):

+ 31 - 0
opencombat/simulation/subject.py View File

32
     visible_opponent_ids = shared.create_self('visible_opponent_ids', lambda: [])
32
     visible_opponent_ids = shared.create_self('visible_opponent_ids', lambda: [])
33
     combat_mode = shared.create_self('combat_mode', COMBAT_MODE_DEFENSE)
33
     combat_mode = shared.create_self('combat_mode', COMBAT_MODE_DEFENSE)
34
     behaviour_selector_class = TileBehaviourSelector
34
     behaviour_selector_class = TileBehaviourSelector
35
+
36
+    def __init__(self, *args, **kwargs):
37
+        super().__init__(*args, **kwargs)
38
+        self._walk_ref_time = float(self.config.resolve('game.move.walk_ref_time'))
39
+        self._run_ref_time = float(self.config.resolve('game.move.run_ref_time'))
40
+        self._crawl_ref_time = float(self.config.resolve('game.move.crawl_ref_time'))
41
+
42
+    @property
43
+    def global_move_coeff(self) -> float:
44
+        return 1
45
+
46
+    @property
47
+    def run_duration(self) -> float:
48
+        return self._run_ref_time * self.global_move_coeff
49
+
50
+    @property
51
+    def walk_duration(self) -> float:
52
+        return self._walk_ref_time * self.global_move_coeff
53
+
54
+    @property
55
+    def crawl_duration(self) -> float:
56
+        return self._crawl_ref_time * self.global_move_coeff
57
+
58
+
59
+class ManSubject(TileSubject):
60
+    pass
61
+
62
+class TankSubject(TileSubject):
63
+    @property
64
+    def global_move_coeff(self) -> float:
65
+        return 3

+ 17 - 3
run.py View File

16
 from opencombat.const import DE_COLOR
16
 from opencombat.const import DE_COLOR
17
 from opencombat.const import URSS_COLOR
17
 from opencombat.const import URSS_COLOR
18
 from opencombat.const import FLAG_URSS
18
 from opencombat.const import FLAG_URSS
19
-from opencombat.simulation.subject import TileSubject
19
+from opencombat.simulation.subject import ManSubject
20
+from opencombat.simulation.subject import TankSubject
20
 from opencombat.simulation.base import TileStrategySimulation
21
 from opencombat.simulation.base import TileStrategySimulation
21
 from opencombat.simulation.base import TileStrategySubjects
22
 from opencombat.simulation.base import TileStrategySubjects
22
 from opencombat.terminal.base import CocosTerminal
23
 from opencombat.terminal.base import CocosTerminal
37
     subjects = TileStrategySubjects(simulation=simulation)
38
     subjects = TileStrategySubjects(simulation=simulation)
38
 
39
 
39
     for position in ((10, 2), (11, 3), (11, 4), (12, 5),):
40
     for position in ((10, 2), (11, 3), (11, 4), (12, 5),):
40
-        man = TileSubject(
41
+        man = ManSubject(
41
             config=config,
42
             config=config,
42
             simulation=simulation,
43
             simulation=simulation,
43
             position=position,
44
             position=position,
50
         subjects.append(man)
51
         subjects.append(man)
51
 
52
 
52
     for position in ((30, 15), (31, 16), (32, 17), (33, 18),):
53
     for position in ((30, 15), (31, 16), (32, 17), (33, 18),):
53
-        man = TileSubject(
54
+        man = ManSubject(
55
+            config=config,
56
+            simulation=simulation,
57
+            position=position,
58
+            properties={
59
+                SELECTION_COLOR_RGB: URSS_COLOR,
60
+                FLAG: FLAG_URSS,
61
+                SIDE: 'ALLIES',
62
+            }
63
+        )
64
+        subjects.append(man)
65
+
66
+    for position in ((38, 24),):
67
+        man = TankSubject(
54
             config=config,
68
             config=config,
55
             simulation=simulation,
69
             simulation=simulation,
56
             position=position,
70
             position=position,