19 #include "addon/manager.hpp"
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)
54 : cmdline_opts_(cmdline_opts)
78 if(
const std::string last_cleaned =
prefs::get()._last_cache_cleaned_ver(); !last_cleaned.empty()) {
141 return std::all_of(special.begin(), special.end(), [&
general](
const auto& pair) {
142 const auto it = general.find(pair.first);
143 return it != general.end() && it->second == pair.second;
153 out <<
"load_game_config: defines:";
156 out << pair.first <<
",";
166 bool reload_everything =
true;
171 reload_everything =
false;
175 reload_everything =
false;
179 LOG_CONFIG <<
"load_game_config reload everything: " << reload_everything;
202 if(reload_everything) {
216 std::vector<std::string> user_dirs;
219 std::vector<std::string> user_files;
224 for(
const std::string& umc : user_dirs) {
225 const std::string cores_file = umc +
"/cores.cfg";
235 bool current_core_valid =
false;
236 std::string wml_tree_root;
239 const std::string&
id = core[
"id"];
243 _(
"Error validating data core."),
244 _(
"Found a core without id attribute.")
245 +
'\n' +
_(
"Skipping the core."));
250 if(valid_cores.
find_child(
"core",
"id",
id)) {
253 _(
"Error validating data core."),
255 +
'\n' +
_(
"The ID is already in use.")
256 +
'\n' +
_(
"Skipping the core."));
261 const std::string&
path = core[
"path"];
265 _(
"Error validating data core."),
267 +
'\n' +
_(
"Core Path: ") +
path
268 +
'\n' +
_(
"File not found.")
269 +
'\n' +
_(
"Skipping the core."));
274 if(
id ==
"default" && !current_core_valid) {
275 wml_tree_root =
path;
278 current_core_valid =
true;
279 wml_tree_root =
path;
285 if(!current_core_valid) {
288 _(
"Error loading core data."),
290 +
'\n' +
_(
"Error loading the core with named id.")
291 +
'\n' +
_(
"Falling back to the default core."));
297 if(wml_tree_root.empty()) {
300 _(
"Error loading core data."),
301 _(
"Can’t locate the default core.")
302 +
'\n' +
_(
"The game will now exit."));
308 std::unique_ptr<schema_validation::schema_validator>
validator;
317 main_transaction.
lock();
331 LOG_CONFIG <<
"Configs not reloaded and active add-ons remain the same; returning early.";
356 ERR_CONFIG <<
"Error loading game configuration files\n" <<
e.message;
363 _(
"Error loading custom game configuration files. The game will try without loading add-ons."),
370 _(
"Error loading custom game configuration files. The game will fallback to the default core files."),
379 _(
"Error loading default core game configuration files. The game will now exit."),
394 for(
auto&
unit_type : units.child_range(
"unit_type")) {
395 for(
const auto& advancefrom :
unit_type.child_range(
"advancefrom")) {
397 {
"lower_level", advancefrom[
"unit"].str()},
404 "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.",
408 unit_type.remove_children(
"advancefrom");
414 static const std::set<std::string> deprecated_defines {
416 "DISABLE_GRAND_MARSHAL",
417 "ENABLE_ARMAGEDDON_DRAKE",
418 "ENABLE_DWARVISH_ARCANISTER",
419 "ENABLE_DWARVISH_RUNESMITH",
420 "ENABLE_WOLF_ADVANCEMENT",
422 "ENABLE_TROLL_SHAMAN",
423 "ENABLE_ANCIENT_LICH",
424 "ENABLE_DEATH_KNIGHT",
428 for(
auto& campaign : umc_cfg.
child_range(
"campaign")) {
429 for(
auto str :
utils::split(campaign[
"extra_defines"])) {
430 if(deprecated_defines.count(str) > 0) {
438 "campaign id='" + campaign[
"id"].str() +
"' has extra_defines=" + str,
441 _(
"instead, use the macro with the same name in the [campaign] tag")
452 std::vector<std::string> error_log;
453 std::vector<std::string> error_addons;
454 std::vector<std::string> user_dirs;
455 std::vector<std::string> user_files;
460 for(
const std::string& file : user_files) {
463 ERR_CONFIG <<
"error reading usermade add-on '" << file <<
"'";
465 error_addons.push_back(file);
471 <<
"' (for single-file add-ons) is not supported anymore, use '"
473 <<
"/_main.cfg' instead.";
475 error_log.push_back(log_msg);
479 loading_screen::spin();
488 loading_screen::spin();
491 for(
const std::string& addon_id : user_dirs) {
493 const std::string addon_dir = user_campaign_dir +
"/" + addon_id;
495 const std::string main_cfg = addon_dir +
"/_main.cfg";
496 const std::string info_cfg = addon_dir +
"/_info.cfg";
502 loading_screen::spin();
515 <<
"The provided addon has an invalid pbl file"
519 error_addons.push_back(
e.message);
520 error_log.push_back(log_msg);
530 std::string using_core = metadata[
"core"];
531 if(using_core.empty()) {
532 using_core =
"default";
537 if(!metadata.
empty() && metadata[
"type"] !=
"core" && using_core !=
prefs::get().core()) {
541 std::string addon_title = metadata[
"title"].str();
542 if(addon_title.empty()) {
543 addon_title = addon_id;
549 std::unique_ptr<schema_validation::schema_validator>
validator;
555 loading_screen::spin();
561 static const std::set<std::string> tags_with_addon_id {
573 if(tags_with_addon_id.count(key) > 0) {
574 cfg[
"addon_id"] = addon_id;
575 cfg[
"addon_title"] = addon_title;
577 cfg[
"addon_version"] = addon_version.
str();
581 loading_screen::spin();
585 loading_screen::spin();
587 static const std::set<std::string> entry_tags {
596 for(
const std::string& tagname : entry_tags) {
600 loading_screen::spin();
604 ERR_CONFIG <<
"config error reading usermade add-on '" << main_cfg <<
"'";
606 error_addons.push_back(main_cfg);
607 error_log.push_back(
err.message);
609 ERR_CONFIG <<
"preprocessor config error reading usermade add-on '" << main_cfg <<
"'";
611 error_addons.push_back(main_cfg);
612 error_log.push_back(
err.message);
614 ERR_CONFIG <<
"filesystem I/O error reading usermade add-on '" << main_cfg <<
"'";
615 error_addons.push_back(main_cfg);
621 ERR_CONFIG <<
"Didn’t find an add-on for --validate-addon - check whether the id has a typo";
623 <<
"Didn't find an add-on for --validate-addon - check whether the id has a typo";
624 error_log.push_back(log_msg);
625 throw game::error(
"Did not find an add-on for --validate-addon");
628 WRN_CONFIG <<
"Note: for --validate-addon to find errors, you have to play (in the GUI) a game that uses the add-on.";
631 if(!error_addons.empty()) {
632 const std::size_t
n = error_addons.size();
633 const std::string& msg1 =
634 _n(
"The following add-on had errors and could not be loaded:",
635 "The following add-ons had errors and could not be loaded:",
637 const std::string& msg2 =
638 _n(
"Please report this to the author or maintainer of this add-on.",
639 "Please report this to the respective authors or maintainers of these add-ons.",
642 const std::string& report =
utils::join(error_log,
"\n\n");
653 hashes[ch[
"id"].str()] = ch.
hash();
704 std::deque<game_config::scoped_preproc_define> extra_defines;
706 extra_defines.emplace_back(extra_define);
709 std::deque<game_config::scoped_preproc_define> modification_defines;
711 modification_defines.emplace_back(mod_define, !mod_define.empty());
719 std::deque<game_config::scoped_preproc_define> previous_defines;
721 previous_defines.emplace_back(preproc.first);
749 std::deque<game_config::scoped_preproc_define> previous_defines;
751 previous_defines.emplace_back(preproc.first);
765 for(
const std::string&
id : addon_ids) {
769 vec.push_back(it->second);
771 ERR_CONFIG <<
"Attempted to enable add-on '" <<
id <<
"' but its config could not be found";
784 LOG_CONFIG <<
"Enabling add-on " << pair.first;
785 vec.push_back(pair.second);
config get_addon_pbl_info(const std::string &addon_name, bool do_validate)
Gets the publish information for an add-on.
bool have_addon_pbl_info(const std::string &addon_name)
Returns whether a .pbl file is present for the specified add-on or not.
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on's version information structs.
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.
utils::optional< std::string > test
Non-empty if –test was given on the command line.
utils::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.
utils::optional< std::string > editor
Non-empty if –editor 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.
A config object defines a single node in a WML file, with access to child nodes.
void append(const config &cfg)
Append data from another config object to this one.
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.
auto all_children_view() const
In-order iteration over all children.
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.
child_itors child_range(config_key_type key)
void append_children_by_move(config &cfg, config_key_type key)
Moves children with the given name from the given config to this one.
config & add_child(config_key_type key)
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.
bool is_multiplayer() const
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)
achievements achievements_
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_
void set_enabled_addon_all()
game_config_view game_config_view_
preproc_map old_defines_map_
game_config::config_cache & cache_
std::shared_ptr< terrain_type_data > tdata_
void set_multiplayer_hashes()
void reload_changed_game_config()
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_
void load_game_config_for_editor()
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.
void load_advanced_prefs(const game_config_view &gc)
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.
static void set_known_themes(const game_config_view *cfg)
Copies the theme configs from the main game config.
void set_config(const game_config_view &cfg)
Resets all data based on the provided config.
A single unit type that the player may recruit.
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)
const std::string DEFAULT_DIFFICULTY
The default difficulty setting for campaigns.
static game_config_manager * singleton
static void show_deprecated_warnings(config &umc_cfg)
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)
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
bool init_strings(const game_config_view &cfg)
Initializes certain English strings.
Standard logging facilities (interface).
#define log_scope2(domain, description)
#define FORCE_LOG_TO(logger, domain)
void set_about(const game_config_view &cfg)
Regenerates the credits data.
void call_in_main_thread(const std::function< void(void)> &f)
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.
const std::string wml_extension
bool is_cfg(const std::string &filename)
Returns true if the file ends with the wmlfile extension.
static bool file_exists(const bfs::path &fpath)
utils::optional< std::string > get_wml_location(const std::string &path, const utils::optional< std::string > ¤t_dir)
Returns a translated path to the actual file or directory, if it exists.
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_short_wml_path(const std::string &filename)
Returns a short path to filename, skipping the (user) data directory.
std::string get_addons_dir()
Game configuration data as global variables.
const version_info wesnoth_version(VERSION)
static void add_color_info(const game_config_view &v, bool build_defaults)
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.
game_classification * classification
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.
Base class for all the errors encountered by the engine.
Exception thrown when the WML parser fails to read a .pbl file.
static map_location::direction n
Definitions related to theme-support.
unit_type_data unit_types