st_pause_ticks_stop();
break;
case 3:
- update_load_save_game_menu(save_game_menu, false);
+ // FIXME:
+ //update_load_save_game_menu(save_game_menu);
break;
case 4:
- update_load_save_game_menu(load_game_menu, true);
+ update_load_save_game_menu(load_game_menu);
break;
case 7:
st_pause_ticks_stop();
std::string slotinfo(int slot)
{
- FILE* fi;
+ char tmp[1024];
char slotfile[1024];
- char tmp[200];
- char str[5];
- int slot_level;
- sprintf(slotfile,"%s/slot%d.save",st_save_dir,slot);
+ sprintf(slotfile,"%s/slot%d.stsg",st_save_dir,slot);
- fi = fopen(slotfile, "rb");
-
- sprintf(tmp,"Slot %d - ",slot);
-
- if (fi == NULL)
- {
- strcat(tmp,"Free");
- }
+ if (access(slotfile, F_OK) == 0)
+ sprintf(tmp,"Slot %d - Savegame",slot);
else
- {
- fgets(str, 100, fi);
- str[strlen(str)-1] = '\0';
- strcat(tmp, str);
- strcat(tmp, " / Level:");
- fread(&slot_level,sizeof(int),1,fi);
- sprintf(str,"%d",slot_level);
- strcat(tmp,str);
- fclose(fi);
- }
+ sprintf(tmp,"Slot %d - Free",slot);
return tmp;
}
+
*/
#include <assert.h>
+#include <stdio.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
highscore_menu->additem(MN_TEXTFIELD,"Enter your name:",0,0);
}
-void update_load_save_game_menu(Menu* pmenu, int load)
+void update_load_save_game_menu(Menu* pmenu)
{
for(int i = 2; i < 7; ++i)
{
// FIXME: Insert a real savegame struct/class here instead of
// doing string vodoo
- std::string tmp = slotinfo(i-1);
-
- if(load && tmp.length() == strlen("Slot X - Free"))
- pmenu->item[i].kind = MN_ACTION;
- else
- pmenu->item[i].kind = MN_ACTION;
+ std::string tmp = slotinfo(i - 1);
+ pmenu->item[i].kind = MN_ACTION;
pmenu->item[i].change_text(tmp.c_str());
}
}
if(slot != -1)
{
- // FIXME: Insert a real savegame struct/class here instead of
- // doing string vodoo
- std::string tmp = slotinfo(slot-1);
+ WorldMapNS::WorldMap worldmap;
+
+ char slotfile[1024];
+ snprintf(slotfile, 1024, "%s/slot%d.stsg", st_save_dir, slot-1);
+
+ worldmap.loadgame(slotfile);
+
+ worldmap.display();
+
+ show_menu = true;
+ Menu::set_current(main_menu);
- if (tmp.length() == strlen("Slot X - Free"))
- { // Slot is free, so start a new game
- worldmap_run();
-
- show_menu = true;
- Menu::set_current(main_menu);
- }
- else
- {
- puts("Warning: Loading games isn't supported at the moment");
- }
st_pause_ticks_stop();
return true;
}
/** Return true if the gameloop() was entered, false otherwise */
bool process_load_game_menu();
-void update_load_save_game_menu(Menu* pmenu, int load);
+void update_load_save_game_menu(Menu* pmenu);
void parseargs(int argc, char * argv[]);
#endif /*SUPERTUX_SETUP_H*/
if (launch_worldmap_mode)
{
- worldmap_run();
+ WorldMapNS::WorldMap worldmap;
+ worldmap.display();
}
else if (level_startup_file)
{
#endif
case 0:
// Start Game, ie. goto the slots menu
- update_load_save_game_menu(load_game_menu, true);
+ update_load_save_game_menu(load_game_menu);
break;
case 1:
// Contrib Menu
play_music(song, 1);
show_menu = 0;
menu_reset();
- savegame(std::string(st_save_dir) + "/slot1.stsg");
+ if (!savegame_file.empty())
+ savegame(savegame_file);
return;
}
}
void
WorldMap::savegame(const std::string& filename)
{
+ std::cout << "savegame: " << filename << std::endl;
std::ofstream out(filename.c_str());
+ int nb_solved_levels = 0;
+ for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+ {
+ if (i->solved)
+ ++nb_solved_levels;
+ }
+
out << "(supertux-savegame\n"
<< " (version 1)\n"
+ << " (title \"Icyisland - " << nb_solved_levels << "/" << levels.size() << "\")\n"
<< " (lives " << player_status.lives << ")\n"
<< " (score " << player_status.score << ")\n"
<< " (distros " << player_status.distros << ")\n"
- << " (tux (x " << tux->get_tile_pos().x << ") (y " << tux->get_tile_pos().y << ")\n"
+ << " (tux (x " << tux->get_tile_pos().x << ") (y " << tux->get_tile_pos().y << "))\n"
<< " (levels\n";
for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
<< " )\n\n;; EOF ;;" << std::endl;
}
-} // namespace WorldMapNS
-
-void worldmap_run()
+void
+WorldMap::loadgame(const std::string& filename)
{
- WorldMapNS::WorldMap worldmap;
+ std::cout << "loadgame: " << filename << std::endl;
+ savegame_file = filename;
+
+ if (access(filename.c_str(), F_OK) == 0)
+ {
+ lisp_object_t* cur = lisp_read_from_file(filename);
+
+ if (strcmp(lisp_symbol(lisp_car(cur)), "supertux-savegame") != 0)
+ return;
+
+ cur = lisp_cdr(cur);
+ LispReader reader(cur);
- worldmap.display();
+ reader.read_int("lives", &player_status.lives);
+ reader.read_int("score", &player_status.score);
+ reader.read_int("distros", &player_status.distros);
+
+ lisp_object_t* tux_cur = 0;
+ if (reader.read_lisp("tux", &tux_cur))
+ {
+ Point p;
+ LispReader tux_reader(tux_cur);
+ tux_reader.read_int("x", &p.x);
+ tux_reader.read_int("y", &p.y);
+
+ tux->set_tile_pos(p);
+ }
+
+ lisp_object_t* level_cur = 0;
+ if (reader.read_lisp("levels", &level_cur))
+ {
+ while(level_cur)
+ {
+ std::string name;
+ bool solved = false;
+ LispReader level_reader(level_cur);
+ level_reader.read_string("name", &name);
+ level_reader.read_bool("solved", &solved);
+
+ for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+ {
+ if (name == i->name)
+ i->solved = solved;
+ }
+
+ level_cur = lisp_cdr(level_cur);
+ }
+ }
+ }
}
+} // namespace WorldMapNS
+
/* EOF */
bool enter_level;
Point offset;
+ std::string savegame_file;
void draw_status();
public:
bool path_ok(Direction direction, Point pos, Point* new_pos);
void savegame(const std::string& filename);
+ void loadgame(const std::string& filename);
};
} // namespace WorldMapNS
-void worldmap_run();
-
#endif
/* Local Variables: */