2003-07-09 03:10:01 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: UnlockSystem
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001-2003 by the person(s) listed below. All rights reserved.
|
|
|
|
|
Kevin Slaughter
|
2003-07-10 07:22:31 +00:00
|
|
|
Andrew Wong
|
2003-07-09 03:10:01 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "RageLog.h"
|
2003-07-09 05:57:09 +00:00
|
|
|
#include "song.h"
|
2003-07-11 18:08:57 +00:00
|
|
|
#include "Course.h"
|
2003-07-09 03:10:01 +00:00
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "UnlockSystem.h"
|
2003-07-09 05:01:37 +00:00
|
|
|
#include "SongManager.h"
|
2003-07-11 18:08:57 +00:00
|
|
|
#include "GameState.h"
|
|
|
|
|
#include "IniFile.h"
|
2003-07-15 00:52:01 +00:00
|
|
|
#include "MsdFile.h"
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-09-19 07:02:53 +00:00
|
|
|
UnlockSystem* UNLOCKSYS = NULL; // global and accessable from anywhere in our program
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
#define UNLOCKS_PATH "Data/Unlocks.dat"
|
|
|
|
|
|
2003-12-10 09:26:05 +00:00
|
|
|
#define MEMCARD_PATH "Data/MemCard.ini"
|
|
|
|
|
|
2003-07-09 03:10:01 +00:00
|
|
|
UnlockSystem::UnlockSystem()
|
|
|
|
|
{
|
2003-09-19 07:02:53 +00:00
|
|
|
UNLOCKSYS = this;
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
LoadFromDATFile();
|
|
|
|
|
|
2003-07-11 09:35:28 +00:00
|
|
|
ArcadePoints = 0;
|
|
|
|
|
DancePoints = 0;
|
|
|
|
|
SongPoints = 0;
|
|
|
|
|
ExtraClearPoints = 0;
|
|
|
|
|
ExtraFailPoints = 0;
|
|
|
|
|
ToastyPoints = 0;
|
|
|
|
|
StagesCleared = 0;
|
|
|
|
|
RouletteSeeds = "1";
|
2003-07-16 12:58:02 +00:00
|
|
|
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH ); // in case its ever accessed,
|
2003-07-11 09:35:28 +00:00
|
|
|
// we want the values to be available
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH ); // create if it does not exist
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-18 08:04:47 +00:00
|
|
|
void UnlockSystem::RouletteUnlock( const Song *song )
|
2003-07-09 11:38:50 +00:00
|
|
|
{
|
2003-08-07 10:15:16 +00:00
|
|
|
// if its an extra stage, don't count it
|
2004-01-24 19:39:18 +00:00
|
|
|
if( GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2() )
|
2003-08-07 10:15:16 +00:00
|
|
|
return;
|
|
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry *p = FindSong( song );
|
2004-01-24 19:39:18 +00:00
|
|
|
if( !p )
|
2003-07-18 08:04:47 +00:00
|
|
|
return; // does not exist
|
2004-01-24 19:39:18 +00:00
|
|
|
if( p->m_iRouletteSeed == 0 )
|
2003-07-18 08:04:47 +00:00
|
|
|
return; // already unlocked
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2003-09-04 21:55:47 +00:00
|
|
|
ASSERT( p->m_iRouletteSeed < (int) RouletteSeeds.size() );
|
2003-07-11 09:35:28 +00:00
|
|
|
RouletteSeeds[p->m_iRouletteSeed] = '1';
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-09 11:38:50 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-10 11:24:16 +00:00
|
|
|
bool UnlockSystem::CourseIsLocked( const Course *course )
|
|
|
|
|
{
|
2003-07-18 08:04:47 +00:00
|
|
|
if( !PREFSMAN->m_bUseUnlockSystem )
|
|
|
|
|
return false;
|
|
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry *p = FindCourse( course );
|
2004-01-24 19:39:18 +00:00
|
|
|
if( p == NULL )
|
|
|
|
|
return false;
|
2003-07-10 11:24:16 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
p->UpdateLocked();
|
|
|
|
|
return p->isLocked;
|
2003-07-10 11:24:16 +00:00
|
|
|
}
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-07-09 04:46:24 +00:00
|
|
|
bool UnlockSystem::SongIsLocked( const Song *song )
|
|
|
|
|
{
|
2003-07-18 08:04:47 +00:00
|
|
|
if( !PREFSMAN->m_bUseUnlockSystem )
|
|
|
|
|
return false;
|
|
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry *p = FindSong( song );
|
2003-07-12 20:16:07 +00:00
|
|
|
if( p == NULL )
|
|
|
|
|
return false;
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2003-07-18 06:38:05 +00:00
|
|
|
p->UpdateLocked();
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2003-07-12 20:16:07 +00:00
|
|
|
LOG->Trace( "current status: %slocked", p->isLocked? "":"un" );
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2003-07-12 20:16:07 +00:00
|
|
|
return p->isLocked;
|
2003-07-09 04:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UnlockSystem::SongIsRoulette( const Song *song )
|
|
|
|
|
{
|
2004-01-24 22:55:59 +00:00
|
|
|
if( !PREFSMAN->m_bUseUnlockSystem )
|
|
|
|
|
return false;
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
const UnlockEntry *p = FindSong( song );
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
return p && p->m_iRouletteSeed != 0;
|
2003-07-09 04:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry *UnlockSystem::FindLockEntry( CString songname )
|
2003-07-10 14:44:13 +00:00
|
|
|
{
|
2004-01-24 19:39:18 +00:00
|
|
|
for( unsigned i = 0; i < m_SongEntries.size(); i++ )
|
|
|
|
|
if( !songname.CompareNoCase(m_SongEntries[i].m_sSongName) )
|
2003-07-10 14:44:13 +00:00
|
|
|
return &m_SongEntries[i];
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry *UnlockSystem::FindSong( const Song *pSong )
|
2003-07-10 11:24:16 +00:00
|
|
|
{
|
2004-01-24 19:39:18 +00:00
|
|
|
for( unsigned i = 0; i < m_SongEntries.size(); i++ )
|
|
|
|
|
if( m_SongEntries[i].m_pSong == pSong )
|
2003-07-10 11:24:16 +00:00
|
|
|
return &m_SongEntries[i];
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry *UnlockSystem::FindCourse( const Course *pCourse )
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
|
|
|
|
for(unsigned i = 0; i < m_SongEntries.size(); i++)
|
2003-07-18 06:38:05 +00:00
|
|
|
if (m_SongEntries[i].m_pCourse== pCourse )
|
2003-07-09 05:01:37 +00:00
|
|
|
return &m_SongEntries[i];
|
2003-07-09 13:54:23 +00:00
|
|
|
|
2003-07-09 05:01:37 +00:00
|
|
|
return NULL;
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry::UnlockEntry()
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
|
|
|
|
m_fDancePointsRequired = 0;
|
|
|
|
|
m_fArcadePointsRequired = 0;
|
|
|
|
|
m_fSongPointsRequired = 0;
|
|
|
|
|
m_fExtraStagesCleared = 0;
|
|
|
|
|
m_fExtraStagesFailed = 0;
|
|
|
|
|
m_fStagesCleared = 0;
|
|
|
|
|
m_fToastysSeen = 0;
|
|
|
|
|
m_iRouletteSeed = 0;
|
|
|
|
|
|
2003-07-18 06:38:05 +00:00
|
|
|
m_pSong = NULL;
|
|
|
|
|
m_pCourse = NULL;
|
2003-07-16 12:58:02 +00:00
|
|
|
|
2003-07-09 03:10:01 +00:00
|
|
|
isLocked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
void UnlockEntry::UpdateLocked()
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2004-01-24 19:39:18 +00:00
|
|
|
if( !isLocked )
|
2003-07-18 06:38:05 +00:00
|
|
|
return;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = true;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( m_fArcadePointsRequired && UNLOCKSYS->ArcadePoints >= m_fArcadePointsRequired )
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( m_fDancePointsRequired && UNLOCKSYS->DancePoints >= m_fDancePointsRequired )
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( m_fSongPointsRequired && UNLOCKSYS->SongPoints >= m_fSongPointsRequired )
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( m_fExtraStagesCleared && UNLOCKSYS->ExtraClearPoints >= m_fExtraStagesCleared )
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( m_fExtraStagesFailed && UNLOCKSYS->ExtraFailPoints >= m_fExtraStagesFailed )
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( m_fStagesCleared && UNLOCKSYS->StagesCleared >= m_fStagesCleared )
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( m_fToastysSeen && UNLOCKSYS->ToastyPoints >= m_fToastysSeen )
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-07-18 06:38:05 +00:00
|
|
|
if ( m_iRouletteSeed )
|
2003-07-09 11:38:50 +00:00
|
|
|
{
|
2003-09-19 07:02:53 +00:00
|
|
|
const CString &tmp = UNLOCKSYS->RouletteSeeds;
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2003-07-18 06:38:05 +00:00
|
|
|
LOG->Trace("Seed in question: %d Roulette seeds: %s", m_iRouletteSeed, tmp.c_str() );
|
2003-07-18 07:51:42 +00:00
|
|
|
if( tmp[m_iRouletteSeed] == '1' )
|
2003-07-18 06:38:05 +00:00
|
|
|
isLocked = false;
|
2003-07-09 11:38:50 +00:00
|
|
|
}
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
bool UnlockSystem::LoadFromDATFile()
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2004-01-24 19:39:18 +00:00
|
|
|
LOG->Trace( "UnlockSystem::LoadFromDATFile()" );
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-07-15 00:52:01 +00:00
|
|
|
MsdFile msd;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( !msd.ReadFile( UNLOCKS_PATH ) )
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2004-01-24 19:39:18 +00:00
|
|
|
LOG->Warn( "Error opening file '%s' for reading: %s.", UNLOCKS_PATH, msd.GetError().c_str() );
|
2003-07-09 03:10:01 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 09:35:28 +00:00
|
|
|
int MaxRouletteSlot = 0;
|
2003-07-16 12:58:02 +00:00
|
|
|
unsigned i, j;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-07-15 00:52:01 +00:00
|
|
|
for( i=0; i<msd.GetNumValues(); i++ )
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2003-07-15 00:52:01 +00:00
|
|
|
int iNumParams = msd.GetNumParams(i);
|
|
|
|
|
const MsdFile::value_t &sParams = msd.GetValue(i);
|
|
|
|
|
CString sValueName = sParams[0];
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( iNumParams < 1 )
|
2003-07-15 00:52:01 +00:00
|
|
|
{
|
|
|
|
|
LOG->Warn("Got \"%s\" tag with no parameters", sValueName.c_str());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2003-07-14 06:36:29 +00:00
|
|
|
|
2003-07-15 00:52:01 +00:00
|
|
|
if( stricmp(sParams[0],"UNLOCK") )
|
|
|
|
|
{
|
2003-07-15 10:11:22 +00:00
|
|
|
LOG->Warn("Unrecognized unlock tag \"%s\", ignored.", sValueName.c_str());
|
2003-07-09 03:10:01 +00:00
|
|
|
continue;
|
2003-07-15 00:52:01 +00:00
|
|
|
}
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry current;
|
2003-07-15 00:52:01 +00:00
|
|
|
current.m_sSongName = sParams[1];
|
|
|
|
|
LOG->Trace("Song entry: %s", current.m_sSongName.c_str() );
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-07-15 00:52:01 +00:00
|
|
|
CStringArray UnlockTypes;
|
2004-01-24 19:39:18 +00:00
|
|
|
split( sParams[2], ",", UnlockTypes );
|
2003-07-14 06:36:29 +00:00
|
|
|
|
2003-07-16 12:58:02 +00:00
|
|
|
for( j=0; j<UnlockTypes.size(); ++j )
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2003-07-14 06:36:29 +00:00
|
|
|
CStringArray readparam;
|
|
|
|
|
|
2003-07-15 00:52:01 +00:00
|
|
|
split(UnlockTypes[j], "=", readparam);
|
|
|
|
|
CString unlock_type = readparam[0];
|
|
|
|
|
float datavalue = (float) atof(readparam[1]);
|
2003-07-14 06:36:29 +00:00
|
|
|
|
2003-07-15 00:52:01 +00:00
|
|
|
LOG->Trace("UnlockTypes line: %s", UnlockTypes[j].c_str() );
|
2003-07-14 06:36:29 +00:00
|
|
|
LOG->Trace("Unlock info: %s %f", unlock_type.c_str(), datavalue);
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( unlock_type == "AP" )
|
2003-07-14 06:36:29 +00:00
|
|
|
current.m_fArcadePointsRequired = datavalue;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( unlock_type == "DP" )
|
2003-07-14 06:36:29 +00:00
|
|
|
current.m_fDancePointsRequired = datavalue;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( unlock_type == "SP" )
|
2003-07-14 06:36:29 +00:00
|
|
|
current.m_fSongPointsRequired = datavalue;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( unlock_type == "EC" )
|
2003-07-14 06:36:29 +00:00
|
|
|
current.m_fExtraStagesCleared = datavalue;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( unlock_type == "EF" )
|
2003-07-14 06:36:29 +00:00
|
|
|
current.m_fExtraStagesFailed = datavalue;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( unlock_type == "CS" )
|
2003-07-14 06:36:29 +00:00
|
|
|
current.m_fStagesCleared = datavalue;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( unlock_type == "!!" )
|
2003-07-14 06:36:29 +00:00
|
|
|
current.m_fToastysSeen = datavalue;
|
2004-01-24 19:39:18 +00:00
|
|
|
if( unlock_type == "RO" )
|
2003-07-14 06:36:29 +00:00
|
|
|
{
|
|
|
|
|
current.m_iRouletteSeed = (int)datavalue;
|
2003-07-15 00:52:01 +00:00
|
|
|
MaxRouletteSlot = max( MaxRouletteSlot, (int) datavalue );
|
2003-07-14 06:36:29 +00:00
|
|
|
}
|
2003-07-09 14:16:21 +00:00
|
|
|
}
|
2003-07-18 06:38:05 +00:00
|
|
|
current.UpdateLocked();
|
2003-07-16 12:58:02 +00:00
|
|
|
|
2003-07-09 03:10:01 +00:00
|
|
|
m_SongEntries.push_back(current);
|
|
|
|
|
}
|
2003-07-15 00:52:01 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
InitRouletteSeeds( MaxRouletteSlot ); // resize roulette seeds for more efficient use of file
|
2003-07-11 09:35:28 +00:00
|
|
|
|
2003-07-18 06:38:05 +00:00
|
|
|
UpdateSongs();
|
|
|
|
|
|
2003-07-14 06:36:29 +00:00
|
|
|
for(i=0; i < m_SongEntries.size(); i++)
|
2003-07-09 11:38:50 +00:00
|
|
|
{
|
|
|
|
|
CString tmp = " ";
|
|
|
|
|
if (!m_SongEntries[i].isLocked) tmp = "un";
|
2003-07-14 06:36:29 +00:00
|
|
|
|
|
|
|
|
LOG->Trace( "UnlockSystem Entry %s", m_SongEntries[i].m_sSongName.c_str() );
|
2003-07-18 06:38:05 +00:00
|
|
|
if (m_SongEntries[i].m_pSong != NULL)
|
|
|
|
|
LOG->Trace( " Translit %s", m_SongEntries[i].m_pSong->GetTranslitMainTitle().c_str() );
|
2003-07-14 06:36:29 +00:00
|
|
|
LOG->Trace( " AP %f", m_SongEntries[i].m_fArcadePointsRequired );
|
|
|
|
|
LOG->Trace( " DP %f", m_SongEntries[i].m_fDancePointsRequired );
|
|
|
|
|
LOG->Trace( " SP %f", m_SongEntries[i].m_fSongPointsRequired );
|
|
|
|
|
LOG->Trace( " CS %f", m_SongEntries[i].m_fStagesCleared );
|
|
|
|
|
LOG->Trace( " RO %i", m_SongEntries[i].m_iRouletteSeed );
|
|
|
|
|
LOG->Trace( " Status %slocked", tmp.c_str() );
|
2003-07-24 14:04:13 +00:00
|
|
|
if (m_SongEntries[i].m_pSong)
|
|
|
|
|
LOG->Trace( " Found matching song entry" );
|
|
|
|
|
if (m_SongEntries[i].m_pCourse)
|
|
|
|
|
LOG->Trace( " Found matching course entry" );
|
2003-07-09 11:38:50 +00:00
|
|
|
}
|
2003-07-09 03:10:01 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-09 06:05:43 +00:00
|
|
|
float UnlockSystem::DancePointsUntilNextUnlock()
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
|
|
|
|
float fSmallestPoints = 400000000; // or an arbitrarily large value
|
|
|
|
|
for( unsigned a=0; a<m_SongEntries.size(); a++ )
|
2003-07-11 09:35:28 +00:00
|
|
|
if( m_SongEntries[a].m_fDancePointsRequired > DancePoints)
|
2003-07-09 03:10:01 +00:00
|
|
|
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fDancePointsRequired);
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( fSmallestPoints == 400000000 )
|
|
|
|
|
return 0; // no match found
|
2003-07-11 09:35:28 +00:00
|
|
|
return fSmallestPoints - DancePoints;
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
2003-07-09 05:01:37 +00:00
|
|
|
|
2003-07-09 06:05:43 +00:00
|
|
|
float UnlockSystem::ArcadePointsUntilNextUnlock()
|
|
|
|
|
{
|
|
|
|
|
float fSmallestPoints = 400000000; // or an arbitrarily large value
|
|
|
|
|
for( unsigned a=0; a<m_SongEntries.size(); a++ )
|
2003-07-11 09:35:28 +00:00
|
|
|
if( m_SongEntries[a].m_fArcadePointsRequired > ArcadePoints)
|
2003-07-09 06:05:43 +00:00
|
|
|
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fArcadePointsRequired);
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( fSmallestPoints == 400000000 )
|
|
|
|
|
return 0; // no match found
|
2003-07-11 09:35:28 +00:00
|
|
|
return fSmallestPoints - ArcadePoints;
|
2003-07-09 06:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float UnlockSystem::SongPointsUntilNextUnlock()
|
|
|
|
|
{
|
|
|
|
|
float fSmallestPoints = 400000000; // or an arbitrarily large value
|
|
|
|
|
for( unsigned a=0; a<m_SongEntries.size(); a++ )
|
2003-07-11 09:35:28 +00:00
|
|
|
if( m_SongEntries[a].m_fSongPointsRequired > SongPoints )
|
2003-07-09 06:05:43 +00:00
|
|
|
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fSongPointsRequired);
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( fSmallestPoints == 400000000 )
|
|
|
|
|
return 0; // no match found
|
2003-07-11 09:35:28 +00:00
|
|
|
return fSmallestPoints - SongPoints;
|
2003-07-09 06:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-18 06:38:05 +00:00
|
|
|
/* Update the song pointer. Only call this when it's likely to have changed,
|
|
|
|
|
* such as on load, or when a song title changes in the editor. */
|
|
|
|
|
void UnlockSystem::UpdateSongs()
|
2003-07-09 05:01:37 +00:00
|
|
|
{
|
2003-07-18 06:38:05 +00:00
|
|
|
for( unsigned i = 0; i < m_SongEntries.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
m_SongEntries[i].m_pSong = NULL;
|
|
|
|
|
m_SongEntries[i].m_pCourse = NULL;
|
2003-07-22 05:45:30 +00:00
|
|
|
m_SongEntries[i].m_pSong = SONGMAN->FindSong( m_SongEntries[i].m_sSongName );
|
2003-07-18 06:38:05 +00:00
|
|
|
if( m_SongEntries[i].m_pSong == NULL )
|
|
|
|
|
m_SongEntries[i].m_pCourse = SONGMAN->FindCourse( m_SongEntries[i].m_sSongName );
|
2003-08-11 22:37:46 +00:00
|
|
|
|
|
|
|
|
// display warning on invalid song entry
|
|
|
|
|
if (m_SongEntries[i].m_pSong == NULL &&
|
|
|
|
|
m_SongEntries[i].m_pCourse == NULL)
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn("UnlockSystem::UpdateSongs(): Cannot find a "
|
|
|
|
|
"matching entry for %s.\nPlease check the song title. "
|
|
|
|
|
"Song titles should include the title and song title, e.g. "
|
|
|
|
|
"Can't Stop Fallin' In Love -Speed Mix-.",
|
|
|
|
|
m_SongEntries[i].m_sSongName.c_str() );
|
|
|
|
|
m_SongEntries.erase(m_SongEntries.begin() + i);
|
|
|
|
|
}
|
2003-07-18 06:38:05 +00:00
|
|
|
}
|
2003-07-09 05:01:37 +00:00
|
|
|
}
|
2003-07-09 13:54:23 +00:00
|
|
|
|
2003-07-09 14:16:21 +00:00
|
|
|
// This is mainly to streamline the INI for unnecessary values.
|
|
|
|
|
void UnlockSystem::InitRouletteSeeds(int MaxRouletteSlot)
|
|
|
|
|
{
|
|
|
|
|
MaxRouletteSlot++; // we actually need one more
|
|
|
|
|
|
2003-09-04 21:55:47 +00:00
|
|
|
// Truncate the value if we have too many seeds:
|
|
|
|
|
if ( (int)RouletteSeeds.size() > MaxRouletteSlot )
|
|
|
|
|
RouletteSeeds = RouletteSeeds.Left( MaxRouletteSlot );
|
2003-07-09 14:16:21 +00:00
|
|
|
|
2003-09-04 21:55:47 +00:00
|
|
|
// Lengthen the value if we have too few seeds:
|
|
|
|
|
while ( (int)RouletteSeeds.size() < MaxRouletteSlot )
|
|
|
|
|
RouletteSeeds += "0";
|
2003-07-11 09:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UnlockSystem::ReadValues( CString filename)
|
|
|
|
|
{
|
|
|
|
|
IniFile data;
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
data.SetPath( filename );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
if( !data.ReadFile() )
|
2003-07-11 09:35:28 +00:00
|
|
|
return false;
|
|
|
|
|
|
2003-10-02 02:03:29 +00:00
|
|
|
data.GetValue ( "Unlock", "ArcadePointsAccumulated", ArcadePoints );
|
|
|
|
|
data.GetValue ( "Unlock", "DancePointsAccumulated", DancePoints );
|
|
|
|
|
data.GetValue ( "Unlock", "SongPointsAccumulated", SongPoints );
|
|
|
|
|
data.GetValue ( "Unlock", "ExtraStagesCleared", ExtraClearPoints );
|
|
|
|
|
data.GetValue ( "Unlock", "ExtraStagesFailed", ExtraFailPoints );
|
|
|
|
|
data.GetValue ( "Unlock", "TotalStagesCleared", StagesCleared );
|
|
|
|
|
data.GetValue ( "Unlock", "TotalToastysSeen", ToastyPoints );
|
2003-07-11 09:35:28 +00:00
|
|
|
data.GetValue ( "Unlock", "RouletteSeeds", RouletteSeeds );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UnlockSystem::WriteValues( CString filename)
|
|
|
|
|
{
|
|
|
|
|
IniFile data;
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
data.SetPath( filename );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
2003-10-02 02:11:47 +00:00
|
|
|
data.SetValue( "Unlock", "ArcadePointsAccumulated", ArcadePoints );
|
|
|
|
|
data.SetValue( "Unlock", "DancePointsAccumulated", DancePoints );
|
|
|
|
|
data.SetValue( "Unlock", "SongPointsAccumulated", SongPoints );
|
|
|
|
|
data.SetValue( "Unlock", "ExtraStagesCleared", ExtraClearPoints );
|
|
|
|
|
data.SetValue( "Unlock", "ExtraStagesFailed", ExtraFailPoints );
|
|
|
|
|
data.SetValue( "Unlock", "TotalStagesCleared", StagesCleared );
|
|
|
|
|
data.SetValue( "Unlock", "TotalToastysSeen", ToastyPoints );
|
|
|
|
|
data.SetValue( "Unlock", "RouletteSeeds", RouletteSeeds );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
data.WriteFile();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float UnlockSystem::UnlockAddAP(float credit)
|
|
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
ArcadePoints += credit;
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return ArcadePoints;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 03:32:48 +00:00
|
|
|
float UnlockSystem::UnlockAddAP(Grade grade)
|
2003-07-11 09:35:28 +00:00
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2004-01-20 03:32:48 +00:00
|
|
|
switch( grade )
|
|
|
|
|
{
|
|
|
|
|
case GRADE_FAILED:
|
|
|
|
|
; // no points
|
|
|
|
|
break;
|
|
|
|
|
case GRADE_TIER_1:
|
|
|
|
|
case GRADE_TIER_2:
|
2003-07-11 09:35:28 +00:00
|
|
|
ArcadePoints += 9;
|
2004-01-20 03:32:48 +00:00
|
|
|
break;
|
|
|
|
|
case GRADE_NO_DATA:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ArcadePoints += 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return ArcadePoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float UnlockSystem::UnlockAddDP(float credit)
|
|
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2003-07-20 15:09:37 +00:00
|
|
|
|
|
|
|
|
// we don't want to ever take away dance points
|
2004-01-24 19:39:18 +00:00
|
|
|
if( credit > 0 )
|
|
|
|
|
DancePoints += credit;
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return DancePoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float UnlockSystem::UnlockAddSP(float credit)
|
|
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
SongPoints += credit;
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return SongPoints;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 03:32:48 +00:00
|
|
|
float UnlockSystem::UnlockAddSP( Grade grade )
|
2003-07-11 09:35:28 +00:00
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2003-07-12 21:41:12 +00:00
|
|
|
|
2004-01-20 03:32:48 +00:00
|
|
|
// TODO: move these to PREFS
|
|
|
|
|
switch( grade )
|
|
|
|
|
{
|
|
|
|
|
case GRADE_TIER_1:/*AAAA*/ SongPoints += 20; break;
|
|
|
|
|
case GRADE_TIER_2:/*AAA*/ SongPoints += 10; break;
|
|
|
|
|
case GRADE_TIER_3:/*AA*/ SongPoints += 5; break;
|
|
|
|
|
case GRADE_TIER_4:/*A*/ SongPoints += 4; break;
|
|
|
|
|
case GRADE_TIER_5:/*B*/ SongPoints += 3; break;
|
|
|
|
|
case GRADE_TIER_6:/*C*/ SongPoints += 2; break;
|
|
|
|
|
case GRADE_TIER_7:/*D*/ SongPoints += 1; break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return SongPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float UnlockSystem::UnlockClearExtraStage()
|
|
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
ExtraClearPoints++;
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return ExtraClearPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float UnlockSystem::UnlockFailExtraStage()
|
|
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
ExtraFailPoints++;
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return ExtraFailPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float UnlockSystem::UnlockClearStage()
|
|
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
StagesCleared++;
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return StagesCleared;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float UnlockSystem::UnlockToasty()
|
|
|
|
|
{
|
2003-12-10 09:26:05 +00:00
|
|
|
ReadValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
ToastyPoints++;
|
2003-12-10 09:26:05 +00:00
|
|
|
WriteValues( MEMCARD_PATH );
|
2003-07-11 09:35:28 +00:00
|
|
|
|
|
|
|
|
return ToastyPoints;
|
2003-07-11 18:08:57 +00:00
|
|
|
}
|
2003-07-25 00:03:05 +00:00
|
|
|
|
|
|
|
|
int UnlockSystem::GetNumUnlocks() const
|
|
|
|
|
{
|
|
|
|
|
return m_SongEntries.size();
|
2003-08-10 03:23:17 +00:00
|
|
|
}
|