Add GetRandomCourse
change GetRandom* to behave like a shuffle so it doesn't pick back-to-back dupes
This commit is contained in:
@@ -121,7 +121,7 @@ void GameState::Reset()
|
||||
|
||||
ResetMusicStatistics();
|
||||
ResetStageStatistics();
|
||||
SONGMAN->UpdateBest();
|
||||
SONGMAN->UpdateBestAndShuffled();
|
||||
|
||||
g_vPlayedStageStats.clear();
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ MusicWheel::MusicWheel()
|
||||
}
|
||||
|
||||
/* Update for SORT_MOST_PLAYED. */
|
||||
SONGMAN->UpdateBest();
|
||||
SONGMAN->UpdateBestAndShuffled();
|
||||
|
||||
RageTimer timer;
|
||||
CString times;
|
||||
|
||||
@@ -750,10 +750,26 @@ void SongManager::GetExtraStageInfo( bool bExtra2, const StyleDef *sd,
|
||||
|
||||
Song* SongManager::GetRandomSong()
|
||||
{
|
||||
if( m_pSongs.empty() )
|
||||
if( m_pShuffledSongs.empty() )
|
||||
return NULL;
|
||||
|
||||
return SONGMAN->m_pSongs[ rand()%m_pSongs.size() ];
|
||||
static i = 0;
|
||||
i++;
|
||||
wrap( i, m_pShuffledSongs.size() );
|
||||
|
||||
return m_pShuffledSongs[ i ];
|
||||
}
|
||||
|
||||
Course* SongManager::GetRandomCourse()
|
||||
{
|
||||
if( m_pShuffledCourses.empty() )
|
||||
return NULL;
|
||||
|
||||
static i = 0;
|
||||
i++;
|
||||
wrap( i, m_pShuffledCourses.size() );
|
||||
|
||||
return m_pShuffledCourses[ i ];
|
||||
}
|
||||
|
||||
Song* SongManager::GetSongFromDir( CString sDir )
|
||||
@@ -841,8 +857,9 @@ Course *SongManager::FindCourse( CString sName )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SongManager::UpdateBest()
|
||||
void SongManager::UpdateBestAndShuffled()
|
||||
{
|
||||
// update players best
|
||||
for( int i = 0; i < NUM_MEMORY_CARDS; ++i )
|
||||
{
|
||||
m_pBestSongs[i] = m_pSongs;
|
||||
@@ -851,6 +868,13 @@ void SongManager::UpdateBest()
|
||||
m_pBestCourses[i] = m_pCourses;
|
||||
SortCoursePointerArrayByMostPlayed( m_pBestCourses[i], (MemoryCard) i );
|
||||
}
|
||||
|
||||
// update shuffled
|
||||
m_pShuffledSongs = m_pSongs;
|
||||
random_shuffle( m_pShuffledSongs.begin(), m_pShuffledSongs.end() );
|
||||
|
||||
m_pShuffledCourses = m_pCourses;
|
||||
random_shuffle( m_pShuffledCourses.begin(), m_pShuffledCourses.end() );
|
||||
}
|
||||
|
||||
void SongManager::UpdateRankingCourses()
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
int GetNumGroups() const;
|
||||
int GetNumCourses() const;
|
||||
Song* GetRandomSong();
|
||||
Course* GetRandomCourse();
|
||||
|
||||
|
||||
void GetAllCourses( vector<Course*> &AddTo, bool bIncludeAutogen );
|
||||
@@ -87,7 +88,7 @@ public:
|
||||
Course* GetCourseFromName( CString sName );
|
||||
|
||||
|
||||
void UpdateBest(); // update Players Best
|
||||
void UpdateBestAndShuffled(); // update Players Best
|
||||
|
||||
void UpdateRankingCourses(); // courses shown on the ranking screen
|
||||
|
||||
@@ -103,10 +104,12 @@ protected:
|
||||
|
||||
vector<Song*> m_pSongs; // all songs that can be played
|
||||
vector<Song*> m_pBestSongs[NUM_MEMORY_CARDS];
|
||||
vector<Song*> m_pShuffledSongs; // used by GetRandomSong
|
||||
CStringArray m_sGroupNames;
|
||||
CStringArray m_sGroupBannerPaths; // each song group may have a banner associated with it
|
||||
vector<Course*> m_pCourses;
|
||||
vector<Course*> m_pBestCourses[NUM_MEMORY_CARDS];
|
||||
vector<Course*> m_pShuffledCourses; // used by GetRandomCourse
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user