Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SAVEGAME_H_INCLUDED
00018 #define SAVEGAME_H_INCLUDED
00019
00020 #include "filesystem.hpp"
00021 #include "gamestatus.hpp"
00022 #include "tod_manager.hpp"
00023 #include "show_dialog.hpp"
00024
00025 class config_writer;
00026 class game_display;
00027
00028 struct load_game_cancelled_exception {};
00029 struct illegal_filename_exception {};
00030
00031 namespace savegame {
00032
00033
00034 class save_info {
00035 private:
00036 friend class create_save_info;
00037 private:
00038 save_info(const std::string& name, const time_t& modified);
00039 public:
00040 const std::string& name() const;
00041 const time_t& modified() const;
00042 public:
00043 const std::string format_time_summary() const;
00044 const std::string format_time_local() const;
00045 const config& summary() const;
00046 private:
00047 std::string name_;
00048 time_t modified_;
00049 };
00050
00051
00052
00053
00054
00055 struct save_info_less_time {
00056 bool operator()(const save_info& a, const save_info& b) const;
00057 };
00058
00059 std::vector<save_info> get_saves_list(const std::string* dir = NULL, const std::string* filter = NULL);
00060
00061
00062 void read_save_file(const std::string& name, config& cfg, std::string* error_log);
00063
00064
00065 bool save_game_exists(const std::string& name, bool compress_saves);
00066
00067
00068 void clean_saves(const std::string& label);
00069
00070
00071 void remove_old_auto_saves(const int autosavemax, const int infinite_auto_saves);
00072
00073
00074 void delete_game(const std::string& name);
00075
00076
00077 class loadgame
00078 {
00079 public:
00080 loadgame(display& gui, const config& game_config, game_state& gamestate);
00081 virtual ~loadgame() {}
00082
00083
00084 void load_game();
00085
00086 void load_game(
00087 const std::string& filename
00088 , const bool show_replay
00089 , const bool cancel_orders
00090 , const bool select_difficulty
00091 , const std::string& difficulty);
00092
00093 void load_multiplayer_game();
00094
00095 void fill_mplevel_config(config& level);
00096
00097 void set_gamestate();
00098
00099
00100 bool show_replay() const { return show_replay_; }
00101 bool cancel_orders() const { return cancel_orders_; }
00102 const std::string filename() const { return filename_; }
00103
00104 private:
00105
00106 void show_dialog(bool show_replay, bool cancel_orders);
00107
00108 void show_difficulty_dialog();
00109
00110 void check_version_compatibility();
00111
00112 void copy_era(config& cfg);
00113
00114 const config& game_config_;
00115 display& gui_;
00116
00117 game_state& gamestate_;
00118 std::string filename_;
00119 std::string difficulty_;
00120 config load_config_;
00121 bool show_replay_;
00122 bool cancel_orders_;
00123 bool select_difficulty_;
00124 };
00125
00126
00127 class savegame
00128 {
00129 public:
00130
00131
00132 savegame(game_state& gamestate, const bool compress_saves, const std::string& title = "Save");
00133
00134 virtual ~savegame() {}
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 bool save_game_automatic(CVideo& video, bool ask_for_overwrite = false, const std::string& filename = "");
00145
00146
00147
00148 bool save_game_interactive(CVideo& video, const std::string& message,
00149 gui::DIALOG_TYPE dialog_type);
00150
00151 const std::string& filename() const { return filename_; }
00152
00153 protected:
00154
00155
00156
00157
00158
00159 bool save_game(CVideo* video = NULL, const std::string& filename = "");
00160
00161
00162
00163 void set_filename(std::string filename);
00164
00165 void check_filename(const std::string& filename, CVideo& video);
00166
00167
00168 void set_error_message(const std::string& error_message) { error_message_ = error_message; }
00169
00170 const std::string& title() const { return title_; }
00171 game_state& gamestate() const { return gamestate_; }
00172 config& snapshot() { return snapshot_; }
00173
00174
00175 virtual void before_save();
00176
00177 private:
00178
00179 static bool is_illegal_file_char(char c);
00180
00181
00182
00183 virtual void create_filename() {}
00184
00185 virtual int show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type);
00186
00187 bool check_overwrite(CVideo& video);
00188
00189
00190
00191 void write_game_to_disk(const std::string& filename);
00192
00193
00194 void write_game(config_writer &out) const;
00195
00196 void finish_save_game(const config_writer &out);
00197
00198 scoped_ostream open_save_game(const std::string &label);
00199 friend class save_info;
00200
00201 game_state& gamestate_;
00202
00203
00204
00205 config snapshot_;
00206
00207 std::string filename_;
00208
00209 const std::string title_;
00210
00211 std::string error_message_;
00212
00213 bool show_confirmation_;
00214
00215 bool compress_saves_;
00216 };
00217
00218
00219
00220 class game_savegame : public savegame
00221 {
00222 public:
00223 game_savegame(game_state& gamestate,
00224 game_display& gui, const config& snapshot_cfg, const bool compress_saves);
00225
00226 private:
00227
00228 virtual void create_filename();
00229
00230
00231 virtual void before_save();
00232
00233
00234 void write_game_snapshot();
00235
00236 protected:
00237 game_display& gui_;
00238 };
00239
00240
00241 class replay_savegame : public savegame
00242 {
00243 public:
00244 replay_savegame(game_state& gamestate, const bool compress_saves);
00245
00246 private:
00247
00248 virtual void create_filename();
00249 };
00250
00251
00252 class autosave_savegame : public game_savegame
00253 {
00254 public:
00255 autosave_savegame(game_state &gamestate,
00256 game_display& gui, const config& snapshot_cfg, const bool compress_saves);
00257
00258 void autosave(const bool disable_autosave, const int autosave_max, const int infinite_autosaves);
00259 private:
00260
00261 virtual void create_filename();
00262 };
00263
00264 class oos_savegame : public game_savegame
00265 {
00266 public:
00267 oos_savegame(const config& snapshot_cfg);
00268
00269 private:
00270
00271 virtual int show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type);
00272 };
00273
00274
00275 class scenariostart_savegame : public savegame
00276 {
00277 public:
00278 scenariostart_savegame(game_state& gamestate, const bool compress_saves);
00279
00280 private:
00281
00282 virtual void before_save();
00283 };
00284
00285 }
00286
00287 void replace_underbar2space(std::string &name);
00288 void replace_space2underbar(std::string &name);
00289
00290 #endif