The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
saved_game.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #ifndef SAVED_GAME_HPP_INCLUDED
15 #define SAVED_GAME_HPP_INCLUDED
16 
17 #include "config.hpp"
18 #include "game_classification.hpp"
19 #include "mp_game_settings.hpp"
20 #include "replay_recorder_base.hpp"
21 
22 class config_writer;
23 
24 
26 {
28  {
29  /// There is no scenario stating pos data (start-of-scenario).
31  /// We have a [snapshot] (mid-game-savefile).
33  /// We have a [scenario] (start-of-scenario) savefile.
35  /// We failed to get a starting pos in expand_scenario.
37  };
38 public:
39  saved_game();
40  saved_game(const saved_game& state);
41  explicit saved_game(config cfg);
43 
45  void swap(saved_game& other);
46  /// destroys the passed config.
47  void set_data(config& cfg);
48  /// writes the config information into a stream (file)
49  void write_config(config_writer& out) const;
50  void write_general_info(config_writer& out) const;
51  void write_carryover(config_writer& out) const;
52  void write_starting_pos(config_writer& out) const;
53  config to_config() const;
56 
57  /** Multiplayer parameters for this game */
59  const mp_game_settings& mp_settings() const { return mp_settings_; }
60 
61  void set_carryover_sides_start(config carryover_sides_start);
62 
63  /// copies the content of a [scenario] with the correct id attribute from the game config into this object.
64  /// reloads the game config from disk if necessary.
65  void expand_scenario();
66  /// merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides]
67  /// Removes [carryover_sides_start] afterwards
68  void expand_carryover();
69  /// adds [event]s from [era] and [modification] into this scenario
70  /// does NOT expand [option]s because variables are persitent anyway to we don't need it
71  /// should be called after expand_scenario() but before expand_carryover()
72  void expand_mp_events();
73  /// helper for expand_mp_events();
74  void load_mod(const std::string& type, const std::string& id);
75  /// adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next level.
76  /// Note that since [variabels] are persistent we only use this once at the beginning
77  /// of a campaign but calling it multiple times is no harm eigher
78  void expand_mp_options();
79  /// takes care of generate_map=, generate_scenario=, map= attributes
80  /// This should be called before expanding carryover or mp_events because this might completely replace starting_pos_.
82  bool valid();
83  /// @return the snapshot in the savefile (get_starting_pos)
84  config& set_snapshot(config snapshot);
85  void set_scenario(config scenario);
86  void remove_snapshot();
87 
89  {
91  }
92  /// converts a normal savegame form the end of a scenaio to a start-of-scenario savefile for the next scenaio,
93  /// The saved_game must contain a [snapshot] made during the linger mode of the last scenaio.
94  void convert_to_start_save();
95  /// sets the random seed if that didn't already happen.
96  void set_random_seed();
97  /// @return the starting pos for replays. Usualy this is [replay_start] but it can also be a [scenario] if no [replay_start] is present
99  /// @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).
101  /// @return the config from which the game will be started. (this is [scenario] or [snapshot] in the savefile)
103  const config& get_starting_pos() const { return starting_pos_; }
105  const config& replay_start() const { return replay_start_; }
106 
107  bool not_corrupt() const;
108  /** sets classification().label to the correct value. */
109  void update_label();
110 
111  void cancel_orders();
112  /* removes network_ai and network controller types*/
113  void unify_controllers();
114  /** does some post loading stuff must be used before passing the data to connect_engine */
115  void set_defaults();
117  const replay_recorder_base& get_replay() const { return replay_data_; }
118 
119 private:
121  /**
122  depends on has_carryover_expanded_:
123  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).
124  if false: The carryover information for all sides from the previous scenario.
125  */
127  /** snapshot made before the start event. To be used as a starting pos for replays */
129  /** some general information of the game that doesn't change during the game */
132 
134  /**
135  The starting pos where the (non replay) game will be started from.
136  This can eigher be a [scenario] for a fresh game or a [snapshot] if this is a reloaded game
137  */
139 
141 };
142 
143 
144 #endif
config replay_start_
snapshot made before the start event.
Definition: saved_game.hpp:128
void write_starting_pos(config_writer &out) const
Definition: saved_game.cpp:143
void expand_scenario()
copies the content of a [scenario] with the correct id attribute from the game config into this objec...
Definition: saved_game.cpp:204
config to_config() const
Definition: saved_game.cpp:510
config & replay_start()
Definition: saved_game.hpp:104
void set_scenario(config scenario)
Definition: saved_game.cpp:458
void set_defaults()
does some post loading stuff must be used before passing the data to connect_engine ...
Definition: saved_game.cpp:167
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
We failed to get a starting pos in expand_scenario.
Definition: saved_game.hpp:36
There is no scenario stating pos data (start-of-scenario).
Definition: saved_game.hpp:30
replay_recorder_base & get_replay()
Definition: saved_game.hpp:116
bool not_corrupt() const
Definition: saved_game.cpp:553
const config & replay_start() const
Definition: saved_game.hpp:105
void unify_controllers()
Definition: saved_game.cpp:583
STARTING_POS_TYPE starting_pos_type_
Definition: saved_game.hpp:133
void expand_random_scenario()
takes care of generate_map=, generate_scenario=, map= attributes This should be called before expandi...
Definition: saved_game.cpp:387
const mp_game_settings & mp_settings() const
Definition: saved_game.hpp:59
bool is_mid_game_save()
Definition: saved_game.hpp:88
config & set_snapshot(config snapshot)
Definition: saved_game.cpp:451
void write_general_info(config_writer &out) const
Definition: saved_game.cpp:161
Definitions for the interface to Wesnoth Markup Language (WML).
void write_config(config_writer &out) const
writes the config information into a stream (file)
Definition: saved_game.cpp:129
void load_mod(const std::string &type, const std::string &id)
helper for expand_mp_events();
Definition: saved_game.cpp:281
void set_random_seed()
sets the random seed if that didn't already happen.
Definition: saved_game.cpp:119
void expand_mp_options()
adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next...
Definition: saved_game.cpp:356
Class for writing a config out to a file in pieces.
void update_label()
sets classification().label to the correct value.
Definition: saved_game.cpp:558
We have a [snapshot] (mid-game-savefile).
Definition: saved_game.hpp:32
config carryover_
depends on has_carryover_expanded_: if true: The carryover information for all sides from the previou...
Definition: saved_game.hpp:126
config & get_starting_pos()
Definition: saved_game.cpp:472
void set_data(config &cfg)
destroys the passed config.
Definition: saved_game.cpp:612
game_classification classification_
some general information of the game that doesn't change during the game
Definition: saved_game.hpp:130
mp_game_settings mp_settings_
Definition: saved_game.hpp:131
config starting_pos_
The starting pos where the (non replay) game will be started from.
Definition: saved_game.hpp:138
std::string get_scenario_id()
Definition: saved_game.cpp:533
void expand_mp_events()
adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because vari...
Definition: saved_game.cpp:321
void expand_carryover()
merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides] Removes [car...
Definition: saved_game.cpp:428
saved_game & operator=(saved_game other)
Definition: saved_game.cpp:594
const config & get_starting_pos() const
Definition: saved_game.hpp:103
void swap(saved_game &other)
Definition: saved_game.cpp:600
void cancel_orders()
Definition: saved_game.cpp:567
replay_recorder_base replay_data_
Definition: saved_game.hpp:140
game_classification & classification()
Definition: saved_game.hpp:54
void set_carryover_sides_start(config carryover_sides_start)
Definition: saved_game.cpp:113
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...
Definition: saved_game.cpp:497
const replay_recorder_base & get_replay() const
Definition: saved_game.hpp:117
void remove_snapshot()
Definition: saved_game.cpp:466
bool valid()
Definition: saved_game.cpp:446
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void write_carryover(config_writer &out) const
Definition: saved_game.cpp:154
bool has_carryover_expanded_
Definition: saved_game.hpp:120
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
Definition: saved_game.hpp:58
We have a [scenario] (start-of-scenario) savefile.
Definition: saved_game.hpp:34
const game_classification & classification() const
Definition: saved_game.hpp:55
GLsizei const GLcharARB ** string
Definition: glew.h:4503
const config & get_replay_starting_pos()
Definition: saved_game.cpp:478