From 5e9606f3c178f689f06309c262ead1ec703aa052 Mon Sep 17 00:00:00 2001 From: mathnerd314 Date: Sat, 14 Nov 2009 13:49:09 +0000 Subject: [PATCH] Use run_dead_script wherever possible and make kill_* operations only do stuff once git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@5935 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/badguy/badguy.cpp | 16 +++++----------- src/badguy/bomb.cpp | 8 +++++--- src/badguy/kamikazesnowball.cpp | 2 ++ src/badguy/kugelblitz.cpp | 1 + src/badguy/mole.cpp | 4 ++-- src/badguy/mrbomb.cpp | 14 +++++++++----- src/badguy/mrtree.cpp | 2 ++ src/badguy/root.cpp | 3 ++- src/badguy/yeti.cpp | 7 +------ 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 7aec6dc5d..2fbacae12 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -337,39 +337,33 @@ BadGuy::kill_squished(GameObject& object) set_group(COLGROUP_MOVING_ONLY_STATIC); Player* player = dynamic_cast(&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 != "") { diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index 940dde883..55e630f1c 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -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(); } diff --git a/src/badguy/kamikazesnowball.cpp b/src/badguy/kamikazesnowball.cpp index b9cf34ff2..643d25290 100644 --- a/src/badguy/kamikazesnowball.cpp +++ b/src/badguy/kamikazesnowball.cpp @@ -81,6 +81,8 @@ KamikazeSnowball::kill_collision() physic.set_velocity_y(0); physic.enable_gravity(true); set_state(STATE_FALLING); + + run_dead_script(); } HitResponse diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index 28c3ae0c5..8065639b5 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -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 diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index 17716cbec..6a14b0f68 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -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; } diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 10b3da4b0..4b6e5e9b0 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -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(); } diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index 382822505..a79350bd9 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -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); } diff --git a/src/badguy/root.cpp b/src/badguy/root.cpp index 5d32120a9..0eb29c742 100644 --- a/src/badguy/root.cpp +++ b/src/badguy/root.cpp @@ -46,7 +46,8 @@ Root::~Root() void Root::deactivate() { - remove_me(); + remove_me(); + //no dead script } void diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 4ad150766..f6cc57adc 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -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); -- 2.11.0