diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index b0e2f01d47..eee1422f7d 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -361,6 +361,8 @@ void GameState::UnjoinPlayer( PlayerNumber pn ) if( m_MasterPlayerNumber == pn ) m_MasterPlayerNumber = GAMESTATE->GetFirstHumanPlayer(); + STATSMAN->UnjoinPlayer( pn ); + Message msg( MessageIDToString(Message_PlayerUnjoined) ); msg.SetParam( "Player", pn ); MESSAGEMAN->Broadcast( msg ); diff --git a/stepmania/src/PlayerStageStats.cpp b/stepmania/src/PlayerStageStats.cpp index f6e7a9b38f..f9dead8507 100644 --- a/stepmania/src/PlayerStageStats.cpp +++ b/stepmania/src/PlayerStageStats.cpp @@ -24,6 +24,7 @@ Grade GetGradeFromPercent( float fPercent, bool bMerciful ); void PlayerStageStats::Init() { + m_bJoined = false; m_vpPlayedSteps.clear(); m_vpPossibleSteps.clear(); m_fAliveSeconds = 0; @@ -63,6 +64,7 @@ void PlayerStageStats::Init() void PlayerStageStats::AddStats( const PlayerStageStats& other ) { + m_bJoined = other.m_bJoined; FOREACH_CONST( Steps*, other.m_vpPlayedSteps, s ) m_vpPlayedSteps.push_back( *s ); FOREACH_CONST( Steps*, other.m_vpPossibleSteps, s ) diff --git a/stepmania/src/PlayerStageStats.h b/stepmania/src/PlayerStageStats.h index f9b1a034d3..d194d3e221 100644 --- a/stepmania/src/PlayerStageStats.h +++ b/stepmania/src/PlayerStageStats.h @@ -26,6 +26,7 @@ public: int GetLessonScoreNeeded() const; void ResetScoreForLesson(); + bool m_bJoined; vector m_vpPlayedSteps; vector m_vpPossibleSteps; float m_fAliveSeconds; // how far into the music did they last before failing? Updated by Gameplay, scaled by music rate. diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index 718a75408e..6402fa5143 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -846,6 +846,12 @@ void ScreenGameplay::InitSongQueues() if( pi->GetPlayerStageStats() ) pi->GetPlayerStageStats()->m_vpPossibleSteps = pi->m_vpStepsQueue; } + + FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi ) + { + if( pi->GetPlayerStageStats() ) + pi->GetPlayerStageStats()->m_bJoined = true; + } } ScreenGameplay::~ScreenGameplay() diff --git a/stepmania/src/StatsManager.cpp b/stepmania/src/StatsManager.cpp index 036ec02850..77107d6dd4 100644 --- a/stepmania/src/StatsManager.cpp +++ b/stepmania/src/StatsManager.cpp @@ -210,6 +210,32 @@ void StatsManager::CommitStatsToProfiles() } } +void StatsManager::UnjoinPlayer( PlayerNumber pn ) +{ + /* A player has been unjoined. Clear his data from m_vPlayedStageStats, and + * purge any m_vPlayedStageStats that no longer have any player data because + * all of the players that were playing at the time have been unjoined. */ + FOREACH( StageStats, m_vPlayedStageStats, ss ) + ss->m_player[pn] = PlayerStageStats(); + + for( int i = 0; i < (int) m_vPlayedStageStats.size(); ++i ) + { + StageStats &ss = m_vPlayedStageStats[i]; + bool bIsActive = false; + FOREACH_PlayerNumber( p ) + if( ss.m_player[p].m_bJoined ) + bIsActive = true; + FOREACH_MultiPlayer( mp ) + if( ss.m_multiPlayer[mp].m_bJoined ) + bIsActive = true; + if( bIsActive ) + continue; + + m_vPlayedStageStats.erase( m_vPlayedStageStats.begin()+i ); + --i; + } + +} // lua start #include "LuaBinding.h" diff --git a/stepmania/src/StatsManager.h b/stepmania/src/StatsManager.h index d367f63c10..a0d98b074d 100644 --- a/stepmania/src/StatsManager.h +++ b/stepmania/src/StatsManager.h @@ -26,6 +26,8 @@ public: void CommitStatsToProfiles(); + void UnjoinPlayer( PlayerNumber pn ); + // Lua void PushSelf( lua_State *L );