Files
itgmania212121/stepmania/src/GameCommand.cpp
T

858 lines
23 KiB
C++
Raw Normal View History

#include "global.h"
2004-12-02 06:29:20 +00:00
#include "GameCommand.h"
#include "RageUtil.h"
#include "RageLog.h"
#include "GameManager.h"
#include "GameState.h"
#include "AnnouncerManager.h"
#include "PlayerOptions.h"
#include "ProfileManager.h"
2005-07-01 05:07:22 +00:00
#include "Profile.h"
2003-09-27 01:45:46 +00:00
#include "StepMania.h"
#include "ScreenManager.h"
#include "PrefsManager.h"
2004-07-25 17:07:32 +00:00
#include "Game.h"
#include "Style.h"
#include "Foreach.h"
2004-12-04 21:14:46 +00:00
#include "arch/Dialog/Dialog.h"
2004-12-05 11:54:43 +00:00
#include "GameSoundManager.h"
#include "PlayerState.h"
#include "SongManager.h"
#include "song.h"
#include "UnlockManager.h"
2006-06-12 09:15:27 +00:00
#include "LocalizedString.h"
#include "arch/ArchHooks/ArchHooks.h"
#include "ScreenPrompt.h"
static LocalizedString COULD_NOT_LAUNCH_BROWSER( "GameCommand", "Could not launch web browser." );
2006-10-01 20:13:27 +00:00
REGISTER_CLASS_TRAITS( GameCommand, new GameCommand(*pCopy) );
2004-12-02 06:29:20 +00:00
void GameCommand::Init()
{
m_bApplyCommitsScreens = true;
2004-01-14 05:10:24 +00:00
m_sName = "";
m_sText = "";
2004-01-14 05:10:24 +00:00
m_bInvalid = true;
2003-09-25 05:56:38 +00:00
m_iIndex = -1;
2006-10-07 03:43:41 +00:00
m_MultiPlayer = MultiPlayer_Invalid;
2004-06-28 07:26:00 +00:00
m_pStyle = NULL;
2006-09-26 20:32:41 +00:00
m_pm = PlayMode_Invalid;
2006-10-07 04:39:48 +00:00
m_dc = Difficulty_Invalid;
2006-10-07 10:49:53 +00:00
m_CourseDifficulty = CourseDifficulty_Invalid;
m_sPreferredModifiers = "";
m_sStageModifiers = "";
2003-09-25 05:56:38 +00:00
m_sAnnouncer = "";
2003-09-27 01:45:46 +00:00
m_sScreen = "";
2005-02-22 03:34:56 +00:00
m_LuaFunction.Unset();
2004-01-25 16:48:09 +00:00
m_pSong = NULL;
2004-01-14 05:10:24 +00:00
m_pSteps = NULL;
2004-04-30 07:46:46 +00:00
m_pCourse = NULL;
2004-06-03 08:22:02 +00:00
m_pTrail = NULL;
2004-01-14 05:10:24 +00:00
m_pCharacter = NULL;
2006-10-07 04:25:28 +00:00
m_SortOrder = SortOrder_Invalid;
m_sUnlockEntryID = "";
2004-12-05 11:54:43 +00:00
m_sSoundPath = "";
m_vsScreensToPrepare.clear();
2005-01-31 02:00:00 +00:00
m_iWeightPounds = -1;
2005-02-15 22:08:42 +00:00
m_iGoalCalories = -1;
2006-10-07 04:25:28 +00:00
m_GoalType = GoalType_Invalid;
2005-07-07 22:08:05 +00:00
m_sProfileID = "";
2006-06-12 09:15:27 +00:00
m_sUrl = "";
2004-12-04 23:24:14 +00:00
m_bInsertCredit = false;
2004-12-30 01:17:52 +00:00
m_bStopMusic = false;
2005-11-30 04:27:10 +00:00
m_bApplyDefaultOptions = false;
}
class SongOptions;
2003-09-27 19:23:34 +00:00
bool CompareSongOptions( const SongOptions &so1, const SongOptions &so2 );
2004-12-02 06:29:20 +00:00
bool GameCommand::DescribesCurrentModeForAllPlayers() const
2003-09-27 19:23:34 +00:00
{
FOREACH_HumanPlayer( pn )
2004-06-03 08:22:02 +00:00
if( !DescribesCurrentMode(pn) )
2003-09-27 19:23:34 +00:00
return false;
return true;
}
2004-12-02 06:29:20 +00:00
bool GameCommand::DescribesCurrentMode( PlayerNumber pn ) const
2003-07-20 07:32:26 +00:00
{
2006-09-26 20:32:41 +00:00
if( m_pm != PlayMode_Invalid && GAMESTATE->m_PlayMode != m_pm )
2003-07-20 07:32:26 +00:00
return false;
2006-09-30 22:13:20 +00:00
if( m_pStyle && GAMESTATE->GetCurrentStyle() != m_pStyle )
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.
2006-10-07 04:39:48 +00:00
if( m_pSteps == NULL && m_dc != Difficulty_Invalid )
2003-07-20 07:32:26 +00:00
{
// Why is this checking for all players?
FOREACH_HumanPlayer( pn )
if( 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_sPreferredModifiers != "" )
2003-09-27 19:23:34 +00:00
{
PlayerOptions po = GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.GetPreferred();
SongOptions so = GAMESTATE->m_SongOptions.GetPreferred();
po.FromString( m_sPreferredModifiers );
so.FromString( m_sPreferredModifiers );
2003-09-27 19:23:34 +00:00
if( po != GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.GetPreferred() )
2004-01-11 04:33:21 +00:00
return false;
if( so != GAMESTATE->m_SongOptions.GetPreferred() )
return false;
}
if( m_sStageModifiers != "" )
{
PlayerOptions po = GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.GetStage();
SongOptions so = GAMESTATE->m_SongOptions.GetStage();
po.FromString( m_sStageModifiers );
so.FromString( m_sStageModifiers );
if( po != GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.GetStage() )
return false;
if( so != GAMESTATE->m_SongOptions.GetStage() )
2003-09-27 19:23:34 +00:00
return false;
}
if( m_pSong && GAMESTATE->m_pCurSong.Get() != m_pSong )
2004-01-25 16:48:09 +00:00
return false;
if( m_pSteps && GAMESTATE->m_pCurSteps[pn].Get() != m_pSteps )
2004-01-14 05:10:24 +00:00
return false;
if( m_pCharacter && GAMESTATE->m_pCurCharacters[pn] != m_pCharacter )
return false;
2005-05-18 07:14:19 +00:00
if( m_pCourse && GAMESTATE->m_pCurCourse.Get() != m_pCourse )
2005-02-14 18:35:50 +00:00
return false;
2005-05-18 07:14:19 +00:00
if( m_pTrail && GAMESTATE->m_pCurTrail[pn].Get() != m_pTrail )
return false;
if( !m_sSongGroup.empty() && GAMESTATE->m_sPreferredSongGroup != m_sSongGroup )
return false;
2006-10-07 04:25:28 +00:00
if( m_SortOrder != SortOrder_Invalid && GAMESTATE->m_PreferredSortOrder != m_SortOrder )
2004-12-04 22:33:55 +00:00
return false;
if( m_iWeightPounds != -1 && PROFILEMAN->GetProfile(pn)->m_iWeightPounds != m_iWeightPounds )
2005-01-31 02:00:00 +00:00
return false;
if( m_iGoalCalories != -1 && PROFILEMAN->GetProfile(pn)->m_iGoalCalories != m_iGoalCalories )
2005-02-15 22:08:42 +00:00
return false;
2006-10-07 04:25:28 +00:00
if( m_GoalType != GoalType_Invalid && PROFILEMAN->GetProfile(pn)->m_GoalType != m_GoalType )
2005-02-17 19:36:10 +00:00
return false;
if( !m_sProfileID.empty() && ProfileManager::m_sDefaultLocalProfileID[pn].Get() != m_sProfileID )
2005-07-07 22:08:05 +00:00
return false;
2004-01-14 05:10:24 +00:00
2003-07-20 07:32:26 +00:00
return true;
}
2004-12-03 05:37:21 +00:00
void GameCommand::Load( int iIndex, const Commands& cmds )
{
2003-09-25 05:56:38 +00:00
m_iIndex = iIndex;
2003-09-25 06:44:25 +00:00
m_bInvalid = false;
m_Commands = cmds;
FOREACH_CONST( Command, cmds.v, cmd )
LoadOne( *cmd );
}
void GameCommand::LoadOne( const Command& cmd )
{
2006-01-22 01:00:06 +00:00
RString sName = cmd.GetName();
if( sName.empty() )
return;
2006-01-22 01:00:06 +00:00
RString sValue;
for( unsigned i = 1; i < cmd.m_vsArgs.size(); ++i )
{
if( i > 1 )
sValue += ",";
2006-01-22 01:00:06 +00:00
sValue += (RString) cmd.GetArg(i);
}
2003-09-21 20:10:15 +00:00
if( sName == "style" )
{
const Style* style = GAMEMAN->GameAndStringToStyle( GAMESTATE->m_pCurGame, sValue );
if( style )
m_pStyle = style;
else
m_bInvalid |= true;
}
else if( sName == "playmode" )
{
PlayMode pm = StringToPlayMode( sValue );
2006-09-26 20:32:41 +00:00
if( pm != PlayMode_Invalid )
m_pm = pm;
else
m_bInvalid |= true;
}
else if( sName == "difficulty" )
{
Difficulty dc = StringToDifficulty( sValue );
2006-10-07 04:39:48 +00:00
if( dc != Difficulty_Invalid )
m_dc = dc;
else
m_bInvalid |= true;
}
else if( sName == "announcer" )
{
m_sAnnouncer = sValue;
}
else if( sName == "name" )
{
m_sName = sValue;
}
2003-09-27 01:45:46 +00:00
else if( sName == "text" )
{
m_sText = sValue;
}
else if( sName == "mod" )
{
if( m_sPreferredModifiers != "" )
m_sPreferredModifiers += ",";
m_sPreferredModifiers += sValue;
}
else if( sName == "stagemod" )
{
if( m_sStageModifiers != "" )
m_sStageModifiers += ",";
m_sStageModifiers += sValue;
}
else if( sName == "lua" )
{
m_LuaFunction.SetFromExpression( sValue );
ASSERT_M( !m_LuaFunction.IsNil(), ssprintf("\"%s\" evaluated to nil", sValue.c_str()) );
}
else if( sName == "screen" )
{
m_sScreen = sValue;
}
else if( sName == "song" )
{
m_pSong = SONGMAN->FindSong( sValue );
if( m_pSong == NULL )
2004-01-25 16:48:09 +00:00
{
m_sInvalidReason = ssprintf( "Song \"%s\" not found", sValue.c_str() );
m_bInvalid |= true;
2004-01-25 16:48:09 +00:00
}
}
2004-01-25 16:48:09 +00:00
else if( sName == "steps" )
{
2006-01-22 01:00:06 +00:00
RString sSteps = sValue;
2004-02-01 02:41:23 +00:00
/* This must be processed after "song" and "style" commands. */
if( !m_bInvalid )
2004-04-30 07:46:46 +00:00
{
Song *pSong = (m_pSong != NULL)? m_pSong:GAMESTATE->m_pCurSong;
2006-09-30 22:13:20 +00:00
const Style *pStyle = m_pStyle ? m_pStyle : GAMESTATE->GetCurrentStyle();
if( pSong == NULL || pStyle == NULL )
RageException::Throw( "Must set Song and Style to set Steps." );
Difficulty dc = StringToDifficulty( sSteps );
if( dc != DIFFICULTY_EDIT )
m_pSteps = SongUtil::GetStepsByDifficulty( pSong, pStyle->m_StepsType, dc );
else
m_pSteps = SongUtil::GetStepsByDescription( pSong, pStyle->m_StepsType, sSteps );
if( m_pSteps == NULL )
2004-04-30 07:46:46 +00:00
{
m_sInvalidReason = "steps not found";
2004-04-30 07:46:46 +00:00
m_bInvalid |= true;
}
}
}
2005-01-31 04:46:18 +00:00
else if( sName == "course" )
{
2006-05-01 21:49:59 +00:00
m_pCourse = SONGMAN->FindCourse( "", sValue );
if( m_pCourse == NULL )
{
m_sInvalidReason = ssprintf( "Course \"%s\" not found", sValue.c_str() );
m_bInvalid |= true;
}
}
else if( sName == "trail" )
{
2006-01-22 01:00:06 +00:00
RString sTrail = sValue;
2004-12-04 21:14:46 +00:00
/* This must be processed after "course" and "style" commands. */
if( !m_bInvalid )
2004-12-04 22:33:55 +00:00
{
Course *pCourse = (m_pCourse != NULL)? m_pCourse:GAMESTATE->m_pCurCourse;
2006-09-30 22:13:20 +00:00
const Style *pStyle = m_pStyle ? m_pStyle : GAMESTATE->GetCurrentStyle();
if( pCourse == NULL || pStyle == NULL )
RageException::Throw( "Must set Course and Style to set Steps." );
const CourseDifficulty cd = StringToCourseDifficulty( sTrail );
2006-10-07 10:49:53 +00:00
ASSERT_M( cd != CourseDifficulty_Invalid, ssprintf("Invalid difficulty '%s'", sTrail.c_str()) );
m_pTrail = pCourse->GetTrail( pStyle->m_StepsType, cd );
if( m_pTrail == NULL )
2004-12-04 22:33:55 +00:00
{
m_sInvalidReason = "trail not found";
2004-12-04 22:33:55 +00:00
m_bInvalid |= true;
}
}
}
else if( sName == "setenv" )
{
if( cmd.m_vsArgs.size() == 3 )
m_SetEnv[ cmd.m_vsArgs[1] ] = cmd.m_vsArgs[2];
}
else if( sName == "songgroup" )
{
m_sSongGroup = sValue;
}
2005-01-31 02:00:00 +00:00
else if( sName == "sort" )
{
m_SortOrder = StringToSortOrder( sValue );
2006-10-07 04:25:28 +00:00
if( m_SortOrder == SortOrder_Invalid )
2005-02-15 22:08:42 +00:00
{
m_sInvalidReason = ssprintf( "SortOrder \"%s\" is not valid.", sValue.c_str() );
m_bInvalid |= true;
2005-02-15 22:08:42 +00:00
}
}
else if( sName == "weight" )
{
m_iWeightPounds = atoi( sValue );
}
2005-02-15 22:08:42 +00:00
else if( sName == "goalcalories" )
{
m_iGoalCalories = atoi( sValue );
}
2005-02-17 19:36:10 +00:00
else if( sName == "goaltype" )
{
m_GoalType = StringToGoalType( sValue );
}
2005-07-07 22:08:05 +00:00
else if( sName == "profileid" )
{
m_sProfileID = sValue;
}
2006-06-12 09:15:27 +00:00
else if( sName == "url" )
{
m_sUrl = sValue;
}
else if( sName == "unlock" )
{
m_sUnlockEntryID = sValue;
}
else if( sName == "sound" )
{
m_sSoundPath = sValue;
}
2004-12-04 22:33:55 +00:00
else if( sName == "preparescreen" )
{
m_vsScreensToPrepare.push_back( sValue );
}
else if( sName == "insertcredit" )
{
m_bInsertCredit = true;
}
else if( sName == "stopmusic" )
{
m_bStopMusic = true;
}
2005-11-30 04:27:10 +00:00
else if( sName == "applydefaultoptions" )
{
m_bApplyDefaultOptions = true;
}
else
{
2006-01-22 01:00:06 +00:00
RString sWarning = ssprintf( "Command '%s' is not valid.", cmd.GetOriginalCommandString().c_str() );
LOG->Warn( sWarning );
Dialog::OK( sWarning, "INVALID_GAME_COMMAND" );
2003-09-27 03:06:35 +00:00
}
}
2003-09-27 01:45:46 +00:00
2004-06-04 21:12:03 +00:00
int GetNumCreditsPaid()
{
int iNumCreditsPaid = GAMESTATE->GetNumSidesJoined();
// players other than the first joined for free
2005-02-21 17:29:49 +00:00
if( GAMESTATE->GetPremium() == PREMIUM_JOINT )
2004-06-04 21:12:03 +00:00
iNumCreditsPaid = min( iNumCreditsPaid, 1 );
return iNumCreditsPaid;
}
2004-06-28 07:26:00 +00:00
int GetCreditsRequiredToPlayStyle( const Style *style )
2003-11-07 20:14:29 +00:00
{
2005-02-21 17:29:49 +00:00
if( GAMESTATE->GetPremium() == PREMIUM_JOINT )
return 1;
switch( style->m_StyleType )
2003-11-07 20:14:29 +00:00
{
case ONE_PLAYER_ONE_SIDE:
2003-11-07 20:14:29 +00:00
return 1;
2006-06-24 00:09:50 +00:00
case TWO_PLAYERS_SHARED_SIDES:
case TWO_PLAYERS_TWO_SIDES:
2003-11-07 20:14:29 +00:00
return 2;
case ONE_PLAYER_TWO_SIDES:
2005-05-20 08:03:01 +00:00
return (GAMESTATE->GetPremium() == PREMIUM_DOUBLE) ? 1 : 2;
2006-06-24 00:09:50 +00:00
DEFAULT_FAIL( style->m_StyleType );
2003-11-07 20:14:29 +00:00
}
}
2004-06-28 07:26:00 +00:00
static bool AreStyleAndPlayModeCompatible( const Style *style, PlayMode pm )
2004-03-20 18:11:17 +00:00
{
2006-09-26 20:32:41 +00:00
if( style == NULL || pm == PlayMode_Invalid )
2004-03-20 18:11:17 +00:00
return true;
switch( pm )
{
case PLAY_MODE_BATTLE:
case PLAY_MODE_RAVE:
// 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.
// Techno Motion scales down versus arrows, though, so allow this.
2006-01-22 01:00:06 +00:00
if( style->m_iColsPerPlayer >= 6 && RString(GAMESTATE->m_pCurGame->m_szName) != "techno" )
2004-03-20 18:11:17 +00:00
return false;
/* Don't allow battle modes if the style takes both sides. */
if( style->m_StyleType==ONE_PLAYER_TWO_SIDES )
2004-03-20 18:11:17 +00:00
return false;
}
return true;
}
2006-01-22 01:00:06 +00:00
bool GameCommand::IsPlayable( RString *why ) const
2003-09-27 03:06:35 +00:00
{
if( m_bInvalid )
2004-04-30 07:46:46 +00:00
{
2004-05-16 12:05:51 +00:00
if( why )
2004-04-30 07:46:46 +00:00
*why = m_sInvalidReason;
2003-09-27 03:06:35 +00:00
return false;
2004-04-30 07:46:46 +00:00
}
2003-09-27 03:06:35 +00:00
2004-06-28 07:26:00 +00:00
if ( m_pStyle )
2003-09-27 03:06:35 +00:00
{
2004-05-07 08:08:11 +00:00
int iCredits = GAMESTATE->m_iCoins / PREFSMAN->m_iCoinsPerCredit;
const int iNumCreditsPaid = GetNumCreditsPaid();
2004-06-28 07:26:00 +00:00
const int iNumCreditsRequired = GetCreditsRequiredToPlayStyle(m_pStyle);
2005-02-21 17:29:49 +00:00
switch( GAMESTATE->GetCoinMode() )
{
2005-05-20 17:45:44 +00:00
case COIN_MODE_HOME:
case COIN_MODE_FREE:
iCredits = NUM_PLAYERS; /* not iNumCreditsPaid */
}
/* With PREFSMAN->m_bDelayedCreditsReconcile disabled, enough credits must be
* paid. (This means that enough sides must be joined.) Enabled, simply having
* enough credits lying in the machine is sufficient; we'll deduct the extra in
* Apply(). */
int iNumCreditsAvailable = iNumCreditsPaid;
2004-05-07 08:08:11 +00:00
if( PREFSMAN->m_bDelayedCreditsReconcile )
iNumCreditsAvailable += iCredits;
if( iNumCreditsAvailable < iNumCreditsRequired )
{
if( why )
*why = ssprintf( "need %i credits, have %i", iNumCreditsRequired, iNumCreditsAvailable );
return false;
}
/* If you've paid too much already, don't allow the mode. (If we allow this,
* the credits will be "refunded" in Apply(), but that's confusing.) */
/* Do allow the mode if they've already joined in more credits than
* are required. Otherwise, people who put in two credits to play
* doubles on a doubles-premium machiune will get locked out.
* the refund logic isn't that awkward because you never see the
* credits number jump up - the credits display is hidden if both
* sides are joined. -Chris */
//if( PREFSMAN->m_iCoinMode == COIN_PAY && iNumCreditsPaid > iNumCreditsRequired )
//{
// if( why )
// *why = ssprintf( "too many credits paid (%i > %i)", iNumCreditsPaid, iNumCreditsRequired );
// return false;
//}
2004-05-07 08:08:11 +00:00
/* If both sides are joined, disallow singles modes, since easy to select them
* accidentally, instead of versus mode. */
if( m_pStyle->m_StyleType == ONE_PLAYER_ONE_SIDE &&
GAMESTATE->GetNumSidesJoined() > 1 )
{
if( why )
*why = "too many players joined for ONE_PLAYER_ONE_CREDIT";
2003-11-09 01:09:35 +00:00
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. */
2006-09-26 20:32:41 +00:00
if( m_pm != PlayMode_Invalid || m_pStyle != NULL )
2003-09-27 03:06:35 +00:00
{
2006-09-26 20:32:41 +00:00
const PlayMode pm = (m_pm != PlayMode_Invalid) ? m_pm : GAMESTATE->m_PlayMode;
2006-09-30 22:13:20 +00:00
const Style *style = (m_pStyle != NULL)? m_pStyle: GAMESTATE->GetCurrentStyle();
2004-03-20 18:11:17 +00:00
if( !AreStyleAndPlayModeCompatible( style, pm ) )
{
if( why )
*why = ssprintf("mode %s is incompatible with style %s",
PlayModeToString(pm).c_str(), style->m_szName );
2004-03-20 18:11:17 +00:00
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;
}
}
if( !m_sPreferredModifiers.empty() )
{
// TODO: Split this and check each modifier individually
if( UNLOCKMAN->ModifierIsLocked(m_sPreferredModifiers) )
{ if( why )
*why = "Modifier is locked";
return false;
}
}
if( !m_sStageModifiers.empty() )
2005-03-29 01:45:38 +00:00
{
// TODO: Split this and check each modifier individually
if( UNLOCKMAN->ModifierIsLocked(m_sStageModifiers) )
2005-03-29 01:45:38 +00:00
{ if( why )
*why = "Modifier is locked";
return false;
}
}
2003-09-27 03:06:35 +00:00
return true;
}
2004-12-02 06:29:20 +00:00
void GameCommand::ApplyToAllPlayers() const
{
vector<PlayerNumber> vpns;
2005-02-19 09:56:53 +00:00
FOREACH_PlayerNumber( pn )
vpns.push_back( pn );
2003-09-27 01:45:46 +00:00
Apply( vpns );
}
2004-12-02 06:29:20 +00:00
void GameCommand::Apply( PlayerNumber pn ) const
{
vector<PlayerNumber> vpns;
vpns.push_back( pn );
Apply( vpns );
}
void GameCommand::Apply( const vector<PlayerNumber> &vpns ) const
{
if( m_Commands.v.size() )
{
// We were filled using a GameCommand from metrics. Apply the options in order.
FOREACH_CONST( Command, m_Commands.v, cmd )
{
GameCommand gc;
gc.m_bInvalid = false;
gc.m_bApplyCommitsScreens = m_bApplyCommitsScreens;
gc.LoadOne( *cmd );
gc.ApplySelf( vpns );
}
}
else
{
2005-09-11 04:34:24 +00:00
// We were filled by an OptionRowHandler in code. m_Commands isn't filled,
// so just apply the values that are already set in this.
this->ApplySelf( vpns );
}
}
void GameCommand::ApplySelf( const vector<PlayerNumber> &vpns ) const
{
const PlayMode OldPlayMode = GAMESTATE->m_PlayMode;
2006-09-26 20:32:41 +00:00
if( m_pm != PlayMode_Invalid )
2005-07-25 03:59:24 +00:00
GAMESTATE->m_PlayMode.Set( m_pm );
2004-06-28 07:26:00 +00:00
if( m_pStyle != NULL )
{
2006-09-30 22:22:26 +00:00
GAMESTATE->SetCurrentStyle( m_pStyle );
2004-05-07 08:08:11 +00:00
// It's possible to choose a style that didn't have enough
// players joined. If enough players aren't joined, then
// we need to subtract credits for the sides that will be
// joined as a result of applying this option.
2005-06-03 05:05:54 +00:00
if( GAMESTATE->GetCoinMode() == COIN_MODE_PAY )
{
int iNumCreditsRequired = GetCreditsRequiredToPlayStyle(m_pStyle);
int iNumCreditsPaid = GetNumCreditsPaid();
int iNumCreditsOwed = iNumCreditsRequired - iNumCreditsPaid;
GAMESTATE->m_iCoins -= iNumCreditsOwed * PREFSMAN->m_iCoinsPerCredit;
LOG->Trace( "Deducted %i coins, %i remaining",
iNumCreditsOwed * PREFSMAN->m_iCoinsPerCredit, GAMESTATE->m_iCoins );
}
2004-05-07 08:08:11 +00:00
// If only one side is joined and we picked a style
// that requires both sides, join the other side.
2004-06-28 07:26:00 +00:00
switch( m_pStyle->m_StyleType )
{
case ONE_PLAYER_ONE_SIDE:
break;
case TWO_PLAYERS_TWO_SIDES:
case ONE_PLAYER_TWO_SIDES:
2006-06-24 00:09:50 +00:00
case TWO_PLAYERS_SHARED_SIDES:
2004-05-07 08:08:11 +00:00
{
FOREACH_PlayerNumber( p )
GAMESTATE->JoinPlayer( p );
2004-05-07 08:08:11 +00:00
}
break;
default:
ASSERT(0);
}
}
2006-10-07 04:39:48 +00:00
if( m_dc != Difficulty_Invalid )
FOREACH_CONST( PlayerNumber, vpns, pn )
GAMESTATE->ChangePreferredDifficulty( *pn, m_dc );
2003-09-25 05:56:38 +00:00
if( m_sAnnouncer != "" )
ANNOUNCER->SwitchAnnouncer( m_sAnnouncer );
if( m_sPreferredModifiers != "" )
FOREACH_CONST( PlayerNumber, vpns, pn )
GAMESTATE->ApplyPreferredModifiers( *pn, m_sPreferredModifiers );
if( m_sStageModifiers != "" )
FOREACH_CONST( PlayerNumber, vpns, pn )
GAMESTATE->ApplyStageModifiers( *pn, m_sStageModifiers );
2005-02-22 03:34:56 +00:00
if( m_LuaFunction.IsSet() )
{
2005-06-16 22:10:24 +00:00
Lua *L = LUA->Get();
2005-02-22 03:34:56 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
{
2005-06-16 22:10:24 +00:00
m_LuaFunction.PushSelf( L );
ASSERT( !lua_isnil(L, -1) );
2005-02-22 03:34:56 +00:00
2005-06-16 22:10:24 +00:00
lua_pushnumber( L, *pn ); // 1st parameter
lua_call( L, 1, 0 ); // call function with 1 argument and 0 results
2005-02-22 03:34:56 +00:00
}
2005-06-16 22:10:24 +00:00
LUA->Release(L);
2005-02-22 03:34:56 +00:00
}
if( m_sScreen != "" && m_bApplyCommitsScreens )
SCREENMAN->SetNewScreen( m_sScreen );
2004-01-25 16:48:09 +00:00
if( m_pSong )
{
GAMESTATE->m_pCurSong.Set( m_pSong );
GAMESTATE->m_pPreferredSong = m_pSong;
}
2004-01-14 05:10:24 +00:00
if( m_pSteps )
FOREACH_CONST( PlayerNumber, vpns, pn )
GAMESTATE->m_pCurSteps[*pn].Set( m_pSteps );
2004-04-30 07:46:46 +00:00
if( m_pCourse )
{
2005-05-18 07:14:19 +00:00
GAMESTATE->m_pCurCourse.Set( m_pCourse );
GAMESTATE->m_pPreferredCourse = m_pCourse;
}
2004-06-03 08:22:02 +00:00
if( m_pTrail )
FOREACH_CONST( PlayerNumber, vpns, pn )
2005-05-18 07:14:19 +00:00
GAMESTATE->m_pCurTrail[*pn].Set( m_pTrail );
2006-10-07 10:49:53 +00:00
if( m_CourseDifficulty != CourseDifficulty_Invalid )
FOREACH_CONST( PlayerNumber, vpns, pn )
GAMESTATE->ChangePreferredCourseDifficulty( *pn, m_CourseDifficulty );
2004-01-14 05:10:24 +00:00
if( m_pCharacter )
FOREACH_CONST( PlayerNumber, vpns, pn )
GAMESTATE->m_pCurCharacters[*pn] = m_pCharacter;
2006-01-22 01:00:06 +00:00
for( map<RString,RString>::const_iterator i = m_SetEnv.begin(); i != m_SetEnv.end(); i++ )
{
Lua *L = LUA->Get();
GAMESTATE->m_Environment->PushSelf(L);
lua_pushstring( L, i->first );
lua_pushstring( L, i->second );
lua_settable( L, -3 );
2006-01-14 06:46:15 +00:00
lua_pop( L, 1 );
LUA->Release(L);
}
if( !m_sSongGroup.empty() )
2005-06-23 08:05:09 +00:00
GAMESTATE->m_sPreferredSongGroup.Set( m_sSongGroup );
2006-10-07 04:25:28 +00:00
if( m_SortOrder != SortOrder_Invalid )
GAMESTATE->m_PreferredSortOrder = m_SortOrder;
if( !m_sUnlockEntryID.empty() )
UNLOCKMAN->UnlockEntryID( m_sUnlockEntryID );
2004-12-05 11:54:43 +00:00
if( m_sSoundPath != "" )
2005-09-03 02:08:27 +00:00
SOUND->PlayOnce( THEME->GetPathS( "", m_sSoundPath ) );
2005-01-31 02:00:00 +00:00
if( m_iWeightPounds != -1 )
FOREACH_CONST( PlayerNumber, vpns, pn )
PROFILEMAN->GetProfile(*pn)->m_iWeightPounds = m_iWeightPounds;
2005-02-15 22:08:42 +00:00
if( m_iGoalCalories != -1 )
FOREACH_CONST( PlayerNumber, vpns, pn )
PROFILEMAN->GetProfile(*pn)->m_iGoalCalories = m_iGoalCalories;
2006-10-07 04:25:28 +00:00
if( m_GoalType != GoalType_Invalid )
2005-02-17 19:36:10 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
PROFILEMAN->GetProfile(*pn)->m_GoalType = m_GoalType;
2005-07-07 22:08:05 +00:00
if( !m_sProfileID.empty() )
FOREACH_CONST( PlayerNumber, vpns, pn )
ProfileManager::m_sDefaultLocalProfileID[*pn].Set( m_sProfileID );
2006-06-12 09:15:27 +00:00
if( !m_sUrl.empty() )
{
if( HOOKS->GoToURL( m_sUrl ) )
SCREENMAN->SetNewScreen( "ScreenExit" );
else
ScreenPrompt::Prompt( SM_None, COULD_NOT_LAUNCH_BROWSER );
}
2005-01-05 03:46:09 +00:00
/* If we're going to stop music, do so before preparing new screens, so we don't
* stop music between preparing screens and loading screens. */
if( m_bStopMusic )
SOUND->StopMusic();
2006-01-22 01:00:06 +00:00
FOREACH_CONST( RString, m_vsScreensToPrepare, s )
SCREENMAN->PrepareScreen( *s );
2004-12-04 23:24:14 +00:00
if( m_bInsertCredit )
{
2005-12-02 01:16:28 +00:00
StepMania::InsertCredit();
2004-12-04 23:24:14 +00:00
}
2005-11-30 04:27:10 +00:00
if( m_bApplyDefaultOptions )
{
// applying options affects only the current stage
2005-11-30 04:27:10 +00:00
FOREACH_PlayerNumber( p )
{
PlayerOptions po;
GAMESTATE->GetDefaultPlayerOptions( po );
2006-08-05 04:47:01 +00:00
GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.Assign( ModsLevel_Stage, po );
}
SongOptions so;
GAMESTATE->GetDefaultSongOptions( so );
2006-08-05 04:47:01 +00:00
GAMESTATE->m_SongOptions.Assign( ModsLevel_Stage, so );
2005-11-30 04:27:10 +00:00
}
// 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.
2005-04-21 04:27:13 +00:00
if( GAMESTATE->m_PlayMode == PLAY_MODE_ONI &&
GAMESTATE->m_PlayMode != OldPlayMode &&
GAMESTATE->m_SongOptions.GetStage().m_LifeType == SongOptions::LIFE_BAR )
2005-04-21 04:27:13 +00:00
{
SO_GROUP_ASSIGN( GAMESTATE->m_SongOptions, ModsLevel_Stage, m_LifeType, SongOptions::LIFE_BATTERY );
2005-04-21 04:27:13 +00:00
}
}
2003-09-29 08:56:33 +00:00
2004-12-02 06:29:20 +00:00
bool GameCommand::IsZero() const
2003-09-29 08:56:33 +00:00
{
if( m_pm != PlayMode_Invalid ||
2004-06-28 07:26:00 +00:00
m_pStyle != NULL ||
2006-10-07 04:39:48 +00:00
m_dc != Difficulty_Invalid ||
2003-09-29 08:56:33 +00:00
m_sAnnouncer != "" ||
m_sPreferredModifiers != "" ||
m_sStageModifiers != "" ||
2004-01-25 16:48:09 +00:00
m_pSong != NULL ||
m_pSteps != NULL ||
2004-06-03 20:25:29 +00:00
m_pCourse != NULL ||
m_pTrail != NULL ||
m_pCharacter != NULL ||
2006-10-07 10:49:53 +00:00
m_CourseDifficulty != CourseDifficulty_Invalid ||
!m_sSongGroup.empty() ||
2006-10-07 04:25:28 +00:00
m_SortOrder != SortOrder_Invalid ||
2005-01-31 02:00:00 +00:00
m_iWeightPounds != -1 ||
2005-02-15 22:08:42 +00:00
m_iGoalCalories != -1 ||
2006-10-07 04:25:28 +00:00
m_GoalType != GoalType_Invalid ||
2006-06-12 09:15:27 +00:00
!m_sProfileID.empty() ||
!m_sUrl.empty() )
2003-09-29 08:56:33 +00:00
return false;
return true;
}
2005-07-07 22:08:05 +00:00
// lua start
#include "LuaBinding.h"
#include "Game.h"
class LunaGameCommand: public Luna<GameCommand>
{
public:
static int GetName( T* p, lua_State *L ) { lua_pushstring(L, p->m_sName ); return 1; }
static int GetText( T* p, lua_State *L ) { lua_pushstring(L, p->m_sText ); return 1; }
static int GetIndex( T* p, lua_State *L ) { lua_pushnumber(L, p->m_iIndex ); return 1; }
static int GetMultiPlayer( T* p, lua_State *L ) { lua_pushnumber(L, p->m_MultiPlayer); return 1; }
static int GetProfileID( T* p, lua_State *L ) { lua_pushstring(L, p->m_sProfileID ); return 1; }
2005-09-07 22:05:41 +00:00
static int GetSong( T* p, lua_State *L ) { if(p->m_pSong==NULL) lua_pushnil(L); else p->m_pSong->PushSelf(L); return 1; }
2005-07-07 22:08:05 +00:00
2006-09-27 19:53:05 +00:00
LunaGameCommand()
2005-07-07 22:08:05 +00:00
{
ADD_METHOD( GetName );
ADD_METHOD( GetText );
ADD_METHOD( GetIndex );
ADD_METHOD( GetMultiPlayer );
ADD_METHOD( GetProfileID );
ADD_METHOD( GetSong );
2005-07-07 22:08:05 +00:00
}
};
LUA_REGISTER_CLASS( GameCommand )
// lua end
2004-05-31 22:42:12 +00:00
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* 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.
*/