The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
replay.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Replay control code.
18  */
19 
20 #ifndef REPLAY_H_INCLUDED
21 #define REPLAY_H_INCLUDED
22 
23 #include "map/location.hpp"
24 
25 #include <deque>
26 #include <iterator>
27 #include <map>
28 #include <set>
30 class game_display;
31 class terrain_label;
32 class unit_map;
33 class play_controller;
34 class config;
35 struct time_of_day;
36 
37 class chat_msg {
38 public:
39  const std::string &text() const { return text_; }
40  const std::string &nick() const { return nick_; }
41  const std::string &color() const { return color_; }
42  const time_t &time() const { return time_; }
43  chat_msg(const config &cfg);
44  virtual ~chat_msg();
45 private:
49  time_t time_;
50 };
51 
52 class replay
53 {
54 public:
55  explicit replay(replay_recorder_base& base);
56 
57 
58  void add_start();
59  void add_countdown_update(int value,int team);
60 
61  void add_synced_command(const std::string& name, const config& command);
62  void init_side();
63  /*
64  returns a reference to the newest config that us not dependent or has undo =no
65 
66  */
68  /**
69  adds a user_input to the replay
70  @param from_side the side that had to make the decision, -1 for 'server'
71  */
72  void user_input(const std::string &, const config &, int from_side);
73  void add_label(const terrain_label*);
74  void clear_labels(const std::string&, bool);
75  void add_rename(const std::string& name, const map_location& loc);
76  void end_turn();
77  void add_unit_checksum(const map_location& loc,config& cfg);
78  void add_log_data(const std::string &key, const std::string &var);
79  void add_log_data(const std::string &category, const std::string &key, const std::string &var);
80  void add_log_data(const std::string &category, const std::string &key, const config& c);
81 
82  /**
83  adds a chat message if it wasn't added yet.
84  @returns true if a message location was added
85  */
88  void speak(const config& cfg);
89  const std::vector<chat_msg>& build_chat_log();
90 
91  //get data range will get a range of moves from the replay system.
92  //if data_type is 'ALL_DATA' then it will return all data in this range
93  //except for undoable data that has already been sent. If data_type is
94  //NON_UNDO_DATA, then it will only retrieve undoable data, and will mark
95  //it as already sent.
96  //undoable data includes moves such as placing a label or speaking, which is
97  //ignored by the undo system.
99  config get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type=ALL_DATA);
100 
101  void undo();
102  /*
103  undoes the last move and puts it into given config to be reone with redo
104  The retuned config also contains the depended commands for that user action.
105  This is needed be becasue we also want to readd those dependent commands to the replay when redoing the command.
106  */
107  void undo_cut(config& dst);
108  /*
109  puts the given config which was cut with undo_cut back in the replay.
110  */
111  void redo(const config& dst);
112 
113  void start_replay();
114  void revert_action();
116 
117  bool at_end() const;
118  void set_to_end();
119 
120  bool empty();
121 
123  void add_config(const config& cfg, MARK_SENT mark=MARK_AS_UNSENT);
124 
125  int ncommands() const;
126 
127  static void process_error(const std::string& msg);
128  /*
129  adds a [start] at the begnning of the replay if there is none.
130  returns true if a [start] was added.
131  */
134 private:
135 
136  void add_chat_log_entry(const config &speak, std::back_insert_iterator< std::vector<chat_msg> > &i) const;
137 
138  config &command(int);
139  void remove_command(int);
140  /** Adds a new empty command to the command list at the end.
141  *
142  * @return a reference to the added command
143  */
144  config& add_command();
145  /**
146  * adds a new command to the command list at the current position.
147  *
148  * @return a reference to the added command
149  */
152  std::vector<int> message_locations;
153 };
154 
156 {
163 };
164 //replays up to one turn from the recorder object
165 //returns true if it got to the end of the turn without data running out
166 REPLAY_RETURN do_replay(bool one_move = false);
167 
168 REPLAY_RETURN do_replay_handle(bool one_move = false);
169 
171 {
172 public:
175 
176  void sync_non_undoable();
177  void commit_and_sync();
178 private:
180  int upto_;
181 };
182 
183 #endif
void delete_upcoming_commands()
Definition: replay.cpp:187
DATA_TYPE
Definition: replay.hpp:98
replay(replay_recorder_base &base)
Definition: replay.cpp:182
REPLAY_RETURN do_replay(bool one_move=false)
Definition: replay.cpp:659
replay_network_sender(replay &obj)
Definition: replay.cpp:872
void add_countdown_update(int value, int team)
Definition: replay.cpp:233
void end_turn()
Definition: replay.cpp:298
int ncommands() const
Definition: replay.cpp:563
bool empty()
Definition: replay.cpp:622
void speak(const config &cfg)
Definition: replay.cpp:342
bool add_chat_message_location()
adds a chat message if it wasn't added yet.
Definition: replay.cpp:325
const GLfloat * c
Definition: glew.h:12741
int pos
Definition: formula.cpp:800
void add_log_data(const std::string &key, const std::string &var)
Definition: replay.cpp:305
REPLAY_RETURN do_replay_handle(bool one_move=false)
Definition: replay.cpp:677
virtual ~chat_msg()
Definition: replay.cpp:178
void add_start()
Definition: replay.cpp:226
void sync_non_undoable()
Definition: replay.cpp:883
const std::string & nick() const
Definition: replay.hpp:40
config & get_last_real_command()
Definition: replay.cpp:423
replay_recorder_base * base_
Definition: replay.hpp:151
void add_synced_command(const std::string &name, const config &command)
Definition: replay.cpp:241
MARK_SENT
Definition: replay.hpp:122
REPLAY_RETURN
Definition: replay.hpp:155
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:48
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
void init_side()
Definition: replay.cpp:218
void redo(const config &dst)
Definition: replay.cpp:410
bool add_start_if_not_there_yet()
Definition: replay.cpp:638
const std::string & color() const
Definition: replay.hpp:41
GLsizei const GLfloat * value
Definition: glew.h:1817
GLenum GLenum dst
Definition: glew.h:2392
void start_replay()
Definition: replay.cpp:586
time_t time_
Definition: replay.hpp:49
GLhandleARB obj
Definition: glew.h:4486
void add_rename(const std::string &name, const map_location &loc)
Definition: replay.cpp:287
void set_to_end()
Definition: replay.cpp:617
void add_chat_log_entry(const config &speak, std::back_insert_iterator< std::vector< chat_msg > > &i) const
Definition: replay.cpp:350
config & command(int)
Definition: replay.cpp:556
void add_unit_checksum(const map_location &loc, config &cfg)
Definition: replay.cpp:205
Encapsulates the map of the game.
Definition: location.hpp:38
static void process_error(const std::string &msg)
Definition: replay.cpp:198
std::string color_
Definition: replay.hpp:46
const std::string & text() const
Definition: replay.hpp:39
size_t i
Definition: function.cpp:1057
void remove_command(int)
Definition: replay.cpp:359
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:112
const std::vector< chat_msg > & build_chat_log()
Definition: replay.cpp:373
GLuint const GLchar * name
Definition: glew.h:1782
To store label data Class implements logic for rendering.
Definition: label.hpp:103
config & add_nonundoable_command()
adds a new command to the command list at the current position.
Definition: replay.cpp:578
void add_config(const config &cfg, MARK_SENT mark=MARK_AS_UNSENT)
Definition: replay.cpp:627
bool at_end() const
Definition: replay.cpp:611
std::vector< int > message_locations
Definition: replay.hpp:152
void undo_cut(config &dst)
Definition: replay.cpp:482
std::string nick_
Definition: replay.hpp:47
Container associating units to locations.
Definition: map.hpp:90
config * get_next_action()
Definition: replay.cpp:598
void revert_action()
Definition: replay.cpp:591
config & add_command()
Adds a new empty command to the command list at the end.
Definition: replay.cpp:568
config get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type=ALL_DATA)
Definition: replay.cpp:391
void undo()
Definition: replay.cpp:550
void user_input(const std::string &, const config &, int from_side)
adds a user_input to the replay
Definition: replay.cpp:251
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void clear_labels(const std::string &, bool)
Definition: replay.cpp:277
GLsizei const GLcharARB ** string
Definition: glew.h:4503
chat_msg(const config &cfg)
Definition: replay.cpp:146
const time_t & time() const
Definition: replay.hpp:42
void add_label(const terrain_label *)
Definition: replay.cpp:266
std::string text_
Definition: replay.hpp:48