New object weak_block: a block that can be destroyed by bullet hits
[supertux.git] / src / collision_grid.cpp
index 6ed8e4c..e53d18a 100644 (file)
@@ -1,7 +1,7 @@
 //  $Id$
-// 
+//
 //  SuperTux
-//  Copyright (C) 2005 Matthias Braun <matze@braunis.de>
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
 //
 //  This program is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU General Public License
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 //  GNU General Public License for more details.
-// 
+//
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //  02111-1307, USA.
-
 #include <config.h>
 
 #include <iostream>
-#include "collision_grid.h"
-#include "collision.h"
-#include "sector.h"
-#include "collision_grid_iterator.h"
+#include "collision_grid.hpp"
+#include "log.hpp"
+#include "collision.hpp"
+#include "sector.hpp"
+#include "collision_grid_iterator.hpp"
 
 static const float DELTA = .001;
 
@@ -76,7 +76,7 @@ CollisionGrid::add_object(MovingObject* object)
       int gridy = int(y / cell_height);
       if(gridx < 0 || gridy < 0 
           || gridx >= int(cells_x) || gridy >= int(cells_y)) {
-        std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n";
+        log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl;
         continue;
       }
       GridEntry* entry = new GridEntry;
@@ -102,8 +102,8 @@ CollisionGrid::remove_object(MovingObject* object)
   assert(wrapper != 0);
 #else
   if(wrapper == 0) {
-       std::cerr << "Tried to remove nonexistant object!\n";
-       return;
+    log_warning << "Tried to remove nonexistant object" << std::endl;
+    return;
   }
 #endif
   
@@ -114,7 +114,7 @@ CollisionGrid::remove_object(MovingObject* object)
       int gridy = int(y / cell_height);
       if(gridx < 0 || gridy < 0 
           || gridx >= int(cells_x) || gridy >= int(cells_y)) {
-        std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n";
+        log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl;
         continue;
       }
       remove_object_from_gridcell(gridy*cells_x + gridx, wrapper);
@@ -134,9 +134,9 @@ CollisionGrid::move_object(ObjectWrapper* wrapper)
     for(float x = obbox.p1.x; x < obbox.p2.x; x += cell_width) {
       int gridx = int(x / cell_width);
       int gridy = int(y / cell_height);
-      if(gridx < 0 || gridy < 0 
-          || gridx >= int(cells_x) || gridy >= int(cells_y)) {
-        std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n";
+      if(gridx < 0 || gridy < 0  ||
+         gridx >= int(cells_x) || gridy >= int(cells_y)) {
+        log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl;
         continue;
       }
       remove_object_from_gridcell(gridy*cells_x + gridx, wrapper);
@@ -150,7 +150,7 @@ CollisionGrid::move_object(ObjectWrapper* wrapper)
       int gridy = int(y / cell_height);
       if(gridx < 0 || gridy < 0 
           || gridx >= int(cells_x) || gridy >= int(cells_y)) {
-        std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n";
+        log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl;
         continue;
       }
 
@@ -168,13 +168,14 @@ void
 CollisionGrid::check_collisions()
 {
   std::vector<ObjectWrapper*> moved_objects;
-  
+#if 0
   CollisionGridIterator iter(*this, Sector::current()->get_active_region());
   while(ObjectWrapper* wrapper = iter.next_wrapper()) {
     MovingObject* object = wrapper->object;
     if(!object->is_valid())
       continue;
-    if(object->get_flags() & GameObject::FLAG_NO_COLLDET) {
+    if(object->get_group() == COLGROUP_DISABLED) {
       object->bbox.move(object->movement);
       object->movement = Vector(0, 0);
       moved_objects.push_back(wrapper);
@@ -192,6 +193,7 @@ CollisionGrid::check_collisions()
       moved_objects.push_back(wrapper);
     }
   }
+#endif
 
   for(std::vector<ObjectWrapper*>::iterator i = moved_objects.begin();
       i != moved_objects.end(); ++i) {
@@ -211,7 +213,7 @@ CollisionGrid::collide_object(ObjectWrapper* wrapper)
       int gridy = int(y / cell_height);
       if(gridx < 0 || gridy < 0 
           || gridx >= int(cells_x) || gridy >= int(cells_y)) {
-        //std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n";
+        //log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl;
         continue;
       }
   
@@ -289,6 +291,6 @@ CollisionGrid::remove_object_from_gridcell(int gridcell, ObjectWrapper* wrapper)
     entry = entry->next;
   };
 
-  std::cerr << "Couldn't find object in cell.\n";
+  log_warning << "Couldn't find object in cell" << std::endl;
 }