move Course autogen logic into CourseUtil

This commit is contained in:
Chris Danford
2006-01-09 21:57:41 +00:00
parent 63b3a5a468
commit 47010623cd
5 changed files with 108 additions and 100 deletions
-93
View File
@@ -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<Song*> 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<Song*> 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;
-3
View File
@@ -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<Song*> aSongs, Difficulty dc );
// sorting values
int m_SortOrder_TotalDifficulty;
+98
View File
@@ -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<Song*> 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<Song*> 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
+6
View File
@@ -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<Course*> &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<Song*> aSongs, Difficulty dc, Course &out );
};
class CourseID
+4 -4
View File
@@ -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 );
}