Browse Source

disable behaviours when placement mode

Bastien Sevajol 5 years ago
parent
commit
2bd6d925f1
4 changed files with 25 additions and 45 deletions
  1. 6 40
      opencombat/simulation/behaviour.py
  2. 9 1
      opencombat/simulation/mechanism.py
  3. 7 1
      opencombat/simulation/move.py
  4. 3 3
      run.py

+ 6 - 40
opencombat/simulation/behaviour.py View File

@@ -3,6 +3,10 @@ import random
3 3
 import time
4 4
 import typing
5 5
 
6
+from synergine2.simulation import Event
7
+from synergine2.simulation import disable_when
8
+from synergine2.simulation import config_value
9
+
6 10
 from opencombat.const import COLLECTION_ALIVE
7 11
 from opencombat.simulation.base import AliveSubjectBehaviour
8 12
 from opencombat.simulation.event import NoLongerVisibleOpponent
@@ -10,45 +14,6 @@ from opencombat.simulation.event import FireEvent
10 14
 from opencombat.simulation.event import DieEvent
11 15
 from opencombat.simulation.event import NewVisibleOpponent
12 16
 from opencombat.simulation.mechanism import OpponentVisibleMechanism
13
-from opencombat.user_action import UserAction
14
-from synergine2.simulation import Event
15
-# from synergine2_xyz.move.simulation import MoveToBehaviour as BaseMoveToBehaviour
16
-#
17
-#
18
-# class MoveToBehaviour(BaseMoveToBehaviour):
19
-#     def is_terminated(self) -> bool:
20
-#         return COLLECTION_ALIVE not in self.subject.collections
21
-#
22
-#     def _can_move_to_next_step(self, move_to_data: dict) -> bool:
23
-#         if move_to_data['gui_action'] == UserAction.ORDER_MOVE:
24
-#             return time.time() - move_to_data['last_intention_time'] >= \
25
-#                    self.subject.walk_duration
26
-#         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
27
-#             return time.time() - move_to_data['last_intention_time'] >= \
28
-#                    self.subject.run_duration
29
-#         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_CRAWL:
30
-#             return time.time() - move_to_data['last_intention_time'] >= \
31
-#                    self.subject.crawl_duration
32
-#
33
-#         raise NotImplementedError(
34
-#             'Gui action {} unknown'.format(move_to_data['gui_action'])
35
-#         )
36
-#
37
-#     # FIXME remove this func when code with new move
38
-#     def get_move_duration(self, move_to_data: dict) -> float:
39
-#         if move_to_data['gui_action'] == UserAction.ORDER_MOVE:
40
-#             return self.subject.walk_duration
41
-#         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
42
-#             return self.subject.run_duration
43
-#         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_CRAWL:
44
-#             return self.subject.crawl_duration
45
-#
46
-#         raise NotImplementedError(
47
-#             'Gui action {} unknown'.format(move_to_data['gui_action'])
48
-#         )
49
-#
50
-#     def finalize_event(self, move_to_data: dict, event: Event) -> None:
51
-#         event.move_duration = self.get_move_duration(move_to_data)
52 17
 
53 18
 
54 19
 class LookAroundBehaviour(AliveSubjectBehaviour):
@@ -86,6 +51,7 @@ class LookAroundBehaviour(AliveSubjectBehaviour):
86 51
 
87 52
         return new_visible_subject_events + no_longer_visible_subject_events
88 53
 
54
+    @disable_when(config_value('_runtime.placement_mode'))
89 55
     def run(self, data):
90 56
         visible_subjects = data[self.visible_mechanism]['visible_subjects']
91 57
         visible_subject_ids = [s.id for s in visible_subjects]
@@ -106,7 +72,6 @@ class LookAroundBehaviour(AliveSubjectBehaviour):
106 72
         }
107 73
 
108 74
 
109
-@disable_when(config_value('_runtime.placement_mode'))
110 75
 class EngageOpponent(AliveSubjectBehaviour):
111 76
     visible_mechanism = OpponentVisibleMechanism
112 77
     use = [visible_mechanism]
@@ -141,6 +106,7 @@ class EngageOpponent(AliveSubjectBehaviour):
141 106
 
142 107
         return events
143 108
 
109
+    @disable_when(config_value('_runtime.placement_mode'))
144 110
     def run(self, data):
145 111
         visible_subjects = data[self.visible_mechanism]['visible_subjects']
146 112
         if not visible_subjects:

+ 9 - 1
opencombat/simulation/mechanism.py View File

@@ -1,14 +1,22 @@
1 1
 # coding: utf-8
2 2
 import typing
3 3
 
4
-from opencombat.const import SIDE, COLLECTION_ALIVE
5 4
 from synergine2_xyz.subjects import XYZSubject
6 5
 from synergine2_xyz.visible.simulation import VisibleMechanism
6
+from synergine2.simulation import disable_when
7
+from synergine2.simulation import config_value
8
+
9
+from opencombat.const import SIDE
10
+from opencombat.const import COLLECTION_ALIVE
7 11
 
8 12
 
9 13
 class OpponentVisibleMechanism(VisibleMechanism):
10 14
     from_collection = COLLECTION_ALIVE
11 15
 
16
+    @disable_when(config_value('_runtime.placement_mode'))
17
+    def run(self) -> dict:
18
+        return super().run()
19
+
12 20
     def reduce_subjects(self, subjects: typing.List[XYZSubject]) -> typing.Iterator[XYZSubject]:
13 21
         def filter_subject(subject: XYZSubject) -> bool:
14 22
             return self.subject.properties[SIDE] != subject.properties[SIDE]

+ 7 - 1
opencombat/simulation/move.py View File

@@ -2,11 +2,14 @@
2 2
 import time
3 3
 import typing
4 4
 
5
-from synergine2.simulation import SubjectBehaviour, SubjectMechanism
5
+from synergine2.simulation import SubjectBehaviour
6
+from synergine2.simulation import SubjectMechanism
6 7
 from synergine2.simulation import Event
7 8
 from synergine2_xyz.move.intention import MoveToIntention
8 9
 from synergine2_xyz.simulation import XYZSimulation
9 10
 from synergine2_xyz.utils import get_angle
11
+from synergine2.simulation import disable_when
12
+from synergine2.simulation import config_value
10 13
 
11 14
 from opencombat.const import COLLECTION_ALIVE
12 15
 from opencombat.user_action import UserAction
@@ -107,6 +110,7 @@ class SubjectFinishMoveEvent(Event):
107 110
 
108 111
 
109 112
 class MoveToMechanism(SubjectMechanism):
113
+    @disable_when(config_value('_runtime.placement_mode'))
110 114
     def run(self) -> dict:
111 115
         try:
112 116
             # TODO: MoveToIntention doit être configurable
@@ -127,6 +131,7 @@ class MoveWithRotationBehaviour(SubjectBehaviour):
127 131
         super().__init__(*args, **kwargs)
128 132
         self.simulation = typing.cast(XYZSimulation, self.simulation)
129 133
 
134
+    @disable_when(config_value('_runtime.placement_mode'))
130 135
     def run(self, data) -> object:
131 136
         """
132 137
         Compute data relative to move
@@ -341,6 +346,7 @@ class MoveBehaviour(SubjectBehaviour):
341 346
         super().__init__(*args, **kwargs)
342 347
         self.simulation = typing.cast(XYZSimulation, self.simulation)
343 348
 
349
+    @disable_when(config_value('_runtime.placement_mode'))
344 350
     def run(self, data) -> object:
345 351
         """
346 352
         Compute data relative to move

+ 3 - 3
run.py View File

@@ -80,8 +80,8 @@ if __name__ == '__main__':
80 80
         default='.',
81 81
     )
82 82
     parser.add_argument(
83
-        '--placement-mode',
84
-        dest='placement_mode',
83
+        '--placement',
84
+        dest='placement',
85 85
         action='store_true',
86 86
     )
87 87
 
@@ -92,5 +92,5 @@ if __name__ == '__main__':
92 92
         seed_value=args.seed,
93 93
         state_file_path=args.state,
94 94
         state_save_dir=args.state_save_dir,
95
-        placement_mode=args.placement_mode,
95
+        placement_mode=args.placement,
96 96
     )