• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

gamedata.h

Go to the documentation of this file.
00001 /*
00002    $Id: gamedata.h,v 1.15 2003/02/23 23:14:34 ksterker Exp $
00003 
00004    Copyright (C) 2001/2002 by Kai Sterker <kaisterker@linuxgames.com>
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 
00016 /**
00017  * @file   gamedata.h
00018  * @author Kai Sterker <kaisterker@linuxgames.com>
00019  * 
00020  * @brief  Declares the gamedata and data classes.
00021  * 
00022  * 
00023  */ 
00024 
00025 
00026 #ifndef GAMEDATA_H__
00027 #define GAMEDATA_H__
00028 
00029 #include "quest.h"
00030 #include "character.h"
00031 #include "adonthell.h"
00032 
00033 /**
00034  * Contains all the attributes related to a saved %game and the
00035  * high level methods for loading/saving the %game.
00036  *
00037  * A word about saved games: all games are stored inside
00038  * $HOME/.adonthell/ into a individual subdirectory, consisting
00039  * of the %game's name (e.g. wastesedge) with the appendix "-save-xxx"
00040  * where "xxx" is a number between 001 and 999. All %data that belongs
00041  * to a saved %game is contained in that directory, thus allowing
00042  * to copy individual games to another machine and/or user.
00043  *
00044  * The numbering of the %game directories has no special meaning. Saved
00045  * games are recognized by the first part of their name, and saving a
00046  * new %game will never overwrite an existing.
00047  */ 
00048 class gamedata
00049 {
00050 public:
00051     /**
00052      * Default constructor.
00053      * 
00054      */ 
00055     gamedata ();
00056 
00057 #ifndef SWIG
00058     /** 
00059      * Alternate constructor.
00060      *
00061      * @attention not available from %Python!
00062      * 
00063      * @param desc description of the saved %game.
00064      * @param dir directory of the saved %game.
00065      * @param time Textual representation of in-game time.
00066      */
00067     gamedata (string desc, string dir, string time); 
00068 #endif
00069 
00070     /** 
00071      * Destructor.
00072      * 
00073      */
00074     ~gamedata ();
00075 
00076     /** 
00077      * Save a record to an opened file.
00078      * 
00079      * @param ogzstream& opened file to save to.
00080      */
00081     void put (ogzstream&);
00082 
00083     /** 
00084      * Load a record from an opened file.
00085      * 
00086      * @param igzstream& opened file to load from.
00087      * 
00088      * @return true in case of success, false otherwise.
00089      */
00090     bool get (igzstream&);
00091 
00092     /**
00093      * A bunch of methods to access the private attributes.
00094      * 
00095      */
00096     //@{
00097     
00098     /** 
00099      * Returns the directory where the saved %game lies.
00100      * 
00101      * @return Directory where the saved %game lies.
00102      */
00103     const char* directory () { return Directory.c_str (); }
00104 
00105     /**
00106      * Returns the description of the saved %game.
00107      *
00108      * @return Description of the saved %game.
00109      */ 
00110     const char* description () { return Description.c_str (); }
00111 
00112     /** 
00113      * Returns the location of the saved %game.
00114      * 
00115      * @return Location of the saved %game.
00116      */
00117     const char* location () { return Location.c_str (); }
00118 
00119     /** 
00120      * Returns the in-game time of the saved %game.
00121      * 
00122      * @return In-game time of the saved %game.
00123      */
00124     const char* gametime () { return Gametime.c_str (); }
00125 
00126     /**
00127      * Returns the (real) time when this game has been saved
00128      *
00129      * @return (Real) time when this game has been saved
00130      */
00131     u_int32 timestamp () { return Timestamp; }
00132     
00133     /** 
00134      * Sets the description for this %game.
00135      * 
00136      * @param string New description for this %game.
00137      */
00138     void set_description (string);
00139 
00140     /** 
00141      * Sets the directory for this %game.
00142      * 
00143      * @param string New directory for this %game.
00144      */
00145     void set_directory (string);
00146 
00147     /** 
00148      * Set the in-game time of the saved %game.
00149      * 
00150      * @param string In-game time of the saved %game.
00151      */
00152     void set_gametime (string);
00153     //@}
00154 
00155     /** 
00156      * Initialise the saved games array. Searches the user directory
00157      * for available save games and loads their description.
00158      *
00159      * @param udir The user directory, usually $HOME/.adonthell
00160      * @param gdir The %game data directory, usually /usr/local/share/adonthell
00161      * @param gname The name of the %game we are running, e.g. wastesedge
00162      * @param qload Whether quick-loading should be enabled or disabled
00163      *
00164      * @return \e true in case of success, false otherwise.
00165      */
00166     static bool init (string udir, string gdir, string gname, u_int8 qload); 
00167     
00168     /** 
00169      * Cleanup the saved %game array.
00170      * 
00171      */
00172     static void cleanup (); 
00173 
00174     /** 
00175      * Load the characters state from a saved %game.
00176      * 
00177      * @param pos Slot number to load.
00178      * 
00179      * @return \e true in case of success, \e false otherwise.
00180      */
00181     static bool load_characters (u_int32 pos); 
00182  
00183     /** 
00184      * Load the quests state from a saved %game.
00185      * 
00186      * @param pos Slot number to load.
00187      * 
00188      * @return \e true in case of success, \e false otherwise.
00189      */
00190     static bool load_quests (u_int32 pos); 
00191 
00192     /** 
00193      * Load the mapengine state from a saved %game.
00194      * 
00195      * @param pos Slot number to load.
00196      * 
00197      * @return \e true in case of success, \e false otherwise.
00198      */
00199     static bool load_mapengine (u_int32 pos); 
00200 
00201     /** 
00202      * Load the audio system state from a saved %game.
00203      * 
00204      * @param pos Slot number to load.
00205      * 
00206      * @return \e true in case of success, \e false otherwise.
00207      */
00208     static bool load_audio (u_int32 pos); 
00209 
00210     /** 
00211      * Loads a previously saved %game. Slot 0 points to the
00212      * initial %game %data and needs to be loaded when starting
00213      * a fresh %game.
00214      * 
00215      * @param pos Slot number to load.
00216      * 
00217      * @return \e true in case of success, \e false otherwise.
00218      */
00219     static bool load (u_int32 pos); 
00220     
00221     /** 
00222      * Loads the most recent saved %game. This method only takes
00223      * games created by the player into account, not the initial
00224      * saved %game.
00225      * 
00226      * @return \e true in case of success, \e false otherwise.
00227      */
00228     static bool load_newest (); 
00229 
00230     /** 
00231      * Save a %game. When given a slot number in the range of
00232      * the available saved games, the according %game will be
00233      * overwritten, otherwise a new saved %game is created.
00234      * Saving to slot 0 is not possible, as it contains the
00235      * initial %game %data.
00236      * 
00237      * @param pos Slot number where to save to.
00238      * @param desc Description of the %game to be saved.
00239      * @param time Textual representation of in-game time.
00240      * 
00241      * @return \e true in case of success, false otherwise.
00242      */
00243     static bool save (u_int32 pos, string desc, string time);
00244     
00245     /**
00246      * Unloads the current %game, resetting the engine to it's
00247      * initial state.
00248      * 
00249      */ 
00250     static void unload (); 
00251 
00252     /** 
00253      * Returns a pointer to the next saved %game.
00254      * 
00255      * 
00256      * @return Next saved %game.
00257      */
00258     static gamedata* next_save ();
00259     
00260     /** 
00261      * Returns the user %data directory ($HOME/.adonthell).
00262      * 
00263      * 
00264      * @return user %data directory.
00265      */
00266     static string user_data_dir () 
00267     {
00268         return user_data_dir_; 
00269     }
00270     
00271     /** 
00272      * Returns the %game %data directory.
00273      * 
00274      * 
00275      * @return %game %data directory.
00276      */
00277     static string game_data_dir () 
00278     {
00279         return game_data_dir_; 
00280     }
00281 
00282     /** 
00283      * Returns a pointer to a saved %game.
00284      * 
00285      * @param pos Slot number to return.
00286      * 
00287      * @return Pointer to the saved %game at position \pos.
00288      */
00289     static gamedata * get_saved_game (u_int32 pos) 
00290     {
00291         return saves[pos];
00292     }
00293 
00294     /** 
00295      * Returns the global quests dictionary.
00296      * 
00297      * 
00298      * @return Global quests dictionary.
00299      */
00300     static dictionary <quest *> quests ()
00301     {
00302         return data::quests;
00303     }
00304 
00305     /** 
00306      * Returns the player %character.
00307      * 
00308      * 
00309      * @return Player %character.
00310      */
00311     static character* player ()
00312     {
00313         return data::the_player;
00314     }
00315  
00316     /**
00317      * Returns a certain NPC when given the name. Use player () to get
00318      * the player %character, as his/her name will be set at runtime.
00319      *
00320      * @param name The name of the %character to return
00321      *
00322      * @return a %character.
00323      */
00324     static character* get_character (string name)
00325     {
00326         return data::characters [name]; 
00327     }
00328 
00329     /**
00330      * Returns a certain quest when given the name.
00331      *
00332      * @param name The name of the %quest to return
00333      *
00334      * @return a %quest
00335      */
00336     static quest* get_quest (string name)
00337     {
00338         return data::quests [name];
00339     }
00340 
00341     /** 
00342      * Returns the characters dictionary
00343      * 
00344      * 
00345      * @return Characters dictionary.
00346      */
00347     static dictionary<character*> characters ()
00348     {
00349         return data::characters;
00350     }
00351 
00352     /** 
00353      * Returns a pointer to the global game engine.
00354      * 
00355      * 
00356      * @return Pointer to the global game engine.
00357      */
00358     static adonthell* engine ()
00359     {
00360         return data::engine;
00361     }
00362 
00363 private:
00364 #ifndef SWIG
00365     string Directory;               // the game's location on the harddisk
00366     string Description;             // user supplied description of the game
00367     string Location;                // the map or area the player is on
00368     string Gametime;                // the gametime of the saved game
00369     u_int32 Timestamp;              // time of last save to this file
00370     
00371     static string game_name; 
00372     static u_int8 quick_load;
00373     
00374     /** 
00375      * Keeps track of available saved games.
00376      * 
00377      */
00378     static vector<gamedata*> saves; 
00379      
00380     /**
00381      * $HOME/.adonthell
00382      * 
00383      */ 
00384     static string user_data_dir_; 
00385 
00386     /**
00387      * Game data directory.
00388      * 
00389      */ 
00390     static string game_data_dir_;
00391 #endif
00392 };
00393 
00394 #endif // GAMEDATA_H__

Generated on Mon Sep 12 2011 for Adonthell by  doxygen 1.7.1