This commit is contained in:
Glenn Maynard
2004-01-24 23:40:40 +00:00
parent ec5d3282bf
commit 4b50f2999d
2 changed files with 92 additions and 177 deletions
+62 -133
View File
@@ -28,19 +28,23 @@ UnlockSystem* UNLOCKSYS = NULL; // global and accessable from anywhere in our pr
#define MEMCARD_PATH "Data/MemCard.ini" #define MEMCARD_PATH "Data/MemCard.ini"
static const char *g_UnlockNames[NUM_UNLOCK_TYPES] =
{
"ArcadePointsAccumulated",
"DancePointsAccumulated",
"SongPointsAccumulated",
"ExtraStagesCleared",
"ExtraStagesFailed",
"TotalToastysSeen",
"TotalStagesCleared"
};
UnlockSystem::UnlockSystem() UnlockSystem::UnlockSystem()
{ {
UNLOCKSYS = this;
LoadFromDATFile(); LoadFromDATFile();
ArcadePoints = 0; memset( m_fScores, 0, sizeof(m_fScores) );
DancePoints = 0;
SongPoints = 0;
ExtraClearPoints = 0;
ExtraFailPoints = 0;
ToastyPoints = 0;
StagesCleared = 0;
RouletteSeeds = "1"; RouletteSeeds = "1";
ReadValues( MEMCARD_PATH ); // in case its ever accessed, ReadValues( MEMCARD_PATH ); // in case its ever accessed,
@@ -134,13 +138,7 @@ UnlockEntry *UnlockSystem::FindCourse( const Course *pCourse )
UnlockEntry::UnlockEntry() UnlockEntry::UnlockEntry()
{ {
m_fDancePointsRequired = 0; memset( m_fRequired, 0, sizeof(m_fRequired) );
m_fArcadePointsRequired = 0;
m_fSongPointsRequired = 0;
m_fExtraStagesCleared = 0;
m_fExtraStagesFailed = 0;
m_fStagesCleared = 0;
m_fToastysSeen = 0;
m_iRouletteSeed = 0; m_iRouletteSeed = 0;
m_pSong = NULL; m_pSong = NULL;
@@ -156,26 +154,9 @@ void UnlockEntry::UpdateLocked()
return; return;
isLocked = true; isLocked = true;
if( m_fArcadePointsRequired && UNLOCKSYS->ArcadePoints >= m_fArcadePointsRequired ) for( int i = 0; i < NUM_UNLOCK_TYPES; ++i )
isLocked = false; if( m_fRequired[i] && UNLOCKSYS->m_fScores[i] >= m_fRequired[i] )
isLocked = false;
if( m_fDancePointsRequired && UNLOCKSYS->DancePoints >= m_fDancePointsRequired )
isLocked = false;
if( m_fSongPointsRequired && UNLOCKSYS->SongPoints >= m_fSongPointsRequired )
isLocked = false;
if( m_fExtraStagesCleared && UNLOCKSYS->ExtraClearPoints >= m_fExtraStagesCleared )
isLocked = false;
if( m_fExtraStagesFailed && UNLOCKSYS->ExtraFailPoints >= m_fExtraStagesFailed )
isLocked = false;
if( m_fStagesCleared && UNLOCKSYS->StagesCleared >= m_fStagesCleared )
isLocked = false;
if( m_fToastysSeen && UNLOCKSYS->ToastyPoints >= m_fToastysSeen )
isLocked = false;
if ( m_iRouletteSeed ) if ( m_iRouletteSeed )
{ {
@@ -238,19 +219,19 @@ bool UnlockSystem::LoadFromDATFile()
LOG->Trace("Unlock info: %s %f", unlock_type.c_str(), datavalue); LOG->Trace("Unlock info: %s %f", unlock_type.c_str(), datavalue);
if( unlock_type == "AP" ) if( unlock_type == "AP" )
current.m_fArcadePointsRequired = datavalue; current.m_fRequired[UNLOCK_ARCADE_POINTS] = datavalue;
if( unlock_type == "DP" ) if( unlock_type == "DP" )
current.m_fDancePointsRequired = datavalue; current.m_fRequired[UNLOCK_DANCE_POINTS] = datavalue;
if( unlock_type == "SP" ) if( unlock_type == "SP" )
current.m_fSongPointsRequired = datavalue; current.m_fRequired[UNLOCK_SONG_POINTS] = datavalue;
if( unlock_type == "EC" ) if( unlock_type == "EC" )
current.m_fExtraStagesCleared = datavalue; current.m_fRequired[UNLOCK_EXTRA_CLEARED] = datavalue;
if( unlock_type == "EF" ) if( unlock_type == "EF" )
current.m_fExtraStagesFailed = datavalue; current.m_fRequired[UNLOCK_EXTRA_CLEARED] = datavalue;
if( unlock_type == "CS" )
current.m_fStagesCleared = datavalue;
if( unlock_type == "!!" ) if( unlock_type == "!!" )
current.m_fToastysSeen = datavalue; current.m_fRequired[UNLOCK_TOASTY] = datavalue;
if( unlock_type == "CS" )
current.m_fRequired[UNLOCK_CLEARED] = datavalue;
if( unlock_type == "RO" ) if( unlock_type == "RO" )
{ {
current.m_iRouletteSeed = (int)datavalue; current.m_iRouletteSeed = (int)datavalue;
@@ -274,10 +255,10 @@ bool UnlockSystem::LoadFromDATFile()
LOG->Trace( "UnlockSystem Entry %s", m_SongEntries[i].m_sSongName.c_str() ); LOG->Trace( "UnlockSystem Entry %s", m_SongEntries[i].m_sSongName.c_str() );
if (m_SongEntries[i].m_pSong != NULL) if (m_SongEntries[i].m_pSong != NULL)
LOG->Trace( " Translit %s", m_SongEntries[i].m_pSong->GetTranslitMainTitle().c_str() ); LOG->Trace( " Translit %s", m_SongEntries[i].m_pSong->GetTranslitMainTitle().c_str() );
LOG->Trace( " AP %f", m_SongEntries[i].m_fArcadePointsRequired ); LOG->Trace( " AP %f", m_SongEntries[i].m_fRequired[UNLOCK_ARCADE_POINTS] );
LOG->Trace( " DP %f", m_SongEntries[i].m_fDancePointsRequired ); LOG->Trace( " DP %f", m_SongEntries[i].m_fRequired[UNLOCK_DANCE_POINTS] );
LOG->Trace( " SP %f", m_SongEntries[i].m_fSongPointsRequired ); LOG->Trace( " SP %f", m_SongEntries[i].m_fRequired[UNLOCK_SONG_POINTS] );
LOG->Trace( " CS %f", m_SongEntries[i].m_fStagesCleared ); LOG->Trace( " CS %f", m_SongEntries[i].m_fRequired[UNLOCK_CLEARED] );
LOG->Trace( " RO %i", m_SongEntries[i].m_iRouletteSeed ); LOG->Trace( " RO %i", m_SongEntries[i].m_iRouletteSeed );
LOG->Trace( " Status %slocked", tmp.c_str() ); LOG->Trace( " Status %slocked", tmp.c_str() );
if (m_SongEntries[i].m_pSong) if (m_SongEntries[i].m_pSong)
@@ -289,40 +270,16 @@ bool UnlockSystem::LoadFromDATFile()
return true; return true;
} }
float UnlockSystem::DancePointsUntilNextUnlock() float UnlockSystem::PointsUntilNextUnlock( UnlockType t ) const
{ {
float fSmallestPoints = 400000000; // or an arbitrarily large value float fSmallestPoints = 400000000; // or an arbitrarily large value
for( unsigned a=0; a<m_SongEntries.size(); a++ ) for( unsigned a=0; a<m_SongEntries.size(); a++ )
if( m_SongEntries[a].m_fDancePointsRequired > DancePoints) if( m_SongEntries[a].m_fRequired[t] > m_fScores[t] )
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fDancePointsRequired); fSmallestPoints = min( fSmallestPoints, m_SongEntries[a].m_fRequired[t] );
if( fSmallestPoints == 400000000 ) if( fSmallestPoints == 400000000 )
return 0; // no match found return 0; // no match found
return fSmallestPoints - DancePoints; return fSmallestPoints - m_fScores[t];
}
float UnlockSystem::ArcadePointsUntilNextUnlock()
{
float fSmallestPoints = 400000000; // or an arbitrarily large value
for( unsigned a=0; a<m_SongEntries.size(); a++ )
if( m_SongEntries[a].m_fArcadePointsRequired > ArcadePoints)
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fArcadePointsRequired);
if( fSmallestPoints == 400000000 )
return 0; // no match found
return fSmallestPoints - ArcadePoints;
}
float UnlockSystem::SongPointsUntilNextUnlock()
{
float fSmallestPoints = 400000000; // or an arbitrarily large value
for( unsigned a=0; a<m_SongEntries.size(); a++ )
if( m_SongEntries[a].m_fSongPointsRequired > SongPoints )
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fSongPointsRequired);
if( fSmallestPoints == 400000000 )
return 0; // no match found
return fSmallestPoints - SongPoints;
} }
/* Update the song pointer. Only call this when it's likely to have changed, /* Update the song pointer. Only call this when it's likely to have changed,
@@ -374,13 +331,8 @@ bool UnlockSystem::ReadValues( CString filename)
if( !data.ReadFile() ) if( !data.ReadFile() )
return false; return false;
data.GetValue ( "Unlock", "ArcadePointsAccumulated", ArcadePoints ); for( int i = 0; i < NUM_UNLOCK_TYPES; ++i )
data.GetValue ( "Unlock", "DancePointsAccumulated", DancePoints ); data.GetValue( "Unlock", g_UnlockNames[i], m_fScores[i] );
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 );
data.GetValue ( "Unlock", "RouletteSeeds", RouletteSeeds ); data.GetValue ( "Unlock", "RouletteSeeds", RouletteSeeds );
return true; return true;
@@ -393,13 +345,8 @@ bool UnlockSystem::WriteValues( CString filename)
data.SetPath( filename ); data.SetPath( filename );
data.SetValue( "Unlock", "ArcadePointsAccumulated", ArcadePoints ); for( int i = 0; i < NUM_UNLOCK_TYPES; ++i )
data.SetValue( "Unlock", "DancePointsAccumulated", DancePoints ); data.SetValue( "Unlock", g_UnlockNames[i], m_fScores[i] );
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 ); data.SetValue( "Unlock", "RouletteSeeds", RouletteSeeds );
data.WriteFile(); data.WriteFile();
@@ -407,16 +354,14 @@ bool UnlockSystem::WriteValues( CString filename)
return true; return true;
} }
float UnlockSystem::UnlockAddAP(float credit) void UnlockSystem::UnlockAddAP(float credit)
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
ArcadePoints += credit; m_fScores[UNLOCK_ARCADE_POINTS] += credit;
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return ArcadePoints;
} }
float UnlockSystem::UnlockAddAP(Grade grade) void UnlockSystem::UnlockAddAP(Grade grade)
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
switch( grade ) switch( grade )
@@ -426,96 +371,80 @@ float UnlockSystem::UnlockAddAP(Grade grade)
break; break;
case GRADE_TIER_1: case GRADE_TIER_1:
case GRADE_TIER_2: case GRADE_TIER_2:
ArcadePoints += 9; m_fScores[UNLOCK_ARCADE_POINTS] += 9;
break; break;
case GRADE_NO_DATA: case GRADE_NO_DATA:
ASSERT(0); ASSERT(0);
break; break;
default: default:
ArcadePoints += 1; m_fScores[UNLOCK_ARCADE_POINTS] += 1;
break; break;
} }
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return ArcadePoints;
} }
float UnlockSystem::UnlockAddDP(float credit) void UnlockSystem::UnlockAddDP(float credit)
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
// we don't want to ever take away dance points // we don't want to ever take away dance points
if( credit > 0 ) if( credit > 0 )
DancePoints += credit; m_fScores[UNLOCK_DANCE_POINTS] += credit;
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return DancePoints;
} }
float UnlockSystem::UnlockAddSP(float credit) void UnlockSystem::UnlockAddSP(float credit)
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
SongPoints += credit; m_fScores[UNLOCK_SONG_POINTS] += credit;
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return SongPoints;
} }
float UnlockSystem::UnlockAddSP( Grade grade ) void UnlockSystem::UnlockAddSP( Grade grade )
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
// TODO: move these to PREFS // TODO: move these to PREFS
switch( grade ) switch( grade )
{ {
case GRADE_TIER_1:/*AAAA*/ SongPoints += 20; break; case GRADE_TIER_1:/*AAAA*/ m_fScores[UNLOCK_SONG_POINTS] += 20; break;
case GRADE_TIER_2:/*AAA*/ SongPoints += 10; break; case GRADE_TIER_2:/*AAA*/ m_fScores[UNLOCK_SONG_POINTS] += 10; break;
case GRADE_TIER_3:/*AA*/ SongPoints += 5; break; case GRADE_TIER_3:/*AA*/ m_fScores[UNLOCK_SONG_POINTS] += 5; break;
case GRADE_TIER_4:/*A*/ SongPoints += 4; break; case GRADE_TIER_4:/*A*/ m_fScores[UNLOCK_SONG_POINTS] += 4; break;
case GRADE_TIER_5:/*B*/ SongPoints += 3; break; case GRADE_TIER_5:/*B*/ m_fScores[UNLOCK_SONG_POINTS] += 3; break;
case GRADE_TIER_6:/*C*/ SongPoints += 2; break; case GRADE_TIER_6:/*C*/ m_fScores[UNLOCK_SONG_POINTS] += 2; break;
case GRADE_TIER_7:/*D*/ SongPoints += 1; break; case GRADE_TIER_7:/*D*/ m_fScores[UNLOCK_SONG_POINTS] += 1; break;
} }
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return SongPoints;
} }
float UnlockSystem::UnlockClearExtraStage() void UnlockSystem::UnlockClearExtraStage()
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
ExtraClearPoints++; ++m_fScores[UNLOCK_EXTRA_CLEARED];
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return ExtraClearPoints;
} }
float UnlockSystem::UnlockFailExtraStage() void UnlockSystem::UnlockFailExtraStage()
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
ExtraFailPoints++; ++m_fScores[UNLOCK_EXTRA_FAILED];
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return ExtraFailPoints;
} }
float UnlockSystem::UnlockClearStage() void UnlockSystem::UnlockClearStage()
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
StagesCleared++; ++m_fScores[UNLOCK_CLEARED];
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return StagesCleared;
} }
float UnlockSystem::UnlockToasty() void UnlockSystem::UnlockToasty()
{ {
ReadValues( MEMCARD_PATH ); ReadValues( MEMCARD_PATH );
ToastyPoints++; ++m_fScores[UNLOCK_TOASTY];
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return ToastyPoints;
} }
int UnlockSystem::GetNumUnlocks() const int UnlockSystem::GetNumUnlocks() const
+30 -44
View File
@@ -16,6 +16,18 @@
class Song; class Song;
enum UnlockType
{
UNLOCK_ARCADE_POINTS,
UNLOCK_DANCE_POINTS,
UNLOCK_SONG_POINTS,
UNLOCK_EXTRA_CLEARED,
UNLOCK_EXTRA_FAILED,
UNLOCK_TOASTY,
UNLOCK_CLEARED,
NUM_UNLOCK_TYPES
};
struct UnlockEntry struct UnlockEntry
{ {
UnlockEntry(); UnlockEntry();
@@ -27,13 +39,7 @@ struct UnlockEntry
Song *m_pSong; Song *m_pSong;
Course *m_pCourse; Course *m_pCourse;
float m_fDancePointsRequired; // Ways to unlock/lock songs. float m_fRequired[NUM_UNLOCK_TYPES];
float m_fArcadePointsRequired;
float m_fSongPointsRequired;
float m_fExtraStagesCleared;
float m_fExtraStagesFailed;
float m_fStagesCleared;
float m_fToastysSeen;
int m_iRouletteSeed; int m_iRouletteSeed;
bool isLocked; // cached locked tag bool isLocked; // cached locked tag
@@ -49,25 +55,13 @@ class UnlockSystem
friend struct UnlockEntry; friend struct UnlockEntry;
public: public:
/* TODO:
enum UnlockType
{
UNLOCK_ARCADE_POINTS,
UNLOCK_DANCE_POINTS,
UNLOCK_SONG_POINTS,
UNLOCK_EXTRA_CLEARED,
UNLOCK_EXTRA_FAILED,
UNLOCK_TOASTY,
UNLOCK_CLEARED,
NUM_UNLOCK_TYPES
};
*/
UnlockSystem(); UnlockSystem();
// returns # of points till next unlock - used for ScreenUnlock // returns # of points till next unlock - used for ScreenUnlock
float DancePointsUntilNextUnlock(); float PointsUntilNextUnlock( UnlockType t ) const;
float ArcadePointsUntilNextUnlock(); float ArcadePointsUntilNextUnlock() const { return PointsUntilNextUnlock(UNLOCK_ARCADE_POINTS); }
float SongPointsUntilNextUnlock(); float DancePointsUntilNextUnlock() const { return PointsUntilNextUnlock(UNLOCK_DANCE_POINTS); }
float SongPointsUntilNextUnlock() const { return PointsUntilNextUnlock(UNLOCK_SONG_POINTS); }
// Used on select screens: // Used on select screens:
bool SongIsLocked( const Song *song ); bool SongIsLocked( const Song *song );
@@ -80,16 +74,18 @@ public:
// Gets number of unlocks for title screen // Gets number of unlocks for title screen
int GetNumUnlocks() const; int GetNumUnlocks() const;
void UpdateSongs();
// functions that add to values // functions that add to values
float UnlockAddAP(Grade credit); void UnlockAddAP(Grade credit);
float UnlockAddAP(float credit); void UnlockAddAP(float credit);
float UnlockAddDP(float credit); void UnlockAddDP(float credit);
float UnlockAddSP(Grade credit); void UnlockAddSP(Grade credit);
float UnlockAddSP(float credit); void UnlockAddSP(float credit);
float UnlockClearExtraStage(); void UnlockClearExtraStage();
float UnlockFailExtraStage(); void UnlockFailExtraStage();
float UnlockClearStage(); void UnlockClearStage();
float UnlockToasty(); void UnlockToasty();
// unlocks given song in roulette // unlocks given song in roulette
void RouletteUnlock( const Song *song ); void RouletteUnlock( const Song *song );
@@ -98,8 +94,6 @@ public:
bool ReadValues( CString filename); bool ReadValues( CString filename);
bool WriteValues( CString filename); bool WriteValues( CString filename);
void UpdateSongs();
UnlockEntry *FindLockEntry( CString lockname ); UnlockEntry *FindLockEntry( CString lockname );
// All locked songs are stored here // All locked songs are stored here
@@ -109,19 +103,11 @@ private:
UnlockEntry *FindSong( const Song *pSong ); UnlockEntry *FindSong( const Song *pSong );
UnlockEntry *FindCourse( const Course *pCourse ); UnlockEntry *FindCourse( const Course *pCourse );
void InitRouletteSeeds(int MaxRouletteSlot);
// makes RouletteSeeds more efficient // makes RouletteSeeds more efficient
void InitRouletteSeeds(int MaxRouletteSlot);
// float m_fScores[NUM_UNLOCK_TYPES];
// unlock values, cached // unlock values, cached
float ArcadePoints; float m_fScores[NUM_UNLOCK_TYPES];
float DancePoints;
float SongPoints;
float ExtraClearPoints;
float ExtraFailPoints;
float ToastyPoints;
float StagesCleared;
CString RouletteSeeds; CString RouletteSeeds;
}; };