Files
itgmania212121/stepmania/src/ModeChoice.cpp
T

332 lines
8.1 KiB
C++
Raw Normal View History

#include "global.h"
#include "ModeChoice.h"
#include "RageUtil.h"
#include "RageLog.h"
#include "GameManager.h"
#include "GameState.h"
#include "RageDisplay.h"
#include "AnnouncerManager.h"
#include "ProfileManager.h"
2003-09-27 01:45:46 +00:00
#include "StepMania.h"
#include "ScreenManager.h"
#include "SongManager.h"
#include "PrefsManager.h"
#include "arch/ArchHooks/ArchHooks.h"
#include "MemoryCardManager.h"
void ModeChoice::Init()
{
2004-01-14 05:10:24 +00:00
m_sName = "";
m_bInvalid = true;
2003-09-25 05:56:38 +00:00
m_iIndex = -1;
m_game = GAME_INVALID;
m_style = STYLE_INVALID;
m_pm = PLAY_MODE_INVALID;
m_dc = DIFFICULTY_INVALID;
2003-09-27 08:01:17 +00:00
m_sModifiers = "";
2003-09-25 05:56:38 +00:00
m_sAnnouncer = "";
2003-09-27 01:45:46 +00:00
m_sScreen = "";
2004-01-14 05:10:24 +00:00
m_pSteps = NULL;
m_pCharacter = NULL;
2004-01-14 08:17:34 +00:00
m_CourseDifficulty = COURSE_DIFFICULTY_INVALID;
}
2003-09-27 19:23:34 +00:00
bool CompareSongOptions( const SongOptions &so1, const SongOptions &so2 );
bool ModeChoice::DescribesCurrentModeForAllPlayers() const
{
for( int pn=0; pn<NUM_PLAYERS; pn++ )
if( !DescribesCurrentMode( (PlayerNumber) pn) )
return false;
return true;
}
bool ModeChoice::DescribesCurrentMode( PlayerNumber pn ) const
2003-07-20 07:32:26 +00:00
{
2003-09-25 05:56:38 +00:00
if( m_game != GAME_INVALID && m_game != GAMESTATE->m_CurGame )
2003-07-20 07:32:26 +00:00
return false;
2003-09-25 05:56:38 +00:00
if( m_pm != PLAY_MODE_INVALID && GAMESTATE->m_PlayMode != m_pm )
2003-07-20 07:32:26 +00:00
return false;
2003-09-25 05:56:38 +00:00
if( m_style != STYLE_INVALID && GAMESTATE->m_CurStyle != m_style )
2003-07-20 07:32:26 +00:00
return false;
// HACK: don't compare m_dc if m_pSteps is set. This causes problems
// in ScreenSelectOptionsMaster::ImportOptions if m_PreferredDifficulty
// doesn't match the difficulty of m_pCurSteps.
if( m_pSteps == NULL && m_dc != DIFFICULTY_INVALID )
2003-07-20 07:32:26 +00:00
{
// Why is this checking for all players?
2003-07-20 07:32:26 +00:00
for( int pn=0; pn<NUM_PLAYERS; pn++ )
2003-09-25 05:56:38 +00:00
if( GAMESTATE->IsHumanPlayer(pn) && GAMESTATE->m_PreferredDifficulty[pn] != m_dc )
2003-07-20 07:32:26 +00:00
return false;
}
2003-09-25 05:56:38 +00:00
if( m_sAnnouncer != "" && m_sAnnouncer != ANNOUNCER->GetCurAnnouncerName() )
2003-07-20 07:32:26 +00:00
return false;
2003-09-27 19:23:34 +00:00
if( m_sModifiers != "" )
{
/* Apply modifiers. */
PlayerOptions po = GAMESTATE->m_PlayerOptions[pn];
SongOptions so = GAMESTATE->m_SongOptions;
po.FromString( m_sModifiers );
so.FromString( m_sModifiers );
2003-09-27 19:23:34 +00:00
2004-01-11 04:33:21 +00:00
if( po != GAMESTATE->m_PlayerOptions[pn] )
return false;
if( so != GAMESTATE->m_SongOptions )
2003-09-27 19:23:34 +00:00
return false;
}
2004-01-14 05:10:24 +00:00
if( m_pSteps && GAMESTATE->m_pCurNotes[pn] != m_pSteps )
return false;
if( m_pCharacter && GAMESTATE->m_pCurCharacters[pn] != m_pCharacter )
return false;
if( m_CourseDifficulty != COURSE_DIFFICULTY_INVALID && GAMESTATE->m_CourseDifficulty[pn] != m_CourseDifficulty )
return false;
2004-01-14 05:10:24 +00:00
2003-07-20 07:32:26 +00:00
return true;
}
2003-09-25 05:56:38 +00:00
void ModeChoice::Load( int iIndex, CString sChoice )
{
2003-09-25 05:56:38 +00:00
m_iIndex = iIndex;
2003-09-25 05:56:38 +00:00
m_sName = sChoice;
2003-09-25 06:44:25 +00:00
m_bInvalid = false;
2003-09-21 20:10:15 +00:00
CStringArray asCommands;
split( sChoice, ";", asCommands );
for( unsigned i=0; i<asCommands.size(); i++ )
{
2003-09-21 20:10:15 +00:00
CString sCommand = asCommands[i];
2003-09-21 20:10:15 +00:00
CStringArray asBits;
split( sCommand, ",", asBits );
CString sName = asBits[0];
asBits.erase(asBits.begin(), asBits.begin()+1);
CString sValue = join( ",", asBits );
2003-09-21 20:10:15 +00:00
sName.MakeLower();
// sValue.MakeLower();
2003-09-21 20:10:15 +00:00
if( sName == "game" )
{
Game game = GAMEMAN->StringToGameType( sValue );
if( game != GAME_INVALID )
2003-09-25 05:56:38 +00:00
m_game = game;
2003-09-21 20:10:15 +00:00
else
2003-09-25 05:56:38 +00:00
m_bInvalid |= true;
2003-09-21 20:10:15 +00:00
}
if( sName == "style" )
{
2003-09-21 20:10:15 +00:00
Style style = GAMEMAN->GameAndStringToStyle( GAMESTATE->m_CurGame, sValue );
if( style != STYLE_INVALID )
2003-09-25 05:56:38 +00:00
m_style = style;
2003-09-21 20:10:15 +00:00
else
2003-09-25 05:56:38 +00:00
m_bInvalid |= true;
}
2003-09-21 20:10:15 +00:00
if( sName == "playmode" )
{
2003-09-21 20:10:15 +00:00
PlayMode pm = StringToPlayMode( sValue );
if( pm != PLAY_MODE_INVALID )
2003-09-25 05:56:38 +00:00
m_pm = pm;
2003-09-21 20:10:15 +00:00
else
2003-09-25 05:56:38 +00:00
m_bInvalid |= true;
}
2003-09-21 20:10:15 +00:00
if( sName == "difficulty" )
{
2003-09-21 20:10:15 +00:00
Difficulty dc = StringToDifficulty( sValue );
if( dc != DIFFICULTY_INVALID )
2003-09-25 05:56:38 +00:00
m_dc = dc;
2003-09-21 20:10:15 +00:00
else
2003-09-25 05:56:38 +00:00
m_bInvalid |= true;
}
2003-09-21 20:10:15 +00:00
if( sName == "announcer" )
2003-09-25 05:56:38 +00:00
m_sAnnouncer = sValue;
2003-09-25 21:27:14 +00:00
if( sName == "name" )
m_sName = sValue;
2003-09-27 01:45:46 +00:00
2003-09-27 08:01:17 +00:00
if( sName == "mod" )
2003-09-27 01:45:46 +00:00
{
2003-09-27 08:01:17 +00:00
if( m_sModifiers != "" )
m_sModifiers += ",";
m_sModifiers += sValue;
2003-09-27 03:06:35 +00:00
}
2003-09-27 08:01:17 +00:00
if( sName == "screen" )
m_sScreen = sValue;
2003-09-27 03:06:35 +00:00
}
}
2003-09-27 01:45:46 +00:00
2003-11-07 20:14:29 +00:00
int GetSidesRequiredToPlayStyle( Style style )
{
switch( GAMEMAN->GetStyleDefForStyle(style)->m_StyleType )
{
case StyleDef::ONE_PLAYER_ONE_CREDIT:
return 1;
case StyleDef::TWO_PLAYERS_TWO_CREDITS:
return 2;
2003-11-09 01:09:35 +00:00
case StyleDef::ONE_PLAYER_TWO_CREDITS:
2003-11-09 08:55:21 +00:00
return (PREFSMAN->m_Premium == PrefsManager::DOUBLES_PREMIUM) ? 1 : 2;
2003-11-07 20:14:29 +00:00
default:
ASSERT(0);
return 1;
}
}
2003-09-27 03:06:35 +00:00
bool ModeChoice::IsPlayable( CString *why ) const
{
if( m_bInvalid )
return false;
if ( m_style != STYLE_INVALID )
{
int iNumSidesJoined = GAMESTATE->GetNumSidesJoined();
2003-11-07 20:14:29 +00:00
int iNumSidesRequired = GetSidesRequiredToPlayStyle(m_style);
2003-11-09 01:09:35 +00:00
if( iNumSidesRequired != iNumSidesJoined )
return false;
2003-09-27 03:06:35 +00:00
}
/* Don't allow a PlayMode that's incompatible with our current Style (if set),
* and vice versa. */
const PlayMode &rPlayMode = (m_pm != PLAY_MODE_INVALID) ? m_pm : GAMESTATE->m_PlayMode;
if( rPlayMode == PLAY_MODE_RAVE || rPlayMode == PLAY_MODE_BATTLE )
{
// Can't play rave if there isn't enough room for two players.
// This is correct for dance (ie, no rave for solo and doubles),
// and should be okay for pump .. not sure about other game types.
const Style &rStyle = m_style != STYLE_INVALID? m_style: GAMESTATE->m_CurStyle;
if( rStyle != STYLE_INVALID &&
GAMEMAN->GetStyleDefForStyle(rStyle)->m_iColsPerPlayer >= 6 )
return false;
}
2003-09-27 03:06:35 +00:00
if( !m_sScreen.CompareNoCase("ScreenEditCoursesMenu") )
{
vector<Course*> vCourses;
SONGMAN->GetAllCourses( vCourses, false );
if( vCourses.size() == 0 )
{
if( why )
*why = "No courses are installed";
return false;
}
}
if( !m_sScreen.CompareNoCase("ScreenJukeboxMenu") ||
!m_sScreen.CompareNoCase("ScreenEditMenu") ||
!m_sScreen.CompareNoCase("ScreenEditCoursesMenu") )
{
if( SONGMAN->GetNumSongs() == 0 )
{
if( why )
*why = "No songs are installed";
return false;
}
}
return true;
}
2003-09-27 19:23:34 +00:00
void ModeChoice::ApplyToAllPlayers() const
{
for( int pn=0; pn<NUM_PLAYERS; pn++ )
if( GAMESTATE->IsHumanPlayer(pn) )
Apply((PlayerNumber) pn);
2003-09-27 01:45:46 +00:00
if( m_sScreen != "" )
SCREENMAN->SetNewScreen( m_sScreen );
}
2003-09-27 19:23:34 +00:00
void ModeChoice::Apply( PlayerNumber pn ) const
{
2003-11-08 15:49:48 +00:00
if( !GAMESTATE->IsHumanPlayer(pn) )
return;
const PlayMode OldPlayMode = GAMESTATE->m_PlayMode;
2003-09-25 05:56:38 +00:00
if( m_game != GAME_INVALID )
GAMESTATE->m_CurGame = m_game;
if( m_pm != PLAY_MODE_INVALID )
GAMESTATE->m_PlayMode = m_pm;
if( m_style != STYLE_INVALID )
{
2003-09-25 05:56:38 +00:00
GAMESTATE->m_CurStyle = m_style;
// If only one side is joined and we picked a style
// that requires both sides, join the other side.
switch( GAMEMAN->GetStyleDefForStyle(m_style)->m_StyleType )
{
case StyleDef::ONE_PLAYER_ONE_CREDIT:
break;
case StyleDef::TWO_PLAYERS_TWO_CREDITS:
case StyleDef::ONE_PLAYER_TWO_CREDITS:
int p;
for( p=0; p<NUM_PLAYERS; p++ )
GAMESTATE->m_bSideIsJoined[p] = true;
break;
default:
ASSERT(0);
}
}
2003-09-25 05:56:38 +00:00
if( m_dc != DIFFICULTY_INVALID && pn != PLAYER_INVALID )
GAMESTATE->m_PreferredDifficulty[pn] = m_dc;
if( m_sAnnouncer != "" )
ANNOUNCER->SwitchAnnouncer( m_sAnnouncer );
2003-09-27 08:01:17 +00:00
if( m_sModifiers != "" )
2003-09-27 19:23:34 +00:00
GAMESTATE->ApplyModifiers( pn, m_sModifiers );
2004-01-14 05:10:24 +00:00
if( m_pSteps )
GAMESTATE->m_pCurNotes[pn] = m_pSteps;
if( m_pCharacter )
GAMESTATE->m_pCurCharacters[pn] = m_pCharacter;
if( m_CourseDifficulty != COURSE_DIFFICULTY_INVALID )
{
GAMESTATE->m_CourseDifficulty[pn] = m_CourseDifficulty;
if( PREFSMAN->m_bLockCourseDifficulties )
for( int p = 0; p < NUM_PLAYERS; ++p )
GAMESTATE->m_CourseDifficulty[p] = GAMESTATE->m_CourseDifficulty[pn];
}
// HACK: Set life type to BATTERY just once here so it happens once and
// we don't override the user's changes if they back out.
if( GAMESTATE->m_PlayMode == PLAY_MODE_ONI && GAMESTATE->m_PlayMode != OldPlayMode )
GAMESTATE->m_SongOptions.m_LifeType = SongOptions::LIFE_BATTERY;
2003-09-08 07:21:41 +00:00
//
// We know what players are joined at the time we set the Style
//
2003-09-25 05:56:38 +00:00
if( m_style != STYLE_INVALID )
2003-09-08 07:21:41 +00:00
{
MEMCARDMAN->LockCards( true );
2003-09-08 07:21:41 +00:00
}
}
2003-09-29 08:56:33 +00:00
bool ModeChoice::IsZero() const
{
if( m_game != GAME_INVALID ||
m_pm != PLAY_MODE_INVALID ||
m_style != STYLE_INVALID ||
m_dc != DIFFICULTY_INVALID ||
m_sAnnouncer != "" ||
m_sModifiers != "" ||
m_pSteps != NULL ||
m_pCharacter != NULL ||
m_CourseDifficulty != COURSE_DIFFICULTY_INVALID )
2003-09-29 08:56:33 +00:00
return false;
return true;
}