The Battle for Wesnoth  1.19.5+dev
playsingle_controller.hpp
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 #pragma once
18 
19 #include "play_controller.hpp"
20 
21 #include "cursor.hpp"
24 #include "replay.hpp"
25 
26 #include <exception>
27 
28 class replay_controller;
29 class saved_game;
30 
31 struct reset_gamestate_exception final : public lua_jailbreak_exception, public std::exception
32 {
33  reset_gamestate_exception(std::shared_ptr<config> l, std::shared_ptr<config> stats, bool s = true) : level(l), stats_(stats), start_replay(s)
34  {
35  this->store();
36  }
37  std::shared_ptr<config> level;
38  std::shared_ptr<config> stats_;
40  const char * what() const noexcept { return "reset_gamestate_exception"; }
41 private:
42 
44 };
45 
47 {
48 public:
49  playsingle_controller(const config& level, saved_game& state_of_game);
50 
53  void play_scenario_init(const config& level);
54 
55  struct ses_result { int side_num; bool wrapped; };
56  /// Calculates the current side, starting at @a side_num that is non-empty
57  /// @return side_num: the new side that is non-empty,
58  /// @a side_num, if no such side was found.
59  /// wrapped: whether we wrapped around (usually indicates a new tod turn.)
60  /// also true if no non-empty side was found.
61  ses_result skip_empty_sides(int side_num);
62  void play_some();
63  void play_side();
64  void finish_side_turn();
65  void do_end_level();
67 
68  virtual void handle_generic_event(const std::string& name) override;
69 
70  virtual void check_objectives() override;
71  virtual void on_not_observer() override {}
72  virtual bool is_host() const { return true; }
73  virtual void maybe_linger();
74 
75  void end_turn();
76  void force_end_turn() override;
77  void require_end_turn();
78 
79  class hotkey_handler;
80  std::string describe_result() const;
81 
84  virtual bool should_return_to_play_side() const override;
85  replay_controller * get_replay_controller() const override { return replay_controller_.get(); }
86  void enable_replay(bool is_unit_test = false);
87  void on_replay_end(bool is_unit_test);
88 protected:
89  void play_side_impl();
90  void before_human_turn();
91  void show_turn_dialog();
92  void execute_gotos();
93  virtual void play_human_turn();
94  virtual void after_human_turn();
95  void end_turn_enable(bool enable);
96  void play_ai_turn();
97  virtual void play_idle_loop();
98  virtual void do_idle_notification();
99  virtual void play_network_turn();
100  virtual void init_gui() override;
101 
103 
104  /// true iff the user has pressed the end turn button this turn.
105  /// (or wants to end linger mode, which is implemented via the same button)
107  /// true when the current side is actually an ai side but was taken over by a human (usually for debugging purposes),
108  /// we need this variable to remember to give the ai control back next turn.
110  /// non-null when replay mode in active, is used in singleplayer and for the "back to turn" feature in multiplayer.
111  std::unique_ptr<replay_controller> replay_controller_;
112  void linger();
113  void update_gui_linger();
114  void sync_end_turn() override;
115  bool is_team_visible(int team_num, bool observer) const;
116  /** returns 0 if no such team was found. */
117  int find_viewing_side() const override;
118  void update_viewing_player() override;
119  void reset_replay();
120 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
Base class for exceptions that want to be thrown 'through' lua.
void store() const noexcept
Stores a copy the current exception to be rethrown.
bool player_type_changed_
true when the controller of the currently playing side has changed.
void end_turn_enable(bool enable)
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.
bool is_team_visible(int team_num, bool observer) const
replay_controller * get_replay_controller() const override
level_result::type play_scenario(const config &level)
virtual bool is_host() const
virtual bool should_return_to_play_side() const override
~playsingle_controller()
Defined here to reduce file includes.
const cursor::setter cursor_setter_
void update_viewing_player() override
playsingle_controller(const config &level, saved_game &state_of_game)
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.
virtual void on_not_observer() override
int find_viewing_side() const override
returns 0 if no such team was found.
void play_scenario_init(const config &level)
void enable_replay(bool is_unit_test=false)
#define IMPLEMENT_LUA_JAILBREAK_EXCEPTION(type)
Helper macro for classes deriving from lua_jailbreak_exception.
std::string observer
Replay control code.
std::shared_ptr< config > stats_
const char * what() const noexcept
std::shared_ptr< config > level
reset_gamestate_exception(std::shared_ptr< config > l, std::shared_ptr< config > stats, bool s=true)
static map_location::direction s