migrate some stuff to PlayerState

This commit is contained in:
Glenn Maynard
2006-01-13 05:14:42 +00:00
parent e927fa4022
commit 75120c7a12
3 changed files with 56 additions and 33 deletions
+4 -33
View File
@@ -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; s<m_pPlayerState[pn]->m_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; s<NUM_INVENTORY_SLOTS; s++ )
{
m_pPlayerState[p]->m_Inventory[s].fSecsRemaining = 0;
m_pPlayerState[p]->m_Inventory[s].sModifiers = "";
}
}
m_pPlayerState[p]->RemoveAllInventory();
}
void GameState::RemoveAllActiveAttacks() // called on end of song
+48
View File
@@ -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; s<m_ActiveAttacks.size(); s++ )
{
if( al != NUM_ATTACK_LEVELS && al != m_ActiveAttacks[s].level )
continue;
m_ActiveAttacks.erase( m_ActiveAttacks.begin()+s, m_ActiveAttacks.begin()+s+1 );
--s;
}
RebuildPlayerOptionsFromActiveAttacks();
}
void PlayerState::EndActiveAttacks()
{
FOREACH( Attack, m_ActiveAttacks, a )
a->fSecsRemaining = 0;
}
void PlayerState::RemoveAllInventory()
{
for( int s=0; s<NUM_INVENTORY_SLOTS; s++ )
{
m_Inventory[s].fSecsRemaining = 0;
m_Inventory[s].sModifiers = "";
}
}
void PlayerState::RebuildPlayerOptionsFromActiveAttacks()
{
// rebuild player options
+4
View File
@@ -40,6 +40,9 @@ public:
//
// Used in Battle and Rave
//
void LaunchAttack( const Attack& a );
void RemoveActiveAttacks( AttackLevel al=NUM_ATTACK_LEVELS /*all*/ );
void EndActiveAttacks();
void RebuildPlayerOptionsFromActiveAttacks();
int GetSumOfActiveAttackLevels() const;
int m_iCpuSkill; // only used when m_PlayerController is PC_CPU
@@ -61,6 +64,7 @@ public:
//
// Used in Battle
//
void RemoveAllInventory();
Attack m_Inventory[NUM_INVENTORY_SLOTS];
// Lua