Adonthell  0.4
gamedata Class Reference

Contains all the attributes related to a saved game and the high level methods for loading/saving the game. More...

#include <gamedata.h>

Public Member Functions

 gamedata ()
 Default constructor. More...
 
 gamedata (string desc, string dir, string time)
 Alternate constructor. More...
 
 ~gamedata ()
 Destructor. More...
 
void put (ogzstream &)
 Save a record to an opened file. More...
 
bool get (igzstream &)
 Load a record from an opened file. More...
 
const char * directory ()
 A bunch of methods to access the private attributes. More...
 
const char * description ()
 Returns the description of the saved game. More...
 
const char * location ()
 Returns the location of the saved game. More...
 
const char * gametime ()
 Returns the in-game time of the saved game. More...
 
u_int32 timestamp ()
 Returns the (real) time when this game has been saved. More...
 
void set_description (string)
 Sets the description for this game. More...
 
void set_directory (string)
 Sets the directory for this game. More...
 
void set_gametime (string)
 Set the in-game time of the saved game. More...
 

Static Public Member Functions

static bool init (string udir, string gdir, string gname, u_int8 qload)
 Initialise the saved games array. More...
 
static void cleanup ()
 Cleanup the saved game array. More...
 
static bool load_characters (u_int32 pos)
 Load the characters state from a saved game. More...
 
static bool load_quests (u_int32 pos)
 Load the quests state from a saved game. More...
 
static bool load_mapengine (u_int32 pos)
 Load the mapengine state from a saved game. More...
 
static bool load_audio (u_int32 pos)
 Load the audio system state from a saved game. More...
 
static bool load_achievements (u_int32 pos)
 
static bool load (u_int32 pos)
 Loads a previously saved game. More...
 
static bool load_newest ()
 Loads the most recent saved game. More...
 
static bool save (u_int32 pos, string desc, string time)
 Save a game. More...
 
static void unload ()
 Unloads the current game, resetting the engine to it's initial state. More...
 
static gamedatanext_save ()
 Returns a pointer to the next saved game. More...
 
static string user_data_dir ()
 Returns the user data directory ($HOME/.adonthell). More...
 
static string game_data_dir ()
 Returns the game data directory. More...
 
static gamedataget_saved_game (u_int32 pos)
 Returns a pointer to a saved game. More...
 
static dictionary< quest * > quests ()
 Returns the global quests dictionary. More...
 
static characterplayer ()
 Returns the player character. More...
 
static characterget_character (string name)
 Returns a certain NPC when given the name. More...
 
static questget_quest (string name)
 Returns a certain quest when given the name. More...
 
static dictionary< character * > characters ()
 Returns the characters dictionary. More...
 
static adonthellengine ()
 Returns a pointer to the global game engine. More...
 

Detailed Description

Contains all the attributes related to a saved game and the high level methods for loading/saving the game.

A word about saved games: all games are stored inside $HOME/.adonthell/ into a individual subdirectory, consisting of the game's name (e.g. wastesedge) with the appendix "-save-xxx" where "xxx" is a number between 001 and 999. All data that belongs to a saved game is contained in that directory, thus allowing to copy individual games to another machine and/or user.

The numbering of the game directories has no special meaning. Saved games are recognized by the first part of their name, and saving a new game will never overwrite an existing.

Definition at line 52 of file gamedata.h.

Constructor & Destructor Documentation

◆ gamedata() [1/2]

gamedata::gamedata ( )

Default constructor.

Definition at line 61 of file gamedata.cc.

◆ gamedata() [2/2]

gamedata::gamedata ( string  desc,
string  dir,
string  time 
)

Alternate constructor.

Attention
not available from Python!
Parameters
descdescription of the saved game.
dirdirectory of the saved game.
timeTextual representation of in-game time.

Definition at line 65 of file gamedata.cc.

◆ ~gamedata()

gamedata::~gamedata ( )

Destructor.

Definition at line 73 of file gamedata.cc.

Member Function Documentation

◆ put()

void gamedata::put ( ogzstream file)

Save a record to an opened file.

Parameters
ogzstream&opened file to save to.

Definition at line 90 of file gamedata.cc.

◆ get()

bool gamedata::get ( igzstream file)

Load a record from an opened file.

Parameters
igzstream&opened file to load from.
Returns
true in case of success, false otherwise.

Definition at line 77 of file gamedata.cc.

◆ directory()

const char* gamedata::directory ( )
inline

A bunch of methods to access the private attributes.

Returns the directory where the saved game lies.

Returns
Directory where the saved game lies.

Definition at line 107 of file gamedata.h.

◆ description()

const char* gamedata::description ( )
inline

Returns the description of the saved game.

Returns
Description of the saved game.

Definition at line 114 of file gamedata.h.

◆ location()

const char* gamedata::location ( )
inline

Returns the location of the saved game.

Returns
Location of the saved game.

Definition at line 121 of file gamedata.h.

◆ gametime()

const char* gamedata::gametime ( )
inline

Returns the in-game time of the saved game.

Returns
In-game time of the saved game.

Definition at line 128 of file gamedata.h.

◆ timestamp()

u_int32 gamedata::timestamp ( )
inline

Returns the (real) time when this game has been saved.

Returns
(Real) time when this game has been saved

Definition at line 135 of file gamedata.h.

◆ set_description()

void gamedata::set_description ( string  desc)

Sets the description for this game.

Parameters
stringNew description for this game.

Definition at line 103 of file gamedata.cc.

◆ set_directory()

void gamedata::set_directory ( string  dir)

Sets the directory for this game.

Parameters
stringNew directory for this game.

Definition at line 108 of file gamedata.cc.

◆ set_gametime()

void gamedata::set_gametime ( string  time)

Set the in-game time of the saved game.

Parameters
stringIn-game time of the saved game.

Definition at line 113 of file gamedata.cc.

◆ init()

bool gamedata::init ( string  udir,
string  gdir,
string  gname,
u_int8  qload 
)
static

Initialise the saved games array.

Searches the user directory for available save games and loads their description.

Parameters
udirThe user directory, usually $HOME/.adonthell
gdirThe game data directory, usually /usr/local/share/adonthell
gnameThe name of the game we are running, e.g. wastesedge
qloadWhether quick-loading should be enabled or disabled
Returns
true in case of success, false otherwise.

Definition at line 544 of file gamedata.cc.

◆ cleanup()

void gamedata::cleanup ( void  )
static

Cleanup the saved game array.

Definition at line 612 of file gamedata.cc.

◆ load_characters()

bool gamedata::load_characters ( u_int32  pos)
static

Load the characters state from a saved game.

Parameters
posSlot number to load.
Returns
true in case of success, false otherwise.

Definition at line 118 of file gamedata.cc.

◆ load_quests()

bool gamedata::load_quests ( u_int32  pos)
static

Load the quests state from a saved game.

Parameters
posSlot number to load.
Returns
true in case of success, false otherwise.

Definition at line 164 of file gamedata.cc.

◆ load_mapengine()

bool gamedata::load_mapengine ( u_int32  pos)
static

Load the mapengine state from a saved game.

Parameters
posSlot number to load.
Returns
true in case of success, false otherwise.

Definition at line 203 of file gamedata.cc.

◆ load_audio()

bool gamedata::load_audio ( u_int32  pos)
static

Load the audio system state from a saved game.

Parameters
posSlot number to load.
Returns
true in case of success, false otherwise.

Definition at line 237 of file gamedata.cc.

◆ load()

bool gamedata::load ( u_int32  pos)
static

Loads a previously saved game.

Slot 0 points to the initial game data and needs to be loaded when starting a fresh game.

Parameters
posSlot number to load.
Returns
true in case of success, false otherwise.

Definition at line 303 of file gamedata.cc.

◆ load_newest()

bool gamedata::load_newest ( )
static

Loads the most recent saved game.

This method only takes games created by the player into account, not the initial saved game.

Returns
true in case of success, false otherwise.

Definition at line 317 of file gamedata.cc.

◆ save()

bool gamedata::save ( u_int32  pos,
string  desc,
string  time 
)
static

Save a game.

When given a slot number in the range of the available saved games, the according game will be overwritten, otherwise a new saved game is created. Saving to slot 0 is not possible, as it contains the initial game data.

Parameters
posSlot number where to save to.
descDescription of the game to be saved.
timeTextual representation of in-game time.
Returns
true in case of success, false otherwise.

Definition at line 340 of file gamedata.cc.

◆ unload()

void gamedata::unload ( )
static

Unloads the current game, resetting the engine to it's initial state.

Definition at line 620 of file gamedata.cc.

◆ next_save()

gamedata * gamedata::next_save ( )
static

Returns a pointer to the next saved game.

Returns
Next saved game.

Definition at line 521 of file gamedata.cc.

◆ user_data_dir()

static string gamedata::user_data_dir ( )
inlinestatic

Returns the user data directory ($HOME/.adonthell).

Returns
user data directory.

Definition at line 272 of file gamedata.h.

◆ game_data_dir()

static string gamedata::game_data_dir ( )
inlinestatic

Returns the game data directory.

Returns
game data directory.

Definition at line 283 of file gamedata.h.

◆ get_saved_game()

static gamedata* gamedata::get_saved_game ( u_int32  pos)
inlinestatic

Returns a pointer to a saved game.

Parameters
posSlot number to return.
Returns
Pointer to the saved game at position .

Definition at line 295 of file gamedata.h.

◆ quests()

static dictionary<quest *> gamedata::quests ( )
inlinestatic

Returns the global quests dictionary.

Returns
Global quests dictionary.

Definition at line 306 of file gamedata.h.

◆ player()

static character* gamedata::player ( )
inlinestatic

Returns the player character.

Returns
Player character.

Definition at line 317 of file gamedata.h.

◆ get_character()

static character* gamedata::get_character ( string  name)
inlinestatic

Returns a certain NPC when given the name.

Use player () to get the player character, as his/her name will be set at runtime.

Parameters
nameThe name of the character to return
Returns
a character.

Definition at line 330 of file gamedata.h.

◆ get_quest()

static quest* gamedata::get_quest ( string  name)
inlinestatic

Returns a certain quest when given the name.

Parameters
nameThe name of the quest to return
Returns
a quest

Definition at line 342 of file gamedata.h.

◆ characters()

static dictionary<character*> gamedata::characters ( )
inlinestatic

Returns the characters dictionary.

Returns
Characters dictionary.

Definition at line 353 of file gamedata.h.

◆ engine()

static adonthell* gamedata::engine ( )
inlinestatic

Returns a pointer to the global game engine.

Returns
Pointer to the global game engine.

Definition at line 364 of file gamedata.h.


The documentation for this class was generated from the following files: