diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index cad69aa8bb..6e4657ef37 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -34,10 +34,12 @@ #include "LightsManager.h" #include "RageFile.h" #include "Bookkeeper.h" -#include #include "MemoryCardManager.h" #include "StageStats.h" #include "GameConstantsAndTypes.h" +#include "StepMania.h" + +#include #define DEFAULT_MODIFIERS THEME->GetMetric( "Common","DefaultModifiers" ) @@ -71,6 +73,35 @@ GameState::~GameState() delete m_pCharacters[i]; } +void GameState::ApplyCmdline() +{ + int i; + + /* This is in order of dependency: we need to join players before we can set + * the style, and we need to set the style before we can select steps. */ + CString sPlayer; + for( i = 0; GetCommandlineArgument( "player", &sPlayer, i ); ++i ) + { + int pn = atoi( sPlayer )-1; + if( !IsAnInt( sPlayer ) || pn < 0 || pn >= NUM_PLAYERS ) + RageException::Throw( "Invalid argument \"--player=%s\"", sPlayer.c_str() ); + + this->JoinPlayer( (PlayerNumber) pn ); + } + + CString sMode; + for( i = 0; GetCommandlineArgument( "mode", &sMode, i ); ++i ) + { + ModeChoice m; + m.Load( 0, sMode ); + CString why; + if( !m.IsPlayable(&why) ) + RageException::Throw( "Can't apply mode \"%s\": %s", sMode.c_str(), why.c_str() ); + + m.ApplyToAllPlayers(); + } +} + void GameState::Reset() { if( !m_timeGameStarted.IsZero() && g_vPlayedStageStats.size() ) // we were in the middle of a game and played at least one song @@ -168,6 +199,19 @@ void GameState::Reset() MEMCARDMAN->LockCards( false ); LIGHTSMAN->SetLightsMode( LIGHTSMODE_ATTRACT ); + + ApplyCmdline(); +} + +void GameState::JoinPlayer( PlayerNumber pn ) +{ + this->m_bSideIsJoined[pn] = true; + if( this->m_MasterPlayerNumber == PLAYER_INVALID ) + this->m_MasterPlayerNumber = pn; + + // if first player to join, set start time + if( this->GetNumSidesJoined() == 1 ) + this->BeginGame(); } void GameState::BeginGame() @@ -1153,7 +1197,10 @@ void GameState::AdjustFailType() /* Find the easiest difficulty notes selected by either player. */ Difficulty dc = DIFFICULTY_INVALID; FOREACH_HumanPlayer( p ) + { + ASSERT( this->m_pCurNotes[p] ); dc = min(dc, this->m_pCurNotes[p]->GetDifficulty()); + } /* Reset the fail type to the default. */ SongOptions so; diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 937e4dbd21..a1ede1fba4 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -39,7 +39,9 @@ public: GameState(); ~GameState(); void Reset(); + void ApplyCmdline(); // called by Reset void BeginGame(); // called when first player joins + void JoinPlayer( PlayerNumber pn ); void PlayersFinalized(); // called after a style is chosen, which means the number of players is finalized void EndGame(); // called on ScreenGameOver, ScreenMusicScroll, ScreenCredits void SaveCurrentSettingsToProfile( PlayerNumber pn ); // called at the beginning of each stage diff --git a/stepmania/src/Screen.cpp b/stepmania/src/Screen.cpp index b96ac508e0..61e92c83c8 100644 --- a/stepmania/src/Screen.cpp +++ b/stepmania/src/Screen.cpp @@ -193,14 +193,7 @@ bool Screen::JoinInput( const DeviceInput& DeviceI, const InputEventType type, c GAMESTATE->m_iCoins -= iCoinsToCharge; SCREENMAN->PlayStartSound(); - - GAMESTATE->m_bSideIsJoined[MenuI.player] = true; - if( GAMESTATE->m_MasterPlayerNumber == PLAYER_INVALID ) - GAMESTATE->m_MasterPlayerNumber = MenuI.player; - - // if first player to join, set start time - if( GAMESTATE->GetNumSidesJoined() == 1 ) - GAMESTATE->BeginGame(); + GAMESTATE->JoinPlayer( MenuI.player ); PROFILEMAN->LoadFirstAvailableProfile( MenuI.player, true ); // fast load SCREENMAN->RefreshCreditsMessages();