This commit is contained in:
hiker 2015-04-27 17:14:23 +10:00
parent 38e4e4e03c
commit aaf20dc919
4 changed files with 29 additions and 13 deletions

View File

@ -151,20 +151,21 @@ irr::core::stringw Achievement::getProgressAsString() const
* \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)
void Achievement::increase(const std::string & key,
const std::string &goal_key, int 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);
if (it->second > m_achievement_info->getGoalValue(goal_key))
it->second = m_achievement_info->getGoalValue(goal_key);
}
else
{
if (increase>m_achievement_info->getGoalValue(key))
increase = m_achievement_info->getGoalValue(key);
if (increase>m_achievement_info->getGoalValue(goal_key))
increase = m_achievement_info->getGoalValue(goal_key);
m_progress_map[key] = increase;
}
check();

View File

@ -65,7 +65,8 @@ public:
virtual void load(const XMLNode *node);
virtual void save(UTFWriter &out);
virtual int getValue(const std::string & key);
void increase(const std::string & key, int increase = 1);
void increase(const std::string & key, const std::string &goal_key,
int increase = 1);
virtual void reset();
virtual irr::core::stringw getProgressAsString() const;

View File

@ -143,16 +143,27 @@ public:
} // getCurrentAchievementsStatus
// ------------------------------------------------------------------------
/** A handy shortcut to increase points for an achievement key of the
* current player. */
static void increaseAchievement(unsigned int index, const std::string &key,
int increase = 1)
* current player.
* \param achievement_id The achievement id.
* \param key The key of the current value to increase.
* \param increase How much to increase the current value.
* \param goal_key Optional: The goal key to compare the current value
* with. If not set, defaults to key.
*/
static void increaseAchievement(unsigned int achievement_id,
const std::string &key,
int increase = 1,
const std::string &goal_key="")
{
Achievement *a = getCurrentAchievementsStatus()->getAchievement(index);
Achievement *a = getCurrentAchievementsStatus()
->getAchievement(achievement_id);
if (!a)
{
Log::fatal("PlayerManager", "Achievement '%d' not found.", index);
Log::fatal("PlayerManager", "Achievement '%d' not found.",
achievement_id);
}
a->increase(key, increase);
a->increase(key, goal_key.empty() ? key : goal_key, increase);
} // increaseAchievement
// ------------------------------------------------------------------------
}; // PlayerManager

View File

@ -301,8 +301,11 @@ void Physics::update(float dt)
if (target_kart != kart && c &&
c->getPlayer()->getConstProfile() == PlayerManager::getCurrentPlayer())
{
// Compare the current value of hits with the 'hit' goal value
// (otherwise it would be compared with the kart id goal value,
// which doesn't exist.
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_ARCH_ENEMY,
target_kart->getIdent(), 1);
target_kart->getIdent(), 1, "hit");
if (type == PowerupManager::POWERUP_BOWLING)
{
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_STRIKE,