45 #define ENGINE_DAT_VER 5
46 #define AUDIO_DAT_VER 2
47 #define CHAR_DAT_VER 4
48 #define QUEST_DAT_VER 1
49 #define SAVE_DAT_VER 3
50 #define ACVMENT_DAT_VER 1
52 vector<gamedata*> gamedata::saves;
53 string gamedata::user_data_dir_;
54 string gamedata::game_data_dir_;
55 string gamedata::game_name;
56 u_int8 gamedata::quick_load;
95 Timestamp = time (NULL);
126 filepath = saves[pos]->directory ();
127 filepath +=
"/character.data";
132 cerr <<
"Couldn't open \"" << filepath <<
"\" - stopping\n" << endl;
147 data::the_player->character_base::get_state (in);
154 mynpc->character_base::get_state (in);
172 filepath = saves[pos]->directory ();
173 filepath +=
"/quest.data";
178 cerr <<
"Couldn't open \"" << filepath <<
" - stopping\n" << endl;
210 filepath = saves[pos]->directory();
211 filepath +=
"/mapengine.data";
216 cerr <<
"Couldn't open \"" << filepath <<
" - stopping\n" << endl;
226 if (!data::engine->get_state(in))
228 cerr <<
"Couldn't load \"" << filepath <<
" - stopping\n" << endl;
243 filepath = saves[pos]->directory();
244 filepath +=
"/audio.data";
249 cerr <<
"Couldn't open \"" << filepath <<
" - stopping\n" << endl;
259 if (!audio::get_state (in))
261 cerr <<
"Couldn't load \"" << filepath <<
" - stopping\n" << endl;
270 bool gamedata::load_achievements (
u_int32 pos)
276 filepath = saves[pos]->directory();
277 filepath +=
"/achievements.data";
282 cerr <<
"Couldn't open \"" << filepath <<
" - stopping\n" << endl;
294 cerr <<
"Couldn't load \"" << filepath <<
" - stopping\n" << endl;
308 if (!load_characters (pos))
return false;
309 if (!load_quests (pos))
return false;
310 if (!load_mapengine (pos))
return false;
311 if (!load_audio (pos))
return false;
312 if (!load_achievements(pos))
return false;
320 if (!quick_load || saves.size () <= 1)
return false;
326 for (vector<gamedata*>::iterator i = saves.begin (); i != saves.end (); i++)
328 if ((*i)->timestamp () > timestamp)
330 timestamp = (*i)->timestamp ();
337 return load (newest);
349 if (pos == 0)
return false;
352 if (pos >= saves.size ())
360 sprintf(t,
"%03i", pos++);
361 filepath = user_data_dir ();
362 filepath +=
"/" + game_name +
"-save-";
366 success = mkdir (filepath.c_str());
368 success = mkdir (filepath.c_str(), 0700);
374 cerr <<
"Save failed - seems like you have no write permission in\n"
375 << user_data_dir () << endl;
381 gdata =
new gamedata (filepath, desc, time);
392 filepath +=
"/character.data";
393 file.
open (filepath);
397 cerr <<
"Couldn't create \"" << filepath <<
"\" - save failed\n";
404 data::the_player->character_base::put_state (file);
411 if (itc->second == (
character*) data::the_player)
continue;
418 itc->second->character_base::put_state (file);
428 filepath +=
"/quest.data";
429 file.open (filepath);
431 if (!file.is_open ())
433 cerr <<
"Couldn't create \"" << filepath <<
"\" - save failed\n";
447 itq->second->save (file);
457 filepath +=
"/mapengine.data";
458 file.open (filepath);
460 if (!file.is_open ())
462 cerr <<
"Couldn't create \"" << filepath <<
"\" - save failed\n";
472 filepath +=
"/audio.data";
473 file.open (filepath);
475 if (!file.is_open ())
477 cerr <<
"Couldn't create \"" << filepath <<
"\" - save failed\n";
482 audio::put_state (file);
487 filepath +=
"/achievements.data";
488 file.open (filepath);
490 if (!file.is_open ())
492 cerr <<
"Couldn't create \"" << filepath <<
"\" - save failed\n";
502 filepath +=
"/save.data";
504 file.open (filepath);
505 if (!file.is_open ())
507 cerr <<
"Couldn't create \"" << filepath <<
"\" - save failed\n";
516 if (pos >= saves.size ()) saves.push_back (gdata);
523 static vector<gamedata*>::iterator i = saves.begin ();
524 static u_int32 size = saves.size ();
527 if (size != saves.size ())
529 size = saves.size ();
534 if (++i == saves.end ())
548 struct dirent *dirent;
552 user_data_dir_ = udir;
553 game_data_dir_ = gdir;
558 if (chdir (game_data_dir ().c_str ()))
560 fprintf (stderr,
"Seems like %s is no valid data directory.\n", game_data_dir ().c_str ());
561 fprintf (stderr,
"Please make sure that your Adonthell installation is correct.\n");
566 gdata =
new gamedata (gdir,
"Start New Game",
"Day 0 - 00:00");
567 saves.push_back (gdata);
571 if ((dir = opendir (user_data_dir ().c_str ())) != NULL)
573 while ((dirent = readdir (dir)) != NULL)
575 string filepath = user_data_dir () +
"/";
576 filepath += dirent->d_name;
578 string name_save = game_name +
"-save-";
580 if (stat (filepath.c_str (), &statbuf) != -1 && S_ISDIR (statbuf.st_mode) &&
581 strncmp (name_save.c_str (), dirent->d_name, name_save.length ()) == 0)
584 filepath +=
"/save.data";
591 filepath = user_data_dir ();
593 filepath += dirent->d_name;
599 saves.push_back (gdata);
614 for (vector<gamedata*>::iterator i = saves.begin (); i != saves.end (); i++)
623 audio::fade_out_background (500);
629 itc->second->remove_from_map ();
634 data::the_player = NULL;