The Battle for Wesnoth  1.17.23+dev
carryover.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2023
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);
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:
67  , variables_()
68  , rng_()
69  , wml_menu_items_()
70  , next_scenario_()
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 };
double t
Definition: astarsearch.cpp:65
void add_side(const config &cfg)
Definition: carryover.cpp:143
const config to_config()
Definition: carryover.cpp:224
std::string next_scenario_
the scenario coming next (for campaigns)
Definition: carryover.hpp:106
std::vector< carryover > & get_all_sides()
Definition: carryover.cpp:139
void add_side(const team &t, const int gold, const bool add)
config variables_
Definition: carryover.hpp:103
randomness::mt_rng & rng()
Definition: carryover.hpp:94
void merge_old_carryover(const carryover_info &old_carryover)
Definition: carryover.cpp:255
std::vector< carryover > carryover_sides_
Definition: carryover.hpp:102
void transfer_to(config &level)
Definition: carryover.cpp:195
void transfer_all_to(config &side_cfg)
Definition: carryover.cpp:169
const randomness::mt_rng & rng() const
Definition: carryover.hpp:93
void set_variables(const config &vars)
Definition: carryover.hpp:90
int next_underlying_unit_id_
Definition: carryover.hpp:107
const config & get_variables() const
Definition: carryover.hpp:91
randomness::mt_rng rng_
Definition: carryover.hpp:104
const std::string & next_scenario() const
Definition: carryover.hpp:96
carryover * get_side(const std::string &save_id)
Definition: carryover.cpp:245
std::vector< config > wml_menu_items_
Definition: carryover.hpp:105
void remove_side(const std::string &id)
Definition: carryover.cpp:147
std::string save_id_
Definition: carryover.hpp:56
void transfer_all_gold_to(config &side_cfg)
Definition: carryover.cpp:46
config variables_
Definition: carryover.hpp:57
std::vector< config > recall_list_
Definition: carryover.hpp:55
std::string current_player_
Definition: carryover.hpp:49
const std::string & get_save_id() const
Definition: carryover.hpp:41
bool add_
Definition: carryover.hpp:48
void transfer_all_recruits_to(config &side_cfg)
Definition: carryover.cpp:66
void transfer_all_recalls_to(config &side_cfg)
Definition: carryover.cpp:72
std::string get_recruits(bool erase=false)
Definition: carryover.cpp:79
const std::string to_string()
Definition: carryover.cpp:89
void to_config(config &cfg)
Definition: carryover.cpp:98
std::set< std::string > previous_recruits_
Definition: carryover.hpp:51
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:76
void erase(const std::string &key)
Definition: general.cpp:205