The Battle for Wesnoth  1.17.17+dev
saved_game.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 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 /**
16  * Some information about savefiles:
17  *
18  * A savefile can contain:
19  *
20  * - General information (toplevel attributes, [multiplayer])
21  * This is present in all savefiles
22  *
23  * - [statistics]
24  * This is present in all savefiles but it's not handled by playcampaign/play_controller/saved_game.
25  * It's handled by savegame.cpp
26  *
27  * - [snapshot]
28  * If a savegame was saved during a scenario this contains a snapshot of the game at the point when
29  * it was saved.
30  *
31  * - [carryover_sides_start]
32  * At start-of-scenario saves this contains data from the previous scenario that was preserved.
33  *
34  * - [carryover_sides]
35  * In savefile made during the game, this tag contains data from [carryover_sides_start] that was not
36  * used in the current scenario but should be saved for a next scenario
37  *
38  * - [replay_start]
39  * A snapshot made very early to replay the game from.
40  *
41  * - [replay]
42  * A record of game actions that was made between the creation of [replay_start] and [snapshot].
43  *
44  *
45  * The following types of savegames are known:
46  *
47  * - Start of scenario savefiles
48  * These files only contain general information, statistics, and [carryover_sides_start]. When these
49  * saves are loaded, the scenario data is loaded form the game config using the next_scenario attribute
50  * from [carryover_sides_start].
51  *
52  * - Expanded Start of scenario savefiles
53  * Similar to normal Start-of-scenario savefiles, but the also contain a [scenario] that contains the
54  * scenario data. This type is only used internally and usually doesn't get written to the disk.
55  *
56  * - In-game savefile
57  * These files contain general information, statistics, [snapshot], [replay], [replay_start], [snapshot],
58  * and [carryover_sides]. These files don't contain a [carryover_sides_start] because both starting points
59  * ([replay_start] and [snapshot]) were made after [carryover_sides_start] was merged into the scenario.
60  *
61  * - Replay savefiles
62  * Like a in-game save made during linger mode, but without the [snapshot].
63  */
64 
65 #include "saved_game.hpp"
66 
67 #include "carryover.hpp"
68 #include "config.hpp"
69 #include "cursor.hpp"
70 #include "formula/string_utils.hpp"
71 #include "game_config_manager.hpp"
73 #include "log.hpp"
74 #include "random.hpp"
76 #include "side_controller.hpp"
77 #include "statistics.hpp"
78 #include "variable.hpp" // for config_variable_set
79 #include "variable_info.hpp"
80 
81 #include <cassert>
82 #include <iomanip>
83 
84 static lg::log_domain log_engine("engine");
85 #define ERR_NG LOG_STREAM(err, log_engine)
86 #define WRN_NG LOG_STREAM(warn, log_engine)
87 #define LOG_NG LOG_STREAM(info, log_engine)
88 #define DBG_NG LOG_STREAM(debug, log_engine)
89 
90 namespace
91 {
92 bool variable_to_bool(const config& vars, const std::string& expression)
93 {
94  std::string res = utils::interpolate_variables_into_string(expression, config_variable_set(vars));
95  return res == "true" || res == "yes" || res == "1";
96 }
97 
98 // helper objects for saved_game::expand_mp_events()
99 struct modevents_entry
100 {
101  modevents_entry(const std::string& _type, const std::string& _id)
102  : type(_type)
103  , id(_id)
104  {
105  }
106 
107  std::string type;
108  std::string id;
109 };
110 
111 bool is_illegal_file_char(char c)
112 {
113  return c == '/' || c == '\\' || c == ':' || (c >= 0x00 && c < 0x20)
114 #ifdef _WIN32
115  || c == '?' || c == '|' || c == '<' || c == '>' || c == '*' || c == '"'
116 #endif
117  ;
118 }
119 
120 } // end anon namespace
121 
123  : has_carryover_expanded_(false)
124  , carryover_(carryover_info().to_config())
125  , replay_start_()
126  , classification_()
127  , mp_settings_()
128  , starting_point_type_(starting_point::NONE)
129  , starting_point_()
130  , replay_data_()
131  , statistics_()
132  , skip_story_(false)
133 {
134 }
135 
137  : has_carryover_expanded_(false)
138  , carryover_()
139  , replay_start_()
140  , classification_(cfg)
141  , mp_settings_()
142  , starting_point_type_(starting_point::NONE)
143  , starting_point_()
144  , replay_data_()
145  , statistics_()
146  , skip_story_(false)
147 {
148  set_data(cfg);
149 }
150 
152  : has_carryover_expanded_(state.has_carryover_expanded_)
153  , carryover_(state.carryover_)
154  , replay_start_(state.replay_start_)
155  , classification_(state.classification_)
156  , mp_settings_(state.mp_settings_)
157  , starting_point_type_(state.starting_point_type_)
158  , starting_point_(state.starting_point_)
159  , replay_data_(state.replay_data_)
160  , statistics_(state.statistics_)
161  , skip_story_(state.skip_story_)
162 {
163 }
164 
166 {
167  carryover_.swap(carryover_sides_start);
168  has_carryover_expanded_ = false;
169 }
170 
172 {
173  if(has_carryover_expanded_ || !carryover_["random_seed"].empty()) {
174  return;
175  }
176 
177  std::stringstream stream;
178  stream << std::setfill('0') << std::setw(8) << std::hex << randomness::generator->get_random_int(0, INT_MAX);
179  carryover_["random_seed"] = stream.str();
180  carryover_["random_calls"] = 0;
181 }
182 
184 {
185  write_general_info(out);
187 
188  if(!replay_start_.empty()) {
189  out.write_child("replay_start", replay_start_);
190  }
191 
192  out.open_child("replay");
193  replay_data_.write(out);
194  out.close_child("replay");
195  write_carryover(out);
196 }
197 
199 {
201  out.write_child("snapshot", starting_point_);
203  out.write_child("scenario", starting_point_);
204  }
205 }
206 
208 {
209  assert(not_corrupt());
210  out.write_child(has_carryover_expanded_ ? "carryover_sides" : "carryover_sides_start", carryover_);
211 }
212 
214 {
216  out.write_child("multiplayer", mp_settings_.to_config());
217  out.open_child("statistics");
218  statistics().write(out);
219  out.close_child("statistics");
220 }
221 
223 {
224  const bool is_loaded_game = starting_point_type_ != starting_point::SCENARIO;
225  const bool is_multiplayer_tag = classification().get_tagname() == "multiplayer";
227 
228  static const std::vector<std::string> team_defaults {
229  "carryover_percentage",
230  "carryover_add",
231  };
232 
233  if(auto campaign = game_config.find_child("campaign", "id", classification_.campaign)) {
234  bool require_campaign = campaign["require_campaign"].to_bool(true);
235  starting_point_["require_scenario"] = require_campaign;
236  }
237 
238  for(config& side : starting_point_.child_range("side")) {
239  // Set save_id default value directly after loading to its default to prevent different default behaviour in
240  // mp_connect code and sp code.
241 
242  if(side["no_leader"].to_bool()) {
243  side["leader_lock"] = true;
244  side.remove_attribute("type");
245  }
246 
247  if(side["save_id"].empty()) {
248  side["save_id"] = side["id"];
249  }
250  if(side["save_id"].empty()) {
251  side["save_id"] = side.child_or_empty("leader")["id"];
252  }
253 
254  if(!is_multiplayer_tag) {
255  if(side["name"].blank()) {
256  side["name"] = side.child_or_empty("leader")["name"];
257  }
258  if(side["side_name"].blank()) {
259  side["side_name"] = side["name"];
260  }
261  }
262 
263  if(!is_loaded_game && !side["current_player"].empty()) {
264  ERR_NG << "Removed invalid 'current_player' attribute from [side] while loading a scenario. Consider using "
265  "'side_name' instead";
266 
267  side["current_player"] = config::attribute_value();
268  }
269 
270  // Set some team specific values to their defaults specified in scenario
271  for(const std::string& att_name : team_defaults) {
272  const config::attribute_value* scenario_value = starting_point_.get(att_name);
273  config::attribute_value& team_value = side[att_name];
274 
275  if(scenario_value && team_value.empty()) {
276  team_value = *scenario_value;
277  }
278  }
279  }
280 }
281 
283 {
286 
288  auto scenario =
289  game_config.find_child(classification().get_tagname(), "id", carryover_["next_scenario"]);
290 
291  if(scenario) {
293  starting_point_ = *scenario;
294 
295  // A hash has to be generated using an unmodified scenario data.
296  mp_settings_.hash = scenario->hash();
297 
299 
300  update_label();
301  set_defaults();
302  } else {
303  ERR_NG << "Couldn't find [" << classification().get_tagname() << "] with id=" << carryover_["next_scenario"];
306  }
307  }
308 }
309 
311 {
312  const std::string version_default = starting_point_["addon_id"].empty() ? game_config::wesnoth_version.str() : "";
313  config scenario;
314  scenario["id"] = starting_point_["addon_id"].str("mainline");
315  scenario["name"] = starting_point_["addon_title"].str("mainline");
316  scenario["version"] = starting_point_["addon_version"].str(version_default);
317  scenario["min_version"] = starting_point_["addon_min_version"];
318  scenario["required"] = starting_point_["require_scenario"].to_bool(false);
319  config& content = scenario.add_child("content");
320  content["id"] = starting_point_["id"];
321  content["name"] = starting_point_["name"];
322  content["type"] = "scenario";
323 
325 }
326 
327 // "non scenario" at the time of writing this meaning any era, campaign, mods, or resources (see expand_mp_events() below).
328 void saved_game::load_non_scenario(const std::string& type, const std::string& id, size_t pos)
329 {
330  if(auto cfg = game_config_manager::get()->game_config().find_child(type, "id", id)) {
331  // Note the addon_id if this mod is required to play the game in mp.
332  std::string require_attr = "require_" + type;
333 
334  // By default, eras have "require_era = true", and mods have "require_modification = false".
335  // anything with no addon_id is from mainline, and therefore isn't required in the sense that all players already have it
336  const bool require_default = cfg["addon_id"].empty() ? false : type == "era";
337  const std::string version_default = cfg["addon_id"].empty() ? game_config::wesnoth_version.str() : "";
338  config non_scenario;
339  // if there's no addon_id, then this isn't an add-on
340  non_scenario["id"] = cfg["addon_id"].str("mainline");
341  non_scenario["name"] = cfg["addon_title"].str("mainline");
342  non_scenario["version"] = cfg["addon_version"].str(version_default);
343  non_scenario["min_version"] = cfg["addon_min_version"];
344  non_scenario["required"] = cfg[require_attr].to_bool(require_default);
345  config& content = non_scenario.add_child("content");
346  content["id"] = id;
347  content["name"] = cfg["addon_title"].str(cfg["name"].str(""));
348  content["type"] = type;
349 
351 
352  // Copy events
353  for(const config& modevent : cfg->child_range("event")) {
354  if(modevent["enable_if"].empty()
355  || variable_to_bool(carryover_.child_or_empty("variables"), modevent["enable_if"])
356  ) {
357  starting_point_.add_child_at_total("event", modevent, pos++);
358  }
359  }
360 
361  // Copy lua
362  for(const config& modlua : cfg->child_range("lua")) {
363  starting_point_.add_child_at_total("lua", modlua, pos++);
364  }
365 
366  // Copy modify_unit_type
367  for(const config& modlua : cfg->child_range("modify_unit_type")) {
368  starting_point_.add_child_at_total("modify_unit_type", modlua, pos++);
369  }
370 
371  // Copy load_resource
372  for(const config& load_resource : cfg->child_range("load_resource")) {
373  starting_point_.add_child_at_total("load_resource", load_resource, pos++);
374  }
375  } else {
376  // TODO: A user message instead?
377  ERR_NG << "Couldn't find [" << type << "] with id=" << id;
378  }
379 }
380 
381 // Gets the ids of the mp_era and modifications which were set to be active, then fetches these configs from the
382 // game_config and copies their [event] and [lua] to the starting_point_.
383 // At this time, also collect the addon_id attributes which appeared in them and put this list in the addon_ids
384 // attribute of the mp_settings.
386 {
387  expand_scenario();
388 
389  if(starting_point_type_ == starting_point::SCENARIO && !starting_point_["has_mod_events"].to_bool(false)) {
390  std::vector<modevents_entry> mods;
391  std::set<std::string> loaded_resources;
392 
393  std::transform(classification_.active_mods.begin(), classification_.active_mods.end(), std::back_inserter(mods),
394  [](const std::string& id) { return modevents_entry("modification", id); }
395  );
396 
397  // We don't want the error message below if there is no era (= if this is a sp game).
398  if(!classification_.era_id.empty()) {
399  mods.emplace_back("era", classification_.era_id);
400  }
401 
402  if(!classification_.campaign.empty()) {
403  mods.emplace_back("campaign", classification_.campaign);
404  }
405 
406  for(modevents_entry& mod : mods) {
408  }
409  mods.clear();
410 
411  while(starting_point_.has_child("load_resource")) {
412  assert(starting_point_.child_count("load_resource") > 0);
413  std::string id = starting_point_.mandatory_child("load_resource")["id"];
414  size_t pos = starting_point_.find_total_first_of("load_resource");
415  starting_point_.remove_child("load_resource", 0);
416  if(loaded_resources.find(id) == loaded_resources.end()) {
417  loaded_resources.insert(id);
418  load_non_scenario("resource", id, pos);
419  }
420  }
421  starting_point_["has_mod_events"] = true;
422  starting_point_["loaded_resources"] = utils::join(loaded_resources);
423  }
424 }
425 
427 {
429  std::vector<modevents_entry> mods;
430 
431  std::transform(classification_.active_mods.begin(), classification_.active_mods.end(), std::back_inserter(mods),
432  [](const std::string& id) { return modevents_entry("modification", id); }
433  );
434 
435  mods.emplace_back("era", classification_.era_id);
436  mods.emplace_back("multiplayer", get_scenario_id());
437  mods.emplace_back("campaign", classification().campaign);
438 
439  config& variables = carryover_.child_or_add("variables");
440 
441  for(modevents_entry& mod : mods) {
442  if(auto cfg = mp_settings().options.find_child(mod.type, "id", mod.id)) {
443  for(const config& option : cfg->child_range("option")) {
444  try {
445  variable_access_create(option["id"], variables).as_scalar() = option["value"];
446  } catch(const invalid_variablename_exception&) {
447  ERR_NG << "variable " << option["id"] << "cannot be set to " << option["value"];
448  }
449  }
450  } else {
451  LOG_NG << "Couldn't find [" << mod.type << "] with id=" << mod.id << " for [option]s";
452  }
453  }
454  }
455 }
456 
457 static void inherit_scenario(config& scenario, config& map_scenario)
458 {
459  config sides;
460  sides.splice_children(map_scenario, "side");
461  scenario.append_children(map_scenario);
462  scenario.inherit_attributes(map_scenario);
463  for(config& side_from : sides.child_range("side")) {
464  auto side_to = scenario.find_child("side", "side", side_from["side"]);
465  if(side_to) {
466  side_to->inherit_attributes(side_from);
467  side_to->append_children(side_from);
468  } else {
469  scenario.add_child("side", side_from);
470  }
471  }
472 }
473 
475 {
476  if(scenario["map_data"].empty() && !scenario["map_file"].empty()) {
477  std::string map_data = filesystem::read_map(scenario["map_file"]);
478  if(map_data.find("map_data") != std::string::npos) {
479  // we have a scenario, gnerated by the editor
480  config map_data_cfg;
481  read(map_data_cfg, map_data);
482  inherit_scenario(scenario, map_data_cfg);
483  } else {
484  // we have an plain map_data file
485  scenario["map_data"] = map_data;
486  }
487  }
488 }
489 
491 {
492  expand_scenario();
493 
495  // If the entire scenario should be randomly generated
496  if(!starting_point_["scenario_generation"].empty()) {
497  LOG_NG << "randomly generating scenario...";
498  const cursor::setter cursor_setter(cursor::WAIT);
499 
500  config scenario_new =
501  random_generate_scenario(starting_point_["scenario_generation"], starting_point_.mandatory_child("generator"), &carryover_.child_or_empty("variables"));
502 
504  starting_point_ = std::move(scenario_new);
505 
506  update_label();
507  set_defaults();
508  }
509 
510  // If no map_data is provided, try to load the specified file directly
512  // If the map should be randomly generated
513  // We don’t want that we accidentally to this twice so we check for starting_point_["map_data"].empty()
514  if(starting_point_["map_data"].empty() && !starting_point_["map_generation"].empty()) {
515  LOG_NG << "randomly generating map...";
516  const cursor::setter cursor_setter(cursor::WAIT);
517 
518  starting_point_["map_data"] =
519  random_generate_map(starting_point_["map_generation"], starting_point_.mandatory_child("generator"), &carryover_.child_or_empty("variables"));
520  }
521  }
522 }
523 
524 void saved_game::post_scenario_generation(const config& old_scenario, config& generated_scenario)
525 {
526  static const std::vector<std::string> attributes_to_copy {
527  "id",
528  "addon_id",
529  "addon_title",
530  "addon_version",
531  "addon_min_version",
532  "require_scenario",
533  };
534 
535  // TODO: should we add "description" to this list?
536  // TODO: in theory it is possible that whether the scenario is required depends on the generated scenario, so maybe remove require_scenario from this list.
537 
538  for(const auto& str : attributes_to_copy) {
539  generated_scenario[str] = old_scenario[str];
540  }
541 
542  // Preserve "story" from the scenario toplevel.
543  // Note that it does not delete [story] tags in generated_scenario, so you can still have your story
544  // dependent on the generated scenario.
545  for(const config& story : old_scenario.child_range("story")) {
546  generated_scenario.add_child("story", story);
547  }
548 }
549 
550 
552 {
553  expand_scenario();
555  carryover_info sides(carryover_);
556 
558  for(config& side_cfg : get_starting_point().child_range("side")) {
559  sides.transfer_all_to(side_cfg);
560  }
561 
562  carryover_ = sides.to_config();
565  }
566 }
567 
568 bool saved_game::valid() const
569 {
571 }
572 
574 {
576  starting_point_.swap(snapshot);
577 
578  return starting_point_;
579 }
580 
582 {
584  starting_point_.swap(scenario);
585 
586  has_carryover_expanded_ = false;
587 
588  update_label();
589 }
590 
592 {
595 }
596 
598 {
599  return starting_point_;
600 }
601 
603 {
604  if(!replay_start_.empty()) {
605  return replay_start_;
606  }
607 
609  // Try to load the scenario form game config or from [scenario] if there is no [replay_start]
610  expand_scenario();
612  }
613 
615  return starting_point_;
616  }
617 
618  throw config::error("No replay_start found");
619 }
620 
622 {
624 
625  carryover_info sides(starting_point_, true);
626 
628  sides.rng().rotate_random();
629 
630  carryover_ = sides.to_config();
631 
632  has_carryover_expanded_ = false;
633 
636 
637  remove_snapshot();
638 }
639 
641 {
642  // TODO: remove this code duplication with write_... functions.
644 
645  if(!replay_start_.empty()) {
646  r.add_child("replay_start", replay_start_);
647  }
648 
649  replay_data_.write(r.add_child("replay"));
650 
652  r.add_child("snapshot", starting_point_);
654  r.add_child("scenario", starting_point_);
655  }
656 
657  r.add_child(has_carryover_expanded_ ? "carryover_sides" : "carryover_sides_start", carryover_);
658  r.add_child("multiplayer", mp_settings_.to_config());
659  r.add_child("statistics", statistics_.to_config());
660 
661  return r;
662 }
663 
664 std::string saved_game::get_scenario_id() const
665 {
666  std::string scenario_id;
667 
669  scenario_id = starting_point_["id"].str();
670  } else if(!has_carryover_expanded_) {
671  scenario_id = carryover_["next_scenario"].str();
672  } else if(!replay_start_.empty()) {
673  scenario_id = replay_start_["id"].str();
674  } else {
675  assert(!"cannot figure out scenario_id");
676  throw "assertion ignored";
677  }
678 
679  return scenario_id == "null" ? "" : scenario_id;
680 }
681 
683 {
684  return true;
685 }
686 
688 {
689  std::string& label = classification().label;
690 
691  if(classification().abbrev.empty()) {
692  label = starting_point_["name"].str();
693  } else {
694  label = classification().abbrev + "-" + starting_point_["name"];
695  }
696 
697  label.erase(std::remove_if(label.begin(), label.end(), is_illegal_file_char), label.end());
698  std::replace(label.begin(), label.end(), '_', ' ');
699 }
700 
702 {
703  for(config& side : starting_point_.child_range("side")) {
704  // for humans "goto_x/y" is used for multi-turn-moves
705  // for the ai "goto_x/y" is a way for wml to order the ai to move a unit to a certain place.
706  // we want to cancel human order but not to break wml.
707  if(side["controller"] != side_controller::human) {
708  continue;
709  }
710 
711  for(config& unit : side.child_range("unit")) {
712  unit["goto_x"] = -999;
713  unit["goto_y"] = -999;
714  }
715  }
716 }
717 
719 {
720  for(config& side : starting_point_.child_range("side")) {
721  side.remove_attribute("is_local");
722  }
723 }
724 
726 {
727  swap(other);
728  return *this;
729 }
730 
732 {
733  carryover_.swap(other.carryover_);
734 
738 
742 
744 }
745 
747 {
748  log_scope("read_game");
749 
750  if(auto caryover_sides = cfg.optional_child("carryover_sides")) {
751  carryover_.swap(*caryover_sides);
753  } else if(auto caryover_sides_start = cfg.optional_child("carryover_sides_start")) {
754  carryover_.swap(*caryover_sides_start);
755  has_carryover_expanded_ = false;
756  } else {
757  carryover_.clear();
758  has_carryover_expanded_ = false;
759  }
760 
761  if(auto replay_start = cfg.optional_child("replay_start")) {
763  } else {
765  }
766 
768 
769  // Serversided replays can contain multiple [replay]
770  for(config& replay : cfg.child_range("replay")) {
772  }
773 
775 
776  if(auto snapshot = cfg.optional_child("snapshot")) {
778  starting_point_.swap(*snapshot);
779  } else if(auto scenario = cfg.optional_child("scenario")) {
781  starting_point_.swap(*scenario);
782  } else {
785  }
786 
787  LOG_NG << "scenario: '" << carryover_["next_scenario"].str() << "'";
788 
789  if(auto stats = cfg.optional_child("statistics")) {
790  statistics_.read(*stats);
791  }
792 
794  mp_settings_ = { cfg.child_or_empty("multiplayer") };
795 
796  cfg.clear();
797 }
798 
800 {
801  carryover_.clear();
802  classification_ = {};
803  has_carryover_expanded_ = false;
804  mp_settings_ = {};
805  replay_data_.swap({});
810 }
811 
812 void swap(saved_game& lhs, saved_game& rhs)
813 {
814  lhs.swap(rhs);
815 }
const config to_config()
Definition: carryover.cpp:224
void merge_old_carryover(const carryover_info &old_carryover)
Definition: carryover.cpp:255
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
Variant for storing WML attributes.
bool empty() const
Tests for an attribute that either was never set or was set to "".
Class for writing a config out to a file in pieces.
void close_child(const std::string &key)
void write(const config &cfg)
void write_child(const std::string &key, const config &cfg)
void open_child(const std::string &key)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
Definition: config.cpp:399
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
Definition: config.cpp:371
void remove_child(config_key_type key, std::size_t index)
Definition: config.cpp:649
config_attribute_value attribute_value
Variant for storing WML attributes.
Definition: config.hpp:294
std::size_t child_count(config_key_type key) const
Definition: config.cpp:301
optional_config_impl< config > find_child(config_key_type key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Definition: config.cpp:791
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
Definition: config.cpp:321
child_itors child_range(config_key_type key)
Definition: config.cpp:277
config & child_or_add(config_key_type key)
Returns a reference to the first child with the given key.
Definition: config.cpp:410
std::size_t all_children_count() const
Definition: config.cpp:311
config & add_child_at_total(config_key_type key, const config &val, std::size_t pos)
Definition: config.cpp:517
void remove_attribute(config_key_type key)
Definition: config.cpp:164
void inherit_attributes(const config &c)
Merge the attributes of config 'c' into this config, preserving this config's values.
Definition: config.cpp:1193
std::size_t find_total_first_of(config_key_type key, std::size_t start=0)
Definition: config.cpp:503
void swap(config &cfg)
Definition: config.cpp:1344
void append_children(const config &cfg)
Adds children from cfg.
Definition: config.cpp:169
void splice_children(config &src, const std::string &key)
Moves all the children with tag key from src to this.
Definition: config.cpp:585
bool empty() const
Definition: config.cpp:856
void clear()
Definition: config.cpp:835
const attribute_value * get(config_key_type key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
Definition: config.cpp:691
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Euivalent to mandatory_child, but returns an empty optional if the nth child was not found.
Definition: config.cpp:389
config & add_child(config_key_type key)
Definition: config.cpp:445
std::vector< std::string > active_mods
std::string label
Name of the game (e.g.
std::string get_tagname() const
std::string campaign
The id of the campaign being played.
std::string abbrev
the campaign abbreviation
static game_config_manager * get()
void load_game_config_for_game(const game_classification &classification, const std::string &scenario_id)
const game_config_view & game_config() const
A class grating read only view to a vector of config objects, viewed as one config with all children ...
void rotate_random()
Resets the random to the 0 calls and the seed to the random this way we stay in the same sequence but...
Definition: mt_rng.cpp:74
int get_random_int(int min, int max)
Definition: random.hpp:52
void write(config_writer &out) const
void append_config(const config &data)
void swap(replay_recorder_base &other)
game_classification & classification()
Definition: saved_game.hpp:56
bool not_corrupt() const
Definition: saved_game.cpp:682
saved_game & operator=(const saved_game &other)=delete
void set_random_seed()
sets the random seed if that didn't already happen.
Definition: saved_game.cpp:171
config replay_start_
snapshot made before the start event.
Definition: saved_game.hpp:158
void swap(saved_game &other)
Definition: saved_game.cpp:731
void write_config(config_writer &out) const
writes the config information into a stream (file)
Definition: saved_game.cpp:183
void expand_scenario()
copies the content of a [scenario] with the correct id attribute from the game config into this objec...
Definition: saved_game.cpp:282
void expand_mp_options()
adds values of [option]s into [carryover_sides_start][variables] so that they are applied in the next...
Definition: saved_game.cpp:426
void unify_controllers()
Definition: saved_game.cpp:718
void set_carryover_sides_start(config carryover_sides_start)
Definition: saved_game.cpp:165
config to_config() const
Definition: saved_game.cpp:640
starting_point starting_point_type_
Definition: saved_game.hpp:163
std::string get_scenario_id() const
Definition: saved_game.cpp:664
static void post_scenario_generation(const config &old_scenario, config &generated_scenario)
copies attributes & tags from the 'outer' [scenario] to the scenario that is generated by scenario_ge...
Definition: saved_game.cpp:524
replay_recorder_base replay_data_
Definition: saved_game.hpp:170
void clear()
Definition: saved_game.cpp:799
void load_non_scenario(const std::string &type, const std::string &id, size_t pos)
helper for expand_mp_events();
Definition: saved_game.cpp:328
void update_label()
sets classification().label to the correct value.
Definition: saved_game.cpp:687
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
Definition: saved_game.hpp:60
statistics_record::campaign_stats_t statistics_
Definition: saved_game.hpp:172
void set_scenario(config scenario)
Definition: saved_game.cpp:581
bool has_carryover_expanded_
Definition: saved_game.hpp:150
config & replay_start()
Definition: saved_game.hpp:128
static void expand_map_file(config &scenario)
reads scenario["map_file"]
Definition: saved_game.cpp:474
void remove_snapshot()
Definition: saved_game.cpp:591
config & get_starting_point()
Definition: saved_game.cpp:597
config starting_point_
The starting pos where the (non replay) game will be started from.
Definition: saved_game.hpp:168
const config & get_replay_starting_point()
Definition: saved_game.cpp:602
void check_require_scenario()
Add addon_id information if needed.
Definition: saved_game.cpp:310
void write_starting_point(config_writer &out) const
Definition: saved_game.cpp:198
void expand_mp_events()
adds [event]s from [era] and [modification] into this scenario does NOT expand [option]s because vari...
Definition: saved_game.cpp:385
config carryover_
depends on has_carryover_expanded_: if true: The carryover information for all sides from the previou...
Definition: saved_game.hpp:156
void expand_random_scenario()
takes care of generate_map=, generate_scenario=, map= attributes This should be called before expandi...
Definition: saved_game.cpp:490
mp_game_settings mp_settings_
Definition: saved_game.hpp:161
void expand_carryover()
merges [carryover_sides_start] into [scenario] and saves the rest into [carryover_sides] Removes [car...
Definition: saved_game.cpp:551
@ SNAPSHOT
We have a [snapshot] (mid-game-savefile).
@ SCENARIO
We have a [scenario] (start-of-scenario) savefile.
@ NONE
There is no scenario stating pos data (start-of-scenario).
@ INVALID
We failed to get a starting pos in expand_scenario.
statistics_record::campaign_stats_t & statistics()
Definition: saved_game.hpp:143
void cancel_orders()
Definition: saved_game.cpp:701
void convert_to_start_save()
converts a normal savegame form the end of a scenaio to a start-of-scenario savefile for the next sce...
Definition: saved_game.cpp:621
bool valid() const
Definition: saved_game.cpp:568
void set_defaults()
does some post loading stuff must be used before passing the data to connect_engine
Definition: saved_game.cpp:222
void write_general_info(config_writer &out) const
Definition: saved_game.cpp:213
game_classification classification_
some general information of the game that doesn't change during the game
Definition: saved_game.hpp:160
void set_data(config &cfg)
destroys the passed config.
Definition: saved_game.cpp:746
config & set_snapshot(config snapshot)
Definition: saved_game.cpp:573
void write_carryover(config_writer &out) const
Definition: saved_game.cpp:207
This class represents a single unit of a specific type.
Definition: unit.hpp:134
std::string str() const
Serializes the version number into string form.
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:217
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
Standard logging facilities (interface).
#define log_scope(description)
Definition: log.hpp:240
std::string random_generate_map(const std::string &name, const config &cfg, const config *vars)
Definition: map_create.cpp:45
config random_generate_scenario(const std::string &name, const config &cfg, const config *vars)
Definition: map_create.cpp:57
@ WAIT
Definition: cursor.hpp:29
std::string read_map(const std::string &name)
Game configuration data as global variables.
Definition: build_info.cpp:63
const version_info wesnoth_version(VERSION)
@ NONE
Default, unset return value.
Definition: retval.hpp:32
const config & options()
Definition: game.cpp:555
rng * generator
This generator is automatically synced during synced context.
Definition: random.cpp:61
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
static void inherit_scenario(config &scenario, config &map_scenario)
Definition: saved_game.cpp:457
void swap(saved_game &lhs, saved_game &rhs)
Implement non-member swap function for std::swap (calls saved_game::swap).
Definition: saved_game.cpp:812
static lg::log_domain log_engine("engine")
#define ERR_NG
Definition: saved_game.cpp:85
#define LOG_NG
Definition: saved_game.cpp:87
void read(config &cfg, std::istream &in, abstract_validator *validator)
Definition: parser.cpp:627
void update_addon_requirements(const config &addon_cfg)
Takes a config with addon metadata (id, name, version, min_version) and adds it as a requirement for ...
config to_config() const
void new_scenario(const std::string &scenario_name)
Adds an entry for anew scenario to wrte to.
void read(const config &cfg, bool append=false)
void write(config_writer &out) const
mock_char c
variable_info_mutable< variable_info_implementation::vi_policy_create > variable_access_create
'Create if nonexistent' access.