Quellcode durchsuchen

Transformed food from food object

Bastien Sevajol vor 9 Jahren
Ursprung
Commit
19f6f7a484

+ 7 - 2
intelligine/display/pygame/config.py Datei anzeigen

@@ -1,13 +1,15 @@
1 1
 from intelligine.synergy.Colony import Colony
2 2
 from intelligine.synergy.Environment import Environment
3 3
 from intelligine.synergy.Simulation import Simulation
4
-from intelligine.synergy.object.StockedFood import StockedFood
5 4
 from intelligine.synergy.object.Food import Food
6 5
 from intelligine.synergy.object.Rock import Rock
7 6
 from intelligine.synergy.object.ant.Ant import Ant
8 7
 from intelligine.synergy.object.ant.Egg import Egg
9 8
 
10 9
 
10
+def stocked_food(food):
11
+    food.transform_to_stocked()
12
+
11 13
 map_config = {
12 14
     'simulation': {
13 15
         'base': Simulation
@@ -21,6 +23,9 @@ map_config = {
21 23
         'egg': Egg,
22 24
         'rock': Rock,
23 25
         'food': Food,
24
-        'stocked_food': StockedFood
26
+        'stocked_food': Food
27
+    },
28
+    'callbacks': {
29
+        'stocked_food': [stocked_food]
25 30
     }
26 31
 }

+ 19 - 14
intelligine/sandbox/exploration/map.tmx Datei anzeigen

@@ -180,30 +180,35 @@
180 180
   </tile>
181 181
   <tile id="2">
182 182
    <properties>
183
+    <property name="callbacks" value="stocked_food"/>
183 184
     <property name="object" value="stocked_food"/>
184 185
    </properties>
185 186
   </tile>
186 187
   <tile id="3">
187 188
    <properties>
188 189
     <property name="actions" value="clone(),"/>
190
+    <property name="callbacks" value="stocked_food"/>
189 191
     <property name="object" value="stocked_food"/>
190 192
    </properties>
191 193
   </tile>
192 194
   <tile id="4">
193 195
    <properties>
194 196
     <property name="actions" value="clone(2),"/>
197
+    <property name="callbacks" value="stocked_food"/>
195 198
     <property name="object" value="stocked_food"/>
196 199
    </properties>
197 200
   </tile>
198 201
   <tile id="5">
199 202
    <properties>
200 203
     <property name="actions" value="clone(3),"/>
204
+    <property name="callbacks" value="stocked_food"/>
201 205
     <property name="object" value="stocked_food"/>
202 206
    </properties>
203 207
   </tile>
204 208
   <tile id="6">
205 209
    <properties>
206 210
     <property name="actions" value="clone(4),"/>
211
+    <property name="callbacks" value="stocked_food"/>
207 212
     <property name="object" value="stocked_food"/>
208 213
    </properties>
209 214
   </tile>
@@ -2331,7 +2336,7 @@
2331 2336
    <tile gid="241"/>
2332 2337
    <tile gid="241"/>
2333 2338
    <tile gid="241"/>
2334
-   <tile gid="1"/>
2339
+   <tile gid="0"/>
2335 2340
    <tile gid="241"/>
2336 2341
    <tile gid="241"/>
2337 2342
    <tile gid="241"/>
@@ -2428,10 +2433,10 @@
2428 2433
    <tile gid="241"/>
2429 2434
    <tile gid="241"/>
2430 2435
    <tile gid="241"/>
2431
-   <tile gid="1"/>
2432
-   <tile gid="1"/>
2433
-   <tile gid="1"/>
2434
-   <tile gid="1"/>
2436
+   <tile gid="0"/>
2437
+   <tile gid="0"/>
2438
+   <tile gid="0"/>
2439
+   <tile gid="0"/>
2435 2440
    <tile gid="241"/>
2436 2441
    <tile gid="241"/>
2437 2442
    <tile gid="241"/>
@@ -2528,7 +2533,7 @@
2528 2533
    <tile gid="241"/>
2529 2534
    <tile gid="241"/>
2530 2535
    <tile gid="241"/>
2531
-   <tile gid="1"/>
2536
+   <tile gid="0"/>
2532 2537
    <tile gid="241"/>
2533 2538
    <tile gid="241"/>
2534 2539
    <tile gid="0"/>
@@ -2627,9 +2632,9 @@
2627 2632
    <tile gid="241"/>
2628 2633
    <tile gid="241"/>
2629 2634
    <tile gid="241"/>
2630
-   <tile gid="1"/>
2631
-   <tile gid="1"/>
2632
-   <tile gid="1"/>
2635
+   <tile gid="0"/>
2636
+   <tile gid="0"/>
2637
+   <tile gid="0"/>
2633 2638
    <tile gid="241"/>
2634 2639
    <tile gid="0"/>
2635 2640
    <tile gid="241"/>
@@ -2727,9 +2732,9 @@
2727 2732
    <tile gid="241"/>
2728 2733
    <tile gid="241"/>
2729 2734
    <tile gid="241"/>
2730
-   <tile gid="1"/>
2735
+   <tile gid="0"/>
2731 2736
    <tile gid="244"/>
2732
-   <tile gid="1"/>
2737
+   <tile gid="0"/>
2733 2738
    <tile gid="241"/>
2734 2739
    <tile gid="0"/>
2735 2740
    <tile gid="241"/>
@@ -2827,9 +2832,9 @@
2827 2832
    <tile gid="241"/>
2828 2833
    <tile gid="241"/>
2829 2834
    <tile gid="241"/>
2830
-   <tile gid="1"/>
2831
-   <tile gid="1"/>
2832
-   <tile gid="1"/>
2835
+   <tile gid="0"/>
2836
+   <tile gid="0"/>
2837
+   <tile gid="0"/>
2833 2838
    <tile gid="241"/>
2834 2839
    <tile gid="0"/>
2835 2840
    <tile gid="241"/>

+ 2 - 1
intelligine/synergy/event/transport/PutableAction.py Datei anzeigen

@@ -29,4 +29,5 @@ class PutableAction(Action):
29 29
 
30 30
         # TODO: DEBUG
31 31
         if isinstance(obj_transported, Food):
32
-            obj_transported.set_position((-1, 0, 0))
32
+            #obj_transported.set_position((-1, 0, 0))
33
+            obj_transported.transform_to_stocked()

+ 9 - 1
intelligine/synergy/object/Food.py Datei anzeigen

@@ -1,5 +1,6 @@
1 1
 from intelligine.synergy.object.ressource.Ressource import Resource
2
-from intelligine.cst import TYPE, TYPE_RESOURCE_EXPLOITABLE
2
+from intelligine.cst import TYPE, TYPE_RESOURCE_EXPLOITABLE, TYPE_RESOURCE_EATABLE, COL_EATABLE, COL_SMELL, SMELL_FOOD, \
3
+    TRANSPORTABLE
3 4
 
4 5
 
5 6
 class Food(Resource):
@@ -12,3 +13,10 @@ class Food(Resource):
12 13
         clone = self.__class__(self._collection, self._context)
13 14
         self._collection.add_object(clone)
14 15
         return clone
16
+
17
+    def transform_to_stocked(self):
18
+        self._context.metas.list.remove(TYPE, self.get_id(), TYPE_RESOURCE_EXPLOITABLE)
19
+        self._context.metas.list.add(TYPE, self.get_id(), TYPE_RESOURCE_EATABLE)
20
+        self._add_col(COL_EATABLE)
21
+        self._add_col(COL_SMELL)
22
+        self._set_smell(SMELL_FOOD)

+ 3 - 0
intelligine/synergy/object/StockedFood.py Datei anzeigen

@@ -11,3 +11,6 @@ class StockedFood(Food):
11 11
         self._add_col(COL_EATABLE)
12 12
         self._add_col(COL_SMELL)
13 13
         self._set_smell(SMELL_FOOD)
14
+
15
+    def __new__(cls, *args, **kwargs):
16
+        return Food(*args, **kwargs)

+ 2 - 2
intelligine/tests/simulation/mode/TestChangeMode.py Datei anzeigen

@@ -1,6 +1,5 @@
1 1
 from intelligine.synergy.Environment import Environment
2 2
 from intelligine.synergy.object.Food import Food
3
-from intelligine.synergy.object.StockedFood import StockedFood
4 3
 from intelligine.tests.simulation.mode.Base import Base
5 4
 from intelligine.synergy.Colony import Colony
6 5
 from intelligine.synergy.Simulation import Simulation
@@ -65,7 +64,8 @@ class TestChangeMode(Base):
65 64
             def get_start_objects(self, collection, context):
66 65
                 foods = []
67 66
                 food = Food(collection, context)
68
-                stocked_food = StockedFood(collection, context)
67
+                stocked_food = Food(collection, context)
68
+                stocked_food.transform_to_stocked()
69 69
                 food.set_position((0, 0, -20))
70 70
                 stocked_food.set_position((0, 0, 0))
71 71
                 foods.append(stocked_food)