The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
saved_game.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 - 2025
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
15#pragma once
16
17#include "config.hpp"
19#include "mp_game_settings.hpp"
21#include "statistics_record.hpp"
22
23class config_writer;
24
26{
27 enum class starting_point {
28 /** There is no scenario stating pos data (start-of-scenario). */
29 NONE,
30 /** We have a [snapshot] (mid-game-savefile). */
32 /** We have a [scenario] (start-of-scenario) savefile. */
34 /** We failed to get a starting pos in expand_scenario. */
36 };
37
38public:
39 saved_game();
40 saved_game(const saved_game& state);
41 explicit saved_game(config cfg);
43
44 saved_game& operator=(const saved_game& other) = delete;
46 void swap(saved_game& other) noexcept;
47 void set_data(config&& cfg);
48 void clear();
49 /** writes the config information into a stream (file) */
50 void write_config(config_writer& out) const;
51 void write_general_info(config_writer& out) const;
52 void write_carryover(config_writer& out) const;
53 void write_starting_point(config_writer& out) const;
54 config to_config() const;
57
58 /** Multiplayer parameters for this game */
60 const mp_game_settings& mp_settings() const { return mp_settings_; }
61
62 void set_carryover_sides_start(config carryover_sides_start);
63
64 /**
65 * copies the content of a [scenario] with the correct id attribute from the game config into this object.
66 * reloads the game config from disk if necessary.
67 */
68 void expand_scenario();
69 /**
70 * merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides]
71 * Removes [carryover_sides_start] afterwards
72 */
73 void expand_carryover();
74 /**
75 * adds [event]s from [era] and [modification] into this scenario
76 * does NOT expand [option]s because variables are persitent anyway to we don't need it
77 * should be called after expand_scenario() but before expand_carryover()
78 */
79 void expand_mp_events();
80 /** helper for expand_mp_events(); */
81 void load_non_scenario(const std::string& type, const std::string& id, std::size_t pos);
82 /**
83 * adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next level.
84 * Note that since [variabels] are persistent we only use this once at the beginning
85 * of a campaign but calling it multiple times is no harm eigher
86 */
87 void expand_mp_options();
88 /**
89 * takes care of generate_map=, generate_scenario=, map= attributes
90 * This should be called before expanding carryover or mp_events because this might completely replace starting_point_.
91 */
93 /** copies attributes & tags from the 'outer' [scenario] to the scenario that is generated by scenario_generation= */
94 static void post_scenario_generation(const config& old_scenario, config& generated_scenario);
95 /** reads scenario["map_file"] */
96 static void expand_map_file(config& scenario);
97 /** Add addon_id information if needed. */
99 bool valid() const;
100 /** @return the snapshot in the savefile (get_starting_point) */
101 config& set_snapshot(config snapshot);
102 void set_scenario(config scenario);
103 void remove_snapshot();
104
105 bool is_mid_game_save() const
106 {
108 }
110 {
112 }
113 /**
114 * converts a normal savegame form the end of a scenaio to a start-of-scenario savefile for the next scenaio,
115 * The saved_game must contain a [snapshot] made during the linger mode of the last scenaio.
116 */
118 /** sets the random seed if that didn't already happen. */
119 void set_random_seed();
120 /** @return the starting pos for replays. Usually this is [replay_start] but it can also be a [scenario] if no [replay_start] is present */
122 /** @return the id of the currently played scenario or the id of the next scenario if this is a between-scenaios-save (also called start-of-scenario-save). */
123 std::string get_scenario_id() const;
124 /** @return the config from which the game will be started. (this is [scenario] or [snapshot] in the savefile) */
126 const config& get_starting_point() const { return starting_point_; }
128 const config& replay_start() const { return replay_start_; }
129
130 bool not_corrupt() const;
131 /** sets classification().label to the correct value. */
132 void update_label();
133
134 void cancel_orders();
135 /* removes network_ai and network controller types*/
136 void unify_controllers();
137 /** does some post loading stuff must be used before passing the data to connect_engine */
138 void set_defaults();
141
144 /** Whether to play [story] tags */
145 bool skip_story() const { return skip_story_; }
147
148private:
150 /**
151 depends on has_carryover_expanded_:
152 if true: The carryover information for all sides from the previous scenario that aren't used in this scenario (to be carried over to the next scenario).
153 if false: The carryover information for all sides from the previous scenario.
154 */
156 /** snapshot made before the start event. To be used as a starting pos for replays */
158 /** some general information of the game that doesn't change during the game */
161
163 /**
164 The starting pos where the (non replay) game will be started from.
165 This can eigher be a [scenario] for a fresh game or a [snapshot] if this is a reloaded game
166 */
168
170
172
174};
175
176/** Implement non-member swap function for std::swap (calls @ref saved_game::swap). */
177void swap(saved_game& lhs, saved_game& rhs) noexcept;
Class for writing a config out to a file in pieces.
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
bool not_corrupt() const
void set_data(config &&cfg)
config & replay_start()
void set_skip_story(bool skip_story)
void load_non_scenario(const std::string &type, const std::string &id, std::size_t pos)
helper for expand_mp_events();
bool is_mid_game_save() const
bool is_start_of_scenario() const
void set_random_seed()
sets the random seed if that didn't already happen.
const game_classification & classification() const
config replay_start_
snapshot made before the start event.
replay_recorder_base & get_replay()
void write_config(config_writer &out) const
writes the config information into a stream (file)
void expand_scenario()
copies the content of a [scenario] with the correct id attribute from the game config into this objec...
void expand_mp_options()
adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next...
void unify_controllers()
void set_carryover_sides_start(config carryover_sides_start)
config to_config() const
starting_point starting_point_type_
std::string get_scenario_id() const
static void post_scenario_generation(const config &old_scenario, config &generated_scenario)
copies attributes & tags from the 'outer' [scenario] to the scenario that is generated by scenario_ge...
replay_recorder_base replay_data_
const mp_game_settings & mp_settings() const
const config & get_starting_point() const
void update_label()
sets classification().label to the correct value.
game_classification & classification()
statistics_record::campaign_stats_t statistics_
const replay_recorder_base & get_replay() const
void set_scenario(config scenario)
bool has_carryover_expanded_
static void expand_map_file(config &scenario)
reads scenario["map_file"]
void remove_snapshot()
config & get_starting_point()
config starting_point_
The starting pos where the (non replay) game will be started from.
const config & get_replay_starting_point()
void check_require_scenario()
Add addon_id information if needed.
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
const statistics_record::campaign_stats_t & statistics() const
void write_starting_point(config_writer &out) const
void expand_mp_events()
adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because vari...
config carryover_
depends on has_carryover_expanded_: if true: The carryover information for all sides from the previou...
void expand_random_scenario()
takes care of generate_map=, generate_scenario=, map= attributes This should be called before expandi...
mp_game_settings mp_settings_
void expand_carryover()
merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides] Removes [car...
@ SNAPSHOT
We have a [snapshot] (mid-game-savefile).
@ SCENARIO
We have a [scenario] (start-of-scenario) savefile.
@ NONE
There is no scenario stating pos data (start-of-scenario).
@ INVALID
We failed to get a starting pos in expand_scenario.
void cancel_orders()
void convert_to_start_save()
converts a normal savegame form the end of a scenaio to a start-of-scenario savefile for the next sce...
bool valid() const
void set_defaults()
does some post loading stuff must be used before passing the data to connect_engine
void write_general_info(config_writer &out) const
game_classification classification_
some general information of the game that doesn't change during the game
const config & replay_start() const
config & set_snapshot(config snapshot)
void swap(saved_game &other) noexcept
void write_carryover(config_writer &out) const
statistics_record::campaign_stats_t & statistics()
bool skip_story() const
Whether to play [story] tags.
saved_game & operator=(const saved_game &other)=delete
Definitions for the interface to Wesnoth Markup Language (WML).
const config * cfg
void swap(saved_game &lhs, saved_game &rhs) noexcept
Implement non-member swap function for std::swap (calls saved_game::swap).