From 9030291340cff5f1786267034cb2040d2088aa8e Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Sat, 15 Mar 2014 10:47:36 +0100 Subject: [PATCH 1/5] Now IA don't fire a cake if the kart is driving too slow. Also correct some comments. --- src/karts/controller/skidding_ai.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 5db0c83c3..9eeb44211 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -1242,11 +1242,12 @@ void SkiddingAI::handleItems(const float dt) case PowerupManager::POWERUP_CAKE: { // Do not destroy your own shield - if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a swatter. + if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a cake. break; // Leave some time between shots if(m_time_since_last_shot<3.0f) break; - //TODO: do not fire if the kart is driving too slow + // Do not fire if the kart is driving too slow + 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 @@ -1265,7 +1266,7 @@ void SkiddingAI::handleItems(const float dt) case PowerupManager::POWERUP_BOWLING: { // Do not destroy your own shield - if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a swatter. + if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a bowling ball. break; // Leave more time between bowling balls, since they are // slower, so it should take longer to hit something which @@ -1295,7 +1296,7 @@ void SkiddingAI::handleItems(const float dt) case PowerupManager::POWERUP_PLUNGER: { // Do not destroy your own shield - if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a swatter. + if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a plunger. break; // Leave more time after a plunger, since it will take some From 8a34be1ab33ae936413be5a48b9152fe3ee913e9 Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Sat, 15 Mar 2014 15:08:18 +0100 Subject: [PATCH 2/5] Add a new Gold Driver achievement. --- data/achievements.xml | 7 ++++++ src/achievements/achievement_info.hpp | 13 +++++----- src/karts/controller/skidding_ai.cpp | 2 +- src/modes/world.cpp | 34 +++++++++++++++++++++++++++ src/modes/world.hpp | 1 + 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/data/achievements.xml b/data/achievements.xml index 1cfd510fa..12ecbf378 100644 --- a/data/achievements.xml +++ b/data/achievements.xml @@ -25,5 +25,12 @@ title="Marathoner" description="Make a race with 5 laps or more"> + + + + + + diff --git a/src/achievements/achievement_info.hpp b/src/achievements/achievement_info.hpp index 6b8bab458..41dce20da 100644 --- a/src/achievements/achievement_info.hpp +++ b/src/achievements/achievement_info.hpp @@ -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). diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 9eeb44211..b905ab2bd 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -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 diff --git a/src/modes/world.cpp b/src/modes/world.cpp index e90b89dbb..85789af83 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -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(); diff --git a/src/modes/world.hpp b/src/modes/world.hpp index d8fe1c6a6..808f39ebf 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -25,6 +25,7 @@ * battle, etc.) */ +#include #include #include "modes/world_status.hpp" From 5af377da07c270b14dd4988fefe9fc933603cef1 Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Sat, 15 Mar 2014 15:58:17 +0100 Subject: [PATCH 3/5] Fix a build issue for Travis CI. --- src/modes/world.cpp | 2 +- src/modes/world.hpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 85789af83..53903f66f 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -475,7 +475,7 @@ void World::terminateRace() if (m_karts[i]->getPosition() == winnerPosition && kart_amount > opponents ) { // Update the achievement - std::transform(modeName.begin(), modeName.end(), modeName.begin(), std::tolower); + modeName = StringUtils::toLowerCase(modeName); if (achiev->getValue("opponents") <= 0) PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER, "opponents", opponents); diff --git a/src/modes/world.hpp b/src/modes/world.hpp index 808f39ebf..d8fe1c6a6 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -25,7 +25,6 @@ * battle, etc.) */ -#include #include #include "modes/world_status.hpp" From b4fe033331d4ae30fc4345a886729217d3a28b32 Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Mon, 17 Mar 2014 08:10:21 +0100 Subject: [PATCH 4/5] Revert "Now IA don't fire a cake if the kart is driving too slow. Also correct some comments." This reverts commit 9030291340cff5f1786267034cb2040d2088aa8e. --- src/karts/controller/skidding_ai.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index b905ab2bd..5db0c83c3 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -1242,12 +1242,11 @@ void SkiddingAI::handleItems(const float dt) case PowerupManager::POWERUP_CAKE: { // Do not destroy your own shield - if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a cake. + if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a swatter. break; // 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; + //TODO: do not fire if the kart is driving too slow // 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 @@ -1266,7 +1265,7 @@ void SkiddingAI::handleItems(const float dt) case PowerupManager::POWERUP_BOWLING: { // Do not destroy your own shield - if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a bowling ball. + if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a swatter. break; // Leave more time between bowling balls, since they are // slower, so it should take longer to hit something which @@ -1296,7 +1295,7 @@ void SkiddingAI::handleItems(const float dt) case PowerupManager::POWERUP_PLUNGER: { // Do not destroy your own shield - if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a plunger. + if(m_kart->getShieldTime() > min_bubble_time) // if the kart has a shield, do not break it by using a swatter. break; // Leave more time after a plunger, since it will take some From 45ab7e6907d4b40a865208c337bc6e9b4f16e8dd Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Mon, 17 Mar 2014 08:21:49 +0100 Subject: [PATCH 5/5] Clean up some minor coding style issues --- src/modes/world.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 53903f66f..f03591c9a 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -457,30 +457,30 @@ void World::terminateRace() Achievement *achiev = PlayerManager::getCurrentAchievementsStatus()->getAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER); if (achiev) { - std::string modeName = getIdent(); // Get the race mode name - int winnerPosition = 1; + std::string mode_name = getIdent(); // Get the race mode name + int winner_position = 1; int opponents = achiev->getInfo()->getGoalValue("opponents"); // Get the required opponents number - if (modeName == IDENT_FTL) + if (mode_name == IDENT_FTL) { - winnerPosition = 2; + winner_position = 2; opponents++; } - for(unsigned int i = 0; i < kart_amount ; i++) + 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 ) + if (m_karts[i]->getPosition() == winner_position && kart_amount > opponents ) { // Update the achievement - modeName = StringUtils::toLowerCase(modeName); + mode_name = StringUtils::toLowerCase(mode_name); if (achiev->getValue("opponents") <= 0) PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER, "opponents", opponents); PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER, - modeName, 1); + mode_name, 1); } } } // for i < kart_amount