Clean up some sorts; use multiple stable_sorts for multi-level

sorts, instead of hardcoding the order in the compare functions.

Don't consider challenge > hard for extra stages.
This commit is contained in:
Glenn Maynard
2003-02-05 00:33:14 +00:00
parent 94b20d1e95
commit 06be98567b
3 changed files with 28 additions and 13 deletions
+6 -11
View File
@@ -187,25 +187,20 @@ bool CompareNotesPointersByRadarValues(const Notes* pNotes1, const Notes* pNotes
bool CompareNotesPointersByMeter(const Notes *pNotes1, const Notes* pNotes2)
{
if( pNotes1->GetMeter() < pNotes2->GetMeter() )
return true;
if( pNotes1->GetMeter() > pNotes2->GetMeter() )
return false;
return CompareNotesPointersByRadarValues( pNotes1, pNotes2 );
return pNotes1->GetMeter() < pNotes2->GetMeter();
}
bool CompareNotesPointersByDifficulty(const Notes *pNotes1, const Notes *pNotes2)
{
if( pNotes1->GetDifficulty() < pNotes2->GetDifficulty() )
return true;
if( pNotes1->GetDifficulty() > pNotes2->GetDifficulty() )
return false;
return CompareNotesPointersByMeter( pNotes1, pNotes2 );
return pNotes1->GetDifficulty() < pNotes2->GetDifficulty();
}
void SortNotesArrayByDifficulty( vector<Notes*> &arraySteps )
{
sort( arraySteps.begin(), arraySteps.end(), CompareNotesPointersByDifficulty );
/* Sort in reverse order of priority. */
stable_sort( arraySteps.begin(), arraySteps.end(), CompareNotesPointersByRadarValues );
stable_sort( arraySteps.begin(), arraySteps.end(), CompareNotesPointersByMeter );
stable_sort( arraySteps.begin(), arraySteps.end(), CompareNotesPointersByDifficulty );
}
void Notes::Decompress() const
+2
View File
@@ -91,6 +91,8 @@ protected:
void DeAutogen();
};
bool CompareNotesPointersByRadarValues(const Notes* pNotes1, const Notes* pNotes2);
bool CompareNotesPointersByMeter(const Notes *pNotes1, const Notes* pNotes2);
bool CompareNotesPointersByDifficulty(const Notes *pNotes1, const Notes *pNotes2);
void SortNotesArrayByDifficulty( vector<Notes*> &arrayNotess );
+20 -2
View File
@@ -537,6 +537,24 @@ bool SongManager::GetExtraStageInfoFromCourse( bool bExtra2, CString sPreferredG
return true;
}
/* Return true if n1 < n2. */
bool CompareNotesPointersForExtra(const Notes *n1, const Notes *n2)
{
/* Equate CHALLENGE to HARD. */
Difficulty d1 = min(n1->GetDifficulty(), DIFFICULTY_HARD);
Difficulty d2 = min(n2->GetDifficulty(), DIFFICULTY_HARD);
if(d1 < d2) return true;
if(d1 > d2) return false;
/* n1 difficulty == n2 difficulty */
if(CompareNotesPointersByMeter(n1,n2)) return true;
if(CompareNotesPointersByMeter(n2,n1)) return false;
/* n1 meter == n2 meter */
return CompareNotesPointersByRadarValues(n1,n2);
}
void SongManager::GetExtraStageInfo( bool bExtra2, CString sPreferredGroup, const StyleDef *sd,
Song*& pSongOut, Notes*& pNotesOut, PlayerOptions& po_out, SongOptions& so_out )
{
@@ -562,7 +580,7 @@ void SongManager::GetExtraStageInfo( bool bExtra2, CString sPreferredGroup, cons
{
Notes* pNotes = apNotes[n];
if( pExtra1Notes == NULL || CompareNotesPointersByDifficulty(pExtra1Notes,pNotes) ) // pNotes is harder than pHardestNotes
if( pExtra1Notes == NULL || CompareNotesPointersForExtra(pExtra1Notes,pNotes) ) // pNotes is harder than pHardestNotes
{
pExtra1Song = pSong;
pExtra1Notes = pNotes;
@@ -571,7 +589,7 @@ void SongManager::GetExtraStageInfo( bool bExtra2, CString sPreferredGroup, cons
// for extra 2, we don't want to choose the hardest notes possible. So, we'll disgard Notes with meter > 8
if( bExtra2 && pNotes->GetMeter() > 8 )
continue; // skip
if( pExtra2Notes == NULL || CompareNotesPointersByDifficulty(pExtra2Notes,pNotes) ) // pNotes is harder than pHardestNotes
if( pExtra2Notes == NULL || CompareNotesPointersForExtra(pExtra2Notes,pNotes) ) // pNotes is harder than pHardestNotes
{
pExtra2Song = pSong;
pExtra2Notes = pNotes;