Add a new Gold Driver achievement.

This commit is contained in:
Guillaume P 2014-03-15 15:08:18 +01:00
parent 9030291340
commit 8a34be1ab3
5 changed files with 50 additions and 7 deletions

View File

@ -25,5 +25,12 @@
title="Marathoner" description="Make a race with 5 laps or more">
<laps goal="5"/>
</achievement>
<achievement id="5" check-type="all-at-least" reset-after-race="no"
title="Gold driver" description="Win in all single player modes, against at least 3 opponents.">
<standard goal="1"/>
<std_timetrial goal="1"/>
<follow_leader goal="1"/>
<opponents goal="3"/>
</achievement>
</achievements>

View File

@ -42,12 +42,13 @@ class AchievementInfo
{
public:
/** Some handy names for the various achievements. */
enum { ACHIEVE_COLUMBUS = 1,
ACHIEVE_FIRST = ACHIEVE_COLUMBUS,
ACHIEVE_STRIKE = 2,
ACHIEVE_ARCH_ENEMY = 3,
ACHIEVE_MARATHONER = 4,
ACHIEVE_LAST = ACHIEVE_MARATHONER
enum { ACHIEVE_COLUMBUS = 1,
ACHIEVE_FIRST = ACHIEVE_COLUMBUS,
ACHIEVE_STRIKE = 2,
ACHIEVE_ARCH_ENEMY = 3,
ACHIEVE_MARATHONER = 4,
ACHIEVE_GOLD_DRIVER = 5,
ACHIEVE_LAST = ACHIEVE_GOLD_DRIVER
};
/** Achievement check type:
* ALL_AT_LEAST: All goal values must be reached (or exceeded).

View File

@ -1247,7 +1247,7 @@ void SkiddingAI::handleItems(const float dt)
// Leave some time between shots
if(m_time_since_last_shot<3.0f) break;
// Do not fire if the kart is driving too slow
if (m_kart->getSpeed() < 0.5 * m_kart->getCurrentMaxSpeed()) break;
if (m_kart->getSpeed() < 0.5 * m_kart->getCurrentMaxSpeed()) break;
// Since cakes can be fired all around, just use a sane distance
// with a bit of extra for backwards, as enemy will go towards cake

View File

@ -445,6 +445,7 @@ void World::terminateRace()
&best_player);
}
// Check achievements
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_COLUMBUS,
getTrack()->getIdent(), 1);
if (raceHasLaps())
@ -452,6 +453,39 @@ void World::terminateRace()
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_MARATHONER,
"laps", race_manager->getNumLaps());
}
Achievement *achiev = PlayerManager::getCurrentAchievementsStatus()->getAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER);
if (achiev)
{
std::string modeName = getIdent(); // Get the race mode name
int winnerPosition = 1;
int opponents = achiev->getInfo()->getGoalValue("opponents"); // Get the required opponents number
if (modeName == IDENT_FTL)
{
winnerPosition = 2;
opponents++;
}
for(unsigned int i = 0; i < kart_amount ; i++)
{
// Retrieve the current player
StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer();
if (p && p->getConstProfile() == PlayerManager::get()->getCurrentPlayer())
{
// Check if the player has won
if (m_karts[i]->getPosition() == winnerPosition && kart_amount > opponents )
{
// Update the achievement
std::transform(modeName.begin(), modeName.end(), modeName.begin(), std::tolower);
if (achiev->getValue("opponents") <= 0)
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER,
"opponents", opponents);
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER,
modeName, 1);
}
}
} // for i < kart_amount
} // if (achiev)
PlayerManager::get()->getCurrentPlayer()->raceFinished();
if (m_race_gui) m_race_gui->clearAllMessages();

View File

@ -25,6 +25,7 @@
* battle, etc.)
*/
#include <cctype>
#include <vector>
#include "modes/world_status.hpp"