#include "global.h" #include "PlayerState.h" #include "GameState.h" #include "RageLog.h" PlayerState::PlayerState() { m_PlayerNumber = PLAYER_INVALID; m_mp = MultiPlayer_INVALID; Reset(); } void PlayerState::Reset() { m_CurrentPlayerOptions.Init(); m_PlayerOptions.Init(); m_StagePlayerOptions.Init(); m_StoredPlayerOptions.Init(); m_fLastDrawnBeat = -100; m_HealthState = ALIVE; m_PlayerController = PC_HUMAN; m_iCpuSkill = 5; m_iLastPositiveSumOfAttackLevels = 0; m_fSecondsUntilAttacksPhasedOut = 0; m_bAttackBeganThisUpdate = false; m_bAttackEndedThisUpdate = false; m_ActiveAttacks.clear(); m_ModsToApply.clear(); m_fSuperMeter = 0; // between 0 and NUM_ATTACK_LEVELS m_fSuperMeterGrowthScale = 1; for( int i=0; iUpdate is run before any of the Screen update's, // so we'll clear these flags here and let them get turned on later m_bAttackBeganThisUpdate = false; m_bAttackEndedThisUpdate = false; bool bRebuildPlayerOptions = false; /* See if any delayed attacks are starting or ending. */ for( unsigned s=0; sm_fMusicSeconds && GAMESTATE->m_fMusicSeconds < attack.fStartSecond+attack.fSecsRemaining ); if( m_ActiveAttacks[s].bOn == bCurrentlyEnabled ) continue; /* OK */ if( m_ActiveAttacks[s].bOn && !bCurrentlyEnabled ) m_bAttackEndedThisUpdate = true; else if( !m_ActiveAttacks[s].bOn && bCurrentlyEnabled ) m_bAttackBeganThisUpdate = true; bRebuildPlayerOptions = true; m_ActiveAttacks[s].bOn = bCurrentlyEnabled; } if( bRebuildPlayerOptions ) RebuildPlayerOptionsFromActiveAttacks(); if( m_fSecondsUntilAttacksPhasedOut > 0 ) 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 0 ) { m_iLastPositiveSumOfAttackLevels = iSumOfAttackLevels; m_fSecondsUntilAttacksPhasedOut = 10000; // any positive number that won't run out before the attacks } else { // don't change! m_iLastPositiveSumOfAttackLevels[p] = iSumOfAttackLevels; m_fSecondsUntilAttacksPhasedOut = 2; // 2 seconds to phase out } } int PlayerState::GetSumOfActiveAttackLevels() const { int iSum = 0; for( unsigned s=0; s 0 && m_ActiveAttacks[s].level != NUM_ATTACK_LEVELS ) iSum += m_ActiveAttacks[s].level; return iSum; } // lua start #include "LuaBinding.h" class LunaPlayerState: public Luna { public: LunaPlayerState() { LUA->Register( Register ); } static void Register(lua_State *L) { Luna::Register( L ); } }; LUA_REGISTER_CLASS( PlayerState ) // lua end /* * (c) 2001-2004 Chris Danford, Chris Gomez * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, and/or sell copies of the Software, and to permit persons to * whom the Software is furnished to do so, provided that the above * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */