84#define ERR_NG LOG_STREAM(err, log_engine)
85#define LOG_NG LOG_STREAM(info, log_engine)
92 std::string last_created_unit =
"";
93 std::string last_recruit =
"";
94 std::string last_variation =
"";
162 if (unit_dlg->show() && unit_dlg->is_selected()) {
198 symbols[
"msg"] =
e.what();
199 const std::string msg =
VGETTEXT(
"Could not save the map: $msg", symbols);
207 gui2::dialogs::preferences_dialog::display();
215 c[
"name"] =
"prototype of chat log";
227 ?
board().is_observer()
228 ?
_(
"Send to observers only")
229 :
_(
"Send to allies only")
247 if(
board().is_observer()) {
266 std::map<const unit_type*, t_string> err_msgs_map;
267 std::vector<const unit_type*> recruit_list;
268 std::vector<t_string> unknown_units;
274 int selected_index = -1,
i = 0;
279 recruit_list.push_back(type);
282 unknown_units.emplace_back(
recruit);
290 if(type->id() == last_recruit) {
297 if(!unknown_units.empty()) {
302 "Error: there’s an unknown unit type on your recruit list: $unknown_ids",
303 "Error: there are several unknown unit types on your recruit list: $unknown_ids",
304 unknown_units.size(),
305 {{
"unknown_ids", utils::format_conjunct_list(
"", unknown_units) }}
309 if(recruit_list.empty()) {
315 dlg->set_selected_index(selected_index);
316 if (!dlg->show() && !dlg->is_selected()) {
320 const unit_type*
type = recruit_list[dlg->get_selected_index()];
321 last_recruit =
type->id();
324 if(err_msgs_map[type].empty()) {
325 do_recruit(
type->id(), side_num, last_hex);
332void menu_handler::repeat_recruit(
int side_num,
const map_location& last_hex)
334 team& current_team = board().get_team(side_num);
335 const std::string& last_recruit = current_team.
last_recruit();
336 if(last_recruit.empty())
return;
338 const auto validation = std::array
349 for(
const std::string& err : validation) {
356 do_recruit(last_recruit, side_num, last_hex);
359bool menu_handler::do_recruit(
const std::string& type,
int side_num,
const map_location& target_hex)
372 if(
auto wb = pc_.get_whiteboard()) {
373 if(
wb->save_recruit(type, side_num,
dst)) {
379 team& current_team = board().get_team(side_num);
390 if(pc_.get_disallow_recall()) {
395 team& current_team = board().get_team(side_num);
397 std::vector<unit_const_ptr> recall_list_team;
403 DBG_WB <<
"menu_handler::recall: Contents of wb-modified recall list:";
410 _(
"There are no troops available to recall.\n(You must have veteran survivors from a previous scenario.)"));
414 if(recall_list_team.empty()) {
422 dlg->set_show_dismiss(pc_.current_side() == side_num);
424 if(!dlg->show() || !dlg->is_selected()) {
428 int res = dlg->get_selected_index();
437 if(sel_unit->recall_cost() > -1) {
438 unit_cost = sel_unit->recall_cost();
441 int wb_gold = pc_.get_whiteboard() ? pc_.get_whiteboard()->get_spent_gold_for(side_num) : 0;
443 if(current_team.
gold() - wb_gold < unit_cost) {
445 i18n_symbols[
"cost"] = std::to_string(unit_cost);
446 std::string msg =
VNGETTEXT(
"You must have at least 1 gold piece to recall a unit.",
447 "You must have at least $cost gold pieces to recall this unit.", unit_cost, i18n_symbols);
452 LOG_NG <<
"recall index: " << res;
469 if(!pc_.get_whiteboard()
470 || !pc_.get_whiteboard()->save_recall(*sel_unit, side_num, recall_location)) {
475 ERR_NG <<
"menu_handler::recall(): Unit does not exist in the recall list.";
481void menu_handler::show_enemy_moves(
bool ignore_units,
int side_num)
488 gui_->unhighlight_reach();
491 for(
auto& u : pc_.get_units()) {
492 bool invisible = u.invisible(u.get_location());
494 if(board().get_team(side_num).is_enemy(u.side()) && !gui_->fogged(u.get_location()) && !u.incapacitated()
498 =
pathfind::paths(u,
false,
true, gui_->viewing_team(), 0,
false, ignore_units);
500 gui_->highlight_another_reach(path, hex_under_mouse);
504 gui_->invalidate(u.get_location());
509 const bool selected_hex_has_unit = mh.
hex_hosts_unit(hex_under_mouse);
511 if(selected_hex_has_unit) {
520void menu_handler::toggle_shroud_updates(
int side_num)
522 team& current_team = board().get_team(side_num);
526 update_shroud_now(side_num);
533void menu_handler::update_shroud_now(
int )
542bool units_alive(
int side_num,
const unit_map& units)
544 for(
auto&
unit : units) {
554 int side_num,
const unit_map& units,
const game_board& board,
const std::shared_ptr<wb::manager>& whiteb)
556 for(
auto&
unit : units) {
571 int side_num,
const unit_map& units,
const game_board& board,
const std::shared_ptr<wb::manager>& whiteb)
573 for(
auto&
unit : units) {
576 && (!whiteb || !whiteb->unit_has_actions(&
unit))) {
586bool menu_handler::end_turn(
int side_num)
591 reason =
_(
"You cannot end your turn yet!");
597 std::size_t team_num =
static_cast<std::size_t
>(side_num - 1);
598 if(team_num < pc_.get_teams().size() && pc_.get_teams()[team_num].no_turn_confirmation()) {
603 && (!pc_.get_whiteboard() || !pc_.get_whiteboard()->current_side_has_actions())
604 && units_alive(side_num, pc_.get_units())) {
606 _(
"You have not started your turn yet. Do you really want to end your turn?"),
613 else if(
prefs::get().yellow_confirm() && partmoved_units(side_num, pc_.get_units(), board(), pc_.get_whiteboard())) {
615 _(
"Some units have movement left. Do you really want to end your turn?"),
622 else if(
prefs::get().green_confirm() && unmoved_units(side_num, pc_.get_units(), board(), pc_.get_whiteboard())) {
624 _(
"Some units have not moved. Do you really want to end your turn?"),
633 if(pc_.get_whiteboard() && !pc_.get_whiteboard()->allow_end_turn()) {
640void menu_handler::goto_leader(
int side_num)
643 if(
i != pc_.get_units().end() &&
i->is_visible_to_team(gui_->viewing_team(),
false)) {
648void menu_handler::unit_description()
651 if(un != pc_.get_units().end()) {
659 if(pc_.get_map().on_board(
loc) ==
false || gui_->shrouded(
loc)) {
668void menu_handler::rename_unit()
671 if(un == pc_.get_units().end() || gui_->viewing_team().side() != un->side()) {
675 if(un->unrenamable()) {
679 std::string name = un->name();
680 const std::string title(
_(
"Rename Unit"));
681 const std::string
label(
_(
"Name:"));
683 if(edit_text::execute(title,
label, name)) {
686 gui_->invalidate_unit();
692 const mouse_handler& mousehandler = pc_.get_mouse_handler_base();
693 const bool see_all = gui_->show_everything() || (pc_.is_replay() && pc_.get_replay_controller()->see_all());
696 if(res != pc_.get_units().end()) {
707typedef std::tuple<const unit_type*, unit_race::GENDER, std::string> type_gender_variation;
716type_gender_variation choose_unit()
722 for (std::size_t
i = 0;
i < types_list.size();
i++) {
723 if (types_list[
i]->
id() == last_created_unit) {
724 create_dlg->set_selected_index(
i);
725 create_dlg->set_gender(last_gender);
726 create_dlg->set_variation(last_variation);
732 if(!create_dlg->show()) {
736 if(!create_dlg->is_selected()) {
740 const unit_type* ut = types_list[create_dlg->get_selected_index()];
741 last_created_unit = ut->
id();
742 last_gender = create_dlg->gender();
743 last_variation = create_dlg->variation();
746 if (create_dlg->is_selected()) {
747 info = type_gender_variation(ut, last_gender, last_variation);
749 ERR_NG <<
"Create unit dialog returned nonexistent or unusable unit_type id.";
760void create_and_place(
764 const std::string& variation =
"")
772 "variation", variation,
789 if(
const auto& [type, gender, variation] = choose_unit(); type !=
nullptr) {
790 create_and_place(destination, *type, gender, variation);
798 if(
i == pc_.get_units().end()) {
799 if(!pc_.get_map().is_village(
loc)) {
807 if(
team >
static_cast<int>(pc_.get_teams().size())) {
812 int side =
i->side();
814 if(side >
static_cast<int>(pc_.get_teams().size())) {
819 if(pc_.get_map().is_village(
loc)) {
831void menu_handler::label_terrain(
mouse_handler& mousehandler,
bool team_only)
834 if(pc_.get_map().on_board(
loc) ==
false) {
839 std::string
label = old_label ? old_label->
text() :
"";
841 if(edit_label::execute(
label, team_only)) {
842 std::string team_name;
846 team_name = gui_->labels().team_name();
850 const terrain_label* res = gui_->labels().set_label(
loc,
label, gui_->viewing_team_index(), team_name, color);
857void menu_handler::clear_labels()
859 if(!board().is_observer()) {
862 _(
"Are you sure you want to clear map labels?"),
867 std::string viewing_team = gui_->viewing_team().team_name();
868 gui_->labels().clear(viewing_team,
false);
874void menu_handler::label_settings()
876 if(label_settings::execute(board())) {
877 gui_->labels().recalculate_labels();
884 if(
i == pc_.get_units().end() || !
i->move_interrupted()) {
886 if(
i == pc_.get_units().end() || !
i->move_interrupted()) {
890 move_unit_to_loc(
i,
i->get_interrupted_move(),
true, side_num, mousehandler);
893void menu_handler::move_unit_to_loc(
900 assert(ui != pc_.get_units().end());
904 if(route.
steps.empty()) {
908 assert(route.
steps.front() == ui->get_location());
910 gui_->set_route(&route);
911 gui_->unhighlight_reach();
914 LOG_NG <<
"move_unit_to_loc " << route.
steps.front() <<
" to " << route.
steps.back();
919 gui_->set_route(
nullptr);
920 gui_->invalidate_game_status();
929 bool wait_blocker_move =
true;
930 std::set<map_location> fully_moved;
933 bool blocked_unit =
false;
936 blocked_unit =
false;
937 for(
auto&
unit : pc_.get_units()) {
945 if(goto_loc == current_loc) {
950 if(!pc_.get_map().on_board(goto_loc)) {
955 if(fully_moved.count(current_loc)) {
961 if(route.
steps.size() <= 1) {
962 fully_moved.insert(current_loc);
968 pathfind::marked_route::mark_map::const_iterator
w = route.
marks.begin();
969 for(;
w != route.
marks.end(); ++
w) {
970 if(
w->second.turns == 1) {
971 next_stop =
w->first;
976 if(next_stop == current_loc) {
977 fully_moved.insert(current_loc);
983 if(pc_.get_units().count(next_stop)) {
985 if(wait_blocker_move)
989 gui_->set_route(&route);
992 LOG_NG <<
"execute goto from " << route.
steps.front() <<
" to " << route.
steps.back();
999 wait_blocker_move =
true;
1003 if(!change && wait_blocker_move) {
1005 wait_blocker_move =
false;
1008 }
while(change && blocked_unit);
1011 gui_->set_route(
nullptr);
1012 gui_->invalidate_game_status();
1015void menu_handler::toggle_ellipses()
1018 gui_->invalidate_all();
1021void menu_handler::toggle_grid()
1024 gui_->invalidate_all();
1030 if(un != pc_.get_units().end() && un->side() == side_num && un->movement_left() >= 0) {
1031 un->toggle_hold_position();
1036 if(un->hold_position()) {
1045 if(un != pc_.get_units().end() && un->side() == side_num && un->movement_left() >= 0) {
1046 un->toggle_user_end_turn();
1051 if(un->user_end_turn()) {
1063void menu_handler::search()
1065 std::ostringstream msg;
1067 if(last_search_hit_.valid()) {
1068 msg <<
" [" << last_search_ <<
"]";
1074bool menu_handler::do_speak()
1078 return chat_handler::do_speak(
1079 textbox_info_.box()->text(), textbox_info_.check() !=
nullptr ? textbox_info_.check()->checked() :
false);
1082void menu_handler::add_chat_message(
const std::chrono::system_clock::time_point& time,
1083 const std::string& speaker,
1088 gui_->get_chat_manager().add_chat_message(time, speaker, side,
message, type,
false);
1114 using chmap::dispatch;
1115 using chmap::get_commands_list;
1116 using chmap::command_failed;
1122 chat_command_handler::command_handler
h,
1123 const std::string&
help =
"",
1124 const std::string& usage =
"",
1125 const std::string& flags =
"")
1127 chmap::register_command(cmd,
h,
help, usage, flags +
"N");
1132 chmap::register_alias(
to_cmd, cmd);
1137 return chmap::get_arg(
i);
1142 return chmap::get_cmd();
1147 return chmap::get_data(
n);
1151 using chmap::register_command;
1152 using chmap::register_alias;
1154 using chmap::is_enabled;
1155 using chmap::command_failed_need_arg;
1163 void do_controller();
1165 void do_foreground();
1168 void do_benchmark();
1170 void do_save_quit();
1172 void do_ignore_replay_errors();
1174 void do_next_level();
1175 void do_choose_level();
1177 void do_turn_limit();
1181 void do_unsafe_lua();
1183 void do_set_alias();
1187 void do_control_dialog();
1192 void do_undiscover();
1198 void do_toggle_draw_coordinates();
1199 void do_toggle_draw_terrain_codes();
1200 void do_toggle_draw_num_of_bitmaps();
1201 void do_toggle_whiteboard();
1202 void do_whiteboard_options();
1206 return _(
"(D) — debug only, (N) — network only, (A) — admin only");
1209 using chat_command_handler::get_command_flags_description;
1212 std::string
space(
" ");
1213 return (
c.has_flag(
'D') ?
space +
_(
"(debug command)") :
"")
1214 + (
c.has_flag(
'N') ?
space +
_(
"(network only)") :
"")
1215 + (
c.has_flag(
'A') ?
space +
_(
"(admin only)") :
"")
1216 + (
c.has_flag(
'S') ?
space +
_(
"(not during other events)") :
"");
1219 using map::is_enabled;
1223 || (
c.has_flag(
'N') && !menu_handler_.pc_.is_networked_mp())
1230 menu_handler_.add_chat_message(std::chrono::system_clock::now(), title, 0,
message);
1235 chat_command_handler::init_map();
1237 chmap::get_command(
"log")->flags =
"";
1238 chmap::get_command(
"version")->flags =
"";
1239 chmap::get_command(
"ignore")->flags =
"";
1240 chmap::get_command(
"friend")->flags =
"";
1241 chmap::get_command(
"remove")->flags =
"";
1243 chmap::set_cmd_prefix(
":");
1244 chmap::set_cmd_flag(
true);
1246 register_command(
"refresh", &console_handler::do_refresh,
_(
"Refresh gui."));
1247 register_command(
"droid", &console_handler::do_droid,
_(
"Switch a side to/from AI control."),
1251 _(
"[<side> [on/off/full]]\n“on” = enable but retain vision, “full” = as if it’s controlled by another player"));
1252 register_command(
"terrain", &console_handler::do_terrain,
_(
"Change terrain type of current hex"),
1254 _(
"<terrain type> [both|base|overlay]"),
"DS");
1255 register_command(
"idle", &console_handler::do_idle,
_(
"Switch a side to/from idle state."),
1259 _(
"command_idle^[<side> [on/off]]"));
1260 register_command(
"theme", &console_handler::do_theme,
_(
"Change the in-game theme."));
1261 register_command(
"control", &console_handler::do_control,
1262 _(
"Assign control of a side to a different player or observer."),
_(
"<side> <nickname>"),
"N");
1263 register_command(
"controller", &console_handler::do_controller,
_(
"Query the controller status of a side."),
1265 register_command(
"clear", &console_handler::do_clear,
_(
"Clear chat history."));
1266 register_command(
"foreground", &console_handler::do_foreground,
_(
"Debug foreground terrain."),
"",
"D");
1268 "layers", &console_handler::do_layers,
_(
"Debug layers from terrain under the mouse."),
"",
"D");
1269 register_command(
"fps", &console_handler::do_fps,
_(
"Display and log fps (Frames Per Second)."));
1270 register_command(
"benchmark", &console_handler::do_benchmark,
_(
"Similar to the ‘fps’ command, but also forces everything to redraw instead of only things that have changed."));
1271 register_command(
"save", &console_handler::do_save,
_(
"Save game."));
1272 register_alias(
"save",
"w");
1273 register_command(
"quit", &console_handler::do_quit,
_(
"Quit game."));
1275 register_alias(
"quit",
"q!");
1276 register_command(
"save_quit", &console_handler::do_save_quit,
_(
"Save and quit."));
1277 register_alias(
"save_quit",
"wq");
1278 register_command(
"ignore_replay_errors", &console_handler::do_ignore_replay_errors,
_(
"Ignore replay errors."));
1279 register_command(
"nosaves", &console_handler::do_nosaves,
_(
"Disable autosaves."));
1280 register_command(
"next_level", &console_handler::do_next_level,
1281 _(
"Advance to the next scenario, or scenario identified by ‘id’"),
_(
"<id>"),
"DS");
1282 register_alias(
"next_level",
"n");
1283 register_command(
"choose_level", &console_handler::do_choose_level,
_(
"Choose next scenario"),
"",
"DS");
1284 register_alias(
"choose_level",
"cl");
1285 register_command(
"turn", &console_handler::do_turn,
1286 _(
"Change turn number (and time of day), or increase by one if no number is specified."),
_(
"[turn]"),
1288 register_command(
"turn_limit", &console_handler::do_turn_limit,
1289 _(
"Change turn limit, or turn the turn limit off if no number is specified or it’s −1."),
_(
"[limit]"),
1291 register_command(
"debug", &console_handler::do_debug,
_(
"Turn debug mode on."));
1292 register_command(
"nodebug", &console_handler::do_nodebug,
_(
"Turn debug mode off."),
"",
"D");
1294 "lua", &console_handler::do_lua,
_(
"Execute a Lua statement."),
_(
"<command>[;<command>...]"),
"DS");
1296 "unsafe_lua", &console_handler::do_unsafe_lua,
_(
"Grant higher privileges to Lua scripts."),
"",
"D");
1297 register_command(
"custom", &console_handler::do_custom,
_(
"Set the command used by the custom command hotkey"),
1298 _(
"<command>[;<command>...]"));
1299 register_command(
"give_control", &console_handler::do_control_dialog,
1300 _(
"Invoke a dialog allowing changing control of MP sides."),
"",
"N");
1301 register_command(
"inspect", &console_handler::do_inspect,
_(
"Launch the gamestate inspector"),
"",
"D");
1303 "alias", &console_handler::do_set_alias,
_(
"Set or show alias to a command"),
_(
"<name>[=<command>]"));
1305 "set_var", &console_handler::do_set_var,
_(
"Set a scenario variable."),
_(
"<var>=<value>"),
"DS");
1306 register_command(
"show_var", &console_handler::do_show_var,
_(
"Show a scenario variable."),
_(
"<var>"),
"D");
1307 register_command(
"unit", &console_handler::do_unit,
1309 _(
"Modify a unit variable. (Only top level keys are supported, and advances=<number>.)"),
1310 _(
"<var>=<value>"),
"DS");
1316 register_command(
"discover", &console_handler::do_discover,
_(
"Discover all units in help."),
"");
1317 register_command(
"undiscover", &console_handler::do_undiscover,
_(
"‘Undiscover’ all units in help."),
"");
1318 register_command(
"create", &console_handler::do_create,
_(
"Create a unit."),
_(
"<unit type id>"),
"DS");
1319 register_command(
"fog", &console_handler::do_fog,
_(
"Toggle fog for the current player."),
"",
"DS");
1320 register_command(
"shroud", &console_handler::do_shroud,
_(
"Toggle shroud for the current player."),
"",
"DS");
1321 register_command(
"gold", &console_handler::do_gold,
_(
"Give gold to the current player."),
_(
"<amount>"),
"DS");
1322 register_command(
"throw", &console_handler::do_event,
_(
"Fire a game event."),
_(
"<event name>"),
"DS");
1323 register_alias(
"throw",
"fire");
1324 register_command(
"show_coordinates", &console_handler::do_toggle_draw_coordinates,
1325 _(
"Toggle overlaying of x,y coordinates on hexes."));
1326 register_alias(
"show_coordinates",
"sc");
1327 register_command(
"show_terrain_codes", &console_handler::do_toggle_draw_terrain_codes,
1328 _(
"Toggle overlaying of terrain codes on hexes."));
1329 register_alias(
"show_terrain_codes",
"tc");
1330 register_command(
"show_num_of_bitmaps", &console_handler::do_toggle_draw_num_of_bitmaps,
1331 _(
"Toggle overlaying of number of bitmaps on hexes."));
1332 register_alias(
"show_num_of_bitmaps",
"bn");
1333 register_command(
"whiteboard", &console_handler::do_toggle_whiteboard,
_(
"Toggle planning mode."));
1334 register_alias(
"whiteboard",
"wb");
1336 "whiteboard_options", &console_handler::do_whiteboard_options,
_(
"Access whiteboard options dialog."));
1337 register_alias(
"whiteboard_options",
"wbo");
1341 register_alias(
value, key);
1351void menu_handler::send_chat_message(
const std::string&
message,
bool allies_only)
1356 auto now = std::chrono::system_clock::now();
1359 const int side = board().
is_observer() ? 0 : gui_->viewing_team().side();
1360 if(!board().is_observer()) {
1364 bool private_message = has_friends() && allies_only;
1366 if(private_message) {
1367 if(board().is_observer()) {
1370 cfg[
"to_sides"] = gui_->viewing_team().allied_human_teams();
1376 add_chat_message(now,
cfg[
"id"], side,
message,
1380void menu_handler::do_search(
const std::string& new_search)
1382 if(new_search.empty() ==
false && new_search != last_search_)
1383 last_search_ = new_search;
1385 if(last_search_.empty())
1391 std::vector<std::string> args =
utils::split(last_search_,
',');
1392 if(args.size() == 2) {
1394 x = lexical_cast_default<int>(args[0], 0) - 1;
1395 y = lexical_cast_default<int>(args[1], 0) - 1;
1396 if(x >= 0 && x < pc_.get_map().w() && y >= 0 && y < pc_.get_map().h()) {
1409 loc.
x = (
loc.
x + 1) % pc_.get_map().w();
1411 loc.
y = (
loc.
y + 1) % pc_.get_map().h();
1414 if(!gui_->shrouded(
loc)) {
1417 const std::string& label_text =
label->text().str();
1423 if(!gui_->fogged(
loc)) {
1425 if(ui != pc_.get_units().end()) {
1426 const std::string&
unit_name = ui->name();
1428 if(!gui_->viewing_team().is_enemy(ui->side())
1429 || !ui->invisible(ui->get_location())) {
1441 last_search_hit_ =
loc;
1443 gui_->highlight_hex(
loc);
1448 symbols[
"search"] = last_search_;
1449 const std::string msg =
VGETTEXT(
"Could not find label or unit "
1450 "containing the string ‘$search’.",
1456void menu_handler::do_command(
const std::string& str)
1462std::vector<std::string> menu_handler::get_commands_list()
1473void console_handler::do_refresh()
1478 menu_handler_.gui_->create_buttons();
1479 menu_handler_.gui_->queue_rerender();
1482void console_handler::do_droid()
1485 const std::string
side_s = get_arg(1);
1486 std::string action = get_arg(2);
1487 std::transform(action.begin(), action.end(), action.begin(),
tolower);
1490 const bool is_your_turn = menu_handler_.pc_.current_side() ==
static_cast<int>(menu_handler_.gui_->viewing_team().side());
1491 team&
team = menu_handler_.board().get_team(side);
1494 symbols[
"side"] = std::to_string(side);
1497 command_failed(
VGETTEXT(
"Can’t droid invalid side: ‘$side’.",
symbols));
1500 command_failed(
VGETTEXT(
"Can’t droid networked side: ‘$side’.",
symbols));
1510 if(action ==
"on") {
1512 command_failed(
_(
"It is not allowed to change a side from AI to human control when it’s not your turn."));
1515 if(!is_human || !is_droid) {
1520 menu_handler_.pc_.send_to_wesnothd(
config {
"change_controller",
config {
"side", side,
"player",
prefs::get().
login(),
"to", side_controller::human}});
1526 }
else if(action ==
"off") {
1528 command_failed(
_(
"It is not allowed to change a side from AI to human control when it’s not your turn."));
1531 if(!is_human || !is_proxy_human) {
1536 menu_handler_.pc_.send_to_wesnothd(
config {
"change_controller",
config {
"side", side,
"player",
prefs::get().
login(),
"to", side_controller::human}});
1542 }
else if(action ==
"full") {
1544 command_failed(
_(
"It is not allowed to change a side from human to AI control when it’s not your turn."));
1547 if(!is_ai || !is_droid) {
1551 if(is_human || is_proxy_human) {
1552 menu_handler_.pc_.send_to_wesnothd(
config {
"change_controller",
config {
"side", side,
"player",
prefs::get().
login(),
"to", side_controller::ai}});
1554 print(get_cmd(),
VGETTEXT(
"Side ‘$side’ controller is now fully controlled by: AI.",
symbols));
1558 }
else if(action ==
"") {
1560 command_failed(
_(
"It is not allowed to change a side from AI to human control when it’s not your turn."));
1563 if(is_ai || is_droid) {
1568 menu_handler_.pc_.send_to_wesnothd(
config {
"change_controller",
config {
"side", side,
"player",
prefs::get().
login(),
"to", side_controller::human}});
1576 menu_handler_.pc_.send_to_wesnothd(
config {
"change_controller",
config {
"side", side,
"player",
prefs::get().
login(),
"to", side_controller::human}});
1581 print(get_cmd(),
VGETTEXT(
"Invalid action provided for side ‘$side’. Valid actions are: on, off, full.",
symbols));
1584 if(team_num_ == side &&
changed) {
1586 psc->set_player_type_changed();
1590 command_failed(
VGETTEXT(
"Side ‘$side’ is not a human or AI player.",
symbols));
1593 menu_handler_.textbox_info_.close();
1596void console_handler::do_terrain()
1600 const std::string
mode_str = get_arg(2);
1615void console_handler::do_idle()
1618 const std::string
side_s = get_arg(1);
1619 const std::string action = get_arg(2);
1622 team&
team = menu_handler_.board().get_team(side);
1627 command_failed(
VGETTEXT(
"Can’t idle invalid side: ‘$side’.",
symbols));
1631 symbols[
"side"] = std::to_string(side);
1632 command_failed(
VGETTEXT(
"Can’t idle networked side: ‘$side’.",
symbols));
1636 symbols[
"side"] = std::to_string(side);
1637 command_failed(
VGETTEXT(
"Can’t idle local ai side: ‘$side’.",
symbols));
1640 if(
team.
is_idle() ? action ==
" on" : action ==
" off") {
1645 if(team_num_ == side) {
1647 psc->set_player_type_changed();
1651 menu_handler_.textbox_info_.close();
1654void console_handler::do_theme()
1659void console_handler::do_control()
1662 if(!menu_handler_.pc_.is_networked_mp()) {
1666 const std::string side = get_arg(1);
1667 const std::string player = get_arg(2);
1668 if(player.empty()) {
1669 command_failed_need_arg(2);
1673 unsigned int side_num;
1677 const auto& teams = menu_handler_.pc_.get_teams();
1680 if(
it_t == teams.end()) {
1683 command_failed(
VGETTEXT(
"Can’t change control of invalid side: ‘$side’.",
symbols));
1686 side_num =
it_t->side();
1693 command_failed(
VGETTEXT(
"Can’t change control of out-of-bounds side: ‘$side’.",
symbols));
1697 menu_handler_.request_control_change(side_num, player);
1698 menu_handler_.textbox_info_.close();
1701void console_handler::do_controller()
1703 const std::string side = get_arg(1);
1704 unsigned int side_num;
1710 command_failed(
VGETTEXT(
"Can’t query control of invalid side: ‘$side’.",
symbols));
1717 command_failed(
VGETTEXT(
"Can’t query control of out-of-bounds side: ‘$side’.",
symbols));
1722 if(!menu_handler_.board().get_team(side_num).is_proxy_human()) {
1726 if(menu_handler_.board().get_team(side_num).is_network()) {
1727 report +=
" (networked)";
1730 print(get_cmd(), report);
1733void console_handler::do_clear()
1735 menu_handler_.gui_->get_chat_manager().clear_chat_messages();
1738void console_handler::do_foreground()
1741 menu_handler_.gui_->invalidate_all();
1744void console_handler::do_layers()
1746 display& disp = *(menu_handler_.gui_);
1760 if(menu_handler_.pc_.get_map().on_board_with_border(
loc)) {
1761 terrain_layers::display(disp,
loc);
1765void console_handler::do_fps()
1770void console_handler::do_benchmark()
1775void console_handler::do_save()
1777 menu_handler_.pc_.do_consolesave(get_data());
1780void console_handler::do_save_quit()
1786void console_handler::do_quit()
1791void console_handler::do_ignore_replay_errors()
1796void console_handler::do_nosaves()
1801void console_handler::do_next_level()
1806void console_handler::do_choose_level()
1808 std::string tag = menu_handler_.pc_.get_classification().get_tagname();
1809 std::vector<std::string> options;
1811 if(tag !=
"multiplayer") {
1812 for(
const config&
sc : menu_handler_.game_config_.child_range(tag)) {
1813 const std::string&
id =
sc[
"id"];
1814 options.push_back(
id);
1815 if(
id == menu_handler_.gamedata().next_scenario()) {
1822 std::string scenario_id = menu_handler_.pc_.get_mp_settings().mp_scenario;
1823 if(
auto this_scenario = menu_handler_.game_config_.find_child(tag,
"id", scenario_id)) {
1825 for(
const config&
sc : menu_handler_.game_config_.child_range(tag)) {
1826 if(
sc[
"addon_id"] == addon_id) {
1827 std::string
id =
sc[
"id"];
1828 options.push_back(
id);
1829 if(
id == menu_handler_.gamedata().next_scenario()) {
1836 std::sort(options.begin(), options.end());
1837 int choice = std::distance(options.begin(), std::lower_bound(options.begin(), options.end(), next));
1840 dlg.set_selected_index(choice);
1842 choice =
dlg.selected_index();
1849 if(std::size_t(choice) < options.size()) {
1854void console_handler::do_turn()
1856 tod_manager& tod_man = menu_handler_.gamestate().tod_manager_;
1858 int turn = tod_man.
turn() + 1;
1859 const std::string&
data = get_data();
1866void console_handler::do_turn_limit()
1872void console_handler::do_debug()
1875 print(get_cmd(),
_(
"Debug mode activated!"));
1878 command_failed(
_(
"Debug mode not available in network games"));
1882void console_handler::do_nodebug()
1885 print(get_cmd(),
_(
"Debug mode deactivated!"));
1890void console_handler::do_lua()
1892 if(!menu_handler_.gamestate().lua_kernel_) {
1899void console_handler::do_unsafe_lua()
1901 if(!menu_handler_.gamestate().lua_kernel_) {
1906 _(
"Executing Lua code in in this manner opens your computer to potential security breaches from any "
1907 "malicious add-ons or other programs you may have installed.\n\n"
1911 print(get_cmd(),
_(
"Unsafe mode enabled!"));
1912 menu_handler_.gamestate().lua_kernel_->load_package();
1916void console_handler::do_custom()
1921void console_handler::do_set_alias()
1923 const std::string
data = get_data();
1924 const std::string::const_iterator j = std::find(
data.begin(),
data.end(),
'=');
1925 const std::string
alias(
data.begin(), j);
1926 if(j !=
data.end()) {
1927 const std::string command(j + 1,
data.end());
1928 if(!command.empty()) {
1929 register_alias(command,
alias);
1941 const std::string command = chmap::get_actual_cmd(
alias);
1942 print(get_cmd(),
"'" +
alias +
"'" +
" = " +
"'" + command +
"'");
1946void console_handler::do_set_var()
1948 const std::string
data = get_data();
1950 command_failed_need_arg(1);
1954 const std::string::const_iterator j = std::find(
data.begin(),
data.end(),
'=');
1955 if(j !=
data.end()) {
1956 const std::string name(
data.begin(), j);
1957 const std::string
value(j + 1,
data.end());
1960 command_failed(
_(
"Variable not found"));
1964void console_handler::do_show_var()
1969void console_handler::do_inspect()
1972 gamestate_inspector::display(
1976void console_handler::do_control_dialog()
1978 mp_change_control::display(menu_handler_);
1981void console_handler::do_unit()
1989 if(
i == menu_handler_.pc_.get_units().end()) {
1993 "Debug command ‘unit: $unit’ failed: no unit selected or hovered over.",
1999 const std::string
data = get_data(1);
2001 if(parameters.size() < 2) {
2005 if(parameters[0] ==
"alignment") {
2009 symbols[
"alignment"] = get_arg(1);
2011 "Invalid alignment: ‘$alignment’, needs to be one of lawful, neutral, chaotic, or liminal.",
2021 "name", parameters[0],
2022 "value", parameters[1],
2027void console_handler::do_discover()
2029 for(
const unit_type_data::unit_type_map::value_type&
i :
unit_types.
types()) {
2034void console_handler::do_undiscover()
2044void console_handler::do_create()
2048 if(menu_handler_.pc_.get_map().on_board(
loc)) {
2051 command_failed(
_(
"Invalid unit type"));
2058 command_failed(
_(
"Invalid location"));
2062void console_handler::do_fog()
2067void console_handler::do_shroud()
2072void console_handler::do_gold()
2077void console_handler::do_event()
2082void console_handler::do_toggle_draw_coordinates()
2085 menu_handler_.gui_->invalidate_all();
2087void console_handler::do_toggle_draw_terrain_codes()
2090 menu_handler_.gui_->invalidate_all();
2093void console_handler::do_toggle_draw_num_of_bitmaps()
2096 menu_handler_.gui_->invalidate_all();
2099void console_handler::do_toggle_whiteboard()
2101 if(
const std::shared_ptr<wb::manager>&
whiteb = menu_handler_.pc_.get_whiteboard()) {
2103 if(
whiteb->is_active()) {
2104 print(get_cmd(),
_(
"Planning mode activated!"));
2105 whiteb->print_help_once();
2107 print(get_cmd(),
_(
"Planning mode deactivated!"));
2112void console_handler::do_whiteboard_options()
2114 if(menu_handler_.pc_.get_whiteboard()) {
2115 menu_handler_.pc_.get_whiteboard()->options_dlg();
2124 add_chat_message(std::chrono::system_clock::now(),
"wfl", 0, result.
to_debug_string());
2131void menu_handler::user_command()
2136void menu_handler::request_control_change(
int side_num,
const std::string& player)
2138 std::string side = std::to_string(side_num);
2139 if(board().get_team(side_num).is_local_human() && player ==
prefs::get().login()) {
2145 pc_.send_to_wesnothd(
config {
"change_controller",
config {
"side", side,
"player", player}});
2149void menu_handler::custom_command()
2152 do_command(command);
2156void menu_handler::ai_formula()
2158 if(!pc_.is_networked_mp()) {
2163void menu_handler::clear_messages()
2165 gui_->get_chat_manager().clear_chat_messages();
2170 pc_.send_to_wesnothd(
cfg);
Various functions related to moving units.
A config object defines a single node in a WML file, with access to child nodes.
int village_owner(const map_location &loc) const
Given the location of a village, will return the 1-based number of the team that currently owns it,...
bool is_observer() const
Check if we are an observer in this game.
can_move_result unit_can_move(const unit &u) const
Work out what u can do - this does not check which player's turn is currently active,...
virtual const unit_map & units() const =0
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
const team & viewing_team() const
@ DEBUG_COORDINATES
Overlays x,y coords on tiles.
@ DEBUG_BENCHMARK
Toggle to continuously redraw the whole map.
@ DEBUG_NUM_BITMAPS
Overlays number of bitmaps on tiles.
@ DEBUG_FOREGROUND
Separates background and foreground terrain layers.
@ DEBUG_TERRAIN_CODES
Overlays terrain codes on tiles.
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
void queue_rerender()
Marks everything for rendering including all tiles and sidebar.
const display_context & context() const
virtual std::string get_arg(unsigned i) const
std::string get_flags_description() const
virtual std::string get_cmd() const
console_handler(menu_handler &menu_handler)
void print(const std::string &title, const std::string &message)
virtual void register_alias(const std::string &to_cmd, const std::string &cmd)
bool is_enabled(const chmap::command &c) const
virtual std::string get_data(unsigned n=1) const
menu_handler & menu_handler_
std::string get_command_flags_description(const chmap::command &c) const
virtual void register_command(const std::string &cmd, chat_command_handler::command_handler h, const std::string &help="", const std::string &usage="", const std::string &flags="")
map_command_handler< console_handler > chmap
const unsigned int team_num_
bool dispatch(std::string cmd)
std::vector< std::string > get_commands_list() const
game_board & board() const
gui::floating_textbox & get_textbox()
menu_handler(play_controller &pc)
gui::floating_textbox textbox_info_
void show_statistics(int side_num)
void recruit(int side_num, const map_location &last_hex)
game_state & gamestate() const
void disable_units_highlight()
Use this to disable hovering an unit from highlighting its movement range.
void set_current_paths(const pathfind::paths &new_paths)
pathfind::marked_route get_route(const unit *un, map_location go_to, const team &team) const
map_location get_selected_hex() const
const map_location hovered_hex() const
Uses SDL and game_display::hex_clicked_on to fetch the hex the mouse is hovering, if applicable.
bool hex_hosts_unit(const map_location &hex) const
Unit exists on the hex, no matter if friend or foe.
void cycle_units(const bool browse, const bool reverse=false)
const map_location & get_last_hex() const
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
void scroll_to_leader(int side, SCROLL_TYPE scroll_type=ONSCREEN, bool force=true)
Scrolls to the leader of a certain side.
virtual const std::set< std::string > & observers() const override
virtual void select_hex(map_location hex) override
Function to display a location as selected.
std::string write() const
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
file_dialog & set_save_mode(bool value)
Sets the dialog's behavior on non-existent file name inputs.
std::string path() const
Gets the current file selection.
file_dialog & set_extension(const std::string &value)
Sets allowed file extensions for file names in save mode.
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
static bool execute(game_board &board, const team &viewing_team, int &selected_side_number)
Main class to show messages to the user.
@ yes_no_buttons
Shows a yes and no button.
@ ok_cancel_buttons
Shows an ok and cancel button.
@ auto_close
Enables auto close.
bool show(const unsigned auto_close_time=0)
Shows the window.
static std::unique_ptr< units_dialog > build_unit_list_dialog(std::vector< unit_const_ptr > &units_list)
static std::unique_ptr< units_dialog > build_create_dialog(const std::vector< const unit_type * > &types_list)
static std::unique_ptr< units_dialog > build_recruit_dialog(const std::vector< const unit_type * > &recruit_list, recruit_msgs_map &err_msgs_map, const team &team)
static std::unique_ptr< units_dialog > build_recall_dialog(std::vector< unit_const_ptr > &recall_list, const team &team)
void show(gui::TEXTBOX_MODE mode, const std::string &label, const std::string &check_label, bool checked, game_display &gui)
void show_objectives() const
const gamemap & get_map() const
std::vector< team > & get_teams()
statistics_t & statistics()
void notify_event(const std::string &name, const config &data)
static plugins_manager * get()
std::set< std::string > & encountered_units()
void add_alias(const std::string &alias, const std::string &command)
void set_message_private(bool value)
void set_show_fps(bool value)
bool empty() const
Is it empty?
static config get_recall(const std::string &unit_id, const map_location &loc, const map_location &from)
static config get_recruit(const std::string &type_id, const map_location &loc, const map_location &from)
static config get_update_shroud()
Records that the player has manually updated fog/shroud.
static config get_auto_shroud(bool turned_on, bool block_undo=true)
Records that the player has toggled automatic shroud updates.
void add_rename(const std::string &name, const map_location &loc)
void add_label(const terrain_label *)
void speak(const config &cfg)
void clear_labels(const std::string &, bool)
static synced_state get_synced_state()
static bool run_and_throw(const std::string &commandname, const config &data, action_spectator &spectator=get_default_spectator())
This class stores all the data for a single 'side' (in game nomenclature).
bool is_proxy_human() const
const std::string & save_id() const
bool auto_shroud_updates() const
bool is_local_human() const
void set_last_recruit(const std::string &u_type)
recall_list_manager & recall_list()
const std::string & team_name() const
static color_t get_side_color(int side)
void increment_action_bonus_count()
const std::string & last_recruit() const
To store label data Class implements logic for rendering.
const t_string & text() const
Container associating units to locations.
const std::vector< const unit_type * > types_list() const
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
const unit_type_map & types() const
A single unit type that the player may recruit.
const std::string & id() const
The id for this unit_type.
This class represents a single unit of a specific type.
A variable-expanding proxy for the config class.
static vconfig empty_vconfig()
An object representing the state of the game, providing access to the map and basic information.
std::string to_debug_string(bool verbose=false, formula_seen_stack *seen=nullptr) const
Various functions related to the creation of units (recruits, recalls, and placed units).
static void print(std::stringstream &sstr, const std::string &queue, const std::string &id)
Contains the exception interfaces used to signal completion of a scenario, campaign or turn.
void throw_quit_game_exception()
static std::string _(const char *str)
bool user_end_turn() const
Check whether the user ended their turn.
const std::string & id() const
Gets this unit's id.
int side() const
The side this unit belongs to.
const t_string & name() const
Gets this unit's translatable display name.
const map_location & get_goto() const
The map location to which this unit is moving over multiple turns, if any.
const map_location & get_location() const
The current map location this unit is at.
bool has_moved() const
Checks if this unit has moved.
void set_goto(const map_location &new_goto)
Sets this unit's long term destination.
int movement_left() const
Gets how far a unit can move, considering the incapacitated flag.
std::string label
What to show in the filter's drop-down list.
std::string id
Text to match against addon_info.tags()
Standard logging facilities (interface).
std::set< std::string > get_recruits(int side, const map_location &recruit_loc)
Gets the recruitable units from a side's leaders' personal recruit lists who can recruit on or from a...
game_events::pump_result_t get_village(const map_location &loc, int side, bool *action_timebonus, bool fire_event)
Makes it so the village at the given location is owned by the given side.
std::vector< unit_const_ptr > get_recalls(int side, const map_location &recall_loc)
Gets the recallable units for a side, restricted by that side's leaders' personal abilities to recall...
std::size_t move_unit_and_record(const std::vector< map_location > &steps, bool continued_move, bool *interrupted)
Wrapper around the other overload.
std::string find_recall_location(const int side, map_location &recall_location, map_location &recall_from, const unit &unit_recall)
Finds a location on which to recall unit_recall.
auto serialize_timestamp(const std::chrono::system_clock::time_point &time)
Handling of system events.
std::string get_legacy_editor_dir()
const std::string map_extension
void write_file(const std::string &fname, const std::string &data, std::ios_base::openmode mode=std::ios_base::binary)
Throws io_exception if an error occurs.
const color_t LABEL_COLOR
Game configuration data as global variables.
bool ignore_replay_errors
const std::string observer_team_name
observer team name used for observer team chat
void set_debug(bool new_debug)
void show_transient_error_message(const std::string &message, const std::string &image, const bool message_use_markup)
Shows a transient error message to the user.
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
retval
Default window/dialog return values.
@ OK
Dialog was closed with the OK button.
@ CANCEL
Dialog was closed with the CANCEL button.
void show_terrain_description(const terrain_type &t)
void show_unit_description(const unit &u)
void show_help(const std::string &show_topic)
Open the help browser.
void flush_cache()
Purges all image caches.
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
game_events::manager * game_events
bool ci_search(const std::string &s1, const std::string &s2)
Case-insensitive search.
static std::string sgettext(const char *str)
std::string check_recruit_list(const std::string &type, int side_number, const map_location &target_hex)
std::string check_recruit_purse(int unit_cost, int current_purse, int investments)
int planned_gold_spent(int side_number)
std::tuple< std::string, map_location, map_location > validate_recruit_target(const std::string &type, int side_number, const map_location &target_hex)
Verifies that target_hex is a valid recruit location for the given side.
auto find(Container &container, const Value &value, const Projection &projection={})
@ STRIP_SPACES
REMOVE_EMPTY: remove empty elements.
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
std::map< std::string, t_string > string_map
std::vector< std::string > split(const config_attribute_value &val)
std::shared_ptr< const unit > unit_const_ptr
const std::string & gender_string(unit_race::GENDER gender)
static config unit_name(const unit *u)
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
Thrown when a lexical_cast fails.
The basic class for representing 8-bit RGB or RGBA colour values.
An exception object used when an IO error occurs.
Encapsulates the map of the game.
static const map_location & null_location()
Structure which holds a single route and marks for special events.
std::vector< map_location > & steps
Object which contains all the possible locations a unit can move to, with associated best routes to t...
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
Object which temporarily resets a unit's movement.
ONLY IF whiteboard is currently active, applies the planned unit map for the duration of the struct's...
Applies the planned unit map for the duration of the struct's life.
const std::string & gamedata
static map_location::direction n
unit_type_data unit_types
Various functions that implement the undoing (and redoing) of in-game commands.