2003-07-09 03:10:01 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "RageLog.h"
|
2003-07-09 05:57:09 +00:00
|
|
|
#include "song.h"
|
2003-07-11 18:08:57 +00:00
|
|
|
#include "Course.h"
|
2003-07-09 03:10:01 +00:00
|
|
|
#include "RageUtil.h"
|
2005-02-21 06:23:57 +00:00
|
|
|
#include "UnlockManager.h"
|
2003-07-09 05:01:37 +00:00
|
|
|
#include "SongManager.h"
|
2003-07-11 18:08:57 +00:00
|
|
|
#include "GameState.h"
|
2004-02-22 08:16:49 +00:00
|
|
|
#include "ProfileManager.h"
|
2005-02-25 01:28:45 +00:00
|
|
|
#include "ThemeManager.h"
|
2005-03-29 00:31:57 +00:00
|
|
|
#include "Foreach.h"
|
2005-04-24 19:41:52 +00:00
|
|
|
#include "Steps.h"
|
2005-03-29 19:10:42 +00:00
|
|
|
#include <float.h>
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
UnlockManager* UNLOCKMAN = NULL; // global and accessable from anywhere in our program
|
2003-09-19 07:02:53 +00:00
|
|
|
|
2005-02-25 01:28:45 +00:00
|
|
|
#define UNLOCK_NAMES THEME->GetMetric ("Unlocks","UnlockNames")
|
|
|
|
|
#define UNLOCK(sLineName) THEME->GetMetric ("Unlocks",ssprintf("Unlock%s",sLineName.c_str()))
|
2003-12-10 09:26:05 +00:00
|
|
|
|
2005-02-21 06:16:52 +00:00
|
|
|
static CString UnlockTypeNames[NUM_UNLOCK_TYPES] =
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2005-02-25 01:28:45 +00:00
|
|
|
"ArcadePoints",
|
|
|
|
|
"DancePoints",
|
|
|
|
|
"SongPoints",
|
|
|
|
|
"ExtraCleared",
|
|
|
|
|
"ExtraFailed",
|
|
|
|
|
"Toasties",
|
|
|
|
|
"StagesCleared"
|
2004-01-24 23:40:40 +00:00
|
|
|
};
|
2005-03-05 21:50:33 +00:00
|
|
|
XToString( UnlockType, NUM_UNLOCK_TYPES );
|
|
|
|
|
StringToX( UnlockType );
|
2003-09-19 07:02:53 +00:00
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
UnlockManager::UnlockManager()
|
2004-01-24 23:40:40 +00:00
|
|
|
{
|
2004-02-21 01:06:35 +00:00
|
|
|
UNLOCKMAN = this;
|
2004-01-25 16:24:34 +00:00
|
|
|
|
2004-02-22 05:16:12 +00:00
|
|
|
Load();
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
void UnlockManager::UnlockSong( const Song *song )
|
2003-07-09 11:38:50 +00:00
|
|
|
{
|
2004-01-25 16:24:34 +00:00
|
|
|
const UnlockEntry *p = FindSong( song );
|
2004-01-24 19:39:18 +00:00
|
|
|
if( !p )
|
2003-07-18 08:04:47 +00:00
|
|
|
return; // does not exist
|
2004-01-25 16:24:34 +00:00
|
|
|
if( p->m_iCode == -1 )
|
|
|
|
|
return;
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2004-01-25 16:24:34 +00:00
|
|
|
UnlockCode( p->m_iCode );
|
2003-07-09 11:38:50 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-24 00:07:12 +00:00
|
|
|
int UnlockManager::FindCode( const CString &sName ) const
|
|
|
|
|
{
|
|
|
|
|
const UnlockEntry *pEntry = NULL;
|
|
|
|
|
|
|
|
|
|
const Song *pSong = SONGMAN->FindSong( sName );
|
|
|
|
|
if( pSong != NULL )
|
|
|
|
|
pEntry = FindSong( pSong );
|
|
|
|
|
|
|
|
|
|
const Course *pCourse = SONGMAN->FindCourse( sName );
|
|
|
|
|
if( pCourse != NULL )
|
|
|
|
|
pEntry = FindCourse( pCourse );
|
|
|
|
|
|
|
|
|
|
if( pEntry == NULL )
|
|
|
|
|
pEntry = FindModifier( sName );
|
|
|
|
|
|
|
|
|
|
if( pEntry == NULL )
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn( "Couldn't find locked entry \"%s\"", sName.c_str() );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pEntry->m_iCode;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
bool UnlockManager::CourseIsLocked( const Course *course ) const
|
2003-07-10 11:24:16 +00:00
|
|
|
{
|
2003-07-18 08:04:47 +00:00
|
|
|
if( !PREFSMAN->m_bUseUnlockSystem )
|
|
|
|
|
return false;
|
|
|
|
|
|
2004-02-22 21:25:22 +00:00
|
|
|
const UnlockEntry *p = FindCourse( course );
|
2004-01-24 19:39:18 +00:00
|
|
|
if( p == NULL )
|
|
|
|
|
return false;
|
2003-07-10 11:24:16 +00:00
|
|
|
|
2004-01-25 16:24:34 +00:00
|
|
|
return p->IsLocked();
|
2003-07-10 11:24:16 +00:00
|
|
|
}
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
bool UnlockManager::SongIsLocked( const Song *song ) const
|
2003-07-09 04:46:24 +00:00
|
|
|
{
|
2003-07-18 08:04:47 +00:00
|
|
|
if( !PREFSMAN->m_bUseUnlockSystem )
|
|
|
|
|
return false;
|
|
|
|
|
|
2004-02-22 21:25:22 +00:00
|
|
|
const UnlockEntry *p = FindSong( song );
|
2003-07-12 20:16:07 +00:00
|
|
|
if( p == NULL )
|
|
|
|
|
return false;
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2004-01-25 16:24:34 +00:00
|
|
|
return p->IsLocked();
|
2003-07-09 04:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
2004-02-26 20:35:46 +00:00
|
|
|
/* Return true if the song is *only* available in roulette. */
|
2005-02-21 06:13:31 +00:00
|
|
|
bool UnlockManager::SongIsRouletteOnly( const Song *song ) const
|
2003-07-09 04:46:24 +00:00
|
|
|
{
|
2004-01-24 22:55:59 +00:00
|
|
|
if( !PREFSMAN->m_bUseUnlockSystem )
|
|
|
|
|
return false;
|
|
|
|
|
|
2004-01-24 19:39:18 +00:00
|
|
|
const UnlockEntry *p = FindSong( song );
|
2005-04-24 19:41:52 +00:00
|
|
|
if( p == NULL )
|
2004-01-25 16:24:34 +00:00
|
|
|
return false;
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2004-01-25 16:24:34 +00:00
|
|
|
/* If the song is locked by a code, and it's a roulette code, honor IsLocked. */
|
2004-02-26 20:35:46 +00:00
|
|
|
if( p->m_iCode == -1 || m_RouletteCodes.find( p->m_iCode ) == m_RouletteCodes.end() )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return p->IsLocked();
|
2003-07-09 04:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-24 19:41:52 +00:00
|
|
|
bool UnlockManager::StepsIsLocked( const Song *pSong, const Steps *pSteps ) const
|
|
|
|
|
{
|
|
|
|
|
if( !PREFSMAN->m_bUseUnlockSystem )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const UnlockEntry *p = FindSteps( pSong, pSteps );
|
|
|
|
|
if( p == NULL )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return p->IsLocked();
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-29 01:44:36 +00:00
|
|
|
bool UnlockManager::ModifierIsLocked( const CString &sOneMod ) const
|
2003-07-10 14:44:13 +00:00
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
if( !PREFSMAN->m_bUseUnlockSystem )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const UnlockEntry *p = FindModifier( sOneMod );
|
|
|
|
|
if( p == NULL )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return p->IsLocked();
|
|
|
|
|
}
|
2003-07-10 14:44:13 +00:00
|
|
|
|
2005-04-24 19:41:52 +00:00
|
|
|
const UnlockEntry *UnlockManager::FindSong( const Song *pSong ) const
|
2005-03-29 01:44:36 +00:00
|
|
|
{
|
|
|
|
|
FOREACH_CONST( UnlockEntry, m_UnlockEntries, e )
|
2005-04-24 19:41:52 +00:00
|
|
|
if( e->m_pSong == pSong && e->m_dc == DIFFICULTY_INVALID )
|
2005-03-29 01:44:36 +00:00
|
|
|
return &(*e);
|
2003-07-10 14:44:13 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-24 19:41:52 +00:00
|
|
|
const UnlockEntry *UnlockManager::FindSteps( const Song *pSong, const Steps *pSteps ) const
|
2003-07-10 11:24:16 +00:00
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
FOREACH_CONST( UnlockEntry, m_UnlockEntries, e )
|
2005-04-24 19:41:52 +00:00
|
|
|
if( e->m_pSong == pSong && e->m_dc == pSteps->GetDifficulty() )
|
2005-03-29 01:44:36 +00:00
|
|
|
return &(*e);
|
2003-07-10 11:24:16 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
const UnlockEntry *UnlockManager::FindCourse( const Course *pCourse ) const
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
FOREACH_CONST( UnlockEntry, m_UnlockEntries, e )
|
|
|
|
|
if( e->m_pCourse == pCourse )
|
|
|
|
|
return &(*e);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2003-07-09 13:54:23 +00:00
|
|
|
|
2005-03-29 01:44:36 +00:00
|
|
|
const UnlockEntry *UnlockManager::FindModifier( const CString &sOneMod ) const
|
|
|
|
|
{
|
|
|
|
|
FOREACH_CONST( UnlockEntry, m_UnlockEntries, e )
|
2005-04-24 19:41:52 +00:00
|
|
|
if( e->m_cmd.GetArg(1).s.CompareNoCase(sOneMod) == 0 )
|
2005-03-29 01:44:36 +00:00
|
|
|
return &(*e);
|
2003-07-09 05:01:37 +00:00
|
|
|
return NULL;
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2004-02-22 08:16:49 +00:00
|
|
|
static float GetArcadePoints( const Profile *pProfile )
|
|
|
|
|
{
|
|
|
|
|
float fAP = 0;
|
|
|
|
|
|
|
|
|
|
FOREACH_Grade(g)
|
|
|
|
|
{
|
|
|
|
|
switch(g)
|
|
|
|
|
{
|
2005-03-31 06:14:28 +00:00
|
|
|
case GRADE_TIER01:
|
|
|
|
|
case GRADE_TIER02: fAP += 9 * pProfile->m_iNumStagesPassedByGrade[g]; break;
|
2004-08-30 06:07:14 +00:00
|
|
|
default: fAP += 1 * pProfile->m_iNumStagesPassedByGrade[g]; break;
|
2004-02-22 08:16:49 +00:00
|
|
|
|
|
|
|
|
case GRADE_FAILED:
|
|
|
|
|
case GRADE_NO_DATA:
|
|
|
|
|
; // no points
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FOREACH_PlayMode(pm)
|
|
|
|
|
{
|
|
|
|
|
switch(pm)
|
|
|
|
|
{
|
|
|
|
|
case PLAY_MODE_NONSTOP:
|
|
|
|
|
case PLAY_MODE_ONI:
|
|
|
|
|
case PLAY_MODE_ENDLESS:
|
|
|
|
|
fAP += pProfile->m_iNumSongsPlayedByPlayMode[pm];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fAP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static float GetSongPoints( const Profile *pProfile )
|
|
|
|
|
{
|
|
|
|
|
float fSP = 0;
|
|
|
|
|
|
|
|
|
|
FOREACH_Grade(g)
|
|
|
|
|
{
|
|
|
|
|
switch( g )
|
|
|
|
|
{
|
2005-03-31 06:14:28 +00:00
|
|
|
case GRADE_TIER01:/*AAAA*/ fSP += 20 * pProfile->m_iNumStagesPassedByGrade[g]; break;
|
|
|
|
|
case GRADE_TIER02:/*AAA*/ fSP += 10* pProfile->m_iNumStagesPassedByGrade[g]; break;
|
|
|
|
|
case GRADE_TIER03:/*AA*/ fSP += 5* pProfile->m_iNumStagesPassedByGrade[g]; break;
|
|
|
|
|
case GRADE_TIER04:/*A*/ fSP += 4* pProfile->m_iNumStagesPassedByGrade[g]; break;
|
|
|
|
|
case GRADE_TIER05:/*B*/ fSP += 3* pProfile->m_iNumStagesPassedByGrade[g]; break;
|
|
|
|
|
case GRADE_TIER06:/*C*/ fSP += 2* pProfile->m_iNumStagesPassedByGrade[g]; break;
|
|
|
|
|
case GRADE_TIER07:/*D*/ fSP += 1* pProfile->m_iNumStagesPassedByGrade[g]; break;
|
2004-02-22 08:16:49 +00:00
|
|
|
case GRADE_FAILED:
|
|
|
|
|
case GRADE_NO_DATA:
|
|
|
|
|
; // no points
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FOREACH_PlayMode(pm)
|
|
|
|
|
{
|
|
|
|
|
switch(pm)
|
|
|
|
|
{
|
|
|
|
|
case PLAY_MODE_NONSTOP:
|
|
|
|
|
case PLAY_MODE_ONI:
|
|
|
|
|
case PLAY_MODE_ENDLESS:
|
|
|
|
|
fSP += pProfile->m_iNumSongsPlayedByPlayMode[pm];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fSP;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
void UnlockManager::GetPoints( const Profile *pProfile, float fScores[NUM_UNLOCK_TYPES] ) const
|
2004-02-22 08:16:49 +00:00
|
|
|
{
|
|
|
|
|
fScores[UNLOCK_ARCADE_POINTS] = GetArcadePoints( pProfile );
|
|
|
|
|
fScores[UNLOCK_SONG_POINTS] = GetSongPoints( pProfile );
|
|
|
|
|
fScores[UNLOCK_DANCE_POINTS] = (float) pProfile->m_iTotalDancePoints;
|
|
|
|
|
fScores[UNLOCK_CLEARED] = (float) pProfile->GetTotalNumSongsPassed();
|
|
|
|
|
}
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2005-04-30 04:11:55 +00:00
|
|
|
/* Return true if all songs and/or courses referenced by an unlock are available. */
|
|
|
|
|
bool UnlockEntry::IsValid() const
|
|
|
|
|
{
|
|
|
|
|
switch( m_Type )
|
|
|
|
|
{
|
|
|
|
|
case TYPE_SONG:
|
|
|
|
|
return m_pSong != NULL;
|
|
|
|
|
|
|
|
|
|
case TYPE_STEPS:
|
|
|
|
|
return m_pSong != NULL && m_dc != DIFFICULTY_INVALID;
|
|
|
|
|
|
|
|
|
|
case TYPE_COURSE:
|
|
|
|
|
return m_pCourse != NULL;
|
|
|
|
|
|
|
|
|
|
case TYPE_MODIFIER:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
WARN( ssprintf("%i", m_Type) );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-25 16:24:34 +00:00
|
|
|
bool UnlockEntry::IsLocked() const
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2004-02-22 08:16:49 +00:00
|
|
|
float fScores[NUM_UNLOCK_TYPES];
|
|
|
|
|
UNLOCKMAN->GetPoints( PROFILEMAN->GetMachineProfile(), fScores );
|
|
|
|
|
|
2004-01-24 23:40:40 +00:00
|
|
|
for( int i = 0; i < NUM_UNLOCK_TYPES; ++i )
|
2004-02-22 08:16:49 +00:00
|
|
|
if( m_fRequired[i] && fScores[i] >= m_fRequired[i] )
|
2004-01-25 16:24:34 +00:00
|
|
|
return false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2004-02-22 08:16:49 +00:00
|
|
|
if( m_iCode != -1 && PROFILEMAN->GetMachineProfile()->m_UnlockedSongs.find(m_iCode) != PROFILEMAN->GetMachineProfile()->m_UnlockedSongs.end() )
|
2004-01-25 16:24:34 +00:00
|
|
|
return false;
|
2003-07-09 11:38:50 +00:00
|
|
|
|
2004-01-25 16:24:34 +00:00
|
|
|
return true;
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-25 01:28:45 +00:00
|
|
|
void UnlockManager::Load()
|
2004-02-22 05:16:12 +00:00
|
|
|
{
|
2005-02-21 06:13:31 +00:00
|
|
|
LOG->Trace( "UnlockManager::Load()" );
|
2004-02-22 05:16:12 +00:00
|
|
|
|
2005-02-25 01:28:45 +00:00
|
|
|
CStringArray asUnlockNames;
|
|
|
|
|
split( UNLOCK_NAMES, ",", asUnlockNames );
|
|
|
|
|
if( asUnlockNames.empty() )
|
|
|
|
|
return;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2005-02-25 01:28:45 +00:00
|
|
|
for( unsigned i = 0; i < asUnlockNames.size(); ++i )
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2005-02-25 01:28:45 +00:00
|
|
|
const CString &sUnlockName = asUnlockNames[i];
|
|
|
|
|
CString sUnlock = UNLOCK(sUnlockName);
|
2003-07-14 06:36:29 +00:00
|
|
|
|
2005-02-25 01:28:45 +00:00
|
|
|
Commands vCommands;
|
|
|
|
|
ParseCommands( sUnlock, vCommands );
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2003-08-11 20:57:57 +00:00
|
|
|
UnlockEntry current;
|
2005-02-25 01:28:45 +00:00
|
|
|
bool bRoulette = false;
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2005-02-25 01:28:45 +00:00
|
|
|
for( unsigned j = 0; j < vCommands.v.size(); ++j )
|
2003-07-09 03:10:01 +00:00
|
|
|
{
|
2005-02-25 01:28:45 +00:00
|
|
|
const Command &cmd = vCommands.v[j];
|
2005-03-29 01:44:36 +00:00
|
|
|
CString sName = cmd.GetName();
|
|
|
|
|
|
|
|
|
|
if( sName == "song" )
|
|
|
|
|
{
|
|
|
|
|
current.m_Type = UnlockEntry::TYPE_SONG;
|
2005-04-24 19:41:52 +00:00
|
|
|
current.m_cmd = cmd;
|
|
|
|
|
}
|
|
|
|
|
if( sName == "steps" )
|
|
|
|
|
{
|
|
|
|
|
current.m_Type = UnlockEntry::TYPE_STEPS;
|
|
|
|
|
current.m_cmd = cmd;
|
2005-03-29 01:44:36 +00:00
|
|
|
}
|
|
|
|
|
if( sName == "course" )
|
|
|
|
|
{
|
|
|
|
|
current.m_Type = UnlockEntry::TYPE_COURSE;
|
2005-04-24 19:41:52 +00:00
|
|
|
current.m_cmd = cmd;
|
2005-03-29 01:44:36 +00:00
|
|
|
}
|
2005-03-29 02:02:11 +00:00
|
|
|
if( sName == "mod" )
|
2005-03-29 01:44:36 +00:00
|
|
|
{
|
|
|
|
|
current.m_Type = UnlockEntry::TYPE_MODIFIER;
|
2005-04-24 19:41:52 +00:00
|
|
|
current.m_cmd = cmd;
|
2005-03-29 01:44:36 +00:00
|
|
|
}
|
|
|
|
|
else if( sName == "code" )
|
2005-02-25 01:46:10 +00:00
|
|
|
{
|
|
|
|
|
// Hack: Lua only has a floating point type, and codes may be big enough
|
|
|
|
|
// that converting them from string to float to int introduces rounding
|
|
|
|
|
// error. Convert directly to int.
|
|
|
|
|
current.m_iCode = atoi( (CString) cmd.GetArg(1) );
|
|
|
|
|
}
|
2005-03-29 01:44:36 +00:00
|
|
|
else if( sName == "roulette" )
|
|
|
|
|
{
|
2005-02-25 01:28:45 +00:00
|
|
|
bRoulette = true;
|
2005-03-29 01:44:36 +00:00
|
|
|
}
|
2005-02-25 01:28:45 +00:00
|
|
|
else
|
2003-07-14 06:36:29 +00:00
|
|
|
{
|
2005-02-25 01:28:45 +00:00
|
|
|
const UnlockType ut = StringToUnlockType( cmd.GetName() );
|
|
|
|
|
if( ut != UNLOCK_INVALID )
|
|
|
|
|
current.m_fRequired[ut] = cmd.GetArg(1);
|
2003-07-14 06:36:29 +00:00
|
|
|
}
|
2003-07-09 14:16:21 +00:00
|
|
|
}
|
2003-07-16 12:58:02 +00:00
|
|
|
|
2005-02-25 01:28:45 +00:00
|
|
|
if( bRoulette )
|
|
|
|
|
m_RouletteCodes.insert( current.m_iCode );
|
|
|
|
|
|
2005-03-29 01:44:36 +00:00
|
|
|
m_UnlockEntries.push_back( current );
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
2003-07-15 00:52:01 +00:00
|
|
|
|
2005-04-24 19:41:52 +00:00
|
|
|
UpdateCachedPointers();
|
2004-02-22 05:16:12 +00:00
|
|
|
|
2005-03-29 01:44:36 +00:00
|
|
|
FOREACH_CONST( UnlockEntry, m_UnlockEntries, e )
|
2003-07-09 11:38:50 +00:00
|
|
|
{
|
2005-04-24 19:41:52 +00:00
|
|
|
CString str = ssprintf( "Unlock: %s; ", join("\n",e->m_cmd.m_vsArgs).c_str() );
|
2005-02-21 06:16:52 +00:00
|
|
|
FOREACH_UnlockType(j)
|
2005-03-29 01:44:36 +00:00
|
|
|
if( e->m_fRequired[j] )
|
|
|
|
|
str += ssprintf( "%s = %f; ", UnlockTypeToString(j).c_str(), e->m_fRequired[j] );
|
2004-02-22 05:16:12 +00:00
|
|
|
|
2005-03-29 01:44:36 +00:00
|
|
|
str += ssprintf( "code = %i ", e->m_iCode );
|
|
|
|
|
str += e->IsLocked()? "locked":"unlocked";
|
|
|
|
|
if( e->m_pSong )
|
2004-08-05 20:15:54 +00:00
|
|
|
str += ( " (found song)" );
|
2005-03-29 01:44:36 +00:00
|
|
|
if( e->m_pCourse )
|
2004-08-05 20:15:54 +00:00
|
|
|
str += ( " (found course)" );
|
2004-08-05 17:50:30 +00:00
|
|
|
LOG->Trace( "%s", str.c_str() );
|
2003-07-09 11:38:50 +00:00
|
|
|
}
|
2003-07-09 03:10:01 +00:00
|
|
|
|
2005-02-25 01:28:45 +00:00
|
|
|
return;
|
2003-07-09 03:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
float UnlockManager::PointsUntilNextUnlock( UnlockType t ) const
|
2003-07-09 06:05:43 +00:00
|
|
|
{
|
2004-02-22 08:16:49 +00:00
|
|
|
float fScores[NUM_UNLOCK_TYPES];
|
|
|
|
|
UNLOCKMAN->GetPoints( PROFILEMAN->GetMachineProfile(), fScores );
|
|
|
|
|
|
2005-03-29 19:10:42 +00:00
|
|
|
float fSmallestPoints = FLT_MAX; // or an arbitrarily large value
|
2005-03-29 01:44:36 +00:00
|
|
|
for( unsigned a=0; a<m_UnlockEntries.size(); a++ )
|
|
|
|
|
if( m_UnlockEntries[a].m_fRequired[t] > fScores[t] )
|
|
|
|
|
fSmallestPoints = min( fSmallestPoints, m_UnlockEntries[a].m_fRequired[t] );
|
2003-07-09 06:05:43 +00:00
|
|
|
|
2005-03-29 19:10:42 +00:00
|
|
|
if( fSmallestPoints == FLT_MAX )
|
2004-01-24 19:39:18 +00:00
|
|
|
return 0; // no match found
|
2004-02-22 08:16:49 +00:00
|
|
|
return fSmallestPoints - fScores[t];
|
2003-07-09 06:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-29 01:44:36 +00:00
|
|
|
/* Update the cached pointers. Only call this when it's likely to have changed,
|
2003-07-18 06:38:05 +00:00
|
|
|
* such as on load, or when a song title changes in the editor. */
|
2005-04-24 19:41:52 +00:00
|
|
|
void UnlockManager::UpdateCachedPointers()
|
2003-07-09 05:01:37 +00:00
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
FOREACH( UnlockEntry, m_UnlockEntries, e )
|
2003-07-18 06:38:05 +00:00
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
switch( e->m_Type )
|
2003-08-11 22:37:46 +00:00
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
case UnlockEntry::TYPE_SONG:
|
2005-04-24 19:41:52 +00:00
|
|
|
e->m_pSong = SONGMAN->FindSong( e->m_cmd.GetArg(1) );
|
2005-03-29 01:44:36 +00:00
|
|
|
if( e->m_pSong == NULL )
|
2005-04-24 19:41:52 +00:00
|
|
|
LOG->Warn( "Unlock: Cannot find song matching \"%s\"", e->m_cmd.GetArg(1).s.c_str() );
|
|
|
|
|
break;
|
|
|
|
|
case UnlockEntry::TYPE_STEPS:
|
|
|
|
|
e->m_pSong = SONGMAN->FindSong( e->m_cmd.GetArg(1) );
|
|
|
|
|
if( e->m_pSong == NULL )
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn( "Unlock: Cannot find song matching \"%s\"", e->m_cmd.GetArg(1).s.c_str() );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e->m_dc = StringToDifficulty( e->m_cmd.GetArg(2) );
|
|
|
|
|
if( e->m_dc == DIFFICULTY_INVALID )
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn( "Unlock: Invalid difficulty \"%s\"", e->m_cmd.GetArg(2).s.c_str() );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-29 01:44:36 +00:00
|
|
|
break;
|
|
|
|
|
case UnlockEntry::TYPE_COURSE:
|
2005-04-24 19:41:52 +00:00
|
|
|
e->m_pCourse = SONGMAN->FindCourse( e->m_cmd.GetArg(1) );
|
2005-03-29 01:44:36 +00:00
|
|
|
if( e->m_pCourse == NULL )
|
2005-04-24 19:41:52 +00:00
|
|
|
LOG->Warn( "Unlock: Cannot find course matching \"%s\"", e->m_cmd.GetArg(1).s.c_str() );
|
2005-03-29 01:44:36 +00:00
|
|
|
break;
|
|
|
|
|
case UnlockEntry::TYPE_MODIFIER:
|
|
|
|
|
// nothing to cache
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
2003-08-11 22:37:46 +00:00
|
|
|
}
|
2003-07-18 06:38:05 +00:00
|
|
|
}
|
2003-07-09 05:01:37 +00:00
|
|
|
}
|
2003-07-09 13:54:23 +00:00
|
|
|
|
2003-07-11 09:35:28 +00:00
|
|
|
|
2004-01-25 16:24:34 +00:00
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
void UnlockManager::UnlockCode( int num )
|
2004-01-25 16:24:34 +00:00
|
|
|
{
|
2004-02-22 08:16:49 +00:00
|
|
|
FOREACH_PlayerNumber( pn )
|
|
|
|
|
if( PROFILEMAN->IsUsingProfile(pn) )
|
|
|
|
|
PROFILEMAN->GetProfile(pn)->m_UnlockedSongs.insert( num );
|
|
|
|
|
|
|
|
|
|
PROFILEMAN->GetMachineProfile()->m_UnlockedSongs.insert( num );
|
2003-07-11 18:08:57 +00:00
|
|
|
}
|
2003-07-25 00:03:05 +00:00
|
|
|
|
2005-02-24 22:34:54 +00:00
|
|
|
void UnlockManager::PreferUnlockCode( int iCode )
|
|
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
for( unsigned i = 0; i < m_UnlockEntries.size(); ++i )
|
2005-02-24 22:34:54 +00:00
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
UnlockEntry &pEntry = m_UnlockEntries[i];
|
2005-02-24 22:34:54 +00:00
|
|
|
if( pEntry.m_iCode != iCode )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if( pEntry.m_pSong != NULL )
|
|
|
|
|
GAMESTATE->m_pPreferredSong = pEntry.m_pSong;
|
|
|
|
|
if( pEntry.m_pCourse != NULL )
|
|
|
|
|
GAMESTATE->m_pPreferredCourse = pEntry.m_pCourse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-21 06:13:31 +00:00
|
|
|
int UnlockManager::GetNumUnlocks() const
|
2003-07-25 00:03:05 +00:00
|
|
|
{
|
2005-03-29 01:44:36 +00:00
|
|
|
return m_UnlockEntries.size();
|
2003-08-10 03:23:17 +00:00
|
|
|
}
|
2004-06-08 01:24:17 +00:00
|
|
|
|
2005-04-30 04:11:55 +00:00
|
|
|
void UnlockManager::GetUnlocksByType( UnlockEntry::Type t, vector<UnlockEntry *> &apEntries )
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i = 0; i < m_UnlockEntries.size(); ++i )
|
|
|
|
|
if( m_UnlockEntries[i].IsValid() && m_UnlockEntries[i].m_Type == t )
|
|
|
|
|
apEntries.push_back( &m_UnlockEntries[i] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnlockManager::GetSongsUnlockedByCode( vector<Song *> &apSongsOut, int iCode )
|
|
|
|
|
{
|
|
|
|
|
vector<UnlockEntry *> apEntries;
|
|
|
|
|
GetUnlocksByType( UnlockEntry::TYPE_SONG, apEntries );
|
|
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < apEntries.size(); ++i )
|
|
|
|
|
if( apEntries[i]->m_iCode == iCode )
|
|
|
|
|
apSongsOut.push_back( apEntries[i]->m_pSong );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnlockManager::GetStepsUnlockedByCode( vector<Song *> &apSongsOut, vector<Difficulty> &apDifficultyOut, int iCode )
|
|
|
|
|
{
|
|
|
|
|
vector<UnlockEntry *> apEntries;
|
|
|
|
|
GetUnlocksByType( UnlockEntry::TYPE_STEPS, apEntries );
|
|
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < apEntries.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
if( apEntries[i]->m_iCode == iCode )
|
|
|
|
|
{
|
|
|
|
|
apSongsOut.push_back( apEntries[i]->m_pSong );
|
|
|
|
|
apDifficultyOut.push_back( apEntries[i]->m_dc );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-21 06:51:04 +00:00
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
class LunaUnlockManager: public Luna<T>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
LunaUnlockManager() { LUA->Register( Register ); }
|
|
|
|
|
|
2005-04-24 01:25:51 +00:00
|
|
|
static int FindCode( T* p, lua_State *L ) { CString sName = SArg(1); int i = p->FindCode(sName); if( i == -1 ) lua_pushnil(L); else lua_pushnumber(L, i); return 1; }
|
2005-02-21 06:51:04 +00:00
|
|
|
static int UnlockCode( T* p, lua_State *L ) { int iCode = IArg(1); p->UnlockCode(iCode); return 0; }
|
2005-02-24 22:34:54 +00:00
|
|
|
static int PreferUnlockCode( T* p, lua_State *L ) { int iCode = IArg(1); p->PreferUnlockCode(iCode); return 0; }
|
2005-04-30 04:11:55 +00:00
|
|
|
static int GetSongsUnlockedByCode( T* p, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
vector<Song *> apSongs;
|
|
|
|
|
UNLOCKMAN->GetSongsUnlockedByCode( apSongs, IArg(1) );
|
|
|
|
|
LuaHelpers::CreateTableFromArray( apSongs, L );
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int GetStepsUnlockedByCode( T* p, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
// Return the song each steps are associated with, too.
|
|
|
|
|
vector<Song *> apSongs;
|
|
|
|
|
vector<Difficulty> apDifficulty;
|
|
|
|
|
UNLOCKMAN->GetStepsUnlockedByCode( apSongs, apDifficulty, IArg(1) );
|
|
|
|
|
LuaHelpers::CreateTableFromArray( apSongs, L );
|
|
|
|
|
LuaHelpers::CreateTableFromArray( apDifficulty, L );
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
2005-02-21 06:51:04 +00:00
|
|
|
|
|
|
|
|
static void Register(lua_State *L)
|
|
|
|
|
{
|
2005-04-24 00:07:12 +00:00
|
|
|
ADD_METHOD( FindCode )
|
2005-02-21 06:51:04 +00:00
|
|
|
ADD_METHOD( UnlockCode )
|
2005-02-24 22:34:54 +00:00
|
|
|
ADD_METHOD( PreferUnlockCode )
|
2005-04-30 04:11:55 +00:00
|
|
|
ADD_METHOD( GetSongsUnlockedByCode )
|
|
|
|
|
ADD_METHOD( GetStepsUnlockedByCode )
|
2005-02-21 06:51:04 +00:00
|
|
|
Luna<T>::Register( L );
|
|
|
|
|
|
|
|
|
|
// Add global singleton if constructed already. If it's not constructed yet,
|
|
|
|
|
// then we'll register it later when we reinit Lua just before
|
|
|
|
|
// initializing the display.
|
|
|
|
|
if( UNLOCKMAN )
|
|
|
|
|
{
|
|
|
|
|
lua_pushstring(L, "UNLOCKMAN");
|
|
|
|
|
UNLOCKMAN->PushSelf( LUA->L );
|
|
|
|
|
lua_settable(L, LUA_GLOBALSINDEX);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_CLASS( UnlockManager )
|
|
|
|
|
|
2004-06-08 01:24:17 +00:00
|
|
|
/*
|
|
|
|
|
* (c) 2001-2004 Kevin Slaughter, Andrew Wong, Glenn Maynard
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|