The Battle for Wesnoth  1.15.1+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 )
39 
40 /**
41  * Exception used to escape form the ai or ui code to playsingle_controller::play_side.
42  * Never thrown during replays.
43  */
44 class return_to_play_side_exception : public lua_jailbreak_exception, public std::exception
45 {
46 public:
47 
48  return_to_play_side_exception()
49  : lua_jailbreak_exception()
50  , std::exception()
51  {
52  }
53  const char * what() const noexcept { return "return_to_play_side_exception"; }
54 private:
55 
56  IMPLEMENT_LUA_JAILBREAK_EXCEPTION(return_to_play_side_exception)
57 };
58 
61  , public std::exception
62 {
63 public:
64 
67  , std::exception()
68  {
69  }
70  const char * what() const noexcept { return "quit_game_exception"; }
71 private:
73 };
74 
75 /**
76  * The non-persistent part of end_level_data
77  */
79 
81 
82  bool carryover_report; /**< Should a summary of the scenario outcome be displayed? */
83  bool linger_mode; /**< Should linger mode be invoked? */
84  bool reveal_map; /**< Should we reveal map when game is ended? (Multiplayer only) */
85 
86  void write(config& cfg) const;
87 };
88 
89 /**
90  * Additional information on the game outcome which can be provided by WML.
91  */
93 {
95 
96 
97  bool prescenario_save; /**< Should a prescenario be created the next game? */
98  bool replay_save; /**< Should a replay save be made? */
99  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. > */
102  void write(config& cfg) const;
103 
104  void read(const config& cfg);
105 
106  config to_config() const;
107  config to_config_full() const; ///< Includes the transient data
108 };
110 {
111  // Distinguish 'Quit' from 'Regular' end_level_exceptions to solve the following problem:
112  // If a player quits the game during an event after an [endlevel] occurs, the game won't
113  // Quit but continue with the [endlevel] instead.
114  throw quit_game_exception();
115 }
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?
void read(config &cfg, std::istream &in, abstract_validator *validator)
Definition: parser.cpp:625
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(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:909
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
Defines the MAKE_ENUM macro.
Base class for exceptions that want to be thrown &#39;through&#39; lua.