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
This commit is contained in:
parent
8039a18aec
commit
dc43e3d5b2
@ -355,12 +355,9 @@ 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
|
||||
getKartTypeCharacteristic(m_kart_type, m_name);
|
||||
|
||||
// Combine kart type
|
||||
m_combined_characteristic->addCharacteristic(characteristic);
|
||||
|
||||
m_combined_characteristic->addCharacteristic(kart_properties_manager->
|
||||
|
@ -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<const std::string,
|
||||
std::unique_ptr<AbstractCharacteristic> >(name,
|
||||
std::unique_ptr<AbstractCharacteristic>(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<std::string, std::unique_ptr<AbstractCharacteristic> >::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();
|
||||
|
@ -49,6 +49,9 @@ private:
|
||||
/** List of all kart groups. */
|
||||
std::vector<std::string> m_all_groups;
|
||||
|
||||
/** List of all kart types. */
|
||||
std::vector<std::string> m_kart_types;
|
||||
|
||||
/** Mapping of group names to list of kart indices in each group. */
|
||||
std::map<std::string, std::vector<int> > 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;
|
||||
|
Loading…
Reference in New Issue
Block a user