The Battle for Wesnoth  1.15.12+dev
carryover.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017-2018 by the Battle for Wesnoth Project https://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 #pragma once
15 
16 class team;
17 class config;
18 #include <vector>
19 #include <string>
20 #include <set>
21 
22 #include "config.hpp"
23 #include "mt_rng.hpp"
24 
25 class carryover
26 {
27 public:
29  : add_ ()
30  , current_player_()
31  , gold_()
33  , recall_list_()
34  , save_id_()
35  {}
36  // Turns config from a loaded savegame into carryover_info
37  explicit carryover(const config& side);
38  carryover(const team& t, const int gold, const bool add);
40 
41  const std::string& get_save_id() const{ return save_id_; }
42  void transfer_all_gold_to(config& side_cfg);
43  void transfer_all_recruits_to(config& side_cfg);
44  void transfer_all_recalls_to(config& side_cfg);
45  const std::string to_string();
46  void to_config(config& cfg);
47 private:
48  bool add_;
49  std::string current_player_;
50  int gold_;
51  std::set<std::string> previous_recruits_;
52  // NOTE: we store configs instead of units because units often assume or
53  // assert that various resources:: are available, which is not the
54  // case between scenarios.
55  std::vector<config> recall_list_;
56  std::string save_id_;
58 
59  std::string get_recruits(bool erase=false);
60 };
61 
63 {
64 public:
66  : carryover_sides_()
67  , variables_()
68  , rng_()
69  , wml_menu_items_()
70  , next_scenario_()
71  , next_underlying_unit_id_()
72  {}
73  /**
74  * Turns config from a loaded savegame into carryover_info
75  * @param cfg the config to use
76  * @param from_snapshot true if cfg is a [snapshot], false if cfg is [carryover_sides(_start)]
77  */
78  explicit carryover_info(const config& cfg, bool from_snapshot = false);
79 
80  carryover* get_side(const std::string& save_id);
81  std::vector<carryover>& get_all_sides();
82  void add_side(const config& cfg);
83  void add_side(const team& t, const int gold, const bool add);
84  void remove_side(const std::string& id);
85 
86  void transfer_all_to(config& side_cfg);
87 
88  void transfer_to(config& level);
89 
90  void set_variables(const config& vars) { variables_ = vars; }
91  const config& get_variables() const { return variables_; }
92 
93  const randomness::mt_rng& rng() const { return rng_; }
94  randomness::mt_rng& rng() { return rng_; }
95 
96  const std::string& next_scenario() const { return next_scenario_; }
97 
98  const config to_config();
99 
100  void merge_old_carryover(const carryover_info& old_carryover);
101 private:
102  std::vector<carryover> carryover_sides_;
105  std::vector<config> wml_menu_items_;
106  std::string next_scenario_; /**< the scenario coming next (for campaigns) */
108 };
const config & get_variables() const
Definition: carryover.hpp:91
const std::string & get_save_id() const
Definition: carryover.hpp:41
randomness::mt_rng & rng()
Definition: carryover.hpp:94
void transfer_all_recalls_to(config &side_cfg)
Definition: carryover.cpp:87
std::string save_id_
Definition: carryover.hpp:56
config variables_
Definition: carryover.hpp:103
Definitions for the interface to Wesnoth Markup Language (WML).
std::set< std::string > previous_recruits_
Definition: carryover.hpp:51
int next_underlying_unit_id_
Definition: carryover.hpp:107
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
const randomness::mt_rng & rng() const
Definition: carryover.hpp:93
std::vector< config > recall_list_
Definition: carryover.hpp:55
std::vector< config > wml_menu_items_
Definition: carryover.hpp:105
config variables_
Definition: carryover.hpp:57
void erase(const std::string &key)
Definition: general.cpp:218
void transfer_all_gold_to(config &side_cfg)
Definition: carryover.cpp:61
std::vector< carryover > carryover_sides_
Definition: carryover.hpp:102
std::string current_player_
Definition: carryover.hpp:49
std::string next_scenario_
the scenario coming next (for campaigns)
Definition: carryover.hpp:106
const std::string & next_scenario() const
Definition: carryover.hpp:96
const std::string to_string()
Definition: carryover.cpp:104
bool add_
Definition: carryover.hpp:48
std::string get_recruits(bool erase=false)
Definition: carryover.cpp:94
void transfer_all_recruits_to(config &side_cfg)
Definition: carryover.cpp:81
randomness::mt_rng rng_
Definition: carryover.hpp:104
void set_variables(const config &vars)
Definition: carryover.hpp:90
double t
Definition: astarsearch.cpp:64
void to_config(config &cfg)
Definition: carryover.cpp:113
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59