From ba6a4c4feb0db03dc3b9a0b61d846aae2a6397c1 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 27 May 2008 20:51:18 +0000 Subject: [PATCH] experimental: AutoJoin, join players immediately (or as soon as possible) when enough coins are inserted --- stepmania/src/GameState.cpp | 12 ++++++++++++ stepmania/src/GameState.h | 8 +++++++- stepmania/src/ScreenWithMenuElements.cpp | 9 +++++++++ stepmania/src/StepMania.cpp | 7 +++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 3380b42b4b..ffd6320a90 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -103,6 +103,7 @@ static ThemeMetric ARE_STAGE_PLAYER_MODS_FORCED( "GameState","AreStagePlay static ThemeMetric ARE_STAGE_SONG_MODS_FORCED( "GameState","AreStageSongModsForced" ); static Preference g_Premium( "Premium", Premium_Off ); +Preference GameState::m_bAutoJoin( "AutoJoin", false ); GameState::GameState() : m_pCurGame( Message_CurrentGameChanged ), @@ -413,6 +414,17 @@ bool GameState::JoinInput( PlayerNumber pn ) return true; } +bool GameState::JoinPlayers() +{ + bool bJoined = false; + FOREACH_PlayerNumber( pn ) + { + if( JoinInput(pn) ) + bJoined = true; + } + return bJoined; +} + int GameState::GetCoinsNeededToJoin() const { int iCoinsToCharge = 0; diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index ba50321c2c..9ea3fa24ce 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -12,6 +12,7 @@ #include "RageTimer.h" #include "PlayerOptions.h" #include "SongOptions.h" +#include "Preference.h" #include #include @@ -45,6 +46,7 @@ public: void JoinPlayer( PlayerNumber pn ); void UnjoinPlayer( PlayerNumber pn ); bool JoinInput( PlayerNumber pn ); + bool JoinPlayers(); void LoadProfiles( bool bLoadEdits = true ); void SaveProfiles(); void SaveProfile( PlayerNumber pn ); @@ -301,10 +303,14 @@ public: PlayerState* m_pMultiPlayerState[NUM_MultiPlayer]; // - // Preference wrappers + // Preferences + // + static Preference m_bAutoJoin; + // // These options have weird interactions depending on m_bEventMode, // so wrap them + // bool m_bTemporaryEventMode; bool IsEventMode() const; CoinMode GetCoinMode() const; diff --git a/stepmania/src/ScreenWithMenuElements.cpp b/stepmania/src/ScreenWithMenuElements.cpp index dd40887531..fd176bbab6 100644 --- a/stepmania/src/ScreenWithMenuElements.cpp +++ b/stepmania/src/ScreenWithMenuElements.cpp @@ -127,6 +127,15 @@ void ScreenWithMenuElements::BeginScreen() /* Evaluate FirstUpdateCommand. */ this->PlayCommand( "FirstUpdate" ); + + /* If AutoJoin is enabled, we may have a credit that couldn't be used to join when + * the coin was inserted due to AllowLateJoin being disabled at the time. Try to + * join players when a new screen starts. */ + if( GAMESTATE->m_bAutoJoin.Get() ) + { + if( GAMESTATE->JoinPlayers() ) + SCREENMAN->PlayStartSound(); + } } void ScreenWithMenuElements::HandleScreenMessage( const ScreenMessage SM ) diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index db0aabc928..5ee258194a 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1198,6 +1198,13 @@ void StepMania::InsertCoin( int iNum, bool bCountInBookkeeping ) else SCREENMAN->PlayInvalidSound(); + /* If AutoJoin and enough coins to join have been inserted, then try to join a player. */ + if( GAMESTATE->m_bAutoJoin.Get() ) + { + if( GAMESTATE->JoinPlayers() ) + SCREENMAN->PlayStartSound(); + } + Message msg( "CoinInserted" ); // below params are unused //msg.SetParam( "Coins", GAMESTATE->m_iCoins );