- char filename[1024];
-
- // Load data file:
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), level);
- if(!faccessible(filename))
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset.c_str(), level);
-
- return load(filename, world);
-}
-
-int
-Level::load(const std::string& filename, World* world)
-{
- lisp_object_t* root_obj = lisp_read_from_file(filename);
- if (!root_obj)
- {
- std::cout << "Level: Couldn't load file: " << filename << std::endl;
- return -1;
- }
-
- 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;
- }
-
- int version = 0;
- if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
- {
- LispReader reader(lisp_cdr(root_obj));
- version = 0;
- reader.read_int("version", &version);
- 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;
- if (!reader.read_int("start_pos_y", &start_pos_y)) start_pos_y = 170;
- time_left = 500;
- if(!reader.read_int("time", &time_left)) {
- printf("Warning no time specified for level.\n");
- }
-
- height = 15;
- reader.read_int("height", &height);
-
- back_scrolling = false;
- reader.read_bool("back_scrolling", &back_scrolling);
-
- hor_autoscroll_speed = 0;
- reader.read_float("hor_autoscroll_speed", &hor_autoscroll_speed);
-
- bkgd_speed = 50;
- reader.read_int("bkgd_speed", &bkgd_speed);
-
-
- bkgd_top.red = bkgd_top.green = bkgd_top.blue = 0;
- reader.read_int("bkgd_red_top", &bkgd_top.red);
- reader.read_int("bkgd_green_top", &bkgd_top.green);
- reader.read_int("bkgd_blue_top", &bkgd_top.blue);
-
- bkgd_bottom.red = bkgd_bottom.green = bkgd_bottom.blue = 0;
- reader.read_int("bkgd_red_bottom", &bkgd_bottom.red);
- reader.read_int("bkgd_green_bottom", &bkgd_bottom.green);
- reader.read_int("bkgd_blue_bottom", &bkgd_bottom.blue);
-
- gravity = 10;
- reader.read_float("gravity", &gravity);
- name = "Noname";
- reader.read_string("name", &name);
- author = "unknown author";
- reader.read_string("author", &author);
- song_title = "";
- reader.read_string("music", &song_title);
- bkgd_image = "";
- reader.read_string("background", &bkgd_image);
- particle_system = "";
- reader.read_string("particle_system", &particle_system);
-
- reader.read_int_vector("background-tm", &bg_tiles);
- if(int(bg_tiles.size()) != width * height)
- st_abort("Wrong size of backgroundtilemap", "");
-
- if (!reader.read_int_vector("interactive-tm", &ia_tiles))
- reader.read_int_vector("tilemap", &ia_tiles);
- if(int(ia_tiles.size()) != width * height)
- st_abort("Wrong size of interactivetilemap", "");
-
- reader.read_int_vector("foreground-tm", &fg_tiles);
- if(int(fg_tiles.size()) != width * height)
- st_abort("Wrong size of foregroundtilemap", "");
-
- { // Read ResetPoints
- lisp_object_t* cur = 0;
- if (reader.read_lisp("reset-points", &cur))
- {
- while (!lisp_nil_p(cur))
- {
- lisp_object_t* data = lisp_car(cur);
-
- ResetPoint pos;
-
- LispReader reader(lisp_cdr(data));
- if (reader.read_int("x", &pos.x)
- && reader.read_int("y", &pos.y))
- {
- reset_points.push_back(pos);
- }
-
- cur = lisp_cdr(cur);
- }
- }
- }
-
- { // Read BadGuys
- lisp_object_t* cur = 0;
- if (reader.read_lisp("objects", &cur))
- {
- if(world)
- world->parse_objects(cur);
- }
- }
-
-#if 0 // TODO fix this or remove it
- // Convert old levels to the new tile numbers
- if (version == 0)
- {
- std::map<char, int> transtable;
- transtable['.'] = 0;
- transtable['x'] = 104;
- transtable['X'] = 77;
- transtable['y'] = 78;
- transtable['Y'] = 105;
- transtable['A'] = 83;
- transtable['B'] = 102;
- transtable['!'] = 103;
- transtable['a'] = 84;
- transtable['C'] = 85;
- transtable['D'] = 86;
- transtable['E'] = 87;
- transtable['F'] = 88;
- transtable['c'] = 89;
- transtable['d'] = 90;
- transtable['e'] = 91;
- transtable['f'] = 92;