Had a bit of time today and worked on supertux:
[supertux.git] / src / sector.cpp
index 310d64f..4037f35 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "app/globals.h"
 #include "sector.h"
+#include "player_status.h"
 #include "object/gameobjs.h"
 #include "object/camera.h"
 #include "object/background.h"
 #include "statistics.h"
 #include "collision_grid.h"
 #include "collision_grid_iterator.h"
+#include "object_factory.h"
 #include "special/collision.h"
 #include "math/rectangle.h"
 #include "math/aatriangle.h"
 #include "object/coin.h"
 #include "object/block.h"
 #include "object/invisible_block.h"
-#include "object/platform.h"
 #include "object/bullet.h"
-#include "object/rock.h"
 #include "badguy/jumpy.h"
-#include "badguy/snowball.h"
-#include "badguy/bouncing_snowball.h"
-#include "badguy/flame.h"
-#include "badguy/flyingsnowball.h"
-#include "badguy/mriceblock.h"
-#include "badguy/mrbomb.h"
-#include "badguy/dispenser.h"
 #include "badguy/spike.h"
-#include "badguy/spiky.h"
-#include "badguy/nolok_01.h"
-#include "trigger/door.h"
 #include "trigger/sequence_trigger.h"
-#include "trigger/secretarea_trigger.h"
-#include "gameobjs_bridge.h"
+
+//#define USE_GRID
 
 Sector* Sector::_current = 0;
 
@@ -105,30 +95,32 @@ Sector::~Sector()
 GameObject*
 Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
 {
-  if(name == "background") {
-    return new Background(reader);
-  } else if(name == "camera") {
+  if(name == "camera") {
     Camera* camera = new Camera(this);
     camera->parse(reader);
     return camera;
-  } else if(name == "tilemap") {
-    return  new TileMap(reader);
   } else if(name == "particles-snow") {
     SnowParticleSystem* partsys = new SnowParticleSystem();
     partsys->parse(reader);
     return partsys;
+  } else if(name == "particles-rain") {
+    RainParticleSystem* partsys = new RainParticleSystem();
+    partsys->parse(reader);
+    return partsys;
   } else if(name == "particles-clouds") {
     CloudParticleSystem* partsys = new CloudParticleSystem();
     partsys->parse(reader);
     return partsys;
-  } else if(name == "secretarea") {
-    return new SecretAreaTrigger(reader);
-  } else if(name == "sequencetrigger") {
-    return new SequenceTrigger(reader);
-  } else if(is_object(name)) {
-    return create_object(object_name_to_type(name), reader);
-  } else
-    std::cerr << "Unknown object type '" << name << "'.\n";
+  } else if(name == "money") { // for compatibility with old maps
+    return new Jumpy(reader);
+  } 
+
+  try {
+    return create_object(name, reader);
+  } catch(std::exception& e) {
+    std::cerr << e.what() << "\n";
+  }
+  
   return 0;
 }
 
@@ -221,6 +213,8 @@ Sector::parse_old_format(const lisp::Lisp& reader)
     add_object(new CloudParticleSystem());
   else if(particlesystem == "snow")
     add_object(new SnowParticleSystem());
+  else if(particlesystem == "rain")
+    add_object(new RainParticleSystem());
 
   Vector startpos(100, 170);
   reader.get("start_pos_x", startpos.x);
@@ -703,7 +697,7 @@ Sector::collision_object(MovingObject* object1, MovingObject* object2)
 void
 Sector::collision_handler()
 {
-#if 0
+#ifdef USE_GRID
   grid->check_collisions();
 #else
   for(std::vector<GameObject*>::iterator i = gameobjects.begin();
@@ -747,6 +741,10 @@ Sector::collision_handler()
 bool
 Sector::add_bullet(const Vector& pos, float xm, Direction dir)
 {
+  // TODO remove this function and move these checks elsewhere...
+  static const size_t MAX_FIRE_BULLETS = 2;
+  static const size_t MAX_ICE_BULLETS = 1;
+    
   if(player->got_power == Player::FIRE_POWER) {
     if(bullets.size() > MAX_FIRE_BULLETS-1)
       return false;
@@ -835,14 +833,13 @@ int
 Sector::get_total_badguys()
 {
   int total_badguys = 0;
-#if 0
-  for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i)
-    {
+  for(GameObjects::iterator i = gameobjects.begin();
+      i != gameobjects.end(); ++i) {
     BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
     if(badguy)
       total_badguys++;
-    }
-#endif
+  }
+
   return total_badguys;
 }