Files
itgmania212121/stepmania/src/LifeMeterBar.cpp
T

465 lines
14 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-04-28 20:42:32 +00:00
#include "LifeMeterBar.h"
2002-07-23 01:41:40 +00:00
#include "PrefsManager.h"
2002-07-27 19:29:51 +00:00
#include "RageException.h"
#include "RageTimer.h"
#include "GameState.h"
2003-07-04 18:03:20 +00:00
#include "RageMath.h"
#include "ThemeManager.h"
2003-10-16 06:49:02 +00:00
#include "song.h"
2005-02-16 03:25:45 +00:00
#include "StatsManager.h"
#include "ThemeMetric.h"
#include "PlayerState.h"
2005-04-10 01:24:00 +00:00
#include "Quad.h"
#include "ActorUtil.h"
2005-04-21 11:16:01 +00:00
#include "StreamDisplay.h"
2005-06-20 18:37:08 +00:00
#include "Steps.h"
2002-04-28 20:42:32 +00:00
static ThemeMetric<float> METER_WIDTH ("LifeMeterBar","MeterWidth");
static ThemeMetric<float> METER_HEIGHT ("LifeMeterBar","MeterHeight");
static ThemeMetric<float> DANGER_THRESHOLD ("LifeMeterBar","DangerThreshold");
static ThemeMetric<int> NUM_CHAMBERS ("LifeMeterBar","NumChambers");
2005-04-03 08:12:06 +00:00
static ThemeMetric<int> NUM_STRIPS ("LifeMeterBar","NumStrips");
static ThemeMetric<float> INITIAL_VALUE ("LifeMeterBar","InitialValue");
2002-06-24 22:04:31 +00:00
const float FAIL_THRESHOLD = 0;
2002-07-23 01:41:40 +00:00
2002-04-28 20:42:32 +00:00
LifeMeterBar::LifeMeterBar()
{
2002-07-29 03:06:55 +00:00
switch( GAMESTATE->m_SongOptions.m_DrainType )
{
case SongOptions::DRAIN_NORMAL:
m_fLifePercentage = INITIAL_VALUE;
break;
/* These types only go down, so they always start at full. */
case SongOptions::DRAIN_NO_RECOVER:
case SongOptions::DRAIN_SUDDEN_DEATH:
m_fLifePercentage = 1.0f; break;
2002-07-29 03:06:55 +00:00
default: ASSERT(0);
}
2005-04-21 11:16:01 +00:00
const CString sType = "LifeMeterBar";
m_fPassingAlpha = 0;
2002-07-23 01:41:40 +00:00
m_fHotAlpha = 0;
m_bFailedEarlier = false;
m_fBaseLifeDifficulty = PREFSMAN->m_fLifeDifficultyScale;
m_fLifeDifficulty = m_fBaseLifeDifficulty;
2003-07-29 12:42:38 +00:00
// set up progressive lifebar
m_iProgressiveLifebar = PREFSMAN->m_iProgressiveLifebar;
m_iMissCombo = 0;
// set up combotoregainlife
m_iComboToRegainLife = 0;
2005-04-21 11:16:01 +00:00
m_sprBackground.Load( THEME->GetPathG(sType,"background") );
2005-04-10 01:24:00 +00:00
m_sprBackground->SetName( "Background" );
m_sprBackground->ZoomToWidth( METER_WIDTH );
m_sprBackground->ZoomToHeight( METER_HEIGHT );
this->AddChild( m_sprBackground );
m_quadDangerGlow.ZoomToWidth( METER_WIDTH );
m_quadDangerGlow.ZoomToHeight( METER_HEIGHT );
2005-04-21 11:16:01 +00:00
m_quadDangerGlow.SetEffectDiffuseShift();
m_quadDangerGlow.SetEffectColor1( RageColor(1,0,0,0.8f) );
m_quadDangerGlow.SetEffectColor2( RageColor(1,0,0,0) );
m_quadDangerGlow.SetEffectClock( Actor::CLOCK_BGM_BEAT );
2005-04-10 01:24:00 +00:00
this->AddChild( &m_quadDangerGlow );
2005-04-21 11:16:01 +00:00
m_pStream = new StreamDisplay;
bool bExtra = GAMESTATE->IsExtraStage()||GAMESTATE->IsExtraStage2();
CString sExtra = bExtra ? "extra " : "";
m_pStream->Load(
METER_WIDTH,
METER_HEIGHT,
NUM_STRIPS,
NUM_CHAMBERS,
THEME->GetPathG(sType,sExtra+"normal"),
THEME->GetPathG(sType,sExtra+"hot"),
THEME->GetPathG(sType,sExtra+"passing"),
THEME->GetMetricA(sType,"StreamNormalOnCommand"),
THEME->GetMetricA(sType,"StreamHotOnCommand"),
THEME->GetMetricA(sType,"StreamPassingOnCommand")
2005-04-21 11:16:01 +00:00
);
2005-04-10 01:24:00 +00:00
this->AddChild( m_pStream );
2005-04-21 11:16:01 +00:00
m_sprFrame.Load( THEME->GetPathG(sType,sExtra+"frame") );
m_sprFrame->SetName( "Frame" );
this->AddChild( m_sprFrame );
AfterLifeChanged();
}
2002-05-27 08:23:27 +00:00
LifeMeterBar::~LifeMeterBar()
{
2005-04-21 11:16:01 +00:00
SAFE_DELETE( m_pStream );
2002-04-28 20:42:32 +00:00
}
void LifeMeterBar::Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats )
2002-07-23 01:41:40 +00:00
{
LifeMeter::Load( pPlayerState, pPlayerStageStats );
PlayerNumber pn = pPlayerState->m_PlayerNumber;
2005-06-20 18:37:08 +00:00
// Change life difficulty to really easy if merciful beginner on
bool bMercifulBeginnerInEffect =
GAMESTATE->m_PlayMode == PLAY_MODE_REGULAR &&
GAMESTATE->IsPlayerEnabled( pPlayerState ) &&
GAMESTATE->m_pCurSteps[pn]->GetDifficulty() == DIFFICULTY_BEGINNER &&
2005-06-20 18:37:08 +00:00
PREFSMAN->m_bMercifulBeginner;
if( bMercifulBeginnerInEffect )
{
m_fBaseLifeDifficulty = 2.5f;
m_fLifeDifficulty = m_fBaseLifeDifficulty;
}
2002-07-23 01:41:40 +00:00
}
2002-04-28 20:42:32 +00:00
void LifeMeterBar::ChangeLife( TapNoteScore score )
{
2002-09-07 10:22:21 +00:00
float fDeltaLife=0.f;
2002-07-27 19:29:51 +00:00
switch( GAMESTATE->m_SongOptions.m_DrainType )
2002-04-28 20:42:32 +00:00
{
2002-07-27 19:29:51 +00:00
case SongOptions::DRAIN_NORMAL:
2002-07-23 01:41:40 +00:00
switch( score )
{
case TNS_Tier1: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeTier1; break;
case TNS_Tier2: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeTier2; break;
case TNS_Tier3: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeTier3; break;
case TNS_Tier4: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeTier4; break;
case TNS_Tier5: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeTier5; break;
case TNS_Miss: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeMiss; break;
case TNS_HitMine: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeHitMine; break;
default:
ASSERT(0);
2002-07-23 01:41:40 +00:00
}
if( IsHot() && score < TNS_Tier4 )
2002-07-23 01:41:40 +00:00
fDeltaLife = -0.10f; // make it take a while to get back to "doing great"
break;
2002-07-27 19:29:51 +00:00
case SongOptions::DRAIN_NO_RECOVER:
2002-07-23 01:41:40 +00:00
switch( score )
{
case TNS_Tier1: fDeltaLife = +0.000f; break;
case TNS_Tier2: fDeltaLife = +0.000f; break;
case TNS_Tier3: fDeltaLife = +0.000f; break;
case TNS_Tier4: fDeltaLife = +0.000f; break;
case TNS_Tier5: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeTier5; break;
case TNS_Miss: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeMiss; break;
case TNS_HitMine: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeHitMine; break;
default:
ASSERT(0);
2002-07-23 01:41:40 +00:00
}
break;
2002-07-27 19:29:51 +00:00
case SongOptions::DRAIN_SUDDEN_DEATH:
2002-07-29 03:06:55 +00:00
switch( score )
{
case TNS_Tier1: fDeltaLife = +0; break;
case TNS_Tier2: fDeltaLife = +0; break;
case TNS_Tier3: fDeltaLife = +0; break;
case TNS_Tier4: fDeltaLife = -1.0; break;
case TNS_Tier5: fDeltaLife = -1.0; break;
case TNS_Miss: fDeltaLife = -1.0; break;
case TNS_HitMine: fDeltaLife = -1.0; break;
default:
ASSERT(0);
2002-07-29 03:06:55 +00:00
}
2002-07-23 01:41:40 +00:00
break;
2002-07-29 03:06:55 +00:00
default:
ASSERT(0);
2002-04-28 20:42:32 +00:00
}
2003-11-11 07:36:28 +00:00
ChangeLife( fDeltaLife );
}
void LifeMeterBar::ChangeLife( HoldNoteScore score, TapNoteScore tscore )
{
/* The initial tap note score (which we happen to have in have in
* tscore) has already been reported to the above function. If the
* hold end result was an NG, count it as a miss; if the end result
* was an OK, count a perfect. (Remember, this is just life meter
* computation, not scoring.) */
float fDeltaLife=0.f;
switch( GAMESTATE->m_SongOptions.m_DrainType )
{
case SongOptions::DRAIN_NORMAL:
switch( score )
{
case HNS_Held: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeHeld; break;
case HNS_LetGo: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeLetGo; break;
2003-11-11 07:36:28 +00:00
default:
ASSERT(0);
}
if( IsHot() && score == HNS_LetGo )
2003-11-11 07:36:28 +00:00
fDeltaLife = -0.10f; // make it take a while to get back to "doing great"
break;
case SongOptions::DRAIN_NO_RECOVER:
switch( score )
{
case HNS_Held: fDeltaLife = +0.000f; break;
case HNS_LetGo: fDeltaLife = PREFSMAN->m_fLifeDeltaPercentChangeLetGo; break;
2003-11-11 07:36:28 +00:00
default:
ASSERT(0);
}
break;
case SongOptions::DRAIN_SUDDEN_DEATH:
switch( score )
{
case HNS_Held: fDeltaLife = +0; break;
case HNS_LetGo: fDeltaLife = -1.0; break;
2003-11-11 07:36:28 +00:00
default:
ASSERT(0);
}
break;
default:
ASSERT(0);
}
ChangeLife( fDeltaLife );
}
void LifeMeterBar::ChangeLife( float fDeltaLife )
{
2004-01-11 23:33:56 +00:00
if( PREFSMAN->m_bMercifulDrain && fDeltaLife < 0 )
fDeltaLife *= SCALE( m_fLifePercentage, 0.f, 1.f, 0.5f, 1.f);
// handle progressiveness and ComboToRegainLife here
2003-11-11 07:36:28 +00:00
if( fDeltaLife >= 0 )
2003-07-29 12:42:38 +00:00
{
m_iMissCombo = 0;
2003-10-13 00:06:49 +00:00
m_iComboToRegainLife = max( m_iComboToRegainLife-1, 0 );
if ( m_iComboToRegainLife > 0 )
fDeltaLife = 0.0f;
2003-11-11 07:36:28 +00:00
}
else
{
2003-07-29 12:42:38 +00:00
fDeltaLife *= 1 + (float)m_iProgressiveLifebar/8 * m_iMissCombo;
// do this after; only successive boo/miss will
// increase the amount of life lost.
m_iMissCombo++;
2003-10-13 00:06:49 +00:00
/* Increase by m_iRegenComboAfterMiss; never push it beyond m_iMaxRegenComboAfterMiss
* but don't reduce it if it's already past. */
2005-04-27 07:50:38 +00:00
const int NewComboToRegainLife = min(
(int)PREFSMAN->m_iMaxRegenComboAfterMiss,
m_iComboToRegainLife + PREFSMAN->m_iRegenComboAfterMiss );
2003-10-13 00:06:49 +00:00
m_iComboToRegainLife = max( m_iComboToRegainLife, NewComboToRegainLife );
2003-07-29 12:42:38 +00:00
}
/* If we've already failed, there's no point in letting them fill up the bar again. */
if( m_pPlayerStageStats->bFailed )
2003-10-13 03:24:28 +00:00
fDeltaLife = 0;
switch( GAMESTATE->m_SongOptions.m_DrainType )
{
case SongOptions::DRAIN_NORMAL:
case SongOptions::DRAIN_NO_RECOVER:
if( fDeltaLife > 0 )
fDeltaLife *= m_fLifeDifficulty;
else
fDeltaLife /= m_fLifeDifficulty;
break;
}
2002-05-29 09:47:24 +00:00
// check if this step would cause a fail
2005-04-27 07:50:38 +00:00
if( m_fLifePercentage + fDeltaLife <= FAIL_THRESHOLD && m_fLifePercentage > FAIL_THRESHOLD )
2003-10-13 00:06:49 +00:00
{
/* Increase by m_iRegenComboAfterFail; never push it beyond m_iMaxRegenComboAfterFail
* but don't reduce it if it's already past. */
2005-04-27 07:50:38 +00:00
const int NewComboToRegainLife = min(
(int)PREFSMAN->m_iMaxRegenComboAfterFail,
m_iComboToRegainLife + PREFSMAN->m_iRegenComboAfterFail );
2003-10-13 00:06:49 +00:00
m_iComboToRegainLife = max( m_iComboToRegainLife, NewComboToRegainLife );
}
2002-05-29 09:47:24 +00:00
m_fLifePercentage += fDeltaLife;
2002-07-23 01:41:40 +00:00
CLAMP( m_fLifePercentage, 0, 1 );
2005-04-21 11:16:01 +00:00
AfterLifeChanged();
2002-04-28 20:42:32 +00:00
2002-08-01 05:11:11 +00:00
if( m_fLifePercentage <= FAIL_THRESHOLD )
m_pPlayerStageStats->bFailedEarlier = true;
2002-04-28 20:42:32 +00:00
}
void LifeMeterBar::AfterLifeChanged()
2002-04-28 20:42:32 +00:00
{
2005-04-21 11:16:01 +00:00
m_pStream->SetPercent( m_fLifePercentage );
2002-05-27 08:23:27 +00:00
}
bool LifeMeterBar::IsPastPassmark() const
{
if( m_pPlayerState->m_PlayerOptions.m_fPassmark > 0 )
{
return m_fLifePercentage >= m_pPlayerState->m_PlayerOptions.m_fPassmark;
}
else
{
return false;
}
}
2003-11-03 18:24:13 +00:00
bool LifeMeterBar::IsHot() const
2002-05-27 08:23:27 +00:00
{
2002-05-28 20:01:22 +00:00
return m_fLifePercentage >= 1;
2002-05-27 08:23:27 +00:00
}
2002-04-28 20:42:32 +00:00
2003-11-03 18:24:13 +00:00
bool LifeMeterBar::IsInDanger() const
2002-05-27 08:23:27 +00:00
{
2004-01-03 21:30:20 +00:00
return m_fLifePercentage < DANGER_THRESHOLD;
2002-05-27 08:23:27 +00:00
}
2002-04-28 20:42:32 +00:00
2003-11-03 18:24:13 +00:00
bool LifeMeterBar::IsFailing() const
2002-05-27 08:23:27 +00:00
{
2002-07-23 01:41:40 +00:00
return m_fLifePercentage <= 0;
}
2002-04-28 20:42:32 +00:00
2002-05-27 08:23:27 +00:00
void LifeMeterBar::Update( float fDeltaTime )
{
2002-07-28 20:28:37 +00:00
LifeMeter::Update( fDeltaTime );
m_fPassingAlpha += IsPastPassmark() ? +fDeltaTime*2 : -fDeltaTime*2;
CLAMP( m_fPassingAlpha, 0, 1 );
m_fHotAlpha += IsHot() ? + fDeltaTime*2 : -fDeltaTime*2;
2002-08-19 20:02:30 +00:00
CLAMP( m_fHotAlpha, 0, 1 );
2005-04-21 11:16:01 +00:00
m_pStream->SetPassingAlpha( m_fPassingAlpha );
m_pStream->SetHotAlpha( m_fHotAlpha );
if( m_fLifePercentage < DANGER_THRESHOLD && !GAMESTATE->IsPlayerDead(m_pPlayerState) )
2005-04-21 11:16:01 +00:00
m_quadDangerGlow.SetDiffuseAlpha( 1 );
else
m_quadDangerGlow.SetDiffuseAlpha( 0 );
2002-08-19 20:02:30 +00:00
}
2002-07-23 01:41:40 +00:00
2002-08-19 20:02:30 +00:00
void LifeMeterBar::DrawPrimitives()
{
2002-07-23 01:41:40 +00:00
ActorFrame::DrawPrimitives();
}
#include "RageLog.h"
2003-07-31 15:07:48 +00:00
void LifeMeterBar::UpdateNonstopLifebar(const int cleared,
const int total, int ProgressiveLifebarDifficulty)
{
// if (cleared > total) cleared = total; // clear/total <= 1
// if (total == 0) total = 1; // no division by 0
if (GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2())
{ // extra stage is its own thing, should not be progressive
// and it should be as difficult as life 4
// (e.g. it should not depend on life settings)
m_iProgressiveLifebar = 0;
m_fLifeDifficulty = 1.0f;
return;
}
// should be checked before calling function, but in case
// it isn't, do so here
/* No, wait: if we're playing nonstop, event mode just means that we can play another
* nonstop course later, so it shouldn't affect life difficulty. */
2005-02-21 17:29:49 +00:00
/* if (GAMESTATE->GetEventMode())
{
m_fLifeDifficulty = m_fBaseLifeDifficulty;
return;
} */
2003-07-31 15:07:48 +00:00
if (total > 1)
m_fLifeDifficulty = m_fBaseLifeDifficulty - 0.2f * (int)(ProgressiveLifebarDifficulty * cleared / (total - 1));
else
m_fLifeDifficulty = m_fBaseLifeDifficulty - 0.2f * ProgressiveLifebarDifficulty;
if (m_fLifeDifficulty >= 0.4) return;
/* Approximate deductions for a miss
* Life 1 : 5 %
* Life 2 : 5.7 %
* Life 3 : 6.6 %
* Life 4 : 8 %
* Life 5 : 10 %
* Life 6 : 13.3 %
* Life 7 : 20 %
* Life 8 : 26.6 %
* Life 9 : 32 %
* Life 10: 40 %
* Life 11: 50 %
* Life 12: 57.1 %
* Life 13: 66.6 %
* Life 14: 80 %
* Life 15: 100 %
* Life 16+: 200 %
*
* Note there is 200%, because boos take off 1/2 as much as
* a miss, and a boo would suck up half of your lifebar.
*
* Everything past 7 is intended mainly for nonstop mode.
*/
// the lifebar is pretty harsh at 0.4 already (you lose
// about 20% of your lifebar); at 0.2 it would be 40%, which
// is too harsh at one difficulty level higher. Override.
2003-09-04 10:37:48 +00:00
2003-09-05 06:59:15 +00:00
int m_iLifeDifficulty = int((1.8f - m_fLifeDifficulty)/0.2f);
2003-09-04 10:37:48 +00:00
// first eight values don't matter
float DifficultyValues[16] = {0,0,0,0,0,0,0,0,
0.3f, 0.25f, 0.2f, 0.16f, 0.14f, 0.12f, 0.10f, 0.08f};
if (m_iLifeDifficulty >= 16)
{
2003-09-04 10:37:48 +00:00
// judge 16 or higher
m_fLifeDifficulty = 0.04f;
return;
}
2003-09-04 10:37:48 +00:00
m_fLifeDifficulty = DifficultyValues[m_iLifeDifficulty];
return;
}
void LifeMeterBar::FillForHowToPlay(int NumTier2s, int NumMisses)
{
m_iProgressiveLifebar = 0; // disable progressive lifebar
float AmountForTier2 = NumTier2s * m_fLifeDifficulty * 0.008f;
float AmountForMiss = NumMisses / m_fLifeDifficulty * 0.08f;
m_fLifePercentage = AmountForMiss - AmountForTier2;
CLAMP( m_fLifePercentage, 0.0f, 1.0f );
AfterLifeChanged();
}
2004-06-08 00:08:04 +00:00
2005-04-21 11:16:01 +00:00
void LifeMeterBar::ForceFail()
{
m_fLifePercentage = 0;
AfterLifeChanged();
}
2004-06-08 00:08:04 +00:00
/*
* (c) 2001-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.
*/