#include "stdafx.h" /* ----------------------------------------------------------------------------- Class: GameState Desc: See Header. Copyright (c) 2001-2003 by the person(s) listed below. All rights reserved. Chris Danford Chris Gomez ----------------------------------------------------------------------------- */ #include "GameState.h" #include "IniFile.h" #include "GameManager.h" #include "PrefsManager.h" #include "InputMapper.h" #include "Song.h" #include "RageLog.h" #include "ThemeManager.h" GameState* GAMESTATE = NULL; // global and accessable from anywhere in our program #define STAGE_COLOR_DEMO THEME->GetMetricC("GameState","StageColorDemo") #define STAGE_COLOR( i ) THEME->GetMetricC("GameState",ssprintf("StageColor%d",i+1)) #define STAGE_COLOR_FINAL THEME->GetMetricC("GameState","StageColorFinal") #define STAGE_COLOR_EXTRA1 THEME->GetMetricC("GameState","StageColorExtra1") #define STAGE_COLOR_EXTRA2 THEME->GetMetricC("GameState","StageColorExtra2") #define STAGE_COLOR_NONSTOP THEME->GetMetricC("GameState","StageColorNonstop") #define STAGE_COLOR_ONI THEME->GetMetricC("GameState","StageColorOni") #define STAGE_COLOR_ENDLESS THEME->GetMetricC("GameState","StageColorEndless") #define STAGE_TEXT_DEMO THEME->GetMetric("GameState","StageTextDemo") #define STAGE_TEXT_FINAL THEME->GetMetric("GameState","StageTextFinal") #define STAGE_TEXT_EXTRA1 THEME->GetMetric("GameState","StageTextExtra1") #define STAGE_TEXT_EXTRA2 THEME->GetMetric("GameState","StageTextExtra2") GameState::GameState() { m_CurGame = GAME_DANCE; m_iCoins = 0; Reset(); ResetLastRanking(); } GameState::~GameState() { } void GameState::Reset() { int p; m_CurStyle = STYLE_INVALID; m_bPlayersCanJoin = false; for( p=0; pm_bEventMode ) return false; return m_iCurrentStageIndex == PREFSMAN->m_iNumArcadeStages-1; } bool GameState::IsExtraStage() { if( PREFSMAN->m_bEventMode ) return false; return m_iCurrentStageIndex == PREFSMAN->m_iNumArcadeStages; } bool GameState::IsExtraStage2() { if( PREFSMAN->m_bEventMode ) return false; return m_iCurrentStageIndex == PREFSMAN->m_iNumArcadeStages+1; } CString GameState::GetStageText() { if( m_bDemonstration ) return STAGE_TEXT_DEMO; else if( IsFinalStage() ) return STAGE_TEXT_FINAL; else if( IsExtraStage() ) return STAGE_TEXT_EXTRA1; else if( IsExtraStage2() ) return STAGE_TEXT_EXTRA2; int iStageNo = m_iCurrentStageIndex+1; CString sNumberSuffix; if( ( (iStageNo/10) % 10 ) == 1 ) // in the teens (e.g. 19, 213) { sNumberSuffix = "th"; } else // not in the teens { const int iLastDigit = iStageNo%10; switch( iLastDigit ) { case 1: sNumberSuffix = "st"; break; case 2: sNumberSuffix = "nd"; break; case 3: sNumberSuffix = "rd"; break; default:sNumberSuffix = "th"; break; } } return ssprintf( "%d%s", iStageNo, sNumberSuffix.GetString() ); } RageColor GameState::GetStageColor() { if( m_bDemonstration ) return STAGE_COLOR_DEMO; else if( m_PlayMode==PLAY_MODE_NONSTOP ) return STAGE_COLOR_NONSTOP; else if( m_PlayMode==PLAY_MODE_ONI ) return STAGE_COLOR_ONI; else if( m_PlayMode==PLAY_MODE_ENDLESS ) return STAGE_COLOR_ENDLESS; else if( IsFinalStage() ) return STAGE_COLOR_FINAL; else if( IsExtraStage() ) return STAGE_COLOR_EXTRA1; else if( IsExtraStage2() ) return STAGE_COLOR_EXTRA2; else return STAGE_COLOR( min(m_iCurrentStageIndex,4) ); } GameDef* GameState::GetCurrentGameDef() { ASSERT( m_CurGame != GAME_INVALID ); // the game must be set before calling this return GAMEMAN->GetGameDefForGame( m_CurGame ); } const StyleDef* GameState::GetCurrentStyleDef() { ASSERT( m_CurStyle != STYLE_INVALID ); // the style must be set before calling this return GAMEMAN->GetStyleDefForStyle( m_CurStyle ); } bool GameState::IsPlayerEnabled( PlayerNumber pn ) { if( m_CurStyle == STYLE_INVALID ) // if no style set (we're in TitleMenu, ConfigInstruments or something) return true; // allow input from both sides switch( GetCurrentStyleDef()->m_StyleType ) { case StyleDef::TWO_PLAYERS_TWO_CREDITS: return true; case StyleDef::ONE_PLAYER_ONE_CREDIT: case StyleDef::ONE_PLAYER_TWO_CREDITS: return pn == m_MasterPlayerNumber; default: ASSERT(0); // invalid style type return false; } } bool GameState::HasEarnedExtraStage() { if( (GAMESTATE->IsFinalStage() || GAMESTATE->IsExtraStage()) ) { for( int p=0; pIsPlayerEnabled(p) ) continue; // skip if( GAMESTATE->m_pCurNotes[p]->GetDifficulty()==DIFFICULTY_HARD && m_CurStageStats.GetGrade((PlayerNumber)p)==GRADE_AA ) return true; } } return false; } void GameState::GetFinalEvalStatsAndSongs( StageStats& statsOut, vector& vSongsOut ) { statsOut = StageStats(); // Show stats only for the latest 3 normal songs + passed extra stages int iNumSongsToThrowAway = max( 0, PREFSMAN->m_iNumArcadeStages-3 ); for( unsigned i=iNumSongsToThrowAway; im_vPassedStageStats.size(); i++ ) { statsOut += GAMESTATE->m_vPassedStageStats[i]; vSongsOut.push_back( GAMESTATE->m_vPassedStageStats[i].pSong ); } }