#include "stdafx.h" /* ----------------------------------------------------------------------------- Class: GameState Desc: See Header. Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Chris Danford ----------------------------------------------------------------------------- */ #include "GameState.h" #include "IniFile.h" #include "GameManager.h" #include "PrefsManager.h" #include "InputMapper.h" #include "Song.h" GameState* GAMESTATE = NULL; // global and accessable from anywhere in our program GameState::GameState() { m_CurGame = GAME_DANCE; Reset(); } GameState::~GameState() { } void GameState::Reset() { int p; m_CurStyle = STYLE_NONE; m_bPlayersCanJoin = false; for( int i=0; i<2; i++ ) m_bIsJoined[i] = false; m_sPreferredGroup = ""; 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 "Demo"; else if( IsFinalStage() ) return "Final"; else if( IsExtraStage() ) return "Extra"; else if( IsExtraStage2() ) return "Extra 2"; 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 ); } D3DXCOLOR GameState::GetStageColor() { if( IsFinalStage() ) return D3DXCOLOR(1,0.1f,0.1f,1); // red else if( IsExtraStage() || IsExtraStage2() ) return D3DXCOLOR(1,1,0.3f,1); // yellow else return D3DXCOLOR(0.3f,1,0.3f,1); // green } GameDef* GameState::GetCurrentGameDef() { return GAMEMAN->GetGameDefForGame( m_CurGame ); } StyleDef* GameState::GetCurrentStyleDef() { return GAMEMAN->GetStyleDefForStyle( m_CurStyle ); } bool GameState::IsPlayerEnabled( PlayerNumber pn ) { if( m_CurStyle == STYLE_NONE ) // 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 m_bIsJoined[pn]; default: ASSERT(0); return false; } } float GameState::GetElapsedSeconds() { switch( m_PlayMode ) { case PLAY_MODE_ARCADE: return max( 0, m_fMusicSeconds ); case PLAY_MODE_ONI: case PLAY_MODE_ENDLESS: { float fSecondsTotal = 0; for( int i=0; im_fMusicLengthSeconds; fSecondsTotal += max( 0, m_fMusicSeconds ); return fSecondsTotal; } default: ASSERT(0); return 0; } } float GameState::GetPlayerSurviveTime( PlayerNumber p ) { if( m_fSecondsBeforeFail[p] == -1 ) // haven't failed yet return GetElapsedSeconds(); else return m_fSecondsBeforeFail[p]; }