The Battle for Wesnoth  1.15.6+dev
game_end_exceptions.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2018 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
3  wesnoth playturn Copyright (C) 2003 by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Contains the exception interfaces used to signal
19  * completion of a scenario, campaign or turn.
20  */
21 
22 #pragma once
23 
25 
26 #include "utils/make_enum.hpp"
27 
28 #include <string>
29 #include <exception>
30 
31 class config;
32 
33 MAKE_ENUM(LEVEL_RESULT,
34  (VICTORY, "victory")
35  (DEFEAT, "defeat")
36  (QUIT, "quit")
37  (OBSERVER_END, "observer_end")
38  (TEST_NOT_SET, "result_not_set")
39  (TEST_PASS, "pass")
40  (TEST_FAIL, "fail")
41  (TEST_INVALID, "test_result_value_invalid")
42 )
43 
44 /**
45  * Exception used to escape form the ai or ui code to playsingle_controller::play_side.
46  * Never thrown during replays.
47  */
48 class return_to_play_side_exception : public lua_jailbreak_exception, public std::exception
49 {
50 public:
51 
52  return_to_play_side_exception()
53  : lua_jailbreak_exception()
54  , std::exception()
55  {
56  }
57  const char * what() const noexcept { return "return_to_play_side_exception"; }
58 private:
59 
60  IMPLEMENT_LUA_JAILBREAK_EXCEPTION(return_to_play_side_exception)
61 };
62 
65  , public std::exception
66 {
67 public:
68 
71  , std::exception()
72  {
73  }
74  const char * what() const noexcept { return "quit_game_exception"; }
75 private:
77 };
78 
79 /**
80  * The non-persistent part of end_level_data
81  */
83 
85 
86  bool carryover_report; /**< Should a summary of the scenario outcome be displayed? */
87  bool linger_mode; /**< Should linger mode be invoked? */
88  bool reveal_map; /**< Should we reveal map when game is ended? (Multiplayer only) */
89 
90  void write(config& cfg) const;
91 };
92 
93 /**
94  * Additional information on the game outcome which can be provided by WML.
95  */
97 {
99 
100 
101  bool prescenario_save; /**< Should a prescenario be created the next game? */
102  bool replay_save; /**< Should a replay save be made? */
103  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. > */
105  std::string test_result; /**< result to use if this is a unit test */
107  void write(config& cfg) const;
108 
109  void read(const config& cfg);
110 
111  config to_config() const;
112  config to_config_full() const; ///< Includes the transient data
113 };
115 {
116  // Distinguish 'Quit' from 'Regular' end_level_exceptions to solve the following problem:
117  // If a player quits the game during an event after an [endlevel] occurs, the game won't
118  // Quit but continue with the [endlevel] instead.
119  throw quit_game_exception();
120 }
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
#define IMPLEMENT_LUA_JAILBREAK_EXCEPTION(type)
Helper macro for classes deriving from lua_jailbreak_exception.
bool prescenario_save
Should a prescenario be created the next game?
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:762
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
const char * what() const noexcept
bool carryover_report
Should a summary of the scenario outcome be displayed?
value read(bind.buffer(), bind.length())
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(ALIGNMENT_FEMALE_VARIATION,(LAWFUL, N_("female^lawful"))(FEMALE_NEUTRAL, N_("female^neutral"))(CHAOTIC, N_("female^chaotic"))(LIMINAL, N_("female^liminal"))) std
Implementation detail of unit_type::alignment_description.
Definition: types.cpp:808
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
Defines the MAKE_ENUM macro.
Base class for exceptions that want to be thrown &#39;through&#39; lua.