The Battle for Wesnoth  1.15.9+dev
game_config_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2018 by Andrius Silinskas <silinskas.andrius@gmail.com>
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 #include "game_config_manager.hpp"
16 
17 #include "about.hpp"
18 #include "addon/manager.hpp"
19 #include "ai/configuration.hpp"
20 #include "cursor.hpp"
21 #include "events.hpp"
22 #include "formatter.hpp"
23 #include "game_classification.hpp"
24 #include "game_config.hpp"
25 #include "game_version.hpp"
26 #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"
39 #include "terrain/builder.hpp"
40 #include "terrain/type_data.hpp"
41 #include "theme.hpp"
42 #include "units/types.hpp"
43 
44 static lg::log_domain log_config("config");
45 #define ERR_CONFIG LOG_STREAM(err, log_config)
46 #define WRN_CONFIG LOG_STREAM(warn, log_config)
47 #define LOG_CONFIG LOG_STREAM(info, log_config)
48 
50 
52  : cmdline_opts_(cmdline_opts)
53  , game_config_()
54  , game_config_view_()
55  , addon_cfgs_()
56  , active_addons_()
57  , old_defines_map_()
58  , paths_manager_()
59  , cache_(game_config::config_cache::instance())
60 {
61  assert(!singleton);
62  singleton = this;
63 
64  // All of the validation options imply --nocache, as the validation happens during cache
65  // rebuilding. If the cache isn't rebuilt, validation is silently skipped.
67  cache_.set_use_cache(false);
68  }
69 
72  }
73 }
74 
76 {
77  assert(singleton);
78  singleton = nullptr;
79 }
80 
82 {
83  return singleton;
84 }
85 
87 {
88  // Add preproc defines according to the command line arguments.
90  game_config::scoped_preproc_define test("TEST", cmdline_opts_.test.has_value());
93  game_config::scoped_preproc_define title_screen("TITLE_SCREEN",
95 
97 
99 
100  game_config::load_config(game_config().child("game_config"));
101 
104 
105  // Load the standard hotkeys, then apply any player customizations.
108 
109  // TODO: consider making this part of preferences::manager in some fashion
111 
115 
116  return true;
117 }
118 
119 namespace
120 {
121 /** returns true if every define in special is also defined in general */
122 bool map_includes(const preproc_map& general, const preproc_map& special)
123 {
124  return std::all_of(special.begin(), special.end(), [&general](const auto& pair) {
125  const auto it = general.find(pair.first);
126  return it != general.end() && it->second == pair.second;
127  });
128 }
129 } // end anonymous namespace
130 
132  FORCE_RELOAD_CONFIG force_reload, game_classification const*, std::optional<std::set<std::string>> active_addons)
133 {
134  if(!lg::info().dont_log(log_config)) {
135  auto out = formatter();
136  out << "load_game_config: defines:";
137 
138  for(const auto& pair : cache_.get_preproc_map()) {
139  out << pair.first << ",";
140  }
141 
142  out << "\n add_ons:";
143  if(active_addons) {
144  for(const auto& str : *active_addons) {
145  out << str << ",";
146  }
147  } else {
148  out << "\n Everything:";
149  }
150 
151  out << "\n";
152  FORCE_LOG_TO(lg::info(), log_config) << out.str();
153  }
154 
155  game_config::scoped_preproc_define debug_mode("DEBUG_MODE",
157 
158  bool reload_everything = true;
159 
160  // Game_config already holds requested config in memory.
161  if(!game_config_.empty()) {
162  if((force_reload == NO_FORCE_RELOAD) && old_defines_map_ == cache_.get_preproc_map()) {
163  reload_everything = false;
164  }
165 
166  if((force_reload == NO_INCLUDE_RELOAD) && map_includes(old_defines_map_, cache_.get_preproc_map())) {
167  reload_everything = false;
168  }
169 
170  if(!reload_everything && active_addons == active_addons_) {
171  LOG_CONFIG << "load_game_config aborting\n";
172  return;
173  }
174  }
175 
176  active_addons_ = active_addons;
177 
178  LOG_CONFIG << "load_game_config: everything:" << reload_everything << "\n";
179 
180  gui2::dialogs::loading_screen::display([this, reload_everything]() {
181  load_game_config(reload_everything);
182  });
183 }
184 
185 void game_config_manager::load_game_config(bool reload_everything)
186 {
187  // Make sure that 'debug mode' symbol is set
188  // if command line parameter is selected
189  // also if we're in multiplayer and actual debug mode is disabled.
190 
191  // The loadscreen will erase the titlescreen.
192  // NOTE: even without loadscreen, needed after MP lobby.
193  try {
194  // Read all game configs.
195  // First we load all core configs, the mainline one and the ones from the addons.
196  // Validate the cores and discard the invalid.
197  // Then find the path to the selected core.
198  // Load the selected core.
199  // Handle terrains so that they are last loaded from the core.
200  // Load every compatible addon.
201  if(reload_everything) {
205 
206  // Start transaction so macros are shared.
207  game_config::config_cache_transaction main_transaction;
208 
209  // Load mainline cores definition file.
210  config cores_cfg;
211  cache_.get_config(game_config::path + "/data/cores.cfg", cores_cfg);
212 
213  // Append the $user_campaign_dir/*/cores.cfg files to the cores.
214  std::vector<std::string> user_dirs;
215  {
216  const std::string user_campaign_dir = filesystem::get_addons_dir();
217  std::vector<std::string> user_files;
219  user_campaign_dir, &user_files, &user_dirs, filesystem::name_mode::ENTIRE_FILE_PATH);
220  }
221 
222  for(const std::string& umc : user_dirs) {
223  const std::string cores_file = umc + "/cores.cfg";
224  if(filesystem::file_exists(cores_file)) {
225  config cores;
226  cache_.get_config(cores_file, cores);
227  cores_cfg.append(cores);
228  }
229  }
230 
231  // Validate every core
232  config valid_cores;
233  bool current_core_valid = false;
234  std::string wml_tree_root;
235 
236  for(const config& core : cores_cfg.child_range("core")) {
237  const std::string& id = core["id"];
238  if(id.empty()) {
241  _("Error validating data core."),
242  _("Found a core without id attribute.")
243  + '\n' + _("Skipping the core."));
244  });
245  continue;
246  }
247 
248  if(*&valid_cores.find_child("core", "id", id)) {
251  _("Error validating data core."),
252  _("Core ID: ") + id
253  + '\n' + _("The ID is already in use.")
254  + '\n' + _("Skipping the core."));
255  });
256  continue;
257  }
258 
259  const std::string& path = core["path"];
263  _("Error validating data core."),
264  _("Core ID: ") + id
265  + '\n' + _("Core Path: ") + path
266  + '\n' + _("File not found.")
267  + '\n' + _("Skipping the core."));
268  });
269  continue;
270  }
271 
272  if(id == "default" && !current_core_valid) {
273  wml_tree_root = path;
274  }
275  if(id == preferences::core_id()) {
276  current_core_valid = true;
277  wml_tree_root = path;
278  }
279 
280  valid_cores.add_child("core", core); // append(core);
281  }
282 
283  if(!current_core_valid) {
286  _("Error loading core data."),
287  _("Core ID: ") + preferences::core_id()
288  + '\n' + _("Error loading the core with named id.")
289  + '\n' + _("Falling back to the default core."));
290  });
291  preferences::set_core_id("default");
292  }
293 
294  // check if we have a valid default core which should always be the case.
295  if(wml_tree_root.empty()) {
298  _("Error loading core data."),
299  _("Can't locate the default core.")
300  + '\n' + _("The game will now exit."));
301  });
302  throw;
303  }
304 
305  // Load the selected core
306  std::unique_ptr<schema_validation::schema_validator> validator;
308  validator.reset(new schema_validation::schema_validator(filesystem::get_wml_location("schema/game_config.cfg")));
309  validator->set_create_exceptions(false); // Don't crash if there's an error, just go ahead anyway
310  }
311 
312  cache_.get_config(filesystem::get_wml_location(wml_tree_root), game_config_, validator.get());
313  game_config_.append(valid_cores);
314 
315  main_transaction.lock();
316 
318  load_addons_cfg();
319  }
320  }
321 
322  if(active_addons_) {
324  } else {
326  }
327 
328  // Extract the Lua scripts at toplevel.
330 
331  set_unit_data();
333  tdata_ = std::make_shared<terrain_type_data>(game_config());
336 
338 
340 
341  } catch(const game::error& e) {
342  ERR_CONFIG << "Error loading game configuration files\n" << e.message << '\n';
343 
344  // Try reloading without add-ons
346  game_config::no_addons = true;
349  _("Error loading custom game configuration files. The game will try without loading add-ons."),
350  e.message);
351  });
352  load_game_config(reload_everything);
353  } else if(preferences::core_id() != "default") {
356  _("Error loading custom game configuration files. The game will fallback to the default core files."),
357  e.message);
358  });
359  preferences::set_core_id("default");
360  game_config::no_addons = false;
361  load_game_config(reload_everything);
362  } else {
365  _("Error loading default core game configuration files. The game will now exit."),
366  e.message);
367  });
368  throw;
369  }
370  }
371 
373 
374  // Set new binary paths.
376 }
377 
379 {
380  const std::string user_campaign_dir = filesystem::get_addons_dir();
381 
382  std::vector<std::string> error_log;
383  std::vector<std::string> error_addons;
384  std::vector<std::string> user_dirs;
385  std::vector<std::string> user_files;
386 
387  filesystem::get_files_in_dir(user_campaign_dir, &user_files, &user_dirs, filesystem::name_mode::ENTIRE_FILE_PATH);
388 
389  // Warn player about addons using the no-longer-supported single-file format.
390  for(const std::string& file : user_files) {
391  const int size_minus_extension = file.size() - 4;
392 
393  if(file.substr(size_minus_extension, file.size()) == ".cfg") {
394  ERR_CONFIG << "error reading usermade add-on '" << file << "'\n";
395 
396  error_addons.push_back(file);
397 
398  const int userdata_loc = file.find("data/add-ons") + 5;
399  const std::string log_msg = formatter()
400  << "The format '~"
401  << file.substr(userdata_loc)
402  << "' (for single-file add-ons) is not supported anymore, use '~"
403  << file.substr(userdata_loc, size_minus_extension - userdata_loc)
404  << "/_main.cfg' instead.";
405 
406  error_log.push_back(log_msg);
407  }
408  }
409 
410  // Rerun the directory scan using filename only, to get the addon_ids more easily.
411  user_files.clear();
412  user_dirs.clear();
413 
414  filesystem::get_files_in_dir(user_campaign_dir, nullptr, &user_dirs,
416 
417  // Load the addons.
418  for(const std::string& addon_id : user_dirs) {
419  log_scope2(log_config, "Loading add-on '" + addon_id + "'");
420  const std::string addon_dir = user_campaign_dir + "/" + addon_id;
421 
422  const std::string main_cfg = addon_dir + "/_main.cfg";
423  const std::string info_cfg = addon_dir + "/_info.cfg";
424 
425  if(!filesystem::file_exists(main_cfg)) {
426  continue;
427  }
428 
429  // Try to find this addon's metadata. Author publishing info (_server.pbl) is given
430  // precedence over addon sever-generated info (_info.cfg). If neither are found, it
431  // probably means the addon was installed manually and certain defaults will be used.
432  config metadata;
433 
434  if(have_addon_pbl_info(addon_id)) {
435  // Publishing info needs to be read from disk.
436  try {
437  metadata = get_addon_pbl_info(addon_id);
438  } catch(const invalid_pbl_exception& e) {
439  const std::string log_msg = formatter()
440  << "The provided addon has an invalid pbl file"
441  << " for addon "
442  << addon_id;
443 
444  error_addons.push_back(e.message);
445  error_log.push_back(log_msg);
446  }
447  } else if(filesystem::file_exists(info_cfg)) {
448  // Addon server-generated info can be fetched from cache.
449  config temp;
450  cache_.get_config(info_cfg, temp);
451 
452  metadata = temp.child_or_empty("info");
453  }
454 
455  std::string using_core = metadata["core"];
456  if(using_core.empty()) {
457  using_core = "default";
458  }
459 
460  // Skip add-ons not matching our current core. Cores themselves should be selectable
461  // at all times, so they aren't considered here.
462  if(!metadata.empty() && metadata["type"] != "core" && using_core != preferences::core_id()) {
463  continue;
464  }
465 
466  std::string addon_title = metadata["title"].str();
467  if(addon_title.empty()) {
468  addon_title = addon_id;
469  }
470 
471  version_info addon_version(metadata["version"]);
472 
473  try {
474  std::unique_ptr<schema_validation::schema_validator> validator;
476  validator.reset(new schema_validation::schema_validator(filesystem::get_wml_location("schema/game_config.cfg")));
477  validator->set_create_exceptions(false); // Don't crash if there's an error, just go ahead anyway
478  }
479 
480  // Load this addon from the cache to a config.
481  config umc_cfg;
482  cache_.get_config(main_cfg, umc_cfg, validator.get());
483 
484  static const std::set<std::string> tags_with_addon_id {
485  "era",
486  "modification",
487  "resource",
488  "multiplayer",
489  "scenario",
490  "campaign"
491  };
492 
493  // Annotate appropriate addon types with addon_id info.
494  for(auto child : umc_cfg.all_children_range()) {
495  if(tags_with_addon_id.count(child.key) > 0) {
496  auto& cfg = child.cfg;
497  cfg["addon_id"] = addon_id;
498  cfg["addon_title"] = addon_title;
499  // Note that this may reformat the string in a canonical form.
500  cfg["addon_version"] = addon_version.str();
501  }
502  }
503 
504  config advancefroms;
505  for(auto& units : umc_cfg.child_range("units")) {
506  for(auto& unit_type : units.child_range("unit_type")) {
507  for(const auto& advancefrom : units.child_range("advancefrom")) {
508  config modify_unit_type {
509  "type", unit_type["id"],
510  "add_advancement", advancefrom["unit"],
511  "set_experience", advancefrom["experience"]
512  };
514  "[advancefrom]",
516  {1, 17, 0},
517  _("Use [modify_unit_type]\n") + modify_unit_type.debug() + "\n [/modify_unit_type] instead in [campaign]"
518  );
519 
520  advancefroms.add_child("modify_unit_type", modify_unit_type);
521  }
522  unit_type.remove_children("advancefrom", [](const config&){return true;});
523  }
524  }
525 
526  // hardcoded list of 1.14 advancement macros, just used for the error mesage below.
527  static const std::set<std::string> deprecated_defines {
528  "ENABLE_PARAGON",
529  "DISABLE_GRAND_MARSHAL",
530  "ENABLE_ARMAGEDDON_DRAKE",
531  "ENABLE_DWARVISH_ARCANISTER",
532  "ENABLE_DWARVISH_RUNESMITH",
533  "ENABLE_WOLF_ADVANCEMENT",
534  "ENABLE_NIGHTBLADE",
535  "ENABLE_TROLL_SHAMAN",
536  "ENABLE_ANCIENT_LICH",
537  "ENABLE_DEATH_KNIGHT",
538  "ENABLE_WOSE_SHAMAN"
539  };
540 
541  for(auto& campaign : umc_cfg.child_range("campaign")) {
542  campaign.append_children(std::move(advancefroms));
543 
544  for(auto str : utils::split(campaign["extra_defines"])) {
545  if(deprecated_defines.count(str) > 0) {
546  //TODO: we could try to implement a compatibility path by
547  // somehow getting the content of that macro from the
548  // cache_ object, but considering that 1) the breakage
549  // isn't that bad (just one disabled unit) and 2)
550  // it before also didn't work in all cases (see #4402)
551  // i don't think it is worth it.
553  "extra_defines=" + str,
555  {1, 15, 4},
556  _("instead, use the macro with the same name in the [campaign] tag")
557  );
558  }
559  }
560  }
561 
562  static const std::set<std::string> entry_tags {
563  "era",
564  "modification",
565  "resource",
566  "multiplayer",
567  "scenario",
568  "campaign"
569  };
570 
571  for(const std::string& tagname : entry_tags) {
572  game_config_.append_children_by_move(umc_cfg, tagname);
573  }
574 
575  addon_cfgs_[addon_id] = std::move(umc_cfg);
576  } catch(const config::error& err) {
577  ERR_CONFIG << "error reading usermade add-on '" << main_cfg << "'" << std::endl;
578  ERR_CONFIG << err.message << '\n';
579  error_addons.push_back(main_cfg);
580  error_log.push_back(err.message);
581  } catch(const preproc_config::error& err) {
582  ERR_CONFIG << "error reading usermade add-on '" << main_cfg << "'" << std::endl;
583  ERR_CONFIG << err.message << '\n';
584  error_addons.push_back(main_cfg);
585  error_log.push_back(err.message);
586  } catch(const filesystem::io_exception&) {
587  ERR_CONFIG << "error reading usermade add-on '" << main_cfg << "'" << std::endl;
588  error_addons.push_back(main_cfg);
589  }
590  }
591 
594  ERR_CONFIG << "Didn’t find an add-on for --validate-addon - check whether the id has a typo" << std::endl;
595  const std::string log_msg = formatter()
596  << "Didn't find an add-on for --validate-addon - check whether the id has a typo";
597  error_log.push_back(log_msg);
598  throw game::error("Did not find an add-on for --validate-addon");
599  }
600 
601  WRN_CONFIG << "Note: for --validate-addon to find errors, you have to play (in the GUI) a game that uses the add-on.";
602  }
603 
604  if(!error_addons.empty()) {
605  const std::size_t n = error_addons.size();
606  const std::string& msg1 =
607  _n("The following add-on had errors and could not be loaded:",
608  "The following add-ons had errors and could not be loaded:",
609  n);
610  const std::string& msg2 =
611  _n("Please report this to the author or maintainer of this add-on.",
612  "Please report this to the respective authors or maintainers of these add-ons.",
613  n);
614 
615  const std::string& report = utils::join(error_log, "\n\n");
617  gui2::dialogs::wml_error::display(msg1, msg2, error_addons, report);
618  });
619  }
620 }
621 
623 {
624  config& hashes = game_config_.add_child("multiplayer_hashes");
625  for(const config& ch : game_config().child_range("multiplayer")) {
626  hashes[ch["id"].str()] = ch.hash();
627  }
628 }
629 
631 {
633  unit_types.set_config(game_config().merged_children_view("units"));
634 }
635 
637 {
638  // Rebuild addon version info cache.
640 
641  // Force a reload of configuration information.
643  old_defines_map_.clear();
646 
649 }
650 
652 {
655 }
656 
658  const game_classification& classification, const std::string& scenario_id)
659 {
660  game_config::scoped_preproc_define difficulty(classification.difficulty,
661  !classification.difficulty.empty());
662  game_config::scoped_preproc_define campaign(classification.campaign_define,
663  !classification.campaign_define.empty());
664  game_config::scoped_preproc_define scenario(classification.scenario_define,
665  !classification.scenario_define.empty());
667  !classification.era_define.empty());
668  game_config::scoped_preproc_define multiplayer("MULTIPLAYER",
669  classification.is_multiplayer());
671  classification.is_multiplayer());
672 
673  //
674  // NOTE: these deques aren't used here, but the objects within are utilized as RAII helpers.
675  //
676 
677  std::deque<game_config::scoped_preproc_define> extra_defines;
678  for(const std::string& extra_define : classification.campaign_xtra_defines) {
679  extra_defines.emplace_back(extra_define);
680  }
681 
682  std::deque<game_config::scoped_preproc_define> modification_defines;
683  for(const std::string& mod_define : classification.mod_defines) {
684  modification_defines.emplace_back(mod_define, !mod_define.empty());
685  }
686 
687  try {
688  load_game_config_with_loadscreen(NO_FORCE_RELOAD, &classification, classification.active_addons(scenario_id));
689  } catch(const game::error&) {
691 
692  std::deque<game_config::scoped_preproc_define> previous_defines;
693  for(const preproc_map::value_type& preproc : old_defines_map_) {
694  previous_defines.emplace_back(preproc.first);
695  }
696 
698  throw;
699  }
700 
701  // This needs to be done in the main thread since this function (load_game_config_for_game)
702  // might be called from a loading screen worker thread (and currently is, in fact). If the
703  // image cache is purged from the worker thread, there's a possibility for a data race where
704  // the main thread accesses the image cache and the worker thread simultaneously clears it.
706 }
707 
709 {
710  game_config::scoped_preproc_define multiplayer("MULTIPLAYER", is_mp);
711  game_config::scoped_preproc_define test("TEST", is_test);
712  game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest && is_mp);
713  /** During an mp game the default difficulty define is also defined so better already load it now if we already must reload config cache. */
716 
717  try {
719  } catch(const game::error&) {
721 
722  std::deque<game_config::scoped_preproc_define> previous_defines;
723  for (const preproc_map::value_type& preproc : old_defines_map_) {
724  previous_defines.emplace_back(preproc.first);
725  }
726 
728  throw;
729  }
730 }
731 
732 void game_config_manager::set_enabled_addon(std::set<std::string> addon_ids)
733 {
734  auto& vec = game_config_view_.data();
735  vec.clear();
736  vec.push_back(game_config_);
737 
738  for(const std::string& id : addon_ids) {
739  auto it = addon_cfgs_.find(id);
740  if(it != addon_cfgs_.end()) {
741  vec.push_back(it->second);
742  }
743  }
744 }
745 
747 {
748  auto& vec = game_config_view_.data();
749  vec.clear();
750  vec.push_back(game_config_);
751 
752  for(const auto& pair : addon_cfgs_) {
753  vec.push_back(pair.second);
754  }
755 }
Don&#39;t reload if the previous defines include the new defines.
static std::string _n(const char *str1, const char *str2, int n)
Definition: gettext.hpp:96
bool any_validation_option() const
True if the –validate or any of the –validate-* options are given.
bool mptest
True if –mp-test was given on the command line.
const_all_children_itors all_children_range() const
In-order iteration over all children.
Definition: config.cpp:921
std::string era()
Definition: game.cpp:689
Interfaces for manipulating version numbers of engine, add-ons, etc.
std::optional< std::string > test
Non-empty if –test was given on the command line.
game_classification * classification
Definition: resources.cpp:34
void append(const config &cfg)
Append data from another config object to this one.
Definition: config.cpp:287
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
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:312
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:836
static l_noret error(LoadState *S, const char *why)
Definition: lundump.cpp:39
bool noaddons
True if –noaddons was given on the command line.
logger & info()
Definition: log.cpp:91
Exception thrown when the WML parser fails to read a .pbl file.
Definition: manager.hpp:43
void lock()
Lock the transaction so no more macros are added.
void set_scope_active(scope s, bool set)
static bool file_exists(const bfs::path &fpath)
Definition: filesystem.cpp:263
static void init(const game_config_view &game_config)
Init the parameters of ai configuration parser.
child_itors child_range(config_key_type key)
Definition: config.cpp:362
filesystem::binary_paths_manager paths_manager_
static void progress(loading_stage stage=loading_stage::none)
void load_game_config_for_game(const game_classification &classification, const std::string &scenario_id)
const std::string DEFAULT_DIFFICULTY
The default difficulty setting for campaigns.
#define ERR_CONFIG
static void set_known_themes(const game_config_view *cfg)
Definition: theme.cpp:919
unit_type_data unit_types
Definition: types.cpp:1441
Don&#39;t reload if the previous defines equal the new defines.
static lg::log_domain log_config("config")
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:356
static std::string _(const char *str)
Definition: gettext.hpp:92
void load_config(const config &v)
A single unit type that the player may recruit.
Definition: types.hpp:44
Used to set and unset scoped defines to preproc_map.
void call_in_main_thread(const std::function< void(void)> &f)
Definition: events.cpp:867
void flush_cache()
Purges all image caches.
Definition: picture.cpp:222
void clear_binary_paths_cache()
One of the realizations of serialization/validator.hpp abstract validator.
#define LOG_CONFIG
static game_config_manager * get()
void set_about(const game_config_view &cfg)
Regenerates the credits data.
Definition: about.cpp:114
std::set< std::string > active_addons(const std::string &scenario_id) const
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
Definition: deprecation.cpp:29
void load_hotkeys()
Definition: general.cpp:864
std::optional< std::set< std::string > > active_addons_
std::ostringstream wrapper.
Definition: formatter.hpp:38
const std::string message
Error message to display.
Definition: manager.hpp:59
std::optional< std::string > validate_addon
Non-empty if –validate-addon was given on the command line.
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)
Populates &#39;files&#39; with all the files and &#39;dirs&#39; with all the directories in dir.
Definition: filesystem.cpp:349
std::string campaign_define
If there is a define the campaign uses to customize data.
const game_config_view & game_config() const
game_config_view game_config_view_
void set_force_valid_cache(bool force)
Enable/disable cache validation.
void set_core_id(const std::string &core_id)
Definition: general.cpp:318
static game_config_manager * singleton
std::string path
Definition: game_config.cpp:39
#define log_scope2(domain, description)
Definition: log.hpp:209
bool multiplayer
True if –multiplayer was given on the command line.
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on&#39;s version information structs.
Definition: manager.cpp:355
static void add_color_info(const game_config_view &v, bool build_defaults)
void deactivate_all_scopes()
bool init_strings(const game_config_view &cfg)
Initializes certain English strings.
Definition: language.cpp:379
log_domain & general()
Definition: log.cpp:105
config get_addon_pbl_info(const std::string &addon_name)
Gets the publish information for an add-on.
Definition: manager.cpp:67
std::string era_define
If there is a define the era uses to customize data.
void flush_cache()
Definition: sound.cpp:194
void get_config(const std::string &path, config &cfg, abstract_validator *validator=nullptr)
Gets a config object from given path.
void set_use_cache(bool use)
Enable/disable caching.
#define FORCE_LOG_TO(logger, domain)
Definition: log.hpp:221
void clear_defines()
Clear stored defines map to default values.
bool nocache
True if –nocache was given on the command line.
logger & err()
Definition: log.cpp:79
void set_enabled_addon(std::set< std::string > addon_ids)
std::vector< std::string > campaign_xtra_defines
more customization of data
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&#39;t pres...
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:62
void load_game_config_for_create(bool is_mp, bool is_test=false)
Game configuration data as global variables.
Definition: build_info.cpp:56
const preproc_map & get_preproc_map() const
An exception object used when an IO error occurs.
Definition: filesystem.hpp:45
void reset_color_info()
std::string scenario_define
If there is a define the scenario uses to customize data.
std::vector< std::string > mod_defines
If there are defines the modifications use to customize data.
Definitions related to theme-support.
const bool & debug
Definitions for the terrain builder.
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:54
Represents version numbers.
config & add_child(config_key_type key)
Definition: config.cpp:476
const file_tree_checksum & data_tree_checksum(bool reset=false)
Get the time at which the data/ tree was last modified at.
std::string difficulty
The difficulty level the game is being played on.
std::string core_id()
Definition: general.cpp:312
Used to share macros between cache objects You have to create transaction object to load all macros t...
void set_paths(const game_config_view &cfg)
static void display(std::function< void()> f)
game_config_manager(const commandline_options &cmdline_opts)
void set_config(const game_config_view &cfg)
Resets all data based on the provided config.
Definition: types.cpp:1066
std::vector< std::string > split(const config_attribute_value &val)
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
std::string get_addons_dir()
Managing the AIs configuration - headers.
bool validate_core
True if –validate-core was given on the command line.
void load_game_config(bool reload_everything)
Standard logging facilities (interface).
std::string str() const
Serializes the version number into string form.
std::string message
Definition: exceptions.hpp:31
const commandline_options & cmdline_opts_
bool validcache
True if –validcache was given on the command line.
std::optional< std::string > editor
Non-empty if –editor was given on the command line.
game_config::config_cache & cache_
std::map< std::string, struct preproc_define > preproc_map
#define e
Realization of serialization/validator.hpp abstract validator.
void load_hotkeys(const game_config_view &cfg, bool set_as_default)
Iterates through all hotkeys present in the config struct and creates and adds them to the hotkey lis...
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:453
#define WRN_CONFIG
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:60
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:291
static map_location::DIRECTION n
void load_game_config_with_loadscreen(FORCE_RELOAD_CONFIG force_reload, game_classification const *classification=nullptr, std::optional< std::set< std::string >> active_addons={})
bool init_game_config(FORCE_RELOAD_CONFIG force_reload)
std::map< std::string, config > addon_cfgs_
std::string hash() const
Definition: config.cpp:1335
config_array_view & data()
void init_advanced_manager(const game_config_view &gc)
Initializes the manager singleton.
Definition: advanced.cpp:71
bool empty() const
Definition: config.cpp:884
static void extract_preload_scripts(const game_config_view &game_config)
std::shared_ptr< terrain_type_data > tdata_
void recheck_filetree_checksum()
Force cache checksum validation.