diff --git a/src/achievements/achievements_status.cpp b/src/achievements/achievements_status.cpp index bbe52fb44..fab79223b 100644 --- a/src/achievements/achievements_status.cpp +++ b/src/achievements/achievements_status.cpp @@ -59,7 +59,8 @@ AchievementsStatus::AchievementsStatus() TrackStats new_track; new_track.ident = curr->getIdent(); new_track.race_started = new_track.race_finished = new_track.race_won = 0; - new_track.race_finished_reverse = 0; + new_track.race_finished_reverse = new_track.race_finished_alone = 0; + new_track.egg_hunt_started = new_track.egg_hunt_finished = 0; m_track_stats.push_back(new_track); } // for nget("finished",&m_track_stats[j].race_finished); xml_achievement_tracks[i]->get("won",&m_track_stats[j].race_won); xml_achievement_tracks[i]->get("finished_reverse",&m_track_stats[j].race_finished_reverse); + xml_achievement_tracks[i]->get("finished_alone",&m_track_stats[j].race_finished_alone); + xml_achievement_tracks[i]->get("egg_hunt_started",&m_track_stats[j].egg_hunt_started); + xml_achievement_tracks[i]->get("egg_hunt_finished",&m_track_stats[j].egg_hunt_finished); track_found = true; break; } @@ -151,6 +155,9 @@ void AchievementsStatus::load(const XMLNode * input) xml_achievement_tracks[i]->get("finished",&new_track.race_finished); xml_achievement_tracks[i]->get("won",&new_track.race_won); xml_achievement_tracks[i]->get("finished_reverse",&new_track.race_finished_reverse); + xml_achievement_tracks[i]->get("finished_alone",&new_track.race_finished_alone); + xml_achievement_tracks[i]->get("egg_hunt_started",&new_track.egg_hunt_started); + xml_achievement_tracks[i]->get("egg_hunt_finished",&new_track.egg_hunt_finished); m_track_stats.push_back(new_track); } @@ -192,7 +199,11 @@ void AchievementsStatus::save(UTFWriter &out) out << " started=\"" << m_track_stats[n].race_started << "\""; out << " finished=\"" << m_track_stats[n].race_finished << "\""; out << " won=\"" << m_track_stats[n].race_won << "\""; - out << " finished_reverse=\"" << m_track_stats[n].race_finished_reverse << "\"/>\n"; + out << " finished_reverse=\"" << m_track_stats[n].race_finished_reverse << "\""; + out << " finished_alone=\"" << m_track_stats[n].race_finished_alone << "\""; + out << " egg_hunt_started=\"" << m_track_stats[n].egg_hunt_started << "\""; + out << " egg_hunt_finished=\"" << m_track_stats[n].egg_hunt_finished << "\""; + out << "/>\n"; } // for n\n"; } // save @@ -391,53 +402,32 @@ void AchievementsStatus::onLapEnd() } // onLapEnd // ---------------------------------------------------------------------------- -void AchievementsStatus::raceStarted(std::string track_ident) +/** Use the event type to increment the correct track event counter + * \param track_ident - the internal name of the track + * \param event - the type of counter to increment */ +void AchievementsStatus::trackEvent(std::string track_ident, AchievementsStatus::TrackData event) { + int track_id = -1; for (unsigned int i=0;i m_track_stats; + // TODO : keep track of battle/soccer arenas + bool m_online; bool m_valid; @@ -125,10 +144,7 @@ public : void resetDataVar(unsigned int achieve_data_id); void onRaceEnd(bool aborted=false); void onLapEnd(); - void raceStarted(std::string track_ident); - void raceFinished(std::string track_ident); - void raceWon(std::string track_ident); - void raceFinishedReverse(std::string track_ident); + void trackEvent(std::string track_ident, AchievementsStatus::TrackData event); // ------------------------------------------------------------------------ const std::map& getAllAchievements() { diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp index da0ed3cec..b9954be16 100644 --- a/src/config/player_manager.hpp +++ b/src/config/player_manager.hpp @@ -200,28 +200,13 @@ public: // ---------------------------------------------------------------------------- - static void raceStarted(std::string track_ident) + /** Transmit an incrementation request of one of the track event counters + * \param track_ident - the internal name of the track + * \param event - the type of counter to increment */ + static void trackEvent(std::string track_ident, AchievementsStatus::TrackData event) { - getCurrentAchievementsStatus()->raceStarted(track_ident); - } // raceStarted - - // ---------------------------------------------------------------------------- - static void raceFinished(std::string track_ident) - { - getCurrentAchievementsStatus()->raceFinished(track_ident); - } // raceFinished - - // ---------------------------------------------------------------------------- - static void raceWon(std::string track_ident) - { - getCurrentAchievementsStatus()->raceWon(track_ident); - } // raceWon - - // ---------------------------------------------------------------------------- - static void raceFinishedReverse(std::string track_ident) - { - getCurrentAchievementsStatus()->raceFinishedReverse(track_ident); - } // raceFinishedReverse + getCurrentAchievementsStatus()->trackEvent(track_ident, event); + } // trackEvent // ------------------------------------------------------------------------ }; // PlayerManager diff --git a/src/modes/world.cpp b/src/modes/world.cpp index da3239879..9c41ecb82 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -294,8 +294,10 @@ void World::reset(bool restart) (*i)->reset(); if ((*i)->getController()->canGetAchievements()) { - printf("Track name is %s\n", race_manager->getTrackName().c_str()); - PlayerManager::raceStarted(race_manager->getTrackName()); + if (race_manager->isLinearRaceMode()) + PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_STARTED); + else if (race_manager->isEggHuntMode()) + PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_EGG_HUNT_STARTED); if (restart) PlayerManager::onRaceEnd(true /* previous race aborted */); } @@ -629,7 +631,8 @@ void World::terminateRace() "laps", race_manager->getNumLaps()); } - // Increment won races counts + //TODO : move this stuff to a sub-function + // Increment won races counts and track finished counts if (race_manager->isLinearRaceMode()) { for(unsigned int i = 0; i < kart_amount; i++) @@ -638,15 +641,18 @@ void World::terminateRace() // Retrieve the current player if (m_karts[i]->getController()->canGetAchievements()) { - PlayerManager::raceFinished(race_manager->getTrackName()); + PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED); if (race_manager->getReverseTrack()) - PlayerManager::raceFinishedReverse(race_manager->getTrackName()); + PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED_REVERSE); int winner_position = 1; if (race_manager->isFollowMode()) winner_position = 2;//TODO : check this always work // Check if the player has won if (m_karts[i]->getPosition() == winner_position) { - PlayerManager::raceWon(race_manager->getTrackName()); + if (race_manager->getNumNonGhostKarts() >= 2) + PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_WON); + else + PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED_ALONE); if (race_manager->getNumberOfAIKarts() >= 3) { PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_RACES,1); @@ -673,6 +679,12 @@ void World::terminateRace() } // for iisEggHuntMode()) + { + PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_EGG_HUNT_FINISHED); + } + PlayerManager::getCurrentPlayer()->raceFinished(); if (m_race_gui) m_race_gui->clearAllMessages();