Skip to content

Commit

Permalink
add new attribute side_name= in [side]
Browse files Browse the repository at this point in the history
We cannot call it name becasue thats already used by the unti that is
generated from the side tag.

if given (nonempty), side_name= will be used instead of current_player
in some dialogs (new turn dialog, statistics).

In [scenario] side_name= defaults to name= while in [multiplayer]
side_name= defaults to empty (so that current_player is used in those
dialogs by default).

This specially fixes http://gna.org/bugs/?24226 while still giving wml
authors in mp and in sp the option to use the real players name in those
dialogs.
  • Loading branch information
gfgtdf committed Mar 8, 2016
1 parent 0d254fb commit c941f60
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/game_initialization/connect_engine.cpp
Expand Up @@ -1027,6 +1027,7 @@ config side_engine::new_config() const
desc = player_id_;
}
if(res["name"].str().empty() && !desc.empty()) {
//TODO: maybe we should add this in to the leaders config instead of the side config?
res["name"] = desc;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game_initialization/playcampaign.cpp
Expand Up @@ -176,7 +176,7 @@ void campaign_controller::show_carryover_message(playsingle_controller& playcont
continue;
}
if (persistent_teams > 1) {
report << "\n<b>" << t.current_player() << "</b>\n";
report << "\n<b>" << t.side_name() << "</b>\n";
}

report_victory(report, t, finishing_bonus_per_turn, turns_left, finishing_bonus);
Expand Down
2 changes: 1 addition & 1 deletion src/leader_scroll_dialog.cpp
Expand Up @@ -240,7 +240,7 @@ void scenario_settings_table(display& gui, int selected)
}

str << COLUMN_SEPARATOR << team::get_side_highlight(n)
<< teams[n].current_player() << COLUMN_SEPARATOR
<< teams[n].side_name() << COLUMN_SEPARATOR
<< n + 1 << COLUMN_SEPARATOR
<< teams[n].start_gold() << COLUMN_SEPARATOR
<< teams[n].base_income() << COLUMN_SEPARATOR
Expand Down
6 changes: 3 additions & 3 deletions src/menu_events.cpp
Expand Up @@ -154,7 +154,7 @@ void menu_handler::show_statistics(int side_num)
{
team &current_team = teams()[side_num - 1];
// Current Player name
const std::string &player = current_team.current_player();
const std::string &player = current_team.side_name();
//add player's name to title of dialog
std::stringstream title_str;
title_str << _("Statistics") << " (" << player << ")";
Expand Down Expand Up @@ -272,7 +272,7 @@ void menu_handler::status_table(int selected)
}

if (pc_.get_classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)
leader_name = teams()[n].current_player();
leader_name = teams()[n].side_name();

} else {
leader_bools.push_back(false);
Expand Down Expand Up @@ -393,7 +393,7 @@ void menu_handler::scenario_settings_table(int selected)
}

str << COLUMN_SEPARATOR << team::get_side_highlight(n)
<< teams()[n].current_player() << COLUMN_SEPARATOR
<< teams()[n].side_name() << COLUMN_SEPARATOR
<< n + 1 << COLUMN_SEPARATOR
<< teams()[n].start_gold() << COLUMN_SEPARATOR
<< teams()[n].base_income() << COLUMN_SEPARATOR
Expand Down
2 changes: 1 addition & 1 deletion src/playsingle_controller.cpp
Expand Up @@ -430,7 +430,7 @@ void playsingle_controller::show_turn_dialog(){
gui_->recalculate_minimap();
std::string message = _("It is now $name|’s turn");
utils::string_map symbols;
symbols["name"] = gamestate().board_.teams()[current_side() - 1].current_player();
symbols["name"] = gamestate().board_.teams()[current_side() - 1].side_name();
message = utils::interpolate_variables_into_string(message, &symbols);
gui2::show_transient_message(gui_->video(), "", message);
}
Expand Down
4 changes: 2 additions & 2 deletions src/reports.cpp
Expand Up @@ -216,7 +216,7 @@ static config unit_side(reports::context & rc, const unit* u)
std::stringstream text;
text << " " << u->side();

add_image(report, flag_icon + mods, u_team.current_player(), "");
add_image(report, flag_icon + mods, u_team.side_name(), "");
add_text(report, text.str(), "", "");
return report;
}
Expand Down Expand Up @@ -1485,7 +1485,7 @@ REPORT_GENERATOR(side_playing, rc)
std::string mods = "~RC(" + old_rgb + ">" + new_rgb + ")";
if (flag_icon.empty())
flag_icon = game_config::images::flag_icon;
return image_report(flag_icon + mods, active_team.current_player());
return image_report(flag_icon + mods, active_team.side_name());
}

REPORT_GENERATOR(observers, rc)
Expand Down
5 changes: 5 additions & 0 deletions src/saved_game.cpp
Expand Up @@ -168,6 +168,7 @@ void saved_game::write_general_info(config_writer& out) const

void saved_game::set_defaults()
{
const bool is_multiplayer_tag = classification().get_tagname() == "multiplayer";
static const std::vector<std::string> team_defaults = boost::assign::list_of
("carryover_percentage")
("carryover_add")
Expand All @@ -179,6 +180,10 @@ void saved_game::set_defaults()
{
side["save_id"] = side["id"];
}
if(!is_multiplayer_tag && side["side_name"].blank())
{
side["side_name"] = side["name"];
}
// Set some team specific values to their defaults specified in scenario
BOOST_FOREACH(const std::string& att_name, team_defaults)
{
Expand Down
5 changes: 4 additions & 1 deletion src/team.cpp
Expand Up @@ -65,7 +65,7 @@ const boost::container::flat_set<std::string> team::attributes = boost::assign::
("recall_cost")("recruit")("save_id")("id")("scroll_to_leader")
("share_vision")("share_maps")("share_view")("shroud")("shroud_data")("start_gold")
("suppress_end_turn_confirmation")
("team_name")("user_team_name")("village_gold")("village_support")("is_local")
("team_name")("user_team_name")("side_name")("village_gold")("village_support")("is_local")
// Multiplayer attributes.
("action_bonus_count")("allow_changes")("allow_player")("color_lock")
("countdown_time")("disallow_observers")("faction")
Expand All @@ -85,6 +85,7 @@ team::team_info::team_info() :
can_recruit(),
team_name(),
user_team_name(),
side_name(),
save_id(),
current_player(),
countdown_time(),
Expand Down Expand Up @@ -123,6 +124,7 @@ void team::team_info::read(const config &cfg)
income = cfg["income"];
team_name = cfg["team_name"].str();
user_team_name = cfg["user_team_name"];
side_name = cfg["side_name"];
save_id = cfg["save_id"].str();
current_player = cfg["current_player"].str();
countdown_time = cfg["countdown_time"].str();
Expand Down Expand Up @@ -239,6 +241,7 @@ void team::team_info::write(config& cfg) const
cfg["income"] = income;
cfg["team_name"] = team_name;
cfg["user_team_name"] = user_team_name;
cfg["side_name"] = side_name;
cfg["save_id"] = save_id;
cfg["current_player"] = current_player;
cfg["flag"] = flag;
Expand Down
2 changes: 2 additions & 0 deletions src/team.hpp
Expand Up @@ -117,6 +117,7 @@ class team : public savegame::savegame_config
std::set<std::string> can_recruit;
std::string team_name;
t_string user_team_name;
t_string side_name;
std::string save_id;
// 'id' of the current player (not necessarily unique)
std::string current_player;
Expand Down Expand Up @@ -302,6 +303,7 @@ class team : public savegame::savegame_config
void set_flag(const std::string& flag) { info_.flag = flag; }
void set_flag_icon(const std::string& flag_icon) { info_.flag_icon = flag_icon; }

const std::string& side_name() const { return info_.side_name.empty() ? info_.current_player : info_.side_name; }
//Returns true if the hex is shrouded/fogged for this side, or
//any other ally with shared vision.
bool shrouded(const map_location& loc) const;
Expand Down
6 changes: 0 additions & 6 deletions src/teambuilder.cpp
Expand Up @@ -297,12 +297,6 @@ class team_builder {
BOOST_FOREACH(const config *u, unit_configs_) {
uc.add_unit(*u);
}

// Find the first leader and use its name as the player name.
unit_map::iterator u = board_.units().find_first_leader(t_->side());
if ((u != board_.units().end()) && t_->current_player().empty())
t_->set_current_player(u->name());

}

};
Expand Down

0 comments on commit c941f60

Please sign in to comment.