From fd02bce7840b85347566b86d296925bfdb144be1 Mon Sep 17 00:00:00 2001 From: Kevin Slaughter Date: Fri, 9 May 2003 05:56:05 +0000 Subject: [PATCH] Added new unlock system, disabled by default --- stepmania/Data/Unlocks.dat | 4 + stepmania/Themes/default/metrics.ini | 1 + stepmania/src/GameState.h | 2 + stepmania/src/MusicWheel.cpp | 8 ++ stepmania/src/PrefsManager.cpp | 6 ++ stepmania/src/PrefsManager.h | 2 + stepmania/src/ScreenEvaluation.cpp | 13 +++ stepmania/src/ScreenEvaluation.h | 1 + stepmania/src/ScreenGameplayOptions.cpp | 6 +- stepmania/src/ScreenUnlock.cpp | 32 ++++++ stepmania/src/ScreenUnlock.h | 15 +-- stepmania/src/Song.cpp | 1 + stepmania/src/StepMania.cpp | 3 + stepmania/src/UnlockSystem.cpp | 133 ++++++++++++++++++++++++ stepmania/src/UnlockSystem.h | 37 +++++++ stepmania/src/song.h | 1 + 16 files changed, 258 insertions(+), 7 deletions(-) create mode 100644 stepmania/Data/Unlocks.dat create mode 100644 stepmania/src/ScreenUnlock.cpp create mode 100644 stepmania/src/UnlockSystem.cpp create mode 100644 stepmania/src/UnlockSystem.h diff --git a/stepmania/Data/Unlocks.dat b/stepmania/Data/Unlocks.dat new file mode 100644 index 0000000000..6d6a499801 --- /dev/null +++ b/stepmania/Data/Unlocks.dat @@ -0,0 +1,4 @@ +//Test file for Miryo's new Unlock system. Songs are matched by name, not folder name +[DP]500|Gamelan de Couple +[DP]7500|Exotic Ethnic +[DP]10000|Maxx Unlimited \ No newline at end of file diff --git a/stepmania/Themes/default/metrics.ini b/stepmania/Themes/default/metrics.ini index d27d645550..f0b373a157 100644 --- a/stepmania/Themes/default/metrics.ini +++ b/stepmania/Themes/default/metrics.ini @@ -1708,6 +1708,7 @@ MarvelousTiming=Enable or disable marvelous judgement. HiddenSongs=Some songs are only playable during Oni courses and::with roulette. Leave this &oq;OFF&cq; to always display all songs. PickExtraStage=Instead of a set extra stage, this allows::the player to choose which song to play.::Difficulty and options are still locked. SoloSingles=Turn this option &oq;ON&cq; to enable Solo-Style::for 4-panel single play. +UnlockSystem=Enable or disable unlock system. [ScreenBackgroundOptions] HelpText=&UP; &DOWN; to change line &LEFT; &RIGHT; to select between options::START to accept changes BACK to discard changes diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 51ba6244d3..fc36d43666 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -18,6 +18,7 @@ #include "Style.h" #include "Grade.h" #include "StageStats.h" +#include "UnlockSystem.h" class Song; class Notes; @@ -41,6 +42,7 @@ public: // // Main State Info // + UnlockSystem UnlockingSys; Game m_CurGame; Style m_CurStyle; bool m_bPlayersCanJoin; // true if it's not too late for a player to join - this only has an effect on the credits message diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index 3869082b96..1f695e0a4c 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -274,7 +274,15 @@ void MusicWheel::GetSongList(vector &arraySongs, SongSortOrder so, CStrin pSong->GetNotes( arraySteps, GAMESTATE->GetCurrentStyleDef()->m_NotesType, DIFFICULTY_INVALID, -1, -1, "", PREFSMAN->m_bAutogenMissingTypes ); if( !arraySteps.empty() ) + { + // If we're using unlocks, check it here to prevent from being shown + if( PREFSMAN->m_bUseUnlockSystem ) + { + pSong->m_bIsLocked = GAMESTATE->UnlockingSys.SongIsLocked( pSong->m_sMainTitle ); + if( pSong->m_bIsLocked ) { continue; } + } arraySongs.push_back( pSong ); + } } } diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 391d931296..c9abb00643 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -93,6 +93,8 @@ PrefsManager::PrefsManager() m_bBreakComboToGetItem = false; m_bShowDancingCharacters = false; m_BannerCacheType = preload_none; + m_fDancePointsAccumulated = 0; + m_bUseUnlockSystem = false; /* DDR Extreme-style extra stage support. * Default off so people used to the current behavior (or those with extra @@ -196,6 +198,8 @@ void PrefsManager::ReadGlobalPrefsFromDisk( bool bSwitchToLastPlayedGame ) ini.GetValueB( "Options", "BreakComboToGetItem", m_bBreakComboToGetItem ); ini.GetValueB( "Options", "ShowDancingCharacters", m_bShowDancingCharacters ); ini.GetValueI( "Options", "BannerCacheType", (int&)m_BannerCacheType ); + ini.GetValueF( "Misc", "DancePointsAccumulated", m_fDancePointsAccumulated ); + ini.GetValueB( "Misc", "UseUnlockSystem", m_bUseUnlockSystem ); m_asAdditionalSongFolders.clear(); CString sAdditionalSongFolders; @@ -279,6 +283,8 @@ void PrefsManager::SaveGlobalPrefsToDisk() ini.SetValueB( "Options", "BreakComboToGetItem", m_bBreakComboToGetItem ); ini.SetValueB( "Options", "ShowDancingCharacters", m_bShowDancingCharacters ); ini.SetValueI( "Options", "BannerCacheType", m_BannerCacheType ); + ini.SetValueF( "Misc", "DancePointsAccumulated", m_fDancePointsAccumulated ); + ini.SetValueB( "Misc", "UseUnlockSystem", m_bUseUnlockSystem ); /* Only write these if they aren't the default. This ensures that we can change diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index bbbad18f6c..0f50c80b70 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -76,6 +76,8 @@ public: CString m_sDefaultModifiers; bool m_bBreakComboToGetItem; bool m_bShowDancingCharacters; + float m_fDancePointsAccumulated; + bool m_bUseUnlockSystem; /* 0 = no; 1 = yes; -1 = auto (do whatever is appropriate for the arch). */ int m_iBoostAppPriority; diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 917df2c754..fd5a904cf0 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -195,8 +195,12 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName, Type type ) : Screen(sCl case stage: { for( int p=0; pIsHumanPlayer(p) ) + { GAMESTATE->m_pCurNotes[p]->AddScore( (PlayerNumber)p, grade[p], stageStats.fScore[p], bNewRecord[p] ); + } + } } break; case summary: @@ -208,10 +212,12 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName, Type type ) : Screen(sCl RankingCategory cat[NUM_PLAYERS]; int iRankingIndex[NUM_PLAYERS]; + float fTotalDP; for( int p=0; pm_iNumArcadeStages; cat[p] = AverageMeterToRankingCategory( fAverageMeter ); + fTotalDP += stageStats.iActualDancePoints[p]; } SONGMAN->AddScores( nt, bIsHumanPlayer, cat, stageStats.fScore, iRankingIndex ); @@ -219,6 +225,13 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName, Type type ) : Screen(sCl COPY( GAMESTATE->m_RankingCategory, cat ); COPY( GAMESTATE->m_iRankingIndex, iRankingIndex ); GAMESTATE->m_RankingNotesType = nt; + + // If unlocking is enabled, save the dance points + if( PREFSMAN->m_bUseUnlockSystem ) + { + PREFSMAN->m_fDancePointsAccumulated += fTotalDP; + PREFSMAN->SaveGlobalPrefsToDisk(); + } } break; case course: diff --git a/stepmania/src/ScreenEvaluation.h b/stepmania/src/ScreenEvaluation.h index 59dde21957..963054b63f 100644 --- a/stepmania/src/ScreenEvaluation.h +++ b/stepmania/src/ScreenEvaluation.h @@ -63,6 +63,7 @@ protected: GradeDisplay m_Grades[NUM_PLAYERS]; // points area + bool m_bNewSongsUnlocked; Sprite m_sprPercentFrame[NUM_PLAYERS]; BitmapText m_textPercentWhole[NUM_PLAYERS]; BitmapText m_textPercentRemainder[NUM_PLAYERS]; diff --git a/stepmania/src/ScreenGameplayOptions.cpp b/stepmania/src/ScreenGameplayOptions.cpp index 1e67e003ea..3e78eb8944 100644 --- a/stepmania/src/ScreenGameplayOptions.cpp +++ b/stepmania/src/ScreenGameplayOptions.cpp @@ -31,6 +31,7 @@ enum { GO_EASTER_EGGS, GO_MARVELOUS, GO_PICK_EXTRA_STAGE, + GO_UNLOCK_SYSTEM, NUM_GAMEPLAY_OPTIONS_LINES }; @@ -40,7 +41,8 @@ OptionRow g_GameplayOptionsLines[NUM_GAMEPLAY_OPTIONS_LINES] = { OptionRow( "Hidden\nSongs", "OFF","ON" ), OptionRow( "Easter\nEggs", "OFF","ON" ), OptionRow( "Marvelous\nTiming", "OFF","ON" ), - OptionRow( "Pick Extra\nStage", "OFF","ON" ) + OptionRow( "Pick Extra\nStage", "OFF","ON" ), + OptionRow( "Unlock\nSystem", "OFF","ON" ) }; ScreenGameplayOptions::ScreenGameplayOptions() : @@ -66,6 +68,7 @@ void ScreenGameplayOptions::ImportOptions() m_iSelectedOption[0][GO_EASTER_EGGS] = PREFSMAN->m_bEasterEggs ? 1:0; m_iSelectedOption[0][GO_MARVELOUS] = PREFSMAN->m_bMarvelousTiming ? 1:0; m_iSelectedOption[0][GO_PICK_EXTRA_STAGE] = PREFSMAN->m_bPickExtraStage? 1:0; + m_iSelectedOption[0][GO_UNLOCK_SYSTEM] = PREFSMAN->m_bUseUnlockSystem? 1:0; } void ScreenGameplayOptions::ExportOptions() @@ -76,6 +79,7 @@ void ScreenGameplayOptions::ExportOptions() PREFSMAN->m_bEasterEggs = m_iSelectedOption[0][GO_EASTER_EGGS] == 1; PREFSMAN->m_bMarvelousTiming = m_iSelectedOption[0][GO_MARVELOUS] == 1; PREFSMAN->m_bPickExtraStage = m_iSelectedOption[0][GO_PICK_EXTRA_STAGE] == 1; + PREFSMAN->m_bUseUnlockSystem = m_iSelectedOption[0][GO_UNLOCK_SYSTEM] == 1; } void ScreenGameplayOptions::GoToPrevState() diff --git a/stepmania/src/ScreenUnlock.cpp b/stepmania/src/ScreenUnlock.cpp new file mode 100644 index 0000000000..a7876aef94 --- /dev/null +++ b/stepmania/src/ScreenUnlock.cpp @@ -0,0 +1,32 @@ +#include "global.h" +#include "PrefsManager.h" +#include "ScreenUnlock.h" +#include "ThemeManager.h" +#include "GameState.h" +#include "RageLog.h" + +ScreenUnlock::ScreenUnlock() : ScreenAttract("ScreenUnlock") +{ + LOG->Trace("ScreenUnlock::ScreenUnlock()"); + PointsUntilNextUnlock.LoadFromFont( THEME->GetPathToF("Common normal") ); + PointsUntilNextUnlock.SetHorizAlign( Actor::align_left ); + + CString sDP = ssprintf( "%f", GAMESTATE->UnlockingSys.NumPointsUntilNextUnlock() ); + + // Remove the decimal + if( sDP.Find(".",1) > 0 ) + { + sDP = sDP.Left(sDP.Find(".",1)); + } + + // No negative numbers + if( sDP.Left(1) == "-" ) + { + sDP = "*"; + }; + + PointsUntilNextUnlock.SetText( sDP ); + PointsUntilNextUnlock.SetZoom( 3 ); + PointsUntilNextUnlock.SetXY( 10, 370 ); + this->AddChild( &PointsUntilNextUnlock ); +} \ No newline at end of file diff --git a/stepmania/src/ScreenUnlock.h b/stepmania/src/ScreenUnlock.h index 8a3012943e..fe028f479c 100644 --- a/stepmania/src/ScreenUnlock.h +++ b/stepmania/src/ScreenUnlock.h @@ -8,15 +8,18 @@ Chris Danford ----------------------------------------------------------------------------- */ - #include "ScreenAttract.h" +#include "GameConstantsAndTypes.h" // for NUM_RANKING_LINES +#include "Style.h" + + +class Course; class ScreenUnlock : public ScreenAttract { public: - ScreenUnlock() : ScreenAttract("ScreenUnlock") { }; -}; - - - + ScreenUnlock(); +protected: + BitmapText PointsUntilNextUnlock; +}; \ No newline at end of file diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 442d291470..1f5498531a 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -83,6 +83,7 @@ void SortBackgroundChangesArray( vector &arrayBackgroundChange ////////////////////////////// Song::Song() { + m_bIsLocked = false; m_bChangedSinceSave = false; m_fBeat0OffsetInSeconds = 0; m_fMusicSampleStartSeconds = -1; diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 03b3c43f8b..63d1b41be8 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -347,6 +347,9 @@ int main(int argc, char* argv[]) "(Advanced: To allow use of the software renderer, set 'AllowSoftwareRenderer=1' " "in StepMania.ini)" ); + /* Load the unlocks into memory */ + GAMESTATE->UnlockingSys.LoadFromDATFile("Data/Unlocks.dat"); + /* Run the main loop. */ GameLoop(); diff --git a/stepmania/src/UnlockSystem.cpp b/stepmania/src/UnlockSystem.cpp new file mode 100644 index 0000000000..299aefc319 --- /dev/null +++ b/stepmania/src/UnlockSystem.cpp @@ -0,0 +1,133 @@ +/* +----------------------------------------------------------------------------- + Class: UnlockSystem + + Desc: See header. + + Copyright (c) 2001-2003 by the person(s) listed below. All rights reserved. + Kevin Slaughter +----------------------------------------------------------------------------- +*/ + +#include "global.h" +#include "PrefsManager.h" +#include "RageLog.h" +#include "RageException.h" +#include "RageUtil.h" +#include "UnlockSystem.h" + +#include +#include +using namespace std; + +#define POINTS_ACCUMULATED_BEFORE_LAST_ROUND // Load from file here + +UnlockSystem::UnlockSystem() +{ +} + + +bool UnlockSystem::SongIsLocked( CString sSongName ) +{ + sSongName.MakeUpper(); //Avoid case-sensitive problems + for( unsigned i=0; im_fDancePointsAccumulated >= m_SongEntries[i].m_fDancePointsRequired ) { LOG->Trace(" *This song is UNLOCKED"); return false; } + else { LOG->Trace(" *This song is LOCKED"); return true; }; + } + else { continue; }; + } + + LOG->Trace( " *This song is UNLOCKED (wasn't locked in the first place)" ); + return false; +} + + + + + + + + +static int CompareSongEntries(const SongEntry &se1, const SongEntry &se2) +{ + return se1.m_fDancePointsRequired < se2.m_fDancePointsRequired; +} +void UnlockSystem::SortSongEntriesArray() +{ + sort( m_SongEntries.begin(), m_SongEntries.end(), CompareSongEntries ); +} + + + + + + + + +bool UnlockSystem::LoadFromDATFile( CString sPath ) +{ + LOG->Trace( "\n\n\n\nUnlockSystem::LoadFromDATFile(%s)", sPath.c_str() ); + + ifstream input(sPath); + if(input.bad()) + { + LOG->Warn( "Error opening file '%s' for reading.", sPath.c_str() ); + return false; + } + + string line; + m_SongEntries.clear(); + + while(input.good() && getline(input, line)) + { + if(!line.compare(0, 2, "//")) //Check for comments + continue; + + /* "[data1] data2". Ignore whitespace at the beginning of the line. */ + static Regex x("^ *\\[([^]]+)\\] *(.*)$"); + + vector matches; + if(!x.Compare(line, matches)) + continue; + + CString &sValueName = matches[0]; + CString &sValueData = matches[1]; + StripCrnl(sValueData); + + // Handle our data + if( 0==stricmp(sValueName,"DP") ) // This means the DancePoints value is coming up + { + float DP; + CString SongName; + DP = (float)atof( sValueData.Left(sValueData.Find("|",1)) ); + SongName = (CString)sValueData.Right( sValueData.GetLength() - (sValueData.Find("|",1)+1) ); + SongName.MakeUpper(); // Avoid case-sensitive problems + + SongEntry SE; + SE.m_fDancePointsRequired = DP; + SE.m_sSongName = SongName.c_str(); + m_SongEntries.push_back( SE ); + continue; + } + } + return true; +} + +float UnlockSystem::NumPointsUntilNextUnlock() +{ + float fSmallestPoints; + fSmallestPoints = m_SongEntries[0].m_fDancePointsRequired; + for( unsigned a=0; a= fSmallestPoints ) + { + fSmallestPoints = m_SongEntries[a].m_fDancePointsRequired; + } + } + + float fResults = (fSmallestPoints - PREFSMAN->m_fDancePointsAccumulated); + return fResults; +} \ No newline at end of file diff --git a/stepmania/src/UnlockSystem.h b/stepmania/src/UnlockSystem.h new file mode 100644 index 0000000000..37b9e53de1 --- /dev/null +++ b/stepmania/src/UnlockSystem.h @@ -0,0 +1,37 @@ +#ifndef UNLOCK_SYSTEM_H +#define UNLOCK_SYSTEM_H +/* +----------------------------------------------------------------------------- + Class: UnlockSystem + + Desc: See header. + + Copyright (c) 2001-2003 by the person(s) listed below. All rights reserved. + Kevin Slaughter +----------------------------------------------------------------------------- +*/ +struct SongEntry +{ + float m_fDancePointsRequired; // Ammount of Dance Points needed to unlock this song + CString m_sSongName; /* Name of the song in the DWI/SM file itself.. This allows + for a lot easier compatibility since a lot of people's + song folders are named differantly, song names tend to + be the same in the file.*/ +}; + + + +class UnlockSystem +{ + public: + UnlockSystem(); + float NumPointsUntilNextUnlock(); + bool SongIsLocked( CString sSongName ); + bool LoadFromDATFile( CString sPath ); + bool m_bAllSongsAreUnlocked; // Quick way to check if all songs are unlocked + vector m_SongEntries; // All locked songs are stored here + + private: + void SortSongEntriesArray(); +}; +#endif diff --git a/stepmania/src/song.h b/stepmania/src/song.h index b6d899190d..815446b04c 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -163,6 +163,7 @@ public: bool HasMovieBackground() const; bool HasBGChanges() const; bool HasLyrics() const; + bool m_bIsLocked; vector m_BPMSegments; // this must be sorted before gameplay vector m_StopSegments; // this must be sorted before gameplay