2002-06-14 22:25:22 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: Course
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
|
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Course.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "PrefsManager.h"
|
2002-07-02 17:34:20 +00:00
|
|
|
#include "Song.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "GameManager.h"
|
|
|
|
|
#include "SongManager.h"
|
|
|
|
|
#include "GameState.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageException.h"
|
|
|
|
|
#include "RageLog.h"
|
|
|
|
|
#include "MsdFile.h"
|
2002-07-28 20:28:37 +00:00
|
|
|
#include "PlayerOptions.h"
|
|
|
|
|
#include "SongOptions.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
|
2002-07-02 17:34:20 +00:00
|
|
|
|
|
|
|
|
void Course::LoadFromCRSFile( CString sPath, CArray<Song*,Song*> &apSongs )
|
|
|
|
|
{
|
2002-07-27 19:29:51 +00:00
|
|
|
MsdFile msd;
|
|
|
|
|
if( !msd.ReadFile(sPath) )
|
2002-07-04 21:05:18 +00:00
|
|
|
throw RageException( "Error opening CRS file '%s'.", sPath );
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
CString sDir, sFName, sExt;
|
|
|
|
|
splitrelpath( sPath, sDir, sFName, sExt );
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
CStringArray arrayPossibleBanners;
|
|
|
|
|
GetDirListing( "Courses\\" + sFName + ".png", arrayPossibleBanners, false, true );
|
|
|
|
|
GetDirListing( "Courses\\" + sFName + ".jpg", arrayPossibleBanners, false, true );
|
|
|
|
|
GetDirListing( "Courses\\" + sFName + ".bmp", arrayPossibleBanners, false, true );
|
|
|
|
|
GetDirListing( "Courses\\" + sFName + ".gif", arrayPossibleBanners, false, true );
|
|
|
|
|
if( arrayPossibleBanners.GetSize() > 0 )
|
|
|
|
|
m_sBannerPath = arrayPossibleBanners[0];
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
for( int i=0; i<msd.m_iNumValues; i++ )
|
2002-07-02 17:34:20 +00:00
|
|
|
{
|
2002-07-27 19:29:51 +00:00
|
|
|
CString sValueName = msd.m_szValuesAndParams[i][0];
|
|
|
|
|
CString* sParams = msd.m_sValuesAndParams[i];
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
// handle the data
|
|
|
|
|
if( 0 == stricmp(sValueName, "COURSE") )
|
|
|
|
|
m_sName = sParams[1];
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
else if( 0 == stricmp(sValueName, "REPEAT") )
|
2002-07-02 17:34:20 +00:00
|
|
|
{
|
2002-07-27 19:29:51 +00:00
|
|
|
sParams[1].MakeLower();
|
|
|
|
|
if( sParams[1].Find("yes") != -1 )
|
|
|
|
|
m_bRepeat = true;
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
else if( 0 == stricmp(sValueName, "LIVES") )
|
2002-07-02 17:34:20 +00:00
|
|
|
{
|
2002-07-27 19:29:51 +00:00
|
|
|
m_iLives = atoi( sParams[1] );
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
2002-07-31 04:06:34 +00:00
|
|
|
else if( 0 == stricmp(sValueName, "EXTRA") )
|
|
|
|
|
{
|
|
|
|
|
m_iExtra = atoi( sParams[1] );
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
else if( 0 == stricmp(sValueName, "SONG") )
|
2002-07-02 17:34:20 +00:00
|
|
|
{
|
2002-07-27 19:29:51 +00:00
|
|
|
CString sSongDir = "Songs\\" + sParams[1] + "\\";
|
|
|
|
|
CString sNotesDescription = sParams[2];
|
2002-08-01 13:42:56 +00:00
|
|
|
CString sModifiers = sParams[3];
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2002-07-03 21:27:26 +00:00
|
|
|
int i;
|
|
|
|
|
|
2002-07-02 17:34:20 +00:00
|
|
|
Song* pSong = NULL;
|
2002-07-27 19:29:51 +00:00
|
|
|
for( i=0; i<apSongs.GetSize(); i++ ) // foreach song
|
|
|
|
|
{
|
|
|
|
|
CString sThisSongDir = apSongs[i]->m_sSongDir;
|
|
|
|
|
if( 0 == stricmp(sThisSongDir, sSongDir) )
|
2002-07-02 17:34:20 +00:00
|
|
|
pSong = apSongs[i];
|
2002-07-27 19:29:51 +00:00
|
|
|
}
|
2002-07-02 17:34:20 +00:00
|
|
|
if( pSong == NULL ) // we didn't find the Song
|
|
|
|
|
continue; // skip this song
|
|
|
|
|
|
2002-08-01 13:42:56 +00:00
|
|
|
AddStage( pSong, sNotesDescription, sModifiers );
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "Unexpected value named '%s'", sValueName );
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
2002-07-23 01:41:40 +00:00
|
|
|
|
|
|
|
|
|
2002-07-29 03:06:55 +00:00
|
|
|
void Course::CreateEndlessCourseFromGroupAndDifficultyClass( CString sGroupName, DifficultyClass dc, CArray<Song*,Song*> &apSongsInGroup )
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
2002-07-29 03:06:55 +00:00
|
|
|
m_bRepeat = true;
|
|
|
|
|
m_bRandomize = true;
|
|
|
|
|
m_iLives = -1;
|
2002-08-01 20:30:40 +00:00
|
|
|
|
|
|
|
|
CStringArray asPossibleBannerPaths;
|
|
|
|
|
GetDirListing( "Songs\\" + sGroupName + "\\banner.png", asPossibleBannerPaths, false, true );
|
|
|
|
|
GetDirListing( "Songs\\" + sGroupName + "\\banner.jpg", asPossibleBannerPaths, false, true );
|
|
|
|
|
GetDirListing( "Songs\\" + sGroupName + "\\banner.gif", asPossibleBannerPaths, false, true );
|
|
|
|
|
GetDirListing( "Songs\\" + sGroupName + "\\banner.bmp", asPossibleBannerPaths, false, true );
|
|
|
|
|
if( asPossibleBannerPaths.GetSize() > 0 )
|
|
|
|
|
m_sBannerPath = asPossibleBannerPaths[0];
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
CString sShortGroupName = SONGMAN->ShortenGroupName( sGroupName );
|
|
|
|
|
|
|
|
|
|
m_sName = sShortGroupName + " ";
|
|
|
|
|
switch( dc )
|
|
|
|
|
{
|
|
|
|
|
case CLASS_EASY: m_sName += "Easy"; break;
|
|
|
|
|
case CLASS_MEDIUM: m_sName += "Medium"; break;
|
|
|
|
|
case CLASS_HARD: m_sName += "Hard"; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for( int s=0; s<apSongsInGroup.GetSize(); s++ )
|
|
|
|
|
{
|
|
|
|
|
Song* pSong = apSongsInGroup[s];
|
2002-08-01 13:42:56 +00:00
|
|
|
AddStage( pSong, DifficultyClassToString(dc), "" );
|
2002-07-23 01:41:40 +00:00
|
|
|
}
|
2002-09-04 03:29:42 +00:00
|
|
|
Shuffle();
|
2002-07-23 01:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
2002-09-04 03:29:42 +00:00
|
|
|
void Course::Shuffle()
|
|
|
|
|
{
|
|
|
|
|
/* Shuffle the list. */
|
|
|
|
|
for( int i = 0; i < m_iStages; ++i)
|
|
|
|
|
swap(SongOrdering[i], SongOrdering[rand() % m_iStages]);
|
|
|
|
|
}
|
2002-07-23 01:41:40 +00:00
|
|
|
|
|
|
|
|
Notes* Course::GetNotesForStage( int iStage )
|
|
|
|
|
{
|
|
|
|
|
Song* pSong = m_apSongs[iStage];
|
|
|
|
|
CString sDescription = m_asDescriptions[iStage];
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<pSong->m_apNotes.GetSize(); i++ )
|
|
|
|
|
{
|
|
|
|
|
Notes* pNotes = pSong->m_apNotes[i];
|
2002-09-06 08:56:28 +00:00
|
|
|
/* XXX: hmm. We need to match the first player, then set up other players
|
|
|
|
|
* later ... */
|
2002-07-23 01:41:40 +00:00
|
|
|
if( 0==stricmp(pNotes->m_sDescription, sDescription) &&
|
2002-09-06 08:56:28 +00:00
|
|
|
GAMESTATE->GetCurrentStyleDef()->MatchesNotesType(pNotes->m_NotesType, 0) )
|
2002-07-23 01:41:40 +00:00
|
|
|
return pNotes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Didn't find a matching description. Try to match the DifficultyClass instead.
|
|
|
|
|
DifficultyClass dc = Notes::DifficultyClassFromDescriptionAndMeter( sDescription, 5 );
|
|
|
|
|
|
|
|
|
|
for( i=0; i<pSong->m_apNotes.GetSize(); i++ )
|
|
|
|
|
{
|
|
|
|
|
Notes* pNotes = pSong->m_apNotes[i];
|
2002-09-06 08:56:28 +00:00
|
|
|
if( pNotes->m_DifficultyClass == dc &&
|
|
|
|
|
GAMESTATE->GetCurrentStyleDef()->MatchesNotesType(pNotes->m_NotesType, 0) )
|
2002-07-23 01:41:40 +00:00
|
|
|
return pNotes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-04 03:29:42 +00:00
|
|
|
/* When bShuffled is true, returns courses in the song ordering list. */
|
|
|
|
|
void Course::GetSongAndNotesForCurrentStyle(
|
|
|
|
|
CArray<Song*,Song*>& apSongsOut,
|
|
|
|
|
CArray<Notes*,Notes*>& apNotesOut,
|
|
|
|
|
CStringArray& asModifiersOut,
|
|
|
|
|
bool bShuffled )
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
|
|
|
|
for( int i=0; i<m_iStages; i++ )
|
|
|
|
|
{
|
2002-09-04 03:29:42 +00:00
|
|
|
int num = bShuffled? SongOrdering[i]:i;
|
|
|
|
|
|
|
|
|
|
Song* pSong = m_apSongs[num];
|
|
|
|
|
Notes* pNotes = GetNotesForStage( num );
|
|
|
|
|
CString sModifiers = m_asModifiers[num];
|
2002-07-23 01:41:40 +00:00
|
|
|
|
|
|
|
|
if( pNotes == NULL )
|
|
|
|
|
continue; // skip
|
|
|
|
|
|
|
|
|
|
apSongsOut.Add( pSong );
|
2002-08-01 13:42:56 +00:00
|
|
|
apNotesOut.Add( pNotes );
|
|
|
|
|
asModifiersOut.Add( sModifiers );
|
2002-07-23 01:41:40 +00:00
|
|
|
}
|
2002-07-27 19:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3DXCOLOR Course::GetColor()
|
|
|
|
|
{
|
|
|
|
|
// This could be made smarter
|
|
|
|
|
if( m_iStages >= 7 )
|
|
|
|
|
return D3DXCOLOR(1,0,0,1); // red
|
|
|
|
|
else if( m_iStages >= 4 )
|
|
|
|
|
return D3DXCOLOR(1,0.5f,0,1); // orange
|
|
|
|
|
else
|
|
|
|
|
return D3DXCOLOR(0,1,0,1); // green
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-28 20:28:37 +00:00
|
|
|
void Course::GetPlayerOptions( PlayerOptions* pPO_out )
|
|
|
|
|
{
|
|
|
|
|
*pPO_out = PlayerOptions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Course::GetSongOptions( SongOptions* pSO_out )
|
|
|
|
|
{
|
|
|
|
|
*pSO_out = SongOptions();
|
|
|
|
|
pSO_out->m_LifeType = (m_iLives==-1) ? SongOptions::LIFE_BAR : SongOptions::LIFE_BATTERY;
|
|
|
|
|
if( m_iLives != -1 )
|
|
|
|
|
pSO_out->m_iBatteryLives = m_iLives;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
//
|
|
|
|
|
// Sorting stuff
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int CompareCoursePointersByDifficulty(const void *arg1, const void *arg2)
|
|
|
|
|
{
|
|
|
|
|
Course* pCourse1 = *(Course**)arg1;
|
|
|
|
|
Course* pCourse2 = *(Course**)arg2;
|
|
|
|
|
|
|
|
|
|
float fScore1 = (float)pCourse1->m_iStages;
|
|
|
|
|
float fScore2 = (float)pCourse2->m_iStages;
|
|
|
|
|
|
|
|
|
|
if( fScore1 < fScore2 )
|
|
|
|
|
return -1;
|
|
|
|
|
else if( fScore1 == fScore2 )
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SortCoursePointerArrayByDifficulty( CArray<Course*,Course*> &apCourses )
|
|
|
|
|
{
|
|
|
|
|
qsort( apCourses.GetData(), apCourses.GetSize(), sizeof(Course*), CompareCoursePointersByDifficulty );
|
|
|
|
|
}
|