40 #include <boost/lexical_cast.hpp>
47 #define DBG_REPLAY LOG_STREAM(debug, log_replay)
48 #define LOG_REPLAY LOG_STREAM(info, log_replay)
49 #define WRN_REPLAY LOG_STREAM(warn, log_replay)
50 #define ERR_REPLAY LOG_STREAM(err, log_replay)
61 DBG_REPLAY <<
"run_in_synced_context:" << commandname <<
"\n";
72 error_handler(
"commandname [" +commandname +
"] not found",
true);
76 bool success = it->second(data, use_undo, show, error_handler);
95 ERR_REPLAY <<
"ignored attempt to invoke a synced command during replay\n";
101 bool success =
run(commandname, data, use_undo, show, error_handler);
111 bool success =
run_and_store(commandname, data, use_undo, show, error_handler);
125 return run_and_throw(commandname, data, use_undo, show, error_handler);
128 ERR_REPLAY <<
"trying to execute action while being in a local_choice" << std::endl;
138 error_handler(
"commandname [" +commandname +
"] not found",
true);
143 return it->second(data,
false, show, error_handler);
147 assert(
false &&
"found unknown synced_context::synced_state");
154 ERR_REPLAY <<
"Unexpected Error during synced execution" << message << std::endl;
155 assert(!
"Unexpected Error during synced execution, more info in stderr.");
198 virtual const char*
name()
const
200 return "random_seed";
209 return seed_val.
str();
262 if(mode ==
"deterministic")
290 bool did_require =
false;
305 if (is_replay_end && !is_mp_game)
309 DBG_REPLAY <<
"MP synchronization: local server choice\n";
317 else if(is_replay_end && is_mp_game)
319 DBG_REPLAY <<
"MP synchronization: remote server choice\n";
338 else if (!is_replay_end)
342 DBG_REPLAY <<
"MP synchronization: replay server choice\n";
358 if((*action)[
"from_side"].str() !=
"server" || (*action)[
"side_invalid"].to_bool(
false) )
392 LOG_REPLAY <<
"set_scontext_synced_base::set_scontext_synced_base\n";
405 LOG_REPLAY <<
"set_scontext_synced_base:: destructor\n";
413 , new_checkup_(generate_checkup(
"checkup")), disabler_()
420 , new_checkup_(generate_checkup(
"checkup" +
std::to_string(number))), disabler_()
442 LOG_REPLAY <<
"set_scontext_synced::set_scontext_synced\n";
451 std::stringstream
msg;
454 (
"random_calls",
new_rng_->get_random_calls())
460 if(co[
"random_calls"].empty())
462 msg <<
"cannot find random_calls check in replay" << std::endl;
464 else if(co[
"random_calls"] != cn[
"random_calls"])
466 msg <<
"We called random " <<
new_rng_->get_random_calls() <<
" times, but the original game called random " << co[
"random_calls"].to_int() <<
" times." << std::endl;
469 if(!co[
"next_unit_id"].empty() && co[
"next_unit_id"] != cn[
"next_unit_id"])
471 msg <<
"Our next unit id is " << cn[
"next_unit_id"].to_int() <<
" but during the original the next unit id was " << co[
"next_unit_id"].to_int() << std::endl;
473 if(!msg.str().empty())
475 msg << co.
debug() << std::endl;
490 LOG_REPLAY <<
"set_scontext_synced:: destructor\n";
501 return new_rng_->get_random_calls();
boost::scoped_ptr< checkup > new_checkup_
static lg::log_domain log_replay("replay")
void clear()
Clears the stack of undoable (and redoable) actions.
play_controller * controller
static void add_undo_commands(const config &commands, const game_events::queued_event &ctx)
virtual void send_to_wesnothd(const config &, const std::string &="unknown") const
static bool run_and_store(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
game_classification * classification
void do_final_checkup(bool dont_throw=false)
size_t get_save_id() const
Used for saving id to savegame.
static bool run(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
Sets the context to 'synced', initialises random context, and calls the given function.
rng * generator
This generator is automatically synced during synced context.
static boost::shared_ptr< random_new::rng > get_rng_for_action()
unsigned int get_random_calls()
Provides the number of random calls to the rng in this context.
void send_request() const
static map & registry()
using static function variable instead of static member variable to prevent static initialization fia...
static rng & default_instance()
static std::string generate_random_seed()
virtual config local_choice() const =0
We are in a game with no mp server and need to do this choice locally.
static void add_redo_commands(const config &commands, const game_events::queued_event &ctx)
static void pull_remote_choice()
void check_victory()
Checks to see if a side has won.
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
const std::string number
template to number regex
std::string debug() const
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definitions for the interface to Wesnoth Markup Language (WML).
void add_synced_command(const std::string &name, const config &command)
static synced_state get_synced_state()
static event_list undo_commands_
Actions wml to be executed when the current actio is undone.
Variant for storing WML attributes.
static void reset_is_simultaneously()
static void set_last_unit_id(int id)
random_new::rng * old_rng_
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
boost::shared_ptr< random_new::rng > new_rng_
static void just_log_error_function(const std::string &message, bool heavy)
a function to be passed to run_in_synced_context to log the error.
static synced_state state_
virtual const char * name() const =0
static void ignore_error_function(const std::string &message, bool heavy)
a function to be passed to run_in_synced_context to ignore the error.
std::string next_seed_str()
checkup * checkup_instance
Managing the AIs lifecycle - headers.
std::deque< std::pair< config, game_events::queued_event > > event_list
This checkup compares whether the results calculated during the original game match the ones calculat...
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.
static int last_unit_id_
Used to restore the unit id manager when undoing.
static bool is_simultaneously()
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
static event_list redo_commands_
Actions wml to be executed when the current actio is redone.
static void process_error(const std::string &msg)
void maybe_throw_return_to_play_side()
static checkup * generate_checkup(const std::string &tagname)
A class to check whether the results that were calculated in the replay match the results calculated ...
random_new::rng * old_rng_
This rng is used when the normal synced rng is not available this is currently only he case at the ve...
static int get_unit_id_diff()
static std::string flush(std::ostringstream &s)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
static void send_user_choice()
static void reset_undo_commands()
set_scontext_synced_base()
static bool run_and_throw(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
n_unit::id_manager & unit_id_manager()
static bool run_in_synced_context_if_not_already(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
checks whether we are currently running in a synced context, and if not we enters it...
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).
config * get_next_action()
static void set_synced_state(synced_state newstate)
GLsizei GLenum GLuint GLuint GLsizei char * message
static void default_error_function(const std::string &message, bool heavy)
a function to be passed to run_in_synced_context to assert false on error (the default).
~set_scontext_synced_base()
boost::shared_ptr< wb::manager > whiteboard
std::function< void(const std::string &, bool)> error_handler_function
actions::undo_list * undo_stack
virtual bool is_networked_mp() const
virtual bool local_checkup(const config &expected_data, config &real_data)=0
Compares data to the results calculated during the original game.
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)
static void reset_redo_commands()
virtual config request() const =0
the request which is sended to the mp server.
GLsizei const GLcharARB ** string
This checkup always compares the results in from different clients in a mp game but it also causes mo...
static config ask_server_choice(const server_choice &)
void increase_server_request_number()
static bool is_simultaneously_