Files
itgmania212121/stepmania/src/StageStats.cpp
T

130 lines
3.6 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
#include "StageStats.h"
#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"
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++ )
{
const Steps* pSteps = m_player[pn].vpSteps[i];
iTotalMeter += pSteps->GetMeter();
}
return iTotalMeter / vpSongs.size(); // round down
}
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
{
FOREACH_PlayerNumber( p )
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
{
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
{
FOREACH_EnabledPlayer( p )
if( !m_player[p].bFailedEarlier )
2003-12-31 20:58:14 +00:00
return false;
return true;
}
2005-02-16 02:11:31 +00:00
// lua start
#include "LuaBinding.h"
template<class T>
class LunaStageStats : public Luna<T>
{
public:
LunaStageStats() { LUA->Register( Register ); }
static int GetPlayerStageStats( T* p, lua_State *L ) { p->m_player[IArg(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; }
2005-02-16 02:11:31 +00:00
static void Register(lua_State *L)
{
ADD_METHOD( GetPlayerStageStats )
2005-02-18 12:04:51 +00:00
ADD_METHOD( GetGameplaySeconds )
2005-02-16 02:11:31 +00:00
Luna<T>::Register( L );
}
};
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.
*/