From bb099ee7e056ceb8c117e57bfdf1429ec7b5f58c Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 15 Feb 2005 09:24:48 +0000 Subject: [PATCH] count calories while stepping, not at the end --- stepmania/src/GameCommand.cpp | 5 ++-- stepmania/src/GameState.cpp | 3 ++- stepmania/src/Player.cpp | 42 +++++++++++++++++++++++++++++--- stepmania/src/PlayerState.h | 7 ------ stepmania/src/Profile.cpp | 13 +++------- stepmania/src/Profile.h | 4 +-- stepmania/src/ProfileManager.cpp | 6 ++--- stepmania/src/ProfileManager.h | 2 +- 8 files changed, 54 insertions(+), 28 deletions(-) diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index cac4ca7a08..882236fa9c 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -123,7 +123,7 @@ bool GameCommand::DescribesCurrentMode( PlayerNumber pn ) const return false; if( m_SortOrder != SORT_INVALID && GAMESTATE->m_PreferredSortOrder != m_SortOrder ) return false; - if( m_iWeightPounds != -1 && GAMESTATE->m_pPlayerState[pn]->m_iWeightPounds != m_iWeightPounds ) + if( m_iWeightPounds != -1 && PROFILEMAN->IsUsingProfile(pn) && PROFILEMAN->GetProfile(pn)->m_iWeightPounds != m_iWeightPounds ) return false; if( m_iStopCourseAtSeconds != -1 && GAMESTATE->m_iStopCourseAtSeconds != m_iStopCourseAtSeconds ) return false; @@ -642,7 +642,8 @@ void GameCommand::Apply( const vector &vpns ) const SOUND->PlayOnce( THEME->GetPathToS( m_sSoundPath ) ); if( m_iWeightPounds != -1 ) FOREACH_CONST( PlayerNumber, vpns, pn ) - GAMESTATE->m_pPlayerState[*pn]->m_iWeightPounds = m_iWeightPounds; + if( PROFILEMAN->IsUsingProfile(*pn) ) + PROFILEMAN->GetProfile(*pn)->m_iWeightPounds = m_iWeightPounds; if( m_iStopCourseAtSeconds != -1 ) GAMESTATE->m_iStopCourseAtSeconds = m_iStopCourseAtSeconds; diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index a6b0f41b64..33c38f429d 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -652,7 +652,8 @@ void GameState::FinishStage() int iNumHolds = (int) g_CurStageStats.m_player[pn].radarActual[RADAR_NUM_HOLDS]; int iNumMines = (int) g_CurStageStats.m_player[pn].radarActual[RADAR_NUM_MINES]; int iNumHands = (int) g_CurStageStats.m_player[pn].radarActual[RADAR_NUM_HANDS]; - PROFILEMAN->AddStepTotals( pn, iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands ); + float fCaloriesBurned = g_CurStageStats.m_player[pn].fCaloriesBurned; + PROFILEMAN->AddStepTotals( pn, iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands, fCaloriesBurned ); } diff --git a/stepmania/src/Player.cpp b/stepmania/src/Player.cpp index 842461bdc2..3c3f75bade 100644 --- a/stepmania/src/Player.cpp +++ b/stepmania/src/Player.cpp @@ -37,6 +37,7 @@ #include "GameSoundManager.h" #include "Style.h" #include "MessageManager.h" +#include "ProfileManager.h" CString JUDGMENT_X_NAME( size_t p, size_t both_sides ) { return "JudgmentXOffset" + (both_sides ? CString("BothSides") : ssprintf("OneSideP%d",p+1) ); } CString COMBO_X_NAME( size_t p, size_t both_sides ) { return "ComboXOffset" + (both_sides ? CString("BothSides") : ssprintf("OneSideP%d",p+1) ); } @@ -693,10 +694,45 @@ void Player::HandleStep( int col, const RageTimer &tm ) // // Count calories for this step. // - if( m_pPlayerStageStats ) + if( m_pPlayerStageStats && m_pPlayerState ) { - // FIXME: - m_pPlayerStageStats->fCaloriesBurned += randomf( 1.f, 2.f ); + // TODO: remove use of PlayerNumber + PlayerNumber pn = m_pPlayerState->m_PlayerNumber; + Profile* pProfile = PROFILEMAN->GetProfile(pn); + if( pProfile ) + { + int iLbs = pProfile->m_iWeightPounds; + if( iLbs != 0 ) + { + int iNumTracksHeld = 0; + for( unsigned t=0; tGetCurrentStyle()->StyleInputToGameInput( StyleI ); + float fSecsHeld = INPUTMAPPER->GetSecsHeld( GameI ); + if( fSecsHeld > 0 ) + iNumTracksHeld++; + } + + float fCals = 0; + switch( iNumTracksHeld ) + { + case 0: + // autoplay is on, or this is a computer player + fCals = 0; + break; + default: + { + float fCalsFor100Lbs = SCALE( iNumTracksHeld, 1, 2, 0.029f, 0.222f ); + float fCalsFor200Lbs = SCALE( iNumTracksHeld, 1, 2, 0.052f, 0.386f ); + fCals = SCALE( iLbs, 100.f, 200.f, fCalsFor100Lbs, fCalsFor200Lbs ); + } + break; + } + + m_pPlayerStageStats->fCaloriesBurned += fCals; + } + } } diff --git a/stepmania/src/PlayerState.h b/stepmania/src/PlayerState.h index be9ae54ae3..c1c61a03ad 100644 --- a/stepmania/src/PlayerState.h +++ b/stepmania/src/PlayerState.h @@ -42,8 +42,6 @@ struct PlayerState for( int i=0; iGetMachineProfile()->m_iNumToasties; } -void ProfileManager::AddStepTotals( PlayerNumber pn, int iNumTapsAndHolds, int iNumJumps, int iNumHolds, int iNumMines, int iNumHands ) +void ProfileManager::AddStepTotals( PlayerNumber pn, int iNumTapsAndHolds, int iNumJumps, int iNumHolds, int iNumMines, int iNumHands, float fCaloriesBurned ) { if( PROFILEMAN->IsUsingProfile(pn) ) - PROFILEMAN->GetProfile(pn)->AddStepTotals( iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands ); - PROFILEMAN->GetMachineProfile()->AddStepTotals( iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands ); + PROFILEMAN->GetProfile(pn)->AddStepTotals( iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands, fCaloriesBurned ); + PROFILEMAN->GetMachineProfile()->AddStepTotals( iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands, fCaloriesBurned ); } // diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index cba3fee31a..c1b0e244a5 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -37,7 +37,7 @@ public: // General data // void IncrementToastiesCount( PlayerNumber pn ); - void AddStepTotals( PlayerNumber pn, int iNumTapsAndHolds, int iNumJumps, int iNumHolds, int iNumMines, int iNumHands ); + void AddStepTotals( PlayerNumber pn, int iNumTapsAndHolds, int iNumJumps, int iNumHolds, int iNumMines, int iNumHands, float fCaloriesBurned ); //