Files
itgmania212121/stepmania/src/StageStats.cpp
T

295 lines
8.4 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
/*
-----------------------------------------------------------------------------
Class: StageStats
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
2003-07-06 08:58:44 +00:00
#include "StageStats.h"
#include "GameState.h"
#include "RageLog.h"
2003-09-06 02:05:39 +00:00
#include "SongManager.h"
2003-10-12 21:48:05 +00:00
#include "RageUtil.h"
StageStats::StageStats()
{
memset( this, 0, sizeof(StageStats) );
2003-10-16 06:49:02 +00:00
for( int p=0; p<NUM_PLAYERS; p++ )
2003-10-30 04:41:03 +00:00
{
2003-10-16 06:49:02 +00:00
for( int i = 0; i < LIFE_RECORD_RESOLUTION; ++i )
fLifeRecord[p][i] = -1;
2003-10-30 04:41:03 +00:00
fFirstPos[p] = 1;
fLastPos[p] = 0;
}
}
void StageStats::AddStats( const StageStats& other )
{
pSong = NULL; // meaningless
StageType = STAGE_INVALID; // meaningless
memset( fAliveSeconds, 0, sizeof(fAliveSeconds) );
2003-09-06 02:05:39 +00:00
// weight long and marathon songs
ASSERT( other.pSong );
const int iLengthMultiplier = SongManager::GetNumStagesForSong( other.pSong );
for( int p=0; p<NUM_PLAYERS; p++ )
{
pSteps[p] = NULL;
2003-09-06 02:05:39 +00:00
iMeter[p] += other.iMeter[p] * iLengthMultiplier;
fAliveSeconds[p] += other.fAliveSeconds[p];
bFailed[p] |= other.bFailed[p];
bFailedEarlier[p] |= other.bFailedEarlier[p];
iPossibleDancePoints[p] += other.iPossibleDancePoints[p];
iActualDancePoints[p] += other.iActualDancePoints[p];
for( int t=0; t<NUM_TAP_NOTE_SCORES; t++ )
iTapNoteScores[p][t] += other.iTapNoteScores[p][t];
for( int h=0; h<NUM_HOLD_NOTE_SCORES; h++ )
iHoldNoteScores[p][h] += other.iHoldNoteScores[p][h];
2003-03-16 20:55:45 +00:00
iCurCombo[p] += other.iCurCombo[p];
iMaxCombo[p] += other.iMaxCombo[p];
iCurMissCombo[p] += other.iCurMissCombo[p];
2003-06-18 20:08:39 +00:00
iScore[p] += other.iScore[p];
2003-01-30 07:18:33 +00:00
for( int r=0; r<NUM_RADAR_CATEGORIES; r++ )
{
fRadarPossible[p][r] += other.fRadarPossible[p][r];
fRadarActual[p][r] += other.fRadarActual[p][r];
}
fSecondsBeforeFail[p] += other.fSecondsBeforeFail[p];
iSongsPassed[p] += other.iSongsPassed[p];
2003-07-31 23:01:02 +00:00
iSongsPlayed[p] += other.iSongsPlayed[p];
iTotalError[p] += other.iTotalError[p];
2003-10-16 06:49:02 +00:00
for( int i = 0; i < LIFE_RECORD_RESOLUTION; ++i )
fLifeRecord[p][i] = -1;
}
}
Grade StageStats::GetGrade( PlayerNumber pn )
{
ASSERT( GAMESTATE->IsPlayerEnabled(pn) ); // should be calling this is player isn't joined!
2003-10-13 03:24:28 +00:00
if( bFailedEarlier[pn] )
return GRADE_E;
/* XXX: This entire calculation should be in ScoreKeeper, but final evaluation
2003-10-02 02:03:29 +00:00
* is tricky since at that point the ScoreKeepers no longer exist.
*
* See http://www.aaroninjapan.com/ddr2.html ("Regular play scoring") */
const float TapScoreValues[NUM_TAP_NOTE_SCORES] = { 0, -8, -4, 0, +1, +2, +2 };
const float HoldScoreValues[NUM_HOLD_NOTE_SCORES] = { 0, 0, +6 };
float Possible = 0, Actual = 0;
int i;
for( i = TNS_MISS; i < NUM_TAP_NOTE_SCORES; ++i )
{
Actual += iTapNoteScores[pn][i] * TapScoreValues[i];
Possible += iTapNoteScores[pn][i] * TapScoreValues[TNS_MARVELOUS];
}
for( i = HNS_OK; i < NUM_HOLD_NOTE_SCORES; ++i )
{
Actual += iHoldNoteScores[pn][i] * HoldScoreValues[i];
Possible += iHoldNoteScores[pn][i] * HoldScoreValues[HNS_OK];
}
float fPercentDancePoints = Actual / Possible;
fPercentDancePoints = max( 0.f, fPercentDancePoints );
LOG->Trace( "GetGrade: Actual: %f, Possible: %f, Percent: %f", Actual, Possible, fPercentDancePoints );
2003-08-13 19:52:19 +00:00
/* check for "AAAA". Check DP == 100%: if we're using eg. "LITTLE", we might have all
* marvelouses but still not qualify for a AAAA. */
if( fPercentDancePoints > .9999 &&
iTapNoteScores[pn][TNS_MARVELOUS] > 0 &&
iTapNoteScores[pn][TNS_PERFECT] == 0 &&
iTapNoteScores[pn][TNS_GREAT] == 0 &&
iTapNoteScores[pn][TNS_GOOD] == 0 &&
iTapNoteScores[pn][TNS_BOO] == 0 &&
iTapNoteScores[pn][TNS_MISS] == 0 &&
iHoldNoteScores[pn][HNS_NG] == 0 )
return GRADE_AAAA;
/* Based on the percentage of your total "Dance Points" to the maximum
* possible number, the following rank is assigned:
*
* 100% - AAA
* 93% - AA
* 80% - A
* 65% - B
* 45% - C
* Less - D
* Fail - E
*/
if ( fPercentDancePoints == 1.00 ) return GRADE_AAA;
else if( fPercentDancePoints >= 0.93 ) return GRADE_AA;
else if( fPercentDancePoints >= 0.80 ) return GRADE_A;
else if( fPercentDancePoints >= 0.65 ) return GRADE_B;
else if( fPercentDancePoints >= 0.45 ) return GRADE_C;
else if( fPercentDancePoints >= 0 ) return GRADE_D;
else return GRADE_E;
}
2003-09-06 00:33:09 +00:00
bool StageStats::OnePassed() const
{
for( int p=0; p<NUM_PLAYERS; p++ )
2003-09-06 01:18:55 +00:00
if( GAMESTATE->IsHumanPlayer(p) && !bFailed[p] )
2003-09-06 00:33:09 +00:00
return true;
return false;
}
2003-11-03 23:55:58 +00:00
bool StageStats::AllFailed() const
{
for( int pn=0; pn<NUM_PLAYERS; pn++ )
if( GAMESTATE->IsPlayerEnabled(PlayerNumber(pn)) )
if( !GAMESTATE->m_CurStageStats.bFailed[pn] )
return false;
return true;
}
2003-10-12 21:48:05 +00:00
float StageStats::GetPercentDancePoints( PlayerNumber pn ) const
{
if( iPossibleDancePoints[pn] == 0 )
return 0; // div/0
if( iActualDancePoints[pn] == iPossibleDancePoints[pn] )
return 1; // correct for rounding error
float fPercentDancePoints = iActualDancePoints[pn] / (float)iPossibleDancePoints[pn];
return clamp( fPercentDancePoints, 0, 1 );
}
2003-10-16 06:49:02 +00:00
void StageStats::SetLifeRecord( PlayerNumber pn, float life, float pos )
{
2003-10-23 06:17:12 +00:00
pos = clamp( pos, 0, 1 );
2003-10-16 06:49:02 +00:00
int offset = (int) roundf( pos * LIFE_RECORD_RESOLUTION );
for( int i = 0; i <= offset; ++i )
if( fLifeRecord[pn][i] < 0 )
fLifeRecord[pn][i] = life;
}
void StageStats::GetLifeRecord( PlayerNumber pn, float *life, int nout ) const
{
for( int i = 0; i < nout; ++i )
{
int from = i * (LIFE_RECORD_RESOLUTION-1) / nout;
life[i] = fLifeRecord[pn][from];
}
}
2003-10-23 06:17:12 +00:00
void StageStats::UpdateComboList( PlayerNumber pn, float pos )
{
pos = clamp( pos, 0, 1 );
2003-10-30 04:41:03 +00:00
fFirstPos[pn] = min( pos, fFirstPos[pn] );
fLastPos[pn] = max( pos, fLastPos[pn] );
2003-11-02 17:05:11 +00:00
int cnt = iCurCombo[pn];
2003-10-23 06:17:12 +00:00
if( !cnt )
return; /* no combo */
if( ComboList[pn].size() == 0 || ComboList[pn].back().cnt >= cnt )
{
/* This is a new combo. */
Combo_t NewCombo;
NewCombo.start = pos;
ComboList[pn].push_back( NewCombo );
2003-11-02 17:05:11 +00:00
/* If this is the first combo, and the current combo is greater than 1,
* then that extra part of the combo must have come from a previous song.
* Remember it separately. */
if( ComboList[pn].size() == 1 )
{
ComboList[pn][0].rollover = cnt-1;
cnt = 1;
}
2003-10-23 06:17:12 +00:00
}
Combo_t &combo = ComboList[pn].back();
combo.size = pos - combo.start;
combo.cnt = cnt;
}
2003-11-02 17:05:11 +00:00
/* This returns the largest combo contained within the song, as if
* m_bComboContinuesBetweenSongs is turned off. */
StageStats::Combo_t StageStats::GetMaxCombo( PlayerNumber pn ) const
{
if( ComboList[pn].size() == 0 )
return Combo_t();
int m = 0;
for( unsigned i = 1; i < ComboList[pn].size(); ++i )
{
if( ComboList[pn][i].cnt > ComboList[pn][m].cnt )
m = i;
}
return ComboList[pn][m];
}
2003-10-23 06:17:12 +00:00
/* SetLifeRecord and UpdateComboList take a percentage (0..1) in pos, but the values
* will actually be somewhat off as they're based on Song::m_fFirstBeat and m_fLastBeat,
* which are per-song, not per-Steps. Scale and shift our records so that they're
* really 0..1. */
void StageStats::Finish()
{
for( int pn = 0; pn < NUM_PLAYERS; ++pn )
{
if( ComboList[pn].size() == 0 )
continue;
2003-10-30 04:41:03 +00:00
const float First = fFirstPos[pn];
const float Last = fLastPos[pn];
2003-10-23 06:17:12 +00:00
if( fabsf(First-Last) < 0.0001f )
continue;
unsigned i;
for( i = 0; i < ComboList[pn].size(); ++i )
{
ComboList[pn][i].start = SCALE( ComboList[pn][i].start, First, Last, 0.0f, 1.0f );
ComboList[pn][i].size /= Last - First;
}
float NewLifeRecord[LIFE_RECORD_RESOLUTION];
for( i = 0; i < LIFE_RECORD_RESOLUTION; ++i )
{
int from = (int) roundf( SCALE( i, 0.0f, 1.0f, First, Last ) );
from = clamp( from, 0, LIFE_RECORD_RESOLUTION-1 );
NewLifeRecord[i] = fLifeRecord[pn][from];
}
memcpy( fLifeRecord[pn], NewLifeRecord, sizeof(fLifeRecord[pn]) );
2003-10-30 04:41:03 +00:00
fFirstPos[pn] = 0;
fLastPos[pn] = 1;
}
}
bool StageStats::FullCombo( PlayerNumber pn ) const
{
if( ComboList[pn].size() != 1 )
{
LOG->Trace("FullCombo(%i): %i != 1", pn, ComboList[pn].size() );
return false;
2003-10-23 06:17:12 +00:00
}
2003-10-30 04:41:03 +00:00
const float ComboStart = ComboList[pn][0].start;
const float ComboEnd = ComboList[pn][0].start + ComboList[pn][0].size;
const bool ComboStartsAtBeginning = fabs( ComboStart - fFirstPos[pn] ) < 0.001f;
const bool ComboEndsAtEnd = fabs( ComboEnd - fLastPos[pn] ) < 0.001f;
LOG->Trace("FullCombo(%i): %f .. %f, %f .. %f, %i, %i",
pn, ComboStart, ComboEnd, fFirstPos[pn], fLastPos[pn], ComboStartsAtBeginning, ComboEndsAtEnd );
return ComboStartsAtBeginning && ComboEndsAtEnd;
2003-10-23 06:17:12 +00:00
}