00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GAME_STATUS_HPP_INCLUDED
00020 #define GAME_STATUS_HPP_INCLUDED
00021
00022 #include "filesystem.hpp"
00023 #include "random.hpp"
00024 #include "team.hpp"
00025 #include "unit.hpp"
00026 #include "variable.hpp"
00027
00028 #include <time.h>
00029 #include <string>
00030 #include <vector>
00031
00032 class scoped_wml_variable;
00033
00034
00035 struct time_of_day
00036 {
00037 explicit time_of_day(const config& cfg);
00038 void write(config& cfg) const;
00039
00040
00041
00042 int lawful_bonus;
00043 int bonus_modified;
00044
00045
00046 std::string image;
00047 t_string name;
00048 std::string id;
00049
00050
00051
00052 std::string image_mask;
00053
00054
00055
00056 int red, green, blue;
00057
00058
00059
00060 std::string sounds;
00061 };
00062
00063 struct wml_menu_item
00064 {
00065 wml_menu_item(const std::string& id, const config* cfg=NULL);
00066 std::string name;
00067 std::string image;
00068 t_string description;
00069 bool needs_select;
00070 config show_if;
00071 config filter_location;
00072 config command;
00073 };
00074
00075
00076 struct player_info
00077 {
00078 player_info() :
00079 name(),
00080 gold(-1) ,
00081 gold_add(false),
00082 available_units(),
00083 can_recruit()
00084 {}
00085
00086 std::string name;
00087 int gold;
00088 bool gold_add;
00089
00090
00091 std::vector<unit> available_units;
00092 std::set<std::string> can_recruit;
00093
00094 void debug();
00095 };
00096
00097 class game_state : public variable_set
00098 {
00099 public:
00100 game_state() :
00101 label(),
00102 version(),
00103 campaign_type(),
00104 campaign_define(),
00105 campaign_xtra_defines(),
00106 campaign(),
00107 history(),
00108 abbrev(),
00109 scenario(),
00110 next_scenario(),
00111 completion(),
00112 players(),
00113 scoped_variables(),
00114 wml_menu_items(),
00115 difficulty("NORMAL"),
00116 replay_data(),
00117 starting_pos(),
00118 snapshot(),
00119 last_selected(gamemap::location::null_location),
00120 variables(),
00121 temporaries()
00122 {}
00123
00124 game_state(const game_state& state);
00125 game_state(const config& cfg, bool show_replay = false);
00126
00127 ~game_state();
00128 game_state& operator=(const game_state& state);
00129
00130 std::string label;
00131 std::string version;
00132 std::string campaign_type;
00133
00134 std::string campaign_define;
00135 std::vector<std::string> campaign_xtra_defines;
00136
00137 std::string campaign;
00138 std::string history;
00139 std::string abbrev;
00140 std::string scenario;
00141 std::string next_scenario;
00142 std::string completion;
00143
00144
00145
00146
00147
00148 std::map<std::string, player_info> players;
00149
00150
00151 player_info* get_player(const std::string& id);
00152
00153 std::vector<scoped_wml_variable*> scoped_variables;
00154 std::map<std::string, wml_menu_item*> wml_menu_items;
00155
00156 const config& get_variables() const { return variables; }
00157 void set_variables(const config& vars);
00158
00159 void set_menu_items(const config::child_list& menu_items);
00160
00161
00162
00163 t_string& get_variable(const std::string& varname);
00164 virtual const t_string& get_variable_const(const std::string& varname) const;
00165 config& get_variable_cfg(const std::string& varname);
00166 variable_info::array_range get_variable_cfgs(const std::string& varname);
00167
00168 void set_variable(const std::string& varname, const t_string& value);
00169 config& add_variable_cfg(const std::string& varname, const config& value=config());
00170
00171 void clear_variable(const std::string& varname);
00172 void clear_variable_cfg(const std::string& varname);
00173
00174 const simple_rng& rng() const { return rng_; }
00175 simple_rng& rng() { return rng_; }
00176
00177 std::string difficulty;
00178
00179
00180
00181 config replay_data;
00182
00183
00184
00185
00186 config starting_pos;
00187
00188
00189
00190
00191 config snapshot;
00192
00193
00194 gamemap::location last_selected;
00195
00196 private:
00197 simple_rng rng_;
00198 config variables;
00199 mutable config temporaries;
00200 friend struct variable_info;
00201
00202
00203 void load_recall_list(const config::child_list& players);
00204 };
00205
00206
00207
00208
00209 class gamestatus
00210 {
00211 public:
00212 gamestatus(const config& time_cfg, int num_turns, game_state* s_o_g = NULL);
00213 void write(config& cfg) const;
00214
00215 time_of_day get_time_of_day() const;
00216 time_of_day get_previous_time_of_day() const;
00217 time_of_day get_time_of_day(int illuminated, const gamemap::location& loc) const;
00218 time_of_day get_time_of_day(int illuminated, const gamemap::location& loc, int n_turn) const;
00219 bool set_time_of_day(int);
00220 size_t turn() const;
00221 int number_of_turns() const;
00222 void modify_turns(const std::string& mod);
00223 void add_turns(int num);
00224
00225
00226
00227 bool next_turn();
00228
00229 static bool is_start_ToD(const std::string&);
00230
00231
00232
00233 const game_state& sog() const{return(*state_of_game_);}
00234
00235 std::vector<team> *teams;
00236
00237 private:
00238 void set_start_ToD(config&, game_state*);
00239 time_of_day get_time_of_day_turn(int nturn) const;
00240 void next_time_of_day();
00241
00242 std::vector<time_of_day> times_;
00243
00244 struct area_time_of_day {
00245 area_time_of_day() :
00246 xsrc(),
00247 ysrc(),
00248 times(),
00249 hexes()
00250 {}
00251
00252 std::string xsrc, ysrc;
00253 std::vector<time_of_day> times;
00254 std::set<gamemap::location> hexes;
00255 };
00256
00257 std::vector<area_time_of_day> areas_;
00258
00259 size_t turn_;
00260 int numTurns_;
00261 int currentTime_;
00262 const game_state* state_of_game_;
00263 };
00264
00265 std::string generate_game_uuid();
00266
00267
00268
00269
00270 struct save_info {
00271 save_info(const std::string& n, time_t t) : name(n), time_modified(t) {}
00272 std::string name;
00273 time_t time_modified;
00274 };
00275
00276
00277 std::vector<save_info> get_saves_list(const std::string* dir = NULL, const std::string* filter = NULL);
00278
00279 enum WRITE_GAME_MODE { WRITE_SNAPSHOT_ONLY, WRITE_FULL_GAME };
00280
00281 void read_save_file(const std::string& name, config& cfg, std::string* error_log);
00282
00283 void write_game(const game_state& gamestate, config& cfg, WRITE_GAME_MODE mode=WRITE_FULL_GAME);
00284 void write_game(config_writer &out, const game_state& gamestate, WRITE_GAME_MODE mode=WRITE_FULL_GAME);
00285
00286
00287 bool save_game_exists(const std::string & name);
00288
00289
00290 scoped_ostream open_save_game(const std::string &label);
00291 void finish_save_game(config_writer &out, const game_state& gamestate, const std::string &label);
00292
00293
00294 void load_game(const std::string& name, game_state& gamestate, std::string* error_log);
00295 void load_game_summary(const std::string& name, config& cfg_summary, std::string* error_log);
00296
00297 void save_game(const game_state& gamestate);
00298
00299
00300 void delete_game(const std::string& name);
00301
00302 config& save_summary(const std::string& save);
00303
00304 void write_save_index();
00305
00306 void replace_underbar2space(std::string &name);
00307
00308 #endif