Browse Source

COL system compatibility

Bastien Sevajol 9 years ago
parent
commit
5c3ff17601

+ 8 - 1
intelligine/cst.py View File

12
 TRANSPORTER = IncrementedNamedInt.get('intelligine.transporter')
12
 TRANSPORTER = IncrementedNamedInt.get('intelligine.transporter')
13
 CARRYING = IncrementedNamedInt.get('intelligine.carrying')
13
 CARRYING = IncrementedNamedInt.get('intelligine.carrying')
14
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
14
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
15
-CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
15
+CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
16
+ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
17
+
18
+COL_ALIVE = IncrementedNamedInt.get('intelligine.col.alive')
19
+COL_WALKER = IncrementedNamedInt.get('intelligine.col.walker')
20
+COL_FIGHTER = IncrementedNamedInt.get('intelligine.col.walker')
21
+COL_TRANSPORTER_CARRYING = IncrementedNamedInt.get('intelligine.col.transporter_carrying')
22
+COL_TRANSPORTER_NOT_CARRYING = IncrementedNamedInt.get('intelligine.col.transporter_not_carrying')

+ 10 - 9
intelligine/display/pygame/visualisation.py View File

8
 from intelligine.synergy.object.Rock import Rock
8
 from intelligine.synergy.object.Rock import Rock
9
 from intelligine.synergy.object.ant.Egg import Egg
9
 from intelligine.synergy.object.ant.Egg import Egg
10
 from os import getcwd
10
 from os import getcwd
11
-from synergine.metas import metas
12
 from intelligine.cst import PREVIOUS_DIRECTION
11
 from intelligine.cst import PREVIOUS_DIRECTION
13
 
12
 
14
 # TODO: Analyser les procedes ici pour proposer des outils dans le framework
13
 # TODO: Analyser les procedes ici pour proposer des outils dans le framework
30
 directions_blue_ant = DirectionnedImage(blue_ant)
29
 directions_blue_ant = DirectionnedImage(blue_ant)
31
 directions_green_ant = DirectionnedImage(green_ant)
30
 directions_green_ant = DirectionnedImage(green_ant)
32
 
31
 
33
-def bug_direction(bug):
32
+# TODO: context donne au callbacks
33
+
34
+def bug_direction(bug, context):
34
     if bug.get_life_points() <= 0:
35
     if bug.get_life_points() <= 0:
35
         return dead_ant
36
         return dead_ant
36
     try:
37
     try:
37
-        previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
38
+        previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
38
     except KeyError:
39
     except KeyError:
39
         previous_direction = 14
40
         previous_direction = 14
40
     return directions_ant.get_for_direction(previous_direction)
41
     return directions_ant.get_for_direction(previous_direction)
41
 
42
 
42
-def red_ant_direction(bug):
43
+def red_ant_direction(bug, context):
43
     if bug.get_life_points() <= 0:
44
     if bug.get_life_points() <= 0:
44
         return dead_red_ant
45
         return dead_red_ant
45
     try:
46
     try:
46
-        previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
47
+        previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
47
     except KeyError:
48
     except KeyError:
48
         previous_direction = 14
49
         previous_direction = 14
49
     return directions_red_ant.get_for_direction(previous_direction)
50
     return directions_red_ant.get_for_direction(previous_direction)
50
 
51
 
51
-def blue_ant_direction(bug):
52
+def blue_ant_direction(bug, context):
52
     if bug.get_life_points() <= 0:
53
     if bug.get_life_points() <= 0:
53
         return dead_blue_ant
54
         return dead_blue_ant
54
     try:
55
     try:
55
-        previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
56
+        previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
56
     except KeyError:
57
     except KeyError:
57
         previous_direction = 14
58
         previous_direction = 14
58
     return directions_blue_ant.get_for_direction(previous_direction)
59
     return directions_blue_ant.get_for_direction(previous_direction)
59
 
60
 
60
-def green_ant_direction(bug):
61
+def green_ant_direction(bug, context):
61
     if bug.get_life_points() <= 0:
62
     if bug.get_life_points() <= 0:
62
         return dead_green_ant
63
         return dead_green_ant
63
     try:
64
     try:
64
-        previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
65
+        previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
65
     except KeyError:
66
     except KeyError:
66
         previous_direction = 14
67
         previous_direction = 14
67
     return directions_green_ant.get_for_direction(previous_direction)
68
     return directions_green_ant.get_for_direction(previous_direction)

+ 4 - 5
intelligine/sandbox/colored/RedColonyConfiguration.py View File

1
 from intelligine.synergy.ColonyConfiguration import ColonyConfiguration
1
 from intelligine.synergy.ColonyConfiguration import ColonyConfiguration
2
 from intelligine.sandbox.colored.RedAnt import RedAnt
2
 from intelligine.sandbox.colored.RedAnt import RedAnt
3
 from intelligine.synergy.object.ant.Egg import Egg
3
 from intelligine.synergy.object.ant.Egg import Egg
4
-from synergine.metas import metas
5
 from intelligine.cst import COLONY
4
 from intelligine.cst import COLONY
6
 
5
 
7
 
6
 
10
     _start_position = (0, 20, 70)
9
     _start_position = (0, 20, 70)
11
     _ant_class = RedAnt
10
     _ant_class = RedAnt
12
 
11
 
13
-    def get_start_objects(self, collection):
14
-        objects = super().get_start_objects(collection)
12
+    def get_start_objects(self, collection, context):
13
+        objects = super().get_start_objects(collection, context)
15
 
14
 
16
         for x in range(50):
15
         for x in range(50):
17
           for y in range(1, 50):
16
           for y in range(1, 50):
18
             if x % 3 == 0 and y % 3 == 0:
17
             if x % 3 == 0 and y % 3 == 0:
19
-              egg = Egg()
18
+              egg = Egg(context)
20
               egg.set_position((0, 1+x, 50+y))
19
               egg.set_position((0, 1+x, 50+y))
21
               # TODO: Ce COLONY doit devenir un truc automatise au niveau de la collection (qd get_object)
20
               # TODO: Ce COLONY doit devenir un truc automatise au niveau de la collection (qd get_object)
22
-              metas.value.set(COLONY, egg.get_id(), collection.get_id())
21
+              context.metas.value.set(COLONY, egg.get_id(), collection.get_id())
23
               objects.append(egg)
22
               objects.append(egg)
24
 
23
 
25
         return objects
24
         return objects

+ 3 - 4
intelligine/synergy/ColonyConfiguration.py View File

1
 from synergine.synergy.collection.Configuration import Configuration
1
 from synergine.synergy.collection.Configuration import Configuration
2
 from intelligine.synergy.object.ant.Ant import Ant
2
 from intelligine.synergy.object.ant.Ant import Ant
3
-from synergine.metas import metas
4
 from intelligine.cst import ALIVE, COLONY
3
 from intelligine.cst import ALIVE, COLONY
5
 
4
 
6
 
5
 
9
     _start_position = (0, 20, 20)
8
     _start_position = (0, 20, 20)
10
     _ant_class = Ant
9
     _ant_class = Ant
11
 
10
 
12
-    def get_start_objects(self, collection):
11
+    def get_start_objects(self, collection, context):
13
 
12
 
14
       ants = []
13
       ants = []
15
       for i in range(20):
14
       for i in range(20):
16
-          ant = self._ant_class()
17
-          metas.value.set(COLONY, ant.get_id(), collection.get_id())
15
+          ant = self._ant_class(context)
16
+          context.metas.value.set(COLONY, ant.get_id(), collection.get_id())
18
           ant.set_position(self._start_position)
17
           ant.set_position(self._start_position)
19
           ants.append(ant)
18
           ants.append(ant)
20
 
19
 

+ 2 - 2
intelligine/synergy/RocksConfiguration.py View File

4
 
4
 
5
 class RocksConfiguration(Configuration):
5
 class RocksConfiguration(Configuration):
6
 
6
 
7
-    def get_start_objects(self, collection):
7
+    def get_start_objects(self, collection, context):
8
 
8
 
9
       rocks = []
9
       rocks = []
10
       rocks_positions = []
10
       rocks_positions = []
29
       rocks_positions.append((0, 100, 100))
29
       rocks_positions.append((0, 100, 100))
30
 
30
 
31
       for rock_position in rocks_positions:
31
       for rock_position in rocks_positions:
32
-          rock = Rock()
32
+          rock = Rock(context)
33
           rock.set_position(rock_position)
33
           rock.set_position(rock_position)
34
           rocks.append(rock)
34
           rocks.append(rock)
35
 
35
 

+ 23 - 0
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 xyzworld.cst import POSITION, POSITIONS
2
 from xyzworld.cst import POSITION, POSITIONS
3
+#from intelligine.synergy.event.attack.NearAttackableAction import NearAttackableAction
4
+from intelligine.synergy.event.transport.PutableAction import PutableAction
5
+from intelligine.synergy.event.transport.TakeableAction import TakeableAction
6
+from intelligine.synergy.event.move.MoveAction import MoveAction
7
+from intelligine.synergy.event.CycleAction import CycleAction
8
+from intelligine.cst import COL_TRANSPORTER_CARRYING, COL_TRANSPORTER_NOT_CARRYING, \
9
+    COL_WALKER, ACTION_DIE, COL_ALIVE
3
 
10
 
11
+# TODO: Mettre ailleurs ?
12
+def bug_die(bug, context):
13
+    context.metas.collections.remove_list(bug.get_id(),
14
+                                          [COL_TRANSPORTER_CARRYING, \
15
+                                           COL_TRANSPORTER_NOT_CARRYING, \
16
+                                           COL_WALKER, \
17
+                                           COL_ALIVE],
18
+                                          allow_not_in=True)
19
+    context.metas.states.remove_list(bug.get_id(), [ALIVE, ATTACKABLE])
4
 
20
 
5
 class Simulation(BaseSimulation):
21
 class Simulation(BaseSimulation):
6
 
22
 
23
+    def connect_actions_signals(self, Signals):
24
+        Signals.signal(PutableAction).connect(lambda obj, context: \
25
+            context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING))
26
+        Signals.signal(TakeableAction).connect(lambda obj, context: \
27
+            context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_CARRYING, COL_TRANSPORTER_NOT_CARRYING))
28
+        Signals.signal(ACTION_DIE).connect(lambda obj, context: bug_die(obj, context))
29
+
7
     def end_cycle(self, context):
30
     def end_cycle(self, context):
8
         if context.get_cycle() % 100 is 0:
31
         if context.get_cycle() % 100 is 0:
9
             context.metas.list.clean(POSITIONS)
32
             context.metas.list.clean(POSITIONS)

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

1
 from synergine.synergy.event.Event import Event
1
 from synergine.synergy.event.Event import Event
2
-from intelligine.cst import CANT_CARRY_STILL, TRANSPORTER, ALIVE
2
+from intelligine.cst import COL_ALIVE # TODO: Crer une col TRANPORTER ?
3
 
3
 
4
 
4
 
5
 class CycleEvent(Event):
5
 class CycleEvent(Event):
6
 
6
 
7
-    def concern(self, object_id, context):
8
-        return context.metas.states.have_list(object_id, [TRANSPORTER, ALIVE])
7
+    concern = COL_ALIVE
9
 
8
 
10
     def _object_match(self, object_id, context, parameters):
9
     def _object_match(self, object_id, context, parameters):
11
         return True
10
         return True

+ 4 - 7
intelligine/synergy/event/attack/NearAttackableAction.py View File

1
 from synergine.synergy.event.Action import Action
1
 from synergine.synergy.event.Action import Action
2
 from intelligine.synergy.event.attack.NearAttackableEvent import NearAttackableEvent
2
 from intelligine.synergy.event.attack.NearAttackableEvent import NearAttackableEvent
3
 from random import randint
3
 from random import randint
4
-from intelligine.cst import ALIVE, ATTACKABLE
4
+from intelligine.cst import ALIVE, ATTACKABLE, ACTION_DIE
5
+from synergine.core.Signals import Signals
5
 
6
 
6
 
7
 
7
 class NearAttackableAction(Action):
8
 class NearAttackableAction(Action):
15
         pass
16
         pass
16
 
17
 
17
     def run(self, obj, collection, context, synergy_manager):
18
     def run(self, obj, collection, context, synergy_manager):
18
-        # TODO: TEST
19
+        # TODO: reprendre ?
19
         for obj_id_attackable in self._parameters['objects_ids_attackable']:
20
         for obj_id_attackable in self._parameters['objects_ids_attackable']:
20
             obj_attackable = synergy_manager.get_map().get_object(obj_id_attackable)
21
             obj_attackable = synergy_manager.get_map().get_object(obj_id_attackable)
21
             obj_attackable.hurted(randint(0, 2))
22
             obj_attackable.hurted(randint(0, 2))
22
             if obj_attackable.get_life_points() <= 0:
23
             if obj_attackable.get_life_points() <= 0:
23
-                try:
24
-                    # TODO: Doit etre dans l'objet, lui sais cz qu'il perd comme etat
25
-                    context.metas.states.remove_list(obj_id_attackable, [ALIVE, ATTACKABLE])
26
-                except ValueError:  # Ant maybed killed by other ant at same turn
27
-                    pass
24
+                Signals.signal(ACTION_DIE).send(obj=obj_attackable, context=context)

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

1
 from synergine.synergy.event.Event import Event
1
 from synergine.synergy.event.Event import Event
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
-from intelligine.cst import ATTACKER, ATTACKABLE, COLONY, ALIVE
3
+from intelligine.cst import ATTACKABLE, COLONY, COL_FIGHTER
4
 
4
 
5
 
5
 
6
 class NearAttackableEvent(Event):
6
 class NearAttackableEvent(Event):
7
 
7
 
8
-    def concern(self, object_id, context):
9
-        return context.metas.states.have_list(object_id, [ATTACKER, ALIVE])
8
+    concern = COL_FIGHTER
10
 
9
 
11
     def __init__(self, actions):
10
     def __init__(self, actions):
12
         super().__init__(actions)
11
         super().__init__(actions)

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

1
 from synergine.synergy.event.Event import Event
1
 from synergine.synergy.event.Event import Event
2
 from synergine.core.simulation.mechanism.Mechanism import Mechanism
2
 from synergine.core.simulation.mechanism.Mechanism import Mechanism
3
-from intelligine.cst import ALIVE, WALKER
3
+from intelligine.cst import COL_WALKER
4
 
4
 
5
 
5
 
6
 class MoveEvent(Event):
6
 class MoveEvent(Event):
7
 
7
 
8
-    def concern(self, object_id, context):
9
-        return context.metas.states.have_list(object_id, [ALIVE, WALKER])
8
+    concern = COL_WALKER
10
 
9
 
11
     def __init__(self, actions):
10
     def __init__(self, actions):
12
         super().__init__(actions)
11
         super().__init__(actions)

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

1
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
1
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
-from intelligine.cst import TRANSPORTER, ALIVE, CARRYING, CANT_PUT_STILL
3
+from intelligine.cst import CANT_PUT_STILL, COL_TRANSPORTER_CARRYING
4
 
4
 
5
 
5
 
6
 class PutableEvent(TakeableEvent):
6
 class PutableEvent(TakeableEvent):
7
 
7
 
8
-    def concern(self, object_id, context):
9
-        return context.metas.states.have_list(object_id, [TRANSPORTER, ALIVE, CARRYING]) \
10
-               and not context.metas.value.get(CANT_PUT_STILL, object_id, allow_empty=True)
8
+    concern = COL_TRANSPORTER_CARRYING
9
+
10
+    def _object_match(self, object_id, context, parameters={}):
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)

+ 10 - 8
intelligine/synergy/event/transport/TakeableAction.py View File

1
 from synergine.synergy.event.Action import Action
1
 from synergine.synergy.event.Action import Action
2
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
2
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
3
 from intelligine.cst import CANT_PUT_STILL
3
 from intelligine.cst import CANT_PUT_STILL
4
+from synergine.synergy.event.exception.ActionAborted import ActionAborted
4
 
5
 
5
 
6
 
6
 class TakeableAction(Action):
7
 class TakeableAction(Action):
19
         # ?! Comment gerer lorsque deux obj vont vouloir transporter le meme objet ? process !
20
         # ?! Comment gerer lorsque deux obj vont vouloir transporter le meme objet ? process !
20
         obj_id_transportable = self._parameters['objects_ids_transportable'][0]
21
         obj_id_transportable = self._parameters['objects_ids_transportable'][0]
21
         obj_transportable = synergy_manager.get_map().get_object(obj_id_transportable)
22
         obj_transportable = synergy_manager.get_map().get_object(obj_id_transportable)
22
-        if not obj_transportable.is_carried():
23
-            try:
24
-                obj_transportable.set_carried_by(obj)
25
-                obj.carry(obj_transportable)
26
-                context.metas.value.set(CANT_PUT_STILL, obj.get_id(), 5)
27
-            except ValueError: # Une NotCarriableError serais pus approprie
28
-                # TODO: tmp? Si on as pas pu le porter c'est qu'il vient d'etre porte par une autre.
29
-                pass
23
+        if obj_transportable.is_carried():
24
+            raise ActionAborted()
25
+        try:
26
+            obj_transportable.set_carried_by(obj)
27
+            obj.carry(obj_transportable)
28
+            context.metas.value.set(CANT_PUT_STILL, obj.get_id(), 5)
29
+        except ValueError: # Une NotCarriableError serais pus approprie
30
+            # TODO: tmp? Si on as pas pu le porter c'est qu'il vient d'etre porte par une autre.
31
+            pass

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

1
 from synergine.synergy.event.Event import Event
1
 from synergine.synergy.event.Event import Event
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
-from intelligine.cst import TRANSPORTABLE, TRANSPORTER, ALIVE, CARRYING, CANT_CARRY_STILL
3
+from intelligine.cst import TRANSPORTABLE, CANT_CARRY_STILL, COL_TRANSPORTER_NOT_CARRYING
4
 
4
 
5
 
5
 
6
 class TakeableEvent(Event):
6
 class TakeableEvent(Event):
7
 
7
 
8
-    def concern(self, object_id, context):
9
-        return context.metas.states.have_list(object_id, [TRANSPORTER, ALIVE]) and \
10
-               context.metas.states.dont_have(object_id, CARRYING) and not \
11
-               context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True) # TODO: si COLS: ca plus dans concern mais dans object_match
8
+    concern = COL_TRANSPORTER_NOT_CARRYING
12
 
9
 
13
     def __init__(self, actions):
10
     def __init__(self, actions):
14
         super().__init__(actions)
11
         super().__init__(actions)
15
         self._mechanism = ArroundMechanism
12
         self._mechanism = ArroundMechanism
16
 
13
 
17
     def _object_match(self, object_id, context, parameters={}):
14
     def _object_match(self, object_id, context, parameters={}):
15
+        if context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True):
16
+            return False
18
         # TODO: Nettoyer (refact possible sur ces objets ont tel states, comme dans concern)
17
         # TODO: Nettoyer (refact possible sur ces objets ont tel states, comme dans concern)
19
         for obj_near_id in parameters['objects_ids_near']:
18
         for obj_near_id in parameters['objects_ids_near']:
20
             if context.metas.states.have(obj_near_id, TRANSPORTABLE):
19
             if context.metas.states.have(obj_near_id, TRANSPORTABLE):

+ 7 - 7
intelligine/synergy/object/BaseBug.py View File

1
 from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
1
 from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
-from synergine.metas import metas
3
-from intelligine.cst import ALIVE, ATTACKABLE, TRANSPORTABLE
2
+from intelligine.cst import ALIVE, ATTACKABLE, TRANSPORTABLE, COL_ALIVE
4
 
3
 
5
 
4
 
6
 class BaseBug(XyzSynergyObject):
5
 class BaseBug(XyzSynergyObject):
7
 
6
 
8
-    def __init__(self):
9
-        super().__init__()
10
-        metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
7
+    def __init__(self, context):
8
+        super().__init__(context)
9
+        context.metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
10
+        context.metas.collections.add(self.get_id(), COL_ALIVE)
11
         self._life_points = 10
11
         self._life_points = 10
12
         self._carried_by = None
12
         self._carried_by = None
13
 
13
 
21
         if obj is not None:
21
         if obj is not None:
22
             assert self._carried_by is None
22
             assert self._carried_by is None
23
             self._carried_by = obj
23
             self._carried_by = obj
24
-            metas.states.remove(self.get_id(), TRANSPORTABLE)
24
+            self._context.metas.states.remove(self.get_id(), TRANSPORTABLE)
25
         else:
25
         else:
26
             assert self._carried_by is not None
26
             assert self._carried_by is not None
27
             self._carried_by = None
27
             self._carried_by = None
28
-            metas.states.add(self.get_id(), TRANSPORTABLE)
28
+            self._context.metas.states.add(self.get_id(), TRANSPORTABLE)
29
 
29
 
30
     def is_carried(self):
30
     def is_carried(self):
31
         if self._carried_by:
31
         if self._carried_by:

+ 5 - 5
intelligine/synergy/object/Bug.py View File

1
 from intelligine.synergy.object.BaseBug import BaseBug
1
 from intelligine.synergy.object.BaseBug import BaseBug
2
-from synergine.metas import metas
3
-from intelligine.cst import WALKER
2
+from intelligine.cst import WALKER, COL_WALKER
4
 
3
 
5
 
4
 
6
 class Bug(BaseBug):
5
 class Bug(BaseBug):
7
 
6
 
8
-    def __init__(self):
9
-        super().__init__()
10
-        metas.states.add(self.get_id(), WALKER)
7
+    def __init__(self, context):
8
+        super().__init__(context)
9
+        context.metas.states.add(self.get_id(), WALKER)
10
+        context.metas.collections.add(self.get_id(), COL_WALKER)

+ 4 - 5
intelligine/synergy/object/Egg.py View File

1
 from intelligine.synergy.object.BaseBug import BaseBug
1
 from intelligine.synergy.object.BaseBug import BaseBug
2
-from synergine.metas import metas
3
-from intelligine.cst import ALIVE, TRANSPORTABLE
2
+from intelligine.cst import TRANSPORTABLE
4
 
3
 
5
 
4
 
6
 class Egg(BaseBug):
5
 class Egg(BaseBug):
7
 
6
 
8
-    def __init__(self):
9
-        super().__init__()
10
-        metas.states.add(self.get_id(), TRANSPORTABLE)
7
+    def __init__(self, context):
8
+        super().__init__(context)
9
+        context.metas.states.add(self.get_id(), TRANSPORTABLE)
11
         self._life_points = 1
10
         self._life_points = 1

+ 3 - 4
intelligine/synergy/object/Rock.py View File

1
 from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
1
 from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
-from synergine.metas import metas
3
 from intelligine.cst import IMPENETRABLE
2
 from intelligine.cst import IMPENETRABLE
4
 
3
 
5
 
4
 
6
 class Rock(XyzSynergyObject):
5
 class Rock(XyzSynergyObject):
7
 
6
 
8
-    def __init__(self):
9
-        super().__init__()
10
-        metas.states.add(self.get_id(), IMPENETRABLE)
7
+    def __init__(self, context):
8
+        super().__init__(context)
9
+        context.metas.states.add(self.get_id(), IMPENETRABLE)

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

1
 from intelligine.synergy.object.Bug import Bug
1
 from intelligine.synergy.object.Bug import Bug
2
-from synergine.metas import metas
3
-from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER
2
+from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
3
+    COL_TRANSPORTER_NOT_CARRYING, COL_FIGHTER
4
 
4
 
5
 
5
 
6
 class Ant(Bug):
6
 class Ant(Bug):
7
 
7
 
8
-    def __init__(self):
9
-        super().__init__()
10
-        metas.states.add_list(self.get_id(), [TRANSPORTER, ATTACKER])
8
+    def __init__(self, context):
9
+        super().__init__(context)
10
+        context.metas.states.add_list(self.get_id(), [TRANSPORTER, ATTACKER])
11
+        context.metas.collections.add_list(self.get_id(), [COL_TRANSPORTER_NOT_CARRYING, COL_FIGHTER])
11
         self._carried = []
12
         self._carried = []
12
 
13
 
13
     def put_carry(self, obj):
14
     def put_carry(self, obj):
14
         self._carried.remove(obj)
15
         self._carried.remove(obj)
15
         obj.set_position(self.get_position())
16
         obj.set_position(self.get_position())
16
-        metas.states.remove(self.get_id(), CARRYING)
17
+        self._context.metas.states.remove(self.get_id(), CARRYING)
17
 
18
 
18
     def get_carried(self):
19
     def get_carried(self):
19
         # TODO: cas ou plusieurs ?
20
         # TODO: cas ou plusieurs ?
21
 
22
 
22
     def carry(self, obj):
23
     def carry(self, obj):
23
         self._carried.append(obj)
24
         self._carried.append(obj)
24
-        metas.states.add(self.get_id(), CARRYING)
25
+        self._context.metas.states.add(self.get_id(), CARRYING)
25
 
26
 
26
     def is_carrying(self):
27
     def is_carrying(self):
27
         if len(self._carried):
28
         if len(self._carried):