From dc43e3d5b23105369c4dcfe09fb72cab788b3412 Mon Sep 17 00:00:00 2001 From: Alayan-stk-2 Date: Tue, 21 Aug 2018 02:52:10 +0200 Subject: [PATCH] Assign kart type to karts not having a valid one (#3385) * Fix #3375 * Remove debug print * Don't clear the list of kart types when changing resolution --- src/karts/kart_properties.cpp | 11 ++++------- src/karts/kart_properties_manager.cpp | 19 +++++++++++++++++-- src/karts/kart_properties_manager.hpp | 5 ++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 35c9111ee..5eb29e9af 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -355,13 +355,10 @@ void KartProperties::combineCharacteristics(PerPlayerDifficulty difficulty) // Try to get the kart type const AbstractCharacteristic *characteristic = kart_properties_manager-> - getKartTypeCharacteristic(m_kart_type); - if (!characteristic) - Log::warn("KartProperties", "Can't find kart type '%s' for kart '%s'", - m_kart_type.c_str(), m_name.c_str()); - else - // Kart type found - m_combined_characteristic->addCharacteristic(characteristic); + getKartTypeCharacteristic(m_kart_type, m_name); + + // Combine kart type + m_combined_characteristic->addCharacteristic(characteristic); m_combined_characteristic->addCharacteristic(kart_properties_manager-> getPlayerCharacteristic(getPerPlayerDifficultyAsString(difficulty))); diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 3398794d8..9be55c780 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -215,6 +215,7 @@ void KartPropertiesManager::loadCharacteristics(const XMLNode *root) for (const XMLNode *type : nodes) { type->get("name", &name); + m_kart_types.push_back(name); m_kart_type_characteristics.insert(std::pair >(name, std::unique_ptr(new XmlCharacteristic(type)))); @@ -303,10 +304,24 @@ const AbstractCharacteristic* KartPropertiesManager::getDifficultyCharacteristic } // getDifficultyCharacteristic //----------------------------------------------------------------------------- -const AbstractCharacteristic* KartPropertiesManager::getKartTypeCharacteristic(const std::string &type) const +const AbstractCharacteristic* KartPropertiesManager::getKartTypeCharacteristic(const std::string &type, + const std::string &name) const { + bool type_is_valid = false; + for (unsigned i=0; i < m_kart_types.size(); i++) + { + if (type == m_kart_types[i]) + type_is_valid = true; + } + + if (!type_is_valid) + Log::warn("KartProperties", "Can't find kart type '%s' for kart '%s', defaulting to '%s'.", + type.c_str(), name.c_str(), m_kart_types[0].c_str()); + + std::string valid_type = (type_is_valid) ? type : m_kart_types[0]; + std::map >::const_iterator - it = m_kart_type_characteristics.find(type); + it = m_kart_type_characteristics.find(valid_type); if (it == m_kart_type_characteristics.cend()) return nullptr; return it->second.get(); diff --git a/src/karts/kart_properties_manager.hpp b/src/karts/kart_properties_manager.hpp index 240413a80..4d92d4907 100644 --- a/src/karts/kart_properties_manager.hpp +++ b/src/karts/kart_properties_manager.hpp @@ -49,6 +49,9 @@ private: /** List of all kart groups. */ std::vector m_all_groups; + /** List of all kart types. */ + std::vector m_kart_types; + /** Mapping of group names to list of kart indices in each group. */ std::map > m_groups_2_indices; @@ -105,7 +108,7 @@ public: const AbstractCharacteristic* getDifficultyCharacteristic(const std::string &type) const; // ------------------------------------------------------------------------ /** Get a characteristic that holds the values for a kart type. */ - const AbstractCharacteristic* getKartTypeCharacteristic(const std::string &type) const; + const AbstractCharacteristic* getKartTypeCharacteristic(const std::string &type, const std::string &name) const; // ------------------------------------------------------------------------ /** Get a characteristic that holds the values for a player difficulty. */ const AbstractCharacteristic* getPlayerCharacteristic(const std::string &type) const;