From 8d855da791523b96b2b99348bb899c010e42c21e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 21 Dec 2003 03:05:06 +0000 Subject: [PATCH] fix holes in course ranks --- stepmania/src/ScreenSelectMusic.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 09ce0d3506..915e550071 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -1078,6 +1078,29 @@ void ScreenSelectMusic::SwitchToPreferredDifficulty() } } +template +int FindCourseIndexOfSameMode( T begin, T end, const Course *p ) +{ + const PlayMode pm = p->GetPlayMode(); + + int n = 0; + for( T it = begin; it != end; ++it ) + { + if( *it == p ) + return n; + + /* If it's not playable in this mode, don't increment. It might result in + * different output in different modes, but that's better than having holes. */ + if( !(*it)->IsPlayableIn( GAMESTATE->GetCurrentStyleDef()->m_StepsType ) ) + continue; + if( (*it)->GetPlayMode() != pm ) + continue; + ++n; + } + + return -1; +} + void ScreenSelectMusic::AfterMusicChange() { if( !m_MusicWheel.IsRouletting() ) @@ -1266,7 +1289,7 @@ void ScreenSelectMusic::AfterMusicChange() } const vector best = SONGMAN->GetBestCourses( MEMORY_CARD_MACHINE ); - const int index = FindIndex( best.begin(), best.end(), pCourse ); + const int index = FindCourseIndexOfSameMode( best.begin(), best.end(), pCourse ); if( index != -1 ) m_MachineRank.SetText( ssprintf("%i", index+1) );