add GetCourseRank

This commit is contained in:
Glenn Maynard
2006-08-17 01:58:58 +00:00
parent 5c66cd5e88
commit 1ad871d075
+37
View File
@@ -1739,6 +1739,10 @@ void SongManager::FreeAllLoadedFromProfile( ProfileSlot slot )
// After freeing some Steps pointers, the cache will be invalid.
StepsID::ClearCache();
// Best and Shuffled may refer to courses that we just freed.
// UpdateBest();
// UpdateShuffled();
}
int SongManager::GetNumStepsLoadedFromProfile()
@@ -1758,6 +1762,29 @@ int SongManager::GetNumStepsLoadedFromProfile()
return iCount;
}
template<class T>
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->GetCurrentStyle()->m_StepsType ) )
continue;
if( (*it)->GetPlayMode() != pm )
continue;
++n;
}
return -1;
}
// lua start
#include "LuaBinding.h"
@@ -1809,6 +1836,15 @@ public:
lua_pushnumber( L, iIndex );
return 1;
}
static int GetCourseRank( T* p, lua_State *L )
{
Course *pCourse = Luna<Course>::check(L,1);
CourseType ct = PlayModeToCourseType( GAMESTATE->m_PlayMode );
const vector<Course*> best = SONGMAN->GetPopularCourses( ct, ProfileSlot_Machine );
int iIndex = FindCourseIndexOfSameMode( best.begin(), best.end(), pCourse );
lua_pushnumber( L, iIndex );
return 1;
}
static void Register(lua_State *L)
{
@@ -1828,6 +1864,7 @@ public:
ADD_METHOD( GetNumCourseGroups );
ADD_METHOD( GetSongFromSteps );
ADD_METHOD( GetSongRank );
ADD_METHOD( GetCourseRank );
Luna<T>::Register( L );