From 6258283f301aed960c5f5b085c7238df79d83ccd Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 26 Oct 2007 21:50:04 +0000 Subject: [PATCH] clean up multiplayer difficulty choosing logic --- stepmania/src/ScreenGameplay.cpp | 42 +++++++++++++++++++++----------- stepmania/src/ScreenGameplay.h | 6 ++--- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index 0238882b78..924b06f9e9 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -103,7 +103,7 @@ PlayerInfo::PlayerInfo() m_mp = MultiPlayer_Invalid; m_bIsDummy = false; m_iDummyIndex = 0; - m_difficultyForced = Difficulty_Invalid; + m_iAddToDifficulty = 0; m_pLifeMeter = NULL; m_ptextCourseSongNumber = NULL; m_ptextStepsDescription = NULL; @@ -118,13 +118,13 @@ PlayerInfo::PlayerInfo() m_pDifficultyIcon = NULL; } -void PlayerInfo::Load( PlayerNumber pn, MultiPlayer mp, bool bShowNoteField, Difficulty dcForced ) +void PlayerInfo::Load( PlayerNumber pn, MultiPlayer mp, bool bShowNoteField, int iAddToDifficulty ) { m_pn = pn; m_mp = mp; m_bPlayerEnabled = IsEnabled(); m_bIsDummy = false; - m_difficultyForced = dcForced; + m_iAddToDifficulty = iAddToDifficulty; m_pLifeMeter = NULL; m_ptextCourseSongNumber = NULL; m_ptextStepsDescription = NULL; @@ -192,13 +192,13 @@ void PlayerInfo::Load( PlayerNumber pn, MultiPlayer mp, bool bShowNoteField, Dif } } -void PlayerInfo::LoadDummyP1( int iDummyIndex, Difficulty dcForced ) +void PlayerInfo::LoadDummyP1( int iDummyIndex, int iAddToDifficulty ) { m_pn = PLAYER_1; m_bPlayerEnabled = IsEnabled(); m_bIsDummy = true; m_iDummyIndex = iDummyIndex; - m_difficultyForced = dcForced; + m_iAddToDifficulty = iAddToDifficulty; // don't init any of the scoring objects m_pPlayer = new Player( m_NoteData, true ); @@ -842,18 +842,32 @@ void ScreenGameplay::InitSongQueues() } } - FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi ) + for( int i=0; i<(int)m_apSongsQueue.size(); i++ ) { - if( pi->m_difficultyForced != Difficulty_Invalid ) + Song *pSong = m_apSongsQueue[i]; + + FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi ) { - for( int i=0; i<(int)m_apSongsQueue.size(); i++ ) + Steps *pOldSteps = pi->m_vpStepsQueue[i]; + + vector vpSteps; + SongUtil::GetSteps( pSong, vpSteps, pOldSteps->m_StepsType ); + StepsUtil::SortNotesArrayByDifficulty( vpSteps ); + vector::iterator iter = find( vpSteps.begin(), vpSteps.end(), pOldSteps ); + int iIndexBase = 0; + if( iter != vpSteps.end() ) { - Song *pSong = m_apSongsQueue[i]; - Steps *pOldSteps = pi->m_vpStepsQueue[i]; - Steps *pSteps = SongUtil::GetOneSteps( pSong, pOldSteps->m_StepsType, pi->m_difficultyForced ); - if( pSteps == NULL ) - pSteps = SongUtil::GetClosestNotes( pSong, pOldSteps->m_StepsType, pi->m_difficultyForced ); - ASSERT( pSteps ); + iIndexBase = iter - vpSteps.begin(); + CLAMP( iIndexBase, 0, vpSteps.size() - GAMESTATE->m_iNumMultiplayerNoteFields ); + } + + if( pi->m_iAddToDifficulty > 0 ) + { + int iIndexToUse = iIndexBase + pi->m_iAddToDifficulty; + CLAMP( iIndexToUse, 0, vpSteps.size()-1 ); + LOG->Trace( "pi->m_iAddToDifficulty %d, iIndexToUse %d", pi->m_iAddToDifficulty, iIndexToUse ); + + Steps *pSteps = vpSteps[iIndexToUse]; pi->m_vpStepsQueue[i] = pSteps; } } diff --git a/stepmania/src/ScreenGameplay.h b/stepmania/src/ScreenGameplay.h index 1273533714..f07c2da166 100644 --- a/stepmania/src/ScreenGameplay.h +++ b/stepmania/src/ScreenGameplay.h @@ -43,8 +43,8 @@ public: PlayerInfo(); ~PlayerInfo(); - void Load( PlayerNumber pn, MultiPlayer mp, bool bShowNoteField, Difficulty dcForced ); - void LoadDummyP1( int iDummyIndex, Difficulty dcForced ); + void Load( PlayerNumber pn, MultiPlayer mp, bool bShowNoteField, int iAddToDifficulty ); + void LoadDummyP1( int iDummyIndex, int iAddToDifficulty ); void ShowOniGameOver(); MultiPlayer GetPlayerStateAndStageStatsIndex() { return m_pn == PLAYER_INVALID ? m_mp : (MultiPlayer)m_pn; } @@ -72,7 +72,7 @@ public: MultiPlayer m_mp; bool m_bIsDummy; int m_iDummyIndex; - Difficulty m_difficultyForced; // force use of Steps with this Difficulty + int m_iAddToDifficulty; // if > 0, use the Nth harder Steps bool m_bPlayerEnabled; // IsEnabled cache for iterators PlayerState m_PlayerStateDummy; PlayerStageStats m_PlayerStageStatsDummy;