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);
148 data::characters[data::the_player->
get_id ().c_str ()] = data::the_player;
154 mynpc->character_base::get_state (in);
157 data::characters[mynpc->
get_id ().c_str ()] = mynpc;
172 filepath = saves[pos]->directory ();
173 filepath +=
"/quest.data";
178 cerr <<
"Couldn't open \"" << filepath <<
" - stopping\n" << endl;
196 data::quests[myquest->name.c_str ()] = myquest;
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);
408 for (itc = data::characters.begin (); itc != data::characters.end (); itc++)
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";
440 for (itq = data::quests.begin (); itq != data::quests.end (); itq++)
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);
627 for (itc = data::characters.begin (); itc != data::characters.end (); itc++)
629 itc->second->remove_from_map ();
632 data::characters.clear ();
634 data::the_player = NULL;
638 for (itq = data::quests.begin (); itq != data::quests.end (); itq++)
640 data::quests.clear ();
static bool save(u_int32 pos, string desc, string time)
Save a game.
Class to write data from a Gzip compressed file.
void close()
Close the file that was opened.
void set_description(string)
Sets the description for this game.
Declares the event_handler class.
static void cleanup()
Cleanup the saved game array.
Class to read data from a Gzip compressed file.
static bool load(u_int32 pos)
Loads a previously saved game.
const char * directory()
A bunch of methods to access the private attributes.
static void put_state(ogzstream &file)
Save achievement data to stream.
Class holding game characters.
static bool load_characters(u_int32 pos)
Load the characters state from a saved game.
static bool get_state(igzstream &file)
Load achievement data from stream.
gamedata()
Default constructor.
static bool init(string udir, string gdir, string gname, u_int8 qload)
Initialise the saved games array.
string get_id()
Returns an unique identifier of the character.
#define u_int32
32 bits long unsigned integer
#define u_int8
8 bits long unsigned integer
Stores objects of any kind.
static bool load_audio(u_int32 pos)
Load the audio system state from a saved game.
Manages in-game achievements.
static gamedata * next_save()
Returns a pointer to the next saved game.
bool open(const string &fname)
Opens a file for write access.
bool open(const string &fname)
Opens a file for read access.
static bool get_version(igzstream &file, u_int16 min, u_int16 max, string name)
Declares the gamedata and data classes.
bool is_open()
Returns whether the file is opened or not.
static bool load_newest()
Loads the most recent saved game.
Defines the python class. This file is named this way so it doesn't conflicts with Python...
bool get(igzstream &)
Load a record from an opened file.
static bool load_quests(u_int32 pos)
Load the quests state from a saved game.
static void put_version(ogzstream &file, u_int16 version)
Sets the version number of a file.
s_int8 put_state(ogzstream &file)
Save the engine's state.
void set_gametime(string)
Set the in-game time of the saved game.
static void unload()
Unloads the current game, resetting the engine to it's initial state.
void put(ogzstream &)
Save a record to an opened file.
static bool load_mapengine(u_int32 pos)
Load the mapengine state from a saved game.
void set_directory(string)
Sets the directory for this game.
Contains all the attributes related to a saved game and the high level methods for loading/saving the...