call LoadFromDATFile(); from UnlockSystem ctor, not manually

cleanups
This commit is contained in:
Glenn Maynard
2004-01-24 19:39:18 +00:00
parent 6194103b89
commit 268bff458d
2 changed files with 92 additions and 70 deletions
+29 -25
View File
@@ -24,12 +24,16 @@
UnlockSystem* UNLOCKSYS = NULL; // global and accessable from anywhere in our program UnlockSystem* UNLOCKSYS = NULL; // global and accessable from anywhere in our program
#define UNLOCKS_PATH "Data/Unlocks.dat"
#define MEMCARD_PATH "Data/MemCard.ini" #define MEMCARD_PATH "Data/MemCard.ini"
UnlockSystem::UnlockSystem() UnlockSystem::UnlockSystem()
{ {
UNLOCKSYS = this; UNLOCKSYS = this;
LoadFromDATFile();
ArcadePoints = 0; ArcadePoints = 0;
DancePoints = 0; DancePoints = 0;
SongPoints = 0; SongPoints = 0;
@@ -66,14 +70,12 @@ bool UnlockSystem::CourseIsLocked( const Course *course )
if( !PREFSMAN->m_bUseUnlockSystem ) if( !PREFSMAN->m_bUseUnlockSystem )
return false; return false;
// I know, its not a song, but for purposes of title
// comparison, its the same thing.
UnlockEntry *p = FindCourse( course ); UnlockEntry *p = FindCourse( course );
if( p == NULL )
return false;
if (p)
p->UpdateLocked(); p->UpdateLocked();
return p->isLocked;
return p != NULL && p->isLocked;
} }
bool UnlockSystem::SongIsLocked( const Song *song ) bool UnlockSystem::SongIsLocked( const Song *song )
@@ -94,9 +96,9 @@ bool UnlockSystem::SongIsLocked( const Song *song )
bool UnlockSystem::SongIsRoulette( const Song *song ) bool UnlockSystem::SongIsRoulette( const Song *song )
{ {
UnlockEntry *p = FindSong( song ); const UnlockEntry *p = FindSong( song );
return p && (p->m_iRouletteSeed != 0) ; return p && p->m_iRouletteSeed != 0;
} }
UnlockEntry *UnlockSystem::FindLockEntry( CString songname ) UnlockEntry *UnlockSystem::FindLockEntry( CString songname )
@@ -182,14 +184,14 @@ void UnlockEntry::UpdateLocked()
} }
} }
bool UnlockSystem::LoadFromDATFile( CString sPath ) bool UnlockSystem::LoadFromDATFile()
{ {
LOG->Trace( "UnlockSystem::LoadFromDATFile(%s)", sPath.c_str() ); LOG->Trace( "UnlockSystem::LoadFromDATFile()" );
MsdFile msd; MsdFile msd;
if( !msd.ReadFile( sPath ) ) if( !msd.ReadFile( UNLOCKS_PATH ) )
{ {
LOG->Warn( "Error opening file '%s' for reading: %s.", sPath.c_str(), msd.GetError().c_str() ); LOG->Warn( "Error opening file '%s' for reading: %s.", UNLOCKS_PATH, msd.GetError().c_str() );
return false; return false;
} }
@@ -257,8 +259,7 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
m_SongEntries.push_back(current); m_SongEntries.push_back(current);
} }
InitRouletteSeeds(MaxRouletteSlot); // resize roulette seeds InitRouletteSeeds( MaxRouletteSlot ); // resize roulette seeds for more efficient use of file
// for more efficient use of file
UpdateSongs(); UpdateSongs();
@@ -280,23 +281,23 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
LOG->Trace( " Found matching song entry" ); LOG->Trace( " Found matching song entry" );
if (m_SongEntries[i].m_pCourse) if (m_SongEntries[i].m_pCourse)
LOG->Trace( " Found matching course entry" ); LOG->Trace( " Found matching course entry" );
} }
return true; return true;
} }
bool UnlockEntry::SelectableWheel() bool UnlockEntry::SelectableWheel() const
{ {
return (!isLocked); // cached return !isLocked; // cached
} }
bool UnlockEntry::SelectableRoulette() bool UnlockEntry::SelectableRoulette() const
{ {
if (!isLocked) return true; if( !isLocked )
return true;
if (m_iRouletteSeed != 0) return true; if( m_iRouletteSeed != 0 )
return true;
return false; return false;
} }
@@ -307,7 +308,8 @@ float UnlockSystem::DancePointsUntilNextUnlock()
if( m_SongEntries[a].m_fDancePointsRequired > DancePoints) if( m_SongEntries[a].m_fDancePointsRequired > DancePoints)
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fDancePointsRequired); fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fDancePointsRequired);
if (fSmallestPoints == 400000000) return 0; // no match found if( fSmallestPoints == 400000000 )
return 0; // no match found
return fSmallestPoints - DancePoints; return fSmallestPoints - DancePoints;
} }
@@ -318,7 +320,8 @@ float UnlockSystem::ArcadePointsUntilNextUnlock()
if( m_SongEntries[a].m_fArcadePointsRequired > ArcadePoints) if( m_SongEntries[a].m_fArcadePointsRequired > ArcadePoints)
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fArcadePointsRequired); fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fArcadePointsRequired);
if (fSmallestPoints == 400000000) return 0; // no match found if( fSmallestPoints == 400000000 )
return 0; // no match found
return fSmallestPoints - ArcadePoints; return fSmallestPoints - ArcadePoints;
} }
@@ -329,7 +332,8 @@ float UnlockSystem::SongPointsUntilNextUnlock()
if( m_SongEntries[a].m_fSongPointsRequired > SongPoints ) if( m_SongEntries[a].m_fSongPointsRequired > SongPoints )
fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fSongPointsRequired); fSmallestPoints = min(fSmallestPoints, m_SongEntries[a].m_fSongPointsRequired);
if (fSmallestPoints == 400000000) return 0; // no match found if( fSmallestPoints == 400000000 )
return 0; // no match found
return fSmallestPoints - SongPoints; return fSmallestPoints - SongPoints;
} }
@@ -356,7 +360,6 @@ void UnlockSystem::UpdateSongs()
m_SongEntries[i].m_sSongName.c_str() ); m_SongEntries[i].m_sSongName.c_str() );
m_SongEntries.erase(m_SongEntries.begin() + i); m_SongEntries.erase(m_SongEntries.begin() + i);
} }
} }
} }
@@ -454,7 +457,8 @@ float 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) DancePoints += credit; if( credit > 0 )
DancePoints += credit;
WriteValues( MEMCARD_PATH ); WriteValues( MEMCARD_PATH );
return DancePoints; return DancePoints;
+34 -16
View File
@@ -40,8 +40,8 @@ struct UnlockEntry
bool IsCourse() const { return m_pCourse != NULL; } bool IsCourse() const { return m_pCourse != NULL; }
// if song is selectable vai two means // if song is selectable vai two means
bool SelectableWheel(); bool SelectableWheel() const;
bool SelectableRoulette(); bool SelectableRoulette() const;
void UpdateLocked(); // updates isLocked void UpdateLocked(); // updates isLocked
@@ -50,7 +50,22 @@ struct UnlockEntry
class UnlockSystem class UnlockSystem
{ {
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();
float DancePointsUntilNextUnlock(); float DancePointsUntilNextUnlock();
@@ -64,10 +79,7 @@ public:
bool CourseIsLocked( const Course *course ); bool CourseIsLocked( const Course *course );
// executed when program is first executed // executed when program is first executed
bool LoadFromDATFile( CString sPath ); bool LoadFromDATFile();
// All locked songs are stored here
vector<UnlockEntry> m_SongEntries;
// Gets number of unlocks for title screen // Gets number of unlocks for title screen
int GetNumUnlocks() const; int GetNumUnlocks() const;
@@ -90,16 +102,6 @@ public:
bool ReadValues( CString filename); bool ReadValues( CString filename);
bool WriteValues( CString filename); bool WriteValues( CString filename);
// unlock values, cached
float ArcadePoints;
float DancePoints;
float SongPoints;
float ExtraClearPoints;
float ExtraFailPoints;
float ToastyPoints;
float StagesCleared;
CString RouletteSeeds;
void UpdateSongs(); void UpdateSongs();
UnlockEntry *FindLockEntry( CString lockname ); UnlockEntry *FindLockEntry( CString lockname );
@@ -112,6 +114,22 @@ private:
void InitRouletteSeeds(int MaxRouletteSlot); void InitRouletteSeeds(int MaxRouletteSlot);
// makes RouletteSeeds more efficient // makes RouletteSeeds more efficient
public: // XXX
// All locked songs are stored here
vector<UnlockEntry> m_SongEntries;
// float m_fScores[NUM_UNLOCK_TYPES];
// unlock values, cached
float ArcadePoints;
float DancePoints;
float SongPoints;
float ExtraClearPoints;
float ExtraFailPoints;
float ToastyPoints;
float StagesCleared;
CString RouletteSeeds;
}; };
extern UnlockSystem* UNLOCKSYS; // global and accessable from anywhere in program extern UnlockSystem* UNLOCKSYS; // global and accessable from anywhere in program