Browse Source

use STATE shorcuts

Bastien Sevajol 9 years ago
parent
commit
7ce497d88b

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

@@ -1,13 +1,11 @@
1 1
 from synergine.synergy.event.Event import Event
2 2
 from intelligine.cst import CANT_CARRY_STILL, TRANSPORTER, ALIVE
3
-from intelligine.synergy.Simulation import Simulation
4 3
 
5 4
 
6 5
 class CycleEvent(Event):
7 6
 
8 7
     def concern(self, object_id, context):
9
-        return context.metas.list.have(Simulation.STATE, object_id, TRANSPORTER) and \
10
-               context.metas.list.have(Simulation.STATE, object_id, ALIVE)
8
+        return context.metas.states.have(object_id, [TRANSPORTER, ALIVE])
11 9
 
12 10
     def _object_match(self, object_id, context, parameters):
13 11
         return True

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

@@ -1,7 +1,6 @@
1 1
 from synergine.synergy.event.Action import Action
2 2
 from intelligine.synergy.event.attack.NearAttackableEvent import NearAttackableEvent
3 3
 from random import randint
4
-from intelligine.synergy.Simulation import Simulation
5 4
 from intelligine.cst import ALIVE, ATTACKABLE
6 5
 
7 6
 
@@ -22,7 +21,7 @@ class NearAttackableAction(Action):
22 21
             obj_attackable.hurted(randint(0, 2))
23 22
             if obj_attackable.get_life_points() <= 0:
24 23
                 try:
25
-                    context.metas.list.remove(Simulation.STATE, obj_id_attackable, ALIVE)
26
-                    context.metas.list.remove(Simulation.STATE, obj_id_attackable, ATTACKABLE)
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])
27 26
                 except ValueError:  # Ant maybed killed by other ant at same turn
28 27
                     pass

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

@@ -1,14 +1,12 @@
1 1
 from synergine.synergy.event.Event import Event
2 2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
-from synergine.synergy.Simulation import Simulation
4 3
 from intelligine.cst import ATTACKER, ATTACKABLE, COLONY, ALIVE
5 4
 
6 5
 
7 6
 class NearAttackableEvent(Event):
8 7
 
9 8
     def concern(self, object_id, context):
10
-        return context.metas.list.have(Simulation.STATE, object_id, ATTACKER) and \
11
-               context.metas.list.have(Simulation.STATE, object_id, ALIVE)
9
+        return context.metas.states.have(object_id, [ATTACKER, ALIVE])
12 10
 
13 11
     def __init__(self, actions):
14 12
         super().__init__(actions)
@@ -18,7 +16,7 @@ class NearAttackableEvent(Event):
18 16
         # TODO: nettoyer
19 17
         obj_colony_id = context.metas.value.get(COLONY, object_id)
20 18
         for obj_near_id in parameters['objects_ids_near']:
21
-            if context.metas.list.have(Simulation.STATE, obj_near_id, ATTACKABLE):
19
+            if context.metas.states.have(obj_near_id, [ATTACKABLE]):
22 20
                 if obj_colony_id != context.metas.value.get(COLONY, obj_near_id):
23 21
                     if 'objects_ids_attackable' not in parameters:
24 22
                         parameters['objects_ids_attackable'] = []

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

@@ -3,7 +3,6 @@ from intelligine.synergy.event.move.MoveEvent import MoveEvent
3 3
 from random import randint, choice
4 4
 from xyzworld.cst import POSITION, POSITIONS
5 5
 from intelligine.cst import IMPENETRABLE, PREVIOUS_DIRECTION, BLOCKED_SINCE
6
-from synergine.synergy.Simulation import Simulation
7 6
 from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
8 7
 
9 8
 
@@ -54,7 +53,7 @@ class MoveAction(Action):
54 53
     def _direction_point_is_possible(self, context, direction_point):
55 54
         objects_ids_on_this_point = context.metas.list.get(POSITIONS, direction_point, allow_empty=True)
56 55
         for object_id_on_this_point in objects_ids_on_this_point:
57
-          if context.metas.list.have(Simulation.STATE, object_id_on_this_point, IMPENETRABLE):
56
+          if context.metas.states.have(object_id_on_this_point, [IMPENETRABLE]):
58 57
             return False
59 58
         return True
60 59
 

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

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

+ 2 - 5
intelligine/synergy/event/transport/PutableEvent.py View File

@@ -1,13 +1,10 @@
1 1
 from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
2 2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
-from intelligine.synergy.Simulation import Simulation
4 3
 from intelligine.cst import TRANSPORTER, ALIVE, CARRYING, CANT_PUT_STILL
5 4
 
6 5
 
7 6
 class PutableEvent(TakeableEvent):
8 7
 
9 8
     def concern(self, object_id, context):
10
-        return context.metas.list.have(Simulation.STATE, object_id, TRANSPORTER) and \
11
-               context.metas.list.have(Simulation.STATE, object_id, ALIVE) and \
12
-               context.metas.list.have(Simulation.STATE, object_id, CARRYING) and \
13
-               not context.metas.value.get(CANT_PUT_STILL, object_id, allow_empty=True)
9
+        return context.metas.states.have(object_id, [TRANSPORTER, ALIVE, CARRYING]) \
10
+               and not context.metas.value.get(CANT_PUT_STILL, object_id, allow_empty=True)

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

@@ -1,16 +1,14 @@
1 1
 from synergine.synergy.event.Event import Event
2 2
 from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
3
-from intelligine.synergy.Simulation import Simulation
4 3
 from intelligine.cst import TRANSPORTABLE, TRANSPORTER, ALIVE, CARRYING, CANT_CARRY_STILL
5 4
 
6 5
 
7 6
 class TakeableEvent(Event):
8 7
 
9 8
     def concern(self, object_id, context):
10
-        return context.metas.list.have(Simulation.STATE, object_id, TRANSPORTER) and \
11
-               context.metas.list.have(Simulation.STATE, object_id, ALIVE) and \
12
-               not context.metas.list.have(Simulation.STATE, object_id, CARRYING) and \
13
-               not context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True)
9
+        return context.metas.states.have(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)
14 12
 
15 13
     def __init__(self, actions):
16 14
         super().__init__(actions)
@@ -19,7 +17,7 @@ class TakeableEvent(Event):
19 17
     def _object_match(self, object_id, context, parameters={}):
20 18
         # TODO: Nettoyer (refact possible sur ces objets ont tel states, comme dans concern)
21 19
         for obj_near_id in parameters['objects_ids_near']:
22
-            if context.metas.list.have(Simulation.STATE, obj_near_id, TRANSPORTABLE):
20
+            if context.metas.states.have(obj_near_id, [TRANSPORTABLE]):
23 21
                 if 'objects_ids_transportable' not in parameters:
24 22
                     parameters['objects_ids_transportable'] = []
25 23
                 parameters['objects_ids_transportable'].append(obj_near_id)

+ 3 - 5
intelligine/synergy/object/BaseBug.py View File

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

+ 1 - 2
intelligine/synergy/object/Bug.py View File

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

+ 1 - 2
intelligine/synergy/object/Egg.py View File

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

+ 1 - 2
intelligine/synergy/object/Rock.py View File

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

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

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