store PlayerStates for MultiPlayers

This commit is contained in:
Chris Danford
2005-08-23 20:55:58 +00:00
parent 5a19510ead
commit 995b441180
2 changed files with 53 additions and 21 deletions
+41 -13
View File
@@ -101,6 +101,12 @@ GameState::GameState() :
m_pPlayerState[p] = new PlayerState; m_pPlayerState[p] = new PlayerState;
m_pPlayerState[p]->m_PlayerNumber = p; 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; m_Environment = new LuaTable;
@@ -115,6 +121,8 @@ GameState::~GameState()
{ {
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
SAFE_DELETE( m_pPlayerState[p] ); SAFE_DELETE( m_pPlayerState[p] );
FOREACH_MultiPlayer( p )
SAFE_DELETE( m_pMultiPlayerState[p] );
SAFE_DELETE( m_Environment ); SAFE_DELETE( m_Environment );
@@ -171,6 +179,7 @@ void GameState::Reset()
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;
m_bMultiplayer = false;
m_mapEnv.clear(); m_mapEnv.clear();
m_sPreferredSongGroup.Set( GROUP_ALL ); m_sPreferredSongGroup.Set( GROUP_ALL );
m_sPreferredCourseGroup.Set( GROUP_ALL ); m_sPreferredCourseGroup.Set( GROUP_ALL );
@@ -207,6 +216,8 @@ void GameState::Reset()
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
m_pPlayerState[p]->Reset(); m_pPlayerState[p]->Reset();
FOREACH_MultiPlayer( p )
m_pMultiPlayerState[p]->Reset();
ResetMusicStatistics(); ResetMusicStatistics();
ResetStageStatistics(); ResetStageStatistics();
@@ -783,6 +794,20 @@ bool GameState::IsPlayerEnabled( PlayerNumber pn ) const
return IsHumanPlayer( pn ); 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 GameState::GetNumPlayersEnabled() const
{ {
int count = 0; int count = 0;
@@ -1017,14 +1042,14 @@ bool GameState::IsDisqualified( PlayerNumber pn )
void GameState::ResetNoteSkins() void GameState::ResetNoteSkins()
{ {
FOREACH_PlayerNumber( pn ) FOREACH_PlayerNumber( pn )
ResetNoteSkinsForPlayer( pn ); ResetNoteSkinsForPlayer( m_pPlayerState[pn] );
++m_BeatToNoteSkinRev; ++m_BeatToNoteSkinRev;
} }
void GameState::ResetNoteSkinsForPlayer( PlayerNumber pn ) void GameState::ResetNoteSkinsForPlayer( PlayerState *ps )
{ {
m_pPlayerState[pn]->ResetNoteSkins(); ps->ResetNoteSkins();
++m_BeatToNoteSkinRev; ++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 /* 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. */ * 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 ); 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); 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; SongOptions::FailType ft = m_SongOptions.m_FailType;
/* If the player changed the fail mode explicitly, leave it alone. */ /* If the player changed the fail mode explicitly, leave it alone. */
@@ -1739,25 +1765,25 @@ Premium GameState::GetPremium()
return PREFSMAN->m_Premium; 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; return false;
if( !PREFSMAN->m_bShowDanger ) if( !PREFSMAN->m_bShowDanger )
return false; 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 false;
return GAMESTATE->m_pPlayerState[pn]->m_HealthState == PlayerState::DEAD; return pPlayerState->m_HealthState == PlayerState::DEAD;
} }
float GameState::GetGoalPercentComplete( PlayerNumber pn ) 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 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 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 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 ) static int ApplyGameCommand( T* p, lua_State *L )
{ {
PlayerNumber pn = PLAYER_INVALID; PlayerNumber pn = PLAYER_INVALID;
@@ -1982,6 +2009,7 @@ public:
ADD_METHOD( IsHumanPlayer ) ADD_METHOD( IsHumanPlayer )
ADD_METHOD( GetPlayerDisplayName ) ADD_METHOD( GetPlayerDisplayName )
ADD_METHOD( GetMasterPlayerNumber ) ADD_METHOD( GetMasterPlayerNumber )
ADD_METHOD( GetMultiplayer )
ADD_METHOD( ApplyGameCommand ) ADD_METHOD( ApplyGameCommand )
ADD_METHOD( GetCurrentSong ) ADD_METHOD( GetCurrentSong )
ADD_METHOD( SetCurrentSong ) ADD_METHOD( SetCurrentSong )
+12 -8
View File
@@ -24,8 +24,8 @@ class Game;
class Style; class Style;
class Character; class Character;
class TimingData; class TimingData;
struct StageStats; class StageStats;
struct PlayerState; class PlayerState;
struct lua_State; struct lua_State;
class LuaTable; class LuaTable;
class Profile; class Profile;
@@ -58,6 +58,7 @@ public:
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;
BroadcastOnChange1D<CourseDifficulty,NUM_PLAYERS> m_PreferredCourseDifficulty;// used in nonstop BroadcastOnChange1D<CourseDifficulty,NUM_PLAYERS> m_PreferredCourseDifficulty;// used in nonstop
bool DifficultiesLocked(); bool DifficultiesLocked();
bool ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc ); bool ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc );
@@ -83,6 +84,8 @@ public:
void GetPlayerInfo( PlayerNumber pn, bool& bIsEnabledOut, bool& bIsHumanOut ); void GetPlayerInfo( PlayerNumber pn, bool& bIsEnabledOut, bool& bIsHumanOut );
bool IsPlayerEnabled( PlayerNumber pn ) const; bool IsPlayerEnabled( PlayerNumber pn ) const;
bool IsMultiPlayerEnabled( MultiPlayer mp ) const;
bool IsPlayerEnabled( const PlayerState* pPlayerState ) const;
int GetNumPlayersEnabled() const; int GetNumPlayersEnabled() const;
bool PlayerUsingBothSides() const; bool PlayerUsingBothSides() const;
@@ -161,7 +164,7 @@ public:
int m_BeatToNoteSkinRev; /* hack: incremented whenever m_BeatToNoteSkin changes */ int m_BeatToNoteSkinRev; /* hack: incremented whenever m_BeatToNoteSkin changes */
void ResetNoteSkins(); void ResetNoteSkins();
void ResetNoteSkinsForPlayer( PlayerNumber pn ); void ResetNoteSkinsForPlayer( PlayerState *ps );
void GetAllUsedNoteSkins( vector<CString> &out ) const; void GetAllUsedNoteSkins( vector<CString> &out ) const;
static const float MUSIC_SECONDS_INVALID; static const float MUSIC_SECONDS_INVALID;
@@ -170,9 +173,9 @@ public:
void UpdateSongPosition( float fPositionSeconds, const TimingData &timing, const RageTimer &timestamp = RageZeroTimer ); void UpdateSongPosition( float fPositionSeconds, const TimingData &timing, const RageTimer &timestamp = RageZeroTimer );
float GetSongPercent( float beat ) const; float GetSongPercent( float beat ) const;
bool IsPlayerHot( PlayerNumber pn ) const; bool IsPlayerHot( const PlayerState *pPlayerState ) const;
bool IsPlayerInDanger( PlayerNumber pn ) const; bool IsPlayerInDanger( const PlayerState *pPlayerState ) const;
bool IsPlayerDead( PlayerNumber pn ) const; bool IsPlayerDead( const PlayerState *pPlayerState ) const;
bool AllAreInDangerOrWorse() const; bool AllAreInDangerOrWorse() const;
bool AllAreDead() const; bool AllAreDead() const;
bool AllHumanHaveComboOf30OrMoreMisses() const; bool AllHumanHaveComboOf30OrMoreMisses() const;
@@ -191,7 +194,7 @@ public:
bool m_bGoalComplete[NUM_PLAYERS]; 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 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 RemoveAllActiveAttacks(); // called on end of song
void RemoveActiveAttacksForPlayer( PlayerNumber pn, AttackLevel al=NUM_ATTACK_LEVELS /*all*/ ); void RemoveActiveAttacksForPlayer( PlayerNumber pn, AttackLevel al=NUM_ATTACK_LEVELS /*all*/ );
void EndActiveAttacksForPlayer( PlayerNumber pn ); void EndActiveAttacksForPlayer( PlayerNumber pn );
@@ -220,7 +223,7 @@ public:
bool IsDisqualified( PlayerNumber pn ); bool IsDisqualified( PlayerNumber pn );
bool PlayerIsUsingModifier( PlayerNumber pn, const CString &sModifier ); bool PlayerIsUsingModifier( PlayerNumber pn, const CString &sModifier );
SongOptions::FailType GetPlayerFailType( PlayerNumber pn ) const; SongOptions::FailType GetPlayerFailType( const PlayerState *pPlayerState ) const;
// character stuff // character stuff
Character* m_pCurCharacters[NUM_PLAYERS]; Character* m_pCurCharacters[NUM_PLAYERS];
@@ -272,6 +275,7 @@ public:
// PlayerState // PlayerState
// //
PlayerState* m_pPlayerState[NUM_PLAYERS]; PlayerState* m_pPlayerState[NUM_PLAYERS];
PlayerState* m_pMultiPlayerState[NUM_MultiPlayer];
// //
// Preference wrappers // Preference wrappers