Skip to content

Commit

Permalink
in fcn expand_mp_events, also collect addon_ids, for mp_settings
Browse files Browse the repository at this point in the history
At the same time that we expand multiplayer events, by looking up
the tags of the given ids from the game config, we also note their
addon_id field if present and write this list to the mp_settings,
which will become an attribute of the [multiplayer] tag for the
scenario. When the scenario is hosted, this will tell other
clients what addons they can download to be able to play.
  • Loading branch information
cbeck88 committed Mar 15, 2015
1 parent 1f793bb commit e334a50
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mp_game_settings.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/mp_game_settings.hpp
Expand Up @@ -40,6 +40,7 @@ struct mp_game_settings : public savegame::savegame_config
std::string mp_campaign;
std::string difficulty_define;
std::vector<std::string> active_mods;
std::vector<std::string> addon_ids;
std::map<std::string, std::string> side_users;

bool show_configure;
Expand Down
11 changes: 11 additions & 0 deletions src/saved_game.cpp
Expand Up @@ -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<modevents_entry> mods;
std::vector<std::string> addon_ids;

boost::copy( mp_settings_.active_mods
| boost::adaptors::transformed(modevents_entry_for("modification"))
Expand All @@ -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);
Expand All @@ -255,6 +265,7 @@ void saved_game::expand_mp_events()
}
}

mp_settings_.addon_ids = addon_ids;
this->starting_pos_["has_mod_events"] = true;
}
}
Expand Down

0 comments on commit e334a50

Please sign in to comment.