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