28 #include <boost/lexical_cast.hpp>
34 #define DBG_REPLAY LOG_STREAM(debug, log_replay)
35 #define LOG_REPLAY LOG_STREAM(info, log_replay)
36 #define WRN_REPLAY LOG_STREAM(warn, log_replay)
37 #define ERR_REPLAY LOG_STREAM(err, log_replay)
41 class user_choice_notifer_ingame
46 unsigned int start_show_;
49 user_choice_notifer_ingame()
52 , start_show_(SDL_GetTicks() + 2000)
57 ~user_choice_notifer_ingame()
66 if(label_id_ == -1 && SDL_GetTicks() > start_show_)
70 if(message == message_) {
80 void start_show_label()
82 assert(label_id_ == -1);
95 assert(label_id_ != -1);
113 replay::process_error(
"MP synchronization only works in a synced context (for example Select or preload events are no synced context).\n");
114 return std::map<int,config>();
120 std::set<int> empty_sides;
121 for(
int side : sides)
123 assert(1 <= side && side <= max_side);
126 empty_sides.insert(side);
130 for(
int side : empty_sides)
137 for(
int side : empty_sides)
155 bool is_side_null_controlled;
162 LOG_REPLAY <<
"MP synchronization called during an unsynced context.\n";
181 if ( side < 1 || max_side < side )
185 ERR_REPLAY <<
"Invalid parameter for side in get_user_choice." << std::endl;
188 LOG_REPLAY <<
" side changed to " << side <<
"\n";
190 is_side_null_controlled = (*resources::teams)[side-1].is_empty();
194 <<
" is_synced=" << is_synced
195 <<
" is_mp_game=" << is_mp_game
196 <<
" is_side_null_controlled=" << is_side_null_controlled <<
"\n";
198 if (is_side_null_controlled)
200 DBG_REPLAY <<
"MP synchronization: side 1 being null-controlled in get_user_choice.\n";
208 assert(side <= max_side);
212 assert(1 <= side && side <= max_side);
217 if(retv.find(side) == retv.end())
234 , changed_event_(
"user_choice_update")
241 assert(1 <= side && side <= max_side);
242 const team&
t = (*resources::teams)[side-1];
278 int from_side = (*action)[
"from_side"].to_int(0);
279 if((*action)[
"side_invalid"].to_bool(
false) ==
true)
282 replay::process_error(
"MP synchronization: side_invalid in replay data, this could mean someone wants to cheat.\n");
286 replay::process_error(
"MP synchronization: we got an answer from side " + std::to_string(from_side) +
"for [" +
tagname_ +
"] which is not was we expected\n");
288 if(
res_.find(from_side) !=
res_.end())
290 replay::process_error(
"MP synchronization: we got already our answer from side " + std::to_string(from_side) +
"for [" +
tagname_ +
"] now we have it twice.\n");
319 sides_str += std::to_string(side);
342 DBG_REPLAY <<
"MP synchronization: local choice\n";
347 WRN_REPLAY <<
"Discarding a local choice becasue we found it already on the replay";
366 ERR_REPLAY <<
"A sync error appeared while waiting for a synced user choice of type '" <<
uch_.
description() <<
"' ([" +
tagname_ +
"]), doing the choice locally\n";
371 ERR_REPLAY <<
"Doing a local choice for side " << side <<
"\n";
380 user_choice_notifer_ingame notifer;
play_controller * controller
virtual std::string description() const
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
user_choice_manager(const std::string &name, const mp_sync::user_choice &uch, std::set< int > sides)
static lg::log_domain log_replay("replay")
virtual void notify_observers()
void set_clip_rect(const SDL_Rect &r)
void update_local_choice()
std::set< int > required_
const std::string & tagname_
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
static void wait_ingame(user_choice_manager &man)
void play_slice(bool is_delay_enabled=true)
void set_font_size(int font_size)
std::string debug() const
const SDL_Color NORMAL_COLOR
void process(events::pump_info &)
Inherited from events::pump_monitor.
std::map< int, config > get_user_choice_multiple_sides(const std::string &name, const user_choice &uch, std::set< int > sides)
Performs a choice for mutiple sides for WML events.
virtual config random_choice(int side) const =0
bool waiting()
Note: currently finished() does not imply !waiting() so you may need to check both.
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
This class stores all the data for a single 'side' (in game nomenclature).
int current_side() const
Returns the number of the side whose turn it is.
std::vector< team > * teams
void set_lifetime(int lifetime)
virtual bool is_visible() const
whether the choice is visible for the user like an advacement choice a non-visible choice is for exam...
Interface for querying local choices.
static std::map< int, config > get_user_choice_internal(const std::string &name, const mp_sync::user_choice &uch, const std::set< int > &sides)
events::generic_event changed_event_
const mp_sync::user_choice & uch_
void set_color(const SDL_Color &color)
void set_position(double xpos, double ypos)
const std::string & wait_message()
static void send_user_choice()
called from get_user_choice to send a recently made choice to the other clients.
static void pull_remote_user_input()
called from get_user_choice while waiting for a remove user choice.
virtual config query_user(int side) const =0
static bool is_simultaneously()
static void process_error(const std::string &msg)
std::string wait_message_
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
GLuint const GLchar * name
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Various functions that implement the undoing (and redoing) of in-game commands.
Standard logging facilities (interface).
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
config * get_next_action()
GLsizei GLenum GLuint GLuint GLsizei char * message
std::map< int, config > res_
virtual bool is_networked_mp() const
void user_input(const std::string &, const config &, int from_side)
adds a user_input to the replay
static void set_is_simultaneously()
A config object defines a single node in a WML file, with access to child nodes.
REPLAY_RETURN do_replay_handle(bool one_move)
GLsizei const GLcharARB ** string
static void wait_prestart(user_choice_manager &man)