Bastien Sevajol 9 anni fa
parent
commit
ac91025137

+ 3 - 1
intelligine/simulation/object/brain/part/BrainPart.py Vedi File

@@ -2,6 +2,8 @@ class BrainPart():
2 2
 
3 3
     def __init__(self, host_brain):
4 4
         self._host_brain = host_brain
5
+        self._context = self._host_brain.get_context()
6
+        self._host = self._host_brain.get_host()
5 7
 
6 8
     def get_host_brain(self):
7 9
         return self._host_brain
@@ -9,5 +11,5 @@ class BrainPart():
9 11
     def get_host(self):
10 12
         return self.get_host_brain().get_host()
11 13
 
12
-    def done(self, obj, context):
14
+    def done(self):
13 15
         pass

+ 18 - 20
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py Vedi File

@@ -3,7 +3,7 @@ from intelligine.simulation.object.brain.part.move.AntStar.Host import Host
3 3
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
4 4
 from intelligine.synergy.event.move.direction import directions_modifiers, get_position_with_direction_decal
5 5
 from synergine_xyz.cst import POSITION
6
-from intelligine.core.exceptions import NoMolecule, NoTypeInMolecule
6
+from intelligine.core.exceptions import NoMolecule
7 7
 from intelligine.cst import MOLECULE_SEARCHING, MOVE_MODE_EXPLO, MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, \
8 8
     EXPLORATION_VECTOR, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG
9 9
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
@@ -17,10 +17,9 @@ class AntMoveBrainPart(MoveBrainPart):
17 17
 
18 18
     def _set_exploration_vector(self, new_vector):
19 19
         self._exploration_vector = new_vector
20
-        # TODO: On devrais donner le context aux brain parts
21
-        self._host_brain.get_context().metas.value.set(EXPLORATION_VECTOR,
22
-                                                       self._host_brain.get_host().get_id(),
23
-                                                       new_vector)
20
+        self._context.metas.value.set(EXPLORATION_VECTOR,
21
+                                      self._host_brain.get_host().get_id(),
22
+                                      new_vector)
24 23
 
25 24
     @classmethod
26 25
     def get_direction(cls, context, object_id):
@@ -79,18 +78,17 @@ class AntMoveBrainPart(MoveBrainPart):
79 78
         return ByPass(ant_host, home_vector, context, object_id)
80 79
 
81 80
     # TODO: obj pas necessaire, il est dans _host
82
-    def done(self, obj, context):
83
-        super().done(obj, context)
84
-        self._appose_molecule(obj)
85
-        self._check_context(obj, context)
86
-        self._apply_context(obj, context)
81
+    def done(self):
82
+        super().done()
83
+        self._appose_molecule()
84
+        self._check_context()
85
+        self._apply_context()
87 86
 
88
-    @staticmethod
89
-    def _appose_molecule(obj):
90
-        if obj.get_movement_molecule_gland().is_enabled():
91
-            obj.get_movement_molecule_gland().appose()
87
+    def _appose_molecule(self):
88
+        if self._host.get_movement_molecule_gland().is_enabled():
89
+            self._host.get_movement_molecule_gland().appose()
92 90
 
93
-    def _check_context(self, obj, context):
91
+    def _check_context(self):
94 92
         """
95 93
 
96 94
         If was in exploration, and just found home smell;
@@ -104,17 +102,17 @@ class AntMoveBrainPart(MoveBrainPart):
104 102
         """
105 103
         movement_mode = self._host_brain.get_movement_mode()
106 104
 
107
-        if movement_mode == MOVE_MODE_GOHOME and self._on_home_smell(context, obj.get_id()):
105
+        if movement_mode == MOVE_MODE_GOHOME and self._on_home_smell(self._context, self._host.get_id()):
108 106
             self._host_brain.switch_to_mode(MOVE_MODE_HOME)
109
-            ant_star = self._get_by_pass_brain(context, obj.get_id())
107
+            ant_star = self._get_by_pass_brain(self._context, self._host.get_id())
110 108
             ant_star.erase()
111 109
             # TODO: on change les molecule recherché (Food => SmellFood, definis dans Take, en fct de ce qui est take)
112 110
 
113
-        elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(context, obj.get_id()):
111
+        elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(self._context, self._host.get_id()):
114 112
             self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
115 113
             self._start_new_exploration()
116 114
 
117
-        elif movement_mode == MOVE_MODE_EXPLO and self._on_home_smell(context, obj.get_id()):
115
+        elif movement_mode == MOVE_MODE_EXPLO and self._on_home_smell(self._context, self._host.get_id()):
118 116
             self._start_new_exploration()  # TODO: rename en reinit_explo
119 117
 
120 118
         # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
@@ -140,7 +138,7 @@ class AntMoveBrainPart(MoveBrainPart):
140 138
         self._set_exploration_vector((self._exploration_vector[0] + just_move_vector[1],
141 139
                                       self._exploration_vector[1] + just_move_vector[2]))
142 140
 
143
-    def _apply_context(self, obj, context):
141
+    def _apply_context(self):
144 142
         movement_mode = self._host_brain.get_movement_mode()
145 143
         if movement_mode == MOVE_MODE_EXPLO or movement_mode == MOVE_MODE_GOHOME:
146 144
             self._update_exploration_vector()

+ 2 - 2
intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py Vedi File

@@ -61,11 +61,11 @@ class AntPutBrainPart(TransportBrainPart):
61 61
             return True
62 62
         return False
63 63
 
64
-    def done(self, obj, puted_object, context):
64
+    def done(self, puted_object):
65 65
         # TODO: Il faut refact/logique qqpart pour ca !! Genre Brain.done(PUT, ??)
66 66
         if isinstance(puted_object, Food):
67 67
             # TODO: Quel mode ? On vient de poser (ps forcement dans la colonie) cls._mode_swicth ?
68
-            obj.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
68
+            self._host.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
69 69
             # TODO: TEST Depose au -1 pour des raisons de test. Plus tard ce sera des tas comme un autre !
70 70
             puted_object.set_position((-1, 0, 0))
71 71
 

+ 3 - 3
intelligine/simulation/object/brain/part/transport/AntTakeBrainPart.py Vedi File

@@ -27,10 +27,10 @@ class AntTakeBrainPart(TakeBrainPart):
27 27
         # Pour le moment si le type de l'objet fait partie des types admis pour le mode courant du porteur, c'est bon.
28 28
         return cls._match_with_mode(context, object_id, object_to_take_id)
29 29
 
30
-    def done(self, obj, take_object, context):
30
+    def done(self, take_object):
31 31
         # TODO: Ranger ca ? Truc plus dynamique/configurable ?
32 32
         # TODO: qqch plus generique ... (attention aux eggs)
33 33
         if isinstance(take_object, Resource):
34 34
             self._smell_target = self._host_brain.get_smell_for_object_taken(take_object)
35
-            obj.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
36
-            obj.get_movement_molecule_gland().appose()
35
+            self._host.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
36
+            self._host.get_movement_molecule_gland().appose()

+ 1 - 1
intelligine/synergy/event/move/MoveAction.py Vedi File

@@ -29,4 +29,4 @@ class MoveAction(Action):
29 29
 
30 30
         obj.set_position(self._parameters[MoveEvent.PARAM_POSITION])
31 31
         obj.set_previous_direction(self._parameters[MoveEvent.PARAM_DIRECTION])
32
-        obj.get_brain().get_part(BRAIN_PART_MOVE).done(obj, context)
32
+        obj.get_brain().get_part(BRAIN_PART_MOVE).done()

+ 1 - 1
intelligine/synergy/event/transport/PutableAction.py Vedi File

@@ -21,4 +21,4 @@ class PutableAction(Action):
21 21
         obj.put_carry(obj_transported, position_to_put)
22 22
         context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
23 23
 
24
-        obj.get_brain().get_part(BRAIN_PART_PUT).done(obj, obj_transported, context)
24
+        obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)

+ 1 - 1
intelligine/synergy/event/transport/TakeableAction.py Vedi File

@@ -26,4 +26,4 @@ class TakeableAction(Action):
26 26
         obj.carry(obj_carried)
27 27
         cant_put_still = Core.get_configuration_manager().get('ant.take.cant_put_still')
28 28
         context.metas.value.set(CANT_PUT_STILL, obj.get_id(), cant_put_still)
29
-        obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj, obj_carried, context)
29
+        obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj_carried)