From 995b441180af56adc369cd526b6d70f44bfbad15 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 23 Aug 2005 20:55:58 +0000 Subject: [PATCH] store PlayerStates for MultiPlayers --- stepmania/src/GameState.cpp | 54 ++++++++++++++++++++++++++++--------- stepmania/src/GameState.h | 20 ++++++++------ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index a65ae1b764..c777c1898e 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -101,6 +101,12 @@ GameState::GameState() : m_pPlayerState[p] = new PlayerState; m_pPlayerState[p]->m_PlayerNumber = p; } + FOREACH_MultiPlayer( p ) + { + m_pMultiPlayerState[p] = new PlayerState; + m_pMultiPlayerState[p]->m_PlayerNumber = PLAYER_1; + m_pMultiPlayerState[p]->m_mp = p; + } m_Environment = new LuaTable; @@ -115,6 +121,8 @@ GameState::~GameState() { FOREACH_PlayerNumber( p ) SAFE_DELETE( m_pPlayerState[p] ); + FOREACH_MultiPlayer( p ) + SAFE_DELETE( m_pMultiPlayerState[p] ); SAFE_DELETE( m_Environment ); @@ -171,6 +179,7 @@ void GameState::Reset() MEMCARDMAN->UnlockCards(); // m_iCoins = 0; // don't reset coin count! m_MasterPlayerNumber = PLAYER_INVALID; + m_bMultiplayer = false; m_mapEnv.clear(); m_sPreferredSongGroup.Set( GROUP_ALL ); m_sPreferredCourseGroup.Set( GROUP_ALL ); @@ -207,6 +216,8 @@ void GameState::Reset() FOREACH_PlayerNumber( p ) m_pPlayerState[p]->Reset(); + FOREACH_MultiPlayer( p ) + m_pMultiPlayerState[p]->Reset(); ResetMusicStatistics(); ResetStageStatistics(); @@ -783,6 +794,20 @@ bool GameState::IsPlayerEnabled( PlayerNumber pn ) const return IsHumanPlayer( pn ); } +bool GameState::IsMultiPlayerEnabled( MultiPlayer mp ) const +{ + return m_bIsMultiPlayerJoined[ mp ]; +} + +bool GameState::IsPlayerEnabled( const PlayerState* pPlayerState ) const +{ + if( pPlayerState->m_mp != MultiPlayer_INVALID ) + return m_bIsMultiPlayerJoined[ pPlayerState->m_mp ]; + if( pPlayerState->m_PlayerNumber != PLAYER_INVALID ) + return IsPlayerEnabled( pPlayerState->m_PlayerNumber ); + return false; +} + int GameState::GetNumPlayersEnabled() const { int count = 0; @@ -1017,14 +1042,14 @@ bool GameState::IsDisqualified( PlayerNumber pn ) void GameState::ResetNoteSkins() { FOREACH_PlayerNumber( pn ) - ResetNoteSkinsForPlayer( pn ); + ResetNoteSkinsForPlayer( m_pPlayerState[pn] ); ++m_BeatToNoteSkinRev; } -void GameState::ResetNoteSkinsForPlayer( PlayerNumber pn ) +void GameState::ResetNoteSkinsForPlayer( PlayerState *ps ) { - m_pPlayerState[pn]->ResetNoteSkins(); + ps->ResetNoteSkins(); ++m_BeatToNoteSkinRev; } @@ -1129,7 +1154,7 @@ void GameState::SetNoteSkinForBeatRange( PlayerState* pPlayerState, const CStrin /* 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( PlayerNumber target, const Attack& a ) +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 ); @@ -1195,8 +1220,9 @@ void setmax( T &a, const T &b ) a = max(a, b); } -SongOptions::FailType GameState::GetPlayerFailType( PlayerNumber pn ) const +SongOptions::FailType GameState::GetPlayerFailType( const PlayerState *pPlayerState ) const { + PlayerNumber pn = pPlayerState->m_PlayerNumber; SongOptions::FailType ft = m_SongOptions.m_FailType; /* If the player changed the fail mode explicitly, leave it alone. */ @@ -1739,25 +1765,25 @@ Premium GameState::GetPremium() return PREFSMAN->m_Premium; } -bool GameState::IsPlayerHot( PlayerNumber pn ) const +bool GameState::IsPlayerHot( const PlayerState *pPlayerState ) const { - return GAMESTATE->m_pPlayerState[pn]->m_HealthState == PlayerState::HOT; + return pPlayerState->m_HealthState == PlayerState::HOT; } -bool GameState::IsPlayerInDanger( PlayerNumber pn ) const +bool GameState::IsPlayerInDanger( const PlayerState *pPlayerState ) const { - if( GAMESTATE->GetPlayerFailType(pn) == SongOptions::FAIL_OFF ) + if( GAMESTATE->GetPlayerFailType(pPlayerState) == SongOptions::FAIL_OFF ) return false; if( !PREFSMAN->m_bShowDanger ) return false; - return GAMESTATE->m_pPlayerState[pn]->m_HealthState == PlayerState::DANGER; + return pPlayerState->m_HealthState == PlayerState::DANGER; } -bool GameState::IsPlayerDead( PlayerNumber pn ) const +bool GameState::IsPlayerDead( const PlayerState *pPlayerState ) const { - if( GAMESTATE->GetPlayerFailType(pn) == SongOptions::FAIL_OFF ) + if( GAMESTATE->GetPlayerFailType(pPlayerState) == SongOptions::FAIL_OFF ) return false; - return GAMESTATE->m_pPlayerState[pn]->m_HealthState == PlayerState::DEAD; + return pPlayerState->m_HealthState == PlayerState::DEAD; } float GameState::GetGoalPercentComplete( PlayerNumber pn ) @@ -1858,6 +1884,7 @@ public: static int IsHumanPlayer( T* p, lua_State *L ) { lua_pushboolean(L, p->IsHumanPlayer((PlayerNumber)IArg(1)) ); return 1; } static int GetPlayerDisplayName( T* p, lua_State *L ) { lua_pushstring(L, p->GetPlayerDisplayName((PlayerNumber)IArg(1)) ); return 1; } static int GetMasterPlayerNumber( T* p, lua_State *L ) { lua_pushnumber(L, p->m_MasterPlayerNumber ); return 1; } + static int GetMultiplayer( T* p, lua_State *L ) { lua_pushnumber(L, p->m_bMultiplayer); return 1; } static int ApplyGameCommand( T* p, lua_State *L ) { PlayerNumber pn = PLAYER_INVALID; @@ -1982,6 +2009,7 @@ public: ADD_METHOD( IsHumanPlayer ) ADD_METHOD( GetPlayerDisplayName ) ADD_METHOD( GetMasterPlayerNumber ) + ADD_METHOD( GetMultiplayer ) ADD_METHOD( ApplyGameCommand ) ADD_METHOD( GetCurrentSong ) ADD_METHOD( SetCurrentSong ) diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 069edba5a4..1a8a3a1558 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -24,8 +24,8 @@ class Game; class Style; class Character; class TimingData; -struct StageStats; -struct PlayerState; +class StageStats; +class PlayerState; struct lua_State; class LuaTable; class Profile; @@ -58,6 +58,7 @@ public: BroadcastOnChange m_PlayMode; // many screens display different info depending on this value int m_iCoins; // not "credits" PlayerNumber m_MasterPlayerNumber; // used in Styles where one player controls both sides + bool m_bMultiplayer; BroadcastOnChange1D m_PreferredCourseDifficulty;// used in nonstop bool DifficultiesLocked(); bool ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc ); @@ -83,6 +84,8 @@ public: void GetPlayerInfo( PlayerNumber pn, bool& bIsEnabledOut, bool& bIsHumanOut ); bool IsPlayerEnabled( PlayerNumber pn ) const; + bool IsMultiPlayerEnabled( MultiPlayer mp ) const; + bool IsPlayerEnabled( const PlayerState* pPlayerState ) const; int GetNumPlayersEnabled() const; bool PlayerUsingBothSides() const; @@ -161,7 +164,7 @@ public: int m_BeatToNoteSkinRev; /* hack: incremented whenever m_BeatToNoteSkin changes */ void ResetNoteSkins(); - void ResetNoteSkinsForPlayer( PlayerNumber pn ); + void ResetNoteSkinsForPlayer( PlayerState *ps ); void GetAllUsedNoteSkins( vector &out ) const; static const float MUSIC_SECONDS_INVALID; @@ -170,9 +173,9 @@ public: void UpdateSongPosition( float fPositionSeconds, const TimingData &timing, const RageTimer ×tamp = RageZeroTimer ); float GetSongPercent( float beat ) const; - bool IsPlayerHot( PlayerNumber pn ) const; - bool IsPlayerInDanger( PlayerNumber pn ) const; - bool IsPlayerDead( PlayerNumber pn ) const; + bool IsPlayerHot( const PlayerState *pPlayerState ) const; + bool IsPlayerInDanger( const PlayerState *pPlayerState ) const; + bool IsPlayerDead( const PlayerState *pPlayerState ) const; bool AllAreInDangerOrWorse() const; bool AllAreDead() const; bool AllHumanHaveComboOf30OrMoreMisses() const; @@ -191,7 +194,7 @@ public: bool m_bGoalComplete[NUM_PLAYERS]; void GetUndisplayedBeats( const PlayerState* pPlayerState, float TotalSeconds, float &StartBeat, float &EndBeat ) const; // only meaningful when a NoteField is in use - void LaunchAttack( PlayerNumber target, const Attack& a ); + void LaunchAttack( MultiPlayer target, const Attack& a ); void RemoveAllActiveAttacks(); // called on end of song void RemoveActiveAttacksForPlayer( PlayerNumber pn, AttackLevel al=NUM_ATTACK_LEVELS /*all*/ ); void EndActiveAttacksForPlayer( PlayerNumber pn ); @@ -220,7 +223,7 @@ public: bool IsDisqualified( PlayerNumber pn ); bool PlayerIsUsingModifier( PlayerNumber pn, const CString &sModifier ); - SongOptions::FailType GetPlayerFailType( PlayerNumber pn ) const; + SongOptions::FailType GetPlayerFailType( const PlayerState *pPlayerState ) const; // character stuff Character* m_pCurCharacters[NUM_PLAYERS]; @@ -272,6 +275,7 @@ public: // PlayerState // PlayerState* m_pPlayerState[NUM_PLAYERS]; + PlayerState* m_pMultiPlayerState[NUM_MultiPlayer]; // // Preference wrappers