From 49bbddcb7405a34b7ea31d020e9736d48225244b Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 7 May 2005 00:27:31 +0000 Subject: [PATCH] broadcast players joined and finalized --- stepmania/src/GameState.cpp | 36 +++++++++++++++++++------------- stepmania/src/GameState.h | 3 ++- stepmania/src/MessageManager.cpp | 3 +++ stepmania/src/MessageManager.h | 3 +++ stepmania/src/Screen.cpp | 13 +++--------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index c99be434c0..6953a69a20 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -233,6 +233,8 @@ void GameState::Reset() void GameState::JoinPlayer( PlayerNumber pn ) { this->m_bSideIsJoined[pn] = true; + MESSAGEMAN->Broadcast( (Message)(MESSAGE_SIDE_JOINED_P1+pn) ); + if( this->m_MasterPlayerNumber == PLAYER_INVALID ) this->m_MasterPlayerNumber = pn; @@ -241,6 +243,21 @@ void GameState::JoinPlayer( PlayerNumber pn ) this->BeginGame(); } +int GameState::GetCoinsNeededToJoin() const +{ + int iCoinsToCharge = 0; + + if( GAMESTATE->GetCoinMode() == COIN_PAY ) + iCoinsToCharge = PREFSMAN->m_iCoinsPerCredit; + + // If joint premium don't take away a credit for the 2nd join. + if( GAMESTATE->GetPremium() == PREMIUM_JOINT && + GAMESTATE->GetNumSidesJoined() == 1 ) + iCoinsToCharge = 0; + + return iCoinsToCharge; +} + /* * Game flow: * @@ -777,21 +794,6 @@ bool GameState::PlayersCanJoin() const return GetNumSidesJoined() == 0 || this->m_pCurStyle == NULL; // selecting a style finalizes the players } -bool GameState::EnoughCreditsToJoin() const -{ - switch( GAMESTATE->GetCoinMode() ) - { - case COIN_PAY: - return GAMESTATE->m_iCoins >= PREFSMAN->m_iCoinsPerCredit; - case COIN_HOME: - case COIN_FREE: - return true; - default: - ASSERT(0); - return false; - } -} - int GameState::GetNumSidesJoined() const { int iNumSidesJoined = 0; @@ -2003,6 +2005,8 @@ public: static int GetSongBeat( T* p, lua_State *L ) { lua_pushnumber(L, p->m_fSongBeat ); return 1; } static int PlayerUsingBothSides( T* p, lua_State *L ) { lua_pushboolean(L, p->PlayerUsingBothSides() ); return 1; } static int GetCoins( T* p, lua_State *L ) { lua_pushnumber(L, p->m_iCoins ); return 1; } + static int IsSideJoined( T* p, lua_State *L ) { lua_pushboolean(L, p->m_bSideIsJoined[(PlayerNumber)IArg(1)] ); return 1; } + static int GetCoinsNeededToJoin( T* p, lua_State *L ) { lua_pushnumber(L, p->GetCoinsNeededToJoin() ); return 1; } static void Register(lua_State *L) { @@ -2041,6 +2045,8 @@ public: ADD_METHOD( GetSongBeat ) ADD_METHOD( PlayerUsingBothSides ) ADD_METHOD( GetCoins ) + ADD_METHOD( IsSideJoined ) + ADD_METHOD( GetCoinsNeededToJoin ) Luna::Register( L ); diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index d3e0671713..2e0a313c99 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -72,7 +72,8 @@ public: int m_iGameSeed, m_iStageSeed; bool PlayersCanJoin() const; // true if it's not too late for a player to join - bool EnoughCreditsToJoin() const; // true if an unjoined player can join by pressint start + int GetCoinsNeededToJoin() const; + bool EnoughCreditsToJoin() const { return GetCoinsNeededToJoin() <= 0; } int GetNumSidesJoined() const; const Game* GetCurrentGame(); diff --git a/stepmania/src/MessageManager.cpp b/stepmania/src/MessageManager.cpp index 721a2038de..f8c4f3d87f 100644 --- a/stepmania/src/MessageManager.cpp +++ b/stepmania/src/MessageManager.cpp @@ -39,6 +39,9 @@ static const CString MessageNames[] = { "MadeChoiceP1", "MadeChoiceP2", "CoinInserted", + "SideJoinedP1", + "SideJoinedP2", + "PlayersFinalized", }; XToString( Message, NUM_MESSAGES ); diff --git a/stepmania/src/MessageManager.h b/stepmania/src/MessageManager.h index a97cabb458..51d634fdc7 100644 --- a/stepmania/src/MessageManager.h +++ b/stepmania/src/MessageManager.h @@ -46,6 +46,9 @@ enum Message MESSAGE_MADE_CHOICE_P1, MESSAGE_MADE_CHOICE_P2, MESSAGE_COIN_INSERTED, + MESSAGE_SIDE_JOINED_P1, + MESSAGE_SIDE_JOINED_P2, + PLAYERS_FINALIZED, NUM_MESSAGES, MESSAGE_INVALID }; diff --git a/stepmania/src/Screen.cpp b/stepmania/src/Screen.cpp index 5675f1388c..2494f65894 100644 --- a/stepmania/src/Screen.cpp +++ b/stepmania/src/Screen.cpp @@ -215,19 +215,12 @@ bool Screen::JoinInput( const MenuInput &MenuI ) return false; /* subtract coins */ - int iCoinsToCharge = 0; - if( GAMESTATE->GetCoinMode() == COIN_PAY ) - iCoinsToCharge = PREFSMAN->m_iCoinsPerCredit; + int iCoinsNeededToJoin = GAMESTATE->GetCoinsNeededToJoin(); - // If joint premium don't take away a credit for the 2nd join. - if( GAMESTATE->GetPremium() == PREMIUM_JOINT && - GAMESTATE->GetNumSidesJoined() == 1 ) - iCoinsToCharge = 0; - - if( GAMESTATE->m_iCoins < iCoinsToCharge ) + if( GAMESTATE->m_iCoins < iCoinsNeededToJoin ) return false; // not enough coins else - GAMESTATE->m_iCoins -= iCoinsToCharge; + GAMESTATE->m_iCoins -= iCoinsNeededToJoin; // HACK: Only play start sound for the 2nd player who joins. The // start sound for the 1st player will be played by ScreenTitleMenu