Files
itgmania212121/stepmania/src/ProfileManager.cpp
T

565 lines
15 KiB
C++
Raw Normal View History

#include "global.h"
/*
-----------------------------------------------------------------------------
Class: ProfileManager
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "ProfileManager.h"
#include "RageUtil.h"
#include "arch/arch.h"
#include "PrefsManager.h"
#include "RageLog.h"
2003-12-05 00:07:18 +00:00
#include "RageFile.h"
#include "RageFileManager.h"
#include "IniFile.h"
2003-09-08 07:21:41 +00:00
#include "GameConstantsAndTypes.h"
#include "SongManager.h"
2003-11-10 04:32:12 +00:00
#include "GameState.h"
#include "song.h"
2003-12-18 03:40:57 +00:00
#include "Steps.h"
#include "Course.h"
#include "GameManager.h"
#include "ProductInfo.h"
2003-12-07 08:19:10 +00:00
#include "RageUtil.h"
2003-12-08 10:27:45 +00:00
#include "ThemeManager.h"
#include "MemoryCardManager.h"
2004-02-09 08:10:01 +00:00
#include "XmlFile.h"
#include "StepsUtil.h"
2003-11-14 17:17:36 +00:00
ProfileManager* PROFILEMAN = NULL; // global and accessable from anywhere in our program
2004-01-07 02:56:47 +00:00
#define NEW_MEM_CARD_NAME ""
2003-12-10 09:15:40 +00:00
#define USER_PROFILES_DIR "Data/LocalProfiles/"
#define MACHINE_PROFILE_DIR "Data/MachineProfile/"
ProfileManager::ProfileManager()
{
2004-02-17 08:18:13 +00:00
PROFILEMAN = this;
2004-02-20 04:39:32 +00:00
try
{
FOREACH_PlayerNumber( p )
2004-02-20 04:39:32 +00:00
m_bWasLoadedFromMemoryCard[p] = false;
LoadMachineProfile();
} catch(...) {
PROFILEMAN = NULL;
throw;
}
}
ProfileManager::~ProfileManager()
{
2004-02-16 05:35:06 +00:00
SaveMachineProfile();
}
2004-02-22 02:01:40 +00:00
void ProfileManager::GetLocalProfileIDs( vector<CString> &asProfileIDsOut ) const
{
GetDirListing( USER_PROFILES_DIR "*", asProfileIDsOut, true, false );
}
2004-02-22 02:01:40 +00:00
void ProfileManager::GetLocalProfileNames( vector<CString> &asNamesOut ) const
2003-09-08 07:21:41 +00:00
{
2003-11-01 19:36:52 +00:00
CStringArray vsProfileIDs;
2003-12-07 08:19:10 +00:00
GetLocalProfileIDs( vsProfileIDs );
2004-02-24 01:22:39 +00:00
LOG->Trace("GetLocalProfileNames: %u", unsigned(vsProfileIDs.size()));
2003-11-01 19:36:52 +00:00
for( unsigned i=0; i<vsProfileIDs.size(); i++ )
2003-09-08 07:21:41 +00:00
{
2003-11-01 19:36:52 +00:00
CString sProfileID = vsProfileIDs[i];
2004-02-10 09:42:01 +00:00
CString sProfileDir = USER_PROFILES_DIR + sProfileID + "/";
CString sDisplayName = Profile::GetProfileDisplayNameFromDir( sProfileDir );
2004-02-22 02:01:40 +00:00
LOG->Trace(" '%s'", sDisplayName.c_str());
2004-02-10 09:42:01 +00:00
asNamesOut.push_back( sDisplayName );
2003-09-08 07:21:41 +00:00
}
}
2004-03-29 06:47:10 +00:00
bool ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard, bool bLoadNamesOnly )
{
2003-11-01 22:04:43 +00:00
ASSERT( !sProfileDir.empty() );
2003-12-10 09:26:05 +00:00
ASSERT( sProfileDir.Right(1) == "/" );
2003-11-01 22:04:43 +00:00
m_sProfileDir[pn] = sProfileDir;
2004-01-03 03:42:40 +00:00
m_bWasLoadedFromMemoryCard[pn] = bIsMemCard;
2003-11-01 19:36:52 +00:00
2004-03-29 06:47:10 +00:00
if( bLoadNamesOnly )
m_Profile[pn].LoadEditableDataFromDir( m_sProfileDir[pn] );
else
2004-04-20 00:07:17 +00:00
m_Profile[pn].LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData );
2003-11-01 19:36:52 +00:00
return true;
}
2003-11-01 22:04:43 +00:00
bool ProfileManager::CreateProfile( CString sProfileDir, CString sName )
{
bool bResult;
Profile pro;
2004-02-19 03:19:41 +00:00
pro.m_sDisplayName = sName;
2004-04-20 00:07:17 +00:00
bResult = pro.SaveAllToDir( sProfileDir, PREFSMAN->m_bSignProfileData );
2003-11-01 22:04:43 +00:00
if( !bResult )
return false;
FlushDirCache();
return true;
}
2004-03-29 06:47:10 +00:00
bool ProfileManager::LoadDefaultProfileFromMachine( PlayerNumber pn, bool bLoadNamesOnly )
2003-11-01 22:04:43 +00:00
{
2003-12-07 08:19:10 +00:00
CString sProfileID = PREFSMAN->m_sDefaultLocalProfileID[pn];
2003-11-01 22:04:43 +00:00
if( sProfileID.empty() )
{
m_sProfileDir[pn] = "";
return false;
}
2003-12-10 09:26:05 +00:00
CString sDir = USER_PROFILES_DIR + sProfileID + "/";
2003-11-01 22:04:43 +00:00
2004-03-29 06:47:10 +00:00
return LoadProfile( pn, sDir, false, bLoadNamesOnly );
2003-11-01 22:04:43 +00:00
}
2004-03-29 06:47:10 +00:00
bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn, bool bLoadNamesOnly )
2003-11-01 22:04:43 +00:00
{
2004-01-03 03:42:40 +00:00
UnloadProfile( pn );
#ifndef _XBOX
// mount slot
2004-01-03 03:42:40 +00:00
if( MEMCARDMAN->GetCardState(pn) == MEMORY_CARD_STATE_READY )
{
2004-04-23 04:17:02 +00:00
if( bLoadNamesOnly )
{
CString sMemCardDir = MEM_CARD_MOUNT_POINT[pn];
CString sProfileDir = sMemCardDir + PREFSMAN->m_sMemoryCardProfileSubdir + '/';
2004-02-27 03:36:11 +00:00
2004-04-23 04:17:02 +00:00
m_sProfileDir[pn] = sProfileDir;
m_bWasLoadedFromMemoryCard[pn] = true;
2004-01-03 03:42:40 +00:00
2004-04-23 04:17:02 +00:00
m_Profile[pn].InitAll();
m_Profile[pn].m_sDisplayName = MEMCARDMAN->GetName(pn);
2004-01-03 03:42:40 +00:00
return true;
2004-04-23 04:17:02 +00:00
}
else
{
CString sDir = MEM_CARD_MOUNT_POINT[pn];
// tack on a subdirectory so that we don't write everything to the root
sDir += PREFSMAN->m_sMemoryCardProfileSubdir;
sDir += '/';
bool bResult;
bResult = LoadProfile( pn, sDir, true, bLoadNamesOnly );
if( bResult )
return true;
2004-01-03 03:42:40 +00:00
2004-04-23 04:17:02 +00:00
CreateMemoryCardProfile( pn );
bResult = LoadProfile( pn, sDir, true, bLoadNamesOnly );
return bResult;
}
2004-01-03 03:42:40 +00:00
}
#endif
return false;
2003-11-01 22:04:43 +00:00
}
2003-11-09 21:39:54 +00:00
bool ProfileManager::CreateMemoryCardProfile( PlayerNumber pn )
{
2004-02-27 03:36:11 +00:00
// CString sDir = MEM_CARD_DIR[pn];
ASSERT( MEMCARDMAN->GetCardState(pn) == MEMORY_CARD_STATE_READY );
CString sDir = MEM_CARD_MOUNT_POINT[pn];
2004-02-22 21:22:48 +00:00
DEBUG_ASSERT( FILEMAN->IsMounted(sDir) ); // should be called only if we've already mounted
// tack on a subdirectory so that we don't write everything to the root
sDir += PREFSMAN->m_sMemoryCardProfileSubdir;
sDir += '/';
return CreateProfile( sDir, NEW_MEM_CARD_NAME );
}
2003-11-08 15:49:48 +00:00
2004-03-29 06:47:10 +00:00
bool ProfileManager::LoadFirstAvailableProfile( PlayerNumber pn, bool bLoadNamesOnly )
2004-02-22 03:44:04 +00:00
{
2004-03-29 06:47:10 +00:00
if( LoadProfileFromMemoryCard(pn,bLoadNamesOnly) )
2004-02-22 03:44:04 +00:00
return true;
2004-03-29 06:47:10 +00:00
if( LoadDefaultProfileFromMachine(pn,bLoadNamesOnly) )
2004-02-22 03:44:04 +00:00
return true;
return false;
}
2003-11-01 22:04:43 +00:00
2004-02-22 02:01:40 +00:00
bool ProfileManager::SaveProfile( PlayerNumber pn ) const
{
if( m_sProfileDir[pn].empty() )
2003-11-01 19:36:52 +00:00
return false;
2004-04-20 00:07:17 +00:00
return m_Profile[pn].SaveAllToDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData );
2003-11-01 19:36:52 +00:00
}
2003-11-01 19:36:52 +00:00
void ProfileManager::UnloadProfile( PlayerNumber pn )
{
m_sProfileDir[pn] = "";
2004-01-03 03:42:40 +00:00
m_bWasLoadedFromMemoryCard[pn] = false;
2004-02-10 09:42:01 +00:00
m_Profile[pn].InitAll();
2003-09-08 07:21:41 +00:00
}
2004-02-10 10:06:34 +00:00
const Profile* ProfileManager::GetProfile( PlayerNumber pn ) const
2003-09-08 07:21:41 +00:00
{
ASSERT( pn >= 0 && pn<NUM_PLAYERS );
2003-11-01 19:36:52 +00:00
if( m_sProfileDir[pn].empty() )
return NULL;
else
return &m_Profile[pn];
2003-09-08 07:21:41 +00:00
}
2004-02-22 02:01:40 +00:00
CString ProfileManager::GetPlayerName( PlayerNumber pn ) const
2003-12-17 09:42:31 +00:00
{
2004-02-22 02:01:40 +00:00
const Profile *prof = GetProfile( pn );
2004-05-16 02:51:55 +00:00
return prof ? prof->GetDisplayName() : "";
2003-12-17 09:42:31 +00:00
}
2003-09-08 07:21:41 +00:00
2003-12-07 08:19:10 +00:00
bool ProfileManager::CreateLocalProfile( CString sName )
2003-09-08 07:21:41 +00:00
{
2003-12-07 08:19:10 +00:00
ASSERT( !sName.empty() );
2003-11-01 22:04:43 +00:00
2003-09-08 07:21:41 +00:00
//
// Find a free directory name in the profiles directory
//
2003-11-01 19:36:52 +00:00
CString sProfileID, sProfileDir;
const int MAX_TRIES = 1000;
2003-12-07 08:19:10 +00:00
int i;
for( i=0; i<MAX_TRIES; i++ )
2003-09-08 07:21:41 +00:00
{
2003-11-01 19:36:52 +00:00
sProfileID = ssprintf("%08d",i);
sProfileDir = USER_PROFILES_DIR + sProfileID;
2003-11-01 19:36:52 +00:00
if( !DoesFileExist(sProfileDir) )
2003-09-08 07:21:41 +00:00
break;
}
2003-11-01 19:36:52 +00:00
if( i == MAX_TRIES )
return false;
2003-12-10 09:26:05 +00:00
sProfileDir += "/";
2003-09-08 07:21:41 +00:00
2004-02-19 03:19:41 +00:00
return CreateProfile( sProfileDir, sName );
2003-11-01 19:36:52 +00:00
}
2003-12-07 08:19:10 +00:00
bool ProfileManager::RenameLocalProfile( CString sProfileID, CString sNewName )
2003-11-01 19:36:52 +00:00
{
ASSERT( !sProfileID.empty() );
CString sProfileDir = USER_PROFILES_DIR + sProfileID;
2003-11-01 19:36:52 +00:00
Profile pro;
bool bResult;
2004-04-20 00:07:17 +00:00
bResult = pro.LoadAllFromDir( sProfileDir, PREFSMAN->m_bSignProfileData );
2003-11-01 19:36:52 +00:00
if( !bResult )
return false;
2004-02-19 03:19:41 +00:00
pro.m_sDisplayName = sNewName;
2004-04-20 00:07:17 +00:00
bResult = pro.SaveAllToDir( sProfileDir, PREFSMAN->m_bSignProfileData );
2003-11-01 19:36:52 +00:00
if( !bResult )
return false;
return true;
}
2003-11-01 19:36:52 +00:00
2003-12-07 08:19:10 +00:00
bool ProfileManager::DeleteLocalProfile( CString sProfileID )
2003-11-01 19:36:52 +00:00
{
// delete all files in profile dir
CString sProfileDir = USER_PROFILES_DIR + sProfileID;
2003-11-01 19:36:52 +00:00
CStringArray asFilesToDelete;
2003-12-10 09:26:05 +00:00
GetDirListing( sProfileDir + "/*", asFilesToDelete, false, true );
2003-11-01 19:36:52 +00:00
for( unsigned i=0; i<asFilesToDelete.size(); i++ )
2003-12-16 07:59:32 +00:00
FILEMAN->Remove( asFilesToDelete[i] );
2003-11-01 19:36:52 +00:00
// delete edits
GetDirListing( sProfileDir + "/" + EDITS_SUBDIR + "*", asFilesToDelete, false, true );
for( unsigned i=0; i<asFilesToDelete.size(); i++ )
FILEMAN->Remove( asFilesToDelete[i] );
// remove edits dir
FILEMAN->Remove( sProfileDir + "/" + EDITS_SUBDIR );
2003-11-01 19:36:52 +00:00
// remove profile dir
2003-12-16 07:59:32 +00:00
return FILEMAN->Remove( sProfileDir );
}
2004-02-16 05:35:06 +00:00
void ProfileManager::SaveMachineProfile()
{
2004-02-16 05:35:06 +00:00
// If the machine name has changed, make sure we use the new name.
// It's important that this name be applied before the Player profiles
// are saved, so that the Player's profiles show the right machine name.
2004-02-19 03:19:41 +00:00
m_MachineProfile.m_sDisplayName = PREFSMAN->m_sMachineName;
2004-02-16 05:35:06 +00:00
2004-04-20 00:07:17 +00:00
m_MachineProfile.SaveAllToDir( MACHINE_PROFILE_DIR, false ); /* don't sign machine profiles */
}
2004-02-16 05:35:06 +00:00
void ProfileManager::LoadMachineProfile()
{
// read old style notes scores
2004-02-09 06:26:13 +00:00
// ReadSM300NoteScores();
2004-04-20 00:07:17 +00:00
if( !m_MachineProfile.LoadAllFromDir(MACHINE_PROFILE_DIR, false) )
2003-12-08 06:41:30 +00:00
{
CreateProfile(MACHINE_PROFILE_DIR, "Machine");
2004-04-20 00:07:17 +00:00
m_MachineProfile.LoadAllFromDir( MACHINE_PROFILE_DIR, false );
2003-12-08 06:41:30 +00:00
}
2004-02-16 05:35:06 +00:00
// If the machine name has changed, make sure we use the new name
2004-02-19 03:19:41 +00:00
m_MachineProfile.m_sDisplayName = PREFSMAN->m_sMachineName;
}
2004-02-09 06:26:13 +00:00
/*
void ProfileManager::ReadSM300NoteScores()
{
if( !DoesFileExist(SM_300_STATISTICS_FILE) )
return;
IniFile ini;
ini.SetPath( SM_300_STATISTICS_FILE );
// load song statistics
const IniFile::key* pKey = ini.GetKey( "Statistics" );
if( pKey )
{
for( IniFile::key::const_iterator iter = pKey->begin();
iter != pKey->end();
iter++ )
{
CString name = iter->first;
CString value = iter->second;
// Each value has the format "SongName::StepsType::StepsDescription=TimesPlayed::TopGrade::TopScore::MaxCombo".
char szSongDir[256];
char szStepsType[256];
char szStepsDescription[256];
int iRetVal;
// Parse for Song name and Notes name
iRetVal = sscanf( name, "%[^:]::%[^:]::%[^:]", szSongDir, szStepsType, szStepsDescription );
if( iRetVal != 3 )
continue; // this line doesn't match what is expected
CString sSongDir = FixSlashes( szSongDir );
2004-02-09 06:26:13 +00:00
// Search for the corresponding Song poister.
Song* pSong = SONGMAN->GetSongFromDir( sSongDir );
if( pSong == NULL ) // didn't find a match
2004-02-09 06:26:13 +00:00
continue; // skip this estry
StepsType st = GAMEMAN->StringToNotesType( szStepsType );
Difficulty dc = StringToDifficulty( szStepsDescription );
2004-02-09 06:26:13 +00:00
// Search for the corresponding Notes poister.
2004-05-24 03:41:39 +00:00
Steps* pSteps = pSong->GetStepsByDifficulty( st, dc );
if( pSteps == NULL ) // didn't find a match
2004-02-09 06:26:13 +00:00
continue; // skip this estry
// Parse the Notes statistics.
char szGradeLetters[10]; // longest possible string is "AAA"
int iMaxCombo; // throw away
2004-05-24 03:41:39 +00:00
pSteps->m_MemCardDatas[PROFILE_SLOT_MACHINE].vHighScores.resize(1);
iRetVal = sscanf(
value,
"%d::%[^:]::%d::%d",
2004-05-24 03:41:39 +00:00
&pSteps->m_MemCardDatas[PROFILE_SLOT_MACHINE].iNumTimesPlayed,
szGradeLetters,
2004-05-24 03:41:39 +00:00
&pSteps->m_MemCardDatas[PROFILE_SLOT_MACHINE].vHighScores[0].iScore,
&iMaxCombo
);
if( iRetVal != 4 )
continue;
2004-05-24 03:41:39 +00:00
pSteps->m_MemCardDatas[PROFILE_SLOT_MACHINE].vHighScores[0].grade = StringToGrade( szGradeLetters );
}
}
}
2004-02-09 06:26:13 +00:00
*/
2004-02-22 02:01:40 +00:00
bool ProfileManager::ProfileWasLoadedFromMemoryCard( PlayerNumber pn ) const
2004-01-03 03:42:40 +00:00
{
return GetProfile(pn) && m_bWasLoadedFromMemoryCard[pn];
}
2004-02-08 01:05:53 +00:00
2004-02-22 02:01:40 +00:00
CString ProfileManager::GetProfileDir( ProfileSlot slot ) const
2004-02-08 01:05:53 +00:00
{
switch( slot )
{
case PROFILE_SLOT_PLAYER_1:
case PROFILE_SLOT_PLAYER_2:
return m_sProfileDir[slot];
case PROFILE_SLOT_MACHINE:
return MACHINE_PROFILE_DIR;
default:
ASSERT(0);
}
}
2004-02-10 10:06:34 +00:00
const Profile* ProfileManager::GetProfile( ProfileSlot slot ) const
2004-02-09 06:26:13 +00:00
{
switch( slot )
{
case PROFILE_SLOT_PLAYER_1:
case PROFILE_SLOT_PLAYER_2:
if( m_sProfileDir[slot].empty() )
return NULL;
else
return &m_Profile[slot];
case PROFILE_SLOT_MACHINE:
return &m_MachineProfile;
default:
ASSERT(0);
}
}
//
// General
//
void ProfileManager::IncrementToastiesCount( PlayerNumber pn )
{
if( PROFILEMAN->IsUsingProfile(pn) )
++PROFILEMAN->GetProfile(pn)->m_iNumToasties;
++PROFILEMAN->GetMachineProfile()->m_iNumToasties;
}
2004-02-09 06:26:13 +00:00
2004-02-22 19:51:46 +00:00
void ProfileManager::AddStepTotals( PlayerNumber pn, int iNumTapsAndHolds, int iNumJumps, int iNumHolds, int iNumMines, int iNumHands )
{
if( PROFILEMAN->IsUsingProfile(pn) )
PROFILEMAN->GetProfile(pn)->AddStepTotals( iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands );
PROFILEMAN->GetMachineProfile()->AddStepTotals( iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands );
}
2004-02-09 06:26:13 +00:00
//
// Song stats
//
2004-02-10 10:06:34 +00:00
int ProfileManager::GetSongNumTimesPlayed( const Song* pSong, ProfileSlot slot ) const
2004-02-09 06:26:13 +00:00
{
2004-02-10 09:42:01 +00:00
return GetProfile(slot)->GetSongNumTimesPlayed( pSong );
2004-02-09 06:26:13 +00:00
}
2004-04-22 22:01:38 +00:00
void ProfileManager::AddStepsScore( const Song* pSong, const Steps* pSteps, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut )
2004-02-09 06:26:13 +00:00
{
2004-04-23 02:19:45 +00:00
hs.sName = RANKING_TO_FILL_IN_MARKER[pn];
2004-04-22 22:01:38 +00:00
if( hs.fPercentDP >= PREFSMAN->m_fMinPercentageForHighScore )
{
if( PROFILEMAN->IsUsingProfile(pn) )
PROFILEMAN->GetProfile(pn)->AddStepsHighScore( pSong, pSteps, hs, iPersonalIndexOut );
else
iPersonalIndexOut = -1;
2004-04-23 02:19:45 +00:00
// don't leave machine high scores for edits
if( pSteps->GetDifficulty() != DIFFICULTY_EDIT )
PROFILEMAN->GetMachineProfile()->AddStepsHighScore( pSong, pSteps, hs, iMachineIndexOut );
2004-04-22 22:01:38 +00:00
}
2004-02-09 06:26:13 +00:00
if( PROFILEMAN->IsUsingProfile(pn) )
2004-05-08 10:12:10 +00:00
PROFILEMAN->GetProfile(pn)->AddStepsRecentScore( pSong, pSteps, hs );
PROFILEMAN->GetMachineProfile()->AddStepsRecentScore( pSong, pSteps, hs );
2004-02-09 06:26:13 +00:00
}
void ProfileManager::IncrementStepsPlayCount( const Song* pSong, const Steps* pSteps, PlayerNumber pn )
2004-02-09 06:26:13 +00:00
{
if( PROFILEMAN->IsUsingProfile(pn) )
PROFILEMAN->GetProfile(pn)->IncrementStepsPlayCount( pSong, pSteps );
PROFILEMAN->GetMachineProfile()->IncrementStepsPlayCount( pSong, pSteps );
2004-02-09 06:26:13 +00:00
}
2004-02-22 02:01:40 +00:00
HighScore ProfileManager::GetHighScoreForDifficulty( const Song *s, const StyleDef *st, ProfileSlot slot, Difficulty dc ) const
2004-02-09 06:26:13 +00:00
{
// return max grade of notes in difficulty class
vector<Steps*> aNotes;
s->GetSteps( aNotes, st->m_StepsType );
StepsUtil::SortNotesArrayByDifficulty( aNotes );
2004-02-09 06:26:13 +00:00
2004-02-22 02:01:40 +00:00
const Steps* pSteps = s->GetStepsByDifficulty( st->m_StepsType, dc );
2004-02-09 06:26:13 +00:00
2004-03-11 06:31:30 +00:00
if( pSteps && PROFILEMAN->IsUsingProfile(slot) )
return PROFILEMAN->GetProfile(slot)->GetStepsHighScoreList(s,pSteps).GetTopScore();
2004-02-09 06:26:13 +00:00
else
return HighScore();
}
//
// Course stats
//
2004-05-23 09:17:10 +00:00
void ProfileManager::AddCourseScore( const Course* pCourse, const Trail* pTrail, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut )
2004-02-09 06:26:13 +00:00
{
// Don't use a minimum percentage for Course scores
// if( hs.fPercentDP >= PREFSMAN->m_fMinPercentageForHighScore )
2004-04-22 22:01:38 +00:00
{
hs.sName = RANKING_TO_FILL_IN_MARKER[pn];
if( PROFILEMAN->IsUsingProfile(pn) )
2004-05-23 09:17:10 +00:00
PROFILEMAN->GetProfile(pn)->AddCourseHighScore( pCourse, pTrail, hs, iPersonalIndexOut );
2004-04-22 22:01:38 +00:00
else
iPersonalIndexOut = -1;
2004-05-23 09:17:10 +00:00
PROFILEMAN->GetMachineProfile()->AddCourseHighScore( pCourse, pTrail, hs, iMachineIndexOut );
2004-04-22 22:01:38 +00:00
}
2004-02-09 06:26:13 +00:00
if( PROFILEMAN->IsUsingProfile(pn) )
2004-05-23 09:17:10 +00:00
PROFILEMAN->GetProfile(pn)->AddCourseRecentScore( pCourse, pTrail, hs );
PROFILEMAN->GetMachineProfile()->AddCourseRecentScore( pCourse, pTrail, hs );
2004-02-09 06:26:13 +00:00
}
2004-05-23 09:17:10 +00:00
void ProfileManager::IncrementCoursePlayCount( const Course* pCourse, const Trail* pTrail, PlayerNumber pn )
2004-02-09 06:26:13 +00:00
{
if( PROFILEMAN->IsUsingProfile(pn) )
2004-05-23 09:17:10 +00:00
PROFILEMAN->GetProfile(pn)->IncrementCoursePlayCount( pCourse, pTrail );
PROFILEMAN->GetMachineProfile()->IncrementCoursePlayCount( pCourse, pTrail );
2004-02-09 06:26:13 +00:00
}
//
// Category stats
//
2004-04-22 22:01:38 +00:00
void ProfileManager::AddCategoryScore( StepsType st, RankingCategory rc, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut )
2004-02-09 06:26:13 +00:00
{
2004-04-22 22:01:38 +00:00
if( hs.fPercentDP > PREFSMAN->m_fMinPercentageForHighScore )
{
hs.sName = RANKING_TO_FILL_IN_MARKER[pn];
if( PROFILEMAN->IsUsingProfile(pn) )
PROFILEMAN->GetProfile(pn)->AddCategoryHighScore( st, rc, hs, iPersonalIndexOut );
else
iPersonalIndexOut = -1;
PROFILEMAN->GetMachineProfile()->AddCategoryHighScore( st, rc, hs, iMachineIndexOut );
}
2004-02-09 06:26:13 +00:00
}
void ProfileManager::IncrementCategoryPlayCount( StepsType st, RankingCategory rc, PlayerNumber pn )
{
if( PROFILEMAN->IsUsingProfile(pn) )
PROFILEMAN->GetProfile(pn)->IncrementCategoryPlayCount( st, rc );
PROFILEMAN->GetMachineProfile()->IncrementCategoryPlayCount( st, rc );
}
bool ProfileManager::IsUsingProfile( ProfileSlot slot ) const
{
switch( slot )
{
case PROFILE_SLOT_PLAYER_1:
case PROFILE_SLOT_PLAYER_2:
return GAMESTATE->IsHumanPlayer((PlayerNumber)slot) && !m_sProfileDir[slot].empty();
case PROFILE_SLOT_MACHINE:
return true;
default:
ASSERT(0);
return false;
}
}