-optimized and cleaned up collision_object_map
[supertux.git] / src / level.cpp
index d8d40e5..cbda1f5 100644 (file)
 
 using namespace std;
 
-st_subset::st_subset()
+LevelSubset::LevelSubset()
+    : image(0), levels(0)
 {
-  levels = 0;
 }
 
-void st_subset::create(const std::string& subset_name)
+LevelSubset::~LevelSubset()
+{
+    delete image;
+}
+
+void LevelSubset::create(const std::string& subset_name)
 {
   Level new_lev;
-  st_subset new_subset;
+  LevelSubset new_subset;
   new_subset.name = subset_name;
   new_subset.title = "Unknown Title";
   new_subset.description = "No description so far.";
@@ -53,7 +58,7 @@ void st_subset::create(const std::string& subset_name)
   new_lev.save(subset_name.c_str(),1);
 }
 
-void st_subset::parse (lisp_object_t* cursor)
+void LevelSubset::parse (lisp_object_t* cursor)
 {
   while(!lisp_nil_p(cursor))
     {
@@ -85,7 +90,7 @@ void st_subset::parse (lisp_object_t* cursor)
     }
 }
 
-void st_subset::load(char *subset)
+void LevelSubset::load(char *subset)
 {
   FILE* fi;
   char filename[1024];
@@ -156,7 +161,7 @@ void st_subset::load(char *subset)
   levels = --i;
 }
 
-void st_subset::save()
+void LevelSubset::save()
 {
   FILE* fi;
   string filename;
@@ -192,15 +197,6 @@ void st_subset::save()
     }
 }
 
-void st_subset::free()
-{
-  title.clear();
-  description.clear();
-  name.clear();
-  delete image;
-  levels = 0;
-}
-
 Level::Level()
   : img_bkgd(0)
 {
@@ -245,8 +241,6 @@ Level::init_defaults()
   bkgd_bottom.red   = 255;
   bkgd_bottom.green = 255;
   bkgd_bottom.blue  = 255;
-  endpos     = 0;
-  use_endsequence = false;
 
   for(int i = 0; i < 15; ++i)
     {
@@ -284,22 +278,17 @@ Level::load(const std::string& subset, int level)
 int 
 Level::load(const std::string& filename)
 {
-  FILE * fi;
-  lisp_object_t* root_obj = 0;
-  fi = fopen(filename.c_str(), "r");
-  if (fi == NULL)
+  lisp_object_t* root_obj = lisp_read_from_file(filename);
+  if (!root_obj)
     {
-      perror(filename.c_str());
+      std::cout << "Level: Couldn't load file: " << filename << std::endl;
       return -1;
     }
 
-  lisp_stream_t stream;
-  lisp_stream_init_file (&stream, fi);
-  root_obj = lisp_read (&stream);
-
   if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
     {
       printf("World: Parse Error in file %s", filename.c_str());
+      return -1;
     }
 
   vector<int> ia_tm;
@@ -312,8 +301,6 @@ Level::load(const std::string& filename)
       LispReader reader(lisp_cdr(root_obj));
       version = 0;
       reader.read_int("version",  &version);
-      use_endsequence = false;
-      reader.read_bool("use-endsequence", &use_endsequence);
       if(!reader.read_int("width",  &width))
         st_abort("No width specified for level.", "");
       if (!reader.read_int("start_pos_x", &start_pos_x)) start_pos_x = 100;
@@ -513,16 +500,7 @@ Level::load(const std::string& filename)
         }
     }
 
-  //  Mark the end position of this level!
-  // FIXME: -10 is a rather random value, we still need some kind of
-  // real levelend gola
-  if (use_endsequence)
-    endpos = 32*(width-30);
-  else
-    endpos = 32*(width-15);
-
   lisp_free(root_obj);
-  fclose(fi);
   return 0;
 }
 
@@ -755,7 +733,7 @@ Level::get_level_music_fast()
 }
 
 unsigned int 
-Level::gettileid(float x, float y)
+Level::gettileid(float x, float y) const
 {
   int xx, yy;
   unsigned int c;
@@ -771,4 +749,13 @@ Level::gettileid(float x, float y)
   return c;
 }
 
+unsigned int
+Level::get_tile_at(int x, int y) const
+{
+  if(x < 0 || x > width || y < 0 || y > 14)
+    return 0;
+  
+  return ia_tiles[y][x];
+}
+
 /* EOF */