The Battle for Wesnoth  1.19.2+dev
play_controller.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2024
3  by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
4  Copyright (C) 2003 by David White <dave@whitevine.net>
5  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
15 */
16 
17 /**
18  * @file
19  * Handle input via mouse & keyboard, events, schedule commands.
20  */
21 
22 #include "play_controller.hpp"
23 
24 #include "actions/heal.hpp"
25 #include "actions/undo.hpp"
26 #include "actions/vision.hpp"
27 #include "ai/manager.hpp"
28 #include "ai/testing.hpp"
29 #include "display_chat_manager.hpp"
30 #include "floating_label.hpp"
31 #include "formula/string_utils.hpp"
32 #include "game_errors.hpp"
34 #include "game_events/pump.hpp"
35 #include "game_state.hpp"
36 #include "gettext.hpp"
38 #include "gui/dialogs/message.hpp" // for show_error_message
42 #include "log.hpp"
43 #include "map/label.hpp"
44 #include "pathfind/teleport.hpp"
46 #include "random.hpp"
47 #include "replay.hpp"
48 #include "resources.hpp"
49 #include "save_index.hpp"
50 #include "saved_game.hpp"
51 #include "savegame.hpp"
54 #include "sound.hpp"
55 #include "soundsource.hpp"
56 #include "statistics.hpp"
57 #include "synced_context.hpp"
58 #include "units/types.hpp"
59 #include "units/unit.hpp"
60 #include "utils/general.hpp"
61 #include "video.hpp"
62 #include "whiteboard/manager.hpp"
63 
64 #include <functional>
65 
66 static lg::log_domain log_aitesting("ai/testing");
67 #define LOG_AIT LOG_STREAM(info, log_aitesting)
68 // If necessary, this define can be replaced with `#define LOG_AIT std::cout` to restore previous behavior
69 
70 static lg::log_domain log_engine("engine");
71 #define LOG_NG LOG_STREAM(info, log_engine)
72 #define DBG_NG LOG_STREAM(debug, log_engine)
73 #define ERR_NG LOG_STREAM(err, log_engine)
74 
75 static lg::log_domain log_display("display");
76 #define ERR_DP LOG_STREAM(err, log_display)
77 
78 static lg::log_domain log_enginerefac("enginerefac");
79 #define LOG_RG LOG_STREAM(info, log_enginerefac)
80 
81 static lg::log_domain log_engine_enemies("engine/enemies");
82 #define DBG_EE LOG_STREAM(debug, log_engine_enemies)
83 
84 /**
85  * Copies [scenario] attributes/tags that are not otherwise stored in C++ structs/clases.
86  */
87 static void copy_persistent(const config& src, config& dst)
88 {
89  static const std::set<std::string> attrs {
90  "description",
91  "name",
92  "disallow_recall",
93  "experience_modifier",
94  "require_scenario",
95  "loaded_resources"
96  };
97 
98  static const std::set<std::string> tags {
99  "terrain_graphics",
100  "modify_unit_type",
101  "lua"
102  };
103 
104  for(const std::string& attr : attrs) {
105  dst[attr] = src[attr];
106  }
107 
108  for(const std::string& tag : tags) {
109  dst.append_children(src, tag);
110  }
111 }
112 
113 static void clear_resources()
114 {
115  resources::controller = nullptr;
116  resources::filter_con = nullptr;
117  resources::gameboard = nullptr;
118  resources::gamedata = nullptr;
119  resources::lua_kernel = nullptr;
120  resources::game_events = nullptr;
121  resources::persist = nullptr;
122  resources::soundsources = nullptr;
123  resources::tod_manager = nullptr;
124  resources::tunnels = nullptr;
125  resources::undo_stack = nullptr;
126  resources::recorder = nullptr;
127  resources::whiteboard.reset();
128  resources::classification = nullptr;
129 }
130 
132  : controller_base()
133  , observer()
135  , ticks_(SDL_GetTicks())
136  , gamestate_()
137  , level_()
138  , saved_game_(state_of_game)
139  , tooltips_manager_()
140  , whiteboard_manager_()
141  , plugins_context_()
142  , labels_manager_(new font::floating_label_context())
143  , help_manager_(&game_config_)
144  , mouse_handler_(nullptr, *this)
145  , menu_handler_(nullptr, *this)
146  , hotkey_handler_(new hotkey_handler(*this, saved_game_))
147  , soundsources_manager_()
148  , persist_()
149  , gui_()
150  , xp_mod_(new unit_experience_accelerator(level["experience_modifier"].to_int(100)))
151  , statistics_context_(new statistics_t(state_of_game.statistics()))
152  , replay_(new replay(state_of_game.get_replay()))
153  , skip_replay_(false)
154  , skip_story_(state_of_game.skip_story())
155  , did_autosave_this_turn_(true)
156  , did_tod_sound_this_turn_(false)
157  , map_start_()
158  , start_faded_(true)
159  , victory_music_()
160  , defeat_music_()
161  , scope_(hotkey::scope_game)
162  , ignore_replay_errors_(false)
163  , player_type_changed_(false)
164 {
166 
167  for(const config& modify_unit_type : level_.child_range("modify_unit_type")) {
168  unit_types.apply_scenario_fix(modify_unit_type);
169  }
170  resources::controller = this;
173 
175 
177 
179 
180  try {
181  init(level);
182  } catch(...) {
183  DBG_NG << "Caught exception initializing level: " << utils::get_unknown_exception_type();
184  clear_resources();
185  throw;
186  }
187 }
188 
190 {
192  clear_resources();
193 }
194 
196 {
197  /*
198  * Initilisation currently happens on the following order:
199  * 1) This code, which is executed with the loadingscreen
200  * From inside the constructor.
201  * 2) The Music is changed.
202  * 3) The Storyscreen is shown.
203  * 4) The Labels are added
204  * 5) The preload event is fired
205  * 6) The prestart event is fired
206  * 7) The gui is activated
207  * 8) The start event is fired
208  */
211 
212  LOG_NG << "initializing game_state..." << (SDL_GetTicks() - ticks());
213  gamestate_.reset(new game_state(level, *this));
214 
222 
223  gamestate_->ai_manager_.add_observer(this);
224  gamestate_->init(level, *this);
226 
227  LOG_NG << "initializing whiteboard..." << (SDL_GetTicks() - ticks());
229  whiteboard_manager_.reset(new wb::manager());
231 
232  LOG_NG << "loading units..." << (SDL_GetTicks() - ticks());
235 
236  LOG_NG << "initializing theme... " << (SDL_GetTicks() - ticks());
238 
239  LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks());
241 
242  gui_.reset(new game_display(gamestate().board_, whiteboard_manager_, *gamestate().reports_, theme(), level));
243  map_start_ = map_location(level.child_or_empty("display").child_or_empty("location"));
244  if(start_faded_) {
245  gui_->set_fade({0,0,0,255});
246  gui_->set_prevent_draw(true);
247  }
248 
249  // Ensure the loading screen doesn't end up underneath the game display
251 
252  if(!video::headless()) {
254  gui_->get_theme().modify_label("time-icon", _("time left for current turn"));
255  } else {
256  gui_->get_theme().modify_label("time-icon", _("current local time"));
257  }
258  }
259 
261  mouse_handler_.set_gui(gui_.get());
262  menu_handler_.set_gui(gui_.get());
263 
264  LOG_NG << "done initializing display... " << (SDL_GetTicks() - ticks());
265 
266  LOG_NG << "building gamestate to gui and whiteboard... " << (SDL_GetTicks() - ticks());
267  // This *needs* to be created before the show_intro and show_map_scene
268  // as that functions use the manager state_of_game
269  // Has to be done before registering any events!
272 
273  init_managers();
275  // loadscreen_manager->reset();
277  gamestate().lua_kernel_->load_game(level);
278 
279  plugins_context_.reset(new plugins_context("Game"));
280  plugins_context_->set_callback("save_game", [this](const config& cfg) { save_game_auto(cfg["filename"]); }, true);
281  plugins_context_->set_callback("save_replay", [this](const config& cfg) { save_replay_auto(cfg["filename"]); }, true);
282  plugins_context_->set_callback("quit", [](const config&) { throw_quit_game_exception(); }, false);
283  plugins_context_->set_accessor_string("scenario_name", [this](config) { return get_scenario_name(); });
284  });
285 }
286 
287 void play_controller::reset_gamestate(const config& level, int replay_pos)
288 {
289  // TODO: should we update we update this->level_ with level ?
290 
291  resources::gameboard = nullptr;
292  resources::gamedata = nullptr;
293  resources::tod_manager = nullptr;
294  resources::filter_con = nullptr;
295  resources::lua_kernel = nullptr;
296  resources::game_events = nullptr;
297  resources::tunnels = nullptr;
298  resources::undo_stack = nullptr;
299 
300  gui_->labels().set_team(nullptr);
301 
302  /* First destroy the old game state, then create the new one.
303  This is necessary to ensure that while the old AI manager is being destroyed,
304  all its member objects access the old manager instead of the new. */
305  gamestate_.reset();
306  gamestate_.reset(new game_state(level, *this));
307 
315 
316  gamestate_->ai_manager_.add_observer(this);
317  gamestate_->init(level, *this);
320 
321  gui_->reset_reports(*gamestate().reports_);
322  gui_->change_display_context(&gamestate().board_);
323  saved_game_.get_replay().set_pos(replay_pos);
324 
326  gamestate().lua_kernel_->load_game(level);
327 }
328 
330 {
331  LOG_NG << "initializing managers... " << (SDL_GetTicks() - ticks());
333 
335  LOG_NG << "done initializing managers... " << (SDL_GetTicks() - ticks());
336 }
337 
339 {
340  // Run initialization scripts, even if loading from a snapshot.
341  gamestate().gamedata_.get_variable("turn_number") = static_cast<int>(turn());
342  pump().fire("preload");
343  gamestate().lua_kernel_->preload_finished();
344 }
345 
347 {
348  // pre-start events must be executed before any GUI operation,
349  // as those may cause the display to be refreshed.
351 
352  // Fire these right before prestart events, to catch only the units sides
353  // have started with.
354  for(const unit& u : get_units()) {
355  pump().fire("unit_placed", map_location(u.get_location()));
356  }
357 
358  pump().fire("prestart");
359 
360  // prestart event may modify start turn with WML, reflect any changes.
361  gamestate().gamedata_.get_variable("turn_number") = static_cast<int>(turn());
362 }
363 
365 {
366  const config cfg("side", gui_->viewing_side());
367  gamestate().lua_kernel_->run_wml_action("show_objectives", vconfig(cfg),
368  game_events::queued_event("_from_interface", "", map_location(), map_location(), config()));
369 }
370 
372 {
374  pump().fire("start");
375 
376  skip_story_ = false; // Show [message]s from now on even with --campaign-skip-story
377 
378  // start event may modify start turn with WML, reflect any changes.
379  gamestate().gamedata_.get_variable("turn_number") = static_cast<int>(turn());
380 
383 
384  // prestart and start events may modify the initial gold amount,
385  // reflect any changes.
386  for(team& tm : get_teams()) {
387  tm.set_start_gold(tm.gold());
388  }
389 
391 }
392 
394 {
395  gui_->begin_game();
396  gui_->update_tod();
397 }
398 
400 {
402  gui_->set_playing_team(std::size_t(current_side() - 1));
403 
405 
407 }
408 
410 {
411  //
412  // We do side init only if not done yet for a local side when we are not replaying.
413  // For all other sides it is recorded in replay and replay handler has to handle
414  // calling do_init_side() functions.
415  //
416  if(is_during_turn()) {
417  // We already executed do_init_side this can for example happe if we reload a game,
418  // but also if we changed control of a side during it's turn
419  return;
420  }
421 
422  if(!current_team().is_local()) {
423  // We are in a mp game and execute do_init_side as soon as we receive [init_side] from the current player
424  // (see replay.cpp)
425  return;
426  }
427 
428  if(is_replay()) {
429  // We are in a replay and execute do_init_side as soon as we reach the next [init_side] in the replay data
430  // (see replay.cpp)
431  return;
432  }
433 
434  if(current_team().is_idle()) {
435  // In this case it can happen that we just gave control of this side to another player so doing init_side
436  // could lead to errors since we no longer own this side from the servers perspective.
437  // (see playturn.cpp)
438  return;
439  }
440 
442  do_init_side();
443 }
444 
446 {
447  { // Block for set_scontext_synced
448  set_scontext_synced sync;
449 
451 
452  log_scope("player turn");
453  // In case we might end up calling sync:network during the side turn events,
454  // and we don't want do_init_side to be called when a player drops.
456  gamestate_->next_player_number_ = gamestate_->player_number_ + 1;
457 
458  const std::string turn_num = std::to_string(turn());
459  const std::string side_num = std::to_string(current_side());
460 
461  gamestate().gamedata_.get_variable("side_number") = current_side();
462 
463  // We might have skipped some sides because they were empty so it is not enough to check for side_num==1
464  if(!gamestate().tod_manager_.has_turn_event_fired()) {
465  pump().fire("turn_" + turn_num);
466  pump().fire("new_turn");
468  }
469 
470  pump().fire("side_turn");
471  pump().fire("side_" + side_num + "_turn");
472  pump().fire("side_turn_" + turn_num);
473  pump().fire("side_" + side_num + "_turn_" + turn_num);
474 
475  // We want to work out if units for this player should get healed,
476  // and the player should get income now.
477  // Healing/income happen if it's not the first turn of processing,
478  // or if we are loading a game.
479  if(turn() > 1) {
482 
483  // If the expense is less than the number of villages owned
484  // times the village support capacity,
485  // then we don't have to pay anything at all
486  int expense = gamestate().board_.side_upkeep(current_side()) - current_team().support();
487  if(expense > 0) {
488  current_team().spend_gold(expense);
489  }
490  }
491 
492  if(do_healing()) {
494  }
495 
496  // Do healing on every side turn except the very first side turn.
497  // (1.14 and earlier did healing whenever turn >= 2.)
498  set_do_healing(true);
499 
500  // Set resting now after the healing has been done.
501  for(unit& patient : resources::gameboard->units()) {
502  if(patient.side() == current_side()) {
503  patient.set_resting(true);
504  }
505  }
506 
507  // Prepare the undo stack.
509 
510  pump().fire("turn_refresh");
511  pump().fire("side_" + side_num + "_turn_refresh");
512  pump().fire("turn_" + turn_num + "_refresh");
513  pump().fire("side_" + side_num + "_turn_" + turn_num + "_refresh");
514 
515  // Make sure vision is accurate.
517 
518  check_victory();
519  sync.do_final_checkup();
521  }
522 
523  statistics().reset_turn_stats(gamestate().board_.get_team(current_side()).save_id_or_number());
524 
525  init_side_end();
526 
527  if(!is_skipping_replay() && current_team().get_scroll_to_leader()) {
528  gui_->scroll_to_leader(current_side(), game_display::ONSCREEN, false);
529  }
530 }
531 
533 {
538  }
539  whiteboard_manager_->on_init_side();
540 }
541 
543 {
544  config cfg = level_;
545 
546  cfg["replay_pos"] = saved_game_.get_replay().get_pos();
547  gamestate().write(cfg);
548 
549  gui_->write(cfg.add_child("display"));
550 
551  // Write the soundsources.
552  soundsources_manager_->write_sourcespecs(cfg);
553 
554  gui_->labels().write(cfg);
556 
557  if(cfg["replay_pos"].to_int(0) > 0 && cfg["playing_team"].empty()) {
558  gui2::show_error_message(_("Trying to create a corrupt file, please report this bug"));
559  }
560 
561  return cfg;
562 }
563 
565 {
566 
567  { // Block for set_scontext_synced
568  set_scontext_synced sync(1);
569  // Also clears the undo stack.
571 
573  const std::string turn_num = std::to_string(turn());
574  const std::string side_num = std::to_string(current_side());
575 
576  // Clear shroud, in case units had been slowed for the turn.
578 
579  pump().fire("side_turn_end");
580  pump().fire("side_" + side_num + "_turn_end");
581  pump().fire("side_turn_" + turn_num + "_end");
582  pump().fire("side_" + side_num + "_turn_" + turn_num + "_end");
583  // This is where we refog, after all of a side's events are done.
585  check_victory();
586  sync.do_final_checkup();
587  }
589 }
590 
592 {
593  set_scontext_synced sync(2);
594  const std::string turn_num = std::to_string(turn());
595  pump().fire("turn_end");
596  pump().fire("turn_" + turn_num + "_end");
597  sync.do_final_checkup();
598 }
599 
601 {
602  // If we aren't using fog/shroud, this is easy :)
603  if(current_team().uses_fog() == false && current_team().uses_shroud() == false) {
604  return true;
605  }
606 
607  // See if any enemies are visible
608  for(const unit& u : get_units()) {
609  if(current_team().is_enemy(u.side()) && !gui_->fogged(u.get_location())) {
610  return true;
611  }
612  }
613 
614  return false;
615 }
616 
618 {
619  if(menu_handler_.get_textbox().active() == false) {
620  return;
621  }
622 
623  const std::string str = menu_handler_.get_textbox().box()->text();
624  const unsigned int team_num = current_side();
625  events::mouse_handler& mousehandler = mouse_handler_;
626 
627  switch(menu_handler_.get_textbox().mode()) {
628  case gui::TEXTBOX_SEARCH:
632  break;
635  menu_handler_.get_textbox().close(); // need to close that one after executing do_speak() !
636  break;
641  break;
642  case gui::TEXTBOX_AI:
645  menu_handler_.do_ai_formula(str, team_num, mousehandler);
646  break;
647  default:
649  ERR_DP << "unknown textbox mode";
650  }
651 }
652 
654 {
655  if(menu_handler_.get_textbox().active() == false) {
656  return;
657  }
658 
661  // Not handling messages to avoid spam
662  return;
663  }
664 
665  const std::string str = menu_handler_.get_textbox().box()->text();
666  const std::vector<std::string>& command_history = menu_handler_.get_textbox().command_history();
667 
668  auto prev = std::find(command_history.begin(), command_history.end(), str);
669 
670  if (prev != command_history.end())
671  {
672  if(up) {
673  if(prev != command_history.begin()) {
674  menu_handler_.get_textbox().box()->set_text(*--prev);
675  }
676  } else {
677  if(++prev != command_history.end()) {
678  menu_handler_.get_textbox().box()->set_text(*prev);
679  } else {
680  menu_handler_.get_textbox().box()->set_text("");
681  }
682  }
683  } else if (up) {
684  if(command_history.size() > 0) {
685  menu_handler_.get_textbox().box()->set_text(*--prev);
686  }
687  if(!str.empty()) {
689  }
690  }
691 }
692 
694 {
696 
697  std::set<std::string> dictionary;
698  switch(mode) {
699  case gui::TEXTBOX_SEARCH: {
700  for(const unit& u : get_units()) {
701  const map_location& loc = u.get_location();
702  if(!gui_->fogged(loc) && !(get_teams()[gui_->viewing_team()].is_enemy(u.side()) && u.invisible(loc)))
703  dictionary.insert(u.name());
704  }
705  // TODO List map labels
706  break;
707  }
708  case gui::TEXTBOX_COMMAND: {
709  std::vector<std::string> commands = menu_handler_.get_commands_list();
710  dictionary.insert(commands.begin(), commands.end());
711  [[fallthrough]]; // we also want player names from the next case
712  }
713  case gui::TEXTBOX_MESSAGE: {
714  for(const team& t : get_teams()) {
715  if(!t.is_empty())
716  dictionary.insert(t.current_player());
717  }
718 
719  // Add observers
720  for(const std::string& o : gui_->observers()) {
721  dictionary.insert(o);
722  }
723 
724  // Add nicks who whispered you
725  for(const std::string& w : gui_->get_chat_manager().whisperers()) {
726  dictionary.insert(w);
727  }
728 
729  // Add nicks from friendlist
730  const std::map<std::string, std::string> friends = prefs::get().get_acquaintances_nice("friend");
731 
732  for(std::map<std::string, std::string>::const_iterator iter = friends.begin(); iter != friends.end(); ++iter) {
733  dictionary.insert((*iter).first);
734  }
735 
736  // Exclude own nick from tab-completion.
737  // NOTE why ?
738  dictionary.erase(prefs::get().login());
739  break;
740  }
741 
742  default:
743  ERR_DP << "unknown textbox mode";
744  } // switch(mode)
745 
746  menu_handler_.get_textbox().tab(dictionary);
747 }
748 
750 {
751  if(get_teams().size() == 0) {
752  throw game::game_error("The scenario has no sides defined");
753  }
754 
755  assert(gamestate().board_.has_team(current_side()));
757 }
758 
760 {
761  if(get_teams().size() == 0) {
762  throw game::game_error("The scenario has no sides defined");
763  }
764 
765  assert(gamestate().board_.has_team(current_side()));
767 }
768 
769 
771 {
772  return mouse_handler_;
773 }
774 
775 std::shared_ptr<wb::manager> play_controller::get_whiteboard() const
776 {
777  return whiteboard_manager_;
778 }
779 
781 {
782  return saved_game_.mp_settings();
783 }
784 
786 {
787  return saved_game_.classification();
788 }
789 
791 {
792  return *gui_;
793 }
794 
796 {
797  return !menu_handler_.get_textbox().active();
798 }
799 
801 {
802  if(event.key.keysym.sym == SDLK_ESCAPE) {
804  } else if(event.key.keysym.sym == SDLK_TAB) {
805  tab();
806  } else if(event.key.keysym.sym == SDLK_UP) {
808  } else if(event.key.keysym.sym == SDLK_DOWN) {
810  } else if(event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_KP_ENTER) {
811  enter_textbox();
812  }
813 }
814 
815 void play_controller::process_keydown_event(const SDL_Event& event)
816 {
817  if(event.key.keysym.sym == SDLK_TAB) {
818  whiteboard_manager_->set_invert_behavior(true);
819  }
820 }
821 
822 void play_controller::process_keyup_event(const SDL_Event& event)
823 {
824  // If the user has pressed 1 through 9, we want to show
825  // how far the unit can move in that many turns
826  if(event.key.keysym.sym >= '1' && event.key.keysym.sym <= '9') {
827  const int new_path_turns = (event.type == SDL_KEYDOWN) ? event.key.keysym.sym - '1' : 0;
828 
829  if(new_path_turns != mouse_handler_.get_path_turns()) {
830  mouse_handler_.set_path_turns(new_path_turns);
831 
833 
834  if(u.valid()) {
835  // if it's not the unit's turn, we reset its moves
836  unit_movement_resetter move_reset(*u, u->side() != current_side());
837 
839  *u, false, true, get_teams()[gui_->viewing_team()], mouse_handler_.get_path_turns()));
840 
841  gui_->highlight_reach(mouse_handler_.current_paths());
842  } else {
844  }
845  }
846  } else if(event.key.keysym.sym == SDLK_TAB) {
847  CKey keys;
848  if(!keys[SDLK_TAB]) {
849  whiteboard_manager_->set_invert_behavior(false);
850  }
851  }
852 }
853 
855 {
856  assert(replay_);
857  return *replay_.get();
858 }
859 
861 {
862  // Saving while an event is running isn't supported
863  // because it may lead to expired event handlers being saved.
864  assert(!gamestate().events_manager_->is_event_running());
865 
866  scoped_savegame_snapshot snapshot(*this);
867  savegame::ingame_savegame save(saved_game_, prefs::get().save_compression_format());
869 }
870 
871 void play_controller::save_game_auto(const std::string& filename)
872 {
873  scoped_savegame_snapshot snapshot(*this);
874  savegame::ingame_savegame save(saved_game_, prefs::get().save_compression_format());
875  save.save_game_automatic(false, filename);
876 }
877 
879 {
880  savegame::replay_savegame save(saved_game_, prefs::get().save_compression_format());
882 }
883 
884 void play_controller::save_replay_auto(const std::string& filename)
885 {
886  savegame::replay_savegame save(saved_game_, prefs::get().save_compression_format());
887  save.save_game_automatic(false, filename);
888 }
889 
891 {
893 }
894 
896 {
898  load.load_game_ingame();
899 }
900 
902 {
904  undo_stack().undo();
905 }
906 
908 {
910  undo_stack().redo();
911 }
912 
914 {
916 }
917 
919 {
921 }
922 
923 const std::string& play_controller::select_music(bool victory) const
924 {
925  const std::vector<std::string>& music_list = victory
926  ? (gamestate_->get_game_data()->get_victory_music().empty()
928  : gamestate_->get_game_data()->get_victory_music())
929  : (gamestate_->get_game_data()->get_defeat_music().empty()
931  : gamestate_->get_game_data()->get_defeat_music());
932 
933  if(music_list.empty()) {
934  // Since this function returns a reference, we can't return a temporary empty string.
935  static const std::string empty_str = "";
936  return empty_str;
937  }
938 
939  return music_list[randomness::rng::default_instance().get_random_int(0, music_list.size() - 1)];
940 }
941 
943 {
944  if(is_linger_mode()) {
945  return;
946  }
947 
948  if(is_regular_game_end()) {
949  return;
950  }
951 
952  bool continue_level, found_player, found_network_player, invalidate_all;
953  std::set<unsigned> not_defeated;
954 
956  continue_level,
957  found_player,
958  found_network_player,
960  not_defeated,
961  gamestate().remove_from_carryover_on_defeat_
962  );
963 
964  if(invalidate_all) {
965  gui_->invalidate_all();
966  }
967 
968  if(continue_level) {
969  return;
970  }
971 
972  if(found_player || found_network_player) {
973  pump().fire("enemies_defeated");
974  if(is_regular_game_end()) {
975  return;
976  }
977  }
978 
979  DBG_EE << "victory_when_enemies_defeated: " << gamestate().victory_when_enemies_defeated_;
980  DBG_EE << "found_player: " << found_player;
981  DBG_EE << "found_network_player: " << found_network_player;
982 
983  if(!gamestate().victory_when_enemies_defeated_ && (found_player || found_network_player)) {
984  // This level has asked not to be ended by this condition.
985  return;
986  }
987 
988  if(video::headless()) {
989  LOG_AIT << "winner: ";
990  for(unsigned l : not_defeated) {
992  if(ai.empty())
993  ai = "default ai";
994  LOG_AIT << l << " (using " << ai << ") ";
995  }
996 
997  LOG_AIT;
998  ai_testing::log_victory(not_defeated);
999  }
1000 
1001  DBG_EE << "throwing end level exception...";
1002  // Also proceed to the next scenario when another player survived.
1003  end_level_data el_data;
1005  el_data.proceed_to_next_level = found_player || found_network_player;
1006  el_data.is_victory = found_player;
1007  set_end_level_data(el_data);
1008 }
1009 
1010 void play_controller::process_oos(const std::string& msg) const
1011 {
1012  if(video::headless()) {
1013  throw game::game_error(msg);
1014  }
1015 
1017  return;
1018  }
1019 
1020  std::stringstream message;
1021  message << _("The game is out of sync. It might not make much sense to continue. Do you want to save your game?");
1022  message << "\n\n" << _("Error details:") << "\n\n" << msg;
1023 
1024  scoped_savegame_snapshot snapshot(*this);
1026  save.save_game_interactive(message.str(), savegame::savegame::YES_NO); // can throw quit_game_exception
1027 }
1028 
1030 {
1031  return saved_game_.classification().get_tagname() == "multiplayer";
1032 }
1033 
1034 void play_controller::update_gui_to_player(const int team_index, const bool observe)
1035 {
1036  gui_->set_team(team_index, observe);
1037  gui_->recalculate_minimap();
1038  gui_->invalidate_all();
1039 }
1040 
1042 {
1043  scoped_savegame_snapshot snapshot(*this);
1044  savegame::autosave_savegame save(saved_game_, prefs::get().save_compression_format());
1045  save.autosave(false, prefs::get().autosavemax(), pref_constants::INFINITE_AUTO_SAVES);
1046 }
1047 
1048 void play_controller::do_consolesave(const std::string& filename)
1049 {
1050  scoped_savegame_snapshot snapshot(*this);
1051  savegame::ingame_savegame save(saved_game_, prefs::get().save_compression_format());
1052  save.save_game_automatic(true, filename);
1053 }
1054 
1056 {
1057  // note: this writes to level_ if this is not a replay.
1059 }
1060 
1062 {
1063  return gamestate().events_manager_->pump();
1064 }
1065 
1067 {
1068  return ticks_;
1069 }
1070 
1072 {
1073  return soundsources_manager_.get();
1074 }
1075 
1077 {
1078  return plugins_context_.get();
1079 }
1080 
1082 {
1083  return hotkey_handler_.get();
1084 }
1085 
1087 {
1088  if(!gamestate().in_phase(game_data::TURN_PLAYING)) {
1089  return true;
1090  }
1091 
1092  const team& t = current_team();
1093  return !t.is_local_human() || !t.is_proxy_human();
1094 }
1095 
1097 {
1099  return;
1100  }
1101 
1102  try {
1103  play_slice();
1104  } catch(const return_to_play_side_exception&) {
1105  assert(should_return_to_play_side());
1106  }
1107 }
1108 
1110 {
1111  if(gamestate().in_phase(game_data::PRELOAD)) {
1114 
1115  set_scontext_synced sync;
1116 
1117  // So that the code knows it can send choices immidiateley
1118  // todo: im not sure whetrh this is actually needed.
1120  fire_prestart();
1121  if(is_regular_game_end()) {
1122  return;
1123  }
1124 
1125  for(const team& t : get_teams()) {
1126  actions::clear_shroud(t.side(), false, false);
1127  }
1128 
1129  init_gui();
1130  LOG_NG << "first_time..." << (is_skipping_replay() ? "skipping" : "no skip");
1131 
1132  fire_start();
1133  if(is_regular_game_end()) {
1134  return;
1135  }
1136 
1137  sync.do_final_checkup();
1138  gui_->recalculate_minimap();
1139 
1140  // Initialize countdown clock.
1141  for(const team& t : get_teams()) {
1143  t.set_countdown_time(1000 * saved_game_.mp_settings().mp_countdown_init_time);
1144  }
1145  }
1146  did_autosave_this_turn_ = false;
1147  } else {
1148  init_gui();
1149  gui_->recalculate_minimap();
1150  }
1151 
1153 }
1154 
1155 /**
1156  * Find all [endlevel]next_scenario= attributes, and add them to @a result.
1157  */
1158 static void find_next_scenarios(const config& parent, std::set<std::string>& result) {
1159  for(const auto& endlevel : parent.child_range("endlevel")) {
1160  if(endlevel.has_attribute("next_scenario")) {
1161  result.insert(endlevel["next_scenario"]);
1162  }
1163  }
1164  for(const auto cfg : parent.all_children_range()) {
1165  find_next_scenarios(cfg.cfg, result);
1166  }
1167 };
1168 
1170  // Which scenarios are reachable from the current one?
1171  std::set<std::string> possible_next_scenarios;
1172  possible_next_scenarios.insert(gamestate().gamedata_.next_scenario());
1173 
1174  // Find all "endlevel" tags that could be triggered in events
1175  config events;
1176  gamestate().events_manager_->write_events(events);
1177  find_next_scenarios(events, possible_next_scenarios);
1178 
1179  // Are we looking for [scenario]id=, [multiplayer]id= or [test]id=?
1180  const auto tagname = saved_game_.classification().get_tagname();
1181 
1182  // Of the possible routes, work out which exist.
1183  bool possible_this_is_the_last_scenario = false;
1184  std::vector<std::string> known;
1185  std::vector<std::string> unknown;
1186  for(const auto& x : possible_next_scenarios) {
1187  if(x.empty() || x == "null") {
1188  possible_this_is_the_last_scenario = true;
1189  LOG_NG << "This can be the last scenario";
1190  } else if(utils::contains(x, '$')) {
1191  // Assume a WML variable will be set to a correct value before the end of the scenario
1192  known.push_back(x);
1193  LOG_NG << "Variable value for next scenario '" << x << "'";
1194  } else if(game_config_.find_child(tagname, "id", x)) {
1195  known.push_back(x);
1196  LOG_NG << "Known next scenario '" << x << "'";
1197  } else {
1198  unknown.push_back(x);
1199  ERR_NG << "Unknown next scenario '" << x << "'";
1200  }
1201  }
1202 
1203  if(unknown.empty()) {
1204  // everything's good
1205  return;
1206  }
1207 
1208  std::string title = _("Warning: broken campaign branches");
1209  std::stringstream message;
1210 
1211  message << _n(
1212  // TRANSLATORS: This is an error that will hopefully only be seen by UMC authors and by players who have already
1213  // said "okay" to a "loading saves from an old version might not work" dialog.
1214  "The next scenario is missing, you will not be able to finish this campaign.",
1215  // TRANSLATORS: This is an error that will hopefully only be seen by UMC authors and by players who have already
1216  // said "okay" to a "loading saves from an old version might not work" dialog.
1217  "Some of the possible next scenarios are missing, you might not be able to finish this campaign.",
1218  unknown.size() + known.size() + (possible_this_is_the_last_scenario ? 1 : 0));
1219  message << "\n\n";
1220  message << _n(
1221  "Please report the following missing scenario to the campaign’s author:\n$unknown_list|",
1222  "Please report the following missing scenarios to the campaign’s author:\n$unknown_list|",
1223  unknown.size());
1224  message << "\n";
1225  message << _("Once this is fixed, you will need to restart this scenario.");
1226 
1227  std::stringstream unknown_list;
1228  for(const auto& x : unknown) {
1229  unknown_list << font::unicode_bullet << " " << x << "\n";
1230  }
1231  utils::string_map symbols;
1232  symbols["unknown_list"] = unknown_list.str();
1233  auto message_str = utils::interpolate_variables_into_string(message.str(), &symbols);
1234  ERR_NG << message_str;
1236 }
1237 
1239 {
1240  const team& viewing_team = get_teams()[gui_->viewing_team()];
1241  return gui_->viewing_team() == gui_->playing_team() && !events::commands_disabled && viewing_team.is_local_human()
1242  && !is_browsing();
1243 }
1244 
1245 std::set<std::string> play_controller::all_players() const
1246 {
1247  std::set<std::string> res = gui_->observers();
1248  for(const team& t : get_teams()) {
1249  if(t.is_human()) {
1250  res.insert(t.current_player());
1251  }
1252  }
1253 
1254  return res;
1255 }
1256 
1258 {
1259  const bool time_left = gamestate().tod_manager_.next_turn(&gamestate().gamedata_);
1260 
1261  if(!time_left) {
1262  LOG_NG << "firing time over event...";
1264  pump().fire("time_over");
1265  LOG_NG << "done firing time over event...";
1266 
1267  // If turns are added while handling 'time over' event.
1268  if(gamestate().tod_manager_.is_time_left()) {
1269  return;
1270  }
1271 
1272  if(video::headless()) {
1273  LOG_AIT << "time over (draw)";
1275  }
1276 
1277  check_victory();
1278  if(is_regular_game_end()) {
1279  return;
1280  }
1281 
1282  end_level_data e;
1283  e.transient.reveal_map = reveal_map_default();
1284  e.proceed_to_next_level = false;
1285  e.is_victory = false;
1287  }
1288 }
1289 
1291  : controller_(controller)
1292 {
1294 }
1295 
1297 {
1298  controller_.saved_game_.remove_snapshot();
1299 }
1300 
1302 {
1303  const team& t = get_teams()[gui_->viewing_team()];
1304  static const std::string no_objectives(_("No objectives available"));
1305  std::string objectives = utils::interpolate_variables_into_string(t.objectives(), *gamestate_->get_game_data());
1306  gui2::show_transient_message(get_scenario_name(), (objectives.empty() ? no_objectives : objectives), "", true);
1307  t.reset_objectives_changed();
1308 }
1309 
1311 {
1313  const std::shared_ptr<gui::button> skip_animation_button = get_display().find_action_button("skip-animation");
1314  if(skip_animation_button) {
1315  skip_animation_button->set_check(skip_replay_);
1316  }
1317 }
1318 
1320 {
1322 }
1323 
1325 {
1327 }
1328 
1330 {
1333  }
1334 }
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands.
double t
Definition: astarsearch.cpp:63
map_location prev
Definition: astarsearch.cpp:64
Class that keeps track of all the keys on the keyboard.
Definition: key.hpp:29
void new_side_turn(int side)
Performs some initializations and error checks when starting a new side-turn.
Definition: undo.cpp:244
bool can_undo() const
True if there are actions that can be undone.
Definition: undo.hpp:99
void redo()
Redoes the top action on the redo stack.
Definition: undo.cpp:386
bool can_redo() const
True if there are actions that can be redone.
Definition: undo.hpp:101
void undo()
Undoes the top action on the undo stack.
Definition: undo.cpp:330
std::string get_active_ai_identifier_for_side(side_number side)
Gets AI algorithm identifier for active AI of the given side.
Definition: manager.cpp:685
static manager & get_singleton()
Definition: manager.hpp:142
static void log_victory(std::set< unsigned int > teams)
Definition: testing.cpp:81
static void log_draw()
Definition: testing.cpp:75
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
const_all_children_itors all_children_range() const
In-order iteration over all children.
Definition: config.cpp:887
child_itors child_range(config_key_type key)
Definition: config.cpp:273
void append_children(const config &cfg)
Adds children from cfg.
Definition: config.cpp:165
config & add_child(config_key_type key)
Definition: config.cpp:441
virtual void play_slice(bool is_delay_enabled=true)
const game_config_view & game_config_
int side_upkeep(int side_num) const
@ ONSCREEN
Definition: display.hpp:506
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
Definition: display.cpp:805
void do_ai_formula(const std::string &str, int side_num, mouse_handler &mousehandler)
gui::floating_textbox & get_textbox()
void do_command(const std::string &str)
void do_search(const std::string &new_search)
void set_gui(game_display *gui)
Definition: menu_events.hpp:57
std::vector< std::string > get_commands_list()
void set_gui(game_display *gui)
const pathfind::paths & current_paths() const
void set_current_paths(const pathfind::paths &new_paths)
unit_map::iterator selected_unit()
map_location get_selected_hex() const
int get_path_turns() const
void select_hex(const map_location &hex, const bool browse, const bool highlight=true, const bool fire_event=true)
void set_side(int side_number)
void set_path_turns(const int path_turns)
void check_victory(bool &, bool &, bool &, bool &, std::set< unsigned > &, bool)
Definition: game_board.cpp:114
team & get_team(int i)
Definition: game_board.hpp:92
void end_turn(int pnum)
Definition: game_board.cpp:79
void new_turn(int pnum)
Definition: game_board.cpp:70
std::string get_tagname() const
optional_const_config find_child(config_key_type key, const std::string &name, const std::string &value) const
static game_config_view wrap(const config &cfg)
void set_phase(PHASE phase)
Definition: game_data.hpp:106
@ PRELOAD
the preload [event] is fired next phase: PRESTART (normal game), TURN_STARTING_WAITING (reloaded game...
Definition: game_data.hpp:76
@ GAME_ENDED
The game has ended and the user is observing the final state "lingering" The game can be saved here.
Definition: game_data.hpp:102
@ PRESTART
the prestart [event] is fired next phase: START (default), GAME_ENDING
Definition: game_data.hpp:79
@ TURN_PLAYING
The User is controlling the game and invoking actions The game can be saved here.
Definition: game_data.hpp:93
@ TURN_STARTING_WAITING
we are waiting for the turn to start.
Definition: game_data.hpp:86
@ START
the start [event] is fired next phase: TURN_STARTING_WAITING (default), GAME_ENDING
Definition: game_data.hpp:82
@ TURN_STARTING
the turn, side turn etc.
Definition: game_data.hpp:89
map_location last_selected
the last location where a select event fired.
Definition: game_data.hpp:126
config::attribute_value & get_variable(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
Definition: game_data.cpp:66
pump_result_t fire(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
Function to fire an event.
Definition: pump.cpp:399
void write(config &cfg) const
Definition: game_state.cpp:218
bool in_phase(game_data::PHASE phase) const
Definition: game_state.hpp:109
void set_game_display(game_display *)
Definition: game_state.cpp:213
std::unique_ptr< game_lua_kernel > lua_kernel_
Definition: game_state.hpp:48
std::unique_ptr< pathfind::manager > pathfind_manager_
Definition: game_state.hpp:46
game_board board_
Definition: game_state.hpp:44
const std::unique_ptr< game_events::manager > events_manager_
Definition: game_state.hpp:50
bool victory_when_enemies_defeated_
Definition: game_state.hpp:61
tod_manager tod_manager_
Definition: game_state.hpp:45
game_data gamedata_
Definition: game_state.hpp:43
static void progress(loading_stage stage=loading_stage::none)
Report what is being loaded to the loading screen.
static void raise()
Raise the loading screen to the top of the draw stack.
static void display(std::function< void()> f)
@ close_button
Shows a close button.
Definition: message.hpp:75
void memorize_command(const std::string &command)
const std::unique_ptr< gui::textbox > & box() const
TEXTBOX_MODE mode() const
void tab(const std::set< std::string > &dictionary)
const std::vector< std::string > & command_history() const
game_classification & get_classification()
const std::string & select_music(bool victory) const
void process_keydown_event(const SDL_Event &event) override
Process keydown (always).
void maybe_throw_return_to_play_side() const
config to_config() const
Builds the snapshot config from members and their respective configs.
void init(const config &level)
std::vector< team > & get_teams()
std::unique_ptr< hotkey_handler > hotkey_handler_
virtual void init_gui()
bool have_keyboard_focus() override
Derived classes should override this to return false when arrow keys should not scroll the map,...
std::unique_ptr< game_state > gamestate_
void show_objectives() const
events::menu_handler menu_handler_
void fire_preload()
preload events cannot be synced
void check_victory()
Checks to see if a side has won.
bool is_linger_mode() const
actions::undo_list & undo_stack()
statistics_t & statistics()
virtual soundsource::manager * get_soundsource_man() override
Get (optionally) a soundsources manager a derived class uses.
void check_next_scenario_is_known()
This shows a warning dialog if either [scenario]next_scenario or any [endlevel]next_scenario would le...
bool reveal_map_default() const
const unit_map & get_units() const
play_controller(const config &level, saved_game &state_of_game)
bool do_healing() const
void set_end_level_data(const end_level_data &data)
events::mouse_handler & get_mouse_handler_base() override
Get a reference to a mouse handler member a derived class uses.
void update_savegame_snapshot() const
void set_do_healing(bool do_healing)
bool is_during_turn() const
bool can_use_synced_wml_menu() const
void reset_gamestate(const config &level, int replay_pos)
void do_consolesave(const std::string &filename)
void save_game_auto(const std::string &filename)
void textbox_move_vertically(bool up)
bool is_regular_game_end() const
virtual void check_objectives()=0
void save_replay_auto(const std::string &filename)
saved_game & saved_game_
game_state & gamestate()
hotkey::command_executor * get_hotkey_command_executor() override
Optionally get a command executor to handle context menu events.
bool enemies_visible() const
std::unique_ptr< replay > replay_
const mp_game_settings & get_mp_settings()
game_display & get_display() override
Get a reference to a display member a derived class uses.
virtual void update_viewing_player()=0
std::unique_ptr< game_display > gui_
void maybe_do_init_side()
Called by turn_info::process_network_data() or init_side() to call do_init_side() if necessary.
virtual void process_oos(const std::string &msg) const
Asks the user whether to continue on an OOS error.
bool is_browsing() const override
std::unique_ptr< soundsource::manager > soundsources_manager_
void do_init_side()
Called by replay handler or init_side() to do actual work for turn change.
std::string theme() const
int current_side() const
Returns the number of the side whose turn it is.
bool is_skipping_replay() const
std::shared_ptr< wb::manager > get_whiteboard() const
bool did_autosave_this_turn_
Whether we did init sides in this session (false = we did init sides before we reloaded the game).
bool is_replay() const
std::size_t turn() const
map_location map_start_
virtual bool should_return_to_play_side() const
std::set< std::string > all_players() const
void update_gui_to_player(const int team_index, const bool observe=false)
Changes the UI for this client to the passed side index.
events::mouse_handler mouse_handler_
std::unique_ptr< plugins_context > plugins_context_
virtual plugins_context * get_plugins_context() override
Get (optionally) a plugins context a derived class uses.
virtual ~play_controller()
bool can_undo() const
void process_focus_keydown_event(const SDL_Event &event) override
Process keydown (only when the general map display does not have focus).
void refresh_objectives() const
Reevaluate [show_if] conditions and build a new objectives string.
bool can_redo() const
game_events::wml_event_pump & pump()
void process_keyup_event(const SDL_Event &event) override
Process keyup (always).
void finish_side_turn_events()
persist_manager persist_
std::shared_ptr< wb::manager > whiteboard_manager_
virtual void check_time_over()
t_string get_scenario_name() const
static prefs & get()
void encounter_all_content(const game_board &gb)
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
Implements a quit confirmation dialog.
static rng & default_instance()
Definition: random.cpp:73
int get_random_int(int min, int max)
Definition: random.hpp:51
bool add_start_if_not_there_yet()
Definition: replay.cpp:675
void init_side()
Definition: replay.cpp:219
config * get_next_action()
Definition: replay.cpp:621
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
game_classification & classification()
Definition: saved_game.hpp:56
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
Definition: saved_game.hpp:60
replay_recorder_base & get_replay()
Definition: saved_game.hpp:140
config & set_snapshot(config snapshot)
Definition: saved_game.cpp:587
Class for autosaves.
Definition: savegame.hpp:281
void autosave(const bool disable_autosave, const int autosave_max, const int infinite_autosaves)
Definition: savegame.cpp:599
Class for "normal" midgame saves.
Definition: savegame.hpp:254
The class for loading a savefile.
Definition: savegame.hpp:101
Class for replay saves (either manually or automatically).
Definition: savegame.hpp:268
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
Definition: save_index.cpp:208
bool save_game_automatic(bool ask_for_overwrite=false, const std::string &filename="")
Saves a game without user interaction, unless the file exists and it should be asked to overwrite it.
Definition: savegame.cpp:360
bool save_game_interactive(const std::string &message, DIALOG_TYPE dialog_type)
Save a game interactively through the savegame dialog.
Definition: savegame.cpp:377
A RAII object to enter the synced context, cannot be called if we are already in a synced context.
void do_final_checkup(bool dont_throw=false)
void reset_turn_stats(const std::string &save_id)
Definition: statistics.cpp:207
static void block_undo(bool do_block=true)
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
int support() const
Calculate total support capacity, based on support_per_village.
Definition: team.hpp:189
bool is_local_human() const
Definition: team.hpp:253
void spend_gold(const int amount)
Definition: team.hpp:194
void new_turn()
Definition: team.hpp:190
void turn_event_fired()
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
Definition: tod_manager.hpp:56
bool next_turn(game_data *vars)
Function to move to the next turn.
void remove_scenario_fixes()
Definition: types.cpp:1453
void apply_scenario_fix(const config &cfg)
Definition: types.cpp:1419
This class represents a single unit of a specific type.
Definition: unit.hpp:133
A variable-expanding proxy for the config class.
Definition: variable.hpp:45
This class is the frontend of the whiteboard framework for the rest of the Wesnoth code.
Definition: manager.hpp:44
int w
void throw_quit_game_exception()
static std::string _n(const char *str1, const char *str2, int n)
Definition: gettext.hpp:97
static std::string _(const char *str)
Definition: gettext.hpp:93
void calculate_healing(int side, bool update_display)
Calculates healing for all units for the given side.
Definition: heal.cpp:290
Various functions that implement healing of units (when a side turn starts).
This file implements all the hotkey handling and menu details for play controller.
Standard logging facilities (interface).
#define log_scope(description)
Definition: log.hpp:277
Declarations for a class that implements WML-defined (right-click) menu items.
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
Definition: vision.cpp:749
void recalculate_fog(int side)
Function that recalculates the fog of war.
Definition: vision.cpp:700
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:59
void invalidate_all()
Mark the entire screen as requiring redraw.
Handling of system events.
Collection of helper functions relating to Pango formatting.
const std::string unicode_bullet
Definition: constants.cpp:47
std::string observer
std::vector< std::string > default_defeat_music
bool ignore_replay_errors
Definition: game_config.cpp:85
static void add_color_info(const game_config_view &v, bool build_defaults)
std::vector< std::string > default_victory_music
std::vector< game_tip > load(const config &cfg)
Loads the tips from a config.
Definition: tips.cpp:36
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_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
Definition: message.cpp:203
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.
Definition: message.cpp:150
@ TEXTBOX_MESSAGE
@ TEXTBOX_SEARCH
@ TEXTBOX_COMMAND
Keyboard shortcuts for game actions.
constexpr uint32_t scope_game
const int INFINITE_AUTO_SAVES
Definition: preferences.hpp:58
::tod_manager * tod_manager
Definition: resources.cpp:29
game_board * gameboard
Definition: resources.cpp:20
persist_manager * persist
Definition: resources.cpp:26
game_data * gamedata
Definition: resources.cpp:22
game_events::manager * game_events
Definition: resources.cpp:24
replay * recorder
Definition: resources.cpp:28
actions::undo_list * undo_stack
Definition: resources.cpp:32
soundsource::manager * soundsources
Definition: resources.cpp:27
game_lua_kernel * lua_kernel
Definition: resources.cpp:25
game_classification * classification
Definition: resources.cpp:34
pathfind::manager * tunnels
Definition: resources.cpp:31
play_controller * controller
Definition: resources.cpp:21
filter_context * filter_con
Definition: resources.cpp:23
std::shared_ptr< wb::manager > whiteboard
Definition: resources.cpp:33
void write_music_play_list(config &snapshot)
Definition: sound.cpp:866
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
Definition: sound.cpp:1035
@ SOUND_SOURCES
Definition: sound.hpp:30
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
Definition: general.hpp:83
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
Definition: general.cpp:23
std::map< std::string, t_string > string_map
bool headless()
The game is running headless.
Definition: video.cpp:141
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
static void clear_resources()
static lg::log_domain log_engine("engine")
#define ERR_NG
static lg::log_domain log_aitesting("ai/testing")
static void find_next_scenarios(const config &parent, std::set< std::string > &result)
Find all [endlevel]next_scenario= attributes, and add them to result.
static void copy_persistent(const config &src, config &dst)
Copies [scenario] attributes/tags that are not otherwise stored in C++ structs/clases.
static lg::log_domain log_enginerefac("enginerefac")
#define LOG_AIT
static lg::log_domain log_display("display")
static lg::log_domain log_engine_enemies("engine/enemies")
#define DBG_NG
#define ERR_DP
#define DBG_EE
#define LOG_NG
Define the game's event mechanism.
Replay control code.
Additional information on the game outcome which can be provided by WML.
bool proceed_to_next_level
whether to proceed to the next scenario, equals is_victory in sp.
transient_end_level transient
Error used for any general game error, e.g.
Definition: game_errors.hpp:47
Encapsulates the map of the game.
Definition: location.hpp:38
static const map_location & null_location()
Definition: location.hpp:81
Object which contains all the possible locations a unit can move to, with associated best routes to t...
Definition: pathfind.hpp:73
scoped_savegame_snapshot(const play_controller &controller)
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
std::string sounds
List of "ambient" sounds associated with this time_of_day, Played at the beginning of turn.
bool reveal_map
Should we reveal map when game is ended? (Multiplayer only)
bool valid() const
Definition: map.hpp:273
Object which temporarily resets a unit's movement.
Definition: unit.hpp:2093
Gather statistics important for AI testing and output them.
unit_type_data unit_types
Definition: types.cpp:1486
Various functions that implement the undoing (and redoing) of in-game commands.
Various functions implementing vision (through fog of war and shroud).
#define e