Adonthell  0.4
gamedata.h
Go to the documentation of this file.
1 /*
2  $Id: gamedata.h,v 1.15 2003/02/23 23:14:34 ksterker Exp $
3 
4  Copyright (C) 2001/2002 by Kai Sterker <kaisterker@linuxgames.com>
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 
16 /**
17  * @file gamedata.h
18  * @author Kai Sterker <kaisterker@linuxgames.com>
19  *
20  * @brief Declares the gamedata and data classes.
21  *
22  *
23  */
24 
25 
26 #ifndef GAMEDATA_H__
27 #define GAMEDATA_H__
28 
29 #include "quest.h"
30 #include "character.h"
31 #include "adonthell.h"
32 
33 /**
34  * Contains all the attributes related to a saved %game and the
35  * high level methods for loading/saving the %game.
36  *
37  * A word about saved games: all games are stored inside
38  * $HOME/.adonthell/ into a individual subdirectory, consisting
39  * of the %game's name (e.g. wastesedge) with the appendix "-save-xxx"
40  * where "xxx" is a number between 001 and 999. All %data that belongs
41  * to a saved %game is contained in that directory, thus allowing
42  * to copy individual games to another machine and/or user.
43  *
44  * The numbering of the %game directories has no special meaning. Saved
45  * games are recognized by the first part of their name, and saving a
46  * new %game will never overwrite an existing.
47  */
48 class gamedata
49 {
50 public:
51  /**
52  * Default constructor.
53  *
54  */
55  gamedata ();
56 
57 #ifndef SWIG
58  /**
59  * Alternate constructor.
60  *
61  * @attention not available from %Python!
62  *
63  * @param desc description of the saved %game.
64  * @param dir directory of the saved %game.
65  * @param time Textual representation of in-game time.
66  */
67  gamedata (string desc, string dir, string time);
68 #endif
69 
70  /**
71  * Destructor.
72  *
73  */
74  ~gamedata ();
75 
76  /**
77  * Save a record to an opened file.
78  *
79  * @param ogzstream& opened file to save to.
80  */
81  void put (ogzstream&);
82 
83  /**
84  * Load a record from an opened file.
85  *
86  * @param igzstream& opened file to load from.
87  *
88  * @return true in case of success, false otherwise.
89  */
90  bool get (igzstream&);
91 
92  /**
93  * A bunch of methods to access the private attributes.
94  *
95  */
96  //@{
97 
98  /**
99  * Returns the directory where the saved %game lies.
100  *
101  * @return Directory where the saved %game lies.
102  */
103  const char* directory () { return Directory.c_str (); }
104 
105  /**
106  * Returns the description of the saved %game.
107  *
108  * @return Description of the saved %game.
109  */
110  const char* description () { return Description.c_str (); }
111 
112  /**
113  * Returns the location of the saved %game.
114  *
115  * @return Location of the saved %game.
116  */
117  const char* location () { return Location.c_str (); }
118 
119  /**
120  * Returns the in-game time of the saved %game.
121  *
122  * @return In-game time of the saved %game.
123  */
124  const char* gametime () { return Gametime.c_str (); }
125 
126  /**
127  * Returns the (real) time when this game has been saved
128  *
129  * @return (Real) time when this game has been saved
130  */
131  u_int32 timestamp () { return Timestamp; }
132 
133  /**
134  * Sets the description for this %game.
135  *
136  * @param string New description for this %game.
137  */
138  void set_description (string);
139 
140  /**
141  * Sets the directory for this %game.
142  *
143  * @param string New directory for this %game.
144  */
145  void set_directory (string);
146 
147  /**
148  * Set the in-game time of the saved %game.
149  *
150  * @param string In-game time of the saved %game.
151  */
152  void set_gametime (string);
153  //@}
154 
155  /**
156  * Initialise the saved games array. Searches the user directory
157  * for available save games and loads their description.
158  *
159  * @param udir The user directory, usually $HOME/.adonthell
160  * @param gdir The %game data directory, usually /usr/local/share/adonthell
161  * @param gname The name of the %game we are running, e.g. wastesedge
162  * @param qload Whether quick-loading should be enabled or disabled
163  *
164  * @return \e true in case of success, false otherwise.
165  */
166  static bool init (string udir, string gdir, string gname, u_int8 qload);
167 
168  /**
169  * Cleanup the saved %game array.
170  *
171  */
172  static void cleanup ();
173 
174  /**
175  * Load the characters state from a saved %game.
176  *
177  * @param pos Slot number to load.
178  *
179  * @return \e true in case of success, \e false otherwise.
180  */
181  static bool load_characters (u_int32 pos);
182 
183  /**
184  * Load the quests state from a saved %game.
185  *
186  * @param pos Slot number to load.
187  *
188  * @return \e true in case of success, \e false otherwise.
189  */
190  static bool load_quests (u_int32 pos);
191 
192  /**
193  * Load the mapengine state from a saved %game.
194  *
195  * @param pos Slot number to load.
196  *
197  * @return \e true in case of success, \e false otherwise.
198  */
199  static bool load_mapengine (u_int32 pos);
200 
201  /**
202  * Load the audio system state from a saved %game.
203  *
204  * @param pos Slot number to load.
205  *
206  * @return \e true in case of success, \e false otherwise.
207  */
208  static bool load_audio (u_int32 pos);
209 
210  /**
211  * Loads a previously saved %game. Slot 0 points to the
212  * initial %game %data and needs to be loaded when starting
213  * a fresh %game.
214  *
215  * @param pos Slot number to load.
216  *
217  * @return \e true in case of success, \e false otherwise.
218  */
219  static bool load (u_int32 pos);
220 
221  /**
222  * Loads the most recent saved %game. This method only takes
223  * games created by the player into account, not the initial
224  * saved %game.
225  *
226  * @return \e true in case of success, \e false otherwise.
227  */
228  static bool load_newest ();
229 
230  /**
231  * Save a %game. When given a slot number in the range of
232  * the available saved games, the according %game will be
233  * overwritten, otherwise a new saved %game is created.
234  * Saving to slot 0 is not possible, as it contains the
235  * initial %game %data.
236  *
237  * @param pos Slot number where to save to.
238  * @param desc Description of the %game to be saved.
239  * @param time Textual representation of in-game time.
240  *
241  * @return \e true in case of success, false otherwise.
242  */
243  static bool save (u_int32 pos, string desc, string time);
244 
245  /**
246  * Unloads the current %game, resetting the engine to it's
247  * initial state.
248  *
249  */
250  static void unload ();
251 
252  /**
253  * Returns a pointer to the next saved %game.
254  *
255  *
256  * @return Next saved %game.
257  */
258  static gamedata* next_save ();
259 
260  /**
261  * Returns the user %data directory ($HOME/.adonthell).
262  *
263  *
264  * @return user %data directory.
265  */
266  static string user_data_dir ()
267  {
268  return user_data_dir_;
269  }
270 
271  /**
272  * Returns the %game %data directory.
273  *
274  *
275  * @return %game %data directory.
276  */
277  static string game_data_dir ()
278  {
279  return game_data_dir_;
280  }
281 
282  /**
283  * Returns a pointer to a saved %game.
284  *
285  * @param pos Slot number to return.
286  *
287  * @return Pointer to the saved %game at position \pos.
288  */
290  {
291  return saves[pos];
292  }
293 
294  /**
295  * Returns the global quests dictionary.
296  *
297  *
298  * @return Global quests dictionary.
299  */
301  {
302  return data::quests;
303  }
304 
305  /**
306  * Returns the player %character.
307  *
308  *
309  * @return Player %character.
310  */
311  static character* player ()
312  {
313  return data::the_player;
314  }
315 
316  /**
317  * Returns a certain NPC when given the name. Use player () to get
318  * the player %character, as his/her name will be set at runtime.
319  *
320  * @param name The name of the %character to return
321  *
322  * @return a %character.
323  */
324  static character* get_character (string name)
325  {
326  return data::characters [name];
327  }
328 
329  /**
330  * Returns a certain quest when given the name.
331  *
332  * @param name The name of the %quest to return
333  *
334  * @return a %quest
335  */
336  static quest* get_quest (string name)
337  {
338  return data::quests [name];
339  }
340 
341  /**
342  * Returns the characters dictionary
343  *
344  *
345  * @return Characters dictionary.
346  */
348  {
349  return data::characters;
350  }
351 
352  /**
353  * Returns a pointer to the global game engine.
354  *
355  *
356  * @return Pointer to the global game engine.
357  */
358  static adonthell* engine ()
359  {
360  return data::engine;
361  }
362 
363 private:
364 #ifndef SWIG
365  string Directory; // the game's location on the harddisk
366  string Description; // user supplied description of the game
367  string Location; // the map or area the player is on
368  string Gametime; // the gametime of the saved game
369  u_int32 Timestamp; // time of last save to this file
370 
371  static string game_name;
372  static u_int8 quick_load;
373 
374  /**
375  * Keeps track of available saved games.
376  *
377  */
378  static vector<gamedata*> saves;
379 
380  /**
381  * $HOME/.adonthell
382  *
383  */
384  static string user_data_dir_;
385 
386  /**
387  * Game data directory.
388  *
389  */
390  static string game_data_dir_;
391 #endif
392 };
393 
394 #endif // GAMEDATA_H__
Declares the character class.
static bool save(u_int32 pos, string desc, string time)
Save a game.
Definition: gamedata.cc:289
Class to write data from a Gzip compressed file.
Definition: fileops.h:223
void set_description(string)
Sets the description for this game.
Definition: gamedata.cc:97
static void cleanup()
Cleanup the saved game array.
Definition: gamedata.cc:545
static dictionary< character * > characters()
Returns the characters dictionary.
Definition: gamedata.h:347
Class to read data from a Gzip compressed file.
Definition: fileops.h:131
const char * description()
Returns the description of the saved game.
Definition: gamedata.h:110
static bool load(u_int32 pos)
Loads a previously saved game.
Definition: gamedata.cc:253
const char * directory()
A bunch of methods to access the private attributes.
Definition: gamedata.h:103
Class holding game characters.
Definition: character.h:35
static bool load_characters(u_int32 pos)
Load the characters state from a saved game.
Definition: gamedata.cc:112
Definition: quest.h:23
gamedata()
Default constructor.
Definition: gamedata.cc:55
static bool init(string udir, string gdir, string gname, u_int8 qload)
Initialise the saved games array.
Definition: gamedata.cc:477
#define u_int32
32 bits long unsigned integer
Definition: types.h:35
#define u_int8
8 bits long unsigned integer
Definition: types.h:29
Stores objects of any kind.
Definition: storage.h:227
u_int32 timestamp()
Returns the (real) time when this game has been saved.
Definition: gamedata.h:131
static bool load_audio(u_int32 pos)
Load the audio system state from a saved game.
Definition: gamedata.cc:223
static gamedata * next_save()
Returns a pointer to the next saved game.
Definition: gamedata.cc:454
const char * location()
Returns the location of the saved game.
Definition: gamedata.h:117
Declares the adonthell class.
static string game_data_dir()
Returns the game data directory.
Definition: gamedata.h:277
static character * get_character(string name)
Returns a certain NPC when given the name.
Definition: gamedata.h:324
static bool load_newest()
Loads the most recent saved game.
Definition: gamedata.cc:266
static quest * get_quest(string name)
Returns a certain quest when given the name.
Definition: gamedata.h:336
static gamedata * get_saved_game(u_int32 pos)
Returns a pointer to a saved game.
Definition: gamedata.h:289
static adonthell * engine()
Returns a pointer to the global game engine.
Definition: gamedata.h:358
~gamedata()
Destructor.
Definition: gamedata.cc:67
const char * gametime()
Returns the in-game time of the saved game.
Definition: gamedata.h:124
static character * player()
Returns the player character.
Definition: gamedata.h:311
static bool load_quests(u_int32 pos)
Load the quests state from a saved game.
Definition: gamedata.cc:155
void set_gametime(string)
Set the in-game time of the saved game.
Definition: gamedata.cc:107
static void unload()
Unloads the current game, resetting the engine to it&#39;s initial state.
Definition: gamedata.cc:553
void put(ogzstream &)
Save a record to an opened file.
Definition: gamedata.cc:84
static dictionary< quest * > quests()
Returns the global quests dictionary.
Definition: gamedata.h:300
static bool load_mapengine(u_int32 pos)
Load the mapengine state from a saved game.
Definition: gamedata.cc:192
This is the heart of the Adonthell engine.
Definition: adonthell.h:40
static string user_data_dir()
Returns the user data directory ($HOME/.adonthell).
Definition: gamedata.h:266
void set_directory(string)
Sets the directory for this game.
Definition: gamedata.cc:102
Contains all the attributes related to a saved game and the high level methods for loading/saving the...
Definition: gamedata.h:48