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"
|
2003-01-24 02:43:07 +00:00
|
|
|
|
2003-12-23 00:26:00 +00:00
|
|
|
StageStats g_CurStageStats;
|
|
|
|
|
vector<StageStats> g_vPlayedStageStats;
|
|
|
|
|
|
2004-12-20 10:47:41 +00:00
|
|
|
void StageStats::Init()
|
|
|
|
|
{
|
|
|
|
|
playMode = PLAY_MODE_INVALID;
|
|
|
|
|
pStyle = NULL;
|
|
|
|
|
vpSongs.clear();
|
|
|
|
|
StageType = STAGE_INVALID;
|
|
|
|
|
fGameplaySeconds = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StageStats::AssertValid( PlayerNumber pn ) const
|
|
|
|
|
{
|
|
|
|
|
if( vpSongs[0] )
|
|
|
|
|
CHECKPOINT_M( vpSongs[0]->GetFullTranslitTitle() );
|
|
|
|
|
ASSERT( m_player[pn].vpSteps[0] );
|
|
|
|
|
ASSERT_M( playMode < NUM_PLAY_MODES, ssprintf("playmode %i", playMode) );
|
|
|
|
|
ASSERT( pStyle != NULL );
|
|
|
|
|
ASSERT_M( m_player[pn].vpSteps[0]->GetDifficulty() < NUM_DIFFICULTIES, ssprintf("difficulty %i", m_player[pn].vpSteps[0]->GetDifficulty()) );
|
|
|
|
|
ASSERT( vpSongs.size() == m_player[pn].vpSteps.size() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int StageStats::GetAverageMeter( PlayerNumber pn ) const
|
|
|
|
|
{
|
|
|
|
|
int iTotalMeter = 0;
|
|
|
|
|
ASSERT( vpSongs.size() == m_player[pn].vpSteps.size() );
|
|
|
|
|
|
|
|
|
|
for( unsigned i=0; i<vpSongs.size(); i++ )
|
|
|
|
|
{
|
2005-01-10 18:55:49 +00:00
|
|
|
const Steps* pSteps = m_player[pn].vpSteps[i];
|
|
|
|
|
iTotalMeter += pSteps->GetMeter();
|
2004-12-20 10:47:41 +00:00
|
|
|
}
|
2005-01-10 18:55:49 +00:00
|
|
|
return iTotalMeter / vpSongs.size(); // round down
|
2004-12-20 10:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StageStats::AddStats( const StageStats& other )
|
|
|
|
|
{
|
|
|
|
|
ASSERT( !other.vpSongs.empty() );
|
|
|
|
|
FOREACH_CONST( Song*, other.vpSongs, s )
|
|
|
|
|
vpSongs.push_back( *s );
|
|
|
|
|
StageType = STAGE_INVALID; // meaningless
|
|
|
|
|
|
|
|
|
|
fGameplaySeconds += other.fGameplaySeconds;
|
|
|
|
|
|
|
|
|
|
FOREACH_PlayerNumber( p )
|
|
|
|
|
{
|
|
|
|
|
m_player[p].AddStats( other.m_player[p] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-06 00:33:09 +00:00
|
|
|
bool StageStats::OnePassed() const
|
|
|
|
|
{
|
2004-05-24 06:10:11 +00:00
|
|
|
FOREACH_PlayerNumber( p )
|
2004-12-20 10:47:41 +00:00
|
|
|
if( GAMESTATE->IsHumanPlayer(p) && !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
|
|
|
|
|
{
|
2004-12-20 10:47:41 +00:00
|
|
|
FOREACH_EnabledPlayer( pn )
|
|
|
|
|
if( !m_player[pn].bFailed )
|
|
|
|
|
return false;
|
2003-11-03 23:55:58 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-31 20:58:14 +00:00
|
|
|
bool StageStats::AllFailedEarlier() const
|
|
|
|
|
{
|
2004-12-20 10:47:41 +00:00
|
|
|
FOREACH_EnabledPlayer( p )
|
|
|
|
|
if( !m_player[p].bFailedEarlier )
|
2003-12-31 20:58:14 +00:00
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-14 23:26:32 +00:00
|
|
|
static Grade GetBestGrade()
|
|
|
|
|
{
|
|
|
|
|
Grade g = NUM_GRADES;
|
2004-08-30 04:35:14 +00:00
|
|
|
FOREACH_EnabledPlayer( pn )
|
2004-12-20 10:47:41 +00:00
|
|
|
g = min( g, g_CurStageStats.m_player[pn].GetGrade() );
|
2004-02-14 23:26:32 +00:00
|
|
|
return g;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Grade GetWorstGrade()
|
|
|
|
|
{
|
|
|
|
|
Grade g = GRADE_TIER_1;
|
2004-08-30 04:35:14 +00:00
|
|
|
FOREACH_EnabledPlayer( pn )
|
2004-12-20 10:47:41 +00:00
|
|
|
g = max( g, g_CurStageStats.m_player[pn].GetGrade() );
|
2004-02-14 23:26:32 +00:00
|
|
|
return g;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "LuaFunctions.h"
|
2004-05-11 06:12:40 +00:00
|
|
|
LuaFunction_NoArgs( GetStagesPlayed, (int) g_vPlayedStageStats.size() );
|
2004-02-14 23:26:32 +00:00
|
|
|
LuaFunction_NoArgs( GetBestGrade, GetBestGrade() );
|
|
|
|
|
LuaFunction_NoArgs( GetWorstGrade, GetWorstGrade() );
|
|
|
|
|
LuaFunction_NoArgs( OnePassed, g_CurStageStats.OnePassed() );
|
2005-01-31 03:43:49 +00:00
|
|
|
LuaFunction_NoArgs( AllFailed, g_CurStageStats.AllFailed() );
|
2004-12-20 10:47:41 +00:00
|
|
|
LuaFunction_PlayerNumber( FullCombo, g_CurStageStats.m_player[pn].FullCombo() )
|
|
|
|
|
LuaFunction_PlayerNumber( MaxCombo, g_CurStageStats.m_player[pn].GetMaxCombo().cnt )
|
|
|
|
|
LuaFunction_PlayerNumber( GetGrade, g_CurStageStats.m_player[pn].GetGrade() )
|
2004-02-14 23:26:32 +00:00
|
|
|
LuaFunction_Str( Grade, StringToGrade(str) );
|
|
|
|
|
|
2004-05-11 06:12:40 +00:00
|
|
|
const StageStats *GetStageStatsN( int n )
|
2004-02-14 23:26:32 +00:00
|
|
|
{
|
2004-05-11 06:12:40 +00:00
|
|
|
if( n == (int) g_vPlayedStageStats.size() )
|
|
|
|
|
return &g_CurStageStats;
|
|
|
|
|
if( n > (int) g_vPlayedStageStats.size() )
|
|
|
|
|
return NULL;
|
|
|
|
|
return &g_vPlayedStageStats[n];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* GetGrade(0) returns the first grade; GetGrade(1) returns the second grade, and
|
|
|
|
|
* and so on. GetGrade(GetStagesPlayed()) returns the current grade (from g_CurStageStats).
|
|
|
|
|
* If beyond the current song played, return GRADE_NO_DATA. */
|
|
|
|
|
Grade GetGrade( int n, PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
const StageStats *pStats = GetStageStatsN( n );
|
|
|
|
|
if( pStats == NULL )
|
2004-02-14 23:26:32 +00:00
|
|
|
return GRADE_NO_DATA;
|
2004-12-20 10:47:41 +00:00
|
|
|
return pStats->m_player[pn].GetGrade();
|
2004-02-14 23:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OneGotGrade( int n, Grade g )
|
|
|
|
|
{
|
2004-05-11 06:12:40 +00:00
|
|
|
FOREACH_HumanPlayer( pn )
|
2004-08-30 04:35:14 +00:00
|
|
|
if( GetGrade( n, pn ) == g )
|
2004-05-11 06:12:40 +00:00
|
|
|
return true;
|
2004-02-14 23:26:32 +00:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LuaFunction_IntInt( OneGotGrade, OneGotGrade( a1, (Grade) a2 ) );
|
|
|
|
|
|
|
|
|
|
Grade GetFinalGrade( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
if( !GAMESTATE->IsHumanPlayer(pn) )
|
|
|
|
|
return GRADE_NO_DATA;
|
|
|
|
|
StageStats stats;
|
2004-08-30 04:09:23 +00:00
|
|
|
GAMESTATE->GetFinalEvalStats( stats );
|
2004-12-20 10:47:41 +00:00
|
|
|
return stats.m_player[pn].GetGrade();
|
2004-02-14 23:26:32 +00:00
|
|
|
}
|
2004-08-30 04:09:23 +00:00
|
|
|
LuaFunction_PlayerNumber( GetFinalGrade, GetFinalGrade(pn) );
|
2004-02-14 23:26:32 +00:00
|
|
|
|
|
|
|
|
Grade GetBestFinalGrade()
|
|
|
|
|
{
|
|
|
|
|
Grade top_grade = GRADE_FAILED;
|
|
|
|
|
StageStats stats;
|
2004-08-30 04:09:23 +00:00
|
|
|
GAMESTATE->GetFinalEvalStats( stats );
|
2005-01-31 03:43:49 +00:00
|
|
|
FOREACH_HumanPlayer( p )
|
|
|
|
|
top_grade = min( top_grade, stats.m_player[p].GetGrade() );
|
2004-02-14 23:26:32 +00:00
|
|
|
return top_grade;
|
|
|
|
|
}
|
|
|
|
|
LuaFunction_NoArgs( GetBestFinalGrade, GetBestFinalGrade() );
|
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.
|
|
|
|
|
*/
|