The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
carryover.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 - 2025
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
17class team;
18#include <vector>
19#include <string>
20#include <set>
21
22#include "config.hpp"
23#include "mt_rng.hpp"
24
26{
27public:
29 : add_ ()
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);
46private:
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{
63public:
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_; }
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);
100private:
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
void add_side(const config &cfg)
const std::string & next_scenario() const
Definition carryover.hpp:95
const randomness::mt_rng & rng() const
Definition carryover.hpp:92
const config to_config()
std::string next_scenario_
the scenario coming next (for campaigns)
randomness::mt_rng & rng()
Definition carryover.hpp:93
std::vector< carryover > & get_all_sides()
void add_side(const team &t, const int gold, const bool add)
void merge_old_carryover(const carryover_info &old_carryover)
std::vector< carryover > carryover_sides_
void transfer_to(config &level)
void transfer_all_to(config &side_cfg)
void set_variables(const config &vars)
Definition carryover.hpp:89
int next_underlying_unit_id_
randomness::mt_rng rng_
const config & get_variables() const
Definition carryover.hpp:90
carryover * get_side(const std::string &save_id)
std::vector< config > wml_menu_items_
void remove_side(const std::string &id)
std::string save_id_
Definition carryover.hpp:55
void transfer_all_gold_to(config &side_cfg)
Definition carryover.cpp:46
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
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:50
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
This class stores all the data for a single 'side' (in game nomenclature).
Definition team.hpp:74
Definitions for the interface to Wesnoth Markup Language (WML).
const config * cfg