- char filename[1024];
- char str[80];
-
- /* Save data file: */
- sprintf(str, "/levels/%s/", subset.c_str());
- fcreatedir(str);
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(),
- level);
- if(!fwriteable(filename))
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(),
- subset.c_str(), level);
-
- std::ofstream out(filename);
- if(!out.good()) {
- st_abort("Couldn't write file.", filename);
- }
- LispWriter writer(out);
-
- /* Write header: */
- writer.write_comment("SuperTux level made using the built-in leveleditor");
- writer.start_list("supertux-level");
-
- writer.write_int("version", 1);
- writer.write_string("name", name);
- writer.write_string("author", author);
- writer.write_string("music", song_title);
- writer.write_string("background", bkgd_image);
- writer.write_string("particle_system", particle_system);
- writer.write_int("bkgd_speed", bkgd_speed);
- writer.write_int("bkgd_red_top", bkgd_top.red);
- writer.write_int("bkgd_green_top", bkgd_top.green);
- writer.write_int("bkgd_blue_top", bkgd_top.blue);
- writer.write_int("bkgd_red_bottom", bkgd_bottom.red);
- writer.write_int("bkgd_green_bottom", bkgd_bottom.green);
- writer.write_int("bkgd_blue_bottom", bkgd_bottom.blue);
- writer.write_int("time", time_left);
- writer.write_int("width", width);
- writer.write_int("height", height);
- writer.write_bool("back_scrolling", back_scrolling);
- writer.write_float("hor_autoscroll_speed", hor_autoscroll_speed);
- writer.write_float("gravity", gravity);
-
- writer.write_int_vector("background-tm", bg_tiles);
- writer.write_int_vector("interactive-tm", ia_tiles);
- writer.write_int_vector("foreground-tm", fg_tiles);
-
- writer.start_list("reset-points");
- for(std::vector<ResetPoint>::iterator i = reset_points.begin();
- i != reset_points.end(); ++i) {
- writer.start_list("point");
- writer.write_int("x", i->x);
- writer.write_int("y", i->y);
- writer.end_list("point");
- }
- writer.end_list("reset-points");
-
- // write objects
- writer.start_list("objects");
- // pick all objects that can be written into a levelfile
- for(std::vector<GameObject*>::iterator it = world->gameobjects.begin();
- it != world->gameobjects.end(); ++it) {
- Serializable* serializable = dynamic_cast<Serializable*> (*it);
- if(serializable)
- serializable->write(writer);