Browse Source

a bug die once

Bastien Sevajol 9 years ago
parent
commit
7aed9a8150

+ 0 - 1
TODO View File

1
-* Fourmis attaqué par cadavres
2
 * Fourmis (map.tmx) pas en mode nurse (-> algo de choix d'activité plus tard)
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
 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, ACTION_DIE
5
-from synergine.core.Signals import Signals
6
 
4
 
7
 
5
 
8
 class NearAttackableAction(Action):
6
 class NearAttackableAction(Action):
20
         for obj_id_attackable in self._parameters['objects_ids_attackable']:
18
         for obj_id_attackable in self._parameters['objects_ids_attackable']:
21
             obj_attackable = synergy_manager.get_map().get_object(obj_id_attackable)
19
             obj_attackable = synergy_manager.get_map().get_object(obj_id_attackable)
22
             obj_attackable.hurted(randint(0, 2))
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
 from intelligine.core.exceptions import BodyPartAlreadyExist
1
 from intelligine.core.exceptions import BodyPartAlreadyExist
2
 from intelligine.synergy.object.Transportable import Transportable
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
 from intelligine.simulation.object.brain.Brain import Brain
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
 class BaseBug(Transportable):
9
 class BaseBug(Transportable):
14
         context.metas.collections.add(self.get_id(), COL_ALIVE)
16
         context.metas.collections.add(self.get_id(), COL_ALIVE)
15
         context.metas.value.set(COLONY, self.get_id(), collection.get_id())
17
         context.metas.value.set(COLONY, self.get_id(), collection.get_id())
16
         self._life_points = 10
18
         self._life_points = 10
19
+        self._alive = True
17
         self._movements_count = -1
20
         self._movements_count = -1
18
         self._brain = self._get_brain_instance()
21
         self._brain = self._get_brain_instance()
19
         self._parts = {}
22
         self._parts = {}
20
         self._init_parts()
23
         self._init_parts()
21
 
24
 
22
     def die(self):
25
     def die(self):
26
+        self._set_alive(False)
23
         self._remove_state(ALIVE)
27
         self._remove_state(ALIVE)
24
         self._remove_state(ATTACKABLE)
28
         self._remove_state(ATTACKABLE)
25
         self._remove_col(COL_ALIVE)
29
         self._remove_col(COL_ALIVE)
38
 
42
 
39
     def hurted(self, points):
43
     def hurted(self, points):
40
         self._life_points -= points
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
     def get_life_points(self):
55
     def get_life_points(self):
43
         return self._life_points
56
         return self._life_points