The Battle for Wesnoth  1.19.1+dev
carryover.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2024
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 #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);
39 
40  const std::string& get_save_id() const{ return save_id_; }
41  void transfer_all_gold_to(config& side_cfg);
42  void transfer_all_recruits_to(config& side_cfg);
43  void transfer_all_recalls_to(config& side_cfg);
44  const std::string to_string();
45  void to_config(config& cfg);
46 private:
47  bool add_;
48  std::string current_player_;
49  int gold_;
50  std::set<std::string> previous_recruits_;
51  // NOTE: we store configs instead of units because units often assume or
52  // assert that various resources:: are available, which is not the
53  // case between scenarios.
54  std::vector<config> recall_list_;
55  std::string save_id_;
57 
58  std::string get_recruits(bool erase=false);
59 };
60 
62 {
63 public:
66  , variables_()
67  , rng_()
68  , wml_menu_items_()
69  , next_scenario_()
71  {}
72  /**
73  * Turns config from a loaded savegame into carryover_info
74  * @param cfg the config to use
75  * @param from_snapshot true if cfg is a [snapshot], false if cfg is [carryover_sides(_start)]
76  */
77  explicit carryover_info(const config& cfg, bool from_snapshot = false);
78 
79  carryover* get_side(const std::string& save_id);
80  std::vector<carryover>& get_all_sides();
81  void add_side(const config& cfg);
82  void add_side(const team& t, const int gold, const bool add);
83  void remove_side(const std::string& id);
84 
85  void transfer_all_to(config& side_cfg);
86 
87  void transfer_to(config& level);
88 
89  void set_variables(const config& vars) { variables_ = vars; }
90  const config& get_variables() const { return variables_; }
91 
92  const randomness::mt_rng& rng() const { return rng_; }
93  randomness::mt_rng& rng() { return rng_; }
94 
95  const std::string& next_scenario() const { return next_scenario_; }
96 
97  const config to_config();
98 
99  void merge_old_carryover(const carryover_info& old_carryover);
100 private:
101  std::vector<carryover> carryover_sides_;
104  std::vector<config> wml_menu_items_;
105  std::string next_scenario_; /**< the scenario coming next (for campaigns) */
107 };
double t
Definition: astarsearch.cpp:63
void add_side(const config &cfg)
Definition: carryover.cpp:142
const config to_config()
Definition: carryover.cpp:223
std::string next_scenario_
the scenario coming next (for campaigns)
Definition: carryover.hpp:105
std::vector< carryover > & get_all_sides()
Definition: carryover.cpp:138
void add_side(const team &t, const int gold, const bool add)
config variables_
Definition: carryover.hpp:102
randomness::mt_rng & rng()
Definition: carryover.hpp:93
void merge_old_carryover(const carryover_info &old_carryover)
Definition: carryover.cpp:254
std::vector< carryover > carryover_sides_
Definition: carryover.hpp:101
void transfer_to(config &level)
Definition: carryover.cpp:194
void transfer_all_to(config &side_cfg)
Definition: carryover.cpp:168
const randomness::mt_rng & rng() const
Definition: carryover.hpp:92
void set_variables(const config &vars)
Definition: carryover.hpp:89
int next_underlying_unit_id_
Definition: carryover.hpp:106
const config & get_variables() const
Definition: carryover.hpp:90
randomness::mt_rng rng_
Definition: carryover.hpp:103
const std::string & next_scenario() const
Definition: carryover.hpp:95
carryover * get_side(const std::string &save_id)
Definition: carryover.cpp:244
std::vector< config > wml_menu_items_
Definition: carryover.hpp:104
void remove_side(const std::string &id)
Definition: carryover.cpp:146
std::string save_id_
Definition: carryover.hpp:55
void transfer_all_gold_to(config &side_cfg)
Definition: carryover.cpp:45
config variables_
Definition: carryover.hpp:56
std::vector< config > recall_list_
Definition: carryover.hpp:54
std::string current_player_
Definition: carryover.hpp:48
const std::string & get_save_id() const
Definition: carryover.hpp:40
bool add_
Definition: carryover.hpp:47
void transfer_all_recruits_to(config &side_cfg)
Definition: carryover.cpp:65
void transfer_all_recalls_to(config &side_cfg)
Definition: carryover.cpp:71
std::string get_recruits(bool erase=false)
Definition: carryover.cpp:78
const std::string to_string()
Definition: carryover.cpp:88
void to_config(config &cfg)
Definition: carryover.cpp:97
std::set< std::string > previous_recruits_
Definition: carryover.hpp:50
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
std::string & erase(std::string &str, const std::size_t start, const std::size_t len)
Erases a portion of a UTF-8 string.
Definition: unicode.cpp:103