bugfixes and updates to unlock system (more abstract)

This commit is contained in:
Andrew Wong
2003-07-11 09:35:28 +00:00
parent 203e2b6aea
commit 9958c4c0c5
4 changed files with 230 additions and 61 deletions
+24 -9
View File
@@ -26,6 +26,7 @@
#include "RageSoundManager.h" #include "RageSoundManager.h"
#include "ActorUtil.h" #include "ActorUtil.h"
#include "RageTimer.h" #include "RageTimer.h"
#include "UnlockSystem.h"
const int NUM_SCORE_DIGITS = 9; const int NUM_SCORE_DIGITS = 9;
@@ -202,11 +203,13 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName, Type type ) : Screen(sCl
{ {
GAMESTATE->m_pCurNotes[p]->AddScore( (PlayerNumber)p, grade[p], stageStats.iScore[p], bNewRecord[p] ); GAMESTATE->m_pCurNotes[p]->AddScore( (PlayerNumber)p, grade[p], stageStats.iScore[p], bNewRecord[p] );
// update unlock data // update unlock data if unlocks are on
PREFSMAN->m_fTotalStagesCleared += 1; if ( PREFSMAN->m_bUseUnlockSystem )
// switch ( {
GAMESTATE->m_pUnlockingSys->UnlockClearStage();
GAMESTATE->m_pUnlockingSys->UnlockAddAP( grade[p] );
GAMESTATE->m_pUnlockingSys->UnlockAddSP( grade[p] );
}
} }
} }
} }
@@ -236,10 +239,7 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName, Type type ) : Screen(sCl
// If unlocking is enabled, save the dance points // If unlocking is enabled, save the dance points
if( PREFSMAN->m_bUseUnlockSystem ) if( PREFSMAN->m_bUseUnlockSystem )
{ GAMESTATE->m_pUnlockingSys->UnlockAddDP( fTotalDP );
PREFSMAN->m_fDancePointsAccumulated += fTotalDP;
PREFSMAN->SaveGlobalPrefsToDisk();
}
} }
break; break;
case course: case course:
@@ -262,6 +262,21 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName, Type type ) : Screen(sCl
COPY( GAMESTATE->m_iRankingIndex, iRankingIndex ); COPY( GAMESTATE->m_iRankingIndex, iRankingIndex );
GAMESTATE->m_pRankingCourse = pCourse; GAMESTATE->m_pRankingCourse = pCourse;
GAMESTATE->m_RankingNotesType = nt; GAMESTATE->m_RankingNotesType = nt;
// If unlocking is enabled, save the dance points
// (for courses)
if( PREFSMAN->m_bUseUnlockSystem )
{
for(p=0; p < NUM_PLAYERS; p++)
{
GAMESTATE->m_pUnlockingSys->UnlockAddDP( stageStats.iActualDancePoints[p] );
GAMESTATE->m_pUnlockingSys->UnlockAddAP( stageStats.iSongsPassed[p] );
GAMESTATE->m_pUnlockingSys->UnlockAddSP( stageStats.iSongsPassed[p] );
}
}
// cannot just use score since it may be nonstop mode
} }
break; break;
default: default:
+1 -2
View File
@@ -30,8 +30,7 @@ ScreenUnlock::ScreenUnlock() : ScreenAttract("ScreenUnlock")
CString PointDisplay = THEME->GetMetric("ScreenUnlock", "TypeOfPointsToDisplay"); CString PointDisplay = THEME->GetMetric("ScreenUnlock", "TypeOfPointsToDisplay");
CString IconCommand = CString IconCommand = THEME->GetMetric("ScreenUnlock", "UnlockIconCommand");
THEME->GetMetric("ScreenUnlock", "UnlockIconCommand");
for(int i=1; i <= THEME->GetMetricI("ScreenUnlock", "NumUnlocks"); i++) for(int i=1; i <= THEME->GetMetricI("ScreenUnlock", "NumUnlocks"); i++)
{ {
+189 -48
View File
@@ -19,6 +19,8 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "UnlockSystem.h" #include "UnlockSystem.h"
#include "SongManager.h" #include "SongManager.h"
#include "gamestate.h"
#include "inifile.h"
#include <fstream> #include <fstream>
using namespace std; using namespace std;
@@ -27,6 +29,17 @@ using namespace std;
UnlockSystem::UnlockSystem() UnlockSystem::UnlockSystem()
{ {
ArcadePoints = 0;
DancePoints = 0;
SongPoints = 0;
ExtraClearPoints = 0;
ExtraFailPoints = 0;
ToastyPoints = 0;
StagesCleared = 0;
RouletteSeeds = "1";
ReadValues("Data/MemCard.ini"); // in case its ever accessed,
// we want the values to be available
WriteValues("Data/MemCard.ini"); // create if it does not exist
} }
bool UnlockSystem::RouletteUnlock( const Song *song ) bool UnlockSystem::RouletteUnlock( const Song *song )
@@ -35,8 +48,8 @@ bool UnlockSystem::RouletteUnlock( const Song *song )
if (!p) return false; // does not exist if (!p) return false; // does not exist
if (p->m_iRouletteSeed == 0) return false; // already unlocked if (p->m_iRouletteSeed == 0) return false; // already unlocked
PREFSMAN->m_RouletteSeeds[p->m_iRouletteSeed] = '1'; RouletteSeeds[p->m_iRouletteSeed] = '1';
PREFSMAN->SaveGamePrefsToDisk(); WriteValues("Data/MemCard.ini");
return true; return true;
} }
@@ -54,7 +67,7 @@ bool UnlockSystem::CourseIsLocked( const Course *course )
p->updateLocked(); p->updateLocked();
if (!p->isLocked) tmp = "un"; if (!p->isLocked) tmp = "un";
LOG->Trace( "current status: %slocked", tmp.c_str() ); // LOG->Trace( "current status: %slocked", tmp.c_str() );
} }
return (p != NULL) && (p->isLocked); return (p != NULL) && (p->isLocked);
@@ -225,30 +238,32 @@ bool SongEntry::updateLocked()
{ {
if (!(isLocked)) return true; // if its already true if (!(isLocked)) return true; // if its already true
UnlockSystem *UNLOCKS = GAMESTATE->m_pUnlockingSys;
if (m_fArcadePointsRequired != 0) if (m_fArcadePointsRequired != 0)
isLocked = (PREFSMAN->m_fArcadePointsAccumulated < m_fArcadePointsRequired); isLocked = ( UNLOCKS->ArcadePoints < m_fArcadePointsRequired);
if (m_fDancePointsRequired != 0) if (m_fDancePointsRequired != 0)
isLocked = (PREFSMAN->m_fDancePointsAccumulated < m_fDancePointsRequired); isLocked = ( UNLOCKS->DancePoints < m_fDancePointsRequired);
if (m_fSongPointsRequired != 0) if (m_fSongPointsRequired != 0)
isLocked = (PREFSMAN->m_fSongPointsAccumulated < m_fSongPointsRequired); isLocked = ( UNLOCKS->SongPoints < m_fSongPointsRequired);
if (m_fExtraStagesCleared != 0) if (m_fExtraStagesCleared != 0)
isLocked = (PREFSMAN->m_fExtraStagesCleared < m_fExtraStagesCleared); isLocked = ( UNLOCKS->ExtraClearPoints < m_fExtraStagesCleared);
if (m_fExtraStagesFailed != 0) if (m_fExtraStagesFailed != 0)
isLocked = (PREFSMAN->m_fExtraStagesFailed < m_fExtraStagesFailed); isLocked = ( UNLOCKS->ExtraFailPoints < m_fExtraStagesFailed);
if (m_fStagesCleared != 0) if (m_fStagesCleared != 0)
isLocked = (PREFSMAN->m_fTotalStagesCleared < m_fStagesCleared); isLocked = ( UNLOCKS->StagesCleared < m_fStagesCleared);
if (m_fToastysSeen != 0) if (m_fToastysSeen != 0)
isLocked = (PREFSMAN->m_fTotalToastysSeen < m_fToastysSeen); isLocked = ( UNLOCKS->ToastyPoints < m_fToastysSeen);
if (m_iRouletteSeed != 0) if (m_iRouletteSeed != 0)
{ {
CString tmp = PREFSMAN->m_RouletteSeeds; CString tmp = UNLOCKS->RouletteSeeds;
LOG->Trace("Seed in question: %d Roulette seeds: %s", LOG->Trace("Seed in question: %d Roulette seeds: %s",
m_iRouletteSeed, tmp.c_str() ); m_iRouletteSeed, tmp.c_str() );
@@ -279,6 +294,7 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
char line[256]; char line[256];
CString unlock_type, song_title; CString unlock_type, song_title;
float datavalue; float datavalue;
int MaxRouletteSlot = 0;
// m_SongEntries.clear(); // m_SongEntries.clear();
@@ -292,59 +308,36 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
continue; continue;
SongEntry current; SongEntry current;
int MaxRouletteSlot = 0;
song_title.MakeUpper(); //Avoid case-sensitive problems song_title.MakeUpper(); //Avoid case-sensitive problems
current.m_sSongName = song_title; current.m_sSongName = song_title;
if (unlock_type == "AP") if (unlock_type == "AP")
{
current.m_fArcadePointsRequired = datavalue; current.m_fArcadePointsRequired = datavalue;
current.isLocked = (PREFSMAN->m_fArcadePointsAccumulated < datavalue);
}
if (unlock_type == "DP") if (unlock_type == "DP")
{
current.m_fDancePointsRequired = datavalue; current.m_fDancePointsRequired = datavalue;
current.isLocked = (PREFSMAN->m_fDancePointsAccumulated < datavalue);
}
if (unlock_type == "SP") if (unlock_type == "SP")
{
current.m_fSongPointsRequired = datavalue; current.m_fSongPointsRequired = datavalue;
current.isLocked = (PREFSMAN->m_fSongPointsAccumulated < datavalue);
}
if (unlock_type == "EC") if (unlock_type == "EC")
{
current.m_fExtraStagesCleared = datavalue; current.m_fExtraStagesCleared = datavalue;
current.isLocked = (PREFSMAN->m_fExtraStagesCleared < datavalue);
}
if (unlock_type == "EF") if (unlock_type == "EF")
{
current.m_fExtraStagesFailed = datavalue; current.m_fExtraStagesFailed = datavalue;
current.isLocked = (PREFSMAN->m_fExtraStagesFailed < datavalue);
}
if (unlock_type == "CS") if (unlock_type == "CS")
{
current.m_fStagesCleared = datavalue; current.m_fStagesCleared = datavalue;
current.isLocked = (PREFSMAN->m_fTotalStagesCleared < datavalue);
}
if (unlock_type == "!!") if (unlock_type == "!!")
{
current.m_fToastysSeen = datavalue; current.m_fToastysSeen = datavalue;
current.isLocked = (PREFSMAN->m_fTotalToastysSeen < datavalue);
}
if (unlock_type == "RO") if (unlock_type == "RO")
{ {
current.m_iRouletteSeed = (int)datavalue; current.m_iRouletteSeed = (int)datavalue;
if (datavalue > MaxRouletteSlot) if (datavalue > MaxRouletteSlot)
MaxRouletteSlot = (int) datavalue; MaxRouletteSlot = (int)datavalue;
current.isLocked = true;
// will read on first update
// current.isLocked = ((PREFSMAN->m_RouletteSeeds)[(int)datavalue] != '1');
} }
InitRouletteSeeds(MaxRouletteSlot); current.updateLocked();
m_SongEntries.push_back(current); m_SongEntries.push_back(current);
} }
InitRouletteSeeds(MaxRouletteSlot); // resize roulette seeds
// for more efficient use of data
// sort list so we can make use of binary searching // sort list so we can make use of binary searching
sort( m_SongEntries.begin(), m_SongEntries.end(), CompareSongEntries ); sort( m_SongEntries.begin(), m_SongEntries.end(), CompareSongEntries );
@@ -376,33 +369,33 @@ float UnlockSystem::DancePointsUntilNextUnlock()
{ {
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 > PREFSMAN->m_fDancePointsAccumulated) 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 - PREFSMAN->m_fDancePointsAccumulated; return fSmallestPoints - DancePoints;
} }
float UnlockSystem::ArcadePointsUntilNextUnlock() float UnlockSystem::ArcadePointsUntilNextUnlock()
{ {
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_fArcadePointsRequired > PREFSMAN->m_fArcadePointsAccumulated) 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 - PREFSMAN->m_fArcadePointsAccumulated; return fSmallestPoints - ArcadePoints;
} }
float UnlockSystem::SongPointsUntilNextUnlock() float UnlockSystem::SongPointsUntilNextUnlock()
{ {
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_fSongPointsRequired > PREFSMAN->m_fSongPointsAccumulated) 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 - PREFSMAN->m_fSongPointsAccumulated; return fSmallestPoints - SongPoints;
} }
Song *SongEntry::GetSong() const Song *SongEntry::GetSong() const
@@ -425,7 +418,7 @@ void UnlockSystem::DebugPrint()
// This is mainly to streamline the INI for unnecessary values. // This is mainly to streamline the INI for unnecessary values.
void UnlockSystem::InitRouletteSeeds(int MaxRouletteSlot) void UnlockSystem::InitRouletteSeeds(int MaxRouletteSlot)
{ {
CString seeds = PREFSMAN->m_RouletteSeeds; CString seeds = RouletteSeeds;
MaxRouletteSlot++; // we actually need one more MaxRouletteSlot++; // we actually need one more
// have exactly the needed number of slots // have exactly the needed number of slots
@@ -434,7 +427,7 @@ void UnlockSystem::InitRouletteSeeds(int MaxRouletteSlot)
if (seeds.GetLength() > MaxRouletteSlot) // truncate value if (seeds.GetLength() > MaxRouletteSlot) // truncate value
{ {
seeds = seeds.Left(MaxRouletteSlot); seeds = seeds.Left(MaxRouletteSlot);
PREFSMAN->m_RouletteSeeds = seeds; RouletteSeeds = seeds;
return; return;
} }
@@ -442,5 +435,153 @@ void UnlockSystem::InitRouletteSeeds(int MaxRouletteSlot)
while (seeds.GetLength() != MaxRouletteSlot) while (seeds.GetLength() != MaxRouletteSlot)
seeds += "0"; seeds += "0";
PREFSMAN->m_RouletteSeeds = seeds; RouletteSeeds = seeds;
}
bool UnlockSystem::ReadValues( CString filename)
{
IniFile data;
data.SetPath(filename);
if (data.ReadFile())
return false;
data.GetValueF( "Unlock", "ArcadePointsAccumulated", ArcadePoints );
data.GetValueF( "Unlock", "DancePointsAccumulated", DancePoints );
data.GetValueF( "Unlock", "SongPointsAccumulated", SongPoints );
data.GetValueF( "Unlock", "ExtraStagesCleared", ExtraClearPoints );
data.GetValueF( "Unlock", "ExtraStagesFailed", ExtraFailPoints );
data.GetValueF( "Unlock", "TotalStagesCleared", StagesCleared );
data.GetValueF( "Unlock", "TotalToastysSeen", ToastyPoints );
data.GetValue ( "Unlock", "RouletteSeeds", RouletteSeeds );
return true;
}
bool UnlockSystem::WriteValues( CString filename)
{
IniFile data;
data.SetPath(filename);
data.SetValueF( "Unlock", "ArcadePointsAccumulated", ArcadePoints );
data.SetValueF( "Unlock", "DancePointsAccumulated", DancePoints );
data.SetValueF( "Unlock", "SongPointsAccumulated", SongPoints );
data.SetValueF( "Unlock", "ExtraStagesCleared", ExtraClearPoints );
data.SetValueF( "Unlock", "ExtraStagesFailed", ExtraFailPoints );
data.SetValueF( "Unlock", "TotalStagesCleared", StagesCleared );
data.SetValueF( "Unlock", "TotalToastysSeen", ToastyPoints );
data.SetValue ( "Unlock", "RouletteSeeds", RouletteSeeds );
data.WriteFile();
return true;
}
float UnlockSystem::UnlockAddAP(float credit)
{
ReadValues("Data/MemCard.ini");
ArcadePoints += credit;
WriteValues("Data/MemCard.ini");
return ArcadePoints;
}
float UnlockSystem::UnlockAddAP(Grade credit)
{
ReadValues("Data/MemCard.ini");
if (credit != GRADE_E && credit != GRADE_D)
ArcadePoints += 1;
if (credit == GRADE_AAA)
ArcadePoints += 9;
WriteValues("Data/MemCard.ini");
return ArcadePoints;
}
float UnlockSystem::UnlockAddDP(float credit)
{
ReadValues("Data/MemCard.ini");
DancePoints += credit;
WriteValues("Data/MemCard.ini");
return DancePoints;
}
float UnlockSystem::UnlockAddSP(float credit)
{
ReadValues("Data/MemCard.ini");
SongPoints += credit;
WriteValues("Data/MemCard.ini");
return SongPoints;
}
float UnlockSystem::UnlockAddSP(Grade credit)
{
ReadValues("Data/MemCard.ini");
switch (credit)
{
case GRADE_AAAA:
SongPoints += 20;
break;
case GRADE_AAA:
SongPoints += 10;
break;
case GRADE_AA:
SongPoints += 5;
break;
case GRADE_A:
SongPoints += 4;
break;
case GRADE_B:
SongPoints += 3;
break;
case GRADE_C:
SongPoints += 2;
break;
case GRADE_D:
SongPoints += 1;
}
WriteValues("Data/MemCard.ini");
return SongPoints;
}
float UnlockSystem::UnlockClearExtraStage()
{
ReadValues("Data/MemCard.ini");
ExtraClearPoints++;
WriteValues("Data/MemCard.ini");
return ExtraClearPoints;
}
float UnlockSystem::UnlockFailExtraStage()
{
ReadValues("Data/MemCard.ini");
ExtraFailPoints++;
WriteValues("Data/MemCard.ini");
return ExtraFailPoints;
}
float UnlockSystem::UnlockClearStage()
{
ReadValues("Data/MemCard.ini");
StagesCleared++;
WriteValues("Data/MemCard.ini");
return StagesCleared;
}
float UnlockSystem::UnlockToasty()
{
ReadValues("Data/MemCard.ini");
ToastyPoints++;
WriteValues("Data/MemCard.ini");
return ToastyPoints;
} }
+16 -2
View File
@@ -68,17 +68,31 @@ public:
vector<SongEntry> m_SongEntries; // All locked songs are stored here vector<SongEntry> m_SongEntries; // All locked songs are stored here
// functions that add to values, which don't really work. // functions that add to values
float UnlockAddAP(Grade credit); float UnlockAddAP(Grade credit);
float UnlockAddAP(float credit);
float UnlockAddDP(float credit); float UnlockAddDP(float credit);
float UnlockAddSP(Grade credit); float UnlockAddSP(Grade credit);
float UnlockAddSP(float credit);
float UnlockClearExtraStage(); float UnlockClearExtraStage();
float UnlockFailExtraStage(); float UnlockFailExtraStage();
float UnlockClearStage(); float UnlockClearStage();
float UnlockToasty(); float UnlockToasty();
bool RouletteUnlock( const Song *song ); bool RouletteUnlock( const Song *song );
// read and write unlock functions
bool ReadValues( 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 DebugPrint(); void DebugPrint();