From 47010623cd2d240107860f33e7051051b67f6030 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 9 Jan 2006 21:57:41 +0000 Subject: [PATCH] move Course autogen logic into CourseUtil --- stepmania/src/Course.cpp | 93 --------------------------------- stepmania/src/Course.h | 3 -- stepmania/src/CourseUtil.cpp | 98 +++++++++++++++++++++++++++++++++++ stepmania/src/CourseUtil.h | 6 +++ stepmania/src/SongManager.cpp | 8 +-- 5 files changed, 108 insertions(+), 100 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 750e5b4e07..e97aab0857 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -219,99 +219,6 @@ void Course::Init() m_iTrailCacheSeed = 0; } -void Course::AutogenEndlessFromGroup( CString sGroupName, Difficulty diff ) -{ - m_bIsAutogen = true; - m_bRepeat = true; - m_bShuffle = true; - m_iLives = -1; - FOREACH_Difficulty(dc) - m_iCustomMeter[dc] = -1; - - if( sGroupName == "" ) - { - m_sMainTitle = "All Songs"; - // m_sBannerPath = ""; // XXX - } - else - { - m_sMainTitle = SONGMAN->ShortenGroupName( sGroupName ); - m_sBannerPath = SONGMAN->GetSongGroupBannerPath( sGroupName ); - } - - // We want multiple songs, so we can try to prevent repeats during - // gameplay. (We might still get a repeat at the repeat boundary, - // but that'd be rare.) -glenn - CourseEntry e; - e.sSongGroup = sGroupName; - e.baseDifficulty = diff; - e.bSecret = true; - - vector vSongs; - SONGMAN->GetSongs( vSongs, e.sSongGroup ); - for( unsigned i = 0; i < vSongs.size(); ++i) - m_vEntries.push_back( e ); -} - -void Course::AutogenNonstopFromGroup( CString sGroupName, Difficulty diff ) -{ - AutogenEndlessFromGroup( sGroupName, diff ); - - m_bRepeat = false; - - m_sMainTitle += " Random"; - - // resize to 4 - while( m_vEntries.size() < 4 ) - m_vEntries.push_back( m_vEntries[0] ); - while( m_vEntries.size() > 4 ) - m_vEntries.pop_back(); -} - -void Course::AutogenOniFromArtist( CString sArtistName, CString sArtistNameTranslit, vector aSongs, Difficulty dc ) -{ - m_bIsAutogen = true; - m_bRepeat = false; - m_bShuffle = true; - m_bSortByMeter = true; - - m_iLives = 4; - FOREACH_Difficulty(cd) - m_iCustomMeter[cd] = -1; - - ASSERT( sArtistName != "" ); - ASSERT( aSongs.size() > 0 ); - - /* "Artist Oni" is a little repetitive; "by Artist" stands out less, and lowercasing - * "by" puts more emphasis on the artist's name. It also sorts them together. */ - m_sMainTitle = "by " + sArtistName; - if( sArtistNameTranslit != sArtistName ) - m_sMainTitleTranslit = "by " + sArtistNameTranslit; - - - // m_sBannerPath = ""; // XXX - - /* Shuffle the list to determine which songs we'll use. Shuffle it deterministically, - * so we always get the same set of songs unless the song set changes. */ - { - RandomGen rng( GetHashForString( sArtistName ) + aSongs.size() ); - random_shuffle( aSongs.begin(), aSongs.end(), rng ); - } - - /* Only use up to four songs. */ - if( aSongs.size() > 4 ) - aSongs.erase( aSongs.begin()+4, aSongs.end() ); - - CourseEntry e; - e.baseDifficulty = dc; - - for( unsigned i = 0; i < aSongs.size(); ++i ) - { - e.pSong = aSongs[i]; - m_vEntries.push_back( e ); - } -} - bool Course::IsPlayableIn( StepsType st ) const { return GetTrail( st ) != NULL; diff --git a/stepmania/src/Course.h b/stepmania/src/Course.h index ea9d9d1bcb..4a61244d9d 100644 --- a/stepmania/src/Course.h +++ b/stepmania/src/Course.h @@ -171,9 +171,6 @@ public: void RevertFromDisk(); void Init(); - void AutogenEndlessFromGroup( CString sGroupName, Difficulty dc ); - void AutogenNonstopFromGroup( CString sGroupName, Difficulty dc ); - void AutogenOniFromArtist( CString sArtistName, CString sArtistNameTranslit, vector aSongs, Difficulty dc ); // sorting values int m_SortOrder_TotalDifficulty; diff --git a/stepmania/src/CourseUtil.cpp b/stepmania/src/CourseUtil.cpp index 7fba4d328a..11afe88114 100644 --- a/stepmania/src/CourseUtil.cpp +++ b/stepmania/src/CourseUtil.cpp @@ -195,6 +195,104 @@ void CourseUtil::MakeDefaultEditCourseEntry( CourseEntry& out ) out.baseDifficulty = DIFFICULTY_MEDIUM; } +////////////////////////////////// +// Autogen +////////////////////////////////// + +void CourseUtil::AutogenEndlessFromGroup( const CString &sGroupName, Difficulty diff, Course &out ) +{ + out.m_bIsAutogen = true; + out.m_bRepeat = true; + out.m_bShuffle = true; + out.m_iLives = -1; + FOREACH_Difficulty(dc) + out.m_iCustomMeter[dc] = -1; + + if( sGroupName == "" ) + { + out.m_sMainTitle = "All Songs"; + // m_sBannerPath = ""; // XXX + } + else + { + out.m_sMainTitle = SONGMAN->ShortenGroupName( sGroupName ); + out.m_sBannerPath = SONGMAN->GetSongGroupBannerPath( sGroupName ); + } + + // We want multiple songs, so we can try to prevent repeats during + // gameplay. (We might still get a repeat at the repeat boundary, + // but that'd be rare.) -glenn + CourseEntry e; + e.sSongGroup = sGroupName; + e.baseDifficulty = diff; + e.bSecret = true; + + vector vSongs; + SONGMAN->GetSongs( vSongs, e.sSongGroup ); + for( unsigned i = 0; i < vSongs.size(); ++i) + out.m_vEntries.push_back( e ); +} + +void CourseUtil::AutogenNonstopFromGroup( const CString &sGroupName, Difficulty diff, Course &out ) +{ + AutogenEndlessFromGroup( sGroupName, diff, out ); + + out.m_bRepeat = false; + + out.m_sMainTitle += " Random"; + + // resize to 4 + while( out.m_vEntries.size() < 4 ) + out.m_vEntries.push_back( out.m_vEntries[0] ); + while( out.m_vEntries.size() > 4 ) + out.m_vEntries.pop_back(); +} + +void CourseUtil::AutogenOniFromArtist( const CString &sArtistName, CString sArtistNameTranslit, vector aSongs, Difficulty dc, Course &out ) +{ + out.m_bIsAutogen = true; + out.m_bRepeat = false; + out.m_bShuffle = true; + out.m_bSortByMeter = true; + + out.m_iLives = 4; + FOREACH_Difficulty(cd) + out.m_iCustomMeter[cd] = -1; + + ASSERT( sArtistName != "" ); + ASSERT( aSongs.size() > 0 ); + + /* "Artist Oni" is a little repetitive; "by Artist" stands out less, and lowercasing + * "by" puts more emphasis on the artist's name. It also sorts them together. */ + out.m_sMainTitle = "by " + sArtistName; + if( sArtistNameTranslit != sArtistName ) + out.m_sMainTitleTranslit = "by " + sArtistNameTranslit; + + + // m_sBannerPath = ""; // XXX + + /* Shuffle the list to determine which songs we'll use. Shuffle it deterministically, + * so we always get the same set of songs unless the song set changes. */ + { + RandomGen rng( GetHashForString( sArtistName ) + aSongs.size() ); + random_shuffle( aSongs.begin(), aSongs.end(), rng ); + } + + /* Only use up to four songs. */ + if( aSongs.size() > 4 ) + aSongs.erase( aSongs.begin()+4, aSongs.end() ); + + CourseEntry e; + e.baseDifficulty = dc; + + for( unsigned i = 0; i < aSongs.size(); ++i ) + { + e.pSong = aSongs[i]; + out.m_vEntries.push_back( e ); + } +} + + ////////////////////////////////// // CourseID diff --git a/stepmania/src/CourseUtil.h b/stepmania/src/CourseUtil.h index 81980ba88b..ce0291b374 100644 --- a/stepmania/src/CourseUtil.h +++ b/stepmania/src/CourseUtil.h @@ -4,11 +4,13 @@ #define COURSEUTIL_H #include "GameConstantsAndTypes.h" +#include "Difficulty.h" class Course; class Profile; class XNode; class CourseEntry; +class Song; namespace CourseUtil { @@ -25,6 +27,10 @@ namespace CourseUtil void MoveRandomToEnd( vector &vpCoursesInOut ); void MakeDefaultEditCourseEntry( CourseEntry &out ); + + void AutogenEndlessFromGroup( const CString &sGroupName, Difficulty dc, Course &out ); + void AutogenNonstopFromGroup( const CString &sGroupName, Difficulty dc, Course &out ); + void AutogenOniFromArtist( const CString &sArtistName, CString sArtistNameTranslit, vector aSongs, Difficulty dc, Course &out ); }; class CourseID diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index f436c435c2..608e6e25d1 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -572,11 +572,11 @@ void SongManager::InitAutogenCourses() // Generate random courses from each group. pCourse = new Course; - pCourse->AutogenEndlessFromGroup( sGroupName, DIFFICULTY_MEDIUM ); + CourseUtil::AutogenEndlessFromGroup( sGroupName, DIFFICULTY_MEDIUM, *pCourse ); m_pCourses.push_back( pCourse ); pCourse = new Course; - pCourse->AutogenNonstopFromGroup( sGroupName, DIFFICULTY_MEDIUM ); + CourseUtil::AutogenNonstopFromGroup( sGroupName, DIFFICULTY_MEDIUM, *pCourse ); m_pCourses.push_back( pCourse ); } @@ -584,7 +584,7 @@ void SongManager::InitAutogenCourses() // Generate "All Songs" endless course. pCourse = new Course; - pCourse->AutogenEndlessFromGroup( "", DIFFICULTY_MEDIUM ); + CourseUtil::AutogenEndlessFromGroup( "", DIFFICULTY_MEDIUM, *pCourse ); m_pCourses.push_back( pCourse ); /* Generate Oni courses from artists. Only create courses if we have at least @@ -619,7 +619,7 @@ void SongManager::InitAutogenCourses() sCurArtist.CompareNoCase("Unknown artist") ) { pCourse = new Course; - pCourse->AutogenOniFromArtist( sCurArtist, sCurArtistTranslit, aSongs, DIFFICULTY_HARD ); + CourseUtil::AutogenOniFromArtist( sCurArtist, sCurArtistTranslit, aSongs, DIFFICULTY_HARD, *pCourse ); m_pCourses.push_back( pCourse ); }