* Changed the names of some WML parameters...

...transmitted during client - host MP game setup:

original_description => save_id
id => description.

* Now, use "id" as a faction id, to allow the factions name to be
translated by the client. Made the client use the faction it to lookup
the faction name, and not to use the faction name sent by the server.
This commit is contained in:
Philippe Plantier 2005-02-22 23:07:20 +00:00
parent 38d47c316f
commit 1968b66c3f
6 changed files with 32 additions and 27 deletions

View file

@ -78,7 +78,7 @@ connect::side::side(connect& parent, const config& cfg, int index) :
slider_gold_.hide(!enabled_);
id_ = ""; // Id is reset, and not imported from loading savegames
original_description_ = cfg_["description"];
save_id_ = cfg_["save_id"];
faction_ = lexical_cast_default<int>(cfg_["faction"], 0);
std::vector<std::string>::const_iterator itor = std::find(parent_->team_names_.begin(), parent_->team_names_.end(), cfg_["team_name"]);
if(itor == parent_->team_names_.end()) {
@ -104,7 +104,7 @@ connect::side::side(connect& parent, const config& cfg, int index) :
connect::side::side(const side& a) :
parent_(a.parent_), cfg_(a.cfg_),
index_(a.index_), id_(a.id_), original_description_(a.original_description_),
index_(a.index_), id_(a.id_), save_id_(a.save_id_),
controller_(a.controller_),
faction_(a.faction_), team_(a.team_), colour_(a.colour_),
gold_(a.gold_), leader_(a.leader_), /* taken_(a.taken_), */
@ -254,30 +254,27 @@ config connect::side::get_config() const
if(cfg_["side"].empty() || cfg_["side"] != lexical_cast<std::string>(index_ + 1)) {
res["side"] = lexical_cast<std::string>(index_ + 1);
}
res["id"] = id_;
res["controller"] = controller_names[controller_];
res["description"] = id_;
if (id_.empty()) {
switch(controller_) {
case CNTR_NETWORK:
res["description"] = "(Vacant slot)";
res["user_description"] = _("(Vacant slot)");
break;
case CNTR_LOCAL:
if(enabled_ && cfg_["save_id"].empty()) {
res["save_id"] = "local" + res["side"];
}
res["description"] = "Anonymous local player";
res["user_description"] = _("Anonymous local player");
break;
case CNTR_COMPUTER:
if(enabled_ && cfg_["save_id"].empty()) {
res["save_id"] = "ai" + res["side"];
}
res["description"] = "Computer player";
res["user_description"] = _("Computer player");
break;
case CNTR_EMPTY:
res["description"] = "(Empty slot)";
res["user_description"] = _("(Empty slot)");
break;
default:
@ -288,10 +285,8 @@ config connect::side::get_config() const
res["save_id"] = id_;
}
res["description"] = id_;
res["user_description"] = id_;
}
res["original_description"] = original_description_;
if(enabled_) {
if (leader_.empty()) {
@ -369,9 +364,9 @@ void connect::side::set_id(const std::string& id)
update_ui();
}
const std::string& connect::side::get_original_description() const
const std::string& connect::side::get_save_id() const
{
return original_description_;
return save_id_;
}
void connect::side::import_network_user(const config& data)
@ -476,7 +471,7 @@ connect::connect(display& disp, const config& game_config, const game_data& data
int side_choice = 0;
for(side_list::const_iterator s = sides_.begin(); s != sides_.end(); ++s) {
if(s->get_original_description() == preferences::login()) {
if(s->get_save_id() == preferences::login()) {
side_choice = s - sides_.begin();
}
}

View file

@ -72,7 +72,7 @@ public:
// Sets the username of this side
void set_id(const std::string& id);
const std::string& get_original_description() const;
const std::string& get_save_id() const;
// Imports data from the network into this side, and updates
// the UI accordingly.
@ -98,7 +98,7 @@ public:
// Configurable variables
int index_;
std::string id_;
std::string original_description_;
std::string save_id_;
mp::controller controller_;
int faction_;
int team_;

View file

@ -284,10 +284,8 @@ void create::process_event()
for(int pos = parameters_.scenario_data.get_children("side").size(); pos < map_positions; ++pos) {
config& side = parameters_.scenario_data.add_child("side");
side["enemy"] = "1";
char buf[50];
sprintf(buf,"%d",(pos+1));
side["side"] = buf;
side["team_name"] = buf;
side["side"] = lexical_cast<std::string>(pos+1);
side["team_name"] = lexical_cast<std::string>(pos+1);
side["canrecruit"] = "1";
side["controller"] = "human";
}

View file

@ -61,7 +61,8 @@ void wait::leader_preview_pane::draw_contents()
if(selection_ < side_list_.size()) {
const config& side = *side_list_[selection_];
std::string faction = side["name"];
std::string faction = side["faction"];
const std::string recruits = side["recruit"];
const std::vector<std::string> recruit_list = utils::split(recruits);
std::ostringstream recruit_string;
@ -180,8 +181,8 @@ void wait::join_game(bool observe)
//available side.
int side_choice = 0;
for(config::child_list::const_iterator s = sides_list.begin(); s != sides_list.end(); ++s) {
if((**s)["controller"] == "network" && (**s)["id"].empty()) {
if((**s)["original_description"] == preferences::login()) {
if((**s)["controller"] == "network" && (**s)["description"].empty()) {
if((**s)["save_id"] == preferences::login()) {
side_choice = s - sides_list.begin();
}
}
@ -195,6 +196,7 @@ void wait::join_game(bool observe)
throw network::error(_("Era not available"));
return;
}
era_sides_ = *era_cfg;
const config::child_list& possible_sides = era_cfg->get_children("multiplayer_side");
if(possible_sides.empty()) {
@ -254,7 +256,7 @@ void wait::start_game()
const config::child_list& sides_list = level_.get_children("side");
for(config::child_list::const_iterator side = sides_list.begin();
side != sides_list.end(); ++side) {
if((**side)["controller"] == "network" && (**side)["id"] == preferences::login()) {
if((**side)["controller"] == "network" && (**side)["description"] == preferences::login()) {
(**side)["controller"] = preferences::client_type();
} else if((**side)["controller"] != "null") {
(**side)["controller"] = "network";
@ -351,11 +353,19 @@ void wait::generate_menu()
const config& sd = **s;
std::string description = sd["description"];
std::string side_name = sd["name"];
const std::string faction_id = sd["id"];
const config* const faction_cfg =
era_sides_.find_child("multiplayer_side", "id", faction_id);
std::string side_name;
if (faction_cfg != NULL) {
side_name = (*faction_cfg)["name"];
} else {
side_name = sd["name"];
}
std::string leader_type = sd["type"];
if(!sd["id"].empty())
playerlist.push_back(sd["id"]);
if(!sd["description"].empty())
playerlist.push_back(sd["description"]);
std::string leader_name;
std::string leader_image;

View file

@ -74,6 +74,8 @@ private:
// int team_;
const game_data& game_data_;
config era_sides_;
config level_;
game_state state_;

View file

@ -185,7 +185,7 @@ void game::update_side_data()
config::child_iterator sd;
for(sd = level_sides.first; sd != level_sides.second; ++sd) {
if ((**sd)["id"] == info->second.name()) {
if ((**sd)["description"] == info->second.name()) {
break;
}
}
@ -271,7 +271,7 @@ size_t game::available_slots() const
const config::child_list& sides = level_.get_children("side");
for(config::child_list::const_iterator i = sides.begin(); i != sides.end(); ++i) {
std::cerr << "side controller: '" << (**i)["controller"] << "'\n";
if((**i)["controller"] == "network" && (**i)["id"].empty()) {
if((**i)["controller"] == "network" && (**i)["description"].empty()) {
++available_slots;
}
}