The Battle for Wesnoth  1.19.5+dev
game_end_exceptions.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 /**
18  * @file
19  * Contains the exception interfaces used to signal
20  * completion of a scenario, campaign or turn.
21  */
22 
23 #pragma once
24 
25 #include "level_result.hpp"
27 
28 #include <string>
29 #include <exception>
30 
31 class config;
32 
33 /**
34  * Exception used to escape form the ai or ui code to playsingle_controller::play_side.
35  * Never thrown during replays.
36  */
37 class return_to_play_side_exception final : public lua_jailbreak_exception, public std::exception
38 {
39 public:
40 
43  , std::exception()
44  {
45  this->store();
46  }
47  const char * what() const noexcept { return "return_to_play_side_exception"; }
48 private:
49 
51 };
52 
55  , public std::exception
56 {
57 public:
58 
61  , std::exception()
62  {
63  this->store();
64  }
65  const char * what() const noexcept { return "quit_game_exception"; }
66 private:
68 };
69 
70 /**
71  * The non-persistent part of end_level_data
72  */
74 
76 
77  bool carryover_report; /**< Should a summary of the scenario outcome be displayed? */
78  bool linger_mode; /**< Should linger mode be invoked? */
79  bool reveal_map; /**< Should we reveal map when game is ended? (Multiplayer only) */
80 
81  void write(config& cfg) const;
82 };
83 
84 /**
85  * Additional information on the game outcome which can be provided by WML.
86  */
88 {
90 
91 
92  bool prescenario_save; /**< Should a prescenario be created the next game? */
93  bool replay_save; /**< Should a replay save be made? */
94  bool proceed_to_next_level; /**< whether to proceed to the next scenario, equals is_victory in sp. We need to save this in saves during linger mode. > */
95  bool is_victory;
96  std::string test_result; /**< result to use if this is a unit test */
98  void write(config& cfg) const;
99 
100  void read(const config& cfg);
101 
102  config to_config() const;
103  /** Includes the transient data */
104  config to_config_full() const;
105 };
107 {
108  // Distinguish 'Quit' from 'Regular' end_level_exceptions to solve the following problem:
109  // If a player quits the game during an event after an [endlevel] occurs, the game won't
110  // Quit but continue with the [endlevel] instead.
111  throw quit_game_exception();
112 }
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.
const char * what() const noexcept
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
const char * what() const noexcept
void throw_quit_game_exception()
#define IMPLEMENT_LUA_JAILBREAK_EXCEPTION(type)
Helper macro for classes deriving from lua_jailbreak_exception.
Additional information on the game outcome which can be provided by WML.
void read(const config &cfg)
bool prescenario_save
Should a prescenario be created the next game?
void write(config &cfg) const
bool replay_save
Should a replay save be made?
bool proceed_to_next_level
whether to proceed to the next scenario, equals is_victory in sp.
config to_config() const
std::string test_result
result to use if this is a unit test
config to_config_full() const
Includes the transient data.
The non-persistent part of end_level_data.
bool carryover_report
Should a summary of the scenario outcome be displayed?
bool linger_mode
Should linger mode be invoked?
bool reveal_map
Should we reveal map when game is ended? (Multiplayer only)
void write(config &cfg) const