From 75120c7a121da98700e4d2e91c44b7a3a90ae1a9 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 13 Jan 2006 05:14:42 +0000 Subject: [PATCH] migrate some stuff to PlayerState --- stepmania/src/GameState.cpp | 37 +++------------------------ stepmania/src/PlayerState.cpp | 48 +++++++++++++++++++++++++++++++++++ stepmania/src/PlayerState.h | 4 +++ 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index bad7aab838..12a82380c4 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1135,54 +1135,25 @@ void GameState::GetUndisplayedBeats( const PlayerState* pPlayerState, float Tota } -/* This is called to launch an attack, or to queue an attack if a.fStartSecond - * is set. This is also called by GameState::Update when activating a queued attack. */ void GameState::LaunchAttack( MultiPlayer target, const Attack& a ) { - LOG->Trace( "Launch attack '%s' against P%d at %f", a.sModifiers.c_str(), target+1, a.fStartSecond ); - - Attack attack = a; - - /* If fStartSecond is -1, it means "launch as soon as possible". For m_ActiveAttacks, - * mark the real time it's starting (now), so Update() can know when the attack started - * so it can be removed later. For m_ModsToApply, leave the -1 in, so Player::Update - * knows to apply attack transforms correctly. (yuck) */ - m_pPlayerState[target]->m_ModsToApply.push_back( attack ); - if( attack.fStartSecond == -1 ) - attack.fStartSecond = this->m_fMusicSeconds; - m_pPlayerState[target]->m_ActiveAttacks.push_back( attack ); - - m_pPlayerState[target]->RebuildPlayerOptionsFromActiveAttacks(); + m_pPlayerState[target]->LaunchAttack( a ); } void GameState::RemoveActiveAttacksForPlayer( PlayerNumber pn, AttackLevel al ) { - for( unsigned s=0; sm_ActiveAttacks.size(); s++ ) - { - if( al != NUM_ATTACK_LEVELS && al != m_pPlayerState[pn]->m_ActiveAttacks[s].level ) - continue; - m_pPlayerState[pn]->m_ActiveAttacks.erase( m_pPlayerState[pn]->m_ActiveAttacks.begin()+s, m_pPlayerState[pn]->m_ActiveAttacks.begin()+s+1 ); - --s; - } - m_pPlayerState[pn]->RebuildPlayerOptionsFromActiveAttacks(); + m_pPlayerState[pn]->RemoveActiveAttacks( al ); } void GameState::EndActiveAttacksForPlayer( PlayerNumber pn ) { - FOREACH( Attack, m_pPlayerState[pn]->m_ActiveAttacks, a ) - a->fSecsRemaining = 0; + m_pPlayerState[pn]->EndActiveAttacks(); } void GameState::RemoveAllInventory() { FOREACH_PlayerNumber( p ) - { - for( int s=0; sm_Inventory[s].fSecsRemaining = 0; - m_pPlayerState[p]->m_Inventory[s].sModifiers = ""; - } - } + m_pPlayerState[p]->RemoveAllInventory(); } void GameState::RemoveAllActiveAttacks() // called on end of song diff --git a/stepmania/src/PlayerState.cpp b/stepmania/src/PlayerState.cpp index 31865128cb..eda4470471 100644 --- a/stepmania/src/PlayerState.cpp +++ b/stepmania/src/PlayerState.cpp @@ -1,6 +1,7 @@ #include "global.h" #include "PlayerState.h" #include "GameState.h" +#include "RageLog.h" PlayerState::PlayerState() { @@ -84,6 +85,53 @@ void PlayerState::Update( float fDelta ) m_fSecondsUntilAttacksPhasedOut = max( 0, m_fSecondsUntilAttacksPhasedOut - fDelta ); } +/* This is called to launch an attack, or to queue an attack if a.fStartSecond + * is set. This is also called by GameState::Update when activating a queued attack. */ +void PlayerState::LaunchAttack( const Attack& a ) +{ + LOG->Trace( "Launch attack '%s' against P%d at %f", a.sModifiers.c_str(), m_mp+1, a.fStartSecond ); + + Attack attack = a; + + /* If fStartSecond is -1, it means "launch as soon as possible". For m_ActiveAttacks, + * mark the real time it's starting (now), so Update() can know when the attack started + * so it can be removed later. For m_ModsToApply, leave the -1 in, so Player::Update + * knows to apply attack transforms correctly. (yuck) */ + m_ModsToApply.push_back( attack ); + if( attack.fStartSecond == -1 ) + attack.fStartSecond = GAMESTATE->m_fMusicSeconds; + m_ActiveAttacks.push_back( attack ); + + RebuildPlayerOptionsFromActiveAttacks(); +} + +void PlayerState::RemoveActiveAttacks( AttackLevel al ) +{ + for( unsigned s=0; sfSecsRemaining = 0; +} + +void PlayerState::RemoveAllInventory() +{ + for( int s=0; s