The Battle for Wesnoth  1.19.0-dev
saved_game.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 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 /**
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.
25  *
26  * - [snapshot]
27  * If a savegame was saved during a scenario this contains a snapshot of the game at the point when
28  * it was saved.
29  *
30  * - [carryover_sides_start]
31  * At start-of-scenario saves this contains data from the previous scenario that was preserved.
32  *
33  * - [carryover_sides]
34  * In savefile made during the game, this tag contains data from [carryover_sides_start] that was not
35  * used in the current scenario but should be saved for a next scenario
36  *
37  * - [replay_start]
38  * A snapshot made very early to replay the game from.
39  *
40  * - [replay]
41  * A record of game actions that was made between the creation of [replay_start] and [snapshot].
42  *
43  *
44  * The following types of savegames are known:
45  *
46  * - Start of scenario savefiles
47  * These files only contain general information, statistics, and [carryover_sides_start]. When these
48  * saves are loaded, the scenario data is loaded form the game config using the next_scenario attribute
49  * from [carryover_sides_start].
50  *
51  * - Expanded Start of scenario savefiles
52  * Similar to normal Start-of-scenario savefiles, but the also contain a [scenario] that contains the
53  * scenario data. This type is only used internally and usually doesn't get written to the disk.
54  *
55  * - In-game savefile
56  * These files contain general information, statistics, [snapshot], [replay], [replay_start], [snapshot],
57  * and [carryover_sides]. These files don't contain a [carryover_sides_start] because both starting points
58  * ([replay_start] and [snapshot]) were made after [carryover_sides_start] was merged into the scenario.
59  *
60  * - Replay savefiles
61  * Like a in-game save made during linger mode, but without the [snapshot].
62  */
63 
64 #include "saved_game.hpp"
65 
66 #include "carryover.hpp"
67 #include "config.hpp"
68 #include "cursor.hpp"
69 #include "formula/string_utils.hpp"
70 #include "game_config_manager.hpp"
72 #include "log.hpp"
73 #include "random.hpp"
75 #include "side_controller.hpp"
76 #include "variable.hpp" // for config_variable_set
77 #include "variable_info.hpp"
78 
79 #include <cassert>
80 #include <iomanip>
81 
82 static lg::log_domain log_engine("engine");
83 #define ERR_NG LOG_STREAM(err, log_engine)
84 #define WRN_NG LOG_STREAM(warn, log_engine)
85 #define LOG_NG LOG_STREAM(info, log_engine)
86 #define DBG_NG LOG_STREAM(debug, log_engine)
87 
88 namespace
89 {
90 bool variable_to_bool(const config& vars, const std::string& expression)
91 {
92  std::string res = utils::interpolate_variables_into_string(expression, config_variable_set(vars));
93  return res == "true" || res == "yes" || res == "1";
94 }
95 
96 // helper objects for saved_game::expand_mp_events()
97 struct modevents_entry
98 {
99  modevents_entry(const std::string& _type, const std::string& _id)
100  : type(_type)
101  , id(_id)
102  {
103  }
104 
105  std::string type;
106  std::string id;
107 };
108 
109 bool is_illegal_file_char(char c)
110 {
111  return c == '/' || c == '\\' || c == ':' || (c >= 0x00 && c < 0x20)
112 #ifdef _WIN32
113  || c == '?' || c == '|' || c == '<' || c == '>' || c == '*' || c == '"'
114 #endif
115  ;
116 }
117 
118 } // end anon namespace
119 
121  : has_carryover_expanded_(false)
122  , carryover_(carryover_info().to_config())
123  , replay_start_()
124  , classification_()
125  , mp_settings_()
126  , starting_point_type_(starting_point::NONE)
127  , starting_point_()
128  , replay_data_()
129  , statistics_()
130  , skip_story_(false)
131 {
132 }
133 
135  : has_carryover_expanded_(false)
136  , carryover_()
137  , replay_start_()
138  , classification_(cfg)
139  , mp_settings_()
140  , starting_point_type_(starting_point::NONE)
141  , starting_point_()
142  , replay_data_()
143  , statistics_()
144  , skip_story_(false)
145 {
146  set_data(cfg);
147 }
148 
150  : has_carryover_expanded_(state.has_carryover_expanded_)
151  , carryover_(state.carryover_)
152  , replay_start_(state.replay_start_)
153  , classification_(state.classification_)
154  , mp_settings_(state.mp_settings_)
155  , starting_point_type_(state.starting_point_type_)
156  , starting_point_(state.starting_point_)
157  , replay_data_(state.replay_data_)
158  , statistics_(state.statistics_)
159  , skip_story_(state.skip_story_)
160 {
161 }
162 
164 {
165  carryover_.swap(carryover_sides_start);
166  has_carryover_expanded_ = false;
167 }
168 
170 {
171  if(has_carryover_expanded_ || !carryover_["random_seed"].empty()) {
172  return;
173  }
174 
175  std::stringstream stream;
176  stream << std::setfill('0') << std::setw(8) << std::hex << randomness::generator->get_random_int(0, INT_MAX);
177  carryover_["random_seed"] = stream.str();
178  carryover_["random_calls"] = 0;
179 }
180 
182 {
183  write_general_info(out);
185 
186  if(!replay_start_.empty()) {
187  out.write_child("replay_start", replay_start_);
188  }
189 
190  out.open_child("replay");
191  replay_data_.write(out);
192  out.close_child("replay");
193  write_carryover(out);
194 }
195 
197 {
199  out.write_child("snapshot", starting_point_);
201  out.write_child("scenario", starting_point_);
202  }
203 }
204 
206 {
207  assert(not_corrupt());
208  out.write_child(has_carryover_expanded_ ? "carryover_sides" : "carryover_sides_start", carryover_);
209 }
210 
212 {
214  out.write_child("multiplayer", mp_settings_.to_config());
215  out.open_child("statistics");
216  statistics().write(out);
217  out.close_child("statistics");
218 }
219 
221 {
222  const bool is_loaded_game = starting_point_type_ != starting_point::SCENARIO;
223  const bool is_multiplayer_tag = classification().get_tagname() == "multiplayer";
225 
226  static const std::vector<std::string> team_defaults {
227  "carryover_percentage",
228  "carryover_add",
229  };
230 
231  if(auto campaign = game_config.find_child("campaign", "id", classification_.campaign)) {
232  // FIXME: The mp code could use `require_scenario` to check whether we have the addon in question installed.
233  // But since [scenario]s are usually hidden behind `#ifdef CAMPAIGN_DEFINE` it would not be able to find them.
234  // Investigate how this should actually work.
235  bool require_campaign = campaign["require_campaign"].to_bool(true);
236  starting_point_["require_scenario"] = require_campaign;
237  }
238 
239  for(config& side : starting_point_.child_range("side")) {
240  // Set save_id default value directly after loading to its default to prevent different default behaviour in
241  // mp_connect code and sp code.
242 
243  if(side["no_leader"].to_bool()) {
244  side["leader_lock"] = true;
245  side.remove_attribute("type");
246  }
247 
248  if(side["save_id"].empty()) {
249  side["save_id"] = side["id"];
250  }
251  if(side["save_id"].empty()) {
252  side["save_id"] = side.child_or_empty("leader")["id"];
253  }
254 
255  if(!is_multiplayer_tag) {
256  if(side["name"].blank()) {
257  side["name"] = side.child_or_empty("leader")["name"];
258  }
259  if(side["side_name"].blank()) {
260  side["side_name"] = side["name"];
261  }
262  }
263 
264  if(!is_loaded_game && !side["current_player"].empty()) {
265  ERR_NG << "Removed invalid 'current_player' attribute from [side] while loading a scenario. Consider using "
266  "'side_name' instead";
267 
268  side["current_player"] = config::attribute_value();
269  }
270 
271  // Set some team specific values to their defaults specified in scenario
272  for(const std::string& att_name : team_defaults) {
273  const config::attribute_value* scenario_value = starting_point_.get(att_name);
274  config::attribute_value& team_value = side[att_name];
275 
276  if(scenario_value && team_value.empty()) {
277  team_value = *scenario_value;
278  }
279  }
280  }
281 }
282 
284 {
287 
289  auto scenario =
290  game_config.find_child(classification().get_tagname(), "id", carryover_["next_scenario"]);
291 
292  if(scenario) {
294  starting_point_ = *scenario;
295 
296  // A hash has to be generated using an unmodified scenario data.
297  mp_settings_.hash = scenario->hash();
298 
300 
301  update_label();
302  set_defaults();
303  } else {
304  ERR_NG << "Couldn't find [" << classification().get_tagname() << "] with id=" << carryover_["next_scenario"];
307  }
308  }
309 }
310 
312 {
313  const std::string version_default = starting_point_["addon_id"].empty() ? game_config::wesnoth_version.str() : "";
314  config scenario;
315  scenario["id"] = starting_point_["addon_id"].str("mainline");
316  scenario["name"] = starting_point_["addon_title"].str("mainline");
317  scenario["version"] = starting_point_["addon_version"].str(version_default);
318  scenario["min_version"] = starting_point_["addon_min_version"];
319  scenario["required"] = starting_point_["require_scenario"].to_bool(false);
320  config& content = scenario.add_child("content");
321  content["id"] = starting_point_["id"];
322  content["name"] = starting_point_["name"];
323  // TODO: would it be better if this used the actual tagname ([multiplayer]/[scenario]) instead of always using [scenario]?
324  content["type"] = "scenario";
325 
327 }
328 
329 // "non scenario" at the time of writing this meaning any era, campaign, mods, or resources (see expand_mp_events() below).
330 void saved_game::load_non_scenario(const std::string& type, const std::string& id, size_t pos)
331 {
332  if(auto cfg = game_config_manager::get()->game_config().find_child(type, "id", id)) {
333  // Note the addon_id if this mod is required to play the game in mp.
334  std::string require_attr = "require_" + type;
335 
336  // anything with no addon_id is from mainline, and therefore isn't required in the sense that all players already have it
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(!cfg["addon_id"].empty());
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_scen)
458 {
459  config& map_scenario = map_scen.has_child("multiplayer") ? map_scen.mandatory_child("multiplayer") : (map_scen.has_child("scenario") ? map_scen.mandatory_child("scenario") : map_scen);
460  config sides;
461  sides.splice_children(map_scenario, "side");
462  scenario.append_children(map_scenario);
463  scenario.inherit_attributes(map_scenario);
464  for(config& side_from : sides.child_range("side")) {
465  auto side_to = scenario.find_child("side", "side", side_from["side"]);
466  if(side_to) {
467  side_to->inherit_attributes(side_from);
468  side_to->append_children(side_from);
469  } else {
470  scenario.add_child("side", side_from);
471  }
472  }
473 }
474 
476 {
477  if(!scenario["include_file"].empty()) {
478  std::string include_data = filesystem::read_scenario(scenario["include_file"]);
479  if(!include_data.empty()) {
480  config include_data_cfg;
481  read(include_data_cfg, include_data);
482  inherit_scenario(scenario, include_data_cfg);
483  }
484  // this method gets called two additional times, so without this you end up calling inherit_scenario() three times total
485  // this is equivalent to the below check for map_data being empty
486  scenario["include_file"] = "";
487  }
488 
489  if(scenario["map_data"].empty() && !scenario["map_file"].empty()) {
490  std::string map_data = filesystem::read_map(scenario["map_file"]);
491  if(map_data.find("map_data") != std::string::npos) {
492  // we have a scenario, generated by the editor
493  deprecated_message("map_file cfg", DEP_LEVEL::FOR_REMOVAL, "1.19", "Providing a .cfg file to the map_file attribute is deprecated. Use map_file for .map files and include_file for .cfg files.");
494  config map_data_cfg;
495  read(map_data_cfg, map_data);
496  inherit_scenario(scenario, map_data_cfg);
497  } else {
498  // we have an plain map_data file
499  scenario["map_data"] = map_data;
500  }
501  }
502 }
503 
505 {
506  expand_scenario();
507 
509  // If the entire scenario should be randomly generated
510  if(!starting_point_["scenario_generation"].empty()) {
511  LOG_NG << "randomly generating scenario...";
512  const cursor::setter cursor_setter(cursor::WAIT);
513 
514  config scenario_new =
515  random_generate_scenario(starting_point_["scenario_generation"], starting_point_.mandatory_child("generator"), &carryover_.child_or_empty("variables"));
516 
518  starting_point_ = std::move(scenario_new);
519 
520  update_label();
521  set_defaults();
522  }
523 
524  // If no map_data is provided, try to load the specified file directly
526  // If the map should be randomly generated
527  // We don’t want that we accidentally to this twice so we check for starting_point_["map_data"].empty()
528  if(starting_point_["map_data"].empty() && !starting_point_["map_generation"].empty()) {
529  LOG_NG << "randomly generating map...";
530  const cursor::setter cursor_setter(cursor::WAIT);
531 
532  starting_point_["map_data"] =
533  random_generate_map(starting_point_["map_generation"], starting_point_.mandatory_child("generator"), &carryover_.child_or_empty("variables"));
534  }
535  }
536 }
537 
538 void saved_game::post_scenario_generation(const config& old_scenario, config& generated_scenario)
539 {
540  static const std::vector<std::string> attributes_to_copy {
541  "id",
542  "addon_id",
543  "addon_title",
544  "addon_version",
545  "addon_min_version",
546  "require_scenario",
547  };
548 
549  // TODO: should we add "description" to this list?
550  // 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.
551 
552  for(const auto& str : attributes_to_copy) {
553  generated_scenario[str] = old_scenario[str];
554  }
555 
556  // Preserve "story" from the scenario toplevel.
557  // Note that it does not delete [story] tags in generated_scenario, so you can still have your story
558  // dependent on the generated scenario.
559  for(const config& story : old_scenario.child_range("story")) {
560  generated_scenario.add_child("story", story);
561  }
562 }
563 
564 
566 {
567  expand_scenario();
569  carryover_info sides(carryover_);
570 
572  for(config& side_cfg : get_starting_point().child_range("side")) {
573  sides.transfer_all_to(side_cfg);
574  }
575 
576  carryover_ = sides.to_config();
579  }
580 }
581 
582 bool saved_game::valid() const
583 {
585 }
586 
588 {
590  starting_point_.swap(snapshot);
591 
592  return starting_point_;
593 }
594 
596 {
598  starting_point_.swap(scenario);
599 
600  has_carryover_expanded_ = false;
601 
602  update_label();
603 }
604 
606 {
609 }
610 
612 {
613  return starting_point_;
614 }
615 
617 {
618  if(!replay_start_.empty()) {
619  return replay_start_;
620  }
621 
623  // Try to load the scenario form game config or from [scenario] if there is no [replay_start]
624  expand_scenario();
626  }
627 
629  return starting_point_;
630  }
631 
632  throw config::error("No replay_start found");
633 }
634 
636 {
638 
639  carryover_info sides(starting_point_, true);
640 
642  sides.rng().rotate_random();
643 
644  carryover_ = sides.to_config();
645 
646  has_carryover_expanded_ = false;
647 
650 
651  remove_snapshot();
652 }
653 
655 {
656  // TODO: remove this code duplication with write_... functions.
658 
659  if(!replay_start_.empty()) {
660  r.add_child("replay_start", replay_start_);
661  }
662 
663  replay_data_.write(r.add_child("replay"));
664 
666  r.add_child("snapshot", starting_point_);
668  r.add_child("scenario", starting_point_);
669  }
670 
671  r.add_child(has_carryover_expanded_ ? "carryover_sides" : "carryover_sides_start", carryover_);
672  r.add_child("multiplayer", mp_settings_.to_config());
673  r.add_child("statistics", statistics_.to_config());
674 
675  return r;
676 }
677 
678 std::string saved_game::get_scenario_id() const
679 {
680  std::string scenario_id;
681 
683  scenario_id = starting_point_["id"].str();
684  } else if(!has_carryover_expanded_) {
685  scenario_id = carryover_["next_scenario"].str();
686  } else if(!replay_start_.empty()) {
687  scenario_id = replay_start_["id"].str();
688  } else {
689  assert(!"cannot figure out scenario_id");
690  throw "assertion ignored";
691  }
692 
693  return scenario_id == "null" ? "" : scenario_id;
694 }
695 
697 {
698  return true;
699 }
700 
702 {
703  std::string& label = classification().label;
704 
705  if(classification().abbrev.empty()) {
706  label = starting_point_["name"].str();
707  } else {
708  label = classification().abbrev + "-" + starting_point_["name"];
709  }
710 
711  label.erase(std::remove_if(label.begin(), label.end(), is_illegal_file_char), label.end());
712  std::replace(label.begin(), label.end(), '_', ' ');
713 }
714 
716 {
717  for(config& side : starting_point_.child_range("side")) {
718  // for humans "goto_x/y" is used for multi-turn-moves
719  // for the ai "goto_x/y" is a way for wml to order the ai to move a unit to a certain place.
720  // we want to cancel human order but not to break wml.
721  if(side["controller"] != side_controller::human) {
722  continue;
723  }
724 
725  for(config& unit : side.child_range("unit")) {
726  unit["goto_x"] = -999;
727  unit["goto_y"] = -999;
728  }
729  }
730 }
731 
733 {
734  for(config& side : starting_point_.child_range("side")) {
735  side.remove_attribute("is_local");
736  }
737 }
738 
740 {
741  swap(other);
742  return *this;
743 }
744 
746 {
747  carryover_.swap(other.carryover_);
748 
752 
756 
758 }
759 
761 {
762  log_scope("read_game");
763 
764  if(auto caryover_sides = cfg.optional_child("carryover_sides")) {
765  carryover_.swap(*caryover_sides);
767  } else if(auto caryover_sides_start = cfg.optional_child("carryover_sides_start")) {
768  carryover_.swap(*caryover_sides_start);
769  has_carryover_expanded_ = false;
770  } else {
771  carryover_.clear();
772  has_carryover_expanded_ = false;
773  }
774 
775  if(auto replay_start = cfg.optional_child("replay_start")) {
777  } else {
779  }
780 
782 
783  // Serversided replays can contain multiple [replay]
784  for(config& replay : cfg.child_range("replay")) {
786  }
787 
789 
790  if(auto snapshot = cfg.optional_child("snapshot")) {
792  starting_point_.swap(*snapshot);
793  } else if(auto scenario = cfg.optional_child("scenario")) {
795  starting_point_.swap(*scenario);
796  } else {
799  }
800 
801  LOG_NG << "scenario: '" << carryover_["next_scenario"].str() << "'";
802 
803  if(auto stats = cfg.optional_child("statistics")) {
804  statistics_.read(*stats);
805  }
806 
808  mp_settings_ = { cfg.child_or_empty("multiplayer") };
809 
810  cfg.clear();
811 }
812 
814 {
815  carryover_.clear();
816  classification_ = {};
817  has_carryover_expanded_ = false;
818  mp_settings_ = {};
819  replay_data_.swap({});
824 }
825 
826 void swap(saved_game& lhs, saved_game& rhs)
827 {
828  lhs.swap(rhs);
829 }
const config to_config()
Definition: carryover.cpp:223
void merge_old_carryover(const carryover_info &old_carryover)
Definition: carryover.cpp:254
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
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:159
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:395
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:367
void remove_child(config_key_type key, std::size_t index)
Definition: config.cpp:645
config_attribute_value attribute_value
Variant for storing WML attributes.
Definition: config.hpp:292
std::size_t child_count(config_key_type key) const
Definition: config.cpp:297
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:787
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
Definition: config.cpp:317
child_itors child_range(config_key_type key)
Definition: config.cpp:273
config & child_or_add(config_key_type key)
Returns a reference to the first child with the given key.
Definition: config.cpp:406
std::size_t all_children_count() const
Definition: config.cpp:307
config & add_child_at_total(config_key_type key, const config &val, std::size_t pos)
Definition: config.cpp:513
void remove_attribute(config_key_type key)
Definition: config.cpp:160
void inherit_attributes(const config &c)
Merge the attributes of config 'c' into this config, preserving this config's values.
Definition: config.cpp:1189
std::size_t find_total_first_of(config_key_type key, std::size_t start=0)
Definition: config.cpp:499
void swap(config &cfg)
Definition: config.cpp:1340
void append_children(const config &cfg)
Adds children from cfg.
Definition: config.cpp:165
void splice_children(config &src, const std::string &key)
Moves all the children with tag key from src to this.
Definition: config.cpp:581
bool empty() const
Definition: config.cpp:852
void clear()
Definition: config.cpp:831
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:687
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:385
config & add_child(config_key_type key)
Definition: config.cpp:441
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:51
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:696
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:169
config replay_start_
snapshot made before the start event.
Definition: saved_game.hpp:158
void swap(saved_game &other)
Definition: saved_game.cpp:745
void write_config(config_writer &out) const
writes the config information into a stream (file)
Definition: saved_game.cpp:181
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:283
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:732
void set_carryover_sides_start(config carryover_sides_start)
Definition: saved_game.cpp:163
config to_config() const
Definition: saved_game.cpp:654
starting_point starting_point_type_
Definition: saved_game.hpp:163
std::string get_scenario_id() const
Definition: saved_game.cpp:678
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:538
replay_recorder_base replay_data_
Definition: saved_game.hpp:170
void clear()
Definition: saved_game.cpp:813
void load_non_scenario(const std::string &type, const std::string &id, size_t pos)
helper for expand_mp_events();
Definition: saved_game.cpp:330
void update_label()
sets classification().label to the correct value.
Definition: saved_game.cpp:701
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:595
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:475
void remove_snapshot()
Definition: saved_game.cpp:605
config & get_starting_point()
Definition: saved_game.cpp:611
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:616
void check_require_scenario()
Add addon_id information if needed.
Definition: saved_game.cpp:311
void write_starting_point(config_writer &out) const
Definition: saved_game.cpp:196
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:504
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:565
@ 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:715
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:635
bool valid() const
Definition: saved_game.cpp:582
void set_defaults()
does some post loading stuff must be used before passing the data to connect_engine
Definition: saved_game.cpp:220
void write_general_info(config_writer &out) const
Definition: saved_game.cpp:211
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:760
config & set_snapshot(config snapshot)
Definition: saved_game.cpp:587
void write_carryover(config_writer &out) const
Definition: saved_game.cpp:205
This class represents a single unit of a specific type.
Definition: unit.hpp:133
std::string str() const
Serializes the version number into string form.
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
Definition: deprecation.cpp:29
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:209
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:207
Standard logging facilities (interface).
#define log_scope(description)
Definition: log.hpp:274
std::string random_generate_map(const std::string &name, const config &cfg, const config *vars)
Definition: map_create.cpp:44
config random_generate_scenario(const std::string &name, const config &cfg, const config *vars)
Definition: map_create.cpp:56
@ WAIT
Definition: cursor.hpp:28
std::string read_scenario(const std::string &name)
std::string read_map(const std::string &name)
Game configuration data as global variables.
Definition: build_info.cpp:61
const version_info wesnoth_version(VERSION)
@ NONE
Default, unset return value.
Definition: retval.hpp:32
const config & options()
Definition: game.cpp:552
rng * generator
This generator is automatically synced during synced context.
Definition: random.cpp:60
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.
void swap(saved_game &lhs, saved_game &rhs)
Implement non-member swap function for std::swap (calls saved_game::swap).
Definition: saved_game.cpp:826
static lg::log_domain log_engine("engine")
#define ERR_NG
Definition: saved_game.cpp:83
static void inherit_scenario(config &scenario, config &map_scen)
Definition: saved_game.cpp:457
#define LOG_NG
Definition: saved_game.cpp:85
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.