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()
64 void update(
const std::string& message)
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>();
117 for(
int side : sides)
119 if(1 > side || side > max_side)
122 return std::map<int,config>();
129 std::set<int> empty_sides;
130 for(
int side : sides)
134 empty_sides.insert(side);
138 for(
int side : empty_sides)
145 for(
int side : empty_sides)
163 bool is_side_null_controlled;
166 if(side < 1 || max_side < side) {
168 ERR_REPLAY <<
"Invalid parameter for side in get_user_choice.";
180 LOG_REPLAY <<
"MP synchronization called during an unsynced context.";
200 <<
" is_synced=" << is_synced
201 <<
" is_mp_game=" << is_mp_game
202 <<
" is_side_null_controlled=" << is_side_null_controlled;
204 if (is_side_null_controlled)
206 DBG_REPLAY <<
"MP synchronization: side 1 being null-controlled in get_user_choice.";
212 while ( side <= max_side && resources::gameboard->get_team(side).is_empty() )
214 assert(side <= max_side);
218 assert(1 <= side && side <= max_side);
223 if(retv.find(side) == retv.end())
240 , changed_event_(
"user_choice_update")
247 assert(1 <= side && side <= max_side);
284 int from_side = (*action)[
"from_side"].to_int(0);
285 if((*action)[
"side_invalid"].to_bool(
false) ==
true)
288 replay::process_error(
"MP synchronization: side_invalid in replay data, this could mean someone wants to cheat.\n");
292 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");
294 if(
res_.find(from_side) !=
res_.end())
296 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");
318 std::vector<t_string> sides_str;
324 sides_str.push_back(std::to_string(side));
339 "waiting for $desc from side $sides",
340 "waiting for $desc from sides $sides",
356 DBG_REPLAY <<
"MP synchronization: local choice";
361 WRN_REPLAY <<
"Discarding a local choice because we found it already on the replay";
380 ERR_REPLAY <<
"A sync error appeared while waiting for a synced user choice of type '" <<
uch_.
description() <<
"' ([" +
tagname_ +
"]), doing the choice locally";
385 ERR_REPLAY <<
"Doing a local choice for side " << side;
394 user_choice_notifer_ingame notifer;
412 gui2::dialogs::synched_choice_wait::display(man);
447 static bool ucm_in_proccess =
false;
448 struct ucm_process_scope {
449 ucm_process_scope() { ucm_in_proccess =
true; }
450 ~ucm_process_scope() { ucm_in_proccess =
false; }
457 ucm_process_scope scope1;
play_controller * controller
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
std::string format_conjunct_list(const t_string &empty, const std::vector< t_string > &elems)
Format a conjunctive list.
static display * get_singleton()
Returns the display object if a display object exists.
static lg::log_domain log_replay("replay")
void remove_floating_label(int handle, int fadeout)
removes the floating label given by 'handle' from the screen
virtual const std::vector< team > & teams() const override
virtual void notify_observers()
static bool is_simultaneous()
void set_clip_rect(const SDL_Rect &r)
void update_local_choice()
std::set< int > required_
const std::string & tagname_
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
void set_lifetime(int lifetime, int fadeout=100)
static void set_is_simultaneous()
Sets is_simultaneous_ = true, called using a user choice that is not the currently playing side...
static void wait_ingame(user_choice_manager &man)
user_choice_manager(const std::string &name, const mp_sync::user_choice &uch, const std::set< int > &sides)
virtual void play_slice(bool is_delay_enabled=true)
virtual std::string description() const
void set_font_size(int font_size)
bool waiting() const
Note: currently finished() does not imply !waiting() so you may need to check both.
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 multiple sides for WML events.
virtual config random_choice(int side) const =0
This class stores all the data for a single 'side' (in game nomenclature).
void user_input(const std::string &name, const config &input, int from_side)
adds a user_input to the replay
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_
bool has_local_choice() const
void set_position(double xpos, double ypos)
map_display and display: classes which take care of displaying the map and game-data on the screen...
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
const color_t NORMAL_COLOR
void set_color(const color_t &color)
static void process_error(const std::string &msg)
std::string wait_message_
virtual bool is_networked_mp() const
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
Various functions that implement the undoing (and redoing) of in-game commands.
Standard logging facilities (interface).
int current_side() const
Returns the number of the side whose turn it is.
config * get_next_action()
virtual bool is_visible() const
whether the choice is visible for the user like an advancement choice a non-visible choice is for exa...
rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
A RAII object to temporary leave the synced context like in wesnoth.synchronize_choice.
std::map< int, config > res_
A config object defines a single node in a WML file, with access to child nodes.
REPLAY_RETURN do_replay_handle(bool one_move)
const std::string & wait_message() const
std::string debug() const
static void wait_prestart(user_choice_manager &man)