broadcast players joined and finalized

This commit is contained in:
Chris Danford
2005-05-07 00:27:31 +00:00
parent 820fb0b361
commit 49bbddcb74
5 changed files with 32 additions and 26 deletions
+21 -15
View File
@@ -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<T>::Register( L );
+2 -1
View File
@@ -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();
+3
View File
@@ -39,6 +39,9 @@ static const CString MessageNames[] = {
"MadeChoiceP1",
"MadeChoiceP2",
"CoinInserted",
"SideJoinedP1",
"SideJoinedP2",
"PlayersFinalized",
};
XToString( Message, NUM_MESSAGES );
+3
View File
@@ -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
};
+3 -10
View File
@@ -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