little change to improve win32 portability
[supertux.git] / src / level.cpp
index e8940e6..d493586 100644 (file)
@@ -224,12 +224,6 @@ void level_default(st_level* plevel)
       for(y = 0; y < plevel->width; ++y)
         plevel->fg_tiles[i][y] = (unsigned int) '.';
       plevel->fg_tiles[i][plevel->width] = (unsigned int) '\0';
-
-      plevel->dn_tiles[i] = (unsigned int*) malloc((plevel->width+1)*sizeof(unsigned int));
-      plevel->dn_tiles[i][plevel->width] = (unsigned int) '\0';
-      for(y = 0; y < plevel->width; ++y)
-        plevel->dn_tiles[i][y] = (unsigned int) '.';
-      plevel->dn_tiles[i][plevel->width] = (unsigned int) '\0';
     }
 }
 
@@ -269,7 +263,6 @@ int level_load(st_level* plevel, const char* filename)
     }
 
   vector<int> ia_tm;
-  vector<int> dn_tm;
   vector<int> bg_tm;
   vector<int> fg_tm;
 
@@ -295,7 +288,6 @@ int level_load(st_level* plevel, const char* filename)
       if (!reader.read_int_vector("interactive-tm", &ia_tm))
         reader.read_int_vector("tilemap", &ia_tm);
 
-      reader.read_int_vector("dynamic-tm",     &dn_tm);
       reader.read_int_vector("foreground-tm",  &fg_tm);
 
       {
@@ -324,9 +316,6 @@ int level_load(st_level* plevel, const char* filename)
         {
           std::map<char, int> transtable;
           transtable['.'] = 0;
-          transtable['0'] = 1000;
-          transtable['1'] = 1001;
-          transtable['2'] = 1002;
           transtable['x'] = 104;
           transtable['X'] = 77;
           transtable['y'] = 78;
@@ -365,20 +354,35 @@ int level_load(st_level* plevel, const char* filename)
           transtable['\\'] = 81;
           transtable['&'] = 75;
 
+          int x = 0;
+          int y = 0;
           for(std::vector<int>::iterator i = ia_tm.begin(); i != ia_tm.end(); ++i)
             {
-              std::map<char, int>::iterator j = transtable.find(*i);
-              if (j != transtable.end())
-                *i = j->second;
+              if (*i == '0' || *i == '1' || *i == '2')
+                {
+                  plevel->badguy_data.push_back(BadGuyData(static_cast<BadGuyKind>(*i-'0'),
+                                                           x*32, y*32));
+                  *i = 0;
+                }
               else
-                printf("Error: conversion will fail, unsupported char: '%c' (%d)\n", *i, *i);
+                {
+                  std::map<char, int>::iterator j = transtable.find(*i);
+                  if (j != transtable.end())
+                    *i = j->second;
+                  else
+                    printf("Error: conversion will fail, unsupported char: '%c' (%d)\n", *i, *i);
+                }
+              ++x;
+              if (x >= plevel->width) {
+                x = 0;
+                ++y;
+              }
             }
         }
     }
 
   for(int i = 0; i < 15; ++i)
     {
-      plevel->dn_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
       plevel->ia_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
       plevel->bg_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
       plevel->fg_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
@@ -397,18 +401,6 @@ int level_load(st_level* plevel, const char* filename)
     }
 
   i = j = 0;
-  for(vector<int>::iterator it = dn_tm.begin(); it != dn_tm.end(); ++it, ++i)
-    {
-
-      plevel->dn_tiles[j][i] = (*it);
-      if(i == plevel->width - 1)
-        {
-          i = -1;
-          ++j;
-        }
-    }
-
-  i = j = 0;
   for(vector<int>::iterator it = bg_tm.begin(); it != bg_tm.end(); ++it, ++i)
     {
 
@@ -435,19 +427,10 @@ int level_load(st_level* plevel, const char* filename)
   /* Set the global gravity to the latest loaded level's gravity */
   gravity = plevel->gravity;
 
-  /*  Mark the end position of this level! - Is a bit wrong here thought * /
-
-  for (y = 0; y < 15; ++y)
-  {
-  for (x = 0; x < plevel->width; ++x)
-  {
-  if(plevel->tiles[y][x] == '|')
-  {
-  if(x*32 > endpos)
-  endpos = x*32;
-  }
-  }
-  }*/
+  //  Mark the end position of this level!
+  // FIXME: -10 is a rather random value, we still need some kind of
+  // real levelend gola
+  endpos = 32*(plevel->width-10);
 
   fclose(fi);
   return 0;
@@ -512,15 +495,6 @@ void level_save(st_level* plevel,const  char * subset, int level)
     }
 
   fprintf( fi,")\n");
-  fprintf(fi,"  (dynamic-tm ");
-
-  for(y = 0; y < 15; ++y)
-    {
-      for(i = 0; i < plevel->width; ++i)
-        fprintf(fi," %d ", plevel->dn_tiles[y][i]);
-    }
-
-  fprintf( fi,")\n");
   fprintf(fi,"  (foreground-tm ");
 
   for(y = 0; y < 15; ++y)
@@ -546,14 +520,14 @@ void level_free(st_level* plevel)
   for(i=0; i < 15; ++i)
     free(plevel->ia_tiles[i]);
   for(i=0; i < 15; ++i)
-    free(plevel->dn_tiles[i]);
-  for(i=0; i < 15; ++i)
     free(plevel->fg_tiles[i]);
 
   plevel->name.clear();
   plevel->theme.clear();
   plevel->song_title.clear();
   plevel->bkgd_image.clear();
+
+  plevel->badguy_data.clear();
 }
 
 /* Load graphics: */
@@ -645,7 +619,6 @@ void level_change_size (st_level* plevel, int new_width)
   if(new_width < 21)
     new_width = 21;
   tilemap_change_size((unsigned int***)&plevel->ia_tiles,new_width,plevel->width);
-  tilemap_change_size((unsigned int***)&plevel->dn_tiles,new_width,plevel->width);
   tilemap_change_size((unsigned int***)&plevel->bg_tiles,new_width,plevel->width);
   tilemap_change_size((unsigned int***)&plevel->fg_tiles,new_width,plevel->width);
   plevel->width = new_width;
@@ -665,14 +638,15 @@ void level_change(st_level* plevel, float x, float y, int tm, unsigned int c)
     {
       switch(tm)
         {
-        case 0:
+        case TM_BG:
           plevel->bg_tiles[yy][xx] = c;
-        case 1:
+          break;
+        case TM_IA:
           plevel->ia_tiles[yy][xx] = c;
-        case 2:
-          plevel->dn_tiles[yy][xx] = c;
-        case 4:
+          break;
+        case TM_FG:
           plevel->fg_tiles[yy][xx] = c;
+          break;
         }
     }
 }