Implement TopGradesGrouped properly. Tested somewhat. Needs to be tried on larger...
[openitg.git] / src / GameConstantsAndTypes.cpp
1 #include "global.h"
2 #include "GameState.h"
3 #include "ThemeMetric.h"
4 #include "GameManager.h"
5 #include <float.h>
6
7 #include "LuaFunctions.h"
8 #define LuaXToString(X) \
9 LuaFunction( X##ToString, X##ToString( (X) IArg(1) ) );
10
11 #define LuaStringToX(X) \
12 LuaFunction( StringTo##X, (X) StringTo##X( SArg(1) ) );
13
14 const CString RANKING_TO_FILL_IN_MARKER[NUM_PLAYERS] = {"#P1#","#P2#"};
15
16 static const CString RadarCategoryNames[] = {
17 "Stream",
18 "Voltage",
19 "Air",
20 "Freeze",
21 "Chaos",
22 "Taps",
23 "Jumps",
24 "Holds",
25 "Mines",
26 "Hands",
27 "Rolls"
28 };
29 XToString( RadarCategory, NUM_RADAR_CATEGORIES );
30 XToThemedString( RadarCategory, NUM_RADAR_CATEGORIES );
31
32 static void LuaRadarCategory(lua_State* L)
33 {
34 FOREACH_RadarCategory( rc )
35 {
36 CString s = RadarCategoryNames[rc];
37 s.MakeUpper();
38 LUA->SetGlobal( "RADAR_CATEGORY_"+s, rc );
39 }
40 }
41 REGISTER_WITH_LUA_FUNCTION( LuaRadarCategory );
42
43 static void LuaStepsType(lua_State* L)
44 {
45 FOREACH_StepsType( st )
46 {
47 CString s = GAMEMAN->StepsTypeToString( st );
48 s.MakeUpper();
49 s.Replace('-','_');
50 LUA->SetGlobal( "STEPS_TYPE_"+s, st );
51 }
52 }
53 REGISTER_WITH_LUA_FUNCTION( LuaStepsType );
54
55
56 static const CString PlayModeNames[] = {
57 "Regular",
58 "Nonstop",
59 "Oni",
60 "Endless",
61 "Battle",
62 "Rave",
63 };
64 XToString( PlayMode, NUM_PLAY_MODES );
65 XToThemedString( PlayMode, NUM_PLAY_MODES );
66 StringToX( PlayMode );
67 LuaXToString( PlayMode );
68 static void LuaPlayMode(lua_State* L)
69 {
70 FOREACH_PlayMode( pm )
71 {
72 CString s = PlayModeNames[pm];
73 s.MakeUpper();
74 LUA->SetGlobal( "PLAY_MODE_"+s, pm );
75 }
76 LUA->SetGlobal( "NUM_PLAY_MODES", NUM_PLAY_MODES );
77 }
78 REGISTER_WITH_LUA_FUNCTION( LuaPlayMode );
79
80
81 RankingCategory AverageMeterToRankingCategory( int iAverageMeter )
82 {
83 if( iAverageMeter <= 3 ) return RANKING_A;
84 else if( iAverageMeter <= 6 ) return RANKING_B;
85 else if( iAverageMeter <= 9 ) return RANKING_C;
86 else return RANKING_D;
87 }
88
89
90 static const CString RankingCategoryNames[] = {
91 "a",
92 "b",
93 "c",
94 "d",
95 };
96 XToString( RankingCategory, NUM_RANKING_CATEGORIES );
97 StringToX( RankingCategory );
98
99
100 static const CString PlayerControllerNames[] = {
101 "Human",
102 "Autoplay",
103 "Cpu",
104 };
105 XToString( PlayerController, NUM_PLAYER_CONTROLLERS );
106
107
108 static const CString CoinModeNames[] = {
109 "home",
110 "pay",
111 "free",
112 };
113 XToString( CoinMode, NUM_COIN_MODES );
114 static void LuaCoinMode(lua_State* L)
115 {
116 FOREACH_CoinMode( i )
117 {
118 CString s = CoinModeNames[i];
119 s.MakeUpper();
120 LUA->SetGlobal( "COIN_MODE_"+s, i );
121 }
122 }
123 REGISTER_WITH_LUA_FUNCTION( LuaCoinMode );
124
125
126 static const CString PremiumNames[] = {
127 "none",
128 "double",
129 "joint",
130 };
131 XToString( Premium, NUM_PREMIUMS );
132 static void LuaPremium(lua_State* L)
133 {
134 FOREACH_Premium( i )
135 {
136 CString s = PremiumNames[i];
137 s.MakeUpper();
138 LUA->SetGlobal( "PREMIUM_"+s, i );
139 }
140 }
141 REGISTER_WITH_LUA_FUNCTION( LuaPremium );
142
143
144 static const CString SortOrderNames[] = {
145 "Preferred",
146 "Group",
147 "Title",
148 "Bpm",
149 "Popularity",
150 "TopGrades",
151 "TopGradesGrouped",
152 "Artist",
153 "Genre",
154 "SongLength",
155 "EasyMeter",
156 "MediumMeter",
157 "HardMeter",
158 "ChallengeMeter",
159 "ModeMenu",
160 "AllCourses",
161 "Nonstop",
162 "Oni",
163 "Endless",
164 "Roulette",
165 };
166 XToString( SortOrder, NUM_SORT_ORDERS );
167 StringToX( SortOrder );
168
169 static void LuaSortOrder(lua_State* L)
170 {
171 FOREACH_SortOrder( so )
172 {
173 CString s = SortOrderToString( so );
174
175 // [uppercase] -> _[uppercase]
176 for( unsigned i=0; i<s.size(); i++ )
177 {
178 if( isupper(s[i]) )
179 {
180 s.insert( s.begin()+i, '_' );
181 i++;
182 }
183 }
184
185 s.MakeUpper();
186 LUA->SetGlobal( "SORT"+s, so );
187 }
188 }
189 REGISTER_WITH_LUA_FUNCTION( LuaSortOrder );
190
191
192 static const CString TapNoteScoreNames[] = {
193 "None",
194 "HitMine",
195 "AvoidMine",
196 "Miss",
197 "Boo",
198 "Good",
199 "Great",
200 "Perfect",
201 "Marvelous",
202 };
203 XToString( TapNoteScore, NUM_TAP_NOTE_SCORES );
204 StringToX( TapNoteScore );
205 XToThemedString( TapNoteScore, NUM_TAP_NOTE_SCORES );
206 static void LuaTapNoteScores( lua_State* L )
207 {
208 FOREACH_TapNoteScore( i )
209 {
210 CString s = TapNoteScoreNames[i];
211 s.MakeUpper();
212 LUA->SetGlobal( "TNS_"+s, i );
213 }
214 }
215 REGISTER_WITH_LUA_FUNCTION( LuaTapNoteScores );
216
217
218 static const CString HoldNoteScoreNames[] = {
219 "None",
220 "NG",
221 "OK",
222 };
223 XToString( HoldNoteScore, NUM_HOLD_NOTE_SCORES );
224 StringToX( HoldNoteScore );
225 XToThemedString( HoldNoteScore, NUM_HOLD_NOTE_SCORES );
226 static void LuaHoldNoteScores( lua_State* L )
227 {
228 FOREACH_HoldNoteScore( i )
229 {
230 CString s = HoldNoteScoreNames[i];
231 s.MakeUpper();
232 LUA->SetGlobal( "HNS_"+s, i );
233 }
234 }
235 REGISTER_WITH_LUA_FUNCTION( LuaHoldNoteScores );
236
237
238 static const CString MemoryCardStateNames[] = {
239 "ready",
240 "checking",
241 "late",
242 "error",
243 "removed",
244 "none",
245 };
246 XToString( MemoryCardState, NUM_MEMORY_CARD_STATES );
247
248
249 static const CString PerDifficultyAwardNames[] = {
250 "FullComboGreats",
251 "SingleDigitGreats",
252 "OneGreat",
253 "FullComboPerfects",
254 "SingleDigitPerfects",
255 "OnePerfect",
256 "FullComboMarvelouses",
257 "Greats80Percent",
258 "Greats90Percent",
259 "Greats100Percent",
260 };
261 XToString( PerDifficultyAward, NUM_PER_DIFFICULTY_AWARDS );
262 XToThemedString( PerDifficultyAward, NUM_PER_DIFFICULTY_AWARDS );
263 StringToX( PerDifficultyAward );
264
265
266 // Numbers are intentially not at the front of these strings so that the
267 // strings can be used as XML entity names.
268 // Numbers are intentially not at the back so that "1000" and "10000" don't
269 // conflict when searching for theme elements.
270 static const CString PeakComboAwardNames[] = {
271 "Peak1000Combo",
272 "Peak2000Combo",
273 "Peak3000Combo",
274 "Peak4000Combo",
275 "Peak5000Combo",
276 "Peak6000Combo",
277 "Peak7000Combo",
278 "Peak8000Combo",
279 "Peak9000Combo",
280 "Peak10000Combo",
281 };
282 XToString( PeakComboAward, NUM_PEAK_COMBO_AWARDS );
283 XToThemedString( PeakComboAward, NUM_PEAK_COMBO_AWARDS );
284 StringToX( PeakComboAward );
285
286
287 LuaXToString( Difficulty );
288 LuaStringToX( Difficulty );
289
290
291 void DisplayBpms::Add( float f )
292 {
293 vfBpms.push_back( f );
294 }
295
296 float DisplayBpms::GetMin() const
297 {
298 float fMin = FLT_MAX;
299 FOREACH_CONST( float, vfBpms, f )
300 {
301 if( *f != -1 )
302 fMin = min( fMin, *f );
303 }
304 if( fMin == FLT_MAX )
305 return 0;
306 else
307 return fMin;
308 }
309
310 float DisplayBpms::GetMax() const
311 {
312 float fMax = 0;
313 FOREACH_CONST( float, vfBpms, f )
314 {
315 if( *f != -1 )
316 fMax = max( fMax, *f );
317 }
318 return fMax;
319 }
320
321 bool DisplayBpms::BpmIsConstant() const
322 {
323 return fabsf( GetMin() - GetMax() ) < 0.001f;
324 }
325
326 bool DisplayBpms::IsSecret() const
327 {
328 FOREACH_CONST( float, vfBpms, f )
329 {
330 if( *f == -1 )
331 return true;
332 }
333 return false;
334 }
335
336 static const CString StyleTypeNames[] = {
337 "OnePlayerOneSide",
338 "TwoPlayersTwoSides",
339 "OnePlayerTwoSides",
340 };
341 XToString( StyleType, NUM_STYLE_TYPES );
342 StringToX( StyleType );
343
344
345 static const CString MenuDirNames[] = {
346 "Up",
347 "Down",
348 "Left",
349 "Right",
350 "Auto",
351 };
352 XToString( MenuDir, NUM_MENU_DIRS );
353
354
355 static const CString GoalTypeNames[] = {
356 "Calories",
357 "Time",
358 "None",
359 };
360 XToString( GoalType, NUM_GOAL_TYPES );
361 StringToX( GoalType );
362 static void LuaGoalType(lua_State* L)
363 {
364 FOREACH_GoalType( gt )
365 {
366 CString s = GoalTypeNames[gt];
367 s.MakeUpper();
368 LUA->SetGlobal( "GOAL_"+s, gt );
369 }
370 }
371 REGISTER_WITH_LUA_FUNCTION( LuaGoalType );
372
373
374 static const CString StageNames[] = {
375 "1",
376 "2",
377 "3",
378 "4",
379 "5",
380 "6",
381 "Final",
382 "Extra1",
383 "Extra2",
384 "Nonstop",
385 "Oni",
386 "Endless",
387 "Event",
388 "Demo",
389 };
390 XToString( Stage, NUM_STAGES );
391
392 /*
393 * (c) 2001-2004 Chris Danford
394 * All rights reserved.
395 *
396 * Permission is hereby granted, free of charge, to any person obtaining a
397 * copy of this software and associated documentation files (the
398 * "Software"), to deal in the Software without restriction, including
399 * without limitation the rights to use, copy, modify, merge, publish,
400 * distribute, and/or sell copies of the Software, and to permit persons to
401 * whom the Software is furnished to do so, provided that the above
402 * copyright notice(s) and this permission notice appear in all copies of
403 * the Software and that both the above copyright notice(s) and this
404 * permission notice appear in supporting documentation.
405 *
406 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
407 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
408 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
409 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
410 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
411 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
412 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
413 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
414 * PERFORMANCE OF THIS SOFTWARE.
415 */