move "join player" logic into GameState

add --player, --mode
This commit is contained in:
Glenn Maynard
2004-04-30 07:48:02 +00:00
parent f013cbf3f8
commit 07fa62c417
3 changed files with 51 additions and 9 deletions
+48 -1
View File
@@ -34,10 +34,12 @@
#include "LightsManager.h"
#include "RageFile.h"
#include "Bookkeeper.h"
#include <ctime>
#include "MemoryCardManager.h"
#include "StageStats.h"
#include "GameConstantsAndTypes.h"
#include "StepMania.h"
#include <ctime>
#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;
+2
View File
@@ -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
+1 -8
View File
@@ -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();