Made code -Wshadow clean, missed a bunch of issues in the last commit
[supertux.git] / src / trigger / door.cpp
index c1418d8..2bb4f71 100644 (file)
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+#include "trigger/door.hpp"
+
+#include <sstream>
+
 #include "audio/sound_manager.hpp"
 #include "object/player.hpp"
 #include "sprite/sprite_manager.hpp"
 #include "supertux/game_session.hpp"
 #include "supertux/object_factory.hpp"
-#include "trigger/door.hpp"
+#include "supertux/sector.hpp"
 #include "util/reader.hpp"
 
 Door::Door(const Reader& reader) :
   state(CLOSED),
   target_sector(),
   target_spawnpoint(),
+  script(),
   sprite(),
   stay_open_timer()
 {
@@ -34,6 +39,8 @@ Door::Door(const Reader& reader) :
   reader.get("sector", target_sector);
   reader.get("spawnpoint", target_spawnpoint);
 
+  reader.get("script", script);
+
   sprite = sprite_manager->create("images/objects/door/door.sprite");
   sprite->set_action("closed");
   bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
@@ -45,6 +52,7 @@ Door::Door(int x, int y, std::string sector, std::string spawnpoint) :
   state(CLOSED),
   target_sector(),
   target_spawnpoint(),
+  script(),
   sprite(),
   stay_open_timer()
 {
@@ -122,7 +130,7 @@ Door::event(Player& , EventType type)
 }
 
 HitResponse
-Door::collision(GameObject& other, const CollisionHit& hit)
+Door::collision(GameObject& other, const CollisionHit& hit_)
 {
   switch (state) {
     case CLOSED:
@@ -136,7 +144,14 @@ Door::collision(GameObject& other, const CollisionHit& hit)
       if (player) {
         state = CLOSING;
         sprite->set_action("closing", 1);
-        GameSession::current()->respawn(target_sector, target_spawnpoint);
+        if(!script.empty()) {
+          std::istringstream stream(script);
+          Sector::current()->run_script(stream, "Door");
+        }
+
+        if(!target_sector.empty()) {
+          GameSession::current()->respawn(target_sector, target_spawnpoint);
+        }
       }
     }
     break;
@@ -144,7 +159,7 @@ Door::collision(GameObject& other, const CollisionHit& hit)
       break;
   }
 
-  return TriggerBase::collision(other, hit);
+  return TriggerBase::collision(other, hit_);
 }
 
 /* EOF */