From de5baf26070e7cb6ccf7e071ffd3d8f8c43e925b Mon Sep 17 00:00:00 2001 From: blindbox Date: Mon, 29 Feb 2016 11:07:37 +0800 Subject: [PATCH] Properly add songs that are missing a Medium difficulty to the Endless Course --- src/Course.cpp | 8 ++++++-- src/StepsUtil.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/StepsUtil.h | 9 ++++++++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/Course.cpp b/src/Course.cpp index 6ef6e2dd57..af1798fbfd 100644 --- a/src/Course.cpp +++ b/src/Course.cpp @@ -685,7 +685,7 @@ void Course::GetTrailUnsortedEndless( const vector &entries, Trail if( pSong ) { - StepsUtil::GetAllMatching( pSong, stc, vSongAndSteps ); + StepsUtil::GetAllMatchingEndless( pSong, stc, vSongAndSteps ); } else if( vSongAndSteps.empty() || !( bSameSongCriteria && bSameStepsCriteria ) ) { @@ -821,7 +821,11 @@ void Course::GetTrailUnsortedEndless( const vector &entries, Trail } trail.m_vEntries.push_back( te ); - + if( trail.m_vEntries.size() > 0 && te.dc != cd ) + { + trail.m_vEntries.reserve( trail.m_vEntries.size() - 1 ); + trail.m_vEntries.resize( trail.m_vEntries.size() - 1 ); + } // LOG->Trace( "Chose: %s, %d", te.pSong->GetSongDir().c_str(), te.pSteps->GetMeter() ); if( IsAnEdit() && MAX_SONGS_IN_EDIT_COURSE > 0 && diff --git a/src/StepsUtil.cpp b/src/StepsUtil.cpp index f4b9240c5c..57651263a5 100644 --- a/src/StepsUtil.cpp +++ b/src/StepsUtil.cpp @@ -61,6 +61,42 @@ void StepsUtil::GetAllMatching( Song *pSong, const StepsCriteria &stc, vector &out ) +{ + const vector &vSteps = ( stc.m_st == StepsType_Invalid ? pSong->GetAllSteps() : + pSong->GetStepsByStepsType( stc.m_st ) ); + int previousSize = out.size(); + int successful = false; + + GetAllMatching( pSong, stc, out ); + if( out.size() != previousSize ) + { + successful = true; + } + + if( !successful ) + { + Difficulty difficulty = ( *( vSteps.begin() ) )->GetDifficulty(); + Difficulty previousDifficulty = difficulty; + int lowestDifficultyIndex = 0; + vector difficulties; + FOREACH_CONST( Steps*, vSteps, st ) + { + previousDifficulty = difficulty; + difficulty = ( *st )->GetDifficulty(); + if( ( st - vSteps.begin() ) == 0 ) + { + continue; + } + if( difficulty < previousDifficulty ) + { + lowestDifficultyIndex = st - vSteps.begin(); + } + } + out.push_back( SongAndSteps( pSong, vSteps.at( lowestDifficultyIndex ) ) ); + } +} + bool StepsUtil::HasMatching( const SongCriteria &soc, const StepsCriteria &stc ) { const RString &sGroupName = soc.m_sGroupName.empty()? GROUP_ALL:soc.m_sGroupName; diff --git a/src/StepsUtil.h b/src/StepsUtil.h index 31e644f656..216cc32751 100644 --- a/src/StepsUtil.h +++ b/src/StepsUtil.h @@ -118,7 +118,7 @@ namespace StepsUtil * @param stc the StepsCriteria to look for. * @param out the SongsAndSteps that match. */ - void GetAllMatching( const SongCriteria &soc, const StepsCriteria &stc, vector &out ); // look up in SONGMAN + void GetAllMatching( const SongCriteria &soc, const StepsCriteria &stc, vector &out); // look up in SONGMAN /** * @brief Retrieve all of the Steps that match the criteria. * @param pSong the Song we're checking in. @@ -126,6 +126,13 @@ namespace StepsUtil * @param out the SongsAndSteps that match. */ void GetAllMatching( Song *pSong, const StepsCriteria &stc, vector &out ); + /** + * @brief Retrieve all of the Steps that match the criteria, for Endless mode only. + * @param pSong the Song we're checking in. + * @param stc the StepsCriteria to look for. + * @param out the SongsAndSteps that match. + */ + void GetAllMatchingEndless( Song *pSong, const StepsCriteria &stc, vector &out ); /** * @brief Is there a Step * that matches the criteria?