Browse Source

col/states manipulation in obj mecthod

Bastien Sevajol 9 years ago
parent
commit
ec9f3bf7a2

+ 0 - 9
intelligine/synergy/Simulation.py View File

@@ -1,18 +1,9 @@
1 1
 from synergine.synergy.Simulation import Simulation as BaseSimulation
2 2
 from synergine_xyz.cst import POSITIONS
3
-from intelligine.synergy.event.transport.PutableAction import PutableAction
4
-from intelligine.synergy.event.transport.TakeableAction import TakeableAction
5
-from intelligine.cst import COL_TRANSPORTER_CARRYING, COL_TRANSPORTER_NOT_CARRYING
6 3
 
7 4
 
8 5
 class Simulation(BaseSimulation):
9 6
 
10
-    def connect_actions_signals(self, Signals):
11
-        Signals.signal(PutableAction).connect(lambda obj, context: \
12
-            context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING))
13
-        Signals.signal(TakeableAction).connect(lambda obj, context: \
14
-            context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_CARRYING, COL_TRANSPORTER_NOT_CARRYING))
15
-
16 7
     def end_cycle(self, context):
17 8
         if context.get_cycle() % 100 is 0:
18 9
             context.metas.list.clean(POSITIONS)

+ 9 - 1
intelligine/synergy/object/BaseBug.py View File

@@ -1,6 +1,6 @@
1 1
 from intelligine.core.exceptions import BodyPartAlreadyExist
2 2
 from intelligine.synergy.object.Transportable import Transportable
3
-from intelligine.cst import ALIVE, ATTACKABLE, COL_ALIVE, COLONY
3
+from intelligine.cst import ALIVE, ATTACKABLE, COL_ALIVE, COLONY, CARRIED
4 4
 from intelligine.simulation.object.brain.Brain import Brain
5 5
 
6 6
 
@@ -18,6 +18,7 @@ class BaseBug(Transportable):
18 18
         self._brain = self._get_brain_instance()
19 19
         self._parts = {}
20 20
         self._init_parts()
21
+        self._is_carried = False
21 22
 
22 23
     def die(self):
23 24
         self._remove_state(ALIVE)
@@ -54,3 +55,10 @@ class BaseBug(Transportable):
54 55
 
55 56
     def get_brain(self):
56 57
         return self._brain
58
+
59
+    def set_is_carried(self, is_carried, by_obj):
60
+        self._is_carried = bool(is_carried)
61
+        if self._is_carried:
62
+            self._context.metas.value.set(CARRIED, subject=by_obj.get_id(), value=self.get_id())
63
+        else:
64
+            self._context.metas.value.unset(CARRIED, subject=by_obj.get_id())

+ 8 - 3
intelligine/synergy/object/ant/Ant.py View File

@@ -1,8 +1,8 @@
1 1
 from intelligine.core.exceptions import PheromoneException
2 2
 from intelligine.synergy.object.Bug import Bug
3 3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
4
-    COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, CARRIED, BODY_PART_PHEROMONE_GLAND, TYPE, TYPE_ANT, \
5
-    COL_TRANSPORTER_CARRYING
4
+    COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, BODY_PART_PHEROMONE_GLAND, TYPE, TYPE_ANT, \
5
+    COL_TRANSPORTER_CARRYING, MOVE_MODE_NURSE
6 6
 from intelligine.synergy.object.Food import Food
7 7
 from intelligine.simulation.object.pheromone.MovementPheromoneGland import MovementPheromoneGland
8 8
 from intelligine.simulation.object.brain.AntBrain import AntBrain
@@ -44,7 +44,10 @@ class Ant(Bug):
44 44
             position = self._get_position()
45 45
         self._carried = None
46 46
         obj.set_position(position)
47
+        obj.set_is_carried(False, self)
47 48
         self._context.metas.states.remove(self.get_id(), CARRYING)
49
+        self._add_col(COL_TRANSPORTER_NOT_CARRYING)
50
+        self._remove_col(COL_TRANSPORTER_CARRYING)
48 51
 
49 52
     def get_carried(self):
50 53
         return self._carried
@@ -52,7 +55,9 @@ class Ant(Bug):
52 55
     def carry(self, obj):
53 56
         self._carried = obj
54 57
         self._context.metas.states.add(self.get_id(), CARRYING)
55
-        self._context.metas.value.set(CARRIED, self.get_id(), obj.get_id())
58
+        self._add_col(COL_TRANSPORTER_CARRYING)
59
+        self._remove_col(COL_TRANSPORTER_NOT_CARRYING)
60
+        obj.set_is_carried(True, self)
56 61
         # TODO: pour le moment hardcode, a gerer dans AntTakeBrainPart (callback en fct de ce qui est depose)
57 62
         if isinstance(obj, Food):
58 63
             self.get_brain().switch_to_mode(MOVE_MODE_GOHOME)