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