2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
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"
|
2003-02-16 04:28:17 +00:00
|
|
|
#include "song.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "GameManager.h"
|
|
|
|
|
#include "SongManager.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-11-11 04:53:31 +00:00
|
|
|
#include "RageUtil.h"
|
2003-02-10 23:17:57 +00:00
|
|
|
#include "TitleSubstitution.h"
|
2003-03-28 02:25:15 +00:00
|
|
|
#include "Notes.h"
|
|
|
|
|
#include "GameState.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
|
2002-12-17 05:07:56 +00:00
|
|
|
Course::Course()
|
|
|
|
|
{
|
2003-03-27 01:56:21 +00:00
|
|
|
m_bIsAutogen = false;
|
2002-12-17 05:07:56 +00:00
|
|
|
m_bRepeat = false;
|
|
|
|
|
m_bRandomize = false;
|
2003-03-07 05:24:52 +00:00
|
|
|
m_bDifficult = false;
|
2003-01-26 09:46:30 +00:00
|
|
|
m_iLives = -1;
|
2003-01-22 05:29:27 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Init high scores
|
|
|
|
|
//
|
2003-02-14 21:42:44 +00:00
|
|
|
for( unsigned i=0; i<NUM_NOTES_TYPES; i++ )
|
2003-02-17 20:35:20 +00:00
|
|
|
for( int j=0; j<NUM_RANKING_LINES; j++ )
|
2003-01-26 07:33:03 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
m_RankingScores[i][j].iDancePoints = 573;
|
|
|
|
|
m_RankingScores[i][j].fSurviveTime = 57.3f;
|
|
|
|
|
m_RankingScores[i][j].sName = DEFAULT_RANKING_NAME;
|
2003-01-26 07:33:03 +00:00
|
|
|
}
|
2003-01-22 05:29:27 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
for( unsigned m=0; m<NUM_MEMORY_CARDS; m++ )
|
|
|
|
|
for( unsigned i=0; i<NUM_NOTES_TYPES; i++ )
|
2003-01-26 07:33:03 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
m_MemCardScores[m][i].iNumTimesPlayed = 0;
|
|
|
|
|
m_MemCardScores[m][i].iDancePoints = 0;
|
|
|
|
|
m_MemCardScores[m][i].fSurviveTime = 0;
|
2003-01-26 07:33:03 +00:00
|
|
|
}
|
2002-12-17 05:07:56 +00:00
|
|
|
}
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2003-02-05 19:16:00 +00:00
|
|
|
/*
|
|
|
|
|
* GetSongDir() contains a path to the song, possibly a full path, eg:
|
|
|
|
|
* Songs\Group\SongName or
|
|
|
|
|
* My Other Song Folder\Group\SongName or
|
|
|
|
|
* c:\Corny J-pop\Group\SongName
|
|
|
|
|
*
|
|
|
|
|
* Most course group names are "Group\SongName", so we want to
|
|
|
|
|
* match against the last two elements. Let's also support
|
|
|
|
|
* "SongName" alone, since the group is only important when it's
|
|
|
|
|
* potentially ambiguous.
|
|
|
|
|
*
|
|
|
|
|
* Let's *not* support "Songs\Group\SongName" in course files.
|
|
|
|
|
* That's probably a common error, but that would result in
|
|
|
|
|
* course files floating around that only work for people who put
|
|
|
|
|
* songs in "Songs"; we don't want that.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-02-16 23:54:30 +00:00
|
|
|
Song *Course::FindSong(CString sGroup, CString sSong) const
|
2003-02-05 19:16:00 +00:00
|
|
|
{
|
|
|
|
|
const vector<Song*> &apSongs = SONGMAN->GetAllSongs();
|
|
|
|
|
|
|
|
|
|
// foreach song
|
|
|
|
|
for( unsigned i = 0; i < apSongs.size(); i++ )
|
|
|
|
|
{
|
2003-02-16 23:54:30 +00:00
|
|
|
Song* pSong = apSongs[i];
|
2003-02-05 19:16:00 +00:00
|
|
|
|
2003-02-17 05:16:56 +00:00
|
|
|
if( sGroup.size() && sGroup.CompareNoCase(pSong->m_sGroupName) != 0)
|
|
|
|
|
continue; /* wrong group */
|
|
|
|
|
|
|
|
|
|
CString sDir = pSong->GetSongDir();
|
|
|
|
|
sDir.Replace("\\","/");
|
|
|
|
|
CStringArray bits;
|
|
|
|
|
split( sDir, "/", bits );
|
|
|
|
|
ASSERT(bits.size() >= 2); /* should always have at least two parts */
|
|
|
|
|
CString sLastBit = bits[bits.size()-1];
|
|
|
|
|
|
|
|
|
|
// match on song dir or title (ala DWI)
|
|
|
|
|
if( sSong.CompareNoCase(sLastBit)==0 )
|
|
|
|
|
return pSong;
|
|
|
|
|
if( sSong.CompareNoCase(pSong->GetFullTranslitTitle())==0 )
|
|
|
|
|
return pSong;
|
2003-02-05 19:16:00 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-17 05:16:56 +00:00
|
|
|
LOG->Trace( "Course file '%s' contains a song '%s%s%s' that is not present",
|
2003-04-25 00:01:35 +00:00
|
|
|
m_sPath.c_str(), sGroup.c_str(), sGroup.size()? "/":"", sSong.c_str());
|
2003-02-16 23:54:30 +00:00
|
|
|
|
2003-02-17 05:16:56 +00:00
|
|
|
return NULL;
|
2003-02-05 19:16:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Course::LoadFromCRSFile( CString sPath )
|
2002-07-02 17:34:20 +00:00
|
|
|
{
|
2003-01-21 05:14:59 +00:00
|
|
|
m_sPath = sPath; // save path
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
MsdFile msd;
|
|
|
|
|
if( !msd.ReadFile(sPath) )
|
2003-04-25 00:01:35 +00:00
|
|
|
RageException::Throw( "Error opening CRS file '%s'.", sPath.c_str() );
|
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 );
|
2003-04-22 20:31:12 +00:00
|
|
|
sFName = sDir + sFName;
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
CStringArray arrayPossibleBanners;
|
2003-04-22 20:31:12 +00:00
|
|
|
GetDirListing( sFName + ".png", arrayPossibleBanners, false, true );
|
|
|
|
|
GetDirListing( sFName + ".jpg", arrayPossibleBanners, false, true );
|
|
|
|
|
GetDirListing( sFName + ".bmp", arrayPossibleBanners, false, true );
|
|
|
|
|
GetDirListing( sFName + ".gif", arrayPossibleBanners, false, true );
|
2002-10-31 02:11:52 +00:00
|
|
|
if( !arrayPossibleBanners.empty() )
|
2002-07-27 19:29:51 +00:00
|
|
|
m_sBannerPath = arrayPossibleBanners[0];
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2003-01-14 22:10:04 +00:00
|
|
|
for( unsigned i=0; i<msd.GetNumValues(); i++ )
|
2002-07-02 17:34:20 +00:00
|
|
|
{
|
2003-01-14 22:44:30 +00:00
|
|
|
CString sValueName = msd.GetParam(i, 0);
|
|
|
|
|
const MsdFile::value_t &sParams = msd.GetValue(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
|
|
|
{
|
2003-01-14 22:44:30 +00:00
|
|
|
CString str = sParams[1];
|
|
|
|
|
str.MakeLower();
|
|
|
|
|
if( str.Find("yes") != -1 )
|
2002-07-27 19:29:51 +00:00
|
|
|
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") )
|
|
|
|
|
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
|
|
|
{
|
2003-02-16 10:12:03 +00:00
|
|
|
Entry new_entry;
|
|
|
|
|
|
2003-02-16 23:54:30 +00:00
|
|
|
// infer entry::Type from the first param
|
2003-04-14 07:11:04 +00:00
|
|
|
if( sParams[1].Left(strlen("BEST")) == "BEST" )
|
2003-02-16 10:12:03 +00:00
|
|
|
{
|
2003-04-14 07:11:04 +00:00
|
|
|
new_entry.type = Entry::best;
|
|
|
|
|
new_entry.players_index = atoi( sParams[1].Right(sParams[1].size()-strlen("BEST")) ) - 1;
|
2003-02-16 10:12:03 +00:00
|
|
|
CLAMP( new_entry.players_index, 0, 500 );
|
|
|
|
|
}
|
2003-04-14 07:11:04 +00:00
|
|
|
else if( sParams[1].Left(strlen("WORST")) == "WORST" )
|
2003-02-16 10:12:03 +00:00
|
|
|
{
|
2003-04-14 07:11:04 +00:00
|
|
|
new_entry.type = Entry::worst;
|
|
|
|
|
new_entry.players_index = atoi( sParams[1].Right(sParams[1].size()-strlen("WORST")) ) - 1;
|
2003-02-16 10:12:03 +00:00
|
|
|
CLAMP( new_entry.players_index, 0, 500 );
|
|
|
|
|
}
|
|
|
|
|
else if( sParams[1] == "*" )
|
|
|
|
|
{
|
|
|
|
|
new_entry.type = Entry::random;
|
|
|
|
|
}
|
|
|
|
|
else if( sParams[1].Right(1) == "*" )
|
|
|
|
|
{
|
|
|
|
|
new_entry.type = Entry::random_within_group;
|
2003-02-16 23:54:30 +00:00
|
|
|
CString sSong = sParams[1];
|
|
|
|
|
sSong.Replace( "\\", "/" );
|
|
|
|
|
CStringArray bits;
|
|
|
|
|
split( sSong, "/", bits );
|
|
|
|
|
if( bits.size() == 2 )
|
|
|
|
|
new_entry.group_name = bits[0];
|
|
|
|
|
else
|
|
|
|
|
LOG->Warn( "Course file '%s' contains a random_within_group entry '%s' that is invalid. "
|
|
|
|
|
"Song should be in the format '<group>/*'.",
|
2003-04-25 00:01:35 +00:00
|
|
|
m_sPath.c_str(), sSong.c_str());
|
2003-02-16 23:54:30 +00:00
|
|
|
if( !SONGMAN->DoesGroupExist(new_entry.group_name) )
|
|
|
|
|
{
|
2003-06-15 01:24:12 +00:00
|
|
|
/* XXX: We need a place to put "user warnings". This is too loud for info.txt--
|
|
|
|
|
* it obscures important warnings--and regular users never look there, anyway. */
|
|
|
|
|
//LOG->Warn( "Course file '%s' random_within_group entry '%s' specifies a group that doesn't exist. "
|
|
|
|
|
// "This entry will be ignored.",
|
|
|
|
|
// m_sPath.c_str(), sSong.c_str());
|
2003-02-16 23:54:30 +00:00
|
|
|
continue; // skip this #SONG
|
|
|
|
|
}
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
new_entry.type = Entry::fixed;
|
2003-02-16 23:54:30 +00:00
|
|
|
|
|
|
|
|
CString sSong = sParams[1];
|
|
|
|
|
sSong.Replace( "\\", "/" );
|
|
|
|
|
CStringArray bits;
|
|
|
|
|
split( sSong, "/", bits );
|
2003-02-17 05:16:56 +00:00
|
|
|
if( bits.size() == 1 )
|
|
|
|
|
new_entry.pSong = FindSong( "", bits[0] );
|
|
|
|
|
else if( bits.size() == 2 )
|
2003-02-16 23:54:30 +00:00
|
|
|
new_entry.pSong = FindSong( bits[0], bits[1] );
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn( "Course file '%s' contains a fixed song entry '%s' that is invalid. "
|
|
|
|
|
"Song should be in the format '<group>/<song>'.",
|
2003-04-25 00:01:35 +00:00
|
|
|
m_sPath.c_str(), sSong.c_str());
|
2003-02-16 23:54:30 +00:00
|
|
|
continue; // skip this #SONG
|
|
|
|
|
}
|
|
|
|
|
if( !new_entry.pSong )
|
|
|
|
|
{
|
2003-06-15 01:24:12 +00:00
|
|
|
/* XXX: We need a place to put "user warnings". This is too loud for info.txt--
|
|
|
|
|
* it obscures important warnings--and regular users never look there, anyway. */
|
|
|
|
|
//LOG->Warn( "Course file '%s' contains a fixed song entry '%s' that does not exist. "
|
|
|
|
|
// "This entry will be ignored.",
|
|
|
|
|
// m_sPath.c_str(), sSong.c_str());
|
2003-02-16 23:54:30 +00:00
|
|
|
continue; // skip this #SONG
|
|
|
|
|
}
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_entry.difficulty = StringToDifficulty( sParams[2] );
|
|
|
|
|
if( new_entry.difficulty == DIFFICULTY_INVALID )
|
|
|
|
|
{
|
|
|
|
|
int retval = sscanf( sParams[2], "%d..%d", &new_entry.low_meter, &new_entry.high_meter );
|
2003-05-30 09:19:43 +00:00
|
|
|
if( retval == 1 )
|
|
|
|
|
new_entry.high_meter = new_entry.low_meter;
|
|
|
|
|
else if( retval != 2 )
|
2003-02-16 10:12:03 +00:00
|
|
|
{
|
2003-05-30 09:19:43 +00:00
|
|
|
LOG->Warn("Course file '%s' contains an invalid difficulty setting: \"%s\", 3..6 used instead",
|
|
|
|
|
m_sPath.c_str(), sParams[2].c_str());
|
2003-02-16 10:12:03 +00:00
|
|
|
new_entry.low_meter = 3;
|
|
|
|
|
new_entry.high_meter = 6;
|
|
|
|
|
}
|
2002-10-12 19:30:15 +00:00
|
|
|
}
|
2003-02-16 10:12:03 +00:00
|
|
|
|
|
|
|
|
new_entry.modifiers = sParams[3];
|
|
|
|
|
|
|
|
|
|
m_entries.push_back( new_entry );
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
2003-04-25 00:01:35 +00:00
|
|
|
LOG->Trace( "Unexpected value named '%s'", sValueName.c_str() );
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
2003-02-18 20:34:38 +00:00
|
|
|
static TitleSubst tsub("courses");
|
2003-02-10 23:17:57 +00:00
|
|
|
|
|
|
|
|
CString ignore;
|
|
|
|
|
tsub.Subst(m_sName, ignore, ignore,
|
|
|
|
|
ignore, ignore, ignore);
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
2002-07-23 01:41:40 +00:00
|
|
|
|
|
|
|
|
|
2003-04-11 00:12:22 +00:00
|
|
|
void Course::Save()
|
|
|
|
|
{
|
|
|
|
|
ASSERT( !m_bIsAutogen );
|
|
|
|
|
|
|
|
|
|
FILE* fp = fopen( m_sPath, "w" );
|
|
|
|
|
if( fp == NULL )
|
|
|
|
|
{
|
2003-04-25 00:01:35 +00:00
|
|
|
LOG->Warn( "Could not write course file '%s'.", m_sPath.c_str() );
|
2003-04-11 00:12:22 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-25 00:01:35 +00:00
|
|
|
fprintf( fp, "#COURSE:%s;\n", m_sName.c_str() );
|
2003-04-11 00:12:22 +00:00
|
|
|
fprintf( fp, "#REPEAT:%s;\n", m_bRepeat ? "YES" : "NO" );
|
|
|
|
|
fprintf( fp, "#LIVES:%i;\n", m_iLives );
|
|
|
|
|
fprintf( fp, "#EXTRA:%i;\n", m_iExtra );
|
|
|
|
|
|
|
|
|
|
for( unsigned i=0; i<m_entries.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
const Entry& entry = m_entries[i];
|
|
|
|
|
|
|
|
|
|
switch( entry.type )
|
|
|
|
|
{
|
|
|
|
|
case Entry::fixed:
|
2003-04-25 00:01:35 +00:00
|
|
|
fprintf( fp, "#SONG:%s", entry.pSong->GetSongDir().c_str() );
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
|
|
|
|
case Entry::random:
|
|
|
|
|
fprintf( fp, "#SONG:*" );
|
|
|
|
|
break;
|
|
|
|
|
case Entry::random_within_group:
|
2003-04-25 00:01:35 +00:00
|
|
|
fprintf( fp, "#SONG:%s/*", entry.group_name.c_str() );
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
2003-04-14 07:11:04 +00:00
|
|
|
case Entry::best:
|
|
|
|
|
fprintf( fp, "#SONG:BEST%d", entry.players_index+1 );
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
2003-04-14 07:11:04 +00:00
|
|
|
case Entry::worst:
|
|
|
|
|
fprintf( fp, "#SONG:WORST%d", entry.players_index+1 );
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( entry.difficulty != DIFFICULTY_INVALID )
|
2003-04-25 00:01:35 +00:00
|
|
|
fprintf( fp, ":%s", DifficultyToString(entry.difficulty).c_str() );
|
2003-04-11 00:12:22 +00:00
|
|
|
|
|
|
|
|
if( entry.low_meter != -1 && entry.high_meter != -1 )
|
|
|
|
|
fprintf( fp, ":%d..%d", entry.low_meter, entry.high_meter );
|
|
|
|
|
|
|
|
|
|
fprintf( fp, ";\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose( fp );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-27 01:56:21 +00:00
|
|
|
void Course::AutogenEndlessFromGroup( CString sGroupName, vector<Song*> &apSongsInGroup )
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
2003-03-27 01:56:21 +00:00
|
|
|
m_bIsAutogen = true;
|
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
|
|
|
|
2003-03-27 01:56:21 +00:00
|
|
|
m_sName = SONGMAN->ShortenGroupName( sGroupName );
|
2003-05-30 19:40:10 +00:00
|
|
|
m_sBannerPath = SONGMAN->GetGroupBannerPath( sGroupName );
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2003-02-24 00:58:04 +00:00
|
|
|
// 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
|
2003-02-16 10:12:03 +00:00
|
|
|
Entry e;
|
|
|
|
|
e.type = Entry::random_within_group;
|
|
|
|
|
e.group_name = sGroupName;
|
2003-03-27 01:56:21 +00:00
|
|
|
e.difficulty = DIFFICULTY_MEDIUM;
|
2003-02-24 00:58:04 +00:00
|
|
|
|
|
|
|
|
vector<Song*> vSongs;
|
|
|
|
|
SONGMAN->GetSongs( vSongs, e.group_name );
|
|
|
|
|
for( unsigned i = 0; i < vSongs.size(); ++i)
|
|
|
|
|
m_entries.push_back( e );
|
2002-07-23 01:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-27 01:56:21 +00:00
|
|
|
void Course::AutogenNonstopFromGroup( CString sGroupName, vector<Song*> &apSongsInGroup )
|
|
|
|
|
{
|
|
|
|
|
AutogenEndlessFromGroup( sGroupName, apSongsInGroup );
|
|
|
|
|
|
|
|
|
|
m_bRepeat = false;
|
|
|
|
|
|
|
|
|
|
m_sName += " Random";
|
|
|
|
|
|
|
|
|
|
// resize to 4
|
|
|
|
|
while( m_entries.size() < 4 )
|
|
|
|
|
m_entries.push_back( m_entries[0] );
|
|
|
|
|
while( m_entries.size() > 4 )
|
|
|
|
|
m_entries.pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
|
|
|
|
|
bool Course::HasDifficult() const
|
2002-09-04 03:29:42 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
for( unsigned i=0; i<m_entries.size(); i++ )
|
|
|
|
|
if( m_entries[i].difficulty >= DIFFICULTY_HARD )
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2002-09-04 03:29:42 +00:00
|
|
|
}
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
bool Course::IsPlayableIn( NotesType nt ) const
|
|
|
|
|
{
|
2003-02-24 00:58:04 +00:00
|
|
|
/* XXX: Is this good enough? This needs to be guaranteed: if we say
|
|
|
|
|
* a course is playable and it's not, we'll crash in ScreenGameplay. */
|
|
|
|
|
|
|
|
|
|
vector<Song*> vSongs;
|
|
|
|
|
vector<Notes*> vNotes;
|
|
|
|
|
vector<CString> vsModifiers;
|
2003-06-06 19:42:53 +00:00
|
|
|
GetStageInfo( vSongs, vNotes, vsModifiers, nt);
|
2003-02-24 00:58:04 +00:00
|
|
|
|
|
|
|
|
return vNotes.size() > 0;
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
2003-02-14 21:42:44 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
|
|
|
|
|
void Course::GetStageInfo(
|
2003-02-14 21:42:44 +00:00
|
|
|
vector<Song*>& vSongsOut,
|
|
|
|
|
vector<Notes*>& vNotesOut,
|
|
|
|
|
vector<CString>& vsModifiersOut,
|
2003-06-06 19:42:53 +00:00
|
|
|
NotesType nt ) const
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
2003-02-16 10:12:03 +00:00
|
|
|
vector<Entry> entries = m_entries;
|
2003-02-14 21:42:44 +00:00
|
|
|
|
|
|
|
|
if( m_bRandomize )
|
|
|
|
|
random_shuffle( entries.begin(), entries.end() );
|
2003-02-05 20:00:49 +00:00
|
|
|
|
2003-02-22 22:04:44 +00:00
|
|
|
vector<Song*> vSongsByMostPlayed;
|
2003-02-17 02:45:30 +00:00
|
|
|
|
2003-02-24 00:09:34 +00:00
|
|
|
vector<Song*> AllSongsShuffled = SONGMAN->GetAllSongs();
|
|
|
|
|
random_shuffle( AllSongsShuffled.begin(), AllSongsShuffled.end() );
|
|
|
|
|
int CurSong = 0; /* Current offset into AllSongsShuffled */
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
for( unsigned i=0; i<entries.size(); i++ )
|
2003-02-05 20:00:49 +00:00
|
|
|
{
|
2003-02-16 10:12:03 +00:00
|
|
|
const Entry& e = entries[i];
|
2003-02-05 20:00:49 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
Song* pSong = NULL; // fill this in
|
|
|
|
|
Notes* pNotes = NULL; // fill this in
|
2003-02-05 20:00:49 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
switch( e.type )
|
|
|
|
|
{
|
|
|
|
|
case Entry::fixed:
|
2003-02-16 23:54:30 +00:00
|
|
|
pSong = e.pSong;
|
|
|
|
|
if( pSong )
|
|
|
|
|
{
|
|
|
|
|
if( e.difficulty == DIFFICULTY_INVALID )
|
2003-04-15 22:55:24 +00:00
|
|
|
pNotes = pSong->GetNotes( nt, e.low_meter, e.high_meter, PREFSMAN->m_bAutogenMissingTypes );
|
2003-02-16 23:54:30 +00:00
|
|
|
else
|
2003-04-15 22:55:24 +00:00
|
|
|
pNotes = pSong->GetNotes( nt, e.difficulty, PREFSMAN->m_bAutogenMissingTypes );
|
2003-02-16 23:54:30 +00:00
|
|
|
}
|
2003-02-16 10:12:03 +00:00
|
|
|
break;
|
|
|
|
|
case Entry::random:
|
|
|
|
|
case Entry::random_within_group:
|
|
|
|
|
{
|
2003-02-24 00:09:34 +00:00
|
|
|
// find a song with the notes we want
|
|
|
|
|
for( unsigned j=0; j<AllSongsShuffled.size(); j++ )
|
2003-02-17 02:45:30 +00:00
|
|
|
{
|
2003-02-24 00:09:34 +00:00
|
|
|
/* See if the first song matches what we want. */
|
|
|
|
|
pSong = AllSongsShuffled[CurSong];
|
|
|
|
|
CurSong = (CurSong+1) % AllSongsShuffled.size();
|
2003-02-16 10:12:03 +00:00
|
|
|
|
2003-02-24 00:09:34 +00:00
|
|
|
if(e.type == Entry::random_within_group &&
|
|
|
|
|
pSong->m_sGroupName.CompareNoCase(e.group_name))
|
|
|
|
|
continue; /* wrong group */
|
2003-02-16 10:12:03 +00:00
|
|
|
|
|
|
|
|
if( e.difficulty == DIFFICULTY_INVALID )
|
2003-04-15 22:55:24 +00:00
|
|
|
pNotes = pSong->GetNotes( nt, e.low_meter, e.high_meter, PREFSMAN->m_bAutogenMissingTypes );
|
2003-02-16 10:12:03 +00:00
|
|
|
else
|
2003-04-15 22:55:24 +00:00
|
|
|
pNotes = pSong->GetNotes( nt, e.difficulty, PREFSMAN->m_bAutogenMissingTypes );
|
2003-02-24 00:09:34 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
if( pNotes ) // found a match
|
|
|
|
|
break; // stop searching
|
2003-02-24 00:09:34 +00:00
|
|
|
|
|
|
|
|
pSong = NULL;
|
|
|
|
|
pNotes = NULL;
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-04-14 07:11:04 +00:00
|
|
|
case Entry::best:
|
|
|
|
|
case Entry::worst:
|
2003-02-16 10:12:03 +00:00
|
|
|
{
|
2003-02-22 22:04:44 +00:00
|
|
|
if(vSongsByMostPlayed.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
/* Probably the first time getting here; fill it in just once. */
|
|
|
|
|
/* XXX: This is still expensive enough to cause a noticable
|
|
|
|
|
* frame drop when scrolling over best/worst entries. */
|
|
|
|
|
vSongsByMostPlayed = SONGMAN->GetAllSongs();
|
|
|
|
|
SortSongPointerArrayByMostPlayed( vSongsByMostPlayed );
|
|
|
|
|
|
|
|
|
|
// filter out songs that don't have both medium and hard steps and long ver sons
|
|
|
|
|
for( int j=vSongsByMostPlayed.size()-1; j>=0; j-- )
|
|
|
|
|
{
|
|
|
|
|
Song* pSong = vSongsByMostPlayed[j];
|
|
|
|
|
if( pSong->m_fMusicLengthSeconds > PREFSMAN->m_fLongVerSongSeconds ||
|
|
|
|
|
pSong->m_fMusicLengthSeconds > PREFSMAN->m_fMarathonVerSongSeconds ||
|
2003-04-15 22:55:24 +00:00
|
|
|
!pSong->GetNotes(nt, DIFFICULTY_MEDIUM, PREFSMAN->m_bAutogenMissingTypes) ||
|
|
|
|
|
!pSong->GetNotes(nt, DIFFICULTY_HARD, PREFSMAN->m_bAutogenMissingTypes) )
|
2003-02-22 22:04:44 +00:00
|
|
|
vSongsByMostPlayed.erase( vSongsByMostPlayed.begin()+j );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
if( e.players_index >= (int)vSongsByMostPlayed.size() )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
switch( e.type )
|
|
|
|
|
{
|
2003-04-14 07:11:04 +00:00
|
|
|
case Entry::best:
|
2003-02-16 10:12:03 +00:00
|
|
|
pSong = vSongsByMostPlayed[e.players_index];
|
|
|
|
|
break;
|
2003-04-14 07:11:04 +00:00
|
|
|
case Entry::worst:
|
2003-02-16 10:12:03 +00:00
|
|
|
pSong = vSongsByMostPlayed[vSongsByMostPlayed.size()-1-e.players_index];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( e.difficulty == DIFFICULTY_INVALID )
|
2003-04-15 22:55:24 +00:00
|
|
|
pNotes = pSong->GetNotes( nt, e.low_meter, e.high_meter, PREFSMAN->m_bAutogenMissingTypes );
|
2003-02-16 10:12:03 +00:00
|
|
|
else
|
2003-04-15 22:55:24 +00:00
|
|
|
pNotes = pSong->GetNotes( nt, e.difficulty, PREFSMAN->m_bAutogenMissingTypes );
|
2003-02-16 10:12:03 +00:00
|
|
|
|
|
|
|
|
if( pNotes == NULL )
|
|
|
|
|
pNotes = pSong->GetClosestNotes( nt, DIFFICULTY_MEDIUM );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
2002-12-17 05:07:56 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
if( !pSong || !pNotes )
|
|
|
|
|
continue; // this song entry isn't playable. Skip.
|
2002-12-17 05:07:56 +00:00
|
|
|
|
2003-03-28 02:25:15 +00:00
|
|
|
if(GAMESTATE->m_bDifficultCourses)
|
|
|
|
|
{
|
|
|
|
|
/* See if we can find a NoteData that's one notch more difficult than
|
|
|
|
|
* the one we found above. */
|
|
|
|
|
Difficulty dc = pNotes->GetDifficulty();
|
|
|
|
|
if(dc < DIFFICULTY_CHALLENGE)
|
|
|
|
|
{
|
|
|
|
|
dc = Difficulty(dc + 1);
|
2003-04-15 22:55:24 +00:00
|
|
|
Notes* pNewNotes = pSong->GetNotes( nt, dc, PREFSMAN->m_bAutogenMissingTypes );
|
2003-03-28 02:25:15 +00:00
|
|
|
if(pNewNotes)
|
|
|
|
|
pNotes = pNewNotes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
vSongsOut.push_back( pSong );
|
|
|
|
|
vNotesOut.push_back( pNotes );
|
2003-02-16 10:12:03 +00:00
|
|
|
vsModifiersOut.push_back( e.modifiers );
|
2003-02-14 21:42:44 +00:00
|
|
|
}
|
2003-03-28 02:25:15 +00:00
|
|
|
|
|
|
|
|
|
2002-12-17 05:07:56 +00:00
|
|
|
}
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
bool Course::GetFirstStageInfo(
|
|
|
|
|
Song*& pSongOut,
|
|
|
|
|
Notes*& pNotesOut,
|
|
|
|
|
CString& sModifiersOut,
|
|
|
|
|
NotesType nt ) const
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
vector<Song*> vSongs;
|
|
|
|
|
vector<Notes*> vNotes;
|
|
|
|
|
vector<CString> vsModifiers;
|
|
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
GetStageInfo(
|
2003-02-14 21:42:44 +00:00
|
|
|
vSongs,
|
|
|
|
|
vNotes,
|
|
|
|
|
vsModifiers,
|
2003-06-06 19:42:53 +00:00
|
|
|
nt );
|
2003-02-14 21:42:44 +00:00
|
|
|
if( vSongs.empty() )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
pSongOut = vSongs[0];
|
|
|
|
|
pNotesOut = vNotes[0];
|
|
|
|
|
sModifiersOut = vsModifiers[0];
|
|
|
|
|
return true;
|
2002-07-27 19:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
RageColor Course::GetColor() const
|
2002-07-27 19:29:51 +00:00
|
|
|
{
|
|
|
|
|
// This could be made smarter
|
2003-02-14 21:42:44 +00:00
|
|
|
if( m_entries.size() >= 7 )
|
2002-10-28 05:30:45 +00:00
|
|
|
return RageColor(1,0,0,1); // red
|
2003-02-14 21:42:44 +00:00
|
|
|
else if( m_entries.size() >= 4 )
|
2002-10-28 05:30:45 +00:00
|
|
|
return RageColor(1,0.5f,0,1); // orange
|
2002-07-27 19:29:51 +00:00
|
|
|
else
|
2002-10-28 05:30:45 +00:00
|
|
|
return RageColor(0,1,0,1); // green
|
2002-07-27 19:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
bool Course::IsMysterySong( int stage ) const
|
2002-07-28 20:28:37 +00:00
|
|
|
{
|
2003-02-16 10:12:03 +00:00
|
|
|
switch( m_entries[stage].type )
|
|
|
|
|
{
|
|
|
|
|
case Entry::fixed: return false;
|
|
|
|
|
case Entry::random: return true;
|
|
|
|
|
case Entry::random_within_group: return true;
|
2003-04-14 07:11:04 +00:00
|
|
|
case Entry::best: return false;
|
|
|
|
|
case Entry::worst: return false;
|
2003-02-16 10:12:03 +00:00
|
|
|
default: ASSERT(0); return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Difficulty Course::GetDifficulty( int stage ) const
|
|
|
|
|
{
|
2003-04-20 01:26:49 +00:00
|
|
|
Difficulty dc = m_entries[stage].difficulty;
|
2003-04-20 20:38:17 +00:00
|
|
|
|
|
|
|
|
if(GAMESTATE->m_bDifficultCourses && dc < DIFFICULTY_CHALLENGE)
|
2003-04-20 01:26:49 +00:00
|
|
|
dc = Difficulty(dc + 1);
|
|
|
|
|
|
|
|
|
|
return dc;
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Course::GetMeterRange( int stage, int& iMeterLowOut, int& iMeterHighOut ) const
|
|
|
|
|
{
|
|
|
|
|
iMeterLowOut = m_entries[stage].low_meter;
|
|
|
|
|
iMeterHighOut = m_entries[stage].high_meter;
|
2002-07-28 20:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
bool Course::ContainsAnyMysterySongs() const
|
2002-07-28 20:28:37 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
for( unsigned i=0; i<m_entries.size(); i++ )
|
|
|
|
|
if( IsMysterySong(i) )
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
2002-07-28 20:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
bool Course::GetTotalSeconds( float& fSecondsOut ) const
|
2002-12-17 05:23:45 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
if( ContainsAnyMysterySongs() )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
vector<Song*> vSongsOut;
|
|
|
|
|
vector<Notes*> vNotesOut;
|
|
|
|
|
vector<CString> vsModifiersOut;
|
2003-02-16 10:12:03 +00:00
|
|
|
GetStageInfo(
|
2003-02-14 21:42:44 +00:00
|
|
|
vSongsOut,
|
|
|
|
|
vNotesOut,
|
|
|
|
|
vsModifiersOut,
|
2003-06-06 19:42:53 +00:00
|
|
|
NOTES_TYPE_DANCE_SINGLE ); // doesn't matter
|
2003-02-14 21:42:44 +00:00
|
|
|
|
|
|
|
|
fSecondsOut = 0;
|
|
|
|
|
for( unsigned i=0; i<vSongsOut.size(); i++ )
|
|
|
|
|
fSecondsOut += vSongsOut[i]->m_fMusicLengthSeconds;
|
|
|
|
|
return true;
|
2002-12-17 05:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-24 02:43:07 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
struct RankingToInsert
|
2003-01-24 02:43:07 +00:00
|
|
|
{
|
|
|
|
|
PlayerNumber pn;
|
2003-01-27 02:00:38 +00:00
|
|
|
int iDancePoints;
|
|
|
|
|
float fSurviveTime;
|
2003-01-24 02:43:07 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
static int CompareDescending( const RankingToInsert &hs1, const RankingToInsert &hs2 )
|
2003-01-24 02:43:07 +00:00
|
|
|
{
|
|
|
|
|
if( hs1.iDancePoints > hs2.iDancePoints ) return -1;
|
|
|
|
|
else if( hs1.iDancePoints == hs2.iDancePoints ) return 0;
|
|
|
|
|
else return +1;
|
|
|
|
|
}
|
2003-02-14 21:42:44 +00:00
|
|
|
static void SortDescending( vector<RankingToInsert>& vHSout )
|
2003-01-24 02:43:07 +00:00
|
|
|
{
|
|
|
|
|
sort( vHSout.begin(), vHSout.end(), CompareDescending );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
void Course::AddScores( NotesType nt, bool bPlayerEnabled[NUM_PLAYERS], int iDancePoints[NUM_PLAYERS], float fSurviveTime[NUM_PLAYERS], int iRankingIndexOut[NUM_PLAYERS], bool bNewRecordOut[NUM_PLAYERS] )
|
2003-01-24 02:43:07 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
vector<RankingToInsert> vHS;
|
2003-01-24 02:43:07 +00:00
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
|
|
|
|
{
|
2003-01-27 02:00:38 +00:00
|
|
|
iRankingIndexOut[p] = -1;
|
2003-02-16 07:54:41 +00:00
|
|
|
bNewRecordOut[p] = false;
|
2003-01-24 02:43:07 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
if( !bPlayerEnabled[p] )
|
2003-01-24 02:43:07 +00:00
|
|
|
continue; // skip
|
2003-02-14 21:42:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update memory card
|
|
|
|
|
m_MemCardScores[p][nt].iNumTimesPlayed++;
|
2003-02-16 10:12:03 +00:00
|
|
|
m_MemCardScores[MEMORY_CARD_MACHINE][nt].iNumTimesPlayed++;
|
2003-02-14 21:42:44 +00:00
|
|
|
|
|
|
|
|
if( iDancePoints[p] > m_MemCardScores[p][nt].iDancePoints )
|
|
|
|
|
{
|
|
|
|
|
m_MemCardScores[p][nt].iDancePoints = iDancePoints[p];
|
|
|
|
|
m_MemCardScores[p][nt].fSurviveTime = fSurviveTime[p];
|
|
|
|
|
bNewRecordOut[p] = true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
if( iDancePoints[p] > m_MemCardScores[MEMORY_CARD_MACHINE][nt].iDancePoints )
|
|
|
|
|
{
|
|
|
|
|
m_MemCardScores[MEMORY_CARD_MACHINE][nt].iDancePoints = iDancePoints[p];
|
|
|
|
|
m_MemCardScores[MEMORY_CARD_MACHINE][nt].fSurviveTime = fSurviveTime[p];
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-24 02:43:07 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
// Update Ranking
|
|
|
|
|
RankingToInsert hs;
|
2003-01-24 02:43:07 +00:00
|
|
|
hs.iDancePoints = iDancePoints[p];
|
|
|
|
|
hs.fSurviveTime = fSurviveTime[p];
|
|
|
|
|
hs.pn = (PlayerNumber)p;
|
|
|
|
|
vHS.push_back( hs );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sort descending before inserting.
|
|
|
|
|
// This guarantees that a high score will not switch poitions on us when we later insert scores for the other player
|
2003-02-14 21:42:44 +00:00
|
|
|
RankingToInsert::SortDescending( vHS );
|
2003-01-24 02:43:07 +00:00
|
|
|
|
|
|
|
|
for( unsigned i=0; i<vHS.size(); i++ )
|
|
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
RankingToInsert& newHS = vHS[i];
|
|
|
|
|
RankingScore* rankingScores = m_RankingScores[nt];
|
2003-01-27 02:00:38 +00:00
|
|
|
for( int i=0; i<NUM_RANKING_LINES; i++ )
|
2003-01-24 02:43:07 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
if( newHS.iDancePoints > rankingScores[i].iDancePoints )
|
2003-01-24 02:43:07 +00:00
|
|
|
{
|
|
|
|
|
// We found the insert point. Shift down.
|
2003-02-16 10:12:03 +00:00
|
|
|
for( int j=NUM_RANKING_LINES-1; j>i; j-- )
|
2003-02-14 21:42:44 +00:00
|
|
|
rankingScores[j] = rankingScores[j-1];
|
2003-01-24 02:43:07 +00:00
|
|
|
// insert
|
2003-02-14 21:42:44 +00:00
|
|
|
rankingScores[i].fSurviveTime = newHS.fSurviveTime;
|
|
|
|
|
rankingScores[i].iDancePoints = newHS.iDancePoints;
|
|
|
|
|
rankingScores[i].sName = DEFAULT_RANKING_NAME;
|
2003-01-27 02:00:38 +00:00
|
|
|
iRankingIndexOut[newHS.pn] = i;
|
2003-02-16 10:12:03 +00:00
|
|
|
break;
|
2003-01-24 02:43:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
//
|
|
|
|
|
// Sorting stuff
|
|
|
|
|
//
|
2003-03-27 01:56:21 +00:00
|
|
|
static bool CompareCoursePointersByName(const Course* pCourse1, const Course* pCourse2)
|
|
|
|
|
{
|
|
|
|
|
// HACK: strcmp and other string comparators appear to eat whitespace.
|
|
|
|
|
// For example, the string "Players Best 13-16" is sorted between
|
|
|
|
|
// "Players Best 1-4" and "Players Best 5-8". Replace the string " "
|
|
|
|
|
// with " 0" for comparison only.
|
|
|
|
|
|
|
|
|
|
// XXX: That doesn't happen to me, and it shouldn't (strcmp is strictly
|
|
|
|
|
// a byte sort, though CompareNoCase doesn't use strcmp). Are you sure
|
|
|
|
|
// you didn't have only one space before? -glenn
|
|
|
|
|
CString sName1 = pCourse1->m_sName;
|
|
|
|
|
CString sName2 = pCourse2->m_sName;
|
|
|
|
|
sName1.Replace( " " , " 0" );
|
|
|
|
|
sName2.Replace( " " , " 0" );
|
|
|
|
|
return sName1.CompareNoCase( sName2 ) == -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool CompareCoursePointersByAutogen(const Course* pCourse1, const Course* pCourse2)
|
|
|
|
|
{
|
|
|
|
|
int b1 = pCourse1->m_bIsAutogen;
|
|
|
|
|
int b2 = pCourse2->m_bIsAutogen;
|
|
|
|
|
if( b1 < b2 )
|
|
|
|
|
return true;
|
|
|
|
|
else if( b1 > b2 )
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return CompareCoursePointersByName(pCourse1,pCourse2);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-16 08:11:41 +00:00
|
|
|
static bool CompareCoursePointersByDifficulty(const Course* pCourse1, const Course* pCourse2)
|
2002-07-27 19:29:51 +00:00
|
|
|
{
|
2003-02-16 23:54:30 +00:00
|
|
|
int iNum1 = pCourse1->GetEstimatedNumStages();
|
|
|
|
|
int iNum2 = pCourse2->GetEstimatedNumStages();
|
|
|
|
|
if( iNum1 < iNum2 )
|
|
|
|
|
return true;
|
|
|
|
|
else if( iNum1 > iNum2 )
|
|
|
|
|
return false;
|
|
|
|
|
else // iNum1 == iNum2
|
2003-03-27 01:56:21 +00:00
|
|
|
return CompareCoursePointersByAutogen( pCourse1, pCourse2 );
|
2002-07-27 19:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-03 05:56:28 +00:00
|
|
|
void SortCoursePointerArrayByDifficulty( vector<Course*> &apCourses )
|
2002-07-27 19:29:51 +00:00
|
|
|
{
|
2002-10-24 08:40:27 +00:00
|
|
|
sort( apCourses.begin(), apCourses.end(), CompareCoursePointersByDifficulty );
|
2002-07-27 19:29:51 +00:00
|
|
|
}
|
2003-04-19 18:51:13 +00:00
|
|
|
|
|
|
|
|
bool Course::HasBanner() const
|
|
|
|
|
{
|
|
|
|
|
return m_sBannerPath != "" && IsAFile(m_sBannerPath);
|
|
|
|
|
}
|