convert ints and casts to use PlayerNumber and macros

This commit is contained in:
Chris Danford
2004-08-30 04:35:14 +00:00
parent 081c1e24b5
commit cf9b4af6cb
9 changed files with 110 additions and 157 deletions
+8 -5
View File
@@ -436,13 +436,16 @@ void BGAnimationLayer::LoadFromIni( CString sAniDir, CString sLayer )
int player; int player;
if( ini.GetValue( sLayer, "Player", player ) ) if( ini.GetValue( sLayer, "Player", player ) )
{ {
if( player > 0 && player <= NUM_PLAYERS ) PlayerNumber pn = (PlayerNumber)(player-1);
if( pn>=0 && pn<NUM_PLAYERS )
{ {
if( !GAMESTATE->IsPlayerEnabled(player-1) ) if( !GAMESTATE->IsPlayerEnabled(pn) )
return; return;
} else }
LOG->Warn("BGA \"%s\" %s has an invalid Player field", else
sAniDir.c_str(), sLayer.c_str() ); {
LOG->Warn("BGA \"%s\" %s has an invalid Player field", sAniDir.c_str(), sLayer.c_str() );
}
} }
} }
+6 -13
View File
@@ -71,7 +71,7 @@ BeginnerHelper::~BeginnerHelper()
{ {
} }
void BeginnerHelper::ShowStepCircle( int pn, int CSTEP ) void BeginnerHelper::ShowStepCircle( PlayerNumber pn, int CSTEP )
{ {
int isc=0; // Save OR issues within array boundries.. it's worth the extra few bytes of memory. int isc=0; // Save OR issues within array boundries.. it's worth the extra few bytes of memory.
switch(CSTEP) switch(CSTEP)
@@ -89,7 +89,7 @@ void BeginnerHelper::ShowStepCircle( int pn, int CSTEP )
m_sStepCircle[pn][isc].SetZoom(0); m_sStepCircle[pn][isc].SetZoom(0);
} }
void BeginnerHelper::AddPlayer( int pn, NoteData *pSteps ) void BeginnerHelper::AddPlayer( PlayerNumber pn, NoteData *pSteps )
{ {
ASSERT(!m_bInitialized); ASSERT(!m_bInitialized);
ASSERT(pSteps != NULL); ASSERT(pSteps != NULL);
@@ -268,7 +268,7 @@ void BeginnerHelper::DrawPrimitives()
} }
} }
void BeginnerHelper::Step( int pn, int CSTEP ) void BeginnerHelper::Step( PlayerNumber pn, int CSTEP )
{ {
m_pDancer[pn]->StopTweening(); m_pDancer[pn]->StopTweening();
m_pDancer[pn]->SetRotationY(0); // Make sure we're not still inside of a JUMPUD tween. m_pDancer[pn]->SetRotationY(0); // Make sure we're not still inside of a JUMPUD tween.
@@ -324,12 +324,8 @@ void BeginnerHelper::Update( float fDeltaTime )
// the row we want to check on this update // the row we want to check on this update
int iCurRow = BeatToNoteRowNotRounded(GAMESTATE->m_fSongBeat + 0.4f); int iCurRow = BeatToNoteRowNotRounded(GAMESTATE->m_fSongBeat + 0.4f);
for(int pn=0; pn<NUM_PLAYERS; pn++) FOREACH_EnabledPlayer( pn )
{ {
// Skip if not enabled
if(!m_bPlayerEnabled[pn])
continue;
for(int iRow=m_iLastRowChecked; iRow<iCurRow; iRow++) for(int iRow=m_iLastRowChecked; iRow<iCurRow; iRow++)
{ {
// Check if there are any notes at all on this row.. If not, save scanning. // Check if there are any notes at all on this row.. If not, save scanning.
@@ -357,12 +353,9 @@ void BeginnerHelper::Update( float fDeltaTime )
m_sFlash.Update(fDeltaTime); m_sFlash.Update(fDeltaTime);
float beat = (fDeltaTime*GAMESTATE->m_fCurBPS); float beat = (fDeltaTime*GAMESTATE->m_fCurBPS);
for(int pu=0; pu<NUM_PLAYERS; pu++)
{
// If this is not a human player, the dancer is not shown // If this is not a human player, the dancer is not shown
if(!GAMESTATE->IsHumanPlayer(pu)) FOREACH_HumanPlayer( pu )
continue; {
// Update dancer's animation and StepCircles // Update dancer's animation and StepCircles
m_pDancer[pu]->Update( beat ); m_pDancer[pu]->Update( beat );
for(int scu=0; scu<NUM_PLAYERS; scu++) for(int scu=0; scu<NUM_PLAYERS; scu++)
+3 -3
View File
@@ -17,15 +17,15 @@ public:
bool Initialize( int iDancePadType ); bool Initialize( int iDancePadType );
bool IsInitialized() { return m_bInitialized; } bool IsInitialized() { return m_bInitialized; }
static bool CanUse(); static bool CanUse();
void AddPlayer( int pn, NoteData *pSteps ); void AddPlayer( PlayerNumber pn, NoteData *pSteps );
void ShowStepCircle( int pn, int CSTEP ); void ShowStepCircle( PlayerNumber pn, int CSTEP );
bool m_bShowBackground; bool m_bShowBackground;
void Update( float fDeltaTime ); void Update( float fDeltaTime );
virtual void DrawPrimitives(); virtual void DrawPrimitives();
protected: protected:
void Step( int pn, int CSTEP ); void Step( PlayerNumber pn, int CSTEP );
NoteData m_NoteData[NUM_PLAYERS]; NoteData m_NoteData[NUM_PLAYERS];
bool m_bPlayerEnabled[NUM_PLAYERS]; bool m_bPlayerEnabled[NUM_PLAYERS];
+7 -23
View File
@@ -372,9 +372,7 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
bool foundmatchingdiff=false; bool foundmatchingdiff=false;
for(unsigned d=0;d<info.difficulties.size();d++) for(unsigned d=0;d<info.difficulties.size();d++)
{ {
for(unsigned pn=0; pn<NUM_PLAYERS;pn++) FOREACH_EnabledPlayer( pn )
{
if(GAMESTATE->IsPlayerEnabled(pn))
{ {
if(GAMESTATE->m_pCurSteps[pn] != NULL) if(GAMESTATE->m_pCurSteps[pn] != NULL)
{ {
@@ -387,7 +385,6 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
} }
} }
} }
}
valid = foundmatchingdiff; valid = foundmatchingdiff;
} }
@@ -395,9 +392,7 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
{ {
PlayerOptions po = info.disallowedpo; PlayerOptions po = info.disallowedpo;
bool bModsValid = true; bool bModsValid = true;
for(unsigned pn=0;pn<NUM_PLAYERS;pn++) FOREACH_EnabledPlayer( pn )
{
if(GAMESTATE->IsPlayerEnabled(pn))
{ {
unsigned md; unsigned md;
for(md=0;md<PlayerOptions::NUM_ACCELS;md++) for(md=0;md<PlayerOptions::NUM_ACCELS;md++)
@@ -440,9 +435,6 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
LOG->Info("Found Invalid Transform Mod"); LOG->Info("Found Invalid Transform Mod");
} }
} }
}
} }
valid = bModsValid; valid = bModsValid;
} }
@@ -454,9 +446,7 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
for(unsigned d=0;d<info.songmeters.size();d++) for(unsigned d=0;d<info.songmeters.size();d++)
{ {
LOG->Info("MeterRating: %d",info.songmeters[d]); LOG->Info("MeterRating: %d",info.songmeters[d]);
for(int pn=0;pn<NUM_PLAYERS;pn++) FOREACH_EnabledPlayer( pn )
{
if(GAMESTATE->IsPlayerEnabled(pn))
{ {
if(GAMESTATE->m_pCurSteps[pn] != NULL) if(GAMESTATE->m_pCurSteps[pn] != NULL)
{ {
@@ -478,7 +468,6 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
} }
} }
} }
}
valid = foundmatchingmeter; valid = foundmatchingmeter;
} }
@@ -509,17 +498,14 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
{ {
LOG->Info("Checking Single Grade"); LOG->Info("Checking Single Grade");
bool foundaplayerwithgrade = false; bool foundaplayerwithgrade = false;
for(unsigned pn=0; pn<NUM_PLAYERS;pn++) FOREACH_EnabledPlayer( pn )
{ {
if(GAMESTATE->IsPlayerEnabled(pn)) if(g_CurStageStats.GetGrade(pn) == info.grades[0])
{
if(g_CurStageStats.GetGrade((PlayerNumber)pn) == info.grades[0])
{ {
LOG->Info("Found Valid Grade"); LOG->Info("Found Valid Grade");
foundaplayerwithgrade = true; foundaplayerwithgrade = true;
} }
} }
}
foundmatchinggrades = foundaplayerwithgrade; foundmatchinggrades = foundaplayerwithgrade;
} }
else if(g_vPlayedStageStats.size() < info.grades.size()) // we've not played enough stages to achieve a grade history condition else if(g_vPlayedStageStats.size() < info.grades.size()) // we've not played enough stages to achieve a grade history condition
@@ -622,8 +608,7 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
} }
else if(info.cleared == CBGA_CSMAXCOMBO) else if(info.cleared == CBGA_CSMAXCOMBO)
{ {
for(unsigned pn=0;pn<NUM_PLAYERS;pn++) FOREACH_EnabledPlayer( pn )
if(GAMESTATE->IsPlayerEnabled(pn))
if(g_CurStageStats.FullCombo((PlayerNumber)pn)) if(g_CurStageStats.FullCombo((PlayerNumber)pn))
{ {
foundclearcond = true; foundclearcond = true;
@@ -632,8 +617,7 @@ void ConditionalBGA::CheckBgaRequirements(BgaCondInfo info)
} }
else if(info.cleared == CBGA_CSBROKECOMBO) else if(info.cleared == CBGA_CSBROKECOMBO)
{ {
for(unsigned pn=0;pn<NUM_PLAYERS;pn++) FOREACH_EnabledPlayer( pn )
if(GAMESTATE->IsPlayerEnabled(pn))
if(!g_CurStageStats.FullCombo((PlayerNumber)pn)) if(!g_CurStageStats.FullCombo((PlayerNumber)pn))
{ {
LOG->Info("BrokenCombo Condition"); LOG->Info("BrokenCombo Condition");
-3
View File
@@ -75,16 +75,13 @@ public:
void GetPlayerInfo( PlayerNumber pn, bool& bIsEnabledOut, bool& bIsHumanOut ); void GetPlayerInfo( PlayerNumber pn, bool& bIsEnabledOut, bool& bIsHumanOut );
bool IsPlayerEnabled( PlayerNumber pn ) const; bool IsPlayerEnabled( PlayerNumber pn ) const;
bool IsPlayerEnabled( int p ) const { return IsPlayerEnabled( (PlayerNumber)p ); };
int GetNumPlayersEnabled() const; int GetNumPlayersEnabled() const;
bool PlayerUsingBothSides() const; bool PlayerUsingBothSides() const;
bool IsHumanPlayer( PlayerNumber pn ) const; bool IsHumanPlayer( PlayerNumber pn ) const;
bool IsHumanPlayer( int p ) const { return IsHumanPlayer( (PlayerNumber)p ); };
int GetNumHumanPlayers() const; int GetNumHumanPlayers() const;
PlayerNumber GetFirstHumanPlayer() const; PlayerNumber GetFirstHumanPlayer() const;
bool IsCpuPlayer( PlayerNumber pn ) const; bool IsCpuPlayer( PlayerNumber pn ) const;
bool IsCpuPlayer( int p ) const { return IsCpuPlayer( (PlayerNumber)p ); };
bool AnyPlayersAreCpu() const; bool AnyPlayersAreCpu() const;
void GetCharacters( vector<Character*> &apCharactersOut ); void GetCharacters( vector<Character*> &apCharactersOut );
+6 -7
View File
@@ -22,18 +22,17 @@ ScreenEndlessBreak::ScreenEndlessBreak( CString sName ) : Screen( sName )
m_sprBreakPicture.Load( THEME->GetPathToG("Common fallback takingabreak") ); m_sprBreakPicture.Load( THEME->GetPathToG("Common fallback takingabreak") );
else if( GAMESTATE->GetNumPlayersEnabled() > 1 ) // More than 1 player is present. else if( GAMESTATE->GetNumPlayersEnabled() > 1 ) // More than 1 player is present.
{ {
int PlayerToUse = 999; /* If this was 0 by default, the first player would PlayerNumber pn;
always be selected. Make it an insane number so do
we always generate a random player. */
while (!GAMESTATE->IsPlayerEnabled(PlayerToUse))
{ {
PlayerToUse = (int)(rand()*NUM_PLAYERS); // Is there a danger of this becoming an endless loop?? pn = (PlayerNumber)(rand()%NUM_PLAYERS);
if( (GAMESTATE->IsPlayerEnabled(PlayerToUse)) && (GAMESTATE->m_pCurCharacters[PlayerToUse] != NULL) ) if( GAMESTATE->IsPlayerEnabled(pn) && (GAMESTATE->m_pCurCharacters[pn] != NULL) )
{ {
m_sprBreakPicture.LoadTABreakFromCharacter( GAMESTATE->m_pCurCharacters[PlayerToUse] ); m_sprBreakPicture.LoadTABreakFromCharacter( GAMESTATE->m_pCurCharacters[pn] );
break; break;
} }
} }
while( !GAMESTATE->IsPlayerEnabled(pn) );
} }
} }
else // Characters not enabled. else // Characters not enabled.
+2 -10
View File
@@ -307,11 +307,8 @@ void ScreenOptions::Init( InputMode im, OptionRowData OptionRows[], int iNumOpti
if( row.m_bRowIsLong ) if( row.m_bRowIsLong )
{ {
// init text // init text
for( unsigned p=0; p<NUM_PLAYERS; p++ ) FOREACH_HumanPlayer( p )
{ {
if( !GAMESTATE->IsHumanPlayer(p) )
continue; // skip
BitmapText *bt = new BitmapText; BitmapText *bt = new BitmapText;
textItems.push_back( bt ); textItems.push_back( bt );
@@ -334,12 +331,8 @@ void ScreenOptions::Init( InputMode im, OptionRowData OptionRows[], int iNumOpti
} }
// init underlines // init underlines
FOREACH_HumanPlayer( p )
{ {
for( unsigned p=0; p<NUM_PLAYERS; p++ )
{
if( !GAMESTATE->IsHumanPlayer(p) )
continue; // skip
OptionsCursor *ul = new OptionsCursor; OptionsCursor *ul = new OptionsCursor;
row.m_Underline[p].push_back( ul ); row.m_Underline[p].push_back( ul );
ul->Load( (PlayerNumber)p, true ); ul->Load( (PlayerNumber)p, true );
@@ -349,7 +342,6 @@ void ScreenOptions::Init( InputMode im, OptionRowData OptionRows[], int iNumOpti
ul->SetWidth( float(iWidth) ); ul->SetWidth( float(iWidth) );
} }
} }
}
// Add children here and not above because of the logic that starts // Add children here and not above because of the logic that starts
// over if we run off the right edge of the screen. // over if we run off the right edge of the screen.
+2 -9
View File
@@ -277,9 +277,7 @@ void ScreenSelectMode::SetCharacters()
GAMESTATE->GetCharacters( apCharactersToUse ); GAMESTATE->GetCharacters( apCharactersToUse );
} }
} }
for(int pn=0; pn<NUM_PLAYERS; pn++) FOREACH_EnabledPlayer( pn )
{
if(GAMESTATE->IsPlayerEnabled(pn))
{ {
if(ENABLE_CHAR_SELECT && m_iCurrentChar[pn] != -1) if(ENABLE_CHAR_SELECT && m_iCurrentChar[pn] != -1)
{ {
@@ -287,8 +285,6 @@ void ScreenSelectMode::SetCharacters()
GAMESTATE->m_pCurCharacters[pn] = pChar; GAMESTATE->m_pCurCharacters[pn] = pChar;
} }
} }
}
} }
void ScreenSelectMode::MenuStart( PlayerNumber pn ) void ScreenSelectMode::MenuStart( PlayerNumber pn )
@@ -345,16 +341,13 @@ void ScreenSelectMode::Update( float fDelta )
void ScreenSelectMode::DrawPrimitives() void ScreenSelectMode::DrawPrimitives()
{ {
ScreenSelect::DrawPrimitives(); ScreenSelect::DrawPrimitives();
for(int pn=0; pn<NUM_PLAYERS; pn++) FOREACH_EnabledPlayer( pn )
{
if(GAMESTATE->IsPlayerEnabled(pn))
{ {
if(ENABLE_CHAR_SELECT) if(ENABLE_CHAR_SELECT)
{ {
m_CurChar[pn].Draw(); m_CurChar[pn].Draw();
} }
} }
}
} }
// todo: optimize the following - Frieza // todo: optimize the following - Frieza
+6 -14
View File
@@ -248,7 +248,7 @@ bool StageStats::OnePassed() const
bool StageStats::AllFailed() const bool StageStats::AllFailed() const
{ {
FOREACH_PlayerNumber( pn ) FOREACH_PlayerNumber( pn )
if( GAMESTATE->IsPlayerEnabled(PlayerNumber(pn)) ) if( GAMESTATE->IsPlayerEnabled(pn) )
if( !bFailed[pn] ) if( !bFailed[pn] )
return false; return false;
return true; return true;
@@ -462,24 +462,16 @@ float StageStats::GetPercentageOfTaps( PlayerNumber pn, TapNoteScore tns ) const
static Grade GetBestGrade() static Grade GetBestGrade()
{ {
Grade g = NUM_GRADES; Grade g = NUM_GRADES;
for( unsigned pn=0; pn<NUM_PLAYERS; ++pn ) FOREACH_EnabledPlayer( pn )
{ g = min( g, g_CurStageStats.GetGrade( pn ) );
if( !GAMESTATE->IsPlayerEnabled(pn) )
continue;
g = min( g, g_CurStageStats.GetGrade( (PlayerNumber)pn ) );
}
return g; return g;
} }
static Grade GetWorstGrade() static Grade GetWorstGrade()
{ {
Grade g = GRADE_TIER_1; Grade g = GRADE_TIER_1;
for( unsigned pn=0; pn<NUM_PLAYERS; ++pn ) FOREACH_EnabledPlayer( pn )
{ g = max( g, g_CurStageStats.GetGrade( pn ) );
if( !GAMESTATE->IsPlayerEnabled(pn) )
continue;
g = max( g, g_CurStageStats.GetGrade( (PlayerNumber)pn ) );
}
return g; return g;
} }
@@ -516,7 +508,7 @@ Grade GetGrade( int n, PlayerNumber pn )
bool OneGotGrade( int n, Grade g ) bool OneGotGrade( int n, Grade g )
{ {
FOREACH_HumanPlayer( pn ) FOREACH_HumanPlayer( pn )
if( GetGrade( n, (PlayerNumber)pn ) == g ) if( GetGrade( n, pn ) == g )
return true; return true;
return false; return false;