2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2003-01-24 02:43:07 +00:00
|
|
|
#include "StageStats.h"
|
2003-02-03 05:53:59 +00:00
|
|
|
#include "GameState.h"
|
2004-08-30 04:09:23 +00:00
|
|
|
#include "Foreach.h"
|
|
|
|
|
#include "Steps.h"
|
2004-08-30 05:08:08 +00:00
|
|
|
#include "song.h"
|
2005-09-11 01:44:13 +00:00
|
|
|
#include "RageLog.h"
|
|
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "PlayerState.h"
|
|
|
|
|
#include "Style.h"
|
|
|
|
|
#include "Profile.h"
|
|
|
|
|
#include "ProfileManager.h"
|
2003-01-24 02:43:07 +00:00
|
|
|
|
2005-09-10 23:47:10 +00:00
|
|
|
/*
|
|
|
|
|
* Arcade: for the current stage (one song).
|
|
|
|
|
* Nonstop/Oni/Endless: for current course (which usually contains multiple songs)
|
|
|
|
|
*/
|
|
|
|
|
|
2005-04-04 12:45:35 +00:00
|
|
|
StageStats::StageStats()
|
2004-12-20 10:47:41 +00:00
|
|
|
{
|
2006-09-26 20:32:41 +00:00
|
|
|
playMode = PlayMode_Invalid;
|
2004-12-20 10:47:41 +00:00
|
|
|
pStyle = NULL;
|
2005-04-20 06:13:06 +00:00
|
|
|
vpPlayedSongs.clear();
|
|
|
|
|
vpPossibleSongs.clear();
|
2006-10-07 04:39:48 +00:00
|
|
|
StageType = Stage_Invalid;
|
2005-10-01 00:18:13 +00:00
|
|
|
bGaveUp = false;
|
|
|
|
|
bUsedAutoplay = false;
|
2004-12-20 10:47:41 +00:00
|
|
|
fGameplaySeconds = 0;
|
2005-04-23 02:50:26 +00:00
|
|
|
fStepsSeconds = 0;
|
2004-12-20 10:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-04 12:45:35 +00:00
|
|
|
void StageStats::Init()
|
|
|
|
|
{
|
|
|
|
|
*this = StageStats();
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-20 10:47:41 +00:00
|
|
|
void StageStats::AssertValid( PlayerNumber pn ) const
|
|
|
|
|
{
|
2005-04-20 06:13:06 +00:00
|
|
|
ASSERT( vpPlayedSongs.size() != 0 );
|
|
|
|
|
ASSERT( vpPossibleSongs.size() != 0 );
|
|
|
|
|
if( vpPlayedSongs[0] )
|
2005-05-23 00:38:09 +00:00
|
|
|
CHECKPOINT_M( vpPlayedSongs[0]->GetTranslitFullTitle() );
|
2005-04-20 06:13:06 +00:00
|
|
|
ASSERT( m_player[pn].vpPlayedSteps.size() != 0 );
|
|
|
|
|
ASSERT( m_player[pn].vpPlayedSteps[0] );
|
2006-01-07 04:11:29 +00:00
|
|
|
ASSERT_M( playMode < NUM_PlayMode, ssprintf("playmode %i", playMode) );
|
2004-12-20 10:47:41 +00:00
|
|
|
ASSERT( pStyle != NULL );
|
2006-01-07 04:11:29 +00:00
|
|
|
ASSERT_M( m_player[pn].vpPlayedSteps[0]->GetDifficulty() < NUM_Difficulty, ssprintf("difficulty %i", m_player[pn].vpPlayedSteps[0]->GetDifficulty()) );
|
2005-04-20 06:13:06 +00:00
|
|
|
ASSERT( vpPlayedSongs.size() == m_player[pn].vpPlayedSteps.size() );
|
|
|
|
|
ASSERT( vpPossibleSongs.size() == m_player[pn].vpPossibleSteps.size() );
|
2004-12-20 10:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
2005-08-23 20:49:30 +00:00
|
|
|
void StageStats::AssertValid( MultiPlayer pn ) const
|
|
|
|
|
{
|
|
|
|
|
ASSERT( vpPlayedSongs.size() != 0 );
|
|
|
|
|
ASSERT( vpPossibleSongs.size() != 0 );
|
|
|
|
|
if( vpPlayedSongs[0] )
|
|
|
|
|
CHECKPOINT_M( vpPlayedSongs[0]->GetTranslitFullTitle() );
|
|
|
|
|
ASSERT( m_multiPlayer[pn].vpPlayedSteps.size() != 0 );
|
|
|
|
|
ASSERT( m_multiPlayer[pn].vpPlayedSteps[0] );
|
2006-01-07 04:11:29 +00:00
|
|
|
ASSERT_M( playMode < NUM_PlayMode, ssprintf("playmode %i", playMode) );
|
2005-08-23 20:49:30 +00:00
|
|
|
ASSERT( pStyle != NULL );
|
2006-01-07 04:11:29 +00:00
|
|
|
ASSERT_M( m_player[pn].vpPlayedSteps[0]->GetDifficulty() < NUM_Difficulty, ssprintf("difficulty %i", m_player[pn].vpPlayedSteps[0]->GetDifficulty()) );
|
2005-08-23 20:49:30 +00:00
|
|
|
ASSERT( vpPlayedSongs.size() == m_player[pn].vpPlayedSteps.size() );
|
|
|
|
|
ASSERT( vpPossibleSongs.size() == m_player[pn].vpPossibleSteps.size() );
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-20 10:47:41 +00:00
|
|
|
|
|
|
|
|
int StageStats::GetAverageMeter( PlayerNumber pn ) const
|
|
|
|
|
{
|
2005-04-20 06:13:06 +00:00
|
|
|
AssertValid( pn );
|
|
|
|
|
|
|
|
|
|
// TODO: This isn't correct for courses.
|
|
|
|
|
|
2004-12-20 10:47:41 +00:00
|
|
|
int iTotalMeter = 0;
|
|
|
|
|
|
2005-04-20 06:13:06 +00:00
|
|
|
for( unsigned i=0; i<vpPlayedSongs.size(); i++ )
|
2004-12-20 10:47:41 +00:00
|
|
|
{
|
2005-04-20 06:13:06 +00:00
|
|
|
const Steps* pSteps = m_player[pn].vpPlayedSteps[i];
|
2005-01-10 18:55:49 +00:00
|
|
|
iTotalMeter += pSteps->GetMeter();
|
2004-12-20 10:47:41 +00:00
|
|
|
}
|
2005-04-20 06:13:06 +00:00
|
|
|
return iTotalMeter / vpPlayedSongs.size(); // round down
|
2004-12-20 10:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StageStats::AddStats( const StageStats& other )
|
|
|
|
|
{
|
2005-04-20 06:13:06 +00:00
|
|
|
ASSERT( !other.vpPlayedSongs.empty() );
|
|
|
|
|
FOREACH_CONST( Song*, other.vpPlayedSongs, s )
|
|
|
|
|
vpPlayedSongs.push_back( *s );
|
|
|
|
|
FOREACH_CONST( Song*, other.vpPossibleSongs, s )
|
|
|
|
|
vpPossibleSongs.push_back( *s );
|
2006-10-07 04:39:48 +00:00
|
|
|
StageType = Stage_Invalid; // meaningless
|
2005-10-01 00:18:13 +00:00
|
|
|
|
|
|
|
|
bGaveUp |= other.bGaveUp;
|
|
|
|
|
bUsedAutoplay |= other.bUsedAutoplay;
|
2004-12-20 10:47:41 +00:00
|
|
|
|
|
|
|
|
fGameplaySeconds += other.fGameplaySeconds;
|
2005-04-23 02:50:26 +00:00
|
|
|
fStepsSeconds += other.fStepsSeconds;
|
2004-12-20 10:47:41 +00:00
|
|
|
|
2005-08-26 20:57:06 +00:00
|
|
|
FOREACH_EnabledPlayer( p )
|
2004-12-20 10:47:41 +00:00
|
|
|
m_player[p].AddStats( other.m_player[p] );
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-06 00:33:09 +00:00
|
|
|
bool StageStats::OnePassed() const
|
|
|
|
|
{
|
2005-08-26 20:57:06 +00:00
|
|
|
FOREACH_EnabledPlayer( p )
|
2005-04-20 06:13:06 +00:00
|
|
|
if( !m_player[p].bFailed )
|
2003-09-06 00:33:09 +00:00
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-03 23:55:58 +00:00
|
|
|
bool StageStats::AllFailed() const
|
|
|
|
|
{
|
2005-10-01 00:18:13 +00:00
|
|
|
FOREACH_EnabledPlayer( p )
|
|
|
|
|
if( !m_player[p].bFailed )
|
2004-12-20 10:47:41 +00:00
|
|
|
return false;
|
2003-11-03 23:55:58 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-31 20:58:14 +00:00
|
|
|
bool StageStats::AllFailedEarlier() const
|
|
|
|
|
{
|
2005-08-26 20:57:06 +00:00
|
|
|
FOREACH_EnabledPlayer( p )
|
2004-12-20 10:47:41 +00:00
|
|
|
if( !m_player[p].bFailedEarlier )
|
2003-12-31 20:58:14 +00:00
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-23 02:50:26 +00:00
|
|
|
float StageStats::GetTotalPossibleStepsSeconds() const
|
2005-04-20 06:13:06 +00:00
|
|
|
{
|
|
|
|
|
float fSecs = 0;
|
|
|
|
|
FOREACH_CONST( Song*, vpPossibleSongs, s )
|
2005-04-27 21:46:35 +00:00
|
|
|
fSecs += (*s)->GetStepsSeconds();
|
2005-04-20 06:13:06 +00:00
|
|
|
return fSecs;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-11 01:44:13 +00:00
|
|
|
void StageStats::CommitScores( bool bSummary )
|
|
|
|
|
{
|
|
|
|
|
switch( GAMESTATE->m_PlayMode )
|
|
|
|
|
{
|
|
|
|
|
case PLAY_MODE_BATTLE:
|
|
|
|
|
case PLAY_MODE_RAVE:
|
|
|
|
|
return; /* don't save scores in battle */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( PREFSMAN->m_bScreenTestMode )
|
|
|
|
|
{
|
|
|
|
|
FOREACH_PlayerNumber( pn )
|
|
|
|
|
{
|
|
|
|
|
m_player[pn].m_iPersonalHighScoreIndex = 0;
|
|
|
|
|
m_player[pn].m_iMachineHighScoreIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// don't save scores if the player chose not to
|
2006-08-05 02:38:05 +00:00
|
|
|
if( !GAMESTATE->m_SongOptions.GetCurrent().m_bSaveScore )
|
2005-09-11 01:44:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LOG->Trace( "saving stats and high scores" );
|
|
|
|
|
|
|
|
|
|
FOREACH_HumanPlayer( p )
|
|
|
|
|
{
|
|
|
|
|
// don't save scores if the player is disqualified
|
|
|
|
|
if( GAMESTATE->IsDisqualified(p) )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// whether or not to save scores when the stage was failed
|
|
|
|
|
// depends on if this is a course or not ... it's handled
|
|
|
|
|
// below in the switch
|
|
|
|
|
|
|
|
|
|
HighScore &hs = m_player[p].m_HighScore;
|
|
|
|
|
hs.SetName( RANKING_TO_FILL_IN_MARKER[p] );
|
|
|
|
|
hs.SetGrade( m_player[p].GetGrade() );
|
|
|
|
|
hs.SetScore( m_player[p].iScore );
|
|
|
|
|
hs.SetPercentDP( m_player[p].GetPercentDancePoints() );
|
|
|
|
|
hs.SetSurviveSeconds( m_player[p].fAliveSeconds );
|
2006-08-05 02:38:05 +00:00
|
|
|
hs.SetModifiers( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.GetStage().GetString() );
|
2005-09-11 01:44:13 +00:00
|
|
|
hs.SetDateTime( DateTime::GetNowDateTime() );
|
2006-01-22 01:00:06 +00:00
|
|
|
hs.SetPlayerGuid( PROFILEMAN->IsPersistentProfile(p) ? PROFILEMAN->GetProfile(p)->m_sGuid : RString("") );
|
2005-09-11 01:44:13 +00:00
|
|
|
hs.SetMachineGuid( PROFILEMAN->GetMachineProfile()->m_sGuid );
|
|
|
|
|
hs.SetProductID( PREFSMAN->m_iProductID );
|
|
|
|
|
FOREACH_TapNoteScore( tns )
|
|
|
|
|
hs.SetTapNoteScore( tns, m_player[p].iTapNoteScores[tns] );
|
|
|
|
|
FOREACH_HoldNoteScore( hns )
|
|
|
|
|
hs.SetHoldNoteScore( hns, m_player[p].iHoldNoteScores[hns] );
|
|
|
|
|
hs.SetRadarValues( m_player[p].radarActual );
|
|
|
|
|
hs.SetLifeRemainingSeconds( m_player[p].fLifeRemainingSeconds );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FOREACH_HumanPlayer( p )
|
|
|
|
|
{
|
|
|
|
|
const HighScore &hs = m_player[p].m_HighScore;
|
|
|
|
|
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;
|
|
|
|
|
|
|
|
|
|
const Song* pSong = GAMESTATE->m_pCurSong;
|
|
|
|
|
const Steps* pSteps = GAMESTATE->m_pCurSteps[p];
|
|
|
|
|
|
|
|
|
|
if( bSummary )
|
|
|
|
|
{
|
|
|
|
|
// don't save scores if any stage was failed
|
|
|
|
|
if( m_player[p].bFailed )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
int iAverageMeter = GetAverageMeter(p);
|
|
|
|
|
m_player[p].m_rc = AverageMeterToRankingCategory( iAverageMeter );
|
|
|
|
|
|
|
|
|
|
PROFILEMAN->AddCategoryScore( st, m_player[p].m_rc, p, hs, m_player[p].m_iPersonalHighScoreIndex, m_player[p].m_iMachineHighScoreIndex );
|
|
|
|
|
|
|
|
|
|
// TRICKY: Increment play count here, and not on ScreenGameplay like the others.
|
|
|
|
|
PROFILEMAN->IncrementCategoryPlayCount( st, m_player[p].m_rc, p );
|
|
|
|
|
}
|
|
|
|
|
else if( GAMESTATE->IsCourseMode() )
|
|
|
|
|
{
|
|
|
|
|
Course* pCourse = GAMESTATE->m_pCurCourse;
|
|
|
|
|
ASSERT( pCourse );
|
|
|
|
|
Trail* pTrail = GAMESTATE->m_pCurTrail[p];
|
|
|
|
|
|
|
|
|
|
PROFILEMAN->AddCourseScore( pCourse, pTrail, p, hs, m_player[p].m_iPersonalHighScoreIndex, m_player[p].m_iMachineHighScoreIndex );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// don't save scores for a failed song
|
|
|
|
|
if( m_player[p].bFailed )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ASSERT( pSteps );
|
|
|
|
|
|
|
|
|
|
PROFILEMAN->AddStepsScore( pSong, pSteps, p, hs, m_player[p].m_iPersonalHighScoreIndex, m_player[p].m_iMachineHighScoreIndex );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG->Trace( "done saving stats and high scores" );
|
|
|
|
|
|
|
|
|
|
// If both players get a machine high score in the same HighScoreList,
|
|
|
|
|
// then one player's score may have bumped the other player. Look in
|
|
|
|
|
// the HighScoreList and re-get the high score index.
|
|
|
|
|
FOREACH_HumanPlayer( p )
|
|
|
|
|
{
|
|
|
|
|
if( m_player[p].m_iMachineHighScoreIndex == -1 ) // no record
|
|
|
|
|
continue; // skip
|
|
|
|
|
|
|
|
|
|
HighScore &hs = m_player[p].m_HighScore;
|
|
|
|
|
Profile* pProfile = PROFILEMAN->GetMachineProfile();
|
|
|
|
|
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;
|
|
|
|
|
|
|
|
|
|
const HighScoreList *pHSL = NULL;
|
|
|
|
|
if( bSummary )
|
|
|
|
|
{
|
|
|
|
|
pHSL = &pProfile->GetCategoryHighScoreList( st, m_player[p].m_rc );
|
|
|
|
|
}
|
|
|
|
|
else if( GAMESTATE->IsCourseMode() )
|
|
|
|
|
{
|
|
|
|
|
Course* pCourse = GAMESTATE->m_pCurCourse;
|
|
|
|
|
ASSERT( pCourse );
|
|
|
|
|
Trail *pTrail = GAMESTATE->m_pCurTrail[p];
|
|
|
|
|
ASSERT( pTrail );
|
|
|
|
|
pHSL = &pProfile->GetCourseHighScoreList( pCourse, pTrail );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Song* pSong = GAMESTATE->m_pCurSong;
|
|
|
|
|
Steps* pSteps = GAMESTATE->m_pCurSteps[p];
|
|
|
|
|
pHSL = &pProfile->GetStepsHighScoreList( pSong, pSteps );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector<HighScore>::const_iterator iter = find( pHSL->vHighScores.begin(), pHSL->vHighScores.end(), hs );
|
|
|
|
|
if( iter == pHSL->vHighScores.end() )
|
|
|
|
|
m_player[p].m_iMachineHighScoreIndex = -1;
|
|
|
|
|
else
|
|
|
|
|
m_player[p].m_iMachineHighScoreIndex = iter - pHSL->vHighScores.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2005-02-16 02:11:31 +00:00
|
|
|
|
|
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
|
2005-06-20 05:02:03 +00:00
|
|
|
class LunaStageStats: public Luna<StageStats>
|
2005-02-16 02:11:31 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2006-09-27 09:18:21 +00:00
|
|
|
static int GetPlayerStageStats( T* p, lua_State *L ) { p->m_player[Enum::Check<PlayerNumber>(L, 1)].PushSelf(L); return 1; }
|
|
|
|
|
static int GetMultiPlayerStageStats( T* p, lua_State *L ) { p->m_multiPlayer[Enum::Check<MultiPlayer>(L, 1)].PushSelf(L); return 1; }
|
2005-02-18 12:04:51 +00:00
|
|
|
static int GetGameplaySeconds( T* p, lua_State *L ) { lua_pushnumber(L, p->fGameplaySeconds); return 1; }
|
2006-04-21 00:12:44 +00:00
|
|
|
static int OnePassed( T* p, lua_State *L ) { lua_pushboolean(L, p->OnePassed()); return 1; }
|
|
|
|
|
static int AllFailed( T* p, lua_State *L ) { lua_pushboolean(L, p->AllFailed()); return 1; }
|
2005-02-16 02:11:31 +00:00
|
|
|
|
2006-09-27 20:30:29 +00:00
|
|
|
LunaStageStats()
|
2005-02-16 02:11:31 +00:00
|
|
|
{
|
2005-09-10 02:47:04 +00:00
|
|
|
ADD_METHOD( GetPlayerStageStats );
|
2006-04-21 00:12:44 +00:00
|
|
|
ADD_METHOD( GetMultiPlayerStageStats );
|
2005-09-10 02:47:04 +00:00
|
|
|
ADD_METHOD( GetGameplaySeconds );
|
|
|
|
|
ADD_METHOD( OnePassed );
|
|
|
|
|
ADD_METHOD( AllFailed );
|
2005-02-16 02:11:31 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_CLASS( StageStats )
|
|
|
|
|
// lua end
|
|
|
|
|
|
|
|
|
|
|
2004-05-31 21:35:31 +00:00
|
|
|
/*
|
|
|
|
|
* (c) 2001-2004 Chris Danford, 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.
|
|
|
|
|
*/
|