Files
itgmania212121/src/Attack.cpp
T

145 lines
4.4 KiB
C++
Raw Normal View History

2011-03-17 01:47:30 -04:00
#include "global.h"
#include "Attack.h"
#include "GameState.h"
#include "RageUtil.h"
#include "Song.h"
#include "PlayerOptions.h"
#include "PlayerState.h"
2023-04-19 14:22:59 +02:00
#include <cmath>
2023-04-20 19:02:13 +02:00
#include <vector>
2023-04-19 14:22:59 +02:00
2011-03-17 01:47:30 -04:00
void Attack::GetAttackBeats( const Song *pSong, float &fStartBeat, float &fEndBeat ) const
{
2019-06-22 12:35:38 -07:00
ASSERT( pSong != nullptr );
2011-03-17 01:47:30 -04:00
ASSERT_M( fStartSecond >= 0, ssprintf("StartSecond: %f",fStartSecond) );
2023-04-19 14:22:59 +02:00
2011-05-09 21:11:33 -04:00
const TimingData &timing = pSong->m_SongTiming;
fStartBeat = timing.GetBeatFromElapsedTime( fStartSecond );
fEndBeat = timing.GetBeatFromElapsedTime( fStartSecond+fSecsRemaining );
2011-03-17 01:47:30 -04:00
}
/* Get the range for an attack that's being applied in realtime, eg. during battle
* mode. We need a PlayerState for this, so we can push the region off-screen to
* prevent popping when the attack has note modifers. */
void Attack::GetRealtimeAttackBeats( const Song *pSong, const PlayerState* pPlayerState, float &fStartBeat, float &fEndBeat ) const
{
2019-06-22 12:35:38 -07:00
ASSERT( pSong != nullptr );
2011-03-17 01:47:30 -04:00
if( fStartSecond >= 0 )
{
GetAttackBeats( pSong, fStartBeat, fEndBeat );
return;
}
2019-06-22 12:35:38 -07:00
ASSERT( pPlayerState != nullptr );
2011-03-17 01:47:30 -04:00
/* If reasonable, push the attack forward 8 beats so that notes on screen don't change suddenly. */
fStartBeat = std::min( GAMESTATE->m_Position.m_fSongBeat+8, pPlayerState->m_fLastDrawnBeat );
2023-04-19 14:22:59 +02:00
fStartBeat = std::trunc(fStartBeat) + 1;
2011-03-17 01:47:30 -04:00
2011-05-09 21:11:33 -04:00
const TimingData &timing = pSong->m_SongTiming;
const float lStartSecond = timing.GetElapsedTimeFromBeat( fStartBeat );
2011-03-17 01:47:30 -04:00
const float fEndSecond = lStartSecond + fSecsRemaining;
2011-05-09 21:11:33 -04:00
fEndBeat = timing.GetBeatFromElapsedTime( fEndSecond );
2023-04-19 14:22:59 +02:00
fEndBeat = std::trunc(fEndBeat) + 1;
2011-03-17 01:47:30 -04:00
// loading the course should have caught this.
ASSERT_M( fEndBeat >= fStartBeat, ssprintf("EndBeat %f >= StartBeat %f", fEndBeat, fStartBeat) );
}
bool Attack::operator== ( const Attack &rhs ) const
{
#define EQUAL(a) (a==rhs.a)
2023-04-19 14:22:59 +02:00
return
2011-03-17 01:47:30 -04:00
EQUAL(level) &&
EQUAL(fStartSecond) &&
EQUAL(fSecsRemaining) &&
EQUAL(sModifiers) &&
EQUAL(bOn) &&
EQUAL(bGlobal);
}
bool Attack::ContainsTransformOrTurn() const
{
PlayerOptions po;
po.FromString( sModifiers );
return po.ContainsTransformOrTurn();
}
Attack Attack::FromGlobalCourseModifier( const RString &sModifiers )
{
Attack a;
a.fStartSecond = 0;
a.fSecsRemaining = 10000; /* whole song */
a.level = ATTACK_LEVEL_1;
a.sModifiers = sModifiers;
a.bGlobal = true;
return a;
}
RString Attack::GetTextDescription() const
{
RString s = sModifiers + " " + ssprintf("(%.2f seconds)", fSecsRemaining);
return s;
}
2012-05-21 21:10:10 -04:00
int Attack::GetNumAttacks() const
{
std::vector<RString> tmp;
2012-05-21 21:10:10 -04:00
split(this->sModifiers, ",", tmp);
return tmp.size();
}
2011-03-17 01:47:30 -04:00
bool AttackArray::ContainsTransformOrTurn() const
{
2019-06-22 12:35:38 -07:00
return std::any_of((*this).begin(), (*this).end(), [](Attack const &a) { return a.ContainsTransformOrTurn(); });
2011-03-17 01:47:30 -04:00
}
std::vector<RString> AttackArray::ToVectorString() const
2011-06-24 22:11:07 -04:00
{
std::vector<RString> ret;
2019-06-22 12:35:38 -07:00
for (Attack const &a : *this)
2011-06-24 22:11:07 -04:00
{
ret.push_back(ssprintf("TIME=%f:LEN=%f:MODS=%s",
2019-06-22 12:35:38 -07:00
a.fStartSecond,
a.fSecsRemaining,
a.sModifiers.c_str()));
2011-06-24 22:11:07 -04:00
}
return ret;
}
2011-06-30 13:35:25 -04:00
void AttackArray::UpdateStartTimes(float delta)
{
2019-06-22 12:35:38 -07:00
for (Attack &a : *this)
2011-06-30 13:35:25 -04:00
{
2019-06-22 12:35:38 -07:00
a.fStartSecond += delta;
2011-06-30 13:35:25 -04:00
}
}
2011-03-17 01:47:30 -04:00
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
2023-04-19 14:22:59 +02:00
*
2011-03-17 01:47:30 -04:00
* 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.
2023-04-19 14:22:59 +02:00
*
2011-03-17 01:47:30 -04:00
* 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.
*/