The Battle for Wesnoth  1.19.0-dev
playsingle_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  * Logic for single-player game.
20  */
21 
23 
24 #include "actions/undo.hpp"
25 #include "ai/manager.hpp"
26 #include "ai/testing.hpp"
27 #include "display_chat_manager.hpp"
28 #include "carryover_show_gold.hpp"
29 #include "formula/string_utils.hpp"
30 #include "game_end_exceptions.hpp"
31 #include "game_events/pump.hpp"
32 #include "gettext.hpp"
36 #include "log.hpp"
37 #include "map/label.hpp"
38 #include "map/map.hpp"
39 #include "playturn.hpp"
40 #include "preferences/game.hpp"
41 #include "replay_controller.hpp"
42 #include "replay_helper.hpp"
43 #include "resources.hpp"
44 #include "saved_game.hpp"
45 #include "savegame.hpp"
47 #include "sound.hpp"
48 #include "soundsource.hpp"
49 #include "synced_context.hpp"
50 #include "video.hpp"
52 #include "whiteboard/manager.hpp"
53 
54 
55 static lg::log_domain log_aitesting("ai/testing");
56 #define LOG_AIT LOG_STREAM(info, log_aitesting)
57 // If necessary, this define can be replaced with `#define LOG_AIT std::cout` to restore previous behavior
58 
59 static lg::log_domain log_engine("engine");
60 #define ERR_NG LOG_STREAM(err, log_engine)
61 #define LOG_NG LOG_STREAM(info, log_engine)
62 #define DBG_NG LOG_STREAM(debug, log_engine)
63 
64 static lg::log_domain log_enginerefac("enginerefac");
65 #define LOG_RG LOG_STREAM(info, log_enginerefac)
66 
67 playsingle_controller::playsingle_controller(const config& level, saved_game& state_of_game, bool skip_replay)
68  : play_controller(level, state_of_game, skip_replay, true) // start faded
69  , cursor_setter_(cursor::NORMAL)
70  , replay_sender_(*resources::recorder)
71  , network_reader_([this](config& cfg) { return receive_from_wesnothd(cfg); })
72  , turn_data_(replay_sender_, network_reader_)
73  , end_turn_requested_(false)
74  , ai_fallback_(false)
75  , replay_controller_()
76 {
77  // upgrade hotkey handler to the sp (whiteboard enabled) version
78  hotkey_handler_ = std::make_unique<hotkey_handler>(*this, saved_game_);
79 
80 
81  plugins_context_->set_accessor_string("level_result", std::bind(&playsingle_controller::describe_result, this));
82  plugins_context_->set_accessor_int("turn", std::bind(&play_controller::turn, this));
83 }
84 
85 ///Defined here to reduce file includes.
87 
88 
90 {
91  if(!is_regular_game_end()) {
92  return "NONE";
93  } else if(get_end_level_data().is_victory) {
94  return "VICTORY";
95  } else {
96  return "DEFEAT";
97  }
98 }
99 
101 {
102  LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks());
103  // If we are retarting replay from linger mode.
106 
107  // Scroll to the starting position of the first team. If there is a
108  // human team, use that team; otherwise use team 1. If the map defines
109  // a starting position for the selected team, scroll to that tile. Note
110  // this often does not matter since many scenario start with messages,
111  // which will usually scroll to the speaker. Also note that the map
112  // does not necessarily define the starting positions. While usually
113  // best to use the map, the scenarion may explicitly set the positions,
114  // overriding those found in the map (if any).
115  if(map_start_.valid()) {
116  gui_->scroll_to_tile(map_start_, game_display::WARP, false);
117  LOG_NG << "Found good stored ui location " << map_start_;
118  } else {
119 
120  int scroll_team = find_viewing_side();
121  if(scroll_team == 0) {
122  scroll_team = 1;
123  }
124 
125  map_location loc(get_map().starting_position(scroll_team));
126  if((loc.x >= 0) && (loc.y >= 0)) {
127  gui_->scroll_to_tile(loc, game_display::WARP);
128  LOG_NG << "Found bad stored ui location " << map_start_ << " using side starting location " << loc;
129  } else {
130  LOG_NG << "Found bad stored ui location";
131  }
132  }
133 
134  // Fade in
135  gui_->set_prevent_draw(false);
136  gui_->queue_repaint();
137  if(!video::headless() && !video::testing()) {
138  gui_->fade_to({0,0,0,0}, 500);
139  } else {
140  gui_->set_fade({0,0,0,0});
141  }
142 
144 }
145 
147 {
148  gui_->labels().read(level);
150 
151  // Read sound sources
152  assert(soundsources_manager_ != nullptr);
153  for(const config& s : level.child_range("sound_source")) {
154  try {
156  soundsources_manager_->add(spec);
157  } catch(const bad_lexical_cast&) {
158  ERR_NG << "Error when parsing sound_source config: bad lexical cast.";
159  ERR_NG << "sound_source config was: " << s.debug();
160  ERR_NG << "Skipping this sound source...";
161  }
162  }
163 
164  // At the beginning of the scenario, save a snapshot as replay_start
165  if(saved_game_.replay_start().empty()) {
167  }
168 
169  fire_preload();
171 
172  start_game();
173  gamestate_->player_number_ = skip_empty_sides(gamestate_->player_number_).side_num;
174 
175  if(!get_teams().empty()) {
176  init_side_begin();
177  if(gamestate().in_phase(game_data::TURN_PLAYING)) {
178  init_side_end();
179  }
180  }
181 
183  // This won't cause errors later but we should notify the user about it in case he didn't knew it.
185  // TODO: find a better title
186  _("Game Error"),
187  _("This multiplayer game uses an alternative random mode, if you don't know what this message means, then "
188  "most likely someone is cheating or someone reloaded a corrupt game."));
189  }
190 }
191 
193 {
194  const int sides = static_cast<int>(get_teams().size());
195  const int max = side_num + sides;
196 
197  for (; side_num != max; ++side_num) {
198  int side_num_mod = modulo(side_num, sides, 1);
199  if(!gamestate().board_.get_team(side_num_mod).is_empty()) {
200  return { side_num_mod, side_num_mod != side_num };
201  }
202  }
203  return { side_num, true };
204 }
205 
207 {
208  //TODO: Its still unclear to me when end_turn_requested_ should be reset, i guess the idea is
209  // in particular that in rare cases when the player looses control at the same time
210  // as he presses "end turn" and then regains control back, the "end turn" should be discarded?
211  //One of the main reasonsy why this is here is probably also that play_controller has no access to it.
213 
215 
217  play_side();
218  assert(is_regular_game_end() || gamestate().in_phase(game_data::TURN_ENDED));
219  }
220 
221  if (!is_regular_game_end() && gamestate().in_phase(game_data::TURN_ENDED)) {
223  }
224 
225  if (is_regular_game_end() && !gamestate().in_phase(game_data::GAME_ENDED)) {
227  do_end_level();
229  }
230 
231  if (gamestate().in_phase(game_data::GAME_ENDED)) {
232  if(!get_end_level_data().transient.linger_mode || get_teams().empty() || video::headless()) {
233  end_turn_requested_ = true;
234  }
235  maybe_linger();
236  }
237 }
238 
240 {
241  if(is_regular_game_end()) {
242  return;
243  }
244 
245  /// Make a copy, since the [end_turn] was already sent to to server any changes to
246  // next_player_number by wml would cause OOS otherwise.
247  int next_player_number_temp = gamestate_->next_player_number_;
248  whiteboard_manager_->on_finish_side_turn(current_side());
249 
251  if(is_regular_game_end()) {
252  return;
253  }
254 
255  auto [next_player_number, new_turn] = skip_empty_sides(next_player_number_temp);
256 
257  if(new_turn) {
258  finish_turn();
259  if(is_regular_game_end()) {
260  return;
261  }
262  // Time has run out
263  check_time_over();
264  if(is_regular_game_end()) {
265  return;
266  }
267  did_tod_sound_this_turn_ = false;
268  }
269 
270  gamestate_->player_number_ = next_player_number;
271  if(current_team().is_empty()) {
272  // We don't support this case (turn end events emptying the next sides controller) since the server cannot handle it.
273  throw game::game_error("Empty side after new turn events");
274  }
275 
276  if(new_turn) {
277  whiteboard_manager_->on_gamestate_change();
278  gui_->new_turn();
279  gui_->invalidate_game_status();
280  }
283  did_autosave_this_turn_ = false;
284  end_turn_requested_ = false;
285  init_side_begin();
286 }
287 
289 {
290  LOG_NG << "starting main loop\n" << (SDL_GetTicks() - ticks());
291 
293  while(!(gamestate().in_phase(game_data::GAME_ENDED) && end_turn_requested_ )) {
294  try {
295  play_some();
296  } catch(const reset_gamestate_exception& ex) {
297  boost::dynamic_bitset<> local_players;
298  local_players.resize(get_teams().size(), true);
299  // Preserve side controllers, because we won't get the side controoller updates again when replaying.
300  for(std::size_t i = 0; i < local_players.size(); ++i) {
301  local_players[i] = get_teams()[i].is_local();
302  }
303 
304  if(ex.stats_) {
305  // "Back to turn"
307  } else {
308  // "Reset Replay To start"
310  }
311 
312  reset_gamestate(*ex.level, (*ex.level)["replay_pos"]);
313 
314  for(std::size_t i = 0; i < local_players.size(); ++i) {
315  resources::gameboard->teams()[i].set_local(local_players[i]);
316  }
317 
318  // TODO: we currently don't set the music to the initial playlist, should we?
319 
321 
322  if(replay_controller_ == nullptr) {
323  replay_controller_ = std::make_unique<replay_controller>(*this, false, ex.level, [this]() { on_replay_end(false); });
324  }
325 
326  if(ex.start_replay) {
327  replay_controller_->play_replay();
328  }
329  }
330  } // end for loop
331 }
332 
334 {
336  exit(0);
337  }
338  const bool is_victory = get_end_level_data().is_victory;
339 
341 
342  const end_level_data& end_level = get_end_level_data();
343 
344  if(get_teams().empty()) {
345  // this is probably only a story scenario, i.e. has its endlevel in the prestart event
346  return;
347  }
348 
349 
350  pump().fire(is_victory ? "local_victory" : "local_defeat");
351 
352  { // Block for set_scontext_synced_base
354  pump().fire(end_level.proceed_to_next_level ? level_result::victory : level_result::defeat);
355  pump().fire("scenario_end");
356  }
357 
358  if(end_level.proceed_to_next_level) {
360  }
361 
362  if(is_observer()) {
363  gui2::show_transient_message(_("Game Over"), _("The game is over."));
364  }
365 
366  // If we're a player, and the result is victory/defeat, then send
367  // a message to notify the server of the reason for the game ending.
369  "info", config {
370  "type", "termination",
371  "condition", "game over",
372  "result", is_victory ? level_result::victory : level_result::defeat,
373  },
374  });
375 
376  // Play victory music once all victory events
377  // are finished, if we aren't observers and the
378  // carryover dialog isn't disabled.
379  //
380  // Some scenario authors may use 'continue'
381  // result for something that is not story-wise
382  // a victory, so let them use [music] tags
383  // instead should they want special music.
384  const std::string& end_music = select_music(is_victory);
385  if((!is_victory || end_level.transient.carryover_report) && !end_music.empty()) {
387  sound::play_music_once(end_music);
388  }
389 
392 
393 }
394 
396 {
397  LOG_NG << "in playsingle_controller::play_scenario()...";
398 
399  // Start music.
400  for(const config& m : level.child_range("music")) {
401  sound::play_music_config(m, true);
402  }
403 
405 
407  // Combine all the [story] tags into a single config. Handle this here since
408  // storyscreen::controller doesn't have a default constructor.
409  config cfg;
410  for(const auto& iter : level.child_range("story")) {
411  cfg.append_children(iter);
412  }
413 
414  if(!cfg.empty()) {
416  }
417  }
418 
419 
420  try {
422  // clears level config (the intention was probably just to save some ram),
423  // Note: this might clear 'level', so don't use level after this.
425 
427 
428  // TODO: would it be better if the is_networked_mp() check was done in is_observer() ?
429  if(is_networked_mp() && is_observer()) {
430  return level_result::type::observer_end;
431  }
432  return level_result::get_enum(get_end_level_data().test_result).value_or(get_end_level_data().is_victory ? level_result::type::victory : level_result::type::defeat);
433  } catch(const savegame::load_game_exception&) {
434  // Loading a new game is effectively a quit.
435  saved_game_.clear();
436  throw;
437  } catch(const wesnothd_error& e) {
438  scoped_savegame_snapshot snapshot(*this);
440  if(e.message == "") {
442  _("A network disconnection has occurred, and the game cannot continue. Do you want to save the game?"),
444  } else {
446  _("This game has been ended.\nReason: ") + e.message + _("\nDo you want to save the game?"),
448  }
449 
450  if(dynamic_cast<const ingame_wesnothd_error*>(&e) || dynamic_cast<const leavegame_wesnothd_error*>(&e)) {
451  return level_result::type::quit;
452  } else {
453  throw;
454  }
455  }
456 }
457 
459 {
460  while(!should_return_to_play_side()) {
462  SDL_Delay(10);
463  }
464 }
465 
467 {
468  if(replay_controller_.get() != nullptr) {
469  replay_controller_->play_side_impl();
470 
472  replay_controller_.reset();
473  }
474  } else if((current_team().is_local_human() && current_team().is_proxy_human())) {
475  LOG_NG << "is human...";
476  // If a side is dead end the turn, but play at least side=1's
477  // turn in case all sides are dead
478  if(gamestate().board_.side_units(current_side()) == 0 && !(get_units().empty() && current_side() == 1)) {
480  }
481 
483 
484  if(!end_turn_requested_) {
485  play_human_turn();
486  }
487 
490  }
491 
492  LOG_NG << "human finished turn...";
493  } else if(current_team().is_local_ai() || (current_team().is_local_human() && current_team().is_droid())) {
494  play_ai_turn();
495  } else if(current_team().is_network()) {
497  } else if(current_team().is_local_human() && current_team().is_idle()) {
498  end_turn_enable(false);
501 
503  play_idle_loop();
504  }
505  } else {
506  // we should have skipped over empty controllers before so this shouldn't be possible
507  ERR_NG << "Found invalid side controller " << side_controller::get_string(current_team().controller()) << " ("
508  << side_proxy_controller::get_string(current_team().proxy_controller()) << ") for side " << current_team().side();
509  }
510 }
511 
513 {
514  log_scope("player turn");
515  assert(!is_linger_mode());
517  return;
518  }
519 
522  scoped_savegame_snapshot snapshot(*this);
525  }
526 
527  if(preferences::turn_bell()) {
529  }
530 }
531 
533 {
535  blindfold b(*gui_, true); // apply a blindfold for the duration of this dialog
536  gui_->queue_rerender();
537  std::string message = _("It is now $name|’s turn");
538  utils::string_map symbols;
539  symbols["name"] = gamestate().board_.get_team(current_side()).side_name();
540  message = utils::interpolate_variables_into_string(message, &symbols);
541  gui2::show_transient_message("", message);
542  }
543 }
544 
546 {
548  return;
549  }
550 
551  try {
553  } catch(const return_to_play_side_exception&) {
554  }
555 }
556 
558 {
560 
562  execute_gotos();
563  }
564 
565  end_turn_enable(true);
566 
570  }
571 }
572 
574 {
575  if(is_linger_mode()) {
576  // If we need to set the status depending on the completion state
577  // the key to it is here.
578  gui_->set_game_mode(game_display::LINGER);
579  // change the end-turn button text from "End Turn" to "End Scenario"
580  gui_->get_theme().refresh_title2("button-endturn", "title2");
581  } else {
582  gui_->set_game_mode(game_display::RUNNING);
583  // change the end-turn button text from "End Scenario" to "End Turn"
584  gui_->get_theme().refresh_title2("button-endturn", "title");
585  }
586  // Also checcks whether the button can be pressed.
587  gui_->queue_rerender();
588 }
589 
591 {
592  LOG_NG << "beginning end-of-scenario linger";
593 
594  // Make all of the able-to-move units' orbs consistently red
596 
598 
599  try {
600  if(replay_controller_.get() != nullptr) {
601  replay_controller_->play_side_impl();
603  replay_controller_.reset();
604  }
605  }
606  while(!end_turn_requested_) {
607  play_slice();
608  }
609  } catch(const savegame::load_game_exception&) {
610  // Loading a new game is effectively a quit.
611  saved_game_.clear();
612  throw;
613  }
614 
615  LOG_NG << "ending end-of-scenario linger";
616 }
617 
619 {
620  // TODO: this is really only needed to refresh the visual state of the buttons on each turn.
621  // It looks like we can put it in play_side_impl, but it definitely should be removed from
622  // here since other code already takes care of actually enabling/disabling the end turn button.
624 }
625 
627 {
628  // Clear moves from the GUI.
629  gui_->set_route(nullptr);
630  gui_->unhighlight_reach();
631 }
632 
634 {
635  LOG_NG << "is ai...";
636 
637  end_turn_enable(false);
638  gui_->recalculate_minimap();
639 
640  const cursor::setter cursor_setter(cursor::WAIT);
641 
642  // Correct an oddball case where a human could have left delayed shroud
643  // updates on before giving control to the AI. (The AI does not bother
644  // with the undo stack, so it cannot delay shroud updates.)
645  team& cur_team = current_team();
646  if(!cur_team.auto_shroud_updates()) {
647  // We just took control, so the undo stack is empty. We still need
648  // to record this change for the replay though.
650  }
651 
652  undo_stack().clear();
654 
655  try {
656  try {
659  }
660  } catch(const return_to_play_side_exception&) {
661  } catch(const fallback_ai_to_human_exception&) {
663  player_type_changed_ = true;
664  ai_fallback_ = true;
665  }
666  } catch(...) {
667  DBG_NG << "Caught exception playing ai turn: " << utils::get_unknown_exception_type();
669  throw;
670  }
671 
674  }
675 
677  gui_->recalculate_minimap();
678  gui_->invalidate_unit();
679  gui_->invalidate_game_status();
680  gui_->invalidate_all();
681 }
682 
683 /**
684  * Will handle sending a networked notification in descendent classes.
685  */
687 {
688  gui_->get_chat_manager().add_chat_message(std::time(nullptr), "Wesnoth", 0,
689  "This side is in an idle state. To proceed with the game, the host must assign it to another controller.",
691 }
692 
693 /**
694  * Will handle networked turns in descendent classes.
695  */
697 {
698  // There should be no networked sides in single-player.
699  ERR_NG << "Networked team encountered by playsingle_controller.";
700 }
701 
702 void playsingle_controller::handle_generic_event(const std::string& name)
703 {
704  if(name == "ai_user_interact") {
705  play_slice(false);
706  }
707 }
708 
710 {
711  if(is_linger_mode()) {
712  end_turn_requested_ = true;
713  } else if(!is_browsing() && menu_handler_.end_turn(current_side())) {
715  }
716 }
717 
719 {
721  end_turn_requested_ = true;
722 }
723 
725 {
726  end_turn_requested_ = true;
727 }
728 
730 {
731  if(!get_teams().empty()) {
732  const team& t = get_teams()[gui_->viewing_team()];
733 
734  if(!is_regular_game_end() && !is_browsing() && t.objectives_changed()) {
735  show_objectives();
736  }
737  }
738 }
739 
741 {
742  // mouse_handler expects at least one team for linger mode to work.
743  assert(is_regular_game_end());
744  linger();
745  end_turn_requested_ = true;
746 }
747 
749 {
750  // We cannot add [end_turn] to the recorder while executing another action.
752 
753  if(!gamestate().in_phase(game_data::TURN_ENDED)) {
754  assert(end_turn_requested_);
755  assert(current_team().is_local());
756  assert(gamestate().in_phase(game_data::TURN_PLAYING));
757  // TODO: we should also send this immediately.
758  resources::recorder->end_turn(gamestate_->next_player_number_);
760 
761  }
762 
763 
764  assert(gamestate().in_phase(game_data::TURN_ENDED));
765 
766  if(ai_fallback_) {
767  current_team().make_ai();
768  ai_fallback_ = false;
769  }
770 }
771 
773 {
774  if(replay_controller_ && replay_controller_->is_controlling_view()) {
775  replay_controller_->update_viewing_player();
776  } else if(int side_num = play_controller::find_viewing_side()) {
777  if(side_num != gui_->viewing_side() || gui_->show_everything()) {
778  update_gui_to_player(side_num - 1);
779  }
780  }
781 }
782 
784 {
785  if(replay_controller_ && replay_controller_->allow_reset_replay()) {
786  replay_controller_->stop_replay();
787  throw reset_gamestate_exception(replay_controller_->get_reset_state(), {}, false);
788  } else {
789  ERR_NG << "received invalid reset replay";
790  }
791 }
792 
794 {
795  replay_controller_ = std::make_unique<replay_controller>(
796  *this,
797  true,
798  std::make_shared<config>(saved_game_.get_replay_starting_point()),
799  std::bind(&playsingle_controller::on_replay_end, this, is_unit_test)
800  );
801 
802  if(is_unit_test) {
803  replay_controller_->play_replay();
804  }
805 }
806 
808 {
810  return true;
811  } else if((gamestate().in_phase(game_data::TURN_STARTING_WAITING) || end_turn_requested_) && replay_controller_.get() == 0 && current_team().is_local() && !current_team().is_idle()) {
812  // When we are a locally controlled side and havent done init_side yet also return to play_side
813  return true;
814  } else {
815  return false;
816  }
817 }
818 
820 {
821  if(is_networked_mp()) {
822  // we are using the "Back to turn (replay)" feature
823  // And have reached the current gamestate: end the replay and continue normally.
825  } else if(is_unit_test) {
826  replay_controller_->return_to_play_side();
827  if(!is_regular_game_end()) {
829  e.proceed_to_next_level = false;
830  e.is_victory = false;
832  }
833  } else {
834  replay_controller_->stop_replay();
835  }
836 }
837 
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands.
double t
Definition: astarsearch.cpp:63
void carryover_show_gold(game_state &state, bool hidden, bool is_observer, bool is_test)
calculates the amount of gold carried over for each team, stores the data in the team object and show...
void clear()
Clears the stack of undoable (and redoable) actions.
Definition: undo.cpp:201
static manager & get_singleton()
Definition: manager.hpp:142
void play_turn(side_number side)
Plays a turn for the specified side using its active AI.
Definition: manager.cpp:724
static void log_game_end()
Definition: testing.cpp:102
static void log_game_start()
Definition: testing.cpp:90
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
void append_children(const config &cfg)
Adds children from cfg.
Definition: config.cpp:165
bool empty() const
Definition: config.cpp:852
virtual void play_slice(bool is_delay_enabled=true)
void execute_gotos(mouse_handler &mousehandler, int side_num)
bool end_turn(int side_num)
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:79
void heal_all_survivors()
Definition: game_board.cpp:95
team & get_team(int i)
Definition: game_board.hpp:91
void set_all_units_user_end_turn()
Definition: game_board.cpp:88
void set_end_turn_forced(bool v)
Definition: game_data.hpp:145
void set_phase(PHASE phase)
Definition: game_data.hpp:106
@ 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
@ TURN_PLAYING
The User is controlling the game and invoking actions The game can be saved here.
Definition: game_data.hpp:93
@ TURN_ENDED
The turn_end, side_turn_end etc [events] are fired next phase: TURN_STARTING_WAITING (default),...
Definition: game_data.hpp:96
@ TURN_STARTING_WAITING
we are waiting for the turn to start.
Definition: game_data.hpp:86
@ GAME_ENDING
The victory etc.
Definition: game_data.hpp:99
static PHASE read_phase(const config &cfg)
Definition: game_data.cpp:177
bool end_turn_forced() const
Definition: game_data.hpp:146
@ RUNNING
no linger overlay, show fog and shroud.
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
game_board board_
Definition: game_state.hpp:44
game_data gamedata_
Definition: game_state.hpp:43
static void display(const std::string &scenario_name, const config &story)
const std::string & select_music(bool victory) const
config to_config() const
Builds the snapshot config from members and their respective configs.
virtual bool receive_from_wesnothd(config &) const
std::vector< team > & get_teams()
virtual void init_gui()
std::unique_ptr< game_state > gamestate_
void show_objectives() const
events::menu_handler menu_handler_
int find_viewing_side() const
returns 0 if no such team was found.
void fire_preload()
preload events cannot be synced
bool is_linger_mode() const
actions::undo_list & undo_stack()
const unit_map & get_units() const
void set_end_level_data(const end_level_data &data)
bool is_observer() const
void reset_gamestate(const config &level, int replay_pos)
bool is_skipping_story() const
bool is_regular_game_end() const
saved_game & get_saved_game()
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.
std::unique_ptr< game_display > gui_
bool is_browsing() const override
virtual void send_to_wesnothd(const config &, const std::string &="unknown") const
std::unique_ptr< soundsource::manager > soundsources_manager_
const end_level_data & get_end_level_data() const
int current_side() const
Returns the number of the side whose turn it is.
virtual bool is_networked_mp() const
bool is_skipping_replay() const
const gamemap & get_map() 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
bool player_type_changed_
true when the controller of the currently playing side has changed.
std::size_t turn() const
map_location map_start_
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_
game_events::wml_event_pump & pump()
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
void end_turn_enable(bool enable)
playsingle_controller(const config &level, saved_game &state_of_game, bool skip_replay)
virtual void play_network_turn()
Will handle networked turns in descendent classes.
virtual void init_gui() override
void on_replay_end(bool is_unit_test)
std::string describe_result() const
std::unique_ptr< replay_controller > replay_controller_
non-null when replay mode in active, is used in singleplayer and for the "back to turn" feature in mu...
bool ai_fallback_
true when the current side is actually an ai side but was taken over by a human (usually for debuggin...
virtual void check_objectives() override
ses_result skip_empty_sides(int side_num)
Calculates the current side, starting at side_num that is non-empty.
level_result::type play_scenario(const config &level)
virtual bool should_return_to_play_side() const override
virtual void play_side_impl() override
~playsingle_controller()
Defined here to reduce file includes.
turn_info turn_data_
Helper to read and execute (in particular replay data/ user actions ) messsages from the server.
void update_viewing_player() override
virtual void handle_generic_event(const std::string &name) override
virtual void do_idle_notification()
Will handle sending a networked notification in descendent classes.
bool end_turn_requested_
true iff the user has pressed the end turn button this turn.
void play_scenario_init(const config &level)
void enable_replay(bool is_unit_test=false)
static config get_auto_shroud(bool turned_on)
Records that the player has toggled automatic shroud updates.
void end_turn(int next_player_number)
Definition: replay.cpp:304
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
game_classification & classification()
Definition: saved_game.hpp:56
void clear()
Definition: saved_game.cpp:813
config & replay_start()
Definition: saved_game.hpp:128
void remove_snapshot()
Definition: saved_game.cpp:605
const config & get_replay_starting_point()
Definition: saved_game.cpp:616
statistics_record::campaign_stats_t & statistics()
Definition: saved_game.hpp:143
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
Exception used to signal that the user has decided to abortt a game, and to load another game instead...
Definition: savegame.hpp:85
bool save_game_interactive(const std::string &message, DIALOG_TYPE dialog_type)
Save a game interactively through the savegame dialog.
Definition: savegame.cpp:377
Sound source info class.
static bool run_and_store(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
const std::string & side_name() const
Definition: team.hpp:293
int side() const
Definition: team.hpp:174
bool auto_shroud_updates() const
Definition: team.hpp:324
void make_ai()
Definition: team.hpp:260
void make_human()
Definition: team.hpp:259
void send_data()
Definition: playturn.cpp:78
PROCESS_DATA_RESULT sync_network()
Definition: playturn.cpp:59
std::size_t i
Definition: function.cpp:968
Contains the exception interfaces used to signal completion of a scenario, campaign or turn.
static std::string _(const char *str)
Definition: gettext.hpp:93
An extension of play_controller::hotkey_handler, which has support for SP wesnoth features like white...
Standard logging facilities (interface).
#define log_scope(description)
Definition: log.hpp:274
constexpr T modulo(T num, int mod, T min=0)
Definition: math.hpp:62
@ WAIT
Definition: cursor.hpp:28
@ NORMAL
Definition: cursor.hpp:28
std::string turn_bell
bool disable_autosave
Definition: game_config.cpp:88
bool exit_at_end
Definition: game_config.cpp:86
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.
int autosavemax()
Definition: game.cpp:788
compression::format save_compression_format()
Definition: game.cpp:840
bool turn_dialog()
Definition: game.cpp:413
bool disable_auto_moves()
Definition: general.cpp:971
const int INFINITE_AUTO_SAVES
Definition: game.hpp:208
bool turn_bell()
Definition: general.cpp:675
game_board * gameboard
Definition: resources.cpp:20
replay * recorder
Definition: resources.cpp:28
void empty_playlist()
Definition: sound.cpp:610
void play_music_config(const config &music_node, bool allow_interrupt_current_track, int i)
Definition: sound.cpp:711
void play_music_once(const std::string &file)
Definition: sound.cpp:601
void commit_music_changes()
Definition: sound.cpp:835
void play_bell(const std::string &files)
Definition: sound.cpp:1048
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 ...
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
bool testing()
The game is running unit tests.
Definition: video.cpp:146
static lg::log_domain log_engine("engine")
#define ERR_NG
static lg::log_domain log_aitesting("ai/testing")
static lg::log_domain log_enginerefac("enginerefac")
#define DBG_NG
#define LOG_NG
Define the game's event mechanism.
Thrown when a lexical_cast fails.
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
We received invalid data from wesnothd during a game This means we cannot continue with the game but ...
Encapsulates the map of the game.
Definition: location.hpp:38
bool valid() const
Definition: location.hpp:89
std::shared_ptr< config > stats_
std::shared_ptr< config > level
void read(const config &cfg, bool append=false)
void clear_current_scenario()
Delete the current scenario from the stats.
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
Definition: enum_base.hpp:46
static constexpr std::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
Definition: enum_base.hpp:57
bool carryover_report
Should a summary of the scenario outcome be displayed?
An error occurred during when trying to communicate with the wesnothd server.
static map_location::DIRECTION s
Gather statistics important for AI testing and output them.
Various functions that implement the undoing (and redoing) of in-game commands.
#define e
#define b