From 5d617b9e4f2729fdf252811837f3593e48eeb7c8 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Fri, 5 Jun 2015 16:03:43 +0200 Subject: [PATCH] Allow string identifers in :control :control now also accepts a string as first parameter in this case it searches for a side with save_id matching this string. So for example In LoW you can now use ':controller Kalenz gfgtdf' insetead of ':controller 1 gfgtdf' --- src/menu_events.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/menu_events.cpp b/src/menu_events.cpp index 017f51860271..7b3f95f09f93 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -81,6 +81,7 @@ #include "widgets/combo.hpp" #include +#include static lg::log_domain log_engine("engine"); #define ERR_NG LOG_STREAM(err, log_engine) @@ -2762,6 +2763,17 @@ void console_handler::do_idle() { void console_handler::do_theme() { preferences::show_theme_dialog(*menu_handler_.gui_); } + +struct save_id_matches +{ + save_id_matches(const std::string& save_id) : save_id_(save_id) {} + bool operator()(const team& t) + { + return t.save_id() == save_id_; + } + std::string save_id_; +}; + void console_handler::do_control() { // :control if (network::nconnections() == 0) return; @@ -2772,15 +2784,20 @@ void console_handler::do_control() { command_failed_need_arg(2); return; } - unsigned int side_num; try { side_num = lexical_cast(side); } catch(bad_lexical_cast&) { - utils::string_map symbols; - symbols["side"] = side; - command_failed(vgettext("Can't change control of invalid side: '$side'.", symbols)); - return; + std::vector::const_iterator it_t = boost::find_if(*resources::teams, save_id_matches(side)); + if(it_t == resources::teams->end()) { + utils::string_map symbols; + symbols["side"] = side; + command_failed(vgettext("Can't change control of invalid side: '$side'.", symbols)); + return; + } + else { + side_num = it_t->side(); + } } if (side_num < 1 || side_num > menu_handler_.teams().size()) { utils::string_map symbols;