forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreKeeperRave.cpp
235 lines (206 loc) · 8.31 KB
/
ScoreKeeperRave.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "global.h"
#include "ScoreKeeperRave.h"
#include "RageMath.hpp"
#include "ThemeManager.h"
#include "RageUtil.h"
#include "GameState.h"
#include "Character.h"
#include "ScreenManager.h"
#include "PrefsManager.h"
#include "ThemeMetric.h"
#include "PlayerState.h"
#include "NoteTypes.h"
ThemeMetric<float> ATTACK_DURATION_SECONDS ("ScoreKeeperRave","AttackDurationSeconds");
static void SuperMeterPercentChangeInit( size_t /*ScoreEvent*/ i, std::string &sNameOut, float &defaultValueOut )
{
ScoreEvent ci = (ScoreEvent)i;
sNameOut = "SuperMeterPercentChange" + ScoreEventToString( ci );
switch(ci)
{
case SE_CheckpointHit: defaultValueOut = +0.05f; break;
case SE_W1: defaultValueOut = +0.05f; break;
case SE_W2: defaultValueOut = +0.04f; break;
case SE_W3: defaultValueOut = +0.02f; break;
case SE_W4: defaultValueOut = +0.00f; break;
case SE_W5: defaultValueOut = +0.00f; break;
case SE_Miss: defaultValueOut = -0.20f; break;
case SE_HitMine: defaultValueOut = -0.40f; break;
case SE_CheckpointMiss: defaultValueOut = -0.20f; break;
case SE_Held: defaultValueOut = +0.04f; break;
case SE_LetGo: defaultValueOut = -0.20f; break;
case SE_Missed: defaultValueOut = -0.00f; break;
DEFAULT_FAIL(ci);
}
}
static Preference1D<float> g_fSuperMeterPercentChange( SuperMeterPercentChangeInit, NUM_ScoreEvent );
ScoreKeeperRave::ScoreKeeperRave( PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats ) :
ScoreKeeper(pPlayerState, pPlayerStageStats)
{
}
void ScoreKeeperRave::HandleTapScore( const TapNote &tn )
{
TapNoteScore score = tn.result.tns;
float fPercentToMove = 0;
if( score == TNS_HitMine )
fPercentToMove = g_fSuperMeterPercentChange[SE_HitMine];
AddSuperMeterDelta( fPercentToMove );
}
#define CROSSED( val ) (fOld < val && fNew >= val)
#define CROSSED_ATTACK_LEVEL( level ) CROSSED(1.f/NUM_ATTACK_LEVELS*(level+1))
void ScoreKeeperRave::HandleTapRowScore( const NoteData &nd, int iRow )
{
TapNoteScore scoreOfLastTap;
int iNumTapsInRow;
float fPercentToMove = 0.0f;
GetScoreOfLastTapInRow( nd, iRow, scoreOfLastTap, iNumTapsInRow );
if( iNumTapsInRow <= 0 )
return;
switch( scoreOfLastTap )
{
DEFAULT_FAIL( scoreOfLastTap );
case TNS_W1: fPercentToMove = g_fSuperMeterPercentChange[SE_W1]; break;
case TNS_W2: fPercentToMove = g_fSuperMeterPercentChange[SE_W2]; break;
case TNS_W3: fPercentToMove = g_fSuperMeterPercentChange[SE_W3]; break;
case TNS_W4: fPercentToMove = g_fSuperMeterPercentChange[SE_W4]; break;
case TNS_W5: fPercentToMove = g_fSuperMeterPercentChange[SE_W5]; break;
case TNS_Miss: fPercentToMove = g_fSuperMeterPercentChange[SE_Miss]; break;
}
AddSuperMeterDelta( fPercentToMove );
}
void ScoreKeeperRave::HandleHoldScore( const TapNote &tn )
{
// todo: should hit mine be handled in HandleTapRow score instead? -aj
TapNoteScore tapScore = tn.result.tns;
float fPercentToMove = 0.0f;
switch( tapScore )
{
case TNS_HitMine:
fPercentToMove = g_fSuperMeterPercentChange[SE_HitMine];
break;
default: break;
}
// Playing with this code enabled seems to feel "wrong", but I'm leaving it
// in for player feedback. -aj
HoldNoteScore holdScore = tn.HoldResult.hns;
switch( holdScore )
{
case HNS_Held: fPercentToMove = g_fSuperMeterPercentChange[SE_Held]; break;
case HNS_LetGo: fPercentToMove = g_fSuperMeterPercentChange[SE_LetGo]; break;
case HNS_Missed: fPercentToMove = g_fSuperMeterPercentChange[SE_Missed]; break;
default: break;
}
AddSuperMeterDelta( fPercentToMove );
}
extern ThemeMetric<bool> PENALIZE_TAP_SCORE_NONE;
void ScoreKeeperRave::HandleTapScoreNone()
{
if( PENALIZE_TAP_SCORE_NONE )
{
float fPercentToMove = g_fSuperMeterPercentChange[SE_Miss];
AddSuperMeterDelta( fPercentToMove );
}
}
void ScoreKeeperRave::AddSuperMeterDelta( float fUnscaledPercentChange )
{
if( PREFSMAN->m_bMercifulDrain && fUnscaledPercentChange<0 )
{
float fSuperPercentage = m_pPlayerState->m_fSuperMeter / NUM_ATTACK_LEVELS;
fUnscaledPercentChange *= Rage::scale( fSuperPercentage, 0.f, 1.f, 0.5f, 1.f);
}
// more mercy: Grow super meter slower or faster depending on life.
if( PREFSMAN->m_bMercifulSuperMeter )
{
float fLifePercentage = 0;
switch( m_pPlayerState->m_PlayerNumber )
{
case PLAYER_1: fLifePercentage = GAMESTATE->m_fTugLifePercentP1; break;
case PLAYER_2: fLifePercentage = 1 - GAMESTATE->m_fTugLifePercentP1; break;
default:
FAIL_M(fmt::sprintf("Invalid player number: %i", m_pPlayerState->m_PlayerNumber));
}
fLifePercentage = Rage::clamp( fLifePercentage, 0.f, 1.f );
if( fUnscaledPercentChange > 0 )
fUnscaledPercentChange *= Rage::scale( fLifePercentage, 0.f, 1.f, 1.7f, 0.3f);
else // fUnscaledPercentChange <= 0
fUnscaledPercentChange /= Rage::scale( fLifePercentage, 0.f, 1.f, 1.7f, 0.3f);
}
// mercy: drop super meter faster if at a higher level
if( fUnscaledPercentChange < 0 )
fUnscaledPercentChange *= Rage::scale( m_pPlayerState->m_fSuperMeter, 0.f, 1.f, 0.01f, 1.f );
AttackLevel oldAL = (AttackLevel)(int)m_pPlayerState->m_fSuperMeter;
float fPercentToMove = fUnscaledPercentChange;
m_pPlayerState->m_fSuperMeter += fPercentToMove * m_pPlayerState->m_fSuperMeterGrowthScale;
m_pPlayerState->m_fSuperMeter = Rage::clamp( m_pPlayerState->m_fSuperMeter, 0.f, NUM_ATTACK_LEVELS + 0.f );
AttackLevel newAL = (AttackLevel)(int)m_pPlayerState->m_fSuperMeter;
if( newAL > oldAL )
{
LaunchAttack( oldAL );
if( newAL == NUM_ATTACK_LEVELS ) // hit upper bounds of meter
m_pPlayerState->m_fSuperMeter -= 1.f;
}
// mercy: if losing remove attacks on life drain
if( fUnscaledPercentChange < 0 )
{
bool bWinning;
switch( m_pPlayerState->m_PlayerNumber )
{
case PLAYER_1: bWinning = GAMESTATE->m_fTugLifePercentP1 > 0.5f; break;
case PLAYER_2: bWinning = GAMESTATE->m_fTugLifePercentP1 < 0.5f; break;
default:
bWinning = false;
FAIL_M(fmt::sprintf("Invalid player number: %i", m_pPlayerState->m_PlayerNumber));
}
if( !bWinning )
m_pPlayerState->EndActiveAttacks();
}
}
void ScoreKeeperRave::LaunchAttack( AttackLevel al )
{
PlayerNumber pn = m_pPlayerState->m_PlayerNumber;
std::string* asAttacks = GAMESTATE->m_pCurCharacters[pn]->m_sAttacks[al]; // [NUM_ATTACKS_PER_LEVEL]
std::string sAttackToGive;
if (GAMESTATE->m_pCurCharacters[pn] != nullptr)
sAttackToGive = asAttacks[ RandomInt(NUM_ATTACKS_PER_LEVEL) ];
else
{
// "If you add any noteskins here, you need to make sure they're cached, too." -?
// Noteskins probably won't work here anymore. -aj
std::string DefaultAttacks[8] = { "1.5x", "2.0x", "0.5x", "reverse", "sudden", "boost", "brake", "wave" };
sAttackToGive = DefaultAttacks[ RandomInt(8) ];
}
PlayerNumber pnToAttack = OPPOSITE_PLAYER[pn];
PlayerState *pPlayerStateToAttack = GAMESTATE->m_pPlayerState[pnToAttack];
Attack a;
a.level = al;
a.fSecsRemaining = ATTACK_DURATION_SECONDS;
a.sModifiers = sAttackToGive;
// remove current attack (if any)
pPlayerStateToAttack->RemoveActiveAttacks();
// apply new attack
pPlayerStateToAttack->LaunchAttack( a );
// SCREENMAN->SystemMessage( fmt::sprintf( "attacking %d with %s", pnToAttack+1, sAttackToGive.c_str() ) );
}
/*
* (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.
*/