Browse Source

dapt code to NotConcernedEvent and Event return parameters

Bastien Sevajol 9 years ago
parent
commit
2824b8d000

+ 4 - 1
intelligine/core/exceptions.py View File

35
     def get_best_distance(self):
35
     def get_best_distance(self):
36
         return self._best_distance
36
         return self._best_distance
37
 
37
 
38
+
38
 class BrainException(Exception):
39
 class BrainException(Exception):
39
     pass
40
     pass
40
 
41
 
42
+
41
 class BrainPartAlreadyExist(BrainException):
43
 class BrainPartAlreadyExist(BrainException):
42
     pass
44
     pass
43
 
45
 
46
+
44
 class DirectionException(Exception):
47
 class DirectionException(Exception):
45
-    pass
48
+    pass

+ 2 - 2
intelligine/synergy/event/CycleEvent.py View File

6
 
6
 
7
     concern = COL_TRANSPORTER
7
     concern = COL_TRANSPORTER
8
 
8
 
9
-    def _object_match(self, object_id, context, parameters):
10
-        return True
9
+    def _prepare(self, object_id, context, parameters):
10
+        return parameters

+ 4 - 3
intelligine/synergy/event/attack/NearAttackableEvent.py View File

1
+from synergine.core.exceptions import NotConcernedEvent
1
 from intelligine.synergy.event.src.NearEvent import NearEvent
2
 from intelligine.synergy.event.src.NearEvent import NearEvent
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
 from intelligine.cst import ATTACKABLE, COLONY, COL_FIGHTER
4
 from intelligine.cst import ATTACKABLE, COLONY, COL_FIGHTER
13
         super().__init__(actions)
14
         super().__init__(actions)
14
         self._mechanism = ArroundMechanism
15
         self._mechanism = ArroundMechanism
15
 
16
 
16
-    def _object_match(self, object_id, context, parameters={}):
17
+    def _prepare(self, object_id, context, parameters={}):
17
         obj_colony_id = context.metas.value.get(COLONY, object_id)
18
         obj_colony_id = context.metas.value.get(COLONY, object_id)
18
         filter = lambda near_object_id, context: obj_colony_id != context.metas.value.get(COLONY, near_object_id)
19
         filter = lambda near_object_id, context: obj_colony_id != context.metas.value.get(COLONY, near_object_id)
19
         self.map(context, parameters, stop_at_first=True, filter=filter)
20
         self.map(context, parameters, stop_at_first=True, filter=filter)
20
         if self._near_name not in parameters:
21
         if self._near_name not in parameters:
21
-            return False
22
-        return True
22
+            raise NotConcernedEvent()
23
+        return parameters

+ 2 - 2
intelligine/synergy/event/move/MoveEvent.py View File

11
         super().__init__(actions)
11
         super().__init__(actions)
12
         self._mechanism = Mechanism
12
         self._mechanism = Mechanism
13
 
13
 
14
-    def _object_match(self, object_id, context, parameters={}):
15
-      return True
14
+    def _prepare(self, object_id, context, parameters={}):
15
+        return parameters

+ 4 - 4
intelligine/synergy/event/transport/PutableEvent.py View File

1
+from synergine.core.exceptions import NotConcernedEvent
1
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
2
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
2
-from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
 from intelligine.cst import CANT_PUT_STILL, COL_TRANSPORTER_CARRYING
3
 from intelligine.cst import CANT_PUT_STILL, COL_TRANSPORTER_CARRYING
4
 
4
 
5
 
5
 
7
 
7
 
8
     concern = COL_TRANSPORTER_CARRYING
8
     concern = COL_TRANSPORTER_CARRYING
9
 
9
 
10
-    def _object_match(self, object_id, context, parameters={}):
10
+    def _prepare(self, object_id, context, parameters={}):
11
         if context.metas.value.get(CANT_PUT_STILL, object_id, allow_empty=True):
11
         if context.metas.value.get(CANT_PUT_STILL, object_id, allow_empty=True):
12
-            return False
13
-        return super()._object_match(object_id, context, parameters)
12
+            raise NotConcernedEvent()
13
+        return super()._prepare(object_id, context, parameters)

+ 5 - 4
intelligine/synergy/event/transport/TakeableEvent.py View File

1
+from synergine.core.exceptions import NotConcernedEvent
1
 from intelligine.synergy.event.src.NearEvent import NearEvent
2
 from intelligine.synergy.event.src.NearEvent import NearEvent
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
 from intelligine.cst import TRANSPORTABLE, CANT_CARRY_STILL, COL_TRANSPORTER_NOT_CARRYING
4
 from intelligine.cst import TRANSPORTABLE, CANT_CARRY_STILL, COL_TRANSPORTER_NOT_CARRYING
13
         super().__init__(actions)
14
         super().__init__(actions)
14
         self._mechanism = ArroundMechanism
15
         self._mechanism = ArroundMechanism
15
 
16
 
16
-    def _object_match(self, object_id, context, parameters={}):
17
+    def _prepare(self, object_id, context, parameters={}):
17
         if context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True):
18
         if context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True):
18
-            return False
19
+            raise NotConcernedEvent()
19
         self.map(context, parameters, stop_at_first=True)
20
         self.map(context, parameters, stop_at_first=True)
20
         if self._near_name not in parameters:
21
         if self._near_name not in parameters:
21
-            return False
22
-        return True
22
+            raise NotConcernedEvent()
23
+        return parameters