add multiplayer status

This commit is contained in:
Chris Danford
2006-04-21 00:43:32 +00:00
parent 63989c4aee
commit bead3edf0e
4 changed files with 43 additions and 15 deletions
+9
View File
@@ -446,6 +446,15 @@ REGISTER_WITH_LUA_FUNCTION( LuaStage );
LuaXToString( Stage ); LuaXToString( Stage );
static const char *MultiPlayerStatusNames[] = {
"Joined",
"NotJoined",
"Unplugged",
"MissingMultitap",
};
XToString( MultiPlayerStatus, NUM_MultiPlayerStatus );
/* /*
* (c) 2001-2004 Chris Danford * (c) 2001-2004 Chris Danford
* All rights reserved. * All rights reserved.
+12
View File
@@ -454,6 +454,18 @@ enum ProfileLoadResult
}; };
enum MultiPlayerStatus
{
MultiPlayerStatus_Joined,
MultiPlayerStatus_NotJoined,
MultiPlayerStatus_Unplugged,
MultiPlayerStatus_MissingMultitap,
NUM_MultiPlayerStatus,
MultiPlayerStatus_INVALID
};
const RString& MultiPlayerStatusToString( MultiPlayerStatus i );
#endif #endif
/* /*
+12 -5
View File
@@ -171,7 +171,7 @@ void GameState::Reset()
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
m_bSideIsJoined[p] = false; m_bSideIsJoined[p] = false;
FOREACH_MultiPlayer( p ) FOREACH_MultiPlayer( p )
m_bIsMultiPlayerJoined[p] = false; m_MultiPlayerStatus[p] = MultiPlayerStatus_NotJoined;
MEMCARDMAN->UnlockCards(); MEMCARDMAN->UnlockCards();
// m_iCoins = 0; // don't reset coin count! // m_iCoins = 0; // don't reset coin count!
m_MasterPlayerNumber = PLAYER_INVALID; m_MasterPlayerNumber = PLAYER_INVALID;
@@ -819,13 +819,13 @@ bool GameState::IsPlayerEnabled( PlayerNumber pn ) const
bool GameState::IsMultiPlayerEnabled( MultiPlayer mp ) const bool GameState::IsMultiPlayerEnabled( MultiPlayer mp ) const
{ {
return m_bIsMultiPlayerJoined[ mp ]; return m_MultiPlayerStatus[ mp ] == MultiPlayerStatus_Joined;
} }
bool GameState::IsPlayerEnabled( const PlayerState* pPlayerState ) const bool GameState::IsPlayerEnabled( const PlayerState* pPlayerState ) const
{ {
if( pPlayerState->m_mp != MultiPlayer_INVALID ) if( pPlayerState->m_mp != MultiPlayer_INVALID )
return m_bIsMultiPlayerJoined[ pPlayerState->m_mp ]; return IsMultiPlayerEnabled( pPlayerState->m_mp );
if( pPlayerState->m_PlayerNumber != PLAYER_INVALID ) if( pPlayerState->m_PlayerNumber != PLAYER_INVALID )
return IsPlayerEnabled( pPlayerState->m_PlayerNumber ); return IsPlayerEnabled( pPlayerState->m_PlayerNumber );
return false; return false;
@@ -1790,8 +1790,8 @@ public:
DEFINE_METHOD( IsPlayerEnabled, IsPlayerEnabled((PlayerNumber)IArg(1)) ) DEFINE_METHOD( IsPlayerEnabled, IsPlayerEnabled((PlayerNumber)IArg(1)) )
DEFINE_METHOD( IsHumanPlayer, IsHumanPlayer((PlayerNumber)IArg(1)) ) DEFINE_METHOD( IsHumanPlayer, IsHumanPlayer((PlayerNumber)IArg(1)) )
DEFINE_METHOD( GetPlayerDisplayName, GetPlayerDisplayName((PlayerNumber)IArg(1)) ) DEFINE_METHOD( GetPlayerDisplayName, GetPlayerDisplayName((PlayerNumber)IArg(1)) )
DEFINE_METHOD( GetMasterPlayerNumber, m_MasterPlayerNumber ) DEFINE_METHOD( GetMasterPlayerNumber, m_MasterPlayerNumber )
DEFINE_METHOD( GetMultiplayer, m_bMultiplayer ) DEFINE_METHOD( GetMultiplayer, m_bMultiplayer )
static int GetPlayerState( T* p, lua_State *L ) static int GetPlayerState( T* p, lua_State *L )
{ {
@@ -1799,6 +1799,12 @@ public:
p->m_pPlayerState[pn]->PushSelf(L); p->m_pPlayerState[pn]->PushSelf(L);
return 1; return 1;
} }
static int GetMultiPlayerState( T* p, lua_State *L )
{
MultiPlayer mp = (MultiPlayer)IArg(1);
p->m_pMultiPlayerState[mp]->PushSelf(L);
return 1;
}
static int ApplyGameCommand( T* p, lua_State *L ) static int ApplyGameCommand( T* p, lua_State *L )
{ {
PlayerNumber pn = PLAYER_INVALID; PlayerNumber pn = PLAYER_INVALID;
@@ -1984,6 +1990,7 @@ public:
ADD_METHOD( GetMasterPlayerNumber ); ADD_METHOD( GetMasterPlayerNumber );
ADD_METHOD( GetMultiplayer ); ADD_METHOD( GetMultiplayer );
ADD_METHOD( GetPlayerState ); ADD_METHOD( GetPlayerState );
ADD_METHOD( GetMultiPlayerState );
ADD_METHOD( ApplyGameCommand ); ADD_METHOD( ApplyGameCommand );
ADD_METHOD( GetCurrentSong ); ADD_METHOD( GetCurrentSong );
ADD_METHOD( SetCurrentSong ); ADD_METHOD( SetCurrentSong );
+10 -10
View File
@@ -55,12 +55,12 @@ public:
void SetCurGame( const Game *pGame ); // Call this instead of m_pCurGame.Set to make sure PREFSMAN->m_sCurrentGame stays in sync void SetCurGame( const Game *pGame ); // Call this instead of m_pCurGame.Set to make sure PREFSMAN->m_sCurrentGame stays in sync
BroadcastOnChangePtr<const Game> m_pCurGame; BroadcastOnChangePtr<const Game> m_pCurGame;
BroadcastOnChangePtr<const Style> m_pCurStyle; BroadcastOnChangePtr<const Style> m_pCurStyle;
bool m_bSideIsJoined[NUM_PLAYERS]; // left side, right side bool m_bSideIsJoined[NUM_PLAYERS]; // left side, right side
bool m_bIsMultiPlayerJoined[NUM_MultiPlayer]; MultiPlayerStatus m_MultiPlayerStatus[NUM_MultiPlayer];
BroadcastOnChange<PlayMode> m_PlayMode; // many screens display different info depending on this value BroadcastOnChange<PlayMode> m_PlayMode; // many screens display different info depending on this value
int m_iCoins; // not "credits" int m_iCoins; // not "credits"
PlayerNumber m_MasterPlayerNumber; // used in Styles where one player controls both sides PlayerNumber m_MasterPlayerNumber; // used in Styles where one player controls both sides
bool m_bMultiplayer; bool m_bMultiplayer;
bool DifficultiesLocked(); bool DifficultiesLocked();
bool ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc ); bool ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc );
bool ChangePreferredDifficulty( PlayerNumber pn, int dir ); bool ChangePreferredDifficulty( PlayerNumber pn, int dir );
@@ -75,10 +75,10 @@ public:
/* This is set to a random number per-game/round; it can be used for a random seed. */ /* This is set to a random number per-game/round; it can be used for a random seed. */
int m_iGameSeed, m_iStageSeed; int m_iGameSeed, m_iStageSeed;
bool PlayersCanJoin() const; // true if it's not too late for a player to join bool PlayersCanJoin() const; // true if it's not too late for a player to join
int GetCoinsNeededToJoin() const; int GetCoinsNeededToJoin() const;
bool EnoughCreditsToJoin() const { return GetCoinsNeededToJoin() <= 0; } bool EnoughCreditsToJoin() const { return GetCoinsNeededToJoin() <= 0; }
int GetNumSidesJoined() const; int GetNumSidesJoined() const;
const Game* GetCurrentGame(); const Game* GetCurrentGame();
const Style* GetCurrentStyle() const; const Style* GetCurrentStyle() const;