Fix the display of achievement progress: avoid that a value can be
larger than the goal value (otherwise after racing one track 12 times the progress for Christoffel would should 12/10).
This commit is contained in:
parent
4139d145cf
commit
36c9c4d6c3
@ -139,16 +139,29 @@ irr::core::stringw Achievement::getProgressAsString()
|
||||
} // getProgressAsString
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Increases the value of a key by a specified amount.
|
||||
/** Increases the value of a key by a specified amount, but make sure to not
|
||||
* increase the value above the goal (otherwise the achievement progress
|
||||
* could be 12/10 (e.g. if one track is used 12 times for the Christoffel
|
||||
* achievement), even though the achievement is not achieved.
|
||||
* \param key The key whose value is increased.
|
||||
* \param increase Amount to add to the value of this key.
|
||||
*/
|
||||
void Achievement::increase(const std::string & key, int increase)
|
||||
{
|
||||
if (m_progress_map.find(key) != m_progress_map.end())
|
||||
m_progress_map[key] += increase;
|
||||
std::map<std::string, int>::iterator it;
|
||||
it = m_progress_map.find(key);
|
||||
if (it != m_progress_map.end())
|
||||
{
|
||||
it->second += increase;
|
||||
if (it->second > m_achievement_info->getGoalValue(key))
|
||||
it->second = m_achievement_info->getGoalValue(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (increase>m_achievement_info->getGoalValue(key))
|
||||
increase = m_achievement_info->getGoalValue(key);
|
||||
m_progress_map[key] = increase;
|
||||
}
|
||||
check();
|
||||
} // increase
|
||||
|
||||
|
@ -145,3 +145,13 @@ bool AchievementInfo::checkCompletion(Achievement * achievement) const
|
||||
return false;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
int AchievementInfo::getGoalValue(const std::string &key) const
|
||||
{
|
||||
std::map<std::string, int>::const_iterator it;
|
||||
it = m_goal_values.find(key);
|
||||
if (it != m_goal_values.end())
|
||||
return it->second;
|
||||
else
|
||||
return 0;
|
||||
} // getGoalValue
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -83,6 +83,7 @@ public:
|
||||
|
||||
virtual irr::core::stringw toString() const;
|
||||
virtual bool checkCompletion(Achievement * achievement) const;
|
||||
int getGoalValue(const std::string &key) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the id of this achievement. */
|
||||
@ -98,7 +99,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the check type for this achievement. */
|
||||
AchievementCheckType getCheckType() const { return m_check_type; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
}; // class AchievementInfo
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user