Removed stray code from -nogl branch
[supertux.git] / src / sector.cpp
index ceb80a3..7ea513a 100644 (file)
@@ -63,6 +63,7 @@
 #include "scripting/sound.hpp"
 #include "scripting/scripted_object.hpp"
 #include "scripting/text.hpp"
+#include "msg.hpp"
 
 Sector* Sector::_current = 0;
 
@@ -70,7 +71,6 @@ Sector::Sector()
   : gravity(10), player(0), solids(0), camera(0),
     currentmusic(LEVEL_MUSIC)
 {
-  song_title = "chipdisko.ogg";
   player = new Player(player_status);
   add_object(player);
 
@@ -135,7 +135,7 @@ Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
   try {
     return create_object(name, reader);
   } catch(std::exception& e) {
-    std::cerr << e.what() << "\n";
+    msg_warning(e.what() << "");
   }
   
   return 0;
@@ -154,7 +154,7 @@ Sector::parse(const lisp::Lisp& sector)
     } else if(token == "gravity") {
       iter.value()->get(gravity);
     } else if(token == "music") {
-      iter.value()->get(song_title);
+      iter.value()->get(music);
     } else if(token == "spawnpoint") {
       SpawnPoint* sp = new SpawnPoint(iter.lisp());
       spawnpoints.push_back(sp);
@@ -175,7 +175,7 @@ Sector::parse(const lisp::Lisp& sector)
 
   fix_old_tiles();
   if(!camera) {
-    std::cerr << "sector '" << name << "' does not contain a camera.\n";
+    msg_warning("sector '" << name << "' does not contain a camera.");
     update_game_objects();
     add_object(new Camera(this));
   }
@@ -215,7 +215,8 @@ Sector::parse_old_format(const lisp::Lisp& reader)
   
   if(backgroundimage != "") {
     Background* background = new Background;
-    background->set_image(backgroundimage, bgspeed);
+    background->set_image(
+            std::string("images/background/") + backgroundimage, bgspeed);
     add_object(background);
   } else {
     Background* background = new Background;
@@ -241,8 +242,9 @@ Sector::parse_old_format(const lisp::Lisp& reader)
   spawn->name = "main";
   spawnpoints.push_back(spawn);
 
-  song_title = "chipdisko.ogg";
-  reader.get("music", song_title);
+  music = "chipdisko.ogg";
+  reader.get("music", music);
+  music = "music/" + music;
 
   int width = 30, height = 15;
   reader.get("width", width);
@@ -283,7 +285,7 @@ Sector::parse_old_format(const lisp::Lisp& reader)
           spawnpoints.push_back(sp);
           }
       } else {
-        std::cerr << "Unknown token '" << iter.item() << "' in reset-points.\n";
+        msg_warning("Unknown token '" << iter.item() << "' in reset-points.");
       }
     }
   }
@@ -297,7 +299,7 @@ Sector::parse_old_format(const lisp::Lisp& reader)
       if(object) {
         add_object(object);
       } else {
-        std::cerr << "Unknown object '" << iter.item() << "' in level.\n";
+        msg_warning("Unknown object '" << iter.item() << "' in level.");
       }
     }
   }
@@ -350,7 +352,7 @@ Sector::write(lisp::Writer& writer)
 {
   writer.write_string("name", name);
   writer.write_float("gravity", gravity);
-  writer.write_string("music", song_title);
+  writer.write_string("music", music);
 
   // write spawnpoints
   for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
@@ -406,7 +408,7 @@ Sector::activate(const std::string& spawnpoint)
     }
   }                                                                           
   if(!sp) {
-    std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n";
+    msg_warning("Spawnpoint '" << spawnpoint << "' not found.");
     if(spawnpoint != "main") {
       activate("main");
     } else {
@@ -534,14 +536,14 @@ Sector::update_game_objects()
       if(solids == 0) {
         solids = tilemap;
       } else {
-        std::cerr << "Another solid tilemaps added. Ignoring.";
+        msg_warning("Another solid tilemaps added. Ignoring");
       }
     }
 
     Camera* camera = dynamic_cast<Camera*> (object);
     if(camera) {
       if(this->camera != 0) {
-        std::cerr << "Warning: Multiple cameras added. Ignoring.";
+        msg_warning("Multiple cameras added. Ignoring");
         continue;
       }
       this->camera = camera;
@@ -857,6 +859,39 @@ Sector::handle_collisions()
 }
 
 bool
+Sector::is_free_space(const Rect& rect) const
+{
+  // test with all tiles in this rectangle
+  int starttilex = int(rect.p1.x) / 32;
+  int starttiley = int(rect.p1.y) / 32;
+  int max_x = int(rect.p2.x);
+  int max_y = int(rect.p2.y);
+
+  for(int x = starttilex; x*32 < max_x; ++x) {
+    for(int y = starttiley; y*32 < max_y; ++y) {
+      const Tile* tile = solids->get_tile(x, y);
+      if(!tile)
+        continue;
+      if(tile->getAttributes() & Tile::SOLID)
+        return false;
+    }
+  }
+
+  for(MovingObjects::const_iterator i = moving_objects.begin();
+      i != moving_objects.end(); ++i) {
+    const MovingObject* moving_object = *i;
+    if(moving_object->get_group() != COLGROUP_STATIC
+        || !moving_object->is_valid())
+      continue;
+
+    if(Collision::intersects(rect, moving_object->get_bbox()))
+      return false;
+  }
+
+  return true;
+}
+
+bool
 Sector::add_bullet(const Vector& pos, float xm, Direction dir)
 {
   // TODO remove this function and move these checks elsewhere...
@@ -901,7 +936,7 @@ Sector::play_music(MusicType type)
   currentmusic = type;
   switch(currentmusic) {
     case LEVEL_MUSIC:
-      sound_manager->play_music(std::string("music/") + song_title);
+      sound_manager->play_music(music);
       break;
     case HERRING_MUSIC:
       sound_manager->play_music("music/salcon.ogg");