Files
itgmania212121/stepmania/src/SongOptions.cpp
T

251 lines
6.8 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-08-01 13:42:56 +00:00
#include "SongOptions.h"
#include "RageUtil.h"
#include "GameState.h"
2006-02-05 20:30:37 +00:00
#include "CommonMetrics.h"
2002-08-01 13:42:56 +00:00
2003-08-13 18:30:46 +00:00
void SongOptions::Init()
{
m_LifeType = LIFE_BAR;
m_DrainType = DRAIN_NORMAL;
m_iBatteryLives = 4;
2007-01-25 11:03:41 +00:00
m_bAssistClap = false;
m_bAssistMetronome = false;
2003-08-13 18:30:46 +00:00
m_fMusicRate = 1.0f;
m_SpeedfMusicRate = 1.0f;
2006-11-30 08:22:30 +00:00
m_fHaste = 0.0f;
m_SpeedfHaste = 1.0f;
2005-04-11 04:50:39 +00:00
m_AutosyncType = AUTOSYNC_OFF;
2007-01-16 01:28:59 +00:00
m_SoundEffectType = SOUNDEFFECT_OFF;
2003-09-04 21:24:50 +00:00
m_bSaveScore = true;
2003-08-13 18:30:46 +00:00
}
2002-08-01 13:42:56 +00:00
void SongOptions::Approach( const SongOptions& other, float fDeltaSeconds )
{
#define APPROACH( opt ) \
fapproach( m_ ## opt, other.m_ ## opt, fDeltaSeconds * other.m_Speed ## opt );
#define DO_COPY( x ) \
x = other.x;
DO_COPY( m_LifeType );
DO_COPY( m_DrainType );
DO_COPY( m_iBatteryLives );
APPROACH( fMusicRate );
2006-11-30 08:22:30 +00:00
APPROACH( fHaste );
2007-01-25 11:03:41 +00:00
DO_COPY( m_bAssistClap );
DO_COPY( m_bAssistMetronome );
DO_COPY( m_AutosyncType );
2007-01-16 01:28:59 +00:00
DO_COPY( m_SoundEffectType );
DO_COPY( m_bSaveScore );
#undef APPROACH
#undef DO_COPY
}
2006-11-30 08:22:30 +00:00
static void AddPart( vector<RString> &AddTo, float level, RString name )
{
if( level == 0 )
return;
2007-01-03 05:05:28 +00:00
const RString LevelStr = (level == 1)? RString(""): ssprintf( "%ld%% ", lrintf(level*100) );
2006-11-30 08:22:30 +00:00
AddTo.push_back( LevelStr + name );
}
2006-02-05 20:30:37 +00:00
void SongOptions::GetMods( vector<RString> &AddTo ) const
2002-08-01 13:42:56 +00:00
{
switch( m_LifeType )
{
case LIFE_BAR:
switch( m_DrainType )
{
2006-02-05 20:30:37 +00:00
case DRAIN_NORMAL: break;
case DRAIN_NO_RECOVER: AddTo.push_back("NoRecover"); break;
case DRAIN_SUDDEN_DEATH: AddTo.push_back("SuddenDeath"); break;
2002-08-01 13:42:56 +00:00
}
break;
case LIFE_BATTERY:
2006-02-05 20:30:37 +00:00
AddTo.push_back( ssprintf( "%dLives", m_iBatteryLives ) );
2002-08-01 13:42:56 +00:00
break;
2005-04-21 04:27:13 +00:00
case LIFE_TIME:
2006-02-05 20:30:37 +00:00
AddTo.push_back( "LifeTime" );
2005-04-21 04:27:13 +00:00
break;
2005-04-11 04:50:39 +00:00
default: ASSERT(0);
2002-08-01 13:42:56 +00:00
}
2002-08-01 13:42:56 +00:00
if( m_fMusicRate != 1 )
{
2006-01-22 01:00:06 +00:00
RString s = ssprintf( "%2.2f", m_fMusicRate );
2005-12-21 07:50:14 +00:00
if( s[s.size()-1] == '0' )
s.erase( s.size()-1 );
2006-02-05 20:30:37 +00:00
AddTo.push_back( s + "xMusic" );
2002-08-01 13:42:56 +00:00
}
2006-11-30 08:22:30 +00:00
AddPart( AddTo, m_fHaste, "Haste" );
2005-04-11 04:50:39 +00:00
switch( m_AutosyncType )
{
case AUTOSYNC_OFF: break;
2006-02-05 20:30:37 +00:00
case AUTOSYNC_SONG: AddTo.push_back("AutosyncSong"); break;
case AUTOSYNC_MACHINE: AddTo.push_back("AutosyncMachine"); break;
case AUTOSYNC_TEMPO: AddTo.push_back("AutosyncTempo"); break;
default: ASSERT(0);
2005-04-11 04:50:39 +00:00
}
2007-01-16 01:28:59 +00:00
switch( m_SoundEffectType )
{
case SOUNDEFFECT_OFF: break;
case SOUNDEFFECT_SPEED: AddTo.push_back("EffectSpeed"); break;
case SOUNDEFFECT_PITCH: AddTo.push_back("EffectPitch"); break;
default: ASSERT(0);
}
2007-01-25 11:03:41 +00:00
if( m_bAssistClap )
AddTo.push_back( "Clap" );
if( m_bAssistMetronome )
AddTo.push_back( "Metronome" );
2006-02-05 20:30:37 +00:00
}
2007-01-25 11:03:41 +00:00
void SongOptions::GetLocalizedMods( vector<RString> &v ) const
2006-02-05 20:30:37 +00:00
{
2007-01-25 11:03:41 +00:00
GetMods( v );
FOREACH( RString, v, s )
2006-02-05 20:30:37 +00:00
{
*s = CommonMetrics::LocalizeOptionItem( *s, true );
}
}
2002-10-01 01:55:07 +00:00
2006-02-05 20:30:37 +00:00
RString SongOptions::GetString() const
{
vector<RString> v;
GetMods( v );
return join( ", ", v );
2002-08-01 13:42:56 +00:00
}
2006-02-05 20:30:37 +00:00
RString SongOptions::GetLocalizedString() const
{
vector<RString> v;
GetLocalizedMods( v );
return join( ", ", v );
}
2003-02-22 21:56:59 +00:00
/* Options are added to the current settings; call Init() beforehand if
* you don't want this. */
void SongOptions::FromString( const RString &sMultipleMods )
2002-08-01 13:42:56 +00:00
{
RString sTemp = sMultipleMods;
vector<RString> vs;
split( sTemp, ",", vs, true );
RString sThrowAway;
FOREACH( RString, vs, s )
{
FromOneModString( *s, sThrowAway );
}
}
2002-08-01 13:42:56 +00:00
bool SongOptions::FromOneModString( const RString &sOneMod, RString &sErrorOut )
{
RString sBit = sOneMod;
sBit.MakeLower();
2007-12-01 23:33:38 +00:00
Trim( sBit );
Regex mult("^([0-9]+(\\.[0-9]+)?)xmusic$");
vector<RString> matches;
if( mult.Compare(sBit, matches) )
2002-08-01 13:42:56 +00:00
{
m_fMusicRate = StringToFloat( matches[0] );
return true;
}
matches.clear();
Regex lives("^([0-9]+) ?(lives|life)$");
if( lives.Compare(sBit, matches) )
{
m_iBatteryLives = atoi( matches[0] );
return true;
}
vector<RString> asParts;
split( sBit, " ", asParts, true );
bool on = true;
if( asParts.size() > 1 )
{
sBit = asParts[1];
if( asParts[0] == "no" )
on = false;
2002-08-01 13:42:56 +00:00
}
if( sBit == "norecover" ) m_DrainType = DRAIN_NO_RECOVER;
else if( sBit == "suddendeath" ||
sBit == "death" ) m_DrainType = DRAIN_SUDDEN_DEATH;
else if( sBit == "power-drop" ) m_DrainType = DRAIN_NO_RECOVER;
else if( sBit == "normal-drain" ) m_DrainType = DRAIN_NORMAL;
else if( sBit == "clap" ) m_bAssistClap = on;
else if( sBit == "metronome" ) m_bAssistMetronome = on;
else if( sBit == "autosync" || sBit == "autosyncsong" )
m_AutosyncType = on ? AUTOSYNC_SONG : AUTOSYNC_OFF;
else if( sBit == "autosyncmachine" )
m_AutosyncType = on ? AUTOSYNC_MACHINE : AUTOSYNC_OFF;
else if( sBit == "autosynctempo" )
m_AutosyncType = on ? AUTOSYNC_TEMPO : AUTOSYNC_OFF;
else if( sBit == "effect" && !on )
m_SoundEffectType = SOUNDEFFECT_OFF;
else if( sBit == "effectspeed" )
m_SoundEffectType = on ? SOUNDEFFECT_SPEED : SOUNDEFFECT_OFF;
else if( sBit == "effectpitch" )
m_SoundEffectType = on ? SOUNDEFFECT_PITCH : SOUNDEFFECT_OFF;
else if( sBit == "savescore" ) m_bSaveScore = on;
else if( sBit == "bar" ) m_LifeType = LIFE_BAR;
else if( sBit == "battery" ) m_LifeType = LIFE_BATTERY;
else if( sBit == "lifetime" ) m_LifeType = LIFE_TIME;
else if( sBit == "haste" ) m_fHaste = on? 1.0f:0.0f;
else
return false;
return true;
2002-08-01 13:42:56 +00:00
}
2004-01-18 07:44:39 +00:00
bool SongOptions::operator==( const SongOptions &other ) const
{
2004-01-11 04:33:21 +00:00
#define COMPARE(x) { if( x != other.x ) return false; }
COMPARE( m_LifeType );
COMPARE( m_DrainType );
COMPARE( m_iBatteryLives );
COMPARE( m_fMusicRate );
2006-11-30 08:22:30 +00:00
COMPARE( m_fHaste );
2007-01-25 11:03:41 +00:00
COMPARE( m_bAssistClap );
COMPARE( m_bAssistMetronome );
2005-04-11 04:50:39 +00:00
COMPARE( m_AutosyncType );
2007-01-16 01:28:59 +00:00
COMPARE( m_SoundEffectType );
COMPARE( m_bSaveScore );
#undef COMPARE
return true;
}
2004-05-31 21:35:31 +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.
*/