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
 from synergine.synergy.Simulation import Simulation as BaseSimulation
1
 from synergine.synergy.Simulation import Simulation as BaseSimulation
2
 from synergine_xyz.cst import POSITIONS
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
 class Simulation(BaseSimulation):
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
     def end_cycle(self, context):
7
     def end_cycle(self, context):
17
         if context.get_cycle() % 100 is 0:
8
         if context.get_cycle() % 100 is 0:
18
             context.metas.list.clean(POSITIONS)
9
             context.metas.list.clean(POSITIONS)

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

1
 from intelligine.core.exceptions import BodyPartAlreadyExist
1
 from intelligine.core.exceptions import BodyPartAlreadyExist
2
 from intelligine.synergy.object.Transportable import Transportable
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
 from intelligine.simulation.object.brain.Brain import Brain
4
 from intelligine.simulation.object.brain.Brain import Brain
5
 
5
 
6
 
6
 
18
         self._brain = self._get_brain_instance()
18
         self._brain = self._get_brain_instance()
19
         self._parts = {}
19
         self._parts = {}
20
         self._init_parts()
20
         self._init_parts()
21
+        self._is_carried = False
21
 
22
 
22
     def die(self):
23
     def die(self):
23
         self._remove_state(ALIVE)
24
         self._remove_state(ALIVE)
54
 
55
 
55
     def get_brain(self):
56
     def get_brain(self):
56
         return self._brain
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
 from intelligine.core.exceptions import PheromoneException
1
 from intelligine.core.exceptions import PheromoneException
2
 from intelligine.synergy.object.Bug import Bug
2
 from intelligine.synergy.object.Bug import Bug
3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
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
 from intelligine.synergy.object.Food import Food
6
 from intelligine.synergy.object.Food import Food
7
 from intelligine.simulation.object.pheromone.MovementPheromoneGland import MovementPheromoneGland
7
 from intelligine.simulation.object.pheromone.MovementPheromoneGland import MovementPheromoneGland
8
 from intelligine.simulation.object.brain.AntBrain import AntBrain
8
 from intelligine.simulation.object.brain.AntBrain import AntBrain
44
             position = self._get_position()
44
             position = self._get_position()
45
         self._carried = None
45
         self._carried = None
46
         obj.set_position(position)
46
         obj.set_position(position)
47
+        obj.set_is_carried(False, self)
47
         self._context.metas.states.remove(self.get_id(), CARRYING)
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
     def get_carried(self):
52
     def get_carried(self):
50
         return self._carried
53
         return self._carried
52
     def carry(self, obj):
55
     def carry(self, obj):
53
         self._carried = obj
56
         self._carried = obj
54
         self._context.metas.states.add(self.get_id(), CARRYING)
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
         # TODO: pour le moment hardcode, a gerer dans AntTakeBrainPart (callback en fct de ce qui est depose)
61
         # TODO: pour le moment hardcode, a gerer dans AntTakeBrainPart (callback en fct de ce qui est depose)
57
         if isinstance(obj, Food):
62
         if isinstance(obj, Food):
58
             self.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
63
             self.get_brain().switch_to_mode(MOVE_MODE_GOHOME)