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"
|
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"
|
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-02-14 21:42:44 +00:00
|
|
|
m_bIsAutoGen = false;
|
2002-12-17 05:07:56 +00:00
|
|
|
m_bRepeat = false;
|
|
|
|
|
m_bRandomize = 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++ )
|
|
|
|
|
for( unsigned 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-14 21:42:44 +00:00
|
|
|
Song *Course::FindSong(CString sSongDir) const
|
2003-02-05 19:16:00 +00:00
|
|
|
{
|
|
|
|
|
const vector<Song*> &apSongs = SONGMAN->GetAllSongs();
|
|
|
|
|
|
|
|
|
|
CStringArray split_SongDir;
|
|
|
|
|
sSongDir.Replace("\\", "/");
|
|
|
|
|
split( sSongDir, "/", split_SongDir, true );
|
|
|
|
|
|
|
|
|
|
if( split_SongDir.size() > 2 )
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn( "Course file \"%s\" path \"%s\" should contain "
|
|
|
|
|
"at most one backslash; ignored.",
|
|
|
|
|
m_sPath.GetString(), sSongDir.GetString());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// foreach song
|
|
|
|
|
for( unsigned i = 0; i < apSongs.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
CString dir = apSongs[i]->GetSongDir();
|
|
|
|
|
dir.Replace("\\", "/");
|
|
|
|
|
CStringArray splitted; /* splat! */
|
|
|
|
|
split( dir, "/", splitted, true );
|
|
|
|
|
bool matches = true;
|
|
|
|
|
|
|
|
|
|
int split_no = splitted.size()-1;
|
|
|
|
|
int SongDir_no = split_SongDir.size()-1;
|
|
|
|
|
|
|
|
|
|
while( split_no >= 0 && SongDir_no >= 0 ) {
|
|
|
|
|
if( stricmp(splitted[split_no--], split_SongDir[SongDir_no--] ) )
|
|
|
|
|
matches=false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(matches)
|
|
|
|
|
return apSongs[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG->Trace( "Course \"%s\": couldn't match song \"%s\"",
|
|
|
|
|
m_sPath.GetString(), sSongDir.GetString());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) )
|
2002-12-21 18:36:10 +00:00
|
|
|
RageException::Throw( "Error opening CRS file '%s'.", sPath.GetString() );
|
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;
|
2003-02-14 08:15:15 +00:00
|
|
|
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 );
|
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
|
|
|
{
|
2002-10-12 19:30:15 +00:00
|
|
|
CString sSongDir = sParams[1];
|
2003-02-14 21:42:44 +00:00
|
|
|
Difficulty dc = StringToDifficulty( sParams[2] );
|
2002-08-01 13:42:56 +00:00
|
|
|
CString sModifiers = sParams[3];
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
if( sSongDir.GetLength() == 0 ) {
|
2002-10-12 19:30:15 +00:00
|
|
|
/* Err. */
|
2002-10-29 07:58:44 +00:00
|
|
|
LOG->Trace( "Course file '%s' has an empty #SONG. Ignored.", sPath.GetString(), sSongDir.GetString() );
|
2002-10-12 19:30:15 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
m_entries.push_back( course_entry(sSongDir, dc, sModifiers) );
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
2002-10-29 07:58:44 +00:00
|
|
|
LOG->Trace( "Unexpected value named '%s'", sValueName.GetString() );
|
2002-07-02 17:34:20 +00:00
|
|
|
}
|
2003-02-10 23:17:57 +00:00
|
|
|
static TitleSubst tsub;
|
|
|
|
|
|
|
|
|
|
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-02-14 21:42:44 +00:00
|
|
|
void Course::AutoGenEndlessFromGroupAndDifficulty( CString sGroupName, Difficulty dc, vector<Song*> &apSongsInGroup )
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +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
|
|
|
|
|
|
|
|
CStringArray asPossibleBannerPaths;
|
2003-02-14 08:15:15 +00:00
|
|
|
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 );
|
2002-10-31 02:11:52 +00:00
|
|
|
if( !asPossibleBannerPaths.empty() )
|
2002-08-01 20:30:40 +00:00
|
|
|
m_sBannerPath = asPossibleBannerPaths[0];
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
CString sShortGroupName = SONGMAN->ShortenGroupName( sGroupName );
|
|
|
|
|
|
|
|
|
|
m_sName = sShortGroupName + " ";
|
|
|
|
|
switch( dc )
|
|
|
|
|
{
|
2002-09-29 05:06:18 +00:00
|
|
|
case DIFFICULTY_EASY: m_sName += "Easy"; break;
|
|
|
|
|
case DIFFICULTY_MEDIUM: m_sName += "Medium"; break;
|
|
|
|
|
case DIFFICULTY_HARD: m_sName += "Hard"; break;
|
2003-01-26 07:33:03 +00:00
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
2002-07-23 01:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
2002-10-31 02:11:52 +00:00
|
|
|
for( unsigned s=0; s<apSongsInGroup.size(); s++ )
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
|
|
|
|
Song* pSong = apSongsInGroup[s];
|
2003-02-14 21:42:44 +00:00
|
|
|
m_entries.push_back( course_entry(pSong->GetSongDir(), dc, "") );
|
2002-07-23 01:41:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-14 21:42:44 +00:00
|
|
|
|
|
|
|
|
void Course::GetCourseInfo(
|
|
|
|
|
vector<Song*>& vSongsOut,
|
|
|
|
|
vector<Notes*>& vNotesOut,
|
|
|
|
|
vector<CString>& vsModifiersOut,
|
|
|
|
|
NotesType nt,
|
|
|
|
|
bool bDifficult ) const
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
if( bDifficult )
|
|
|
|
|
ASSERT( HasDifficult() );
|
2002-07-23 01:41:40 +00:00
|
|
|
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
vector<course_entry> entries = m_entries;
|
|
|
|
|
|
|
|
|
|
if( m_bRandomize )
|
|
|
|
|
random_shuffle( entries.begin(), entries.end() );
|
2003-02-05 20:00:49 +00:00
|
|
|
|
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-14 21:42:44 +00:00
|
|
|
CString sSongDir = entries[i].songDir;
|
2003-02-05 20:00:49 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
Song* pSong;
|
|
|
|
|
if( sSongDir.Left(strlen("PlayersBest")) == "PlayersBest" )
|
|
|
|
|
{
|
|
|
|
|
int iNumber = atoi( sSongDir.Right(sSongDir.length()-strlen("PlayersBest")) );
|
|
|
|
|
int index = iNumber - 1;
|
|
|
|
|
pSong = SONGMAN->GetPlayersBest( index );
|
|
|
|
|
}
|
|
|
|
|
else if( sSongDir.Left(strlen("PlayersWorst")) == "PlayersWorst" )
|
|
|
|
|
{
|
|
|
|
|
int iNumber = atoi( sSongDir.Right(sSongDir.length()-strlen("PlayersWorst")) );
|
|
|
|
|
int index = iNumber - 1;
|
|
|
|
|
pSong = SONGMAN->GetPlayersWorst( index );
|
|
|
|
|
}
|
|
|
|
|
else if( sSongDir.Right(1) == "*" )
|
|
|
|
|
{
|
|
|
|
|
CStringArray asSongDirs;
|
|
|
|
|
GetDirListing( sSongDir, asSongDirs, true, true );
|
|
|
|
|
if( asSongDirs.empty() )
|
|
|
|
|
pSong = NULL;
|
|
|
|
|
else
|
|
|
|
|
pSong = FindSong( asSongDirs[rand()%asSongDirs.size()] );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
pSong = FindSong( sSongDir );
|
2003-02-05 20:00:49 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
if( pSong == NULL )
|
|
|
|
|
continue; // skip
|
2002-07-23 01:41:40 +00:00
|
|
|
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
Difficulty dc = entries[i].difficulty;
|
|
|
|
|
if( bDifficult && dc != NUM_DIFFICULTIES-1 )
|
|
|
|
|
dc = (Difficulty)(dc+1);
|
|
|
|
|
Notes* pNotes = pSong->GetNotes( nt, dc );
|
2002-12-17 05:07:56 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
if( pNotes == NULL )
|
|
|
|
|
continue; // skip
|
2002-12-17 05:07:56 +00:00
|
|
|
|
|
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
CString sModifiers = entries[i].modifiers;
|
2002-12-17 05:07:56 +00:00
|
|
|
|
2003-02-14 21:42:44 +00:00
|
|
|
vSongsOut.push_back( pSong );
|
|
|
|
|
vNotesOut.push_back( pNotes );
|
|
|
|
|
vsModifiersOut.push_back( sModifiers );
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
|
|
GetCourseInfo(
|
|
|
|
|
vSongs,
|
|
|
|
|
vNotes,
|
|
|
|
|
vsModifiers,
|
|
|
|
|
nt,
|
|
|
|
|
false );
|
|
|
|
|
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-14 21:42:44 +00:00
|
|
|
CString sSongDir = m_entries[stage].songDir;
|
|
|
|
|
return sSongDir.Right(1) == "*";
|
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;
|
|
|
|
|
GetCourseInfo(
|
|
|
|
|
vSongsOut,
|
|
|
|
|
vNotesOut,
|
|
|
|
|
vsModifiersOut,
|
|
|
|
|
NOTES_TYPE_DANCE_SINGLE, // doesn't matter
|
|
|
|
|
false ); // doesn't matter
|
|
|
|
|
|
|
|
|
|
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
|
|
|
m_MemCardScores[MEMORY_CARD_MACHINE][nt].iNumTimesPlayed++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-14 21:42:44 +00:00
|
|
|
bNewRecordOut = 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++;
|
|
|
|
|
|
|
|
|
|
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-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-01-27 02:00:38 +00:00
|
|
|
for( int j=i+1; j<NUM_RANKING_LINES; 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-01-24 02:43:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
//
|
|
|
|
|
// Sorting stuff
|
|
|
|
|
//
|
2002-10-24 08:17:09 +00:00
|
|
|
static int CompareCoursePointersByDifficulty(const Course* pCourse1, const Course* pCourse2)
|
2002-07-27 19:29:51 +00:00
|
|
|
{
|
2003-02-14 21:42:44 +00:00
|
|
|
return pCourse1->GetEstimatedNumStages() < pCourse2->GetEstimatedNumStages();
|
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
|
|
|
}
|