Skip to content

Commit

Permalink
don't generate "user_description" on the host
Browse files Browse the repository at this point in the history
the host it not capable to generate strings in the correct language.
("(Reserved for $playername)" was resolved on the host). Instead we now
generate the description on the clients.
  • Loading branch information
gfgtdf committed Nov 14, 2014
1 parent f9a3767 commit 1c1621b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
25 changes: 10 additions & 15 deletions src/game_initialization/connect_engine.cpp
Expand Up @@ -940,13 +940,10 @@ config side_engine::new_config() const
(controller_ == CNTR_RESERVED ? reserved_for_ : "");
res["controller"] = (res["current_player"] == preferences::login()) ?
"human" : controller_names[controller_];

if (player_id_.empty()) {
std::string description;
switch(controller_) {
case CNTR_NETWORK:
description = N_("(Vacant slot)");

break;
case CNTR_LOCAL:
if (!parent_.params_.saved_game && !cfg_.has_attribute("save_id")) {
Expand All @@ -956,7 +953,7 @@ config side_engine::new_config() const
res["player_id"] = preferences::login();
res["current_player"] = preferences::login();
description = N_("Anonymous local player");

res["user_description"] = t_string(description, "wesnoth");
break;
case CNTR_COMPUTER: {
if (!parent_.params_.saved_game && !cfg_.has_attribute("saved_id")) {
Expand All @@ -977,39 +974,37 @@ config side_engine::new_config() const

symbols["side"] = res["side"].str();
description = vgettext("$playername $side", symbols);

// Clients might not have ai config description availabe,
// so give them the description in this attribute.
// "user_description" is only used by mp_wait
res["user_description"] = description;
break;
}
case CNTR_EMPTY:
description = N_("(Empty slot)");
res["no_leader"] = true;

break;
case CNTR_RESERVED: {
utils::string_map symbols;
symbols["playername"] = reserved_for_;
description = vgettext("(Reserved for $playername)",symbols);

//will never be the case during the actual game.
break;
}
case CNTR_LAST:
default:
description = N_("(empty)");
assert(false);

break;
} // end switch

res["user_description"] = t_string(description, "wesnoth");
if(res["name"].str().empty() && !description.empty()) {
res["name"] = t_string(description, "wesnoth");
}
} else {
res["player_id"] = player_id_;
if (!parent_.params_.saved_game && !cfg_.has_attribute("save_id")) {
res["save_id"] = player_id_ + res["side"];
}
res["user_description"] = player_id_;
res["name"] = player_id_;
}

res["name"] = res["user_description"];
res["allow_changes"] = allow_changes_;
res["chose_random"] = chose_random_;

Expand Down
37 changes: 36 additions & 1 deletion src/game_initialization/multiplayer_wait.cpp
Expand Up @@ -41,6 +41,7 @@ static lg::log_domain log_network("network");

static lg::log_domain log_enginerefac("enginerefac");
#define LOG_RG LOG_STREAM(info, log_enginerefac)
#define ERR_RG LOG_STREAM(err, log_enginerefac)

namespace {

Expand Down Expand Up @@ -482,6 +483,40 @@ void wait::process_network_data(const config& data, const network::connection so
}
}

static std::string generate_user_description(const config& side)
{
//allow the host to overwrite it, this is needed because only the host knows the ai_algorithm.
if(const config::attribute_value* desc = side.get("user_description")) {
return desc->str();
}

std::string controller_type = side["controller"].str();
std::string reservation = side["reserved_for"].str();
std::string owner = side["player_id"].str();

if(controller_type == "ai") {
return _("Computer Player");
}
else if (controller_type == "null") {
return _("(Empty slot)");
}
else if(owner.empty()) {
return _("(Vacant slot)");
}
else if (controller_type == "reserved") {
utils::string_map symbols;
symbols["playername"] = reservation;
return vgettext("(Reserved for $playername)",symbols);
}
else if (controller_type == "human" || controller_type == "network") {
return owner;
}
else {
ERR_RG << "Found unknown controller type:" << controller_type << std::endl;
return _("(empty)");
}
}

void wait::generate_menu()
{
if (stop_updates_)
Expand All @@ -496,7 +531,7 @@ void wait::generate_menu()
continue;
}

std::string description = sd["user_description"];
std::string description = generate_user_description(sd);

t_string side_name = sd["faction_name"];
std::string leader_type = sd["type"];
Expand Down

0 comments on commit 1c1621b

Please sign in to comment.