Files
itgmania212121/stepmania/src/SongManager.cpp
T

593 lines
17 KiB
C++
Raw Normal View History

2002-02-28 19:40:40 +00:00
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
Class: SongManager
Desc: See header.
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
2002-02-28 19:40:40 +00:00
Chris Danford
-----------------------------------------------------------------------------
*/
2002-04-16 17:31:00 +00:00
//#include <d3dxmath.h>
2002-02-28 19:40:40 +00:00
#include "SongManager.h"
#include "IniFile.h"
2002-05-01 19:14:55 +00:00
#include "RageLog.h"
2002-06-14 22:25:22 +00:00
2002-07-23 01:41:40 +00:00
#include "GameState.h"
2002-05-29 09:47:24 +00:00
#include "PrefsManager.h"
2002-07-27 19:29:51 +00:00
#include "RageException.h"
#include "RageTimer.h"
2002-02-28 19:40:40 +00:00
2002-05-19 01:59:48 +00:00
SongManager* SONGMAN = NULL; // global and accessable from anywhere in our program
2002-02-28 19:40:40 +00:00
const CString g_sStatisticsFileName = "statistics.ini";
2002-09-03 06:33:08 +00:00
#define NUM_GROUP_COLORS THEME->GetMetricI("SongManager","NumGroupColors")
#define GROUP_COLOR( i ) THEME->GetMetricC("SongManager",ssprintf("GroupColor%d",i+1))
2002-08-28 22:42:40 +00:00
#define EXTRA_COLOR THEME->GetMetricC("SongManager","ExtraColor")
D3DXCOLOR g_GroupColors[30];
D3DXCOLOR g_ExtraColor;
2002-04-16 17:31:00 +00:00
2002-02-28 19:40:40 +00:00
2002-07-23 01:41:40 +00:00
SongManager::SongManager( void(*callback)() )
2002-02-28 19:40:40 +00:00
{
for( int i=0; i<NUM_GROUP_COLORS; i++ )
g_GroupColors[i] = GROUP_COLOR( i );
g_ExtraColor = EXTRA_COLOR;
2002-07-23 01:41:40 +00:00
InitSongArrayFromDisk( callback );
2002-02-28 19:40:40 +00:00
ReadStatisticsFromDisk();
2002-06-14 22:25:22 +00:00
InitCoursesFromDisk();
2002-02-28 19:40:40 +00:00
}
SongManager::~SongManager()
{
SaveStatisticsToDisk();
2002-06-14 22:25:22 +00:00
FreeSongArray();
2002-02-28 19:40:40 +00:00
}
2002-07-23 01:41:40 +00:00
void SongManager::InitSongArrayFromDisk( void(*callback)() )
2002-02-28 19:40:40 +00:00
{
2002-07-23 01:41:40 +00:00
LoadStepManiaSongDir( "Songs", callback );
2002-06-27 17:49:10 +00:00
for( int i=0; i<PREFSMAN->m_asAdditionalSongFolders.GetSize(); i++ )
LoadStepManiaSongDir( PREFSMAN->m_asAdditionalSongFolders[i], callback );
2002-04-16 17:31:00 +00:00
2002-06-14 22:25:22 +00:00
// compute group names
2002-04-16 17:31:00 +00:00
CArray<Song*, Song*> arraySongs;
arraySongs.Copy( m_pSongs );
SortSongPointerArrayByGroup( arraySongs );
2002-06-27 19:14:23 +00:00
for( i=0; i<m_pSongs.GetSize(); i++ )
2002-04-16 17:31:00 +00:00
{
Song* pSong = m_pSongs[i];
2002-06-29 11:59:09 +00:00
const CString sGroupName = m_pSongs[i]->m_sGroupName;
2002-04-16 17:31:00 +00:00
if( m_arrayGroupNames.GetSize() == 0 || m_arrayGroupNames[m_arrayGroupNames.GetSize()-1] != sGroupName )
m_arrayGroupNames.Add( sGroupName );
}
LOG->Trace( "Found %d Songs.", m_pSongs.GetSize() );
2002-03-06 08:25:09 +00:00
}
2002-07-23 01:41:40 +00:00
void SongManager::LoadStepManiaSongDir( CString sDir, void(*callback)() )
2002-03-06 08:25:09 +00:00
{
// trim off the trailing slash if any
sDir.TrimRight( "/\\" );
// Find all group directories in "Songs" folder
CStringArray arrayGroupDirs;
GetDirListing( sDir+"\\*.*", arrayGroupDirs, true );
SortCStringArray( arrayGroupDirs );
for( int i=0; i< arrayGroupDirs.GetSize(); i++ ) // for each dir in /Songs/
{
CString sGroupDirName = arrayGroupDirs[i];
if( 0 == stricmp( sGroupDirName, "cvs" ) ) // the directory called "CVS"
continue; // ignore it
// Check to see if they put a song directly inside of the group folder
CStringArray arrayFiles;
GetDirListing( ssprintf("%s\\%s\\*.mp3", sDir, sGroupDirName), arrayFiles );
2002-05-19 01:59:48 +00:00
GetDirListing( ssprintf("%s\\%s\\*.ogg", sDir, sGroupDirName), arrayFiles );
2002-03-06 08:25:09 +00:00
GetDirListing( ssprintf("%s\\%s\\*.wav", sDir, sGroupDirName), arrayFiles );
if( arrayFiles.GetSize() > 0 )
2002-06-14 22:25:22 +00:00
throw RageException(
2002-07-23 01:41:40 +00:00
ssprintf( "The folder '%s' contains music files.\n\n"
"This probably means that you have a song outside of a group folder.\n"
"All song folders must reside in a group folder. For example, 'Songs\\DDR 4th Mix\\B4U'.\n"
"See the StepMania readme for more info.",
2002-03-06 08:25:09 +00:00
ssprintf("%s\\%s", sDir, sGroupDirName ) )
);
// Look for a group banner in this group folder
CStringArray arrayGroupBanners;
GetDirListing( ssprintf("%s\\%s\\*.png", sDir, sGroupDirName), arrayGroupBanners );
GetDirListing( ssprintf("%s\\%s\\*.jpg", sDir, sGroupDirName), arrayGroupBanners );
GetDirListing( ssprintf("%s\\%s\\*.gif", sDir, sGroupDirName), arrayGroupBanners );
GetDirListing( ssprintf("%s\\%s\\*.bmp", sDir, sGroupDirName), arrayGroupBanners );
if( arrayGroupBanners.GetSize() > 0 )
{
m_mapGroupToBannerPath[sGroupDirName] = ssprintf("%s\\%s\\%s", sDir, sGroupDirName, arrayGroupBanners[0] );
LOG->Trace( ssprintf("Group banner for '%s' is '%s'.", sGroupDirName, m_mapGroupToBannerPath[sGroupDirName]) );
2002-03-06 08:25:09 +00:00
}
// Find all Song folders in this group directory
CStringArray arraySongDirs;
GetDirListing( ssprintf("%s\\%s\\*.*", sDir, sGroupDirName), arraySongDirs, true );
SortCStringArray( arraySongDirs );
for( int j=0; j< arraySongDirs.GetSize(); j++ ) // for each song dir
{
CString sSongDirName = arraySongDirs[j];
if( 0 == stricmp( sSongDirName, "cvs" ) ) // the directory called "CVS"
continue; // ignore it
// this is a song directory. Load a new song!
2002-08-01 03:15:27 +00:00
GAMESTATE->m_sLoadingMessage = ssprintf("Loading songs...\n%s\n%s", sGroupDirName, sSongDirName);
2002-07-23 01:41:40 +00:00
if( callback )
callback();
2002-03-06 08:25:09 +00:00
Song* pNewSong = new Song;
pNewSong->LoadFromSongDir( ssprintf("%s\\%s\\%s", sDir, sGroupDirName, sSongDirName) );
m_pSongs.Add( pNewSong );
}
}
2002-07-23 01:41:40 +00:00
GAMESTATE->m_sLoadingMessage = "Done loading songs.";
if( callback )
callback();
2002-03-06 08:25:09 +00:00
}
2002-04-28 20:42:32 +00:00
2002-05-19 01:59:48 +00:00
/*
2002-04-28 20:42:32 +00:00
void SongManager::LoadDWISongDir( CString DWIHome )
2002-03-06 08:25:09 +00:00
{
// trim off the trailing slash if any
2002-04-28 20:42:32 +00:00
DWIHome.TrimRight( "/\\" );
2002-02-28 19:40:40 +00:00
2002-04-28 20:42:32 +00:00
// this has to be fixed, DWI doesn't put files
// in it's DWI folder. It puts them in Songs/<MIX>/<SONGNAME>
// so what we have to do, is go to the DWI directory (which will
// be changeable by the user so they don't have to copy everything
// over and have two copies of everything
2002-02-28 19:40:40 +00:00
// Find all directories in "DWIs" folder
CStringArray arrayDirs;
2002-04-28 20:42:32 +00:00
CStringArray MixDirs;
// now we've got the listing of the mix directories
// and we need to use THOSE directories to find our
// dwis
GetDirListing( ssprintf("%s\\Songs\\*.*", DWIHome ), MixDirs, true );
SortCStringArray( MixDirs );
2002-02-28 19:40:40 +00:00
2002-04-28 20:42:32 +00:00
for( int i=0; i< MixDirs.GetSize(); i++ ) // for each dir in /Songs/
2002-02-28 19:40:40 +00:00
{
2002-04-28 20:42:32 +00:00
// the dir name will most likely be something like
// Dance Dance Revolution 4th Mix, etc.
CString sDirName = MixDirs[i];
2002-02-28 19:40:40 +00:00
sDirName.MakeLower();
if( sDirName == "cvs" ) // ignore the directory called "CVS"
continue;
2002-04-28 20:42:32 +00:00
GetDirListing( ssprintf("%s\\Songs\\%s\\*.*", DWIHome, MixDirs[i]), arrayDirs, true);
SortCStringArray(arrayDirs, true);
2002-02-28 19:40:40 +00:00
2002-04-28 20:42:32 +00:00
for( int b = 0; b < arrayDirs.GetSize(); b++)
2002-02-28 19:40:40 +00:00
{
2002-04-28 20:42:32 +00:00
// Find all DWIs in this directory
CStringArray arrayDWIFiles;
GetDirListing( ssprintf("%s\\Songs\\%s\\%s\\*.dwi", DWIHome, MixDirs[i], arrayDirs[b]), arrayDWIFiles, false);
SortCStringArray( arrayDWIFiles );
2002-02-28 19:40:40 +00:00
2002-04-28 20:42:32 +00:00
for( int j=0; j< arrayDWIFiles.GetSize(); j++ ) // for each DWI file
{
CString sDWIFileName = arrayDWIFiles[j];
sDWIFileName.MakeLower();
// load DWIs from the sub dirs
Song* pNewSong = new Song;
pNewSong->LoadFromDWIFile( ssprintf("%s\\Songs\\%s\\%s\\%s", DWIHome, MixDirs[i], arrayDirs[b], sDWIFileName) );
m_pSongs.Add( pNewSong );
}
2002-02-28 19:40:40 +00:00
}
}
}
2002-05-19 01:59:48 +00:00
*/
2002-02-28 19:40:40 +00:00
2002-03-06 08:25:09 +00:00
2002-06-14 22:25:22 +00:00
void SongManager::FreeSongArray()
2002-02-28 19:40:40 +00:00
{
2002-07-02 00:27:58 +00:00
// Memory is being corrupt somewhere, and this is causing a crash. Bad news. I'll fix it later. Let the OS free it for now.
2002-02-28 19:40:40 +00:00
for( int i=0; i<m_pSongs.GetSize(); i++ )
SAFE_DELETE( m_pSongs[i] );
m_pSongs.RemoveAll();
2002-06-14 22:25:22 +00:00
2002-03-06 08:25:09 +00:00
m_mapGroupToBannerPath.RemoveAll();
2002-02-28 19:40:40 +00:00
}
void SongManager::ReloadSongArray()
{
2002-07-23 01:41:40 +00:00
InitSongArrayFromDisk( NULL );
2002-06-14 22:25:22 +00:00
FreeSongArray();
2002-02-28 19:40:40 +00:00
}
void SongManager::ReadStatisticsFromDisk()
{
IniFile ini;
ini.SetPath( g_sStatisticsFileName );
if( !ini.ReadFile() ) {
LOG->Trace( "WARNING: Could not read config file '%s'.", g_sStatisticsFileName );
2002-02-28 19:40:40 +00:00
return; // load nothing
}
// load song statistics
2002-07-23 01:41:40 +00:00
IniFile::key* pKey = ini.GetKey( "Statistics" );
2002-02-28 19:40:40 +00:00
if( pKey )
{
2002-07-23 01:41:40 +00:00
for( int i=0; i<pKey->names.GetSize(); i++ )
2002-02-28 19:40:40 +00:00
{
2002-07-23 01:41:40 +00:00
CString name = pKey->names[i];
CString value = pKey->values[i];
2002-02-28 19:40:40 +00:00
// Each value has the format "SongName::StepsName=TimesPlayed::TopGrade::TopScore::MaxCombo".
2002-06-29 11:59:09 +00:00
char szSongDir[256];
char szNotesName[256];
2002-02-28 19:40:40 +00:00
int iRetVal;
int i;
2002-05-19 01:59:48 +00:00
// Parse for Song name and Notes name
2002-07-23 01:41:40 +00:00
iRetVal = sscanf( name, "%[^:]::%[^\n]", szSongDir, szNotesName );
2002-02-28 19:40:40 +00:00
if( iRetVal != 2 )
continue; // this line doesn't match what is expected
// Search for the corresponding Song pointer.
Song* pSong = NULL;
for( i=0; i<m_pSongs.GetSize(); i++ )
{
2002-06-29 11:59:09 +00:00
if( m_pSongs[i]->m_sSongDir == szSongDir ) // match!
2002-02-28 19:40:40 +00:00
{
pSong = m_pSongs[i];
break;
}
}
if( pSong == NULL ) // didn't find a match
continue; // skip this entry
2002-05-19 01:59:48 +00:00
// Search for the corresponding Notes pointer.
Notes* pNotes = NULL;
2002-07-11 19:02:26 +00:00
for( i=0; i<pSong->m_apNotes.GetSize(); i++ )
2002-02-28 19:40:40 +00:00
{
2002-07-11 19:02:26 +00:00
if( pSong->m_apNotes[i]->m_sDescription == szNotesName ) // match!
2002-02-28 19:40:40 +00:00
{
2002-07-11 19:02:26 +00:00
pNotes = pSong->m_apNotes[i];
2002-02-28 19:40:40 +00:00
break;
}
}
2002-05-19 01:59:48 +00:00
if( pNotes == NULL ) // didn't find a match
2002-02-28 19:40:40 +00:00
continue; // skip this entry
2002-05-19 01:59:48 +00:00
// Parse the Notes statistics.
2002-02-28 19:40:40 +00:00
char szGradeLetters[10]; // longest possible string is "AAA"
iRetVal = sscanf(
2002-07-23 01:41:40 +00:00
value,
2002-02-28 19:40:40 +00:00
"%d::%[^:]::%d::%d",
2002-05-19 01:59:48 +00:00
&pNotes->m_iNumTimesPlayed,
2002-02-28 19:40:40 +00:00
szGradeLetters,
2002-05-19 01:59:48 +00:00
&pNotes->m_iTopScore,
&pNotes->m_iMaxCombo
2002-02-28 19:40:40 +00:00
);
if( iRetVal != 4 )
continue;
2002-05-19 01:59:48 +00:00
pNotes->m_TopGrade = StringToGrade( szGradeLetters );
2002-02-28 19:40:40 +00:00
}
}
}
void SongManager::SaveStatisticsToDisk()
{
IniFile ini;
ini.SetPath( g_sStatisticsFileName );
// save song statistics
for( int i=0; i<m_pSongs.GetSize(); i++ ) // for each Song
{
Song* pSong = m_pSongs[i];
2002-07-11 19:02:26 +00:00
for( int j=0; j<pSong->m_apNotes.GetSize(); j++ ) // for each Notes
2002-02-28 19:40:40 +00:00
{
2002-07-11 19:02:26 +00:00
Notes* pNotes = pSong->m_apNotes[j];
2002-02-28 19:40:40 +00:00
2002-05-19 01:59:48 +00:00
if( pNotes->m_TopGrade == GRADE_NO_DATA )
continue; // skip
2002-02-28 19:40:40 +00:00
2002-05-19 01:59:48 +00:00
// Each value has the format "SongName::NotesName=TimesPlayed::TopGrade::TopScore::MaxCombo".
2002-02-28 19:40:40 +00:00
2002-06-29 11:59:09 +00:00
CString sName = ssprintf( "%s::%s", pSong->m_sSongDir, pNotes->m_sDescription );
2002-02-28 19:40:40 +00:00
CString sValue = ssprintf(
"%d::%s::%d::%d",
2002-05-19 01:59:48 +00:00
pNotes->m_iNumTimesPlayed,
GradeToString( pNotes->m_TopGrade ),
pNotes->m_iTopScore,
pNotes->m_iMaxCombo
2002-02-28 19:40:40 +00:00
);
ini.SetValue( "Statistics", sName, sValue );
}
}
ini.WriteFile();
2002-03-06 08:25:09 +00:00
}
CString SongManager::GetGroupBannerPath( CString sGroupName )
2002-03-06 08:25:09 +00:00
{
CString sPath;
if( m_mapGroupToBannerPath.Lookup( sGroupName, sPath ) )
return sPath;
else
return "";
}
2002-04-01 02:04:43 +00:00
void SongManager::GetGroupNames( CStringArray &AddTo )
{
2002-04-16 17:31:00 +00:00
AddTo.Copy( m_arrayGroupNames );
}
2002-04-01 02:04:43 +00:00
2002-04-16 17:31:00 +00:00
D3DXCOLOR SongManager::GetGroupColor( const CString &sGroupName )
{
// search for the group index
for( int i=0; i<m_arrayGroupNames.GetSize(); i++ )
2002-04-01 02:04:43 +00:00
{
2002-04-16 17:31:00 +00:00
if( m_arrayGroupNames[i] == sGroupName )
break;
2002-04-01 02:04:43 +00:00
}
2002-04-16 17:31:00 +00:00
ASSERT( i != m_arrayGroupNames.GetSize() ); // this is not a valid group
return g_GroupColors[i%NUM_GROUP_COLORS];
2002-04-01 02:04:43 +00:00
}
D3DXCOLOR SongManager::GetSongColor( Song* pSong )
{
ASSERT( pSong );
for( int i=0; i<pSong->m_apNotes.GetSize(); i++ )
{
Notes* pNotes = pSong->m_apNotes[i];
if( pNotes->m_iMeter == 10 )
return EXTRA_COLOR;
}
return GetGroupColor( pSong->m_sGroupName );
}
2002-04-01 02:04:43 +00:00
void SongManager::GetSongsInGroup( const CString sGroupName, CArray<Song*, Song*> &AddTo )
{
for( int i=0; i<m_pSongs.GetSize(); i++ )
{
Song* pSong = m_pSongs[i];
2002-06-29 11:59:09 +00:00
if( sGroupName == m_pSongs[i]->m_sGroupName )
2002-04-01 02:04:43 +00:00
AddTo.Add( pSong );
}
SortSongPointerArrayByGroup( AddTo );
}
2002-04-16 17:31:00 +00:00
CString SongManager::ShortenGroupName( const CString &sOrigGroupName )
{
CString sShortName = sOrigGroupName;
sShortName.Replace( "Dance Dance Revolution", "DDR" );
sShortName.Replace( "dance dance revolution", "DDR" );
sShortName.Replace( "DANCE DANCE REVOLUTION", "DDR" );
2002-09-07 06:49:53 +00:00
sShortName.Replace( "Pump It Up", "Pump" );
sShortName.Replace( "pump it up", "pump" );
sShortName.Replace( "PUMP IT UP", "PUMP" );
2002-04-16 17:31:00 +00:00
return sShortName;
}
2002-06-14 22:25:22 +00:00
void SongManager::InitCoursesFromDisk()
{
2002-07-02 17:34:20 +00:00
//
// Load courses from CRS files
//
CStringArray saCourseFiles;
GetDirListing( "Courses\\*.crs", saCourseFiles );
for( int i=0; i<saCourseFiles.GetSize(); i++ )
{
Course course;
course.LoadFromCRSFile( "Courses\\" + saCourseFiles[i], m_pSongs );
2002-07-27 19:29:51 +00:00
if( course.m_iStages > 0 )
2002-07-29 03:06:55 +00:00
m_aOniCourses.Add( course );
2002-07-02 17:34:20 +00:00
}
2002-07-02 17:34:20 +00:00
//
2002-07-29 03:06:55 +00:00
// Create endless courses
2002-07-02 17:34:20 +00:00
//
2002-06-14 22:25:22 +00:00
CStringArray saGroupNames;
this->GetGroupNames( saGroupNames );
for( int g=0; g<saGroupNames.GetSize(); g++ ) // foreach Group
{
CString sGroupName = saGroupNames[g];
2002-07-23 01:41:40 +00:00
CArray<Song*, Song*> apGroupSongs;
GetSongsInGroup( sGroupName, apGroupSongs );
2002-06-14 22:25:22 +00:00
2002-07-23 01:41:40 +00:00
for( DifficultyClass dc=CLASS_EASY; dc<=CLASS_HARD; dc=DifficultyClass(dc+1) ) // foreach DifficultyClass
2002-07-04 21:05:18 +00:00
{
Course course;
2002-07-29 03:06:55 +00:00
course.CreateEndlessCourseFromGroupAndDifficultyClass( sGroupName, dc, apGroupSongs );
2002-07-04 21:05:18 +00:00
if( course.m_iStages > 0 )
2002-07-29 03:06:55 +00:00
m_aEndlessCourses.Add( course );
2002-06-14 22:25:22 +00:00
}
}
//
// Load extra stages
//
for( g=0; g<saGroupNames.GetSize(); g++ ) // foreach Group
{
CString sGroupName = saGroupNames[g];
CStringArray saCourseFiles;
GetDirListing( "Songs\\" + sGroupName + "\\*.crs", saCourseFiles );
for( int i=0; i<saCourseFiles.GetSize(); i++ )
{
Course course;
course.LoadFromCRSFile( "Songs\\" + sGroupName + "\\" + saCourseFiles[i], m_pSongs );
if( course.m_iStages > 0 )
m_aExtraCourses.Add( course );
}
}
2002-06-14 22:25:22 +00:00
}
void SongManager::ReloadCourses()
{
}
2002-08-01 13:42:56 +00:00
2002-08-30 20:49:56 +00:00
bool SongManager::GetExtraStageInfoFromCourse( bool bExtra2, CString sPreferredGroup,
Song*& pSongOut, Notes*& pNotesOut, PlayerOptions& po_out, SongOptions& so_out )
{
CString sCoursePath = "Songs\\" + sPreferredGroup + "\\" + (bExtra2 ? "extra2" : "extra1") + ".crs";
if( !DoesFileExist(sCoursePath) ) return false;
Course course;
course.LoadFromCRSFile( sCoursePath, m_pSongs );
if( course.m_iStages <= 0 ) return false;
pSongOut = course.m_apSongs[0];
pNotesOut = course.GetNotesForStage( 0 );
if( pNotesOut == NULL ) return false;
po_out.FromString( course.m_asModifiers[0] );
so_out.FromString( course.m_asModifiers[0] );
return true;
}
2002-08-01 13:42:56 +00:00
void SongManager::GetExtraStageInfo( bool bExtra2, CString sPreferredGroup, const StyleDef *sd,
2002-08-01 13:42:56 +00:00
Song*& pSongOut, Notes*& pNotesOut, PlayerOptions& po_out, SongOptions& so_out )
{
2002-08-30 20:49:56 +00:00
if(GetExtraStageInfoFromCourse(bExtra2, sPreferredGroup,
pSongOut, pNotesOut, po_out, so_out))
2002-08-01 13:42:56 +00:00
return;
// Choose a hard song for the extra stage
Song* pExtra1Song = NULL; // the absolute hardest Song and Notes. Use this for extra stage 1.
Notes* pExtra1Notes = NULL;
Song* pExtra2Song = NULL; // a medium-hard Song and Notes. Use this for extra stage 2.
Notes* pExtra2Notes = NULL;
CArray<Song*,Song*> apSongs;
SONGMAN->GetSongsInGroup( GAMESTATE->m_sPreferredGroup, apSongs );
for( int s=0; s<apSongs.GetSize(); s++ ) // foreach song
{
Song* pSong = apSongs[s];
CArray<Notes*,Notes*> apNotes;
pSong->GetNotesThatMatch( sd, 0, apNotes );
2002-08-01 13:42:56 +00:00
for( int n=0; n<apNotes.GetSize(); n++ ) // foreach Notes
{
Notes* pNotes = apNotes[n];
if( pExtra1Notes == NULL || CompareNotesPointersByDifficulty(pExtra1Notes,pNotes) == -1 ) // pNotes is harder than pHardestNotes
{
pExtra1Song = pSong;
pExtra1Notes = pNotes;
}
// for extra 2, we don't want to choose the hardest notes possible. So, we'll disgard Notes with meter > 8
if( bExtra2 && pNotes->m_iMeter > 8 )
continue; // skip
if( pExtra2Notes == NULL || CompareNotesPointersByDifficulty(pExtra2Notes,pNotes) == -1 ) // pNotes is harder than pHardestNotes
{
pExtra2Song = pSong;
pExtra2Notes = pNotes;
}
}
}
if( pExtra2Song == NULL && pExtra1Song != NULL )
{
pExtra2Song = pExtra1Song;
pExtra2Notes = pExtra1Notes;
}
// If there are any notes at all that match this NotesType, everything should be filled out.
// Also, it's guaranteed that there is at least one Notes that matches the NotesType because the player
// had to play something before reaching the extra stage!
ASSERT( pExtra2Song && pExtra1Song && pExtra2Notes && pExtra1Notes );
pSongOut = (bExtra2 ? pExtra2Song : pExtra1Song);
pNotesOut = (bExtra2 ? pExtra2Notes : pExtra1Notes);
po_out.Init();
so_out.Init();
po_out.m_bReverseScroll = true;
po_out.m_fArrowScrollSpeed = 1.5f;
so_out.m_DrainType = (bExtra2 ? SongOptions::DRAIN_SUDDEN_DEATH : SongOptions::DRAIN_NO_RECOVER);
// should we do something fancy here, like turn on different effects?
int iSongHash = GetHashForString( pSongOut->m_sSongDir );
2002-08-20 21:00:56 +00:00
switch( ((UINT)iSongHash) % 6 )
2002-08-01 13:42:56 +00:00
{
case 0: po_out.m_EffectType = PlayerOptions::EFFECT_DIZZY; break;
case 1: po_out.m_bDark = true; break;
case 2: po_out.m_EffectType = PlayerOptions::EFFECT_DRUNK; break;
case 3: po_out.m_EffectType = PlayerOptions::EFFECT_MINI; break;
case 4: po_out.m_EffectType = PlayerOptions::EFFECT_SPACE; break;
case 5: po_out.m_EffectType = PlayerOptions::EFFECT_WAVE; break;
default: ASSERT(0);
}
}
/* Pick a random song (for the demonstration). */
bool SongManager::ChooseRandomSong()
{
if( SONGMAN->m_pSongs.GetSize() == 0 )
return false;
int i;
for( i=0; i<600; i++ ) // try 600 times
{
Song* pSong = m_pSongs[ rand()%m_pSongs.GetSize() ];
for( int j=0; j<3; j++ ) // try 3 times
{
if( pSong->m_apNotes.GetSize() == 0 )
continue;
/* XXX: This assumes we're set to a style that doesn't use separate
* notes for each player, such as VERSUS. */
Notes* pNotes = pSong->m_apNotes[ rand()%pSong->m_apNotes.GetSize() ];
if( pNotes->m_NotesType != GAMESTATE->GetCurrentStyleDef()->m_NotesTypes[0] )
continue;
// found something we can use!
GAMESTATE->m_pCurSong = pSong;
for( int p=0; p<NUM_PLAYERS; p++ )
GAMESTATE->m_pCurNotes[p] = pNotes;
return true;
}
}
return false;
}