Files
itgmania212121/stepmania/src/ScreenJukebox.cpp
T

354 lines
10 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2004-06-09 02:48:38 +00:00
2003-01-31 21:34:34 +00:00
#include "ScreenJukebox.h"
#include "RageLog.h"
#include "ThemeManager.h"
#include "GameState.h"
#include "SongManager.h"
2003-04-13 00:44:50 +00:00
#include "ScreenManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
#include "Steps.h"
2004-03-23 21:02:58 +00:00
#include "ScreenAttract.h"
#include "RageUtil.h"
2005-02-21 06:22:46 +00:00
#include "UnlockManager.h"
#include "Course.h"
#include "ThemeManager.h"
#include "Style.h"
#include "PlayerState.h"
2005-03-15 07:01:56 +00:00
#include "StatsManager.h"
#include "CommonMetrics.h"
2005-07-04 20:52:21 +00:00
#include "PrefsManager.h"
#include "InputEventPlus.h"
#include "AdjustSync.h"
#include "SongUtil.h"
#include "Song.h"
2003-01-31 21:34:34 +00:00
#define SHOW_COURSE_MODIFIERS_PROBABILITY THEME->GetMetricF(m_sName,"ShowCourseModifiersProbability")
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenJukebox );
void ScreenJukebox::SetSong()
2003-01-31 21:34:34 +00:00
{
ThemeMetric<bool> ALLOW_ADVANCED_MODIFIERS(m_sName,"AllowAdvancedModifiers");
2003-02-11 02:20:38 +00:00
vector<Song*> vSongs;
//Check to see if there is a theme-course
//I.E. If there is a course called exactly the theme name,
//then we pick a song from this course.
2005-01-03 20:56:47 +00:00
Course *pCourse = SONGMAN->GetCourseFromName( THEME->GetCurThemeName() );
if( pCourse != NULL )
2005-06-28 08:11:30 +00:00
for ( unsigned i = 0; i < pCourse->m_vEntries.size(); i++ )
if( pCourse->m_vEntries[i].IsFixedSong() )
2007-08-12 22:43:45 +00:00
vSongs.push_back( pCourse->m_vEntries[i].songID.ToSong() );
if ( vSongs.size() == 0 )
2007-04-07 05:11:47 +00:00
vSongs = SONGMAN->GetSongs( GAMESTATE->m_sPreferredSongGroup );
2003-01-31 21:34:34 +00:00
//
// Calculate what difficulties to show
//
vector<Difficulty> vDifficultiesToShow;
if( m_bDemonstration )
{
// HACK: This belongs in ScreenDemonstration
ThemeMetricDifficultiesToShow DIFFICULTIES_TO_SHOW_HERE(m_sName,"DifficultiesToShow");
2005-06-05 09:45:30 +00:00
vDifficultiesToShow = DIFFICULTIES_TO_SHOW_HERE.GetValue();
}
else
{
2006-10-07 04:39:48 +00:00
if( GAMESTATE->m_PreferredDifficulty[PLAYER_1] != Difficulty_Invalid )
{
vDifficultiesToShow.push_back( GAMESTATE->m_PreferredDifficulty[PLAYER_1] );
}
else
{
FOREACH_ENUM( Difficulty, dc )
vDifficultiesToShow.push_back( dc );
}
}
2005-12-30 13:19:40 +00:00
ASSERT( !vDifficultiesToShow.empty() );
2004-04-14 06:00:32 +00:00
2003-01-31 21:34:34 +00:00
//
2003-08-03 00:13:55 +00:00
// Search for a Song and Steps to play during the demo
2003-01-31 21:34:34 +00:00
//
for( int i=0; i<1000; i++ )
2003-01-31 21:34:34 +00:00
{
2003-02-11 02:20:38 +00:00
if( vSongs.size() == 0 )
return;
2003-02-11 02:20:38 +00:00
Song* pSong = vSongs[RandomInt(vSongs.size())];
2003-01-31 21:34:34 +00:00
ASSERT( pSong != NULL );
2003-01-31 21:34:34 +00:00
if( !pSong->HasMusic() )
continue; // skip
if( !pSong->NormallyDisplayed() )
continue;
if( !pSong->ShowInDemonstrationAndRanking() )
continue; // skip
Difficulty dc = vDifficultiesToShow[ RandomInt(vDifficultiesToShow.size()) ];
Steps* pSteps = SongUtil::GetStepsByDifficulty( pSong, GAMESTATE->GetCurrentStyle()->m_StepsType, dc );
2003-01-31 21:34:34 +00:00
2004-05-24 03:41:39 +00:00
if( pSteps == NULL )
2003-01-31 21:34:34 +00:00
continue; // skip
2004-05-24 03:41:39 +00:00
if( !PREFSMAN->m_bAutogenSteps && pSteps->IsAutogen())
continue; // skip
2003-01-31 21:34:34 +00:00
// Found something we can use!
GAMESTATE->m_pCurSong.Set( pSong );
// We just changed the song. Reset the original sync data.
AdjustSync::ResetOriginalSyncData();
FOREACH_PlayerNumber( p )
GAMESTATE->m_pCurSteps[p].Set( pSteps );
2003-01-31 21:34:34 +00:00
bool bShowModifiers = randomf(0,1) <= SHOW_COURSE_MODIFIERS_PROBABILITY;
if( bShowModifiers )
{
/* If we have a modifier course containing this song, apply its modifiers. Only check
* fixed course entries. */
vector<Course*> apCourses;
SONGMAN->GetAllCourses( apCourses, false );
vector<const CourseEntry *> apOptions;
vector<Course*> apPossibleCourses;
for( unsigned i = 0; i < apCourses.size(); ++i )
{
Course *pCourse = apCourses[i];
const CourseEntry *pEntry = pCourse->FindFixedSong( pSong );
if( pEntry == NULL || pEntry->attacks.size() == 0 )
continue;
if( !ALLOW_ADVANCED_MODIFIERS )
{
// There are some confusing mods that we don't want to show in demonstration.
bool bModsAreOkToShow = true;
AttackArray aAttacks = pEntry->attacks;
if( !pEntry->sModifiers.empty() )
aAttacks.push_back( Attack::FromGlobalCourseModifier( pEntry->sModifiers ) );
FOREACH_CONST( Attack, aAttacks, a )
{
2006-01-22 01:00:06 +00:00
RString s = a->sModifiers;
s.MakeLower();
2005-12-21 08:33:30 +00:00
if( s.find("dark") != string::npos ||
s.find("stealth") != string::npos )
{
bModsAreOkToShow = false;
break;
}
}
if( !bModsAreOkToShow )
continue; // skip
}
apOptions.push_back( pEntry );
apPossibleCourses.push_back( pCourse );
}
if( !apOptions.empty() )
{
int iIndex = RandomInt( apOptions.size() );
m_pCourseEntry = apOptions[iIndex];
Course *pCourse = apPossibleCourses[iIndex];
2005-07-25 03:59:24 +00:00
PlayMode pm = CourseTypeToPlayMode( pCourse->GetCourseType() );
GAMESTATE->m_PlayMode.Set( pm );
GAMESTATE->m_pCurCourse.Set( pCourse );
FOREACH_PlayerNumber( p )
{
GAMESTATE->m_pCurTrail[p].Set( pCourse->GetTrail( GAMESTATE->GetCurrentStyle()->m_StepsType ) );
ASSERT( GAMESTATE->m_pCurTrail[p] );
}
}
}
return; // done looking
2003-01-31 21:34:34 +00:00
}
return; // didn't find a song
}
2006-01-15 19:49:02 +00:00
ScreenJukebox::ScreenJukebox()
2005-01-03 23:20:11 +00:00
{
m_bDemonstration = false;
2005-05-20 09:06:26 +00:00
m_pCourseEntry = NULL;
2005-01-03 23:20:11 +00:00
}
void ScreenJukebox::Init()
{
// ScreeJukeboxMenu must set this
2006-09-30 22:13:20 +00:00
ASSERT( GAMESTATE->GetCurrentStyle() );
2005-07-25 03:59:24 +00:00
GAMESTATE->m_PlayMode.Set( PLAY_MODE_REGULAR );
SetSong();
// ASSERT( GAMESTATE->m_pCurSong );
2003-01-31 21:34:34 +00:00
GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
// choose some cool options
int Benchmark = 0;
2006-08-05 04:47:01 +00:00
if( Benchmark )
2003-01-31 21:34:34 +00:00
{
/* Note that you also need to make sure you benchmark with the
* same notes. I use a copy of MaxU with only heavy notes included. */
FOREACH_EnabledPlayer( p )
2003-01-31 21:34:34 +00:00
{
/* Lots and lots of arrows. This might even bias to arrows a little
* too much. */
PO_GROUP_CALL( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions, ModsLevel_Stage, Init );
PO_GROUP_ASSIGN( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions, ModsLevel_Stage, m_fScrollSpeed, .25f );
PO_GROUP_ASSIGN( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions, ModsLevel_Stage, m_fPerspectiveTilt, -1.0f );
PO_GROUP_ASSIGN_N( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions, ModsLevel_Stage, m_fEffects, PlayerOptions::EFFECT_MINI, 1.0f );
2003-01-31 21:34:34 +00:00
}
SO_GROUP_ASSIGN( GAMESTATE->m_SongOptions, ModsLevel_Stage, m_LifeType, SongOptions::LIFE_BATTERY );
2003-01-31 21:34:34 +00:00
}
FOREACH_EnabledPlayer( p )
2003-01-31 21:34:34 +00:00
{
2007-08-29 16:13:52 +00:00
/* Reset score between songs. */
STATSMAN->m_CurStageStats.m_player[p].ResetScoreForLesson();
2005-03-15 07:01:56 +00:00
2003-02-11 02:20:38 +00:00
if( GAMESTATE->m_bJukeboxUsesModifiers )
2003-04-21 04:10:52 +00:00
{
PlayerOptions po;
GAMESTATE->GetDefaultPlayerOptions( po );
po.ChooseRandomModifiers();
2006-08-05 04:47:01 +00:00
GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.Assign( ModsLevel_Stage, po );
2003-04-21 04:10:52 +00:00
}
2003-01-31 21:34:34 +00:00
}
SongOptions so;
GAMESTATE->GetDefaultSongOptions( so );
2006-08-05 04:47:01 +00:00
GAMESTATE->m_SongOptions.Assign( ModsLevel_Stage, so );
2003-01-31 21:34:34 +00:00
FOREACH_EnabledPlayer( p )
PO_GROUP_ASSIGN( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions, ModsLevel_Stage, m_FailType, PlayerOptions::FAIL_OFF );
2003-01-31 21:34:34 +00:00
2003-03-09 00:55:49 +00:00
GAMESTATE->m_bDemonstrationOrJukebox = true;
2003-01-31 21:34:34 +00:00
2005-01-03 23:20:11 +00:00
/* Now that we've set up, init the base class. */
2005-01-03 22:44:19 +00:00
ScreenGameplay::Init();
2003-01-31 21:34:34 +00:00
if( GAMESTATE->m_pCurSong == NULL ) // we didn't find a song.
{
2003-03-25 21:17:29 +00:00
this->PostScreenMessage( SM_GoToNextScreen, 0 ); // Abort demonstration.
2003-01-31 21:34:34 +00:00
return;
}
ClearMessageQueue(); // remove all of the messages set in ScreenGameplay that animate "ready", "here we go", etc.
GAMESTATE->m_bGameplayLeadIn.Set( false );
2003-01-31 21:34:34 +00:00
m_DancingState = STATE_DANCING;
}
void ScreenJukebox::Input( const InputEventPlus &input )
2003-01-31 21:34:34 +00:00
{
//LOG->Trace( "ScreenJukebox::Input()" );
if( input.type != IET_FIRST_PRESS )
return; /* ignore */
2003-01-31 21:34:34 +00:00
2006-09-14 20:52:34 +00:00
switch( input.MenuI )
2003-01-31 21:34:34 +00:00
{
2008-05-21 05:36:09 +00:00
case GAME_BUTTON_LEFT:
case GAME_BUTTON_RIGHT:
SCREENMAN->PostMessageToTopScreen( SM_NotesEnded, 0 );
return;
2003-01-31 21:34:34 +00:00
}
2004-03-23 21:02:58 +00:00
ScreenAttract::AttractInput( input, this );
2003-01-31 21:34:34 +00:00
}
void ScreenJukebox::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_NotesEnded )
2003-01-31 21:34:34 +00:00
{
if( m_Out.IsTransitioning() || m_Out.IsFinished() )
return; // ignore - we're already fading or faded
2003-03-09 00:55:49 +00:00
m_Out.StartTransitioning( SM_GoToNextScreen );
2003-01-31 21:34:34 +00:00
return;
}
else if( SM == SM_GoToNextScreen )
{
2004-10-25 03:47:22 +00:00
if( m_pSoundMusic )
m_pSoundMusic->Stop();
2003-01-31 21:34:34 +00:00
}
else if( SM == SM_GoToStartScreen )
{
ScreenAttract::GoToStartScreen( m_sName );
}
2003-01-31 21:34:34 +00:00
ScreenGameplay::HandleScreenMessage( SM );
2003-02-16 04:56:36 +00:00
}
2004-06-09 04:28:27 +00:00
void ScreenJukebox::InitSongQueues()
{
ScreenGameplay::InitSongQueues();
2005-05-20 21:08:08 +00:00
// Pare down to just the song in the course that we want.
int iIndexToKeep = -1;
2005-05-20 23:17:53 +00:00
for( unsigned i=0; i<m_apSongsQueue.size(); i++ )
2005-05-20 21:08:08 +00:00
{
if( m_apSongsQueue[i] == GAMESTATE->m_pCurSong )
{
iIndexToKeep = i;
break;
}
}
ASSERT( iIndexToKeep != -1 );
2005-05-20 21:08:08 +00:00
for( int i=(m_apSongsQueue.size())-1; i>=0; i-- )
{
2005-05-20 21:08:08 +00:00
if( i != iIndexToKeep )
{
m_apSongsQueue.erase( m_apSongsQueue.begin()+i );
FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi )
2005-05-20 21:08:08 +00:00
{
pi->m_vpStepsQueue.erase( pi->m_vpStepsQueue.begin()+i );
pi->m_asModifiersQueue.erase( pi->m_asModifiersQueue.begin()+i );
2005-05-20 21:08:08 +00:00
}
}
}
2005-05-20 09:06:26 +00:00
2005-05-20 21:08:08 +00:00
ASSERT_M( m_apSongsQueue.size() == 1, ssprintf("%i", (int) m_apSongsQueue.size()) );
FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi )
2005-05-20 21:08:08 +00:00
{
ASSERT_M( pi->m_vpStepsQueue.size() == 1, ssprintf("%i", (int) pi->m_vpStepsQueue.size()) );
ASSERT_M( pi->m_asModifiersQueue.size() == 1, ssprintf("%i", (int) pi->m_asModifiersQueue.size()) );
}
}
2004-06-09 04:28:27 +00:00
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/