The Battle for Wesnoth  1.19.0-dev
game_config_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2024
3  by Andrius Silinskas <silinskas.andrius@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #include "game_config_manager.hpp"
17 
18 #include "about.hpp"
19 #include "addon/manager.hpp"
20 #include "ai/configuration.hpp"
21 #include "events.hpp"
22 #include "formatter.hpp"
23 #include "formula/string_utils.hpp"
24 #include "game_classification.hpp"
25 #include "game_config.hpp"
26 #include "game_version.hpp"
27 #include "gettext.hpp"
30 #include "hotkey/hotkey_item.hpp"
31 #include "language.hpp"
32 #include "log.hpp"
33 #include "picture.hpp"
34 #include "preferences/advanced.hpp"
35 #include "preferences/general.hpp"
38 #include "sound.hpp"
40 #include "terrain/builder.hpp"
41 #include "terrain/type_data.hpp"
42 #include "theme.hpp"
43 #include "units/types.hpp"
44 
45 static lg::log_domain log_config("config");
46 #define ERR_CONFIG LOG_STREAM(err, log_config)
47 #define WRN_CONFIG LOG_STREAM(warn, log_config)
48 #define LOG_CONFIG LOG_STREAM(info, log_config)
49 
51 
53 
55  : cmdline_opts_(cmdline_opts)
56  , game_config_()
57  , game_config_view_()
58  , addon_cfgs_()
59  , active_addons_()
60  , old_defines_map_()
61  , paths_manager_()
62  , cache_(game_config::config_cache::instance())
63  , achievements_()
64 {
65  assert(!singleton);
66  singleton = this;
67 
68  // All of the validation options imply --nocache, as the validation happens during cache
69  // rebuilding. If the cache isn't rebuilt, validation is silently skipped.
71  cache_.set_use_cache(false);
72  }
73 
76  }
77 
78  // Clean the cache of any old Wesnoth version's cache data
79  if(const std::string last_cleaned = preferences::last_cache_cleared_version(); !last_cleaned.empty()) {
80  if(version_info{last_cleaned} < game_config::wesnoth_version) {
81  if(cache_.clean_cache()) {
83  }
84  }
85  } else {
86  // If the preference wasn't set, set it, else the cleaning will never happen :P
88  }
89 }
90 
92 {
93  assert(singleton);
94  singleton = nullptr;
95 }
96 
98 {
99  return singleton;
100 }
101 
103 {
104  // Add preproc defines according to the command line arguments.
106  game_config::scoped_preproc_define test("TEST", cmdline_opts_.test.has_value());
109  game_config::scoped_preproc_define title_screen("TITLE_SCREEN",
111 
113 
114  load_game_config_with_loadscreen(force_reload, nullptr, "");
115 
116  game_config::load_config(game_config().mandatory_child("game_config"));
117 
118  // It's necessary to block the event thread while load_hotkeys() runs, otherwise keyboard input
119  // can cause a crash by accessing the list of hotkeys while it's being modified.
120  events::call_in_main_thread([this]() {
121  const hotkey::scope_changer hk_scope{hotkey::scope_main, false};
122 
123  // Load the standard hotkeys, then apply any player customizations.
126  });
127 
128  // TODO: consider making this part of preferences::manager in some fashion
130 
134 
135  return true;
136 }
137 
138 namespace
139 {
140 /** returns true if every define in special is also defined in general */
141 bool map_includes(const preproc_map& general, const preproc_map& special)
142 {
143  return std::all_of(special.begin(), special.end(), [&general](const auto& pair) {
144  const auto it = general.find(pair.first);
145  return it != general.end() && it->second == pair.second;
146  });
147 }
148 } // end anonymous namespace
149 
151  FORCE_RELOAD_CONFIG force_reload, const game_classification* classification, const std::string& scenario_id)
152 {
153  if(!lg::info().dont_log(log_config)) {
154  auto out = formatter();
155  out << "load_game_config: defines:";
156 
157  for(const auto& pair : cache_.get_preproc_map()) {
158  out << pair.first << ",";
159  }
160 
161  out << "\n";
162  FORCE_LOG_TO(lg::info(), log_config) << out.str();
163  }
164 
165  game_config::scoped_preproc_define debug_mode("DEBUG_MODE",
167 
168  bool reload_everything = true;
169 
170  // Game_config already holds requested config in memory.
171  if(!game_config_.empty()) {
172  if(force_reload == NO_FORCE_RELOAD && old_defines_map_ == cache_.get_preproc_map()) {
173  reload_everything = false;
174  }
175 
176  if(force_reload == NO_INCLUDE_RELOAD && map_includes(old_defines_map_, cache_.get_preproc_map())) {
177  reload_everything = false;
178  }
179  }
180 
181  LOG_CONFIG << "load_game_config reload everything: " << reload_everything;
182 
183  gui2::dialogs::loading_screen::display([this, reload_everything, classification, scenario_id]() {
184  load_game_config(reload_everything, classification, scenario_id);
185  });
186 }
187 
188 void game_config_manager::load_game_config(bool reload_everything, const game_classification* classification, const std::string& scenario_id)
189 {
190  // Make sure that 'debug mode' symbol is set
191  // if command line parameter is selected
192  // also if we're in multiplayer and actual debug mode is disabled.
193 
194  // The loadscreen will erase the titlescreen.
195  // NOTE: even without loadscreen, needed after MP lobby.
196  try {
197  // Read all game configs.
198  // First we load all core configs, the mainline one and the ones from the addons.
199  // Validate the cores and discard the invalid.
200  // Then find the path to the selected core.
201  // Load the selected core.
202  // Handle terrains so that they are last loaded from the core.
203  // Load every compatible addon.
204  if(reload_everything) {
208 
209  // Start transaction so macros are shared.
210  game_config::config_cache_transaction main_transaction;
212 
213  // Load mainline cores definition file.
214  config cores_cfg;
215  cache_.get_config(game_config::path + "/data/cores.cfg", cores_cfg);
216 
217  // Append the $user_campaign_dir/*/cores.cfg files to the cores.
218  std::vector<std::string> user_dirs;
219  {
220  const std::string user_campaign_dir = filesystem::get_addons_dir();
221  std::vector<std::string> user_files;
223  user_campaign_dir, &user_files, &user_dirs, filesystem::name_mode::ENTIRE_FILE_PATH);
224  }
225 
226  for(const std::string& umc : user_dirs) {
227  const std::string cores_file = umc + "/cores.cfg";
228  if(filesystem::file_exists(cores_file)) {
229  config cores;
230  cache_.get_config(cores_file, cores);
231  cores_cfg.append(cores);
232  }
233  }
234 
235  // Validate every core
236  config valid_cores;
237  bool current_core_valid = false;
238  std::string wml_tree_root;
239 
240  for(const config& core : cores_cfg.child_range("core")) {
241  const std::string& id = core["id"];
242  if(id.empty()) {
245  _("Error validating data core."),
246  _("Found a core without id attribute.")
247  + '\n' + _("Skipping the core."));
248  });
249  continue;
250  }
251 
252  if(valid_cores.find_child("core", "id", id)) {
255  _("Error validating data core."),
256  _("Core ID: ") + id
257  + '\n' + _("The ID is already in use.")
258  + '\n' + _("Skipping the core."));
259  });
260  continue;
261  }
262 
263  const std::string& path = core["path"];
267  _("Error validating data core."),
268  _("Core ID: ") + id
269  + '\n' + _("Core Path: ") + path
270  + '\n' + _("File not found.")
271  + '\n' + _("Skipping the core."));
272  });
273  continue;
274  }
275 
276  if(id == "default" && !current_core_valid) {
277  wml_tree_root = path;
278  }
279  if(id == preferences::core_id()) {
280  current_core_valid = true;
281  wml_tree_root = path;
282  }
283 
284  valid_cores.add_child("core", core); // append(core);
285  }
286 
287  if(!current_core_valid) {
290  _("Error loading core data."),
291  _("Core ID: ") + preferences::core_id()
292  + '\n' + _("Error loading the core with named id.")
293  + '\n' + _("Falling back to the default core."));
294  });
295  preferences::set_core_id("default");
296  }
297 
298  // check if we have a valid default core which should always be the case.
299  if(wml_tree_root.empty()) {
302  _("Error loading core data."),
303  _("Can't locate the default core.")
304  + '\n' + _("The game will now exit."));
305  });
306  throw;
307  }
308 
309  // Load the selected core
310  std::unique_ptr<schema_validation::schema_validator> validator;
312  validator.reset(new schema_validation::schema_validator(filesystem::get_wml_location("schema/game_config.cfg")));
313  validator->set_create_exceptions(false); // Don't crash if there's an error, just go ahead anyway
314  }
315 
316  cache_.get_config(filesystem::get_wml_location(wml_tree_root), game_config_, validator.get());
317  game_config_.append(valid_cores);
318 
319  main_transaction.lock();
320 
322  load_addons_cfg();
323  }
324  }
325 
326  // only after addon configs have been loaded do we check for which addons are needed and whether they exist to be used
327  LOG_CONFIG << "active_addons_ has size " << active_addons_.size() << " and contents: " << utils::join(active_addons_);
328  if(classification) {
329  LOG_CONFIG << "Enabling only some add-ons!";
330  std::set<std::string> active_addons = classification->active_addons(scenario_id);
331  // IMPORTANT: this is a significant performance optimization, particularly for the worst case example of the batched WML unit tests
332  if(!reload_everything && active_addons == active_addons_) {
333  LOG_CONFIG << "Configs not reloaded and active add-ons remain the same; returning early.";
334  LOG_CONFIG << "active_addons has size " << active_addons_.size() << " and contents: " << utils::join(active_addons);
335  return;
336  }
337  active_addons_ = active_addons;
339  } else {
340  LOG_CONFIG << "Enabling all add-ons!";
342  }
343 
344  // Extract the Lua scripts at toplevel.
346 
347  set_unit_data();
349  tdata_ = std::make_shared<terrain_type_data>(game_config());
352 
354 
356 
357  } catch(const game::error& e) {
358  ERR_CONFIG << "Error loading game configuration files\n" << e.message;
359 
360  // Try reloading without add-ons
362  game_config::no_addons = true;
365  _("Error loading custom game configuration files. The game will try without loading add-ons."),
366  e.message);
367  });
368  load_game_config(reload_everything, classification, scenario_id);
369  } else if(preferences::core_id() != "default") {
372  _("Error loading custom game configuration files. The game will fallback to the default core files."),
373  e.message);
374  });
375  preferences::set_core_id("default");
376  game_config::no_addons = false;
377  load_game_config(reload_everything, classification, scenario_id);
378  } else {
381  _("Error loading default core game configuration files. The game will now exit."),
382  e.message);
383  });
384  throw;
385  }
386  }
387 
389 
390  // Set new binary paths.
392 }
393 static void show_deprecated_warnings(config& umc_cfg)
394 {
395  for(auto& units : umc_cfg.child_range("units")) {
396  for(auto& unit_type : units.child_range("unit_type")) {
397  for(const auto& advancefrom : unit_type.child_range("advancefrom")) {
398  auto symbols = utils::string_map {
399  {"lower_level", advancefrom["unit"]},
400  {"higher_level", unit_type["id"]}
401  };
402  auto message = VGETTEXT(
403  // TRANSLATORS: For example, 'Cuttle Fish' units will not be able to advance to 'Kraken'.
404  // The substituted strings are unit ids, not translated names; hopefully any add-ons
405  // that trigger this will be quickly fixed and stop triggering the warning.
406  "Error: [advancefrom] no longer works. ‘$lower_level’ units will not be able to advance to ‘$higher_level’; please ask the add-on author to use [modify_unit_type] instead.",
407  symbols);
408  deprecated_message("[advancefrom]", DEP_LEVEL::REMOVED, {1, 15, 4}, message);
409  }
410  unit_type.remove_children("advancefrom", [](const config&){return true;});
411  }
412  }
413 
414 
415  // hardcoded list of 1.14 advancement macros, just used for the error mesage below.
416  static const std::set<std::string> deprecated_defines {
417  "ENABLE_PARAGON",
418  "DISABLE_GRAND_MARSHAL",
419  "ENABLE_ARMAGEDDON_DRAKE",
420  "ENABLE_DWARVISH_ARCANISTER",
421  "ENABLE_DWARVISH_RUNESMITH",
422  "ENABLE_WOLF_ADVANCEMENT",
423  "ENABLE_NIGHTBLADE",
424  "ENABLE_TROLL_SHAMAN",
425  "ENABLE_ANCIENT_LICH",
426  "ENABLE_DEATH_KNIGHT",
427  "ENABLE_WOSE_SHAMAN"
428  };
429 
430  for(auto& campaign : umc_cfg.child_range("campaign")) {
431  for(auto str : utils::split(campaign["extra_defines"])) {
432  if(deprecated_defines.count(str) > 0) {
433  //TODO: we could try to implement a compatibility path by
434  // somehow getting the content of that macro from the
435  // cache_ object, but considering that 1) the breakage
436  // isn't that bad (just one disabled unit) and 2)
437  // it before also didn't work in all cases (see #4402)
438  // i don't think it is worth it.
440  "campaign id='" + campaign["id"].str() + "' has extra_defines=" + str,
442  {1, 15, 4},
443  _("instead, use the macro with the same name in the [campaign] tag")
444  );
445  }
446  }
447  }
448 }
449 
451 {
452  const std::string user_campaign_dir = filesystem::get_addons_dir();
453 
454  std::vector<std::string> error_log;
455  std::vector<std::string> error_addons;
456  std::vector<std::string> user_dirs;
457  std::vector<std::string> user_files;
458 
459  filesystem::get_files_in_dir(user_campaign_dir, &user_files, &user_dirs, filesystem::name_mode::ENTIRE_FILE_PATH);
460 
461  // Warn player about addons using the no-longer-supported single-file format.
462  for(const std::string& file : user_files) {
463  const int size_minus_extension = file.size() - 4;
464 
465  if(file.substr(size_minus_extension, file.size()) == ".cfg") {
466  ERR_CONFIG << "error reading usermade add-on '" << file << "'";
467 
468  error_addons.push_back(file);
469 
470  const int userdata_loc = file.find("data/add-ons") + 5;
471  const std::string log_msg = formatter()
472  << "The format '~"
473  << file.substr(userdata_loc)
474  << "' (for single-file add-ons) is not supported anymore, use '~"
475  << file.substr(userdata_loc, size_minus_extension - userdata_loc)
476  << "/_main.cfg' instead.";
477 
478  error_log.push_back(log_msg);
479  }
480  }
481 
482  loading_screen::spin();
483 
484  // Rerun the directory scan using filename only, to get the addon_ids more easily.
485  user_files.clear();
486  user_dirs.clear();
487 
488  filesystem::get_files_in_dir(user_campaign_dir, nullptr, &user_dirs,
490 
491  loading_screen::spin();
492 
493  // Load the addons.
494  for(const std::string& addon_id : user_dirs) {
495  log_scope2(log_config, "Loading add-on '" + addon_id + "'");
496  const std::string addon_dir = user_campaign_dir + "/" + addon_id;
497 
498  const std::string main_cfg = addon_dir + "/_main.cfg";
499  const std::string info_cfg = addon_dir + "/_info.cfg";
500 
501  if(!filesystem::file_exists(main_cfg)) {
502  continue;
503  }
504 
505  loading_screen::spin();
506 
507  // Try to find this addon's metadata. Author publishing info (_server.pbl) is given
508  // precedence over addon sever-generated info (_info.cfg). If neither are found, it
509  // probably means the addon was installed manually and certain defaults will be used.
510  config metadata;
511 
512  if(have_addon_pbl_info(addon_id)) {
513  // Publishing info needs to be read from disk.
514  try {
515  metadata = get_addon_pbl_info(addon_id, false);
516  } catch(const invalid_pbl_exception& e) {
517  const std::string log_msg = formatter()
518  << "The provided addon has an invalid pbl file"
519  << " for addon "
520  << addon_id;
521 
522  error_addons.push_back(e.message);
523  error_log.push_back(log_msg);
524  }
525  } else if(filesystem::file_exists(info_cfg)) {
526  // Addon server-generated info can be fetched from cache.
527  config temp;
528  cache_.get_config(info_cfg, temp);
529 
530  metadata = temp.child_or_empty("info");
531  }
532 
533  std::string using_core = metadata["core"];
534  if(using_core.empty()) {
535  using_core = "default";
536  }
537 
538  // Skip add-ons not matching our current core. Cores themselves should be selectable
539  // at all times, so they aren't considered here.
540  if(!metadata.empty() && metadata["type"] != "core" && using_core != preferences::core_id()) {
541  continue;
542  }
543 
544  std::string addon_title = metadata["title"].str();
545  if(addon_title.empty()) {
546  addon_title = addon_id;
547  }
548 
549  version_info addon_version(metadata["version"]);
550 
551  try {
552  std::unique_ptr<schema_validation::schema_validator> validator;
554  validator.reset(new schema_validation::schema_validator(filesystem::get_wml_location("schema/game_config.cfg")));
555  validator->set_create_exceptions(false); // Don't crash if there's an error, just go ahead anyway
556  }
557 
558  loading_screen::spin();
559 
560  // Load this addon from the cache to a config.
561  config umc_cfg;
562  cache_.get_config(main_cfg, umc_cfg, validator.get());
563 
564  static const std::set<std::string> tags_with_addon_id {
565  "era",
566  "modification",
567  "resource",
568  "multiplayer",
569  "scenario",
570  "campaign",
571  "test"
572  };
573 
574  // Annotate appropriate addon types with addon_id info.
575  for(auto child : umc_cfg.all_children_range()) {
576  if(tags_with_addon_id.count(child.key) > 0) {
577  auto& cfg = child.cfg;
578  cfg["addon_id"] = addon_id;
579  cfg["addon_title"] = addon_title;
580  // Note that this may reformat the string in a canonical form.
581  cfg["addon_version"] = addon_version.str();
582  }
583  }
584 
585  loading_screen::spin();
586 
587  show_deprecated_warnings(umc_cfg);
588 
589  loading_screen::spin();
590 
591  static const std::set<std::string> entry_tags {
592  "era",
593  "modification",
594  "resource",
595  "multiplayer",
596  "scenario",
597  "campaign"
598  };
599 
600  for(const std::string& tagname : entry_tags) {
601  game_config_.append_children_by_move(umc_cfg, tagname);
602  }
603 
604  loading_screen::spin();
605 
606  addon_cfgs_[addon_id] = std::move(umc_cfg);
607  } catch(const config::error& err) {
608  ERR_CONFIG << "config error reading usermade add-on '" << main_cfg << "'";
609  ERR_CONFIG << err.message;
610  error_addons.push_back(main_cfg);
611  error_log.push_back(err.message);
612  } catch(const preproc_config::error& err) {
613  ERR_CONFIG << "preprocessor config error reading usermade add-on '" << main_cfg << "'";
614  ERR_CONFIG << err.message;
615  error_addons.push_back(main_cfg);
616  error_log.push_back(err.message);
617  } catch(const filesystem::io_exception&) {
618  ERR_CONFIG << "filesystem I/O error reading usermade add-on '" << main_cfg << "'";
619  error_addons.push_back(main_cfg);
620  }
621  }
622 
625  ERR_CONFIG << "Didn’t find an add-on for --validate-addon - check whether the id has a typo";
626  const std::string log_msg = formatter()
627  << "Didn't find an add-on for --validate-addon - check whether the id has a typo";
628  error_log.push_back(log_msg);
629  throw game::error("Did not find an add-on for --validate-addon");
630  }
631 
632  WRN_CONFIG << "Note: for --validate-addon to find errors, you have to play (in the GUI) a game that uses the add-on.";
633  }
634 
635  if(!error_addons.empty()) {
636  const std::size_t n = error_addons.size();
637  const std::string& msg1 =
638  _n("The following add-on had errors and could not be loaded:",
639  "The following add-ons had errors and could not be loaded:",
640  n);
641  const std::string& msg2 =
642  _n("Please report this to the author or maintainer of this add-on.",
643  "Please report this to the respective authors or maintainers of these add-ons.",
644  n);
645 
646  const std::string& report = utils::join(error_log, "\n\n");
648  gui2::dialogs::wml_error::display(msg1, msg2, error_addons, report);
649  });
650  }
651 }
652 
654 {
655  config& hashes = game_config_.add_child("multiplayer_hashes");
656  for(const config& ch : game_config().child_range("multiplayer")) {
657  hashes[ch["id"].str()] = ch.hash();
658  }
659 }
660 
662 {
664  unit_types.set_config(game_config().merged_children_view("units"));
665 }
666 
668 {
669  // Rebuild addon version info cache.
671 
672  // Force a reload of configuration information.
674  old_defines_map_.clear();
677 
680 }
681 
683 {
686 }
687 
689  const game_classification& classification, const std::string& scenario_id)
690 {
692  !classification.difficulty.empty());
698  !classification.era_define.empty());
699  game_config::scoped_preproc_define multiplayer("MULTIPLAYER",
703 
704  //
705  // NOTE: these deques aren't used here, but the objects within are utilized as RAII helpers.
706  //
707 
708  std::deque<game_config::scoped_preproc_define> extra_defines;
709  for(const std::string& extra_define : classification.campaign_xtra_defines) {
710  extra_defines.emplace_back(extra_define);
711  }
712 
713  std::deque<game_config::scoped_preproc_define> modification_defines;
714  for(const std::string& mod_define : classification.mod_defines) {
715  modification_defines.emplace_back(mod_define, !mod_define.empty());
716  }
717 
718  try {
720  } catch(const game::error&) {
722 
723  std::deque<game_config::scoped_preproc_define> previous_defines;
724  for(const preproc_map::value_type& preproc : old_defines_map_) {
725  previous_defines.emplace_back(preproc.first);
726  }
727 
729  throw;
730  }
731 
732  // This needs to be done in the main thread since this function (load_game_config_for_game)
733  // might be called from a loading screen worker thread (and currently is, in fact). If the
734  // image cache is purged from the worker thread, there's a possibility for a data race where
735  // the main thread accesses the image cache and the worker thread simultaneously clears it.
737 }
738 
740 {
741  game_config::scoped_preproc_define multiplayer("MULTIPLAYER", is_mp);
742  game_config::scoped_preproc_define test("TEST", is_test);
743  game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest && is_mp);
744  /** During an mp game the default difficulty define is also defined so better already load it now if we already must reload config cache. */
747 
748  try {
750  } catch(const game::error&) {
752 
753  std::deque<game_config::scoped_preproc_define> previous_defines;
754  for (const preproc_map::value_type& preproc : old_defines_map_) {
755  previous_defines.emplace_back(preproc.first);
756  }
757 
759  throw;
760  }
761 }
762 
763 void game_config_manager::set_enabled_addon(std::set<std::string> addon_ids)
764 {
765  auto& vec = game_config_view_.data();
766  vec.clear();
767  vec.push_back(game_config_);
768 
769  for(const std::string& id : addon_ids) {
770  auto it = addon_cfgs_.find(id);
771  if(it != addon_cfgs_.end()) {
772  LOG_CONFIG << "Enabling add-on " << id;
773  vec.push_back(it->second);
774  } else {
775  ERR_CONFIG << "Attempted to enable add-on '" << id << "' but its config could not be found";
776  }
777  }
778 }
779 
781 {
782  active_addons_.clear();
783  auto& vec = game_config_view_.data();
784  vec.clear();
785  vec.push_back(game_config_);
786 
787  for(const auto& pair : addon_cfgs_) {
788  LOG_CONFIG << "Enabling add-on " << pair.first;
789  vec.push_back(pair.second);
790  active_addons_.emplace(pair.first);
791  }
792 }
config get_addon_pbl_info(const std::string &addon_name, bool do_validate)
Gets the publish information for an add-on.
Definition: manager.cpp:70
bool have_addon_pbl_info(const std::string &addon_name)
Returns whether a .pbl file is present for the specified add-on or not.
Definition: manager.cpp:65
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on's version information structs.
Definition: manager.cpp:388
Definitions for the terrain builder.
void reload()
Reads the mainline achievements.cfg and then all the achievements of each installed add-on.
static void init(const game_config_view &game_config)
Init the parameters of ai configuration parser.
std::optional< std::string > validate_addon
Non-empty if –validate-addon was given on the command line.
bool mptest
True if –mp-test was given on the command line.
bool multiplayer
True if –multiplayer was given on the command line.
bool validcache
True if –validcache was given on the command line.
bool noaddons
True if –noaddons was given on the command line.
std::optional< std::string > test
Non-empty if –test was given on the command line.
bool any_validation_option() const
True if the –validate or any of the –validate-* options are given.
bool validate_core
True if –validate-core was given on the command line.
bool nocache
True if –nocache was given on the command line.
std::optional< std::string > editor
Non-empty if –editor was given on the command line.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
void append(const config &cfg)
Append data from another config object to this one.
Definition: config.cpp:204
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
void append_children_by_move(config &cfg, const std::string &key)
Moves children with the given name from the given config to this one.
Definition: config.cpp:229
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
const_all_children_itors all_children_range() const
In-order iteration over all children.
Definition: config.cpp:887
child_itors child_range(config_key_type key)
Definition: config.cpp:273
bool empty() const
Definition: config.cpp:852
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
std::string hash() const
Definition: config.cpp:1287
config & add_child(config_key_type key)
Definition: config.cpp:441
std::ostringstream wrapper.
Definition: formatter.hpp:40
std::vector< std::string > campaign_xtra_defines
more customization of data
std::vector< std::string > mod_defines
If there are defines the modifications use to customize data.
std::set< std::string > active_addons(const std::string &scenario_id) const
std::string scenario_define
If there is a define the scenario uses to customize data.
std::string difficulty
The difficulty level the game is being played on.
std::string era_define
If there is a define the era uses to customize data.
std::string campaign_define
If there is a define the campaign uses to customize data.
Used to share macros between cache objects You have to create transaction object to load all macros t...
void lock()
Lock the transaction so no more macros are added.
void recheck_filetree_checksum()
Force cache checksum validation.
void set_use_cache(bool use)
Enable/disable caching.
const preproc_map & get_preproc_map() const
void clear_defines()
Clear stored defines map to default values.
bool clean_cache()
Deletes stale cache files not in use by the game.
void set_force_valid_cache(bool force)
Enable/disable cache validation.
void get_config(const std::string &path, config &cfg, abstract_validator *validator=nullptr)
Gets a config object from given path.
Used to set and unset scoped defines to preproc_map.
void load_game_config_with_loadscreen(FORCE_RELOAD_CONFIG force_reload, const game_classification *classification, const std::string &scenario_id)
@ FORCE_RELOAD
Always reload config.
@ NO_INCLUDE_RELOAD
Don't reload if the previous defines include the new defines.
@ NO_FORCE_RELOAD
Don't reload if the previous defines equal the new defines.
std::map< std::string, config > addon_cfgs_
bool init_game_config(FORCE_RELOAD_CONFIG force_reload)
static game_config_manager * get()
void load_game_config_for_game(const game_classification &classification, const std::string &scenario_id)
void load_game_config(bool reload_everything, const game_classification *classification, const std::string &scenario_id)
std::set< std::string > active_addons_
void load_game_config_for_create(bool is_mp, bool is_test=false)
filesystem::binary_paths_manager paths_manager_
game_config_view game_config_view_
game_config::config_cache & cache_
std::shared_ptr< terrain_type_data > tdata_
game_config_manager(const commandline_options &cmdline_opts)
void set_enabled_addon(std::set< std::string > addon_ids)
const game_config_view & game_config() const
const commandline_options & cmdline_opts_
config_array_view & data()
static void extract_preload_scripts(const game_config_view &game_config)
static void progress(loading_stage stage=loading_stage::none)
Report what is being loaded to the loading screen.
static void display(std::function< void()> f)
static void display(const std::string &summary, const std::string &post_summary, const std::vector< std::string > &files, const std::string &details)
The display function; see modal_dialog for more information.
Definition: wml_error.hpp:41
Realization of serialization/validator.hpp abstract validator.
static void set_terrain_rules_cfg(const game_config_view &cfg)
Set the config where we will parse the global terrain rules.
Definition: builder.cpp:289
static void set_known_themes(const game_config_view *cfg)
Copies the theme configs from the main game config.
Definition: theme.cpp:977
void set_config(const game_config_view &cfg)
Resets all data based on the provided config.
Definition: types.cpp:1101
A single unit type that the player may recruit.
Definition: types.hpp:43
Represents version numbers.
std::string str() const
Serializes the version number into string form.
Managing the AIs configuration - headers.
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
Definition: deprecation.cpp:29
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
const std::string DEFAULT_DIFFICULTY
The default difficulty setting for campaigns.
#define LOG_CONFIG
static game_config_manager * singleton
static void show_deprecated_warnings(config &umc_cfg)
#define ERR_CONFIG
#define WRN_CONFIG
static lg::log_domain log_config("config")
Interfaces for manipulating version numbers of engine, add-ons, etc.
static std::string _n(const char *str1, const char *str2, int n)
Definition: gettext.hpp:97
static std::string _(const char *str)
Definition: gettext.hpp:93
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:207
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:371
bool init_strings(const game_config_view &cfg)
Initializes certain English strings.
Definition: language.cpp:394
Standard logging facilities (interface).
#define log_scope2(domain, description)
Definition: log.hpp:275
#define FORCE_LOG_TO(logger, domain)
Definition: log.hpp:290
void set_about(const game_config_view &cfg)
Regenerates the credits data.
Definition: about.cpp:119
void call_in_main_thread(const std::function< void(void)> &f)
Definition: events.cpp:804
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs, name_mode mode, filter_mode filter, reorder_mode reorder, file_tree_checksum *checksum)
Get a list of all files and/or directories in a given directory.
Definition: filesystem.cpp:405
static bool file_exists(const bfs::path &fpath)
Definition: filesystem.cpp:319
std::string get_wml_location(const std::string &filename, const std::string &current_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
const file_tree_checksum & data_tree_checksum(bool reset=false)
Get the time at which the data/ tree was last modified at.
void clear_binary_paths_cache()
std::string get_addons_dir()
Game configuration data as global variables.
Definition: build_info.cpp:61
std::string path
Definition: filesystem.cpp:84
const version_info wesnoth_version(VERSION)
const bool & debug
Definition: game_config.cpp:91
static void add_color_info(const game_config_view &v, bool build_defaults)
void reset_color_info()
void load_config(const config &v)
void load_default_hotkeys(const game_config_view &cfg)
Registers all hotkeys present in this config.
constexpr uint32_t scope_main
void flush_cache()
Purges all image caches.
Definition: picture.cpp:216
logger & err()
Definition: log.cpp:302
log_domain & general()
Definition: log.cpp:328
logger & info()
Definition: log.cpp:314
void set_core_id(const std::string &core_id)
Definition: general.cpp:340
std::string last_cache_cleared_version()
Definition: general.cpp:1224
std::string era()
Definition: game.cpp:678
void load_hotkeys()
Definition: general.cpp:909
void set_last_cache_cleared_version(const std::string &version)
Definition: general.cpp:1220
void init_advanced_manager(const game_config_view &gc)
Initializes the manager singleton.
Definition: advanced.cpp:82
std::string core_id()
Definition: general.cpp:334
game_classification * classification
Definition: resources.cpp:34
void flush_cache()
Definition: sound.cpp:193
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::map< std::string, t_string > string_map
std::vector< std::string > split(const config_attribute_value &val)
std::map< std::string, struct preproc_define > preproc_map
One of the realizations of serialization/validator.hpp abstract validator.
void set_paths(const game_config_view &cfg)
An exception object used when an IO error occurs.
Definition: filesystem.hpp:64
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
Exception thrown when the WML parser fails to read a .pbl file.
Definition: manager.hpp:45
static map_location::DIRECTION n
Definitions related to theme-support.
unit_type_data unit_types
Definition: types.cpp:1486
#define e