call LoadFromDATFile(); from UnlockSystem ctor, not manually
cleanups
This commit is contained in:
@@ -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;
|
||||||
@@ -47,13 +51,13 @@ UnlockSystem::UnlockSystem()
|
|||||||
void UnlockSystem::RouletteUnlock( const Song *song )
|
void UnlockSystem::RouletteUnlock( const Song *song )
|
||||||
{
|
{
|
||||||
// if its an extra stage, don't count it
|
// if its an extra stage, don't count it
|
||||||
if (GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2())
|
if( GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UnlockEntry *p = FindSong( song );
|
UnlockEntry *p = FindSong( song );
|
||||||
if (!p)
|
if( !p )
|
||||||
return; // does not exist
|
return; // does not exist
|
||||||
if (p->m_iRouletteSeed == 0)
|
if( p->m_iRouletteSeed == 0 )
|
||||||
return; // already unlocked
|
return; // already unlocked
|
||||||
|
|
||||||
ASSERT( p->m_iRouletteSeed < (int) RouletteSeeds.size() );
|
ASSERT( p->m_iRouletteSeed < (int) RouletteSeeds.size() );
|
||||||
@@ -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,15 +96,15 @@ 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 )
|
||||||
{
|
{
|
||||||
for(unsigned i = 0; i < m_SongEntries.size(); i++)
|
for( unsigned i = 0; i < m_SongEntries.size(); i++ )
|
||||||
if (!songname.CompareNoCase(m_SongEntries[i].m_sSongName))
|
if( !songname.CompareNoCase(m_SongEntries[i].m_sSongName) )
|
||||||
return &m_SongEntries[i];
|
return &m_SongEntries[i];
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -110,8 +112,8 @@ UnlockEntry *UnlockSystem::FindLockEntry( CString songname )
|
|||||||
|
|
||||||
UnlockEntry *UnlockSystem::FindSong( const Song *pSong )
|
UnlockEntry *UnlockSystem::FindSong( const Song *pSong )
|
||||||
{
|
{
|
||||||
for(unsigned i = 0; i < m_SongEntries.size(); i++)
|
for( unsigned i = 0; i < m_SongEntries.size(); i++ )
|
||||||
if (m_SongEntries[i].m_pSong == pSong )
|
if( m_SongEntries[i].m_pSong == pSong )
|
||||||
return &m_SongEntries[i];
|
return &m_SongEntries[i];
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -147,29 +149,29 @@ UnlockEntry::UnlockEntry()
|
|||||||
|
|
||||||
void UnlockEntry::UpdateLocked()
|
void UnlockEntry::UpdateLocked()
|
||||||
{
|
{
|
||||||
if (!isLocked)
|
if( !isLocked )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
isLocked = true;
|
isLocked = true;
|
||||||
if ( m_fArcadePointsRequired && UNLOCKSYS->ArcadePoints >= m_fArcadePointsRequired )
|
if( m_fArcadePointsRequired && UNLOCKSYS->ArcadePoints >= m_fArcadePointsRequired )
|
||||||
isLocked = false;
|
isLocked = false;
|
||||||
|
|
||||||
if ( m_fDancePointsRequired && UNLOCKSYS->DancePoints >= m_fDancePointsRequired )
|
if( m_fDancePointsRequired && UNLOCKSYS->DancePoints >= m_fDancePointsRequired )
|
||||||
isLocked = false;
|
isLocked = false;
|
||||||
|
|
||||||
if ( m_fSongPointsRequired && UNLOCKSYS->SongPoints >= m_fSongPointsRequired )
|
if( m_fSongPointsRequired && UNLOCKSYS->SongPoints >= m_fSongPointsRequired )
|
||||||
isLocked = false;
|
isLocked = false;
|
||||||
|
|
||||||
if ( m_fExtraStagesCleared && UNLOCKSYS->ExtraClearPoints >= m_fExtraStagesCleared )
|
if( m_fExtraStagesCleared && UNLOCKSYS->ExtraClearPoints >= m_fExtraStagesCleared )
|
||||||
isLocked = false;
|
isLocked = false;
|
||||||
|
|
||||||
if ( m_fExtraStagesFailed && UNLOCKSYS->ExtraFailPoints >= m_fExtraStagesFailed )
|
if( m_fExtraStagesFailed && UNLOCKSYS->ExtraFailPoints >= m_fExtraStagesFailed )
|
||||||
isLocked = false;
|
isLocked = false;
|
||||||
|
|
||||||
if ( m_fStagesCleared && UNLOCKSYS->StagesCleared >= m_fStagesCleared )
|
if( m_fStagesCleared && UNLOCKSYS->StagesCleared >= m_fStagesCleared )
|
||||||
isLocked = false;
|
isLocked = false;
|
||||||
|
|
||||||
if ( m_fToastysSeen && UNLOCKSYS->ToastyPoints >= m_fToastysSeen )
|
if( m_fToastysSeen && UNLOCKSYS->ToastyPoints >= m_fToastysSeen )
|
||||||
isLocked = false;
|
isLocked = false;
|
||||||
|
|
||||||
if ( m_iRouletteSeed )
|
if ( m_iRouletteSeed )
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +204,7 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
|
|||||||
const MsdFile::value_t &sParams = msd.GetValue(i);
|
const MsdFile::value_t &sParams = msd.GetValue(i);
|
||||||
CString sValueName = sParams[0];
|
CString sValueName = sParams[0];
|
||||||
|
|
||||||
if(iNumParams < 1)
|
if( iNumParams < 1 )
|
||||||
{
|
{
|
||||||
LOG->Warn("Got \"%s\" tag with no parameters", sValueName.c_str());
|
LOG->Warn("Got \"%s\" tag with no parameters", sValueName.c_str());
|
||||||
continue;
|
continue;
|
||||||
@@ -219,7 +221,7 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
|
|||||||
LOG->Trace("Song entry: %s", current.m_sSongName.c_str() );
|
LOG->Trace("Song entry: %s", current.m_sSongName.c_str() );
|
||||||
|
|
||||||
CStringArray UnlockTypes;
|
CStringArray UnlockTypes;
|
||||||
split(sParams[2], ",", UnlockTypes);
|
split( sParams[2], ",", UnlockTypes );
|
||||||
|
|
||||||
for( j=0; j<UnlockTypes.size(); ++j )
|
for( j=0; j<UnlockTypes.size(); ++j )
|
||||||
{
|
{
|
||||||
@@ -232,21 +234,21 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
|
|||||||
LOG->Trace("UnlockTypes line: %s", UnlockTypes[j].c_str() );
|
LOG->Trace("UnlockTypes line: %s", UnlockTypes[j].c_str() );
|
||||||
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_fArcadePointsRequired = datavalue;
|
||||||
if (unlock_type == "DP")
|
if( unlock_type == "DP" )
|
||||||
current.m_fDancePointsRequired = datavalue;
|
current.m_fDancePointsRequired = datavalue;
|
||||||
if (unlock_type == "SP")
|
if( unlock_type == "SP" )
|
||||||
current.m_fSongPointsRequired = datavalue;
|
current.m_fSongPointsRequired = datavalue;
|
||||||
if (unlock_type == "EC")
|
if( unlock_type == "EC" )
|
||||||
current.m_fExtraStagesCleared = datavalue;
|
current.m_fExtraStagesCleared = datavalue;
|
||||||
if (unlock_type == "EF")
|
if( unlock_type == "EF" )
|
||||||
current.m_fExtraStagesFailed = datavalue;
|
current.m_fExtraStagesFailed = datavalue;
|
||||||
if (unlock_type == "CS")
|
if( unlock_type == "CS" )
|
||||||
current.m_fStagesCleared = datavalue;
|
current.m_fStagesCleared = datavalue;
|
||||||
if (unlock_type == "!!")
|
if( unlock_type == "!!" )
|
||||||
current.m_fToastysSeen = datavalue;
|
current.m_fToastysSeen = datavalue;
|
||||||
if (unlock_type == "RO")
|
if( unlock_type == "RO" )
|
||||||
{
|
{
|
||||||
current.m_iRouletteSeed = (int)datavalue;
|
current.m_iRouletteSeed = (int)datavalue;
|
||||||
MaxRouletteSlot = max( MaxRouletteSlot, (int) datavalue );
|
MaxRouletteSlot = max( MaxRouletteSlot, (int) datavalue );
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,9 +381,9 @@ bool UnlockSystem::ReadValues( CString filename)
|
|||||||
{
|
{
|
||||||
IniFile data;
|
IniFile data;
|
||||||
|
|
||||||
data.SetPath(filename);
|
data.SetPath( filename );
|
||||||
|
|
||||||
if (!data.ReadFile())
|
if( !data.ReadFile() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
data.GetValue ( "Unlock", "ArcadePointsAccumulated", ArcadePoints );
|
data.GetValue ( "Unlock", "ArcadePointsAccumulated", ArcadePoints );
|
||||||
@@ -400,7 +403,7 @@ bool UnlockSystem::WriteValues( CString filename)
|
|||||||
{
|
{
|
||||||
IniFile data;
|
IniFile data;
|
||||||
|
|
||||||
data.SetPath(filename);
|
data.SetPath( filename );
|
||||||
|
|
||||||
data.SetValue( "Unlock", "ArcadePointsAccumulated", ArcadePoints );
|
data.SetValue( "Unlock", "ArcadePointsAccumulated", ArcadePoints );
|
||||||
data.SetValue( "Unlock", "DancePointsAccumulated", DancePoints );
|
data.SetValue( "Unlock", "DancePointsAccumulated", DancePoints );
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user