The Battle for Wesnoth  1.15.1+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 #include <boost/ptr_container/ptr_vector.hpp>
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  /// Turns config from a loaded savegame into carryover_info
75  /// @param from_snapshot true if cfg is a [snapshot], false if cfg is [carryover_sides(_start)]
76  explicit carryover_info(const config& cfg, bool from_snapshot = false);
77 
78  carryover* get_side(const std::string& save_id);
79  std::vector<carryover>& get_all_sides();
80  void add_side(const config& cfg);
81  void add_side(const team& t, const int gold, const bool add);
82  void remove_side(const std::string& id);
83 
84  void transfer_all_to(config& side_cfg);
85 
86  void transfer_to(config& level);
87 
88  void set_variables(const config& vars) { variables_ = vars; }
89  const config& get_variables() const { return variables_; }
90 
91  const randomness::mt_rng& rng() const { return rng_; }
92  randomness::mt_rng& rng() { return rng_; }
93 
94  const std::string& next_scenario() const { return next_scenario_; }
95 
96  const config to_config();
97 
98  void merge_old_carryover(const carryover_info& old_carryover);
99 private:
100  std::vector<carryover> carryover_sides_;
103  boost::ptr_vector<config> wml_menu_items_;
104  std::string next_scenario_; /**< the scenario coming next (for campaigns) */
106 };
const config & get_variables() const
Definition: carryover.hpp:89
const std::string & get_save_id() const
Definition: carryover.hpp:42
randomness::mt_rng & rng()
Definition: carryover.hpp:92
boost::ptr_vector< config > wml_menu_items_
Definition: carryover.hpp:103
void transfer_all_recalls_to(config &side_cfg)
Definition: carryover.cpp:87
std::string save_id_
Definition: carryover.hpp:57
config variables_
Definition: carryover.hpp:101
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:105
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:91
std::vector< config > recall_list_
Definition: carryover.hpp:56
config variables_
Definition: carryover.hpp:58
void erase(const std::string &key)
Definition: general.cpp:220
void transfer_all_gold_to(config &side_cfg)
Definition: carryover.cpp:61
std::vector< carryover > carryover_sides_
Definition: carryover.hpp:100
std::string current_player_
Definition: carryover.hpp:50
std::string next_scenario_
the scenario coming next (for campaigns)
Definition: carryover.hpp:104
const std::string & next_scenario() const
Definition: carryover.hpp:94
const std::string to_string()
Definition: carryover.cpp:104
bool add_
Definition: carryover.hpp:49
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:102
void set_variables(const config &vars)
Definition: carryover.hpp:88
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:92