diff --git a/src/mp_game_settings.cpp b/src/mp_game_settings.cpp index 75b40c28e918..1cae436cd51b 100644 --- a/src/mp_game_settings.cpp +++ b/src/mp_game_settings.cpp @@ -32,6 +32,7 @@ mp_game_settings::mp_game_settings() : mp_campaign(), difficulty_define(), active_mods(), + addon_ids(), side_users(), show_configure(true), show_connect(true), @@ -66,6 +67,7 @@ mp_game_settings::mp_game_settings(const config& cfg) , mp_campaign(cfg["mp_campaign"].str()) , difficulty_define(cfg["difficulty_define"].str()) , active_mods(utils::split(cfg["active_mods"], ',')) + , addon_ids(utils::split(cfg["addon_ids"], ',')) , side_users(utils::map_split(cfg["side_users"])) , show_configure(cfg["show_configure"].to_bool(true)) , show_connect(cfg["show_connect"].to_bool(true)) @@ -102,6 +104,7 @@ config mp_game_settings::to_config() const cfg["mp_campaign"] = mp_campaign; cfg["difficulty_define"] = difficulty_define; cfg["active_mods"] = utils::join(active_mods, ","); + cfg["addon_ids"] = utils::join(addon_ids, ","); cfg["side_users"] = utils::join_map(side_users); cfg["show_configure"] = show_configure; cfg["show_connect"] = show_connect; diff --git a/src/mp_game_settings.hpp b/src/mp_game_settings.hpp index ec25e552c949..b85334483a8d 100644 --- a/src/mp_game_settings.hpp +++ b/src/mp_game_settings.hpp @@ -40,6 +40,7 @@ struct mp_game_settings : public savegame::savegame_config std::string mp_campaign; std::string difficulty_define; std::vector active_mods; + std::vector addon_ids; std::map side_users; bool show_configure; diff --git a/src/saved_game.cpp b/src/saved_game.cpp index 7593c789e630..e89c042ea67d 100644 --- a/src/saved_game.cpp +++ b/src/saved_game.cpp @@ -221,12 +221,15 @@ struct modevents_entry_for std::string type_; }; +// Gets the ids of the mp_era and modifications which were set to be active, then fetches these configs from the game_config and copies their [event] and [lua] to the starting_pos_. +// At this time, also collect the addon_id attributes which appeared in them and put this list in the addon_ids attribute of the mp_settings. void saved_game::expand_mp_events() { expand_scenario(); if(this->starting_pos_type_ == STARTINGPOS_SCENARIO && !this->starting_pos_["has_mod_events"].to_bool(false)) { std::vector mods; + std::vector addon_ids; boost::copy( mp_settings_.active_mods | boost::adaptors::transformed(modevents_entry_for("modification")) @@ -239,10 +242,17 @@ void saved_game::expand_mp_events() if(const config& cfg = game_config_manager::get()-> game_config().find_child(mod.type, "id", mod.id)) { + // Note the addon_id + if (cfg.has_attribute("addon_id") && !cfg["addon_id"].empty()) { + addon_ids.push_back(cfg["addon_id"].str()); + } + + // Copy events BOOST_FOREACH(const config& modevent, cfg.child_range("event")) { this->starting_pos_.add_child("event", modevent); } + // Copy lua BOOST_FOREACH(const config& modlua, cfg.child_range("lua")) { this->starting_pos_.add_child("lua", modlua); @@ -255,6 +265,7 @@ void saved_game::expand_mp_events() } } + mp_settings_.addon_ids = addon_ids; this->starting_pos_["has_mod_events"] = true; } }