From 7f12b31439edf8257c9832a6e025946467baf1f5 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 1 Dec 2003 21:04:40 +0000 Subject: [PATCH] dynamic GAMESTATE->m_ActiveAttacks fix crash --- stepmania/src/AttackDisplay.cpp | 16 +++++++------- stepmania/src/GameState.cpp | 36 +++++++++++--------------------- stepmania/src/GameState.h | 3 +-- stepmania/src/ScreenGameplay.cpp | 2 +- 4 files changed, 21 insertions(+), 36 deletions(-) diff --git a/stepmania/src/AttackDisplay.cpp b/stepmania/src/AttackDisplay.cpp index 0078bce4e3..e67ff9fa21 100644 --- a/stepmania/src/AttackDisplay.cpp +++ b/stepmania/src/AttackDisplay.cpp @@ -28,14 +28,12 @@ void AttackDisplay::Update( float fDelta ) { ActorFrame::Update( fDelta ); - // FIXME: Make GAMESTATE->m_ActiveAttacks a vector if( GAMESTATE->m_bAttackBeganThisUpdate[m_PlayerNumber] ) { // don't handle this again GAMESTATE->m_bAttackBeganThisUpdate[m_PlayerNumber] = false; - int s; - for( s=0; sm_ActiveAttacks[m_PlayerNumber].size(); s++ ) { if( GAMESTATE->m_ActiveAttacks[m_PlayerNumber][s].fStartSecond >= 0 ) continue; /* hasn't started yet */ @@ -46,13 +44,13 @@ void AttackDisplay::Update( float fDelta ) if( GAMESTATE->m_ActiveAttacks[m_PlayerNumber][s].IsBlank() ) continue; + CString sText = GAMESTATE->m_ActiveAttacks[m_PlayerNumber][s].sModifier; + + m_textAttack.SetDiffuseAlpha( 1 ); + m_textAttack.SetText( sText ); + m_textAttack.Command( TEXT_ON_COMMAND(m_PlayerNumber) ); + break; } - - CString sText = GAMESTATE->m_ActiveAttacks[m_PlayerNumber][s].sModifier; - - m_textAttack.SetDiffuseAlpha( 1 ); - m_textAttack.SetText( sText ); - m_textAttack.Command( TEXT_ON_COMMAND(m_PlayerNumber) ); } } \ No newline at end of file diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 43a1ff793d..81f9c2e699 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -155,14 +155,14 @@ void GameState::Update( float fDelta ) { for( int p=0; p= 0 ) continue; /* hasn't started yet */ @@ -191,8 +191,7 @@ void GameState::Update( float fDelta ) continue; /* continuing */ /* ending */ - m_ActiveAttacks[p][s].fSecsRemaining = 0; - m_ActiveAttacks[p][s].sModifier = ""; + m_ActiveAttacks[p].erase( m_ActiveAttacks[p].begin()+s, m_ActiveAttacks[p].begin()+s+1 ); m_bAttackEndedThisUpdate[p] = true; RebuildPlayerOptions = true; } @@ -697,30 +696,19 @@ void GameState::LaunchAttack( PlayerNumber target, Attack a ) m_bAttackBeganThisUpdate[target] = true; - // search for an open slot - for( int s=0; sRebuildPlayerOptionsFromActiveAttacks( target ); - return; - } - } - - LOG->Warn("Couldn't launch attack '%s' against p%i: no empty attack slots", - a.sModifier.c_str(), target ); + m_ActiveAttacks[target].push_back( a ); + m_ModsToApply[target].push_back( a ); + GAMESTATE->RebuildPlayerOptionsFromActiveAttacks( target ); } void GameState::RemoveActiveAttacksForPlayer( PlayerNumber pn, AttackLevel al ) { - for( int s=0; s= 0 ) continue; /* hasn't started yet */ @@ -752,7 +740,7 @@ int GameState::GetSumOfActiveAttackLevels( PlayerNumber pn ) { int iSum = 0; - for( int s=0; s 0 && m_ActiveAttacks[pn][s].level != NUM_ATTACK_LEVELS ) iSum += m_ActiveAttacks[pn][s].level; diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index a12f90acf2..d190fa5170 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -163,8 +163,7 @@ public: StageStats m_CurStageStats; // current stage (not necessarily passed if Extra Stage) // used in PLAY_MODE_BATTLE and PLAY_MODE_RAVE - enum { MAX_SIMULTANEOUS_ATTACKS=16 }; - Attack m_ActiveAttacks[NUM_PLAYERS][MAX_SIMULTANEOUS_ATTACKS]; + AttackArray m_ActiveAttacks[NUM_PLAYERS]; vector m_ModsToApply[NUM_PLAYERS]; diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index bd5df55704..0a3a5d5128 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -760,7 +760,7 @@ void ScreenGameplay::LoadNextSong() } /* Hack: Course modifiers that are set to start immediately shouldn't tween on. */ - for( int s=0; s < GameState::MAX_SIMULTANEOUS_ATTACKS; s++ ) + for( unsigned s=0; sm_ActiveAttacks[p].size(); s++ ) { if( GAMESTATE->m_ActiveAttacks[p][s].fStartSecond == 0 ) GAMESTATE->m_ActiveAttacks[p][s].fStartSecond = -1;