Use FOREACH_*

This commit is contained in:
Steve Checkoway
2004-05-16 12:34:02 +00:00
parent e3585798f8
commit b023ee4d94
+69 -110
View File
@@ -113,7 +113,7 @@ void ScreenGameplay::Init()
//need to initialize these before checking for demonstration mode //need to initialize these before checking for demonstration mode
//otherwise destructor will try to delete possibly invalid pointers //otherwise destructor will try to delete possibly invalid pointers
for( p=0; p<NUM_PLAYERS; p++ ) FOREACH_PlayerNumber(p)
{ {
m_pLifeMeter[p] = NULL; m_pLifeMeter[p] = NULL;
m_pPrimaryScoreDisplay[p] = NULL; m_pPrimaryScoreDisplay[p] = NULL;
@@ -150,9 +150,8 @@ void ScreenGameplay::Init()
// fill in difficulty of CPU players with that of the first human player // fill in difficulty of CPU players with that of the first human player
for( p=0; p<NUM_PLAYERS; p++ ) FOREACH_CpuPlayer(p)
if( GAMESTATE->IsCpuPlayer(p) ) GAMESTATE->m_pCurNotes[p] = GAMESTATE->m_pCurNotes[ GAMESTATE->GetFirstHumanPlayer() ];
GAMESTATE->m_pCurNotes[p] = GAMESTATE->m_pCurNotes[ GAMESTATE->GetFirstHumanPlayer() ];
switch( GAMESTATE->m_PlayMode ) switch( GAMESTATE->m_PlayMode )
{ {
@@ -187,11 +186,10 @@ void ScreenGameplay::Init()
const StepsType st = GAMESTATE->GetCurrentStyleDef()->m_StepsType; const StepsType st = GAMESTATE->GetCurrentStyleDef()->m_StepsType;
/* Increment the play count. */ /* Increment the play count. */
if( !m_bDemonstration ) if( !m_bDemonstration )
for( p=0; p<NUM_PLAYERS; p++ ) FOREACH_EnabledPlayer(p)
if( GAMESTATE->IsPlayerEnabled(p) ) PROFILEMAN->IncrementCoursePlayCount( GAMESTATE->m_pCurCourse, st, GAMESTATE->m_PreferredCourseDifficulty[p], (PlayerNumber)p );
PROFILEMAN->IncrementCoursePlayCount( GAMESTATE->m_pCurCourse, st, GAMESTATE->m_PreferredCourseDifficulty[p], (PlayerNumber)p );
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_PlayerNumber(p)
{ {
vector<Course::Info> ci; vector<Course::Info> ci;
GAMESTATE->m_pCurCourse->GetCourseInfo( GAMESTATE->GetCurrentStyleDef()->m_StepsType, ci, GAMESTATE->m_PreferredCourseDifficulty[p] ); GAMESTATE->m_pCurCourse->GetCourseInfo( GAMESTATE->GetCurrentStyleDef()->m_StepsType, ci, GAMESTATE->m_PreferredCourseDifficulty[p] );
@@ -221,7 +219,7 @@ void ScreenGameplay::Init()
else else
{ {
m_apSongsQueue.push_back( GAMESTATE->m_pCurSong ); m_apSongsQueue.push_back( GAMESTATE->m_pCurSong );
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_PlayerNumber(p)
{ {
m_apNotesQueue[p].push_back( GAMESTATE->m_pCurNotes[p] ); m_apNotesQueue[p].push_back( GAMESTATE->m_pCurNotes[p] );
m_asModifiersQueue[p].push_back( AttackArray() ); m_asModifiersQueue[p].push_back( AttackArray() );
@@ -236,10 +234,8 @@ void ScreenGameplay::Init()
g_CurStageStats.style = GAMESTATE->m_CurStyle; g_CurStageStats.style = GAMESTATE->m_CurStyle;
for( p=0; p<NUM_PLAYERS; p++ ) for( p=0; p<NUM_PLAYERS; p++ )
FOREACH_EnabledPlayer(p)
{ {
if( !GAMESTATE->IsPlayerEnabled(p) )
continue; // skip
ASSERT( !m_apNotesQueue[p].empty() ); ASSERT( !m_apNotesQueue[p].empty() );
g_CurStageStats.pSteps[p] = m_apNotesQueue[p][0]; g_CurStageStats.pSteps[p] = m_apNotesQueue[p][0];
g_CurStageStats.iMeter[p] = m_apNotesQueue[p][0]->GetMeter(); g_CurStageStats.iMeter[p] = m_apNotesQueue[p][0]->GetMeter();
@@ -258,12 +254,10 @@ void ScreenGameplay::Init()
// //
// Init ScoreKeepers // Init ScoreKeepers
// //
for( p=0; p<NUM_PLAYERS; p++ )
{
if( !GAMESTATE->IsPlayerEnabled(p) )
continue; // skip
switch( PREFSMAN->m_iScoringType ) FOREACH_PlayerNumber(p)
{
switch( PREFSMAN->m_iScoringType )
{ {
case PrefsManager::SCORING_MAX2: case PrefsManager::SCORING_MAX2:
case PrefsManager::SCORING_5TH: case PrefsManager::SCORING_5TH:
@@ -317,11 +311,8 @@ void ScreenGameplay::Init()
this->AddChild( &m_Toasty ); this->AddChild( &m_Toasty );
} }
for( p=0; p<NUM_PLAYERS; p++ ) FOREACH_EnabledPlayer(p)
{ {
if( !GAMESTATE->IsPlayerEnabled(PlayerNumber(p)) )
continue;
float fPlayerX = (float) GAMESTATE->GetCurrentStyleDef()->m_iCenterX[p]; float fPlayerX = (float) GAMESTATE->GetCurrentStyleDef()->m_iCenterX[p];
/* Perhaps this should be handled better by defining a new /* Perhaps this should be handled better by defining a new
@@ -417,7 +408,7 @@ void ScreenGameplay::Init()
case PLAY_MODE_ONI: case PLAY_MODE_ONI:
case PLAY_MODE_NONSTOP: case PLAY_MODE_NONSTOP:
case PLAY_MODE_ENDLESS: case PLAY_MODE_ENDLESS:
for( p=0; p<NUM_PLAYERS; p++ ) FOREACH_PlayerNumber(p)
{ {
if( !GAMESTATE->IsPlayerEnabled(p) && !SHOW_LIFE_METER_FOR_DISABLED_PLAYERS ) if( !GAMESTATE->IsPlayerEnabled(p) && !SHOW_LIFE_METER_FOR_DISABLED_PLAYERS )
continue; // skip continue; // skip
@@ -467,11 +458,8 @@ void ScreenGameplay::Init()
m_MaxCombo.SetText( ssprintf("%d", g_CurStageStats.iMaxCombo[GAMESTATE->m_MasterPlayerNumber]) ); // TODO: Make this work for both players m_MaxCombo.SetText( ssprintf("%d", g_CurStageStats.iMaxCombo[GAMESTATE->m_MasterPlayerNumber]) ); // TODO: Make this work for both players
this->AddChild( &m_MaxCombo ); this->AddChild( &m_MaxCombo );
for( p=0; p<NUM_PLAYERS; p++ ) FOREACH_EnabledPlayer(p)
{ {
if( !GAMESTATE->IsPlayerEnabled(p) )
continue;
// //
// primary score display // primary score display
// //
@@ -834,9 +822,8 @@ void ScreenGameplay::SetupSong( int p, int iSongIndex )
static int GetMaxSongsPlayed() static int GetMaxSongsPlayed()
{ {
int SongNumber = 0; int SongNumber = 0;
FOREACH_PlayerNumber(p) FOREACH_EnabledPlayer(p)
if( GAMESTATE->IsPlayerEnabled(p) ) SongNumber = max( SongNumber, g_CurStageStats.iSongsPlayed[p] );
SongNumber = max( SongNumber, g_CurStageStats.iSongsPlayed[p] );
return SongNumber; return SongNumber;
} }
@@ -1241,49 +1228,44 @@ void ScreenGameplay::Update( float fDeltaTime )
//LOG->Trace( "m_fOffsetInBeats = %f, m_fBeatsPerSecond = %f, m_Music.GetPositionSeconds = %f", m_fOffsetInBeats, m_fBeatsPerSecond, m_Music.GetPositionSeconds() ); //LOG->Trace( "m_fOffsetInBeats = %f, m_fBeatsPerSecond = %f, m_Music.GetPositionSeconds = %f", m_fOffsetInBeats, m_fBeatsPerSecond, m_Music.GetPositionSeconds() );
int pn;
m_BeginnerHelper.Update(fDeltaTime); m_BeginnerHelper.Update(fDeltaTime);
// //
// update GameState HealthState // update GameState HealthState
// //
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_EnabledPlayer(p)
{ {
if( GAMESTATE->IsPlayerEnabled(p) ) if(
(m_pLifeMeter[p] && m_pLifeMeter[p]->IsHot()) ||
(m_pCombinedLifeMeter && m_pCombinedLifeMeter->IsHot((PlayerNumber)p)) )
{ {
if( GAMESTATE->m_HealthState[p] = GameState::HOT;
(m_pLifeMeter[p] && m_pLifeMeter[p]->IsHot()) || }
(m_pCombinedLifeMeter && m_pCombinedLifeMeter->IsHot((PlayerNumber)p)) ) else if(
{ (m_pLifeMeter[p] && m_pLifeMeter[p]->IsFailing()) ||
GAMESTATE->m_HealthState[p] = GameState::HOT; (m_pCombinedLifeMeter && m_pCombinedLifeMeter->IsFailing((PlayerNumber)p)) )
} {
else if( GAMESTATE->m_HealthState[p] = GameState::DEAD;
(m_pLifeMeter[p] && m_pLifeMeter[p]->IsFailing()) || }
(m_pCombinedLifeMeter && m_pCombinedLifeMeter->IsFailing((PlayerNumber)p)) ) else if(
{ (m_pLifeMeter[p] && m_pLifeMeter[p]->IsInDanger()) ||
GAMESTATE->m_HealthState[p] = GameState::DEAD; (m_pCombinedLifeMeter && m_pCombinedLifeMeter->IsInDanger((PlayerNumber)p)) )
} {
else if( GAMESTATE->m_HealthState[p] = GameState::DANGER;
(m_pLifeMeter[p] && m_pLifeMeter[p]->IsInDanger()) || }
(m_pCombinedLifeMeter && m_pCombinedLifeMeter->IsInDanger((PlayerNumber)p)) ) else
{ {
GAMESTATE->m_HealthState[p] = GameState::DANGER; GAMESTATE->m_HealthState[p] = GameState::ALIVE;
}
else
{
GAMESTATE->m_HealthState[p] = GameState::ALIVE;
}
} }
} }
switch( m_DancingState ) switch( m_DancingState )
{ {
case STATE_DANCING: case STATE_DANCING:
// //
// Update living players' alive time // Update living players' alive time
// //
for( pn=0; pn<NUM_PLAYERS; pn++ ) FOREACH_PlayerNumber(pn)
if( GAMESTATE->IsPlayerEnabled(pn) && !g_CurStageStats.bFailed[pn]) if( GAMESTATE->IsPlayerEnabled(pn) && !g_CurStageStats.bFailed[pn])
g_CurStageStats.fAliveSeconds [pn] += fDeltaTime * GAMESTATE->m_SongOptions.m_fMusicRate; g_CurStageStats.fAliveSeconds [pn] += fDeltaTime * GAMESTATE->m_SongOptions.m_fMusicRate;
@@ -1309,10 +1291,9 @@ void ScreenGameplay::Update( float fDeltaTime )
// //
// update 2d dancing characters // update 2d dancing characters
// //
for( int p=0; p<NUM_PLAYERS; p++ )
FOREACH_EnabledPlayer(p)
{ {
if( !GAMESTATE->IsPlayerEnabled(p) )
continue;
if(m_Background.GetDancingCharacters() != NULL) if(m_Background.GetDancingCharacters() != NULL)
{ {
if(m_Player[p].GetDancingCharacterState() != AS2D_IGNORE) // grab the state of play from player and update the character if(m_Player[p].GetDancingCharacterState() != AS2D_IGNORE) // grab the state of play from player and update the character
@@ -1336,15 +1317,12 @@ void ScreenGameplay::Update( float fDeltaTime )
GAMESTATE->RemoveAllActiveAttacks(); GAMESTATE->RemoveAllActiveAttacks();
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_CpuPlayer(p)
{ {
if( GAMESTATE->IsCpuPlayer(p) ) SOUND->PlayOnceFromDir( THEME->GetPathToS("ScreenGameplay oni die") );
{ ShowOniGameOver((PlayerNumber)p);
SOUND->PlayOnceFromDir( THEME->GetPathToS("ScreenGameplay oni die") ); m_Player[p].Init(); // remove all notes and scoring
ShowOniGameOver((PlayerNumber)p); m_Player[p].FadeToFail(); // tell the NoteField to fade to white
m_Player[p].Init(); // remove all notes and scoring
m_Player[p].FadeToFail(); // tell the NoteField to fade to white
}
} }
} }
} }
@@ -1696,19 +1674,12 @@ void ScreenGameplay::Input( const DeviceInput& DeviceI, const InputEventType typ
bool bIsHoldingShift = bool bIsHoldingShift =
INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RSHIFT)) || INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RSHIFT)) ||
INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LSHIFT)); INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LSHIFT));
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_HumanPlayer(p)
{ {
if( GAMESTATE->IsHumanPlayer(p) ) if( bIsHoldingShift )
{ GAMESTATE->m_PlayerController[p] = PREFSMAN->m_bAutoPlay ? PC_CPU : PC_HUMAN;
if( bIsHoldingShift ) else
{ GAMESTATE->m_PlayerController[p] = PREFSMAN->m_bAutoPlay ? PC_AUTOPLAY : PC_HUMAN;
GAMESTATE->m_PlayerController[p] = PREFSMAN->m_bAutoPlay ? PC_CPU : PC_HUMAN;
}
else
{
GAMESTATE->m_PlayerController[p] = PREFSMAN->m_bAutoPlay ? PC_AUTOPLAY : PC_HUMAN;
}
}
} }
} }
break; break;
@@ -1907,11 +1878,8 @@ void ScreenGameplay::SongFinished()
{ {
LOG->Trace("SongFinished"); LOG->Trace("SongFinished");
// save any statistics // save any statistics
int p; FOREACH_EnabledPlayer(p)
for( p=0; p<NUM_PLAYERS; p++ )
{ {
if( !GAMESTATE->IsPlayerEnabled(p) )
continue;
for( int r=0; r<NUM_RADAR_CATEGORIES; r++ ) for( int r=0; r<NUM_RADAR_CATEGORIES; r++ )
{ {
/* Note that adding stats is only meaningful for the counters (eg. RADAR_NUM_JUMPS), /* Note that adding stats is only meaningful for the counters (eg. RADAR_NUM_JUMPS),
@@ -1937,11 +1905,8 @@ void ScreenGameplay::StageFinished( bool bBackedOut )
iPlaySongIndex < m_apSongsQueue.size(); ++iPlaySongIndex ) iPlaySongIndex < m_apSongsQueue.size(); ++iPlaySongIndex )
{ {
LOG->Trace("Running stats for %i", iPlaySongIndex ); LOG->Trace("Running stats for %i", iPlaySongIndex );
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_EnabledPlayer(p)
{ {
if( !GAMESTATE->IsPlayerEnabled(p) )
continue;
SetupSong( p, iPlaySongIndex ); SetupSong( p, iPlaySongIndex );
m_Player[p].ApplyWaitingTransforms(); m_Player[p].ApplyWaitingTransforms();
SongFinished(); SongFinished();
@@ -1987,12 +1952,8 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM )
* m_NextSongOut finishes. */ * m_NextSongOut finishes. */
// GAMESTATE->RemoveAllActiveAttacks(); // GAMESTATE->RemoveAllActiveAttacks();
int p; FOREACH_EnabledPlayer(p)
for( p=0; p<NUM_PLAYERS; p++ )
{ {
if( !GAMESTATE->IsPlayerEnabled(p) )
continue;
/* If either player's passmark is enabled, check it. */ /* If either player's passmark is enabled, check it. */
if( GAMESTATE->m_PlayerOptions[p].m_fPassmark > 0 && if( GAMESTATE->m_PlayerOptions[p].m_fPassmark > 0 &&
m_pLifeMeter[p] && m_pLifeMeter[p] &&
@@ -2020,15 +1981,17 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM )
if( !bAllReallyFailed && !IsLastSong() ) if( !bAllReallyFailed && !IsLastSong() )
{ {
/* Next song. */ /* Next song. */
for( p=0; p<NUM_PLAYERS; p++ ) FOREACH_EnabledPlayer(p)
if( GAMESTATE->IsPlayerEnabled(p) && !g_CurStageStats.bFailed[p] ) {
{ if( !g_CurStageStats.bFailed[p] )
// give a little life back between stages {
if( m_pLifeMeter[p] ) // give a little life back between stages
m_pLifeMeter[p]->OnSongEnded(); if( m_pLifeMeter[p] )
if( m_pCombinedLifeMeter ) m_pLifeMeter[p]->OnSongEnded();
m_pCombinedLifeMeter->OnSongEnded(); if( m_pCombinedLifeMeter )
} m_pCombinedLifeMeter->OnSongEnded();
}
}
// HACK: Temporarily set the song pointer to the next song so that // HACK: Temporarily set the song pointer to the next song so that
// this m_NextSongOut will show the next song banner // this m_NextSongOut will show the next song banner
@@ -2050,11 +2013,8 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM )
// update dancing characters for win / lose // update dancing characters for win / lose
DancingCharacters *Dancers = m_Background.GetDancingCharacters(); DancingCharacters *Dancers = m_Background.GetDancingCharacters();
if( Dancers ) if( Dancers )
for( p=0; p<NUM_PLAYERS; p++ ) FOREACH_EnabledPlayer(p)
{ {
if( !GAMESTATE->IsPlayerEnabled(p) )
continue;
/* XXX: In battle modes, switch( GAMESTATE->GetStageResult(p) ). */ /* XXX: In battle modes, switch( GAMESTATE->GetStageResult(p) ). */
if( g_CurStageStats.bFailed[p] ) if( g_CurStageStats.bFailed[p] )
Dancers->Change2DAnimState( p, AS2D_FAIL ); // fail anim Dancers->Change2DAnimState( p, AS2D_FAIL ); // fail anim
@@ -2249,9 +2209,8 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM )
if( GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2() ) if( GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2() )
{ {
float fMaxSurviveSeconds = 0; float fMaxSurviveSeconds = 0;
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_EnabledPlayer(p)
if( GAMESTATE->IsPlayerEnabled(p) ) fMaxSurviveSeconds = max( fMaxSurviveSeconds, g_CurStageStats.fAliveSeconds[p] );
fMaxSurviveSeconds = max( fMaxSurviveSeconds, g_CurStageStats.fAliveSeconds[p] );
ASSERT( fMaxSurviveSeconds > 0 ); ASSERT( fMaxSurviveSeconds > 0 );
m_textSurviveTime.SetText( "TIME: " + SecondsToMMSSMsMs(fMaxSurviveSeconds) ); m_textSurviveTime.SetText( "TIME: " + SecondsToMMSSMsMs(fMaxSurviveSeconds) );
SET_XY_AND_ON_COMMAND( m_textSurviveTime ); SET_XY_AND_ON_COMMAND( m_textSurviveTime );
@@ -2328,7 +2287,7 @@ void ScreenGameplay::TweenOnScreen()
ON_COMMAND( m_meterSongPosition ); ON_COMMAND( m_meterSongPosition );
if( m_pCombinedLifeMeter ) if( m_pCombinedLifeMeter )
ON_COMMAND( *m_pCombinedLifeMeter ); ON_COMMAND( *m_pCombinedLifeMeter );
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_PlayerNumber(p)
{ {
if( m_pLifeMeter[p] ) if( m_pLifeMeter[p] )
ON_COMMAND( *m_pLifeMeter[p] ); ON_COMMAND( *m_pLifeMeter[p] );
@@ -2361,7 +2320,7 @@ void ScreenGameplay::TweenOffScreen()
OFF_COMMAND( m_meterSongPosition ); OFF_COMMAND( m_meterSongPosition );
if( m_pCombinedLifeMeter ) if( m_pCombinedLifeMeter )
OFF_COMMAND( *m_pCombinedLifeMeter ); OFF_COMMAND( *m_pCombinedLifeMeter );
for( int p=0; p<NUM_PLAYERS; p++ ) FOREACH_PlayerNumber(p)
{ {
if( m_pLifeMeter[p] ) if( m_pLifeMeter[p] )
OFF_COMMAND( *m_pLifeMeter[p] ); OFF_COMMAND( *m_pLifeMeter[p] );