forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnlockManager.h
209 lines (173 loc) · 7.36 KB
/
UnlockManager.h
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
/* UnlockManager - Unlocks handling. */
#ifndef UNLOCK_MANAGER_H
#define UNLOCK_MANAGER_H
#include "Grade.h"
#include "Command.h"
#include <set>
#include "Difficulty.h"
#include "SongUtil.h"
#include "CourseUtil.h"
class Song;
class Course;
class Steps;
class Profile;
struct lua_State;
/** @brief What is needed to unlock an item? */
enum UnlockRequirement
{
UnlockRequirement_ArcadePoints, /**< Get a certain number of arcade points. */
UnlockRequirement_DancePoints, /**< Get a certain number of dance points. */
UnlockRequirement_SongPoints, /**< Get a certain number of song points. */
UnlockRequirement_ExtraCleared, /**< Pass the extra stage. */
UnlockRequirement_ExtraFailed, /**< Fail the extra stage. */
UnlockRequirement_Toasties, /**< Get a number of toasties. */
UnlockRequirement_StagesCleared, /**< Clear a number of stages. */
UnlockRequirement_NumUnlocked, /**< Have a number of locked items already unlocked. */
NUM_UnlockRequirement,
UnlockRequirement_Invalid,
};
LuaDeclareType( UnlockRequirement );
enum UnlockRewardType {
UnlockRewardType_Song, /**< A song is unlocked. */
UnlockRewardType_Steps, /**< A step pattern for all styles is unlocked. */
UnlockRewardType_Steps_Type, /**< A step pattern for a specific style is unlocked. */
UnlockRewardType_Course, /**< A course is unlocked. */
UnlockRewardType_Modifier, /**< A modifier is unlocked. */
NUM_UnlockRewardType,
UnlockRewardType_Invalid
};
std::string const UnlockRewardTypeToString( UnlockRewardType i );
std::string const UnlockRewardTypeToLocalizedString( UnlockRewardType i );
LuaDeclareType( UnlockRewardType );
enum UnlockEntryStatus {
UnlockEntryStatus_RequrementsNotMet,
UnlockEntryStatus_RequirementsMet,
UnlockEntryStatus_Unlocked,
};
class UnlockEntry
{
public:
/**
* @brief Set up the UnlockEntry with default values.
*
* m_sEntryID starts as an empty string. It will be filled automatically
* if not specified. */
UnlockEntry(): m_Type(UnlockRewardType_Invalid), m_cmd(),
m_Song(), m_dc(Difficulty_Invalid), m_Course(),
m_StepsType(StepsType_Invalid), m_bRequirePassHardSteps(false),
m_bRequirePassChallengeSteps(false), m_bRoulette(false),
m_sEntryID(std::string(""))
{
ZERO( m_fRequirement );
}
UnlockRewardType m_Type;
Command m_cmd;
/* A cached pointer to the song or course this entry refers to. Only one of
* these will be non-nullptr. */
SongID m_Song;
Difficulty m_dc;
CourseID m_Course;
StepsType m_StepsType;
float m_fRequirement[NUM_UnlockRequirement]; // unlocked if any of of these are met
/** @brief Must the hard steps be passed to unlock a higher level? */
bool m_bRequirePassHardSteps;
/** @brief Must the challenge steps be passed to unlock a higher level? */
bool m_bRequirePassChallengeSteps;
bool m_bRoulette;
std::string m_sEntryID;
bool IsValid() const;
bool IsLocked() const { return GetUnlockEntryStatus() != UnlockEntryStatus_Unlocked; }
UnlockEntryStatus GetUnlockEntryStatus() const;
std::string GetModifier() const { return m_cmd.GetArg(1).s; }
std::string GetDescription() const;
std::string GetBannerFile() const;
std::string GetBackgroundFile() const;
// Lua
void PushSelf( lua_State *L );
};
// Option is locked due to an unsatisfied unlock entry.
#define LOCKED_LOCK 0x1
// Option is only available in random selections.
#define LOCKED_ROULETTE 0x2
// Option is locked due to a #SELECTABLE tag.
#define LOCKED_SELECTABLE 0x4
// Option is disabled by the operator. (For courses, this means that a song in the
// course is disabled.)
#define LOCKED_DISABLED 0x8
class UnlockManager
{
friend class UnlockEntry;
public:
UnlockManager();
~UnlockManager();
void Reload();
float PointsUntilNextUnlock( UnlockRequirement t ) const;
int SongIsLocked( const Song *pSong ) const;
bool StepsIsLocked( const Song *pSong, const Steps *pSteps ) const;
bool StepsTypeIsLocked( const Song *pSong, const Steps *pSteps, const StepsType *pSType ) const;
int CourseIsLocked( const Course *course ) const;
bool ModifierIsLocked( const std::string &sOneMod ) const;
// Gets number of unlocks for title screen
int GetNumUnlocks() const;
int GetNumUnlocked() const;
int GetUnlockEntryIndexToCelebrate() const;
bool AnyUnlocksToCelebrate() const;
void GetPoints( const Profile *pProfile, float fScores[NUM_UnlockRequirement] ) const;
// Unlock an entry by code.
void UnlockEntryID( std::string sEntryID );
void UnlockEntryIndex( int iEntryIndex );
// Lock an entry by code.
void LockEntryID( std::string entryID );
void LockEntryIndex( int entryIndex );
/*
* If a code is associated with at least one song or course, set the preferred song
* and/or course in GAMESTATE to them.
*/
void PreferUnlockEntryID( std::string sEntryID );
// Unlocks a song.
void UnlockSong( const Song *pSong );
// Return the associated EntryID.
std::string FindEntryID( const std::string &sName ) const;
// All locked songs are stored here
std::vector<UnlockEntry> m_UnlockEntries;
void GetUnlocksByType( UnlockRewardType t, std::vector<UnlockEntry *> &apEntries );
void GetSongsUnlockedByEntryID( std::vector<Song *> &apSongsOut, std::string sEntryID );
void GetStepsUnlockedByEntryID( std::vector<Song *> &apSongsOut, std::vector<Difficulty> &apStepsOut, std::string sEntryID );
const UnlockEntry *FindSong( const Song *pSong ) const;
const UnlockEntry *FindSteps( const Song *pSong, const Steps *pSteps ) const;
const UnlockEntry *FindStepsType( const Song *pSong, const Steps *pSteps, const StepsType *pSType ) const;
const UnlockEntry *FindCourse( const Course *pCourse ) const;
const UnlockEntry *FindModifier( const std::string &sOneMod ) const;
// Lua
void PushSelf( lua_State *L );
private:
// read unlocks
void Load();
std::set<std::string> m_RouletteCodes; // "codes" which are available in roulette and which unlock if rouletted
};
extern UnlockManager* UNLOCKMAN; // global and accessible from anywhere in program
#endif
/*
* (c) 2001-2004 Kevin Slaughter, Andrew Wong, 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.
*/