- FILE* fi;
- string filename;
-
- /* Save data file: */
- filename = "/levels/" + name + "/";
-
- fcreatedir(filename.c_str());
- filename = string(st_dir) + "/levels/" + name + "/info";
- if(!fwriteable(filename.c_str()))
- filename = datadir + "/levels/" + name + "/info";
- if(fwriteable(filename.c_str()))
- {
- fi = fopen(filename.c_str(), "w");
- if (fi == NULL)
- {
- perror(filename.c_str());
- }
-
- /* Write header: */
- fprintf(fi,";SuperTux-Level-Subset\n");
- fprintf(fi,"(supertux-level-subset\n");
-
- /* Save title info: */
- fprintf(fi," (title \"%s\")\n", title.c_str());
-
- /* Save the description: */
- fprintf(fi," (description \"%s\")\n", description.c_str());
-
- fprintf( fi,")");
- fclose(fi);
-
- }
-}
-
-void st_subset::free()
-{
- title.clear();
- description.clear();
- name.clear();
- texture_free(&image);
- levels = 0;
-}
-
-void level_default(st_level* plevel)
-{
- int i,y;
- plevel->name = "UnNamed";
- plevel->theme = "antarctica";
- plevel->song_title = "Mortimers_chipdisko.mod";
- plevel->bkgd_image = "arctis.png";
- plevel->width = 21;
- plevel->time_left = 100;
- plevel->gravity = 10.;
- plevel->bkgd_red = 0;
- plevel->bkgd_green = 0;
- plevel->bkgd_blue = 0;
-
- for(i = 0; i < 15; ++i)
- {
- plevel->ia_tiles[i] = (unsigned int*) malloc((plevel->width+1)*sizeof(unsigned int));
- plevel->ia_tiles[i][plevel->width] = (unsigned int) '\0';
- for(y = 0; y < plevel->width; ++y)
- plevel->ia_tiles[i][y] = (unsigned int) '.';
- plevel->ia_tiles[i][plevel->width] = (unsigned int) '\0';
-
- plevel->bg_tiles[i] = (unsigned int*) malloc((plevel->width+1)*sizeof(unsigned int));
- plevel->bg_tiles[i][plevel->width] = (unsigned int) '\0';
- for(y = 0; y < plevel->width; ++y)
- plevel->bg_tiles[i][y] = (unsigned int) '.';
- plevel->bg_tiles[i][plevel->width] = (unsigned int) '\0';
-
- plevel->fg_tiles[i] = (unsigned int*) malloc((plevel->width+1)*sizeof(unsigned int));
- plevel->fg_tiles[i][plevel->width] = (unsigned int) '\0';
- 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';
- }
-}
-
-/* Load data for this level: */
-/* Returns -1, if the loading of the level failed. */
-int level_load(st_level* plevel, const char *subset, int level)
-{
- char filename[1024];
-
- /* Load data file: */
-
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset, level);
- if(!faccessible(filename))
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset, level);
-
- return level_load(plevel, filename);
-}
-
-int level_load(st_level* plevel, const char* filename)
-{
- int x, y, j;
- FILE * fi;
- lisp_object_t* root_obj = 0;
- fi = fopen(filename, "r");
- if (fi == NULL)
- {
- perror(filename);
- 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);
- }
-
- vector<int> ia_tm;
- vector<int> dn_tm;
- vector<int> bg_tm;
- vector<int> fg_tm;
-
- if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
- {
- LispReader reader(lisp_cdr(root_obj));
-
- reader.read_int("width", &plevel->width);
- reader.read_int("time", &plevel->time_left);
- reader.read_int("bkgd_red", &plevel->bkgd_red);
- reader.read_int("bkgd_green", &plevel->bkgd_green);
- reader.read_int("bkgd_blue", &plevel->bkgd_blue);
- reader.read_float("gravity", &plevel->gravity);
- reader.read_string("name", &plevel->name);
- reader.read_string("theme", &plevel->theme);
- reader.read_string("music", &plevel->song_title);
- reader.read_string("background", &plevel->bkgd_image);
- reader.read_string("particle_system", &plevel->particle_system);
- reader.read_int_vector("background-tm", &bg_tm);
- reader.read_int_vector("interactive-tm", &ia_tm);
- reader.read_int_vector("dynamic-tm", &dn_tm);
- reader.read_int_vector("foreground-tm", &fg_tm);
- }
-
-
- int i;
- for( 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) );
- }