Use run_dead_script wherever possible and make kill_* operations only do stuff once
authormathnerd314 <mathnerd314@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sat, 14 Nov 2009 13:49:09 +0000 (13:49 +0000)
committermathnerd314 <mathnerd314@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sat, 14 Nov 2009 13:49:09 +0000 (13:49 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@5935 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/badguy/badguy.cpp
src/badguy/bomb.cpp
src/badguy/kamikazesnowball.cpp
src/badguy/kugelblitz.cpp
src/badguy/mole.cpp
src/badguy/mrbomb.cpp
src/badguy/mrtree.cpp
src/badguy/root.cpp
src/badguy/yeti.cpp

index 7aec6dc..2fbacae 100644 (file)
@@ -337,39 +337,33 @@ BadGuy::kill_squished(GameObject& object)
   set_group(COLGROUP_MOVING_ONLY_STATIC);
   Player* player = dynamic_cast<Player*>(&object);
   if (player) {
-    if (countMe) Sector::current()->get_level()->stats.badguys++;
     player->bounce(*this);
   }
 
   // start dead-script
-  if(dead_script != "") {
-    std::istringstream stream(dead_script);
-    Sector::current()->run_script(stream, "dead-script");
-  }
+  run_dead_script();
 }
 
 void
 BadGuy::kill_fall()
 {
   sound_manager->play("sounds/fall.wav", get_pos());
-  if (countMe) Sector::current()->get_level()->stats.badguys++;
   physic.set_velocity_y(0);
   physic.set_acceleration_y(0);
   physic.enable_gravity(true);
   set_state(STATE_FALLING);
 
   // start dead-script
-  if(dead_script != "") {
-    std::istringstream stream(dead_script);
-    Sector::current()->run_script(stream, "dead-script");
-  }
+  run_dead_script();
 }
 
 void
 BadGuy::run_dead_script()
 {
-   if (countMe)
+  if (countMe)
      Sector::current()->get_level()->stats.badguys++;
+
+  countMe = false;
    
    // start dead-script
   if(dead_script != "") {
index 940dde8..55e630f 100644 (file)
@@ -110,9 +110,11 @@ Bomb::explode()
         player->stop_grabbing();
   }
 
-  remove_me();
-  Explosion* explosion = new Explosion(get_bbox().get_middle());
-  Sector::current()->add_object(explosion);
+  if(is_valid()) {
+    remove_me();
+    Explosion* explosion = new Explosion(get_bbox().get_middle());
+    Sector::current()->add_object(explosion);
+  }
 
   run_dead_script();
 }
index b9cf34f..643d252 100644 (file)
@@ -81,6 +81,8 @@ KamikazeSnowball::kill_collision()
     physic.set_velocity_y(0);
     physic.enable_gravity(true);
     set_state(STATE_FALLING);
+
+    run_dead_script();
 }
 
 HitResponse
index 28c3ae0..8065639 100644 (file)
@@ -44,6 +44,7 @@ Kugelblitz::Kugelblitz(const lisp::Lisp& reader)
   reader.get("x", start_position.x);
   sprite->set_action("falling");
   physic.enable_gravity(false);
+  countMe = false;
 }
 
 void
index 17716cb..6a14b0f 100644 (file)
@@ -77,7 +77,7 @@ Mole::kill_fall()
 {
   set_state(DEAD);
   sound_manager->play("sounds/fall.wav", get_pos());
-  if (countMe) Sector::current()->get_level()->stats.badguys++;
+  run_dead_script();
 }
 
 HitResponse
@@ -91,7 +91,7 @@ Mole::collision_squished(GameObject& )
 {
   set_state(DEAD);
   sound_manager->play("sounds/squish.wav", get_pos());
-  if (countMe) Sector::current()->get_level()->stats.badguys++;
+  run_dead_script();
   return true;
 }
 
index 10b3da4..4b6e5e9 100644 (file)
@@ -89,8 +89,10 @@ MrBomb::collision_player(Player& player, const CollisionHit& hit)
 bool
 MrBomb::collision_squished(GameObject& object)
 {
-  remove_me();
-  Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name ));
+  if(is_valid()) {
+    remove_me();
+    Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name ));
+  }
   kill_squished(object);
   return true;
 }
@@ -106,9 +108,11 @@ MrBomb::active_update(float elapsed_time)
 void
 MrBomb::kill_fall()
 {
-  remove_me();
-  Explosion* explosion = new Explosion(get_bbox().get_middle());
-  Sector::current()->add_object(explosion);
+  if(is_valid()) {
+    remove_me();
+    Explosion* explosion = new Explosion(get_bbox().get_middle());
+    Sector::current()->add_object(explosion);
+  }
 
   run_dead_script();
 }
index 3828225..a79350b 100644 (file)
@@ -90,6 +90,7 @@ MrTree::collision_squished(GameObject& object)
   if (Sector::current()->is_free_of_movingstatics(leaf1_bbox, this)) {
     PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1, LEFT);
     leaf1 = leaf1;
+    leaf1->countMe = false;
     Sector::current()->add_object(leaf1);
   }
 
@@ -99,6 +100,7 @@ MrTree::collision_squished(GameObject& object)
   if (Sector::current()->is_free_of_movingstatics(leaf2_bbox, this)) {
     PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1, RIGHT);
     leaf2 = leaf2;
+    leaf2->countMe = false;
     Sector::current()->add_object(leaf2);
   }
 
index 5d32120..0eb29c7 100644 (file)
@@ -46,7 +46,8 @@ Root::~Root()
 void
 Root::deactivate()
 {
-  remove_me(); 
+  remove_me();
+  //no dead script
 }
 
 void
index 4ad1507..f6cc57a 100644 (file)
@@ -230,12 +230,7 @@ void Yeti::take_hit(Player& )
     set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC);
     sprite->set_action("dead");
 
-    if (countMe) Sector::current()->get_level()->stats.badguys++;
-
-    if(dead_script != "") {
-      std::istringstream stream(dead_script);
-      Sector::current()->run_script(stream, "Yeti - dead-script");
-    }
+    run_dead_script();
   }
   else {
     safe_timer.start(SAFE_TIME);