Browse Source

Transportable class + return object tranported by transportable object

Bastien Sevajol 9 years ago
parent
commit
c30a33c2c1

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

@@ -23,8 +23,9 @@ class TakeableAction(Action):
23 23
         if obj_transportable.is_carried():
24 24
             raise ActionAborted()
25 25
         try:
26
-            obj_transportable.set_carried_by(obj)
27
-            obj.carry(obj_transportable)
26
+            obj_carried = obj_transportable.get_carry()
27
+            obj_carried.set_carried_by(obj)
28
+            obj.carry(obj_carried)
28 29
             context.metas.value.set(CANT_PUT_STILL, obj.get_id(), 5)
29 30
         except ValueError: # Une NotCarriableError serais pus approprie
30 31
             # TODO: tmp? Si on as pas pu le porter c'est qu'il vient d'etre porte par une autre.

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

@@ -1,15 +1,14 @@
1
-from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
-from intelligine.cst import ALIVE, ATTACKABLE, TRANSPORTABLE, COL_ALIVE
1
+from intelligine.synergy.object.Transportable import Transportable
2
+from intelligine.cst import ALIVE, ATTACKABLE, COL_ALIVE
3 3
 
4 4
 
5
-class BaseBug(XyzSynergyObject):
5
+class BaseBug(Transportable):
6 6
 
7 7
     def __init__(self, collection, context):
8 8
         super().__init__(collection, context)
9 9
         context.metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
10 10
         context.metas.collections.add(self.get_id(), COL_ALIVE)
11 11
         self._life_points = 10
12
-        self._carried_by = None
13 12
         self._movements_count = -1
14 13
 
15 14
     def hurted(self, points):
@@ -18,21 +17,6 @@ class BaseBug(XyzSynergyObject):
18 17
     def get_life_points(self):
19 18
         return self._life_points
20 19
 
21
-    def set_carried_by(self, obj):
22
-        if obj is not None:
23
-            assert self._carried_by is None
24
-            self._carried_by = obj
25
-            self._context.metas.states.remove(self.get_id(), TRANSPORTABLE)
26
-        else:
27
-            assert self._carried_by is not None
28
-            self._carried_by = None
29
-            self._context.metas.states.add(self.get_id(), TRANSPORTABLE)
30
-
31
-    def is_carried(self):
32
-        if self._carried_by:
33
-            return True
34
-        return False
35
-
36 20
     def set_position(self, point):
37 21
         super().set_position(point)
38 22
         self._movements_count += 1

+ 10 - 4
intelligine/synergy/object/Food.py View File

@@ -1,9 +1,15 @@
1
-from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
-from intelligine.cst import IMPENETRABLE
1
+from intelligine.synergy.object.Transportable import Transportable
2
+from intelligine.cst import IMPENETRABLE, TRANSPORTABLE
3 3
 
4 4
 
5
-class Food(XyzSynergyObject):
5
+class Food(Transportable):
6 6
 
7 7
     def __init__(self, collection, context):
8 8
         super().__init__(collection, context)
9
-        context.metas.states.add(self.get_id(), IMPENETRABLE)
9
+        context.metas.states.add(self.get_id(), IMPENETRABLE)
10
+        context.metas.states.add(self.get_id(), TRANSPORTABLE)
11
+
12
+    def get_carry(self):
13
+        clone = self.__class__(self._collection, self._context)
14
+        self._collection.add_object(clone)
15
+        return clone

+ 27 - 0
intelligine/synergy/object/Transportable.py View File

@@ -0,0 +1,27 @@
1
+from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
+from intelligine.cst import TRANSPORTABLE
3
+
4
+
5
+class Transportable(XyzSynergyObject):
6
+
7
+    def __init__(self, collection, context):
8
+        super().__init__(collection, context)
9
+        self._carried_by = None
10
+
11
+    def set_carried_by(self, obj):
12
+        if obj is not None:
13
+            assert self._carried_by is None
14
+            self._carried_by = obj
15
+            self._context.metas.states.remove(self.get_id(), TRANSPORTABLE)
16
+        else:
17
+            assert self._carried_by is not None
18
+            self._carried_by = None
19
+            self._context.metas.states.add(self.get_id(), TRANSPORTABLE)
20
+
21
+    def is_carried(self):
22
+        if self._carried_by:
23
+            return True
24
+        return False
25
+
26
+    def get_carry(self):
27
+        return self