add side parameter in sync_choice
when we call sync_choice with a third argument there was no way to determine for which side we actualy made the decision.
This commit is contained in:
parent
c9552c9a33
commit
4765b33f58
8 changed files with 27 additions and 25 deletions
|
@ -1377,8 +1377,9 @@ namespace
|
|||
{
|
||||
}
|
||||
|
||||
virtual config query_user() const
|
||||
virtual config query_user(int /*side*/) const
|
||||
{
|
||||
//the 'side' parameter might differ from side_num_-
|
||||
int res = 0;
|
||||
team t = (*resources::teams)[side_num_ - 1];
|
||||
//i wonder how this got included here ?
|
||||
|
@ -1423,7 +1424,7 @@ namespace
|
|||
return retv;
|
||||
|
||||
}
|
||||
virtual config random_choice() const
|
||||
virtual config random_choice(int /*side*/) const
|
||||
{
|
||||
config retv;
|
||||
retv["value"] = 0;
|
||||
|
|
|
@ -145,7 +145,7 @@ namespace { // Types
|
|||
, has_text_input(ht), options(o)
|
||||
{}
|
||||
|
||||
virtual config query_user() const
|
||||
virtual config query_user(int /*side*/) const
|
||||
{
|
||||
std::string image = get_image(cfg, speaker);
|
||||
std::string caption = get_caption(cfg, speaker);
|
||||
|
@ -190,7 +190,7 @@ namespace { // Types
|
|||
return cfg;
|
||||
}
|
||||
|
||||
virtual config random_choice() const
|
||||
virtual config random_choice(int /*side*/) const
|
||||
{
|
||||
return config();
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ namespace { // Types
|
|||
: nb_options(o), loc(l), use_dialog(d)
|
||||
{}
|
||||
|
||||
virtual config query_user() const
|
||||
virtual config query_user(int /*side*/) const
|
||||
{
|
||||
int selected;
|
||||
if (use_dialog) {
|
||||
|
@ -221,7 +221,7 @@ namespace { // Types
|
|||
return cfg;
|
||||
}
|
||||
|
||||
virtual config random_choice() const
|
||||
virtual config random_choice(int /*side*/) const
|
||||
{
|
||||
config cfg;
|
||||
cfg["value"] = random_new::generator->next_random() % nb_options;
|
||||
|
@ -1111,7 +1111,7 @@ WML_HANDLER_FUNCTION(message, event_info, cfg)
|
|||
{
|
||||
/* Always show the dialog if it has no input, whether we are
|
||||
replaying or not. */
|
||||
msg.query_user();
|
||||
msg.query_user(resources::controller->current_side());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "util.hpp"
|
||||
#include "variable.hpp"
|
||||
|
||||
|
||||
#include <cassert>
|
||||
|
||||
//TODO: remove LOG_PERSIST, ERR_PERSIST from persist_context.hpp to .cpp files.
|
||||
#define DBG_PERSIST LOG_STREAM(debug, log_persist)
|
||||
|
@ -41,13 +41,14 @@ struct persist_choice: mp_sync::user_choice {
|
|||
, var_name(name)
|
||||
, side(side_num) {
|
||||
}
|
||||
virtual config query_user() const {
|
||||
virtual config query_user(int side_for) const {
|
||||
assert(side == side_for);
|
||||
config ret;
|
||||
ret["side"] = side;
|
||||
ret.add_child("variables",ctx.get_var(var_name));
|
||||
return ret;
|
||||
}
|
||||
virtual config random_choice() const {
|
||||
virtual config random_choice(int /*side_for*/) const {
|
||||
return config();
|
||||
}
|
||||
virtual bool is_visible() const { return false; }
|
||||
|
|
|
@ -998,7 +998,7 @@ static std::map<int, config> get_user_choice_internal(const std::string &name, c
|
|||
/* At least one of the decisions is ours, and it will be inserted
|
||||
into the replay. */
|
||||
DBG_REPLAY << "MP synchronization: local choice\n";
|
||||
config cfg = uch.query_user();
|
||||
config cfg = uch.query_user(local_side);
|
||||
|
||||
recorder.user_input(name, cfg, local_side);
|
||||
retv[local_side]= cfg;
|
||||
|
@ -1098,7 +1098,7 @@ std::map<int,config> mp_sync::get_user_choice_multiple_sides(const std::string &
|
|||
|
||||
BOOST_FOREACH(int side, empty_sides)
|
||||
{
|
||||
retv[side] = uch.random_choice();
|
||||
retv[side] = uch.random_choice(side);
|
||||
}
|
||||
return retv;
|
||||
|
||||
|
@ -1123,7 +1123,7 @@ config mp_sync::get_user_choice(const std::string &name, const mp_sync::user_cho
|
|||
//This doesn't cause problems and someone could use it for example to use a [message][option] inside a wesnoth.synchronize_choice which could be useful,
|
||||
//so just give a warning.
|
||||
WRN_REPLAY << "MP synchronization called during an unsynced context.";;
|
||||
return uch.query_user();
|
||||
return uch.query_user(side);
|
||||
}
|
||||
if(is_too_early && uch.is_visible())
|
||||
{
|
||||
|
@ -1131,7 +1131,7 @@ config mp_sync::get_user_choice(const std::string &name, const mp_sync::user_cho
|
|||
//Although we are able to sync them, we cannot use query_user,
|
||||
//because we cannot (or shouldn't) put things on the screen inside a prestart event, this is true for SP and MP games.
|
||||
//Quotation form event wiki: "For things displayed on-screen such as character dialog, use start instead"
|
||||
return uch.random_choice();
|
||||
return uch.random_choice(side);
|
||||
}
|
||||
//in start events it's unclear to decide on which side the function should be executed (default= side1 still).
|
||||
//But for advancements we can just decide on the side that owns the unit and that's in the responsibility of advance_unit_at.
|
||||
|
|
|
@ -188,8 +188,8 @@ namespace mp_sync {
|
|||
struct user_choice
|
||||
{
|
||||
virtual ~user_choice() {}
|
||||
virtual config query_user() const = 0;
|
||||
virtual config random_choice() const = 0;
|
||||
virtual config query_user(int side) const = 0;
|
||||
virtual config random_choice(int side) const = 0;
|
||||
///whether the choice is visible for the user like an advacement choice
|
||||
///a non-visible choice is for example get_global_variable
|
||||
virtual bool is_visible() const { return true; }
|
||||
|
|
|
@ -2655,17 +2655,17 @@ namespace {
|
|||
lua_State *L;
|
||||
lua_synchronize(lua_State *l): L(l) {}
|
||||
|
||||
virtual config query_user() const
|
||||
virtual config query_user(int side) const
|
||||
{
|
||||
config cfg;
|
||||
int index = 1;
|
||||
if (!lua_isnoneornil(L, 2)) {
|
||||
int side = resources::controller->current_side();
|
||||
if ((*resources::teams)[side - 1].is_ai())
|
||||
index = 2;
|
||||
}
|
||||
lua_pushvalue(L, index);
|
||||
if (luaW_pcall(L, 0, 1, false)) {
|
||||
lua_pushnumber(L, side);
|
||||
if (luaW_pcall(L, 1, 1, false)) {
|
||||
if(!luaW_toconfig(L, -1, cfg) && game_config::debug) {
|
||||
chat_message("Lua warning", "function returned to wesnoth.synchronize_choice a table which was partially invalid");
|
||||
}
|
||||
|
@ -2673,7 +2673,7 @@ namespace {
|
|||
return cfg;
|
||||
}
|
||||
|
||||
virtual config random_choice() const
|
||||
virtual config random_choice(int /*side*/) const
|
||||
{
|
||||
return config();
|
||||
}
|
||||
|
|
|
@ -231,7 +231,7 @@ config synced_context::ask_server(const std::string &name, const mp_sync::user_c
|
|||
/* The decision is ours, and it will be inserted
|
||||
into the replay. */
|
||||
DBG_REPLAY << "MP synchronization: local server choice\n";
|
||||
config cfg = uch.query_user();
|
||||
config cfg = uch.query_user(-1);
|
||||
//-1 for "server" todo: change that.
|
||||
recorder.user_input(name, cfg, -1);
|
||||
return cfg;
|
||||
|
@ -378,7 +378,7 @@ random_seed_choice::~random_seed_choice()
|
|||
|
||||
}
|
||||
|
||||
config random_seed_choice::query_user() const
|
||||
config random_seed_choice::query_user(int /*side*/) const
|
||||
{
|
||||
//getting here means we are in a sp game
|
||||
|
||||
|
@ -387,7 +387,7 @@ config random_seed_choice::query_user() const
|
|||
retv["new_seed"] = rand();
|
||||
return retv;
|
||||
}
|
||||
config random_seed_choice::random_choice() const
|
||||
config random_seed_choice::random_choice(int /*side*/) const
|
||||
{
|
||||
//it obviously doesn't make sense to call the uninitialized random generator to generatoe a seed ofr the same random generator;
|
||||
//this shoud never happen
|
||||
|
|
|
@ -175,8 +175,8 @@ class random_seed_choice : public mp_sync::user_choice
|
|||
public:
|
||||
random_seed_choice();
|
||||
virtual ~random_seed_choice();
|
||||
virtual config query_user() const;
|
||||
virtual config random_choice() const;
|
||||
virtual config query_user(int /*side*/) const;
|
||||
virtual config random_choice(int /*side*/) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue