2004-05-23 00:53:20 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "Trail.h"
|
|
|
|
|
#include "Foreach.h"
|
|
|
|
|
#include "Steps.h"
|
2004-05-23 21:16:58 +00:00
|
|
|
#include "song.h"
|
2004-07-23 04:45:48 +00:00
|
|
|
#include "PlayerOptions.h"
|
|
|
|
|
#include "NoteData.h"
|
|
|
|
|
#include "NoteDataUtil.h"
|
2004-05-23 00:53:20 +00:00
|
|
|
|
|
|
|
|
void TrailEntry::GetAttackArray( AttackArray &out ) const
|
|
|
|
|
{
|
|
|
|
|
if( !Modifiers.empty() )
|
2005-01-03 23:30:56 +00:00
|
|
|
out.push_back( Attack::FromGlobalCourseModifier( Modifiers ) );
|
2004-05-23 00:53:20 +00:00
|
|
|
|
|
|
|
|
out.insert( out.end(), Attacks.begin(), Attacks.end() );
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-31 20:04:56 +00:00
|
|
|
bool TrailEntry::operator== ( const TrailEntry &rhs ) const
|
|
|
|
|
{
|
|
|
|
|
#define EQUAL(a) (a==rhs.a)
|
|
|
|
|
return
|
|
|
|
|
EQUAL(pSong) &&
|
|
|
|
|
EQUAL(pSteps) &&
|
|
|
|
|
EQUAL(Modifiers) &&
|
|
|
|
|
EQUAL(Attacks) &&
|
2005-03-10 22:54:55 +00:00
|
|
|
EQUAL(bSecret) &&
|
2004-05-31 20:04:56 +00:00
|
|
|
EQUAL(iLowMeter) &&
|
|
|
|
|
EQUAL(iHighMeter) &&
|
|
|
|
|
EQUAL(dc);
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-23 04:45:48 +00:00
|
|
|
bool TrailEntry::ContainsTransformOrTurn() const
|
|
|
|
|
{
|
|
|
|
|
PlayerOptions po;
|
|
|
|
|
po.FromString( Modifiers );
|
|
|
|
|
if( po.ContainsTransformOrTurn() )
|
|
|
|
|
return true;
|
|
|
|
|
if( Attacks.ContainsTransformOrTurn() )
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-07 22:30:39 +00:00
|
|
|
void Trail::SetRadarValues( const RadarValues &rv )
|
|
|
|
|
{
|
|
|
|
|
m_CachedRadarValues = rv;
|
|
|
|
|
m_bRadarValuesCached = true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
RadarValues Trail::GetRadarValues() const
|
|
|
|
|
{
|
2005-03-10 22:54:55 +00:00
|
|
|
if( IsSecret() )
|
2004-07-24 06:40:51 +00:00
|
|
|
{
|
|
|
|
|
// Don't calculate RadarValues for a non-fixed Course. They values are
|
|
|
|
|
// worthless because they'll change every time this Trail is
|
|
|
|
|
// regenerated.
|
|
|
|
|
return RadarValues();
|
|
|
|
|
}
|
|
|
|
|
else if( m_bRadarValuesCached )
|
2004-05-23 00:53:20 +00:00
|
|
|
{
|
2004-07-23 05:28:41 +00:00
|
|
|
return m_CachedRadarValues;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-03-07 22:30:39 +00:00
|
|
|
RadarValues rv;
|
|
|
|
|
rv.Zero();
|
2004-07-23 05:28:41 +00:00
|
|
|
|
|
|
|
|
FOREACH_CONST( TrailEntry, m_vEntries, e )
|
2004-07-23 04:45:48 +00:00
|
|
|
{
|
2004-07-23 05:28:41 +00:00
|
|
|
const Steps *pSteps = e->pSteps;
|
|
|
|
|
ASSERT( pSteps );
|
2004-08-05 20:14:28 +00:00
|
|
|
/* Hack: don't calculate for autogen entries; it makes writing Catalog.xml
|
|
|
|
|
* take way too long. (Tournamix 4 Sample.crs takes me ~10s.) */
|
|
|
|
|
if( !pSteps->IsAutogen() && e->ContainsTransformOrTurn() )
|
2004-07-23 05:28:41 +00:00
|
|
|
{
|
|
|
|
|
NoteData nd;
|
2004-10-23 17:43:49 +00:00
|
|
|
pSteps->GetNoteData( nd );
|
2004-07-23 05:28:41 +00:00
|
|
|
RadarValues rv_orig;
|
2005-04-26 04:16:45 +00:00
|
|
|
NoteDataUtil::CalculateRadarValues( nd, e->pSong->m_fMusicLengthSeconds, rv_orig );
|
2004-07-23 05:28:41 +00:00
|
|
|
PlayerOptions po;
|
|
|
|
|
po.FromString( e->Modifiers );
|
|
|
|
|
if( po.ContainsTransformOrTurn() )
|
|
|
|
|
NoteDataUtil::TransformNoteData( nd, po, pSteps->m_StepsType );
|
|
|
|
|
NoteDataUtil::TransformNoteData( nd, e->Attacks, pSteps->m_StepsType, e->pSong );
|
2005-03-07 22:30:39 +00:00
|
|
|
RadarValues transformed_rv;
|
2005-04-26 04:16:45 +00:00
|
|
|
NoteDataUtil::CalculateRadarValues( nd, e->pSong->m_fMusicLengthSeconds, transformed_rv );
|
2005-03-07 22:30:39 +00:00
|
|
|
rv += transformed_rv;
|
2004-07-23 05:28:41 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-03-07 22:30:39 +00:00
|
|
|
rv += pSteps->GetRadarValues();
|
2004-07-23 05:28:41 +00:00
|
|
|
}
|
2004-07-23 04:45:48 +00:00
|
|
|
}
|
2004-05-23 00:53:20 +00:00
|
|
|
|
2005-03-07 22:30:39 +00:00
|
|
|
/* Hack: SetRadarValues is non-const (a const setter doesn't
|
|
|
|
|
* make sense), but it only modifies a mutable value. Just
|
|
|
|
|
* cast away const. */
|
|
|
|
|
const_cast<Trail*>(this)->SetRadarValues( rv );
|
|
|
|
|
|
2004-07-23 05:28:41 +00:00
|
|
|
return m_CachedRadarValues;
|
|
|
|
|
}
|
2004-05-23 00:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
2004-06-03 08:22:02 +00:00
|
|
|
int Trail::GetMeter() const
|
2004-05-23 00:53:20 +00:00
|
|
|
{
|
2004-06-03 08:22:02 +00:00
|
|
|
if( m_iSpecifiedMeter != -1 )
|
|
|
|
|
return m_iSpecifiedMeter;
|
|
|
|
|
|
2004-05-23 00:53:20 +00:00
|
|
|
if( m_vEntries.empty() )
|
|
|
|
|
return 0;
|
|
|
|
|
|
2004-06-03 08:22:02 +00:00
|
|
|
float fMeter = GetTotalMeter() / (float)m_vEntries.size();
|
|
|
|
|
|
|
|
|
|
return (int)roundf( fMeter );
|
2004-05-23 00:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Trail::GetTotalMeter() const
|
|
|
|
|
{
|
|
|
|
|
int iTotalMeter = 0;
|
|
|
|
|
FOREACH_CONST( TrailEntry, m_vEntries, e )
|
|
|
|
|
{
|
2004-05-24 03:41:39 +00:00
|
|
|
iTotalMeter += e->pSteps->GetMeter();
|
2004-05-23 00:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return iTotalMeter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Trail::GetLengthSeconds() const
|
|
|
|
|
{
|
|
|
|
|
float fSecs = 0;
|
|
|
|
|
FOREACH_CONST( TrailEntry, m_vEntries, e )
|
|
|
|
|
{
|
|
|
|
|
fSecs += e->pSong->m_fMusicLengthSeconds;
|
|
|
|
|
}
|
|
|
|
|
return fSecs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Trail::GetDisplayBpms( DisplayBpms &AddTo )
|
|
|
|
|
{
|
|
|
|
|
FOREACH_CONST( TrailEntry, m_vEntries, e )
|
|
|
|
|
{
|
2005-03-10 22:54:55 +00:00
|
|
|
if( e->bSecret )
|
2004-05-23 00:53:20 +00:00
|
|
|
{
|
|
|
|
|
AddTo.Add( -1 );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Song *pSong = e->pSong;
|
|
|
|
|
ASSERT( pSong );
|
|
|
|
|
switch( pSong->m_DisplayBPMType )
|
|
|
|
|
{
|
|
|
|
|
case Song::DISPLAY_ACTUAL:
|
|
|
|
|
case Song::DISPLAY_SPECIFIED:
|
|
|
|
|
{
|
|
|
|
|
pSong->GetDisplayBpms( AddTo );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Song::DISPLAY_RANDOM:
|
|
|
|
|
AddTo.Add( -1 );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-10 22:54:55 +00:00
|
|
|
bool Trail::IsSecret() const
|
2004-07-24 06:40:51 +00:00
|
|
|
{
|
|
|
|
|
FOREACH_CONST( TrailEntry, m_vEntries, e )
|
|
|
|
|
{
|
2005-03-10 22:54:55 +00:00
|
|
|
if( e->bSecret )
|
2004-07-24 06:40:51 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Trail::ContainsSong( Song* pSong ) const
|
|
|
|
|
{
|
|
|
|
|
FOREACH_CONST( TrailEntry, m_vEntries, e )
|
|
|
|
|
{
|
|
|
|
|
if( e->pSong == pSong )
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-06 11:59:09 +00:00
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
|
2005-06-20 05:02:03 +00:00
|
|
|
class LunaTrail: public Luna<Trail>
|
2005-05-06 11:59:09 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
LunaTrail() { LUA->Register( Register ); }
|
|
|
|
|
|
2005-08-01 05:11:30 +00:00
|
|
|
static int GetCourseDifficulty( T* p, lua_State *L ) { lua_pushnumber(L, p->m_CourseDifficulty ); return 1; }
|
|
|
|
|
static int GetStepsType( T* p, lua_State *L ) { lua_pushnumber(L, p->m_StepsType ); return 1; }
|
2005-05-06 11:59:09 +00:00
|
|
|
|
|
|
|
|
static void Register(lua_State *L)
|
|
|
|
|
{
|
2005-09-10 02:47:04 +00:00
|
|
|
ADD_METHOD( GetCourseDifficulty );
|
|
|
|
|
ADD_METHOD( GetStepsType );
|
2005-08-01 05:11:30 +00:00
|
|
|
|
2005-05-06 11:59:09 +00:00
|
|
|
Luna<T>::Register( L );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_CLASS( Trail )
|
|
|
|
|
// lua end
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|