diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index 954f4beb2..50fe0d76d 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -29,6 +29,7 @@ static PtrVector all_params; // X-macros #define PARAM_PREFIX #define PARAM_DEFAULT(X) = X + #include "config/user_config.hpp" #include "config/saved_grand_prix.hpp" @@ -345,8 +346,11 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, // add the default list va_list arguments; va_start(arguments, nb_elements); - for (int i = 0; i < nb_elements; i++) - m_elements.push_back(T(va_arg(arguments, U))); + typedef std::pair DictThing; + for (int i = 0; i < nb_elements; i++) { + std::pair key_value_pair = va_arg(arguments, DictThing); + m_elements.insert(key_value_pair); + } va_end(arguments); // Cleans up the list } // MapUserConfigParam @@ -376,8 +380,11 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, // add the default list va_list arguments; va_start(arguments, nb_elements); - for (int i = 0; i < nb_elements; i++) - m_elements.push_back(va_arg(arguments, T)); + + for (int i = 0; i < nb_elements; i++) { + std::pair key_value_pair = va_arg(arguments, DictThing); + m_elements.insert(key_value_pair); + } va_end(arguments); // Cleans up the list } // MapUserConfigParam @@ -395,9 +402,8 @@ void MapUserConfigParam::write(std::ofstream& stream) const // actual elements //for (int n = 0; n::iterator it = m_elements.begin(); it != m_elements.end(); ++it) - { - stream << " " << it->first << "=\"" << it->second << "\"\n"; + for (const auto& kv : m_elements) { + stream << " " << kv.first << "=\"" << kv.second << "\"\n"; } stream << " >\n"; stream << " \n\n"; @@ -417,29 +423,29 @@ void MapUserConfigParam::findYourDataInAChildOf(const XMLNode* node) int attr_count = 0; child->get("Size", &attr_count); - for (int n = 0; n elt; std::string str; - child->get(StringUtils::toString(n), &str); - StringUtils::fromString(str, elt); - - // check if the element is already there : + child->get(kv.first, &str); + elt.first = kv.first; + elt.second = str.c_str(); + bool there = false; - for (unsigned int i = 0; i < m_elements.size(); i++) - { - if (elt == m_elements[i]) + + for (const auto& kvRHS : m_elements) { + if (elt.second == kvRHS.second) { there = true; break; } + } if (!there) { - m_elements.push_back(elt); + m_elements.insert(elt); } } - } // findYourDataInAChildOf // ---------------------------------------------------------------------------- diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index f76161f08..6f71d9389 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -178,7 +178,7 @@ public: m_elements = std::map(v); return m_elements; } }; // ListUserConfigParam -typedef MapUserConfigParam StringToStringUserConfigParam; +typedef MapUserConfigParam StringToStringUserConfigParam; // ============================================================================ class IntUserConfigParam : public UserConfigParam @@ -416,20 +416,7 @@ namespace UserConfigParams // ---- Gamemode setup - PARAM_PREFIX StringToStringUserConfigParam m_karts_per_gamemode - PARAM_DEFAULT(StringToStringUserConfigParam("karts_per_gamemode", "The karts per gamemode" - "Number of karts per gamemode. Order corresponds to Enum value", - 10, - "3", - "3", - "3", - "3", - "3", - "3", - "3", - "3", - "3", - "3")); + // ---- Wiimote data PARAM_PREFIX GroupUserConfigParam m_wiimote_group @@ -766,7 +753,15 @@ 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" + "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") + )); PARAM_PREFIX BoolUserConfigParam m_log_packets PARAM_DEFAULT( BoolUserConfigParam(false, "log-network-packets", "If all network packets should be logged") ); diff --git a/src/states_screens/track_info_screen.cpp b/src/states_screens/track_info_screen.cpp index 7e956dbf6..d13ec39b9 100644 --- a/src/states_screens/track_info_screen.cpp +++ b/src/states_screens/track_info_screen.cpp @@ -164,14 +164,19 @@ void TrackInfoScreen::init() m_ai_kart_spinner->setVisible(has_AI); getWidget("ai-text")->setVisible(has_AI); - std::vector karts_per_gamemode;//UserConfigParams::m_karts_per_gamemode; + UserConfigParams::m_num_karts; + std::map karts_per_gamemode = UserConfigParams::m_karts_per_gamemode; + auto data = UserConfigParams::m_karts_per_gamemode; if (has_AI) { m_ai_kart_spinner->setActive(true); int gamemode = race_manager->getMinorMode(); - int num_ai = stoi(karts_per_gamemode[gamemode]) - local_players; //TODO error caused by enums not being sequential - // Avoid negative numbers (which can happen if e.g. the number of karts + //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 // in a previous race was lower than the number of players now. if (num_ai < 0) num_ai = 0; @@ -247,7 +252,7 @@ void TrackInfoScreen::init() race_manager->setNumKarts(race_manager->getNumLocalPlayers()); //This is causing an error - karts_per_gamemode[race_manager->getMinorMode()] = std::to_string(race_manager->getNumLocalPlayers()); +/// 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(); }