Console commands can pass arguments
[supertux.git] / src / sector.cpp
index 071e059..3b1926f 100644 (file)
@@ -32,6 +32,7 @@
 #include "object/gameobjs.hpp"
 #include "object/camera.hpp"
 #include "object/background.hpp"
+#include "object/gradient.hpp"
 #include "object/particlesystem.hpp"
 #include "object/particlesystem_interactive.hpp"
 #include "object/tilemap.hpp"
@@ -135,7 +136,7 @@ Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
   try {
     return create_object(name, reader);
   } catch(std::exception& e) {
-    msg_warning(e.what() << "");
+    msg_warning << e.what() << "" << std::endl;
   }
   
   return 0;
@@ -175,7 +176,7 @@ Sector::parse(const lisp::Lisp& sector)
 
   fix_old_tiles();
   if(!camera) {
-    msg_warning("sector '" << name << "' does not contain a camera.");
+    msg_warning << "sector '" << name << "' does not contain a camera." << std::endl;
     update_game_objects();
     add_object(new Camera(this));
   }
@@ -214,14 +215,14 @@ Sector::parse_old_format(const lisp::Lisp& reader)
   bkgd_bottom.blue = static_cast<float> (b) / 255.0f;
   
   if(backgroundimage != "") {
-    Background* background = new Background;
+    Background* background = new Background();
     background->set_image(
             std::string("images/background/") + backgroundimage, bgspeed);
     add_object(background);
   } else {
-    Background* background = new Background;
-    background->set_gradient(bkgd_top, bkgd_bottom);
-    add_object(background);
+    Gradient* gradient = new Gradient();
+    gradient->set_gradient(bkgd_top, bkgd_bottom);
+    add_object(gradient);
   }
 
   std::string particlesystem;
@@ -285,7 +286,7 @@ Sector::parse_old_format(const lisp::Lisp& reader)
           spawnpoints.push_back(sp);
           }
       } else {
-        msg_warning("Unknown token '" << iter.item() << "' in reset-points.");
+        msg_warning << "Unknown token '" << iter.item() << "' in reset-points." << std::endl;
       }
     }
   }
@@ -299,7 +300,7 @@ Sector::parse_old_format(const lisp::Lisp& reader)
       if(object) {
         add_object(object);
       } else {
-        msg_warning("Unknown object '" << iter.item() << "' in level.");
+        msg_warning << "Unknown object '" << iter.item() << "' in level." << std::endl;
       }
     }
   }
@@ -408,7 +409,7 @@ Sector::activate(const std::string& spawnpoint)
     }
   }                                                                           
   if(!sp) {
-    msg_warning("Spawnpoint '" << spawnpoint << "' not found.");
+    msg_warning << "Spawnpoint '" << spawnpoint << "' not found." << std::endl;
     if(spawnpoint != "main") {
       activate("main");
     } else {
@@ -536,14 +537,14 @@ Sector::update_game_objects()
       if(solids == 0) {
         solids = tilemap;
       } else {
-        msg_warning("Another solid tilemaps added. Ignoring");
+        msg_warning << "Another solid tilemaps added. Ignoring" << std::endl;
       }
     }
 
     Camera* camera = dynamic_cast<Camera*> (object);
     if(camera) {
       if(this->camera != 0) {
-        msg_warning("Multiple cameras added. Ignoring");
+        msg_warning << "Multiple cameras added. Ignoring" << std::endl;
         continue;
       }
       this->camera = camera;
@@ -587,9 +588,8 @@ Sector::collision_tilemap(const Rect& dest, const Vector& movement,
   // test with all tiles in this rectangle
   int starttilex = int(x1) / 32;
   int starttiley = int(y1) / 32;
-  int max_x = int(x2);
-  // the +1 is somehow needed to make characters stay on the floor
-  int max_y = int(y2+1);
+  int max_x = int(x2 + (1 - DELTA));
+  int max_y = int(y2 + (1 - DELTA));
 
   CollisionHit temphit;
   for(int x = starttilex; x*32 < max_x; ++x) {
@@ -665,10 +665,10 @@ Sector::collision_tile_attributes(const Rect& dest) const
   float y2 = dest.p2.y;
 
   // test with all tiles in this rectangle
-  int starttilex = int(x1-1) / 32;
-  int starttiley = int(y1-1) / 32;
-  int max_x = int(x2+1);
-  int max_y = int(y2+1);
+  int starttilex = int(x1) / 32;
+  int starttiley = int(y1) / 32;
+  int max_x = int(x2);
+  int max_y = int(y2);
 
   uint32_t result = 0;
   for(int x = starttilex; x*32 < max_x; ++x) {
@@ -729,17 +729,12 @@ Sector::collision_static(MovingObject* object, const Vector& movement)
         || !moving_object_2->is_valid())
       continue;
         
-    Rect dest2 = moving_object_2->get_bbox();
-    // We're using the old position of the object here,
-    // this might seem a bit wrong but improves some situations
-    // like stacked boxes and badguys alot 
-    //
-    dest2.move(moving_object_2->get_movement());
+    Rect dest = moving_object_2->dest;
+
     Vector rel_movement 
       = movement - moving_object_2->get_movement();
-    //Vector movement = 
-        
-    if(Collision::rectangle_rectangle(temphit, object->dest, rel_movement, dest2)
+
+    if(Collision::rectangle_rectangle(temphit, object->dest, rel_movement, dest)
         && temphit.time > hit.time) {
       hit = temphit;
       collided_with = moving_object_2;
@@ -760,7 +755,7 @@ Sector::collision_static(MovingObject* object, const Vector& movement)
       // the static object "wins" move tux out of the collision
       object->dest.move(-hit.normal * (hit.depth + DELTA));
       return false;
-    } else if(other_response == TEST) {
+    } else if(other_response == PASS_MOVEMENT) {
       object->dest.move(moving_object->get_movement());
       //object->movement += moving_object->get_movement();
     }
@@ -804,18 +799,18 @@ Sector::handle_collisions()
     Vector movement = moving_object->get_movement();
 
     // test if x or y movement is dominant
-    if(fabsf(moving_object->get_movement().x) > fabsf(moving_object->get_movement().y)) {
+    if(fabsf(moving_object->get_movement().x) < fabsf(moving_object->get_movement().y)) {
 
       // test in x direction first, then y direction
       moving_object->dest.move(Vector(0, -movement.y));
       for(int i = 0; i < 2; ++i) {
-        bool res = collision_static(moving_object, /*Vector(movement.x, 0)*/ movement);
+        bool res = collision_static(moving_object, Vector(movement.x, 0));
         if(res)
           break;
       }
       moving_object->dest.move(Vector(0, movement.y));
       for(int i = 0; i < 2; ++i) {
-        bool res = collision_static(moving_object, /*Vector(0, movement.y)*/ movement);
+        bool res = collision_static(moving_object, Vector(0, movement.y));
         if(res)
           break;
       }
@@ -825,13 +820,13 @@ Sector::handle_collisions()
       // test in y direction first, then x direction
       moving_object->dest.move(Vector(-movement.x, 0));
       for(int i = 0; i < 2; ++i) {
-        bool res = collision_static(moving_object, movement/*Vector(0, movement.y)*/);
+        bool res = collision_static(moving_object, Vector(0, movement.y));
         if(res)
           break;
       }
       moving_object->dest.move(Vector(movement.x, 0)); 
       for(int i = 0; i < 2; ++i) {
-        bool res = collision_static(moving_object, movement /*Vector(movement.x, 0)*/);
+        bool res = collision_static(moving_object, Vector(movement.x, 0));
         if(res)
           break;
       }