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"
|
2004-05-23 00:53:20 +00:00
|
|
|
#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-11-11 04:53:31 +00:00
|
|
|
#include "RageUtil.h"
|
2003-02-10 23:17:57 +00:00
|
|
|
#include "TitleSubstitution.h"
|
2003-08-03 00:13:55 +00:00
|
|
|
#include "Steps.h"
|
2003-06-15 02:07:31 +00:00
|
|
|
#include "BannerCache.h"
|
2003-07-22 07:56:46 +00:00
|
|
|
#include "RageFile.h"
|
|
|
|
|
#include "arch/arch.h"
|
2003-07-27 14:10:47 +00:00
|
|
|
#include "ThemeManager.h"
|
2003-11-09 22:16:59 +00:00
|
|
|
#include "ProfileManager.h"
|
2004-05-24 03:32:56 +00:00
|
|
|
#include "Foreach.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
|
2003-07-17 22:44:17 +00:00
|
|
|
/* Amount to increase meter ranges to make them difficult: */
|
2004-05-20 22:56:11 +00:00
|
|
|
const int COURSE_DIFFICULTY_METER_CHANGE[NUM_COURSE_DIFFICULTIES] = { -2, 0, 2 };
|
|
|
|
|
const int COURSE_DIFFICULTY_CLASS_CHANGE[NUM_COURSE_DIFFICULTIES] = { -1, 0, 1 };
|
2003-07-17 22:44:17 +00:00
|
|
|
|
|
|
|
|
/* Maximum lower value of ranges when difficult: */
|
|
|
|
|
const int MAX_BOTTOM_RANGE = 10;
|
2003-02-14 21:42:44 +00:00
|
|
|
|
2003-12-10 11:35:34 +00:00
|
|
|
|
2002-12-17 05:07:56 +00:00
|
|
|
Course::Course()
|
|
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
Init();
|
2002-12-17 05:07:56 +00:00
|
|
|
}
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2003-07-20 01:54:17 +00:00
|
|
|
PlayMode Course::GetPlayMode() const
|
|
|
|
|
{
|
2003-07-27 19:14:05 +00:00
|
|
|
if( m_bRepeat )
|
2003-07-20 01:54:17 +00:00
|
|
|
return PLAY_MODE_ENDLESS;
|
2003-07-27 19:14:05 +00:00
|
|
|
return m_iLives > 0? PLAY_MODE_ONI:PLAY_MODE_NONSTOP;
|
2003-07-20 01:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-05 19:16:00 +00:00
|
|
|
void Course::LoadFromCRSFile( CString sPath )
|
2002-07-02 17:34:20 +00:00
|
|
|
{
|
2003-08-10 08:58:11 +00:00
|
|
|
LOG->Trace( "Course::LoadFromCRSFile( '%s' )", sPath.c_str() );
|
|
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
Init();
|
2004-01-26 20:55:35 +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
|
|
|
|
2003-10-29 21:06:33 +00:00
|
|
|
const CString sFName = SetExtension( sPath, "" );
|
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() )
|
2003-06-15 02:07:31 +00:00
|
|
|
{
|
2002-07-27 19:29:51 +00:00
|
|
|
m_sBannerPath = arrayPossibleBanners[0];
|
2002-07-02 17:34:20 +00:00
|
|
|
|
2003-06-15 02:07:31 +00:00
|
|
|
/* Cache and load the course banner. */
|
|
|
|
|
BANNERCACHE->CacheBanner( m_sBannerPath );
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-26 03:02:30 +00:00
|
|
|
AttackArray attacks;
|
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") )
|
2003-07-10 14:44:13 +00:00
|
|
|
{
|
2002-07-27 19:29:51 +00:00
|
|
|
m_sName = sParams[1];
|
2004-05-25 03:36:18 +00:00
|
|
|
m_sNameTranslit = m_sName;
|
2003-07-10 14:44:13 +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
|
|
|
|
2003-07-21 22:33:01 +00:00
|
|
|
else if( 0 == stricmp(sValueName, "METER") )
|
2004-03-04 22:24:09 +00:00
|
|
|
{
|
|
|
|
|
if( sParams.params.size() == 2 )
|
2004-05-23 00:53:20 +00:00
|
|
|
m_iCustomMeter[COURSE_DIFFICULTY_REGULAR] = atoi( sParams[1] ); /* compat */
|
2004-03-04 22:24:09 +00:00
|
|
|
else if( sParams.params.size() == 3 )
|
|
|
|
|
{
|
|
|
|
|
const CourseDifficulty cd = StringToCourseDifficulty( sParams[1] );
|
|
|
|
|
if( cd == COURSE_DIFFICULTY_INVALID )
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn( "Course file '%s' contains an invalid #METER string: \"%s\"",
|
|
|
|
|
m_sPath.c_str(), sParams[1].c_str() );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2004-05-23 00:53:20 +00:00
|
|
|
m_iCustomMeter[cd] = atoi( sParams[2] );
|
2004-03-04 22:24:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-07-21 22:33:01 +00:00
|
|
|
|
2003-10-26 03:02:30 +00:00
|
|
|
else if( 0 == stricmp(sValueName, "MODS") )
|
|
|
|
|
{
|
|
|
|
|
Attack attack;
|
2003-11-17 17:54:53 +00:00
|
|
|
float end = -9999;
|
2003-10-26 03:02:30 +00:00
|
|
|
for( unsigned j = 1; j < sParams.params.size(); ++j )
|
|
|
|
|
{
|
|
|
|
|
CStringArray sBits;
|
|
|
|
|
split( sParams[j], "=", sBits, false );
|
|
|
|
|
if( sBits.size() == 0 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
TrimLeft( sBits[0] );
|
|
|
|
|
TrimRight( sBits[0] );
|
|
|
|
|
if( !sBits[0].CompareNoCase("TIME") )
|
|
|
|
|
attack.fStartSecond = (float) atof( sBits[1] );
|
|
|
|
|
else if( !sBits[0].CompareNoCase("LEN") )
|
|
|
|
|
attack.fSecsRemaining = (float) atof( sBits[1] );
|
2003-11-17 17:54:53 +00:00
|
|
|
else if( !sBits[0].CompareNoCase("END") )
|
|
|
|
|
end = (float) atof( sBits[1] );
|
2003-10-26 03:02:30 +00:00
|
|
|
else if( !sBits[0].CompareNoCase("MODS") )
|
2003-11-18 00:51:15 +00:00
|
|
|
{
|
|
|
|
|
if( end != -9999 )
|
|
|
|
|
{
|
|
|
|
|
attack.fSecsRemaining = end - attack.fStartSecond;
|
|
|
|
|
end = -9999;
|
|
|
|
|
}
|
2003-10-26 03:02:30 +00:00
|
|
|
attack.sModifier = sBits[1];
|
2003-11-18 00:51:15 +00:00
|
|
|
attacks.push_back( attack );
|
|
|
|
|
}
|
2003-10-26 03:02:30 +00:00
|
|
|
}
|
2003-11-17 17:54:53 +00:00
|
|
|
|
|
|
|
|
|
2003-10-26 03:02:30 +00:00
|
|
|
}
|
2002-07-27 19:29:51 +00:00
|
|
|
else if( 0 == stricmp(sValueName, "SONG") )
|
2002-07-02 17:34:20 +00:00
|
|
|
{
|
2003-08-10 23:48:10 +00:00
|
|
|
CourseEntry new_entry;
|
2003-02-16 10:12:03 +00:00
|
|
|
|
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-08-10 23:48:10 +00:00
|
|
|
new_entry.type = COURSE_ENTRY_BEST;
|
2003-04-14 07:11:04 +00:00
|
|
|
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-08-10 23:48:10 +00:00
|
|
|
new_entry.type = COURSE_ENTRY_WORST;
|
2003-04-14 07:11:04 +00:00
|
|
|
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] == "*" )
|
|
|
|
|
{
|
2003-07-30 21:33:20 +00:00
|
|
|
new_entry.mystery = true;
|
2003-08-10 23:48:10 +00:00
|
|
|
new_entry.type = COURSE_ENTRY_RANDOM;
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
|
|
|
|
else if( sParams[1].Right(1) == "*" )
|
|
|
|
|
{
|
2003-07-30 21:33:20 +00:00
|
|
|
new_entry.mystery = true;
|
2003-08-10 23:48:10 +00:00
|
|
|
new_entry.type = COURSE_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. */
|
2003-09-22 01:06:07 +00:00
|
|
|
LOG->Trace( "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
|
|
|
|
|
{
|
2003-08-10 23:48:10 +00:00
|
|
|
new_entry.type = COURSE_ENTRY_FIXED;
|
2003-02-16 23:54:30 +00:00
|
|
|
|
|
|
|
|
CString sSong = sParams[1];
|
2003-07-22 05:45:30 +00:00
|
|
|
new_entry.pSong = SONGMAN->FindSong( sSong );
|
|
|
|
|
|
|
|
|
|
if( new_entry.pSong == NULL )
|
2003-02-16 23:54:30 +00:00
|
|
|
{
|
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. */
|
2003-07-22 05:45:30 +00:00
|
|
|
LOG->Trace( "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
|
|
|
|
2003-07-30 21:33:20 +00:00
|
|
|
{
|
|
|
|
|
/* If "showcourse" or "noshowcourse" is in the list, force new_entry.mystery
|
|
|
|
|
* on or off. */
|
|
|
|
|
CStringArray mods;
|
|
|
|
|
split( sParams[3], ",", mods, true );
|
|
|
|
|
for( int j = (int) mods.size()-1; j >= 0 ; --j )
|
|
|
|
|
{
|
|
|
|
|
if( !mods[j].CompareNoCase("showcourse") )
|
|
|
|
|
new_entry.mystery = false;
|
|
|
|
|
else if( !mods[j].CompareNoCase("noshowcourse") )
|
|
|
|
|
new_entry.mystery = true;
|
2004-02-10 22:52:43 +00:00
|
|
|
else if( !mods[j].CompareNoCase("nodifficult") )
|
|
|
|
|
new_entry.no_difficult = true;
|
2003-07-30 21:33:20 +00:00
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
mods.erase(mods.begin() + j);
|
|
|
|
|
}
|
|
|
|
|
new_entry.modifiers = join( ",", mods );
|
|
|
|
|
}
|
2003-02-16 10:12:03 +00:00
|
|
|
|
2003-10-26 03:02:30 +00:00
|
|
|
new_entry.attacks = attacks;
|
2003-10-26 03:17:45 +00:00
|
|
|
attacks.clear();
|
2003-10-26 03:02:30 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
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
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
void Course::Init()
|
2004-01-26 20:55:35 +00:00
|
|
|
{
|
|
|
|
|
m_bIsAutogen = false;
|
|
|
|
|
m_bRepeat = false;
|
|
|
|
|
m_bRandomize = false;
|
|
|
|
|
m_iLives = -1;
|
2004-05-25 02:17:17 +00:00
|
|
|
m_bSortByMeter = false;
|
2004-05-23 00:53:20 +00:00
|
|
|
ZERO( m_iCustomMeter );
|
2004-01-26 20:55:35 +00:00
|
|
|
m_entries.clear();
|
2004-05-25 03:36:18 +00:00
|
|
|
m_sPath = m_sName = m_sNameTranslit = m_sBannerPath = m_sCDTitlePath = "";
|
2004-01-26 20:55:35 +00:00
|
|
|
}
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2003-04-11 00:12:22 +00:00
|
|
|
void Course::Save()
|
|
|
|
|
{
|
|
|
|
|
ASSERT( !m_bIsAutogen );
|
|
|
|
|
|
2003-12-04 19:13:29 +00:00
|
|
|
RageFile f;
|
|
|
|
|
if( !f.Open( m_sPath, RageFile::WRITE ) )
|
2003-04-11 00:12:22 +00:00
|
|
|
{
|
2003-12-04 19:13:29 +00:00
|
|
|
LOG->Warn( "Could not write course file '%s': %s", m_sPath.c_str(), f.GetError().c_str() );
|
2003-04-11 00:12:22 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-04 19:13:29 +00:00
|
|
|
f.PutLine( ssprintf("#COURSE:%s;", m_sName.c_str()) );
|
2003-09-05 21:05:05 +00:00
|
|
|
if( m_bRepeat )
|
2003-12-04 19:13:29 +00:00
|
|
|
f.PutLine( "#REPEAT:YES;" );
|
2003-09-05 21:05:05 +00:00
|
|
|
if( m_iLives != -1 )
|
2003-12-04 19:13:29 +00:00
|
|
|
f.PutLine( ssprintf("#LIVES:%i;", m_iLives) );
|
2004-03-04 22:24:09 +00:00
|
|
|
FOREACH_CourseDifficulty( cd )
|
|
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
if( m_iCustomMeter[cd] == -1 )
|
2004-03-04 22:24:09 +00:00
|
|
|
continue;
|
2004-05-23 00:53:20 +00:00
|
|
|
f.PutLine( ssprintf("#METER:%s:%i;", CourseDifficultyToString(cd).c_str(), m_iCustomMeter[cd]) );
|
2004-03-04 22:24:09 +00:00
|
|
|
}
|
2003-04-11 00:12:22 +00:00
|
|
|
|
|
|
|
|
for( unsigned i=0; i<m_entries.size(); i++ )
|
|
|
|
|
{
|
2003-08-10 23:48:10 +00:00
|
|
|
const CourseEntry& entry = m_entries[i];
|
2003-04-11 00:12:22 +00:00
|
|
|
|
2003-10-26 03:17:45 +00:00
|
|
|
for( unsigned j = 0; j < entry.attacks.size(); ++j )
|
|
|
|
|
{
|
|
|
|
|
if( j == 0 )
|
2003-12-04 19:13:29 +00:00
|
|
|
f.PutLine( "#MODS:" );
|
2003-10-26 03:17:45 +00:00
|
|
|
|
2003-12-04 19:13:29 +00:00
|
|
|
CString line;
|
2003-10-26 03:17:45 +00:00
|
|
|
const Attack &a = entry.attacks[j];
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ssprintf( " TIME=%.2f:LEN=%.2f:MODS=%s",
|
2003-10-26 03:17:45 +00:00
|
|
|
a.fStartSecond, a.fSecsRemaining, a.sModifier.c_str() );
|
|
|
|
|
|
|
|
|
|
if( j+1 < entry.attacks.size() )
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ":";
|
2003-10-26 03:17:45 +00:00
|
|
|
else
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ";";
|
|
|
|
|
f.PutLine( line );
|
2003-10-26 03:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
2003-12-04 19:13:29 +00:00
|
|
|
CString line;
|
2003-04-11 00:12:22 +00:00
|
|
|
switch( entry.type )
|
|
|
|
|
{
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_FIXED:
|
2003-08-12 07:48:35 +00:00
|
|
|
{
|
|
|
|
|
// strip off everything but the group name and song dir
|
|
|
|
|
CStringArray as;
|
2003-12-10 09:26:05 +00:00
|
|
|
split( entry.pSong->GetSongDir(), "/", as );
|
2003-08-12 07:48:35 +00:00
|
|
|
ASSERT( !as.empty() );
|
|
|
|
|
CString sGroup = as[ as.size()-2 ];
|
|
|
|
|
CString sSong = as[ as.size()-1 ];
|
2003-12-04 19:13:29 +00:00
|
|
|
line += "#SONG:" + sGroup + '/' + sSong;
|
2003-08-12 07:48:35 +00:00
|
|
|
}
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_RANDOM:
|
2003-12-04 19:13:29 +00:00
|
|
|
line += "#SONG:*";
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_RANDOM_WITHIN_GROUP:
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ssprintf( "#SONG:%s/*", entry.group_name.c_str() );
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_BEST:
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ssprintf( "#SONG:BEST%d", entry.players_index+1 );
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_WORST:
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ssprintf( "#SONG:WORST%d", entry.players_index+1 );
|
2003-04-11 00:12:22 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ":";
|
2003-04-11 00:12:22 +00:00
|
|
|
if( entry.difficulty != DIFFICULTY_INVALID )
|
2003-12-04 19:13:29 +00:00
|
|
|
line += DifficultyToString(entry.difficulty);
|
2003-09-05 21:05:05 +00:00
|
|
|
else if( entry.low_meter != -1 && entry.high_meter != -1 )
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ssprintf( "%d..%d", entry.low_meter, entry.high_meter );
|
2004-02-10 22:52:43 +00:00
|
|
|
line += ":";
|
2003-07-30 21:33:20 +00:00
|
|
|
|
2004-02-10 22:52:43 +00:00
|
|
|
CString modifiers = entry.modifiers;
|
2003-09-05 21:05:05 +00:00
|
|
|
bool default_mystery = (entry.type == COURSE_ENTRY_RANDOM || entry.type == COURSE_ENTRY_RANDOM_WITHIN_GROUP);
|
2003-07-30 21:33:20 +00:00
|
|
|
if( default_mystery != entry.mystery )
|
|
|
|
|
{
|
2004-02-10 22:52:43 +00:00
|
|
|
if( modifiers != "" )
|
|
|
|
|
modifiers += ",";
|
|
|
|
|
modifiers += entry.mystery? "noshowcourse":"showcourse";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( entry.no_difficult )
|
|
|
|
|
{
|
|
|
|
|
if( modifiers != "" )
|
|
|
|
|
modifiers += ",";
|
|
|
|
|
modifiers += "nodifficult";
|
2003-07-30 21:33:20 +00:00
|
|
|
}
|
2004-02-10 22:52:43 +00:00
|
|
|
line += modifiers;
|
2003-04-11 00:12:22 +00:00
|
|
|
|
2003-12-04 19:13:29 +00:00
|
|
|
line += ";";
|
|
|
|
|
f.PutLine( line );
|
2003-04-11 00:12:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-05-20 23:14:36 +00:00
|
|
|
void Course::AutogenEndlessFromGroup( CString sGroupName, Difficulty diff )
|
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;
|
2004-05-23 00:53:20 +00:00
|
|
|
m_iCustomMeter[0] = m_iCustomMeter[1] = -1;
|
2002-08-01 20:30:40 +00:00
|
|
|
|
2004-05-20 23:14:36 +00:00
|
|
|
if( sGroupName == "" )
|
|
|
|
|
{
|
|
|
|
|
m_sName = "All Songs";
|
|
|
|
|
// m_sBannerPath = ""; // XXX
|
|
|
|
|
} else {
|
2004-05-24 23:31:56 +00:00
|
|
|
m_sName = SONGMAN->ShortenGroupName( sGroupName );
|
2004-05-20 23:14:36 +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-08-10 23:48:10 +00:00
|
|
|
CourseEntry e;
|
2004-05-20 23:14:36 +00:00
|
|
|
if( sGroupName != "" )
|
|
|
|
|
e.type = COURSE_ENTRY_RANDOM_WITHIN_GROUP;
|
|
|
|
|
else
|
|
|
|
|
e.type = COURSE_ENTRY_RANDOM;
|
|
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
e.group_name = sGroupName;
|
2004-05-20 03:26:36 +00:00
|
|
|
e.difficulty = diff;
|
2003-08-06 08:05:41 +00:00
|
|
|
e.mystery = true;
|
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
|
|
|
}
|
|
|
|
|
|
2004-05-20 23:14:36 +00:00
|
|
|
void Course::AutogenNonstopFromGroup( CString sGroupName, Difficulty diff )
|
2004-05-20 03:26:36 +00:00
|
|
|
{
|
2004-05-20 23:14:36 +00:00
|
|
|
AutogenEndlessFromGroup( sGroupName, diff );
|
2003-03-27 01:56:21 +00:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-25 02:17:17 +00:00
|
|
|
void Course::AutogenOniFromArtist( CString sArtistName, vector<Song*> aSongs, Difficulty dc )
|
|
|
|
|
{
|
|
|
|
|
m_bIsAutogen = true;
|
|
|
|
|
m_bRepeat = false;
|
|
|
|
|
m_bRandomize = true;
|
|
|
|
|
m_bSortByMeter = true;
|
|
|
|
|
|
|
|
|
|
m_iLives = 4;
|
|
|
|
|
m_iCustomMeter[0] = m_iCustomMeter[1] = -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_sName = "by " + sArtistName;
|
|
|
|
|
|
|
|
|
|
// 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.type = COURSE_ENTRY_FIXED;
|
|
|
|
|
e.difficulty = dc;
|
|
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < aSongs.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
e.pSong = aSongs[i];
|
|
|
|
|
m_entries.push_back( e );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-17 22:44:17 +00:00
|
|
|
/*
|
|
|
|
|
* Difficult courses do the following:
|
|
|
|
|
*
|
|
|
|
|
* For entries with a meter range, bump it up by DIFFICULT_METER_CHANGE;
|
|
|
|
|
* eg. 3..6 -> 5..8, with a minimum no higher than MAX_BOTTOM_RANGE.
|
|
|
|
|
*
|
|
|
|
|
* For entries with a difficulty class, use notes one class harder, if they
|
|
|
|
|
* exist. This way, if a static song entry points to a difficulty, we'll always
|
|
|
|
|
* play that song, even if we're on difficult and harder notes don't exist. (The
|
|
|
|
|
* exception is a static song entry with a meter range, but that's not very useful.)
|
|
|
|
|
*/
|
2004-05-24 03:32:56 +00:00
|
|
|
bool Course::HasCourseDifficulty( StepsType st, CourseDifficulty cd ) const
|
2002-09-04 03:29:42 +00:00
|
|
|
{
|
2003-07-21 21:54:07 +00:00
|
|
|
/* Check to see if any songs would change if difficult. */
|
2003-07-17 22:44:17 +00:00
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
/* COURSE_DIFFICULTY_REGULAR is always available (if IsPlayableIn == true). */
|
2004-01-21 01:47:54 +00:00
|
|
|
if( cd == COURSE_DIFFICULTY_REGULAR )
|
|
|
|
|
return true;
|
|
|
|
|
|
2004-05-24 03:32:56 +00:00
|
|
|
Trail *Regular = GetTrail( st, COURSE_DIFFICULTY_REGULAR );
|
|
|
|
|
Trail *Other = GetTrail( st, cd );
|
2003-07-21 21:54:07 +00:00
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
return Regular != Other;
|
2002-09-04 03:29:42 +00:00
|
|
|
}
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2004-05-24 03:32:56 +00:00
|
|
|
bool Course::IsPlayableIn( StepsType st ) const
|
2003-02-16 10:12:03 +00:00
|
|
|
{
|
2004-05-24 03:32:56 +00:00
|
|
|
Trail* pTrail = GetTrail( st, COURSE_DIFFICULTY_REGULAR );
|
2004-05-23 00:53:20 +00:00
|
|
|
return !pTrail->m_vEntries.empty();
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
2003-02-14 21:42:44 +00:00
|
|
|
|
2004-05-24 03:32:56 +00:00
|
|
|
static vector<Song*> GetFilteredBestSongs( StepsType st )
|
2003-08-04 21:34:45 +00:00
|
|
|
{
|
2003-12-21 00:49:22 +00:00
|
|
|
const vector<Song*> &vSongsByMostPlayed = SONGMAN->GetBestSongs();
|
|
|
|
|
vector<Song*> ret;
|
|
|
|
|
ret.reserve( vSongsByMostPlayed.size() );
|
|
|
|
|
|
|
|
|
|
for( unsigned i=0; i < vSongsByMostPlayed.size(); ++i )
|
2003-08-04 21:34:45 +00:00
|
|
|
{
|
2003-12-21 00:49:22 +00:00
|
|
|
// filter out long songs and songs that don't have both medium and hard steps
|
|
|
|
|
Song* pSong = vSongsByMostPlayed[i];
|
|
|
|
|
if( SONGMAN->GetNumStagesForSong(pSong) > 1 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
bool FoundMedium = false, FoundHard = false;
|
2004-05-24 03:41:39 +00:00
|
|
|
FOREACH( Steps*, pSong->m_vpSteps, pSteps )
|
2003-12-21 00:49:22 +00:00
|
|
|
{
|
2004-05-24 03:32:56 +00:00
|
|
|
if( (*pSteps)->m_StepsType != st )
|
2003-12-21 00:49:22 +00:00
|
|
|
continue;
|
2004-05-24 03:32:56 +00:00
|
|
|
if( !PREFSMAN->m_bAutogenSteps && (*pSteps)->IsAutogen() )
|
2003-12-21 00:49:22 +00:00
|
|
|
continue;
|
|
|
|
|
|
2004-05-24 03:32:56 +00:00
|
|
|
if( (*pSteps)->GetDifficulty() == DIFFICULTY_MEDIUM )
|
2003-12-21 00:49:22 +00:00
|
|
|
FoundMedium = true;
|
2004-05-24 03:32:56 +00:00
|
|
|
else if( (*pSteps)->GetDifficulty() == DIFFICULTY_HARD )
|
2003-12-21 00:49:22 +00:00
|
|
|
FoundHard = true;
|
|
|
|
|
|
|
|
|
|
if( FoundMedium && FoundHard )
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if( !FoundMedium || !FoundHard )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ret.push_back( pSong );
|
2003-08-04 21:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
2003-12-21 00:49:22 +00:00
|
|
|
return ret;
|
2003-08-04 21:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
2004-05-25 02:17:17 +00:00
|
|
|
struct SortTrailEntry
|
|
|
|
|
{
|
|
|
|
|
TrailEntry entry;
|
|
|
|
|
int SortMeter;
|
|
|
|
|
bool operator< ( const SortTrailEntry &rhs ) const { return SortMeter < rhs.SortMeter; }
|
|
|
|
|
};
|
|
|
|
|
|
2003-12-21 02:54:23 +00:00
|
|
|
/* This is called by many simple functions, like Course::GetTotalSeconds, and may
|
|
|
|
|
* be called on all songs to sort. It can take time to execute, so we cache the
|
|
|
|
|
* results. */
|
2004-05-24 03:32:56 +00:00
|
|
|
Trail* Course::GetTrail( StepsType st, CourseDifficulty cd ) const
|
2002-07-23 01:41:40 +00:00
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
//
|
|
|
|
|
// Look in the Trail cache
|
|
|
|
|
//
|
2004-05-24 03:32:56 +00:00
|
|
|
const TrailParams params( st, cd );
|
2004-05-23 00:53:20 +00:00
|
|
|
TrailCache::iterator it = m_TrailCache.find( params );
|
|
|
|
|
if( it != m_TrailCache.end() )
|
2003-12-21 02:54:23 +00:00
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
return &it->second;
|
2003-12-21 02:54:23 +00:00
|
|
|
}
|
2003-02-14 21:42:44 +00:00
|
|
|
|
2004-05-25 02:17:17 +00:00
|
|
|
//
|
|
|
|
|
// Construct a new Trail, add it to the cache, then return it.
|
|
|
|
|
//
|
|
|
|
|
Trail trail;
|
|
|
|
|
GetTrailUnsorted( st, cd, trail );
|
|
|
|
|
|
|
|
|
|
if( this->m_bSortByMeter )
|
|
|
|
|
{
|
|
|
|
|
/* Sort according to COURSE_DIFFICULTY_REGULAR, since the order of songs
|
|
|
|
|
* must not change across difficulties. */
|
|
|
|
|
Trail SortTrail;
|
|
|
|
|
if( cd == COURSE_DIFFICULTY_REGULAR )
|
|
|
|
|
SortTrail = trail;
|
|
|
|
|
else
|
|
|
|
|
GetTrailUnsorted( st, COURSE_DIFFICULTY_REGULAR, SortTrail );
|
|
|
|
|
ASSERT_M( trail.m_vEntries.size() == SortTrail.m_vEntries.size(), ssprintf("%i %i", trail.m_vEntries.size(), SortTrail.m_vEntries.size()) );
|
|
|
|
|
|
|
|
|
|
vector<SortTrailEntry> entries;
|
|
|
|
|
for( unsigned i = 0; i < trail.m_vEntries.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
SortTrailEntry ste;
|
|
|
|
|
ste.entry = trail.m_vEntries[i];
|
|
|
|
|
ste.SortMeter = SortTrail.m_vEntries[i].pSteps->GetMeter();
|
|
|
|
|
entries.push_back( ste );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stable_sort( entries.begin(), entries.end() );
|
|
|
|
|
for( unsigned i = 0; i < trail.m_vEntries.size(); ++i )
|
|
|
|
|
trail.m_vEntries[i] = entries[i].entry;
|
|
|
|
|
}
|
2004-05-23 00:53:20 +00:00
|
|
|
|
2004-05-25 02:17:17 +00:00
|
|
|
/* Cache results. */
|
|
|
|
|
m_TrailCache[params] = trail;
|
|
|
|
|
return &m_TrailCache[params];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) const
|
|
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
//
|
|
|
|
|
// Construct a new Trail, add it to the cache, then return it.
|
|
|
|
|
//
|
2003-08-03 07:12:33 +00:00
|
|
|
/* Different seed for each course, but the same for the whole round: */
|
|
|
|
|
RandomGen rnd( GAMESTATE->m_iRoundSeed + GetHashForString(m_sName) );
|
|
|
|
|
|
2003-12-21 02:54:23 +00:00
|
|
|
vector<CourseEntry> tmp_entries;
|
2003-02-14 21:42:44 +00:00
|
|
|
if( m_bRandomize )
|
2003-08-03 07:12:33 +00:00
|
|
|
{
|
|
|
|
|
/* Always randomize the same way per round. Otherwise, the displayed course
|
|
|
|
|
* will change every time it's viewed, and the displayed order will have no
|
|
|
|
|
* bearing on what you'll actually play. */
|
2003-12-21 02:54:23 +00:00
|
|
|
tmp_entries = m_entries;
|
|
|
|
|
random_shuffle( tmp_entries.begin(), tmp_entries.end(), rnd );
|
2003-08-03 07:12:33 +00:00
|
|
|
}
|
2003-02-05 20:00:49 +00:00
|
|
|
|
2003-12-21 02:54:23 +00:00
|
|
|
const vector<CourseEntry> &entries = m_bRandomize? tmp_entries:m_entries;
|
|
|
|
|
|
2003-08-04 21:34:45 +00:00
|
|
|
/* This can take some time, so don't fill it out unless we need it. */
|
|
|
|
|
bool bMostPlayedSet = false;
|
|
|
|
|
vector<Song*> vSongsByMostPlayed;
|
2003-07-30 21:33:20 +00:00
|
|
|
|
2003-12-21 02:54:23 +00:00
|
|
|
bool bShuffledSet = false;
|
|
|
|
|
vector<Song*> AllSongsShuffled;
|
2003-02-24 00:09:34 +00:00
|
|
|
|
2003-12-21 02:54:23 +00:00
|
|
|
int CurSong = 0; /* Current offset into AllSongsShuffled */
|
2004-05-23 00:53:20 +00:00
|
|
|
|
2004-05-24 03:32:56 +00:00
|
|
|
trail.m_StepsType = st;
|
2004-05-23 09:17:10 +00:00
|
|
|
trail.m_CourseDifficulty = cd;
|
2003-07-21 21:54:07 +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-09-11 03:35:05 +00:00
|
|
|
const CourseEntry &e = entries[i];
|
2004-02-10 22:52:43 +00:00
|
|
|
CourseDifficulty entry_difficulty = cd;
|
|
|
|
|
if( e.no_difficult && entry_difficulty == COURSE_DIFFICULTY_DIFFICULT )
|
|
|
|
|
entry_difficulty = COURSE_DIFFICULTY_REGULAR;
|
2003-02-05 20:00:49 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
Song* pSong = NULL; // fill this in
|
2004-05-24 03:41:39 +00:00
|
|
|
Steps* pSteps = NULL; // fill this in
|
2003-02-05 20:00:49 +00:00
|
|
|
|
2003-07-17 22:44:17 +00:00
|
|
|
/* This applies difficult mode for meter ranges. (If it's a difficulty
|
|
|
|
|
* class, we'll do it below.) */
|
|
|
|
|
int low_meter, high_meter;
|
2004-02-10 22:52:43 +00:00
|
|
|
GetMeterRange( i, low_meter, high_meter, entry_difficulty );
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
switch( e.type )
|
|
|
|
|
{
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_FIXED:
|
2003-02-16 23:54:30 +00:00
|
|
|
pSong = e.pSong;
|
|
|
|
|
if( pSong )
|
|
|
|
|
{
|
2003-08-12 06:51:03 +00:00
|
|
|
if( e.difficulty != DIFFICULTY_INVALID )
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = pSong->GetStepsByDifficulty( st, e.difficulty );
|
2003-08-12 06:51:03 +00:00
|
|
|
else if( e.low_meter != -1 && e.high_meter != -1 )
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = pSong->GetStepsByMeter( st, low_meter, high_meter );
|
2003-02-16 23:54:30 +00:00
|
|
|
else
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = pSong->GetStepsByDifficulty( st, DIFFICULTY_MEDIUM );
|
2003-02-16 23:54:30 +00:00
|
|
|
}
|
2003-02-16 10:12:03 +00:00
|
|
|
break;
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_RANDOM:
|
|
|
|
|
case COURSE_ENTRY_RANDOM_WITHIN_GROUP:
|
2003-02-16 10:12:03 +00:00
|
|
|
{
|
2003-12-21 02:54:23 +00:00
|
|
|
if( !bShuffledSet )
|
|
|
|
|
{
|
|
|
|
|
AllSongsShuffled = SONGMAN->GetAllSongs();
|
|
|
|
|
random_shuffle( AllSongsShuffled.begin(), AllSongsShuffled.end(), rnd );
|
|
|
|
|
bShuffledSet = true;
|
|
|
|
|
}
|
|
|
|
|
|
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. */
|
2003-08-01 12:12:02 +00:00
|
|
|
ASSERT( unsigned(CurSong) < AllSongsShuffled.size() );
|
2003-02-24 00:09:34 +00:00
|
|
|
pSong = AllSongsShuffled[CurSong];
|
2003-08-01 00:13:16 +00:00
|
|
|
ASSERT( pSong );
|
2003-02-24 00:09:34 +00:00
|
|
|
CurSong = (CurSong+1) % AllSongsShuffled.size();
|
2003-02-16 10:12:03 +00:00
|
|
|
|
2003-08-10 23:48:10 +00:00
|
|
|
if(e.type == COURSE_ENTRY_RANDOM_WITHIN_GROUP &&
|
2003-02-24 00:09:34 +00:00
|
|
|
pSong->m_sGroupName.CompareNoCase(e.group_name))
|
|
|
|
|
continue; /* wrong group */
|
2003-02-16 10:12:03 +00:00
|
|
|
|
|
|
|
|
if( e.difficulty == DIFFICULTY_INVALID )
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = pSong->GetStepsByMeter( st, low_meter, high_meter );
|
2003-02-16 10:12:03 +00:00
|
|
|
else
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = pSong->GetStepsByDifficulty( st, e.difficulty );
|
2003-02-24 00:09:34 +00:00
|
|
|
|
2004-05-24 03:41:39 +00:00
|
|
|
if( pSteps ) // found a match
|
2003-02-16 10:12:03 +00:00
|
|
|
break; // stop searching
|
2003-02-24 00:09:34 +00:00
|
|
|
|
|
|
|
|
pSong = NULL;
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = NULL;
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_BEST:
|
|
|
|
|
case COURSE_ENTRY_WORST:
|
2003-02-16 10:12:03 +00:00
|
|
|
{
|
2003-08-04 21:34:45 +00:00
|
|
|
if( !bMostPlayedSet )
|
|
|
|
|
{
|
|
|
|
|
bMostPlayedSet = true;
|
2004-05-24 03:32:56 +00:00
|
|
|
vSongsByMostPlayed = GetFilteredBestSongs( st );
|
2003-08-04 21:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-16 10:12:03 +00:00
|
|
|
if( e.players_index >= (int)vSongsByMostPlayed.size() )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
switch( e.type )
|
|
|
|
|
{
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_ENTRY_BEST:
|
2003-02-16 10:12:03 +00:00
|
|
|
pSong = vSongsByMostPlayed[e.players_index];
|
|
|
|
|
break;
|
2003-08-10 23:48:10 +00:00
|
|
|
case COURSE_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 )
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = pSong->GetStepsByMeter( st, low_meter, high_meter );
|
2003-02-16 10:12:03 +00:00
|
|
|
else
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = pSong->GetStepsByDifficulty( st, e.difficulty );
|
2003-02-16 10:12:03 +00:00
|
|
|
|
2004-05-24 03:41:39 +00:00
|
|
|
if( pSteps == NULL )
|
|
|
|
|
pSteps = pSong->GetClosestNotes( st, DIFFICULTY_MEDIUM );
|
2003-02-16 10:12:03 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
2002-12-17 05:07:56 +00:00
|
|
|
|
2004-05-24 03:41:39 +00:00
|
|
|
if( !pSong || !pSteps )
|
2003-02-16 10:12:03 +00:00
|
|
|
continue; // this song entry isn't playable. Skip.
|
2002-12-17 05:07:56 +00:00
|
|
|
|
2004-05-20 22:56:11 +00:00
|
|
|
/* If e.difficulty == DIFFICULTY_INVALID, then we already adjusted difficulty
|
2003-07-17 22:44:17 +00:00
|
|
|
* based on meter. */
|
2004-05-20 22:56:11 +00:00
|
|
|
if( entry_difficulty != COURSE_DIFFICULTY_REGULAR && e.difficulty != DIFFICULTY_INVALID )
|
2003-03-28 02:25:15 +00:00
|
|
|
{
|
2004-05-20 22:56:11 +00:00
|
|
|
/* See if we can find a NoteData after adjusting the difficulty by COURSE_DIFFICULTY_CLASS_CHANGE.
|
|
|
|
|
* If we can't, just use the one we already have. */
|
2004-05-24 03:41:39 +00:00
|
|
|
Difficulty original_dc = pSteps->GetDifficulty();
|
2004-05-20 22:56:11 +00:00
|
|
|
Difficulty dc = Difficulty( original_dc + COURSE_DIFFICULTY_CLASS_CHANGE[entry_difficulty] );
|
|
|
|
|
dc = clamp( dc, DIFFICULTY_BEGINNER, DIFFICULTY_CHALLENGE );
|
|
|
|
|
if( dc != original_dc )
|
2003-03-28 02:25:15 +00:00
|
|
|
{
|
2004-05-24 03:32:56 +00:00
|
|
|
Steps* pNewNotes = pSong->GetStepsByDifficulty( st, dc );
|
2004-01-14 06:11:28 +00:00
|
|
|
if( pNewNotes )
|
2004-05-24 03:41:39 +00:00
|
|
|
pSteps = pNewNotes;
|
2003-03-28 02:25:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
TrailEntry te;
|
|
|
|
|
te.pSong = pSong;
|
2004-05-24 03:41:39 +00:00
|
|
|
te.pSteps = pSteps;
|
2004-05-23 00:53:20 +00:00
|
|
|
te.Modifiers = e.modifiers;
|
|
|
|
|
te.Attacks = e.attacks;
|
|
|
|
|
te.bMystery = e.mystery;
|
|
|
|
|
te.iLowMeter = low_meter;
|
|
|
|
|
te.iHighMeter = high_meter;
|
|
|
|
|
trail.m_vEntries.push_back( te );
|
2003-02-14 21:42:44 +00:00
|
|
|
}
|
2003-12-21 02:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-13 23:11:57 +00:00
|
|
|
bool Course::HasMods() const
|
|
|
|
|
{
|
2004-03-14 05:35:54 +00:00
|
|
|
for( unsigned i=0; i<m_entries.size(); i++ )
|
2004-03-13 23:11:57 +00:00
|
|
|
{
|
2004-03-21 16:59:03 +00:00
|
|
|
if( !m_entries[i].modifiers.empty() || !m_entries[i].attacks.empty() )
|
2004-03-13 23:11:57 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-20 19:24:38 +00:00
|
|
|
bool Course::AllSongsAreFixed() const
|
|
|
|
|
{
|
2004-03-22 01:05:16 +00:00
|
|
|
for( unsigned i=0; i<m_entries.size(); i++ )
|
2004-03-20 19:24:38 +00:00
|
|
|
{
|
|
|
|
|
if( m_entries[i].type != COURSE_ENTRY_FIXED )
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-21 02:54:23 +00:00
|
|
|
void Course::ClearCache()
|
|
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
m_TrailCache.clear();
|
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
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
// FIXME: These colors shouldn't be hard-coded
|
|
|
|
|
int iMeter = 5;
|
|
|
|
|
|
2003-07-27 14:54:56 +00:00
|
|
|
switch (PREFSMAN->m_iCourseSortOrder)
|
|
|
|
|
{
|
2003-07-27 19:14:05 +00:00
|
|
|
case PrefsManager::COURSE_SORT_SONGS:
|
2003-07-27 14:54:56 +00:00
|
|
|
if( m_entries.size() >= 7 )
|
|
|
|
|
return RageColor(1,0,0,1); // red
|
|
|
|
|
else if( m_entries.size() >= 4 )
|
|
|
|
|
return RageColor(1,1,0,1); // yellow
|
|
|
|
|
else
|
|
|
|
|
return RageColor(0,1,0,1); // green
|
|
|
|
|
// never should get here
|
|
|
|
|
break;
|
|
|
|
|
|
2003-07-27 19:14:05 +00:00
|
|
|
case PrefsManager::COURSE_SORT_METER:
|
2003-08-12 20:28:56 +00:00
|
|
|
if ( !IsFixed() )
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(0,0,1,1); // blue
|
2004-05-23 00:53:20 +00:00
|
|
|
if (iMeter > 8.5)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(1,0,0,1); // red
|
2004-05-23 00:53:20 +00:00
|
|
|
if (iMeter >= 7)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(1,0.5f,0,1); // orange
|
2004-05-23 00:53:20 +00:00
|
|
|
if (iMeter >= 5)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(1,1,0,1); // yellow
|
|
|
|
|
return RageColor(0,1,0,1); // green
|
|
|
|
|
|
2003-07-27 19:14:05 +00:00
|
|
|
case PrefsManager::COURSE_SORT_METER_SUM:
|
2003-08-12 20:28:56 +00:00
|
|
|
if ( !IsFixed() )
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(0,0,1,1); // blue
|
2004-05-23 00:53:20 +00:00
|
|
|
if (m_SortOrder_TotalDifficulty >= 40)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(1,0,0,1); // red
|
2004-05-23 00:53:20 +00:00
|
|
|
if (m_SortOrder_TotalDifficulty >= 30)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(1,0.5f,0,1); // orange
|
2004-05-23 00:53:20 +00:00
|
|
|
if (m_SortOrder_TotalDifficulty >= 20)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(1,1,0,1); // yellow
|
|
|
|
|
return RageColor(0,1,0,1); // green
|
|
|
|
|
|
2003-07-27 19:14:05 +00:00
|
|
|
case PrefsManager::COURSE_SORT_RANK:
|
2004-05-23 00:53:20 +00:00
|
|
|
if (m_SortOrder_Ranking == 3)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(0,0,1,1); // blue
|
2004-05-23 00:53:20 +00:00
|
|
|
if (m_SortOrder_Ranking == 2)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(1,0.5f,0,1); // orange
|
2004-05-23 00:53:20 +00:00
|
|
|
if (m_SortOrder_Ranking == 1)
|
2003-07-27 14:54:56 +00:00
|
|
|
return RageColor(0,1,0,1); // green
|
|
|
|
|
return RageColor(1,1,0,1); // yellow, never should get here
|
2003-07-27 19:14:05 +00:00
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
return RageColor(1,1,1,1); // white, never should reach here
|
2003-07-27 14:54:56 +00:00
|
|
|
}
|
2002-07-27 19:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-12 20:28:56 +00:00
|
|
|
bool Course::IsFixed() const
|
|
|
|
|
{
|
|
|
|
|
for(unsigned i = 0; i < m_entries.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if ( m_entries[i].type == COURSE_ENTRY_FIXED )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-02-16 10:12:03 +00:00
|
|
|
|
2004-01-14 06:11:28 +00:00
|
|
|
void Course::GetMeterRange( int stage, int& iMeterLowOut, int& iMeterHighOut, CourseDifficulty cd ) const
|
2003-02-16 10:12:03 +00:00
|
|
|
{
|
|
|
|
|
iMeterLowOut = m_entries[stage].low_meter;
|
|
|
|
|
iMeterHighOut = m_entries[stage].high_meter;
|
2003-07-17 22:44:17 +00:00
|
|
|
|
2004-01-21 01:35:54 +00:00
|
|
|
iMeterHighOut += COURSE_DIFFICULTY_METER_CHANGE[ cd ];
|
|
|
|
|
iMeterLowOut += COURSE_DIFFICULTY_METER_CHANGE[ cd ];
|
|
|
|
|
iMeterLowOut = min( iMeterLowOut, MAX_BOTTOM_RANGE );
|
2002-07-28 20:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-21 22:21:03 +00:00
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
bool Course::GetTotalSeconds( StepsType st, float& fSecondsOut ) const
|
2003-07-21 22:21:03 +00:00
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
if( !IsFixed() )
|
|
|
|
|
return false;
|
2003-07-21 22:21:03 +00:00
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
Trail* pTrail = GetTrail( st, COURSE_DIFFICULTY_REGULAR );
|
2003-02-14 21:42:44 +00:00
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
fSecondsOut = pTrail->GetLengthSeconds();
|
2003-02-14 21:42:44 +00:00
|
|
|
return true;
|
2002-12-17 05:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-12 00:18:33 +00:00
|
|
|
bool Course::CourseHasBestOrWorst() const
|
|
|
|
|
{
|
|
|
|
|
for(unsigned i = 0; i < m_entries.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
switch( m_entries[i].type )
|
|
|
|
|
{
|
|
|
|
|
case COURSE_ENTRY_BEST:
|
|
|
|
|
case COURSE_ENTRY_WORST:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-19 18:51:13 +00:00
|
|
|
bool Course::HasBanner() const
|
|
|
|
|
{
|
|
|
|
|
return m_sBannerPath != "" && IsAFile(m_sBannerPath);
|
|
|
|
|
}
|
2003-07-27 14:10:47 +00:00
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
void Course::UpdateCourseStats( StepsType st )
|
2003-07-27 14:10:47 +00:00
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
m_SortOrder_TotalDifficulty = 0;
|
2003-07-27 14:10:47 +00:00
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
2003-08-04 20:45:34 +00:00
|
|
|
// courses with random/players best-worst songs should go at the end
|
|
|
|
|
for(i = 0; i < m_entries.size(); i++)
|
|
|
|
|
{
|
2003-08-10 23:48:10 +00:00
|
|
|
if ( m_entries[i].type == COURSE_ENTRY_FIXED )
|
2003-08-04 20:45:34 +00:00
|
|
|
continue;
|
|
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
if ( m_SortOrder_Ranking == 2 )
|
|
|
|
|
m_SortOrder_Ranking = 3;
|
|
|
|
|
m_SortOrder_TotalDifficulty = 999999; // large number
|
2003-08-04 20:45:34 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
Trail* pTrail = GetTrail( st, COURSE_DIFFICULTY_REGULAR );
|
2003-07-27 14:10:47 +00:00
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
m_SortOrder_TotalDifficulty += pTrail->GetTotalMeter();
|
2003-07-27 14:10:47 +00:00
|
|
|
|
2003-08-04 09:18:26 +00:00
|
|
|
// OPTIMIZATION: Ranking info isn't dependant on style, so
|
|
|
|
|
// call it sparingly. Its handled on startup and when
|
|
|
|
|
// themes change..
|
2003-08-09 22:08:17 +00:00
|
|
|
|
2003-09-19 01:16:42 +00:00
|
|
|
LOG->Trace("%s: Total feet: %d",
|
2003-08-09 22:08:17 +00:00
|
|
|
this->m_sName.c_str(),
|
2004-05-23 00:53:20 +00:00
|
|
|
m_SortOrder_TotalDifficulty );
|
2003-10-25 22:55:11 +00:00
|
|
|
}
|
2003-11-03 10:14:13 +00:00
|
|
|
|
|
|
|
|
bool Course::IsRanking() const
|
|
|
|
|
{
|
|
|
|
|
CStringArray rankingsongs;
|
|
|
|
|
|
|
|
|
|
split(THEME->GetMetric("ScreenRanking", "CoursesToShow"), ",", rankingsongs);
|
|
|
|
|
|
|
|
|
|
for(unsigned i=0; i < rankingsongs.size(); i++)
|
|
|
|
|
if (rankingsongs[i].CompareNoCase(m_sPath))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
2003-11-05 05:00:32 +00:00
|
|
|
}
|
2003-11-09 22:16:59 +00:00
|
|
|
|
2004-05-24 03:32:56 +00:00
|
|
|
float Course::GetMeter( StepsType st, CourseDifficulty cd ) const
|
2004-03-12 05:24:32 +00:00
|
|
|
{
|
2004-05-23 00:53:20 +00:00
|
|
|
/* If we have a manually-entered meter for this difficulty, use it. */
|
|
|
|
|
if( m_iCustomMeter[cd] != -1 )
|
2004-05-23 00:57:26 +00:00
|
|
|
return (float)m_iCustomMeter[cd];
|
2004-03-12 05:24:32 +00:00
|
|
|
|
2004-05-24 03:32:56 +00:00
|
|
|
return roundf( GetTrail(st,cd)->GetAverageMeter() );
|
2004-03-12 05:24:32 +00:00
|
|
|
}
|