gamestatus.cpp File Reference

Maintain status of a game, load&save games. More...

#include "global.hpp"
#include "filesystem.hpp"
#include "game_config.hpp"
#include "game_errors.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "language.hpp"
#include "log.hpp"
#include "game_preferences.hpp"
#include "statistics.hpp"
#include "util.hpp"
#include "wesconfig.h"
#include "serialization/binary_or_text.hpp"
#include "serialization/binary_wml.hpp"
#include "serialization/parser.hpp"
#include "serialization/string_utils.hpp"
#include "wml_exception.hpp"
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <sstream>
#include <sys/time.h>
#include <time.h>

Include dependency graph for gamestatus.cpp:

Go to the source code of this file.

Classes

struct  save_info_less_time
 A structure for comparing to save_info objects based on their modified time. More...

Defines

#define DBG_NG   lg::debug(lg::engine)
#define LOG_NG   lg::info(lg::engine)
#define WRN_NG   lg::warn(lg::engine)
#define ERR_NG   lg::err(lg::engine)

Functions

void replace_underbar2space (std::string &name)
static void replace_space2underbar (std::string &name)
static void extract_summary_from_config (config &cfg_save, config &cfg_summary)
static void extract_summary_data_from_save (const game_state &gamestate, config &out)
static void parse_times (const config &cfg, std::vector< time_of_day > &normal_times)
static player_info read_player (const config *cfg)
static void write_player (const player_info &player, config &cfg)
static void write_player (config_writer &out, const player_info &player)
void write_game (const game_state &gamestate, config &cfg, WRITE_GAME_MODE mode)
void write_game (config_writer &out, const game_state &gamestate, WRITE_GAME_MODE mode)
std::vector< save_infoget_saves_list (const std::string *dir, const std::string *filter)
 Get a list of available saves.
bool save_game_exists (const std::string &name)
 Returns true iff there is already a savegame with that name.
void delete_game (const std::string &name)
 Delete a savegame.
void read_save_file (const std::string &name, config &cfg, std::string *error_log)
static void copy_era (config &cfg)
void load_game (const std::string &name, game_state &gamestate, std::string *error_log)
 Load/Save games.
void load_game_summary (const std::string &name, config &cfg_summary, std::string *error_log)
scoped_ostream open_save_game (const std::string &label)
 Throws game::save_game_failed.
void finish_save_game (config_writer &out, const game_state &gamestate, const std::string &label)
void save_game (const game_state &gamestate)
 Throws gamestatus::save_game_failed.
static configsave_index ()
configsave_summary (const std::string &save)
void write_save_index ()
static void clear_wmi (std::map< std::string, wml_menu_item * > &gs_wmi)

Variables

bool save_index_loaded = false
config save_index_cfg


Detailed Description

Maintain status of a game, load&save games.

Definition in file gamestatus.cpp.


Define Documentation

#define DBG_NG   lg::debug(lg::engine)

Definition at line 45 of file gamestatus.cpp.

#define ERR_NG   lg::err(lg::engine)

Definition at line 48 of file gamestatus.cpp.

#define LOG_NG   lg::info(lg::engine)

Definition at line 46 of file gamestatus.cpp.

#define WRN_NG   lg::warn(lg::engine)

Definition at line 47 of file gamestatus.cpp.


Function Documentation

static void clear_wmi ( std::map< std::string, wml_menu_item * > &  gs_wmi  )  [static]

static void copy_era ( config cfg  )  [static]

Definition at line 802 of file gamestatus.cpp.

References config::add_child(), config::child(), and game_state::snapshot.

Referenced by load_game().

void delete_game ( const std::string &  name  ) 

Delete a savegame.

Definition at line 764 of file gamestatus.cpp.

References get_saves_dir(), and replace_space2underbar().

Referenced by clean_saves(), and remove_old_auto_saves().

void extract_summary_data_from_save ( const game_state gamestate,
config out 
) [static]

void extract_summary_from_config ( config cfg_save,
config cfg_summary 
) [static]

Todo:
Ideally we should grab all leaders if there's more than 1 human player?

Definition at line 1006 of file gamestatus.cpp.

References config::child(), config::find_child(), config::get_children(), game_state::players, game_state::snapshot, utils::string_bool(), and units.

Referenced by load_game_summary().

void finish_save_game ( config_writer out,
const game_state gamestate,
const std::string &  label 
)

std::vector<save_info> get_saves_list ( const std::string *  dir,
const std::string *  filter 
)

Get a list of available saves.

Definition at line 727 of file gamestatus.cpp.

References file_create_time(), get_files_in_dir(), get_saves_dir(), and replace_underbar2space().

Referenced by clean_saves(), dialogs::load_game_dialog(), and remove_old_auto_saves().

void load_game ( const std::string &  name,
game_state gamestate,
std::string *  error_log 
)

Load/Save games.

Definition at line 813 of file gamestatus.cpp.

References cfg, copy_era(), game_state::game_state(), log_scope, and read_save_file().

void load_game_summary ( const std::string &  name,
config cfg_summary,
std::string *  error_log 
)

Definition at line 824 of file gamestatus.cpp.

References cfg, extract_summary_from_config(), log_scope, and read_save_file().

scoped_ostream open_save_game ( const std::string &  label  ) 

static void parse_times ( const config cfg,
std::vector< time_of_day > &  normal_times 
) [static]

Definition at line 165 of file gamestatus.cpp.

References dummy_cfg, config::get_children(), and time_of_day::time_of_day().

Referenced by gamestatus::gamestatus().

static player_info read_player ( const config cfg  )  [static]

void read_save_file ( const std::string &  name,
config cfg,
std::string *  error_log 
)

static void replace_space2underbar ( std::string &  name  )  [static]

Definition at line 115 of file gamestatus.cpp.

Referenced by delete_game(), open_save_game(), read_save_file(), and save_game_exists().

void replace_underbar2space ( std::string &  name  ) 

Definition at line 112 of file gamestatus.cpp.

Referenced by get_saves_list(), and dialogs::show_objectives().

void save_game ( const game_state gamestate  ) 

Throws gamestatus::save_game_failed.

Definition at line 868 of file gamestatus.cpp.

References preferences::compress_saves(), finish_save_game(), game_state::label, open_save_game(), PACKAGE, and write_game().

Referenced by play_game().

bool save_game_exists ( const std::string &  name  ) 

Returns true iff there is already a savegame with that name.

Definition at line 752 of file gamestatus.cpp.

References preferences::compress_saves(), file_exists(), get_saves_dir(), and replace_space2underbar().

Referenced by play_controller::expand_autosaves(), and dialogs::get_save_name().

static config& save_index (  )  [static]

config& save_summary ( const std::string &  save  ) 

void write_game ( config_writer out,
const game_state gamestate,
WRITE_GAME_MODE  mode 
)

void write_game ( const game_state gamestate,
config cfg,
WRITE_GAME_MODE  mode 
)

static void write_player ( config_writer out,
const player_info player 
) [static]

static void write_player ( const player_info player,
config cfg 
) [static]

void write_save_index (  ) 


Variable Documentation

Definition at line 883 of file gamestatus.cpp.

Referenced by save_index().

bool save_index_loaded = false [static]

Definition at line 882 of file gamestatus.cpp.

Referenced by save_index().


Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs