Browse Source

a bug die once

Bastien Sevajol 9 years ago
parent
commit
7aed9a8150

+ 0 - 1
TODO View File

@@ -1,2 +1 @@
1
-* Fourmis attaqué par cadavres
2 1
 * Fourmis (map.tmx) pas en mode nurse (-> algo de choix d'activité plus tard)

+ 0 - 5
intelligine/synergy/event/attack/NearAttackableAction.py View File

@@ -1,8 +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.cst import ALIVE, ATTACKABLE, ACTION_DIE
5
-from synergine.core.Signals import Signals
6 4
 
7 5
 
8 6
 class NearAttackableAction(Action):
@@ -20,6 +18,3 @@ class NearAttackableAction(Action):
20 18
         for obj_id_attackable in self._parameters['objects_ids_attackable']:
21 19
             obj_attackable = synergy_manager.get_map().get_object(obj_id_attackable)
22 20
             obj_attackable.hurted(randint(0, 2))
23
-            if obj_attackable.get_life_points() <= 0:
24
-                obj_attackable.die()
25
-                Signals.signal(ACTION_DIE).send(obj=obj_attackable, context=context)

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

@@ -1,7 +1,9 @@
1 1
 from intelligine.core.exceptions import BodyPartAlreadyExist
2 2
 from intelligine.synergy.object.Transportable import Transportable
3
-from intelligine.cst import ALIVE, ATTACKABLE, COL_ALIVE, COLONY
3
+from intelligine.cst import COL_ALIVE, COLONY, ACTION_DIE
4 4
 from intelligine.simulation.object.brain.Brain import Brain
5
+from intelligine.cst import ALIVE, ATTACKABLE
6
+from synergine.core.Signals import Signals
5 7
 
6 8
 
7 9
 class BaseBug(Transportable):
@@ -14,12 +16,14 @@ class BaseBug(Transportable):
14 16
         context.metas.collections.add(self.get_id(), COL_ALIVE)
15 17
         context.metas.value.set(COLONY, self.get_id(), collection.get_id())
16 18
         self._life_points = 10
19
+        self._alive = True
17 20
         self._movements_count = -1
18 21
         self._brain = self._get_brain_instance()
19 22
         self._parts = {}
20 23
         self._init_parts()
21 24
 
22 25
     def die(self):
26
+        self._set_alive(False)
23 27
         self._remove_state(ALIVE)
24 28
         self._remove_state(ATTACKABLE)
25 29
         self._remove_col(COL_ALIVE)
@@ -38,6 +42,15 @@ class BaseBug(Transportable):
38 42
 
39 43
     def hurted(self, points):
40 44
         self._life_points -= points
45
+        if self.get_life_points() <= 0 and self.is_alive():
46
+            self.die()
47
+            Signals.signal(ACTION_DIE).send(obj=self, context=self._context)
48
+
49
+    def is_alive(self):
50
+        return self._alive
51
+
52
+    def _set_alive(self, alive):
53
+        self._alive = bool(alive)
41 54
 
42 55
     def get_life_points(self):
43 56
         return self._life_points