Browse Source

disable behaviours when placement mode

Bastien Sevajol 6 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
 import time
3
 import time
4
 import typing
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
 from opencombat.const import COLLECTION_ALIVE
10
 from opencombat.const import COLLECTION_ALIVE
7
 from opencombat.simulation.base import AliveSubjectBehaviour
11
 from opencombat.simulation.base import AliveSubjectBehaviour
8
 from opencombat.simulation.event import NoLongerVisibleOpponent
12
 from opencombat.simulation.event import NoLongerVisibleOpponent
10
 from opencombat.simulation.event import DieEvent
14
 from opencombat.simulation.event import DieEvent
11
 from opencombat.simulation.event import NewVisibleOpponent
15
 from opencombat.simulation.event import NewVisibleOpponent
12
 from opencombat.simulation.mechanism import OpponentVisibleMechanism
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
 class LookAroundBehaviour(AliveSubjectBehaviour):
19
 class LookAroundBehaviour(AliveSubjectBehaviour):
86
 
51
 
87
         return new_visible_subject_events + no_longer_visible_subject_events
52
         return new_visible_subject_events + no_longer_visible_subject_events
88
 
53
 
54
+    @disable_when(config_value('_runtime.placement_mode'))
89
     def run(self, data):
55
     def run(self, data):
90
         visible_subjects = data[self.visible_mechanism]['visible_subjects']
56
         visible_subjects = data[self.visible_mechanism]['visible_subjects']
91
         visible_subject_ids = [s.id for s in visible_subjects]
57
         visible_subject_ids = [s.id for s in visible_subjects]
106
         }
72
         }
107
 
73
 
108
 
74
 
109
-@disable_when(config_value('_runtime.placement_mode'))
110
 class EngageOpponent(AliveSubjectBehaviour):
75
 class EngageOpponent(AliveSubjectBehaviour):
111
     visible_mechanism = OpponentVisibleMechanism
76
     visible_mechanism = OpponentVisibleMechanism
112
     use = [visible_mechanism]
77
     use = [visible_mechanism]
141
 
106
 
142
         return events
107
         return events
143
 
108
 
109
+    @disable_when(config_value('_runtime.placement_mode'))
144
     def run(self, data):
110
     def run(self, data):
145
         visible_subjects = data[self.visible_mechanism]['visible_subjects']
111
         visible_subjects = data[self.visible_mechanism]['visible_subjects']
146
         if not visible_subjects:
112
         if not visible_subjects:

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

1
 # coding: utf-8
1
 # coding: utf-8
2
 import typing
2
 import typing
3
 
3
 
4
-from opencombat.const import SIDE, COLLECTION_ALIVE
5
 from synergine2_xyz.subjects import XYZSubject
4
 from synergine2_xyz.subjects import XYZSubject
6
 from synergine2_xyz.visible.simulation import VisibleMechanism
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
 class OpponentVisibleMechanism(VisibleMechanism):
13
 class OpponentVisibleMechanism(VisibleMechanism):
10
     from_collection = COLLECTION_ALIVE
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
     def reduce_subjects(self, subjects: typing.List[XYZSubject]) -> typing.Iterator[XYZSubject]:
20
     def reduce_subjects(self, subjects: typing.List[XYZSubject]) -> typing.Iterator[XYZSubject]:
13
         def filter_subject(subject: XYZSubject) -> bool:
21
         def filter_subject(subject: XYZSubject) -> bool:
14
             return self.subject.properties[SIDE] != subject.properties[SIDE]
22
             return self.subject.properties[SIDE] != subject.properties[SIDE]

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

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

+ 3 - 3
run.py View File

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