Browse Source

Put: try multiple position to put

Bastien Sevajol 9 years ago
parent
commit
21606fa917

+ 19 - 13
intelligine/synergy/event/transport/PutableAction.py View File

1
+from synergine.synergy.event.exception.ActionAborted import ActionAborted
1
 from intelligine.synergy.event.move.MoveAction import MoveAction
2
 from intelligine.synergy.event.move.MoveAction import MoveAction
2
 from intelligine.synergy.object.Food import Food
3
 from intelligine.synergy.object.Food import Food
3
 from synergine.synergy.event.Action import Action
4
 from synergine.synergy.event.Action import Action
14
         super().__init__(object_id, parameters)
15
         super().__init__(object_id, parameters)
15
 
16
 
16
     def run(self, obj, context, synergy_manager):
17
     def run(self, obj, context, synergy_manager):
17
-        position_to_put = self._parameters[PutableEvent.PARAM_PUT_TO]
18
         obj_transported = obj.get_carried()
18
         obj_transported = obj.get_carried()
19
 
19
 
20
-        obj_transported.set_carried_by(None)
21
-        #  TODO: re controle de si posable ? La position a été calculé
22
-        #  dans le process. Ce qui fait que la situation peut avoir changer.
23
-        # Soit: Recalculer d'office BrainPut.cant_put_at.. Soit le recalculer que si le hash
24
-        # de ce qu'il y a la a changer ?
25
-        obj.put_carry(obj_transported, position_to_put)
26
-        context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
20
+        if not self._parameters[PutableEvent.PARAM_PUT_TO]:
21
+            raise ActionAborted()
27
 
22
 
28
-        obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)
23
+        for position_to_put in self._parameters[PutableEvent.PARAM_PUT_TO]:
29
 
24
 
30
-        # TODO: DEBUG
31
-        if isinstance(obj_transported, Food):
32
-            #obj_transported.set_position((-1, 0, 0))
33
-            obj_transported.transform_to_stocked()
25
+            #  TODO: re controle de si posable ? La position a été calculé
26
+            #  dans le process. Ce qui fait que la situation peut avoir changer.
27
+            # Soit: Recalculer d'office BrainPut.cant_put_at.. Soit le recalculer que si le hash
28
+            # de ce qu'il y a la a changer ?
29
+
30
+            obj_transported.set_carried_by(None)
31
+            obj.put_carry(obj_transported, position_to_put)
32
+            context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
33
+
34
+            obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)
35
+
36
+            # TODO: DEV
37
+            if isinstance(obj_transported, Food):
38
+                #obj_transported.set_position((-1, 0, 0))
39
+                obj_transported.transform_to_stocked()

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

23
             raise NotConcernedEvent()
23
             raise NotConcernedEvent()
24
 
24
 
25
         try:
25
         try:
26
-            self.map(context, parameters, stop_at_first=True)
26
+            self.map(context, parameters, stop_at_first=False)
27
         except NearNothingFound:
27
         except NearNothingFound:
28
             raise NotConcernedEvent()
28
             raise NotConcernedEvent()
29
 
29
 
30
-        object_near_id = parameters[self._near_name][0]
31
         brain_part = get_brain_part(context, object_id, BRAIN_PART_PUT)
30
         brain_part = get_brain_part(context, object_id, BRAIN_PART_PUT)
32
-
33
-        if not brain_part.can_put(context, object_id, object_near_id):
34
-            raise NotConcernedEvent()
35
-
36
-        try:
37
-            put_position = brain_part.get_put_position(context, object_id, object_near_id)
38
-        except CantFindWhereToPut:
39
-            raise NotConcernedEvent()
40
-
41
-        parameters[self.PARAM_PUT] = parameters[self._near_name][0]
42
-        parameters[self.PARAM_PUT_TO] = put_position
43
-        return parameters
31
+        parameters[self.PARAM_PUT] = []
32
+        parameters[self.PARAM_PUT_TO] = []
33
+
34
+        for object_near_id in parameters[self._near_name]:
35
+            if brain_part.can_put(context, object_id, object_near_id):
36
+                try:
37
+                    put_position = brain_part.get_put_position(context, object_id, object_near_id)
38
+                    parameters[self.PARAM_PUT].append(object_near_id)
39
+                    parameters[self.PARAM_PUT_TO].append(put_position)
40
+                    return parameters  # Si a terme on veut tous les calculer a l'avance, ne pas retourner ici
41
+                except CantFindWhereToPut:
42
+                    pass  # On continu la booucle
43
+
44
+        # Si a terme on veut tous les calculer a l'avance, raise que si rien trouve
45
+        raise NotConcernedEvent()
44
 
46
 
45
     @staticmethod
47
     @staticmethod
46
     def _can_put(object_id, context):
48
     def _can_put(object_id, context):