- for(i = 0; i < plevel->width; ++i)
- fprintf(fi," %d ", plevel->ia_tiles[y][i]);
- }
-
- fprintf( fi,")\n");
- fprintf(fi," (foreground-tm ");
-
- for(y = 0; y < 15; ++y)
- {
- for(i = 0; i < plevel->width; ++i)
- fprintf(fi," %d ", plevel->fg_tiles[y][i]);
- }
-
- fprintf( fi,")\n");
- fprintf( fi,"(objects\n");
-
- for(std::vector<BadGuyData>::iterator it = plevel->
- badguy_data.begin();
- it != plevel->badguy_data.end();
- ++it)
- fprintf( fi,"(%s (x %d) (y %d))\n",badguykind_to_string((*it).kind).c_str(),(*it).x,(*it).y);
-
- fprintf( fi,")\n");
-
- fprintf( fi,")\n");
-
- fclose(fi);
-}
-
-
-/* Unload data for this level: */
-
-void
-st_level::cleanup()
-{
- for(int i=0; i < 15; ++i)
- free(bg_tiles[i]);
- for(int i=0; i < 15; ++i)
- free(ia_tiles[i]);
- for(int i=0; i < 15; ++i)
- free(fg_tiles[i]);
-
- name.clear();
- theme.clear();
- song_title.clear();
- bkgd_image.clear();
-
- badguy_data.clear();
-}
-
-/* Load graphics: */
-
-void level_load_gfx(st_level *plevel)
-{
- level_load_image(&img_brick[0],plevel->theme,"brick0.png", IGNORE_ALPHA);
- level_load_image(&img_brick[1],plevel->theme,"brick1.png", IGNORE_ALPHA);
-
- level_load_image(&img_solid[0],plevel->theme,"solid0.png", USE_ALPHA);
- level_load_image(&img_solid[1],plevel->theme,"solid1.png", USE_ALPHA);
- level_load_image(&img_solid[2],plevel->theme,"solid2.png", USE_ALPHA);
- level_load_image(&img_solid[3],plevel->theme,"solid3.png", USE_ALPHA);
-
- level_load_image(&img_bkgd_tile[0][0],plevel->theme,"bkgd-00.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[0][1],plevel->theme,"bkgd-01.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[0][2],plevel->theme,"bkgd-02.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[0][3],plevel->theme,"bkgd-03.png", USE_ALPHA);
-
- level_load_image(&img_bkgd_tile[1][0],plevel->theme,"bkgd-10.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[1][1],plevel->theme,"bkgd-11.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[1][2],plevel->theme,"bkgd-12.png", USE_ALPHA);
- level_load_image(&img_bkgd_tile[1][3],plevel->theme,"bkgd-13.png", USE_ALPHA);
-
- if(!plevel->bkgd_image.empty())
- {
- char fname[1024];
- snprintf(fname, 1024, "%s/background/%s", st_dir, plevel->bkgd_image.c_str());
- if(!faccessible(fname))
- snprintf(fname, 1024, "%s/images/background/%s", datadir.c_str(), plevel->bkgd_image.c_str());
- texture_load(&img_bkgd, fname, IGNORE_ALPHA);
- }
- else
- {
- /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */#
- level_load_image(&img_bkgd, plevel->theme,"solid0.png", IGNORE_ALPHA);
- }
-}
-
-/* Free graphics data for this level: */
-
-void level_free_gfx(void)
-{
- int i;
-
- for (i = 0; i < 2; i++)
- {
- texture_free(&img_brick[i]);
- }
- for (i = 0; i < 4; i++)
- {
- texture_free(&img_solid[i]);
- texture_free(&img_bkgd_tile[0][i]);
- texture_free(&img_bkgd_tile[1][i]);
- }
-
- texture_free(&img_bkgd);
-}
-
-/* Load a level-specific graphic... */
-
-void level_load_image(texture_type* ptexture, string theme,const char * file, int use_alpha)
-{
- char fname[1024];
-
- snprintf(fname, 1024, "%s/themes/%s/%s", st_dir, theme.c_str(), file);
- if(!faccessible(fname))
- snprintf(fname, 1024, "%s/images/themes/%s/%s", datadir.c_str(), theme.c_str(), file);
-
- texture_load(ptexture, fname, use_alpha);
-}
-
-void tilemap_change_size(unsigned int** tilemap[15], int w, int old_w)
-{
- int j,y;
- for(y = 0; y < 15; ++y)
- {
- *tilemap[y] = (unsigned int*) realloc(*tilemap[y],(w+1)*sizeof(unsigned int));
- if(w > old_w)
- for(j = 0; j < w - old_w; ++j)
- *tilemap[y][old_w+j] = 0;
- *tilemap[y][w] = 0;
- }
-}
-
-/* Change the size of a level (width) */
-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->bg_tiles,new_width,plevel->width);
- tilemap_change_size((unsigned int***)&plevel->fg_tiles,new_width,plevel->width);
- plevel->width = new_width;
-
-}
-
-/* Edit a piece of the map! */
-
-void level_change(st_level* plevel, float x, float y, int tm, unsigned int c)
-{
- int xx, yy;
-
- yy = ((int)y / 32);
- xx = ((int)x / 32);
-
- if (yy >= 0 && yy < 15 && xx >= 0 && xx <= plevel->width)
- {
- switch(tm)
- {
- case TM_BG:
- plevel->bg_tiles[yy][xx] = c;
- break;
- case TM_IA:
- plevel->ia_tiles[yy][xx] = c;
- break;
- case TM_FG:
- plevel->fg_tiles[yy][xx] = c;
- break;
- }