diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index 50fe0d76d..e2d93c2b8 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -426,10 +426,9 @@ void MapUserConfigParam::findYourDataInAChildOf(const XMLNode* node) for (const auto& kv : m_elements) { std::pair elt; - std::string str; - child->get(kv.first, &str); elt.first = kv.first; - elt.second = str.c_str(); + elt.second = kv.second; + bool there = false; diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 6f71d9389..ab58ddd2a 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -169,17 +169,19 @@ public: { return m_elements; } - float& operator=(const std::map& v) + std::map& operator=(const std::map& v) { - m_elements = std::map(v); return m_elements; + m_elements = std::map(v); + return m_elements; } - float& operator=(const MapUserConfigParam& v) + std::map& operator=(const MapUserConfigParam& v) { - m_elements = std::map(v); return m_elements; + m_elements = std::map(v); + return m_elements; } }; // ListUserConfigParam typedef MapUserConfigParam StringToStringUserConfigParam; - +typedef MapUserConfigParam IntToIntUserConfigParam; // ============================================================================ class IntUserConfigParam : public UserConfigParam { @@ -753,14 +755,14 @@ namespace UserConfigParams "stun.voxalot.com", "stun.voxgratia.org", "stun.xten.com") ); - PARAM_PREFIX StringToStringUserConfigParam m_karts_per_gamemode - PARAM_DEFAULT(StringToStringUserConfigParam("karts_per_gamemode", "The karts per gamemode" + PARAM_PREFIX IntToIntUserConfigParam m_karts_per_gamemode + PARAM_DEFAULT(IntToIntUserConfigParam("karts_per_gamemode", "The karts per gamemode" "Number of karts per gamemode. Order corresponds to Enum value", 4, - std::make_pair("3", "1"), - std::make_pair("f", "2"), - std::make_pair("e", "4"), - std::make_pair("te", "5") + std::make_pair(0, 1), + std::make_pair(1, 2), + std::make_pair(3, 4), + std::make_pair(4, 5) )); PARAM_PREFIX BoolUserConfigParam m_log_packets PARAM_DEFAULT( BoolUserConfigParam(false, "log-network-packets", diff --git a/src/states_screens/track_info_screen.cpp b/src/states_screens/track_info_screen.cpp index d13ec39b9..cab8ae795 100644 --- a/src/states_screens/track_info_screen.cpp +++ b/src/states_screens/track_info_screen.cpp @@ -165,21 +165,24 @@ void TrackInfoScreen::init() getWidget("ai-text")->setVisible(has_AI); UserConfigParams::m_num_karts; - std::map karts_per_gamemode = UserConfigParams::m_karts_per_gamemode; - auto data = UserConfigParams::m_karts_per_gamemode; + std::map karts_per_gamemode = UserConfigParams::m_karts_per_gamemode; if (has_AI) { m_ai_kart_spinner->setActive(true); int gamemode = race_manager->getMinorMode(); - //Temp fix - //int num_ai = stoi(karts_per_gamemode[ "3"/*gamemode*/]) - local_players; //TODO error caused by enums not being sequential - int num_ai = 1; - - // Avoid negative numbers (which can happen if e.g. the number of karts + int num_ai = karts_per_gamemode[gamemode]; + + // Avoid negative numbers (which can happen if e.g. the number of karts // in a previous race was lower than the number of players now. - if (num_ai < 0) num_ai = 0; + if (num_ai < 0) + { + num_ai = 0; + karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumPlayers(); + UserConfigParams::m_karts_per_gamemode = karts_per_gamemode; + } + m_ai_kart_spinner->setValue(num_ai); race_manager->setNumKarts(num_ai + local_players); @@ -250,11 +253,9 @@ void TrackInfoScreen::init() m_ai_kart_spinner->setValue(0); m_ai_kart_spinner->setActive(false); race_manager->setNumKarts(race_manager->getNumLocalPlayers()); - - //This is causing an error -/// karts_per_gamemode[race_manager->getMinorMode()] = std::to_string(race_manager->getNumLocalPlayers()); - // UserConfigParams::m_karts_per_gamemode = karts_per_gamemode; //TODO Causes error - UserConfigParams::m_num_karts = race_manager->getNumLocalPlayers(); + + karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumPlayers(); + UserConfigParams::m_karts_per_gamemode = karts_per_gamemode; } else if (record_available) {