The Battle for Wesnoth  1.17.0-dev
game_end_exceptions.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2021
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 
26 
27 #include "utils/make_enum.hpp"
28 
29 #include <string>
30 #include <exception>
31 
32 class config;
33 
34 MAKE_ENUM(LEVEL_RESULT,
35  (VICTORY, "victory")
36  (DEFEAT, "defeat")
37  (QUIT, "quit")
38  (OBSERVER_END, "observer_end")
39  (TEST_NOT_SET, "result_not_set")
40  (TEST_PASS, "pass")
41  (TEST_FAIL, "fail")
42  (TEST_INVALID, "test_result_value_invalid")
43 );
44 
45 /**
46  * Exception used to escape form the ai or ui code to playsingle_controller::play_side.
47  * Never thrown during replays.
48  */
49 class return_to_play_side_exception : public lua_jailbreak_exception, public std::exception
50 {
51 public:
52 
55  , std::exception()
56  {
57  }
58  const char * what() const noexcept { return "return_to_play_side_exception"; }
59 private:
60 
62 };
63 
66  , public std::exception
67 {
68 public:
69 
72  , std::exception()
73  {
74  }
75  const char * what() const noexcept { return "quit_game_exception"; }
76 private:
78 };
79 
80 /**
81  * The non-persistent part of end_level_data
82  */
84 
86 
87  bool carryover_report; /**< Should a summary of the scenario outcome be displayed? */
88  bool linger_mode; /**< Should linger mode be invoked? */
89  bool reveal_map; /**< Should we reveal map when game is ended? (Multiplayer only) */
90 
91  void write(config& cfg) const;
92 };
93 
94 /**
95  * Additional information on the game outcome which can be provided by WML.
96  */
98 {
100 
101 
102  bool prescenario_save; /**< Should a prescenario be created the next game? */
103  bool replay_save; /**< Should a replay save be made? */
104  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. > */
106  std::string test_result; /**< result to use if this is a unit test */
108  void write(config& cfg) const;
109 
110  void read(const config& cfg);
111 
112  config to_config() const;
113  /** Includes the transient data */
114  config to_config_full() const;
115 };
117 {
118  // Distinguish 'Quit' from 'Regular' end_level_exceptions to solve the following problem:
119  // If a player quits the game during an event after an [endlevel] occurs, the game won't
120  // Quit but continue with the [endlevel] instead.
121  throw quit_game_exception();
122 }
#define IMPLEMENT_LUA_JAILBREAK_EXCEPTION(type)
Helper macro for classes deriving from lua_jailbreak_exception.
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
bool prescenario_save
Should a prescenario be created the next game?
const char * what() const noexcept
STL namespace.
bool replay_save
Should a replay save be made?
bool reveal_map
Should we reveal map when game is ended? (Multiplayer only)
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
Definition: parser.cpp:764
void throw_quit_game_exception()
bool linger_mode
Should linger mode be invoked?
std::string test_result
result to use if this is a unit test
void read(config &cfg, std::istream &in, abstract_validator *validator)
Definition: parser.cpp:627
const char * what() const noexcept
bool carryover_report
Should a summary of the scenario outcome be displayed?
The non-persistent part of end_level_data.
bool proceed_to_next_level
whether to proceed to the next scenario, equals is_victory in sp.
Additional information on the game outcome which can be provided by WML.
MAKE_ENUM(LEVEL_RESULT,(VICTORY, "victory")(DEFEAT, "defeat")(QUIT, "quit")(OBSERVER_END, "observer_end")(TEST_NOT_SET, "result_not_set")(TEST_PASS, "pass")(TEST_FAIL, "fail")(TEST_INVALID, "test_result_value_invalid"))
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
Defines the MAKE_ENUM macro.
Base class for exceptions that want to be thrown &#39;through&#39; lua.