diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 7c65104bc6..aaca336e5d 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -294,13 +294,13 @@ int Profile::GetSongNumTimesPlayed( const Song* pSong ) const int Profile::GetSongNumTimesPlayed( const SongID& songID ) const { + const HighScoresForASong *hsSong = GetHighScoresForASong( songID ); + if( hsSong == NULL ) + return 0; + int iTotalNumTimesPlayed = 0; - - std::map &songHighScores = ((Profile*)(this))->m_SongHighScores; - const HighScoresForASong& hsSong = songHighScores[songID]; - - for( std::map::const_iterator j = hsSong.m_StepsHighScores.begin(); - j != hsSong.m_StepsHighScores.end(); + for( std::map::const_iterator j = hsSong->m_StepsHighScores.begin(); + j != hsSong->m_StepsHighScores.end(); j++ ) { const HighScoresForASteps &hsSteps = j->second; @@ -347,6 +347,32 @@ void Profile::IncrementStepsPlayCount( const Song* pSong, const Steps* pSteps ) GetStepsHighScoreList(pSong,pSteps).iNumTimesPlayed++; } +void Profile::GetGrades( const Song* pSong, StepsType st, int iCounts[NUM_GRADES] ) const +{ + SongID songID; + songID.FromSong( pSong ); + + + memset( iCounts, 0, sizeof(int)*NUM_GRADES ); + const HighScoresForASong *hsSong = GetHighScoresForASong( songID ); + if( hsSong == NULL ) + return; + + FOREACH_Grade(g) + { + std::map::const_iterator it; + for( it = hsSong->m_StepsHighScores.begin(); it != hsSong->m_StepsHighScores.end(); ++it ) + { + const StepsID &id = it->first; + if( !id.MatchesStepsType(st) ) + continue; + + const HighScoresForASteps &hsSteps = it->second; + if( hsSteps.hs.GetTopScore().grade == g ) + iCounts[g]++; + } + } +} // // Course high scores @@ -1973,3 +1999,11 @@ void Profile::AddCourseLastScore( const Course* pCourse, StepsType st, CourseDif m_vLastCourseScores.push_back( h ); } +const Profile::HighScoresForASong *Profile::GetHighScoresForASong( const SongID& songID ) const +{ + std::map::const_iterator it; + it = m_SongHighScores.find( songID ); + if( it == m_SongHighScores.end() ) + return NULL; + return &it->second; +} diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index fe70cccfa0..ab99ed6884 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -137,6 +137,7 @@ public: HighScoreList& GetStepsHighScoreList( const Song* pSong, const Steps* pSteps ); int GetStepsNumTimesPlayed( const Song* pSong, const Steps* pSteps ) const; void IncrementStepsPlayCount( const Song* pSong, const Steps* pSteps ); + void GetGrades( const Song* pSong, StepsType st, int iCounts[NUM_GRADES] ) const; // @@ -339,6 +340,9 @@ public: void SaveStatsWebPageToDir( CString sDir ) const; void SaveMachinePublicKeyToDir( CString sDir ) const; + +private: + const HighScoresForASong *GetHighScoresForASong( const SongID& songID ) const; };