00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef REPLAY_H_INCLUDED
00019 #define REPLAY_H_INCLUDED
00020
00021 #include "config.hpp"
00022 #include "gamestatus.hpp"
00023 #include "map.hpp"
00024 #include "random.hpp"
00025
00026 class config_writer;
00027 class game_display;
00028 class terrain_label;
00029 class unit_map;
00030
00031 struct verification_manager
00032 {
00033 verification_manager(const unit_map& units);
00034 ~verification_manager();
00035 };
00036
00037 class replay: public rng
00038 {
00039 public:
00040 replay();
00041 explicit replay(const config& cfg);
00042
00043 void set_save_info(const game_state& save);
00044 void set_save_info_completion(const std::string &st);
00045
00046 void set_skip(bool skip);
00047 bool is_skipping() const;
00048
00049 void save_game(const std::string& label, const config& snapshot,
00050 const config& starting_pos, bool include_replay = true);
00051
00052 void add_start();
00053 void add_recruit(int unit_index, const gamemap::location& loc);
00054 void add_recall(int unit_index, const gamemap::location& loc);
00055 void add_disband(int unit_index);
00056 void add_countdown_update(int value,int team);
00057 void add_movement(const gamemap::location& a, const gamemap::location& b);
00058 void add_attack(const gamemap::location& a, const gamemap::location& b,
00059 int att_weapon, int def_weapon);
00060 void choose_option(int index);
00061 void text_input(std::string input);
00062 void set_random_value(const std::string& choice);
00063 void add_label(const terrain_label*);
00064 void clear_labels(const std::string&);
00065 void add_rename(const std::string& name, const gamemap::location& loc);
00066 void end_turn();
00067 void add_event(const std::string& name,
00068 const gamemap::location& loc=gamemap::location::null_location);
00069 void add_unit_checksum(const gamemap::location& loc,config* const cfg);
00070 void add_checksum_check(const gamemap::location& loc);
00071
00072
00073
00074
00075 void add_advancement(const gamemap::location& loc);
00076
00077 void add_chat_message_location();
00078 void speak(const config& cfg);
00079 std::string build_chat_log(const std::string& team);
00080
00081
00082
00083
00084
00085
00086
00087
00088 enum DATA_TYPE { ALL_DATA, NON_UNDO_DATA };
00089 config get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type=ALL_DATA);
00090 config get_last_turn(int num_turns=1);
00091
00092 void undo();
00093
00094 void start_replay();
00095 void revert_action();
00096 config* get_next_action();
00097 void pre_replay();
00098
00099 bool at_end() const;
00100 void set_to_end();
00101
00102 void clear();
00103 bool empty();
00104
00105 enum MARK_SENT { MARK_AS_UNSENT, MARK_AS_SENT };
00106 void add_config(const config& cfg, MARK_SENT mark=MARK_AS_UNSENT);
00107
00108 int ncommands();
00109
00110 static void throw_error(const std::string& msg);
00111
00112 struct error {
00113 error(const std::string& msg) : message(msg) {}
00114 std::string message;
00115 };
00116
00117 static std::string last_replay_error;
00118 private:
00119
00120 void add_pos(const std::string& type,
00121 const gamemap::location& a, const gamemap::location& b);
00122
00123 void add_value(const std::string& type, int value);
00124
00125 void add_chat_log_entry(const config*, std::stringstream&, const std::string&) const;
00126
00127 const config::child_list& commands() const;
00128 void remove_command(int);
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 config* add_command(bool update_random_context=true);
00141 config cfg_;
00142 unsigned int pos_;
00143
00144 config* current_;
00145
00146 game_state saveInfo_;
00147
00148 bool skip_;
00149
00150 std::vector<int> message_locations;
00151 };
00152
00153 replay& get_replay_source();
00154
00155 extern replay recorder;
00156
00157
00158
00159 bool do_replay(game_display& disp, const gamemap& map,
00160 unit_map& units, std::vector<team>& teams, int team_num,
00161 const gamestatus& state, game_state& state_of_game, replay* obj=NULL);
00162
00163 bool do_replay_handle(game_display& disp, const gamemap& map,
00164 unit_map& units, std::vector<team>& teams, int team_num,
00165 const gamestatus& state, game_state& state_of_game,
00166 const std::string& do_untill);
00167
00168
00169
00170 struct replay_undo
00171 {
00172 replay_undo(replay& obj) : obj_(&obj) {}
00173 ~replay_undo() { if(obj_) obj_->undo(); }
00174 void confirm_transaction() { obj_ = NULL; }
00175
00176 private:
00177 replay* obj_;
00178 };
00179
00180 class replay_network_sender
00181 {
00182 public:
00183 replay_network_sender(replay& obj);
00184 ~replay_network_sender();
00185
00186 void sync_non_undoable();
00187 void commit_and_sync();
00188 private:
00189 replay& obj_;
00190 int upto_;
00191 };
00192
00193 #endif