wavelength 1.0.0
Loading...
Searching...
No Matches
gamedb.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
7#include "game/campaign.h"
8#include "game/gameoptions.h"
9#include "game/inputmap.h"
10#include "game/playerinfo.h"
11#include "game/remixinfo.h"
12#include "game/songentry.h"
14#include "os/scheduler.h"
15#include "os/string.h"
16#include "script/dataarray.h"
17
27class GameDb {
28public:
35
43
52
54 static constexpr int kPowerupLevelNone = 2;
55
63
71 static GameDb *shared();
72
79 void Init();
80
87 void Terminate();
88
97 void InitSfx();
98
106
113 void Poll();
114
123 DataArray *FindSong(const char *pszSong);
124
132 int GetNumPlayers() const;
133
141 void SetGameParams(const NetGameParams *pParams);
142
150 void SetRemixBuffer(int nSize);
151
160 return mRemixBuffer;
161 }
162
170 void SetRemix(const RemixInfo *pInfo);
171
181 void SetRemixActive(int nActive);
182
192 int GetRemixActive() const;
193
201 void SetRemixName(const char *pszName);
202
215 void GetHostSongs(std::vector<SongEntry> *pSongs, int nSkillLevel, bool bDuelOnly);
216
224 int GetNumPads() const;
225
234 int IsLocalPlayer(int nPlayer) const;
235
244 int GetPlayerSlot(int nPlayer) const;
245
254 const char *GetPlayerName(int nPlayer) const;
255
266 const char *GetPlayerColor(int nPlayer) const;
267
276 int GetPlayerNetOrder(int nPlayer) const;
277
288 int GetPlayerPad(int nPlayer) const;
289
298 Campaign *GetProfile(int nPlayer);
299
309
318 int GetPlayerScore(int nPlayer) const;
319
328 int GetPlayerRank(int nPlayer) const;
329
338 InputMap *GetInputMap(int nPlayer);
339
348 void SetPlayerScore(int nPlayer, int nScore);
349
357 const char *GetDemo() const;
358
366 void SetWon(bool bWon);
367
375 const char *FindSongGroup();
376
385
394
402 void SetOptions(const GameOptions *pOptions);
403
414 void SetAvatarCameraParams(float fNear, float fFar);
415
425
433 int IsWinSequence() const;
434
442 void SetWinSequence(bool bWinSequence);
443
451 void SetPracticeMode(bool bPracticeMode);
452
460
468 void AddPlayer(const Campaign *pProfile);
469
480 void AddPlayer(int bLocal, const Campaign *pProfile, int nSlot, int nNetOrder);
481
489 void SetSkillLevel(int nSkillLevel);
490
498 void SetPowerupLevel(int nPowerupLevel);
499
510 void SetTutorial(int nTutorial);
511
519 void SetSong(const char *pszSong);
520
528 void SetLoadRemix(bool bLoadRemix);
529
537 void SetRuleSet(int nRuleSet);
538
546 void SetCommunity(int nCommunity);
547
555 void SetMaxPlayers(int nMaxPlayers);
556
564 void SetDemo(const char *pszDemo);
565
573 void SetEnergized(float fEnergized);
574
582 void SetFullMixBars(int nBars);
583
591 void SetBestStreak(int nStreak);
592
600 void SetProgress(float fProgress);
601
609 float GetEnergized() const;
610
618 int GetFullMixBars() const;
619
627 int GetBestStreak() const;
628
636 float GetProgress() const;
637
645 void SetArena(const char *pszArena);
646
655
663 void SetRemixReadOnly(int nReadOnly);
664
672 int GetNetRemixEnded() const;
673
681 void SetNetRemixEnded(int nEnded);
682
690 const char *GetDifficultyName() const;
691
701 const char *GetDifficultyName(int nSkillLevel, int nRuleSet) const;
702
710 const char *GetModeName() const;
711
720 const char *GetModeName(int nRuleSet) const;
721
732 const char *GetPowerupName(int nPowerupLevel) const;
733
742 void GetArenaNames(std::vector<const char *> *pArenas, bool bIncludeTutorial);
743
754 void GetUnlockedArenas(std::vector<const char *> *pArenas,
755 int nSkillLevel,
756 bool bFirstPlayerOnly,
757 bool bIncludeTutorial);
758
769 void GetArenaSongs(std::vector<SongEntry> *pSongs,
770 const char *pszArena,
771 int nSkillLevel,
772 int nFilter);
773
784 void GetUnlockedSongs(std::vector<SongEntry> *pSongs,
785 const char *pszArena,
786 int nSkillLevel,
787 bool bFirstPlayerOnly);
788
798 void GetAllSongs(std::vector<SongEntry> *pSongs, bool bDuelOnly, int nSkillLevel);
799
808 bool HasSong(const char *pszSong);
809
819 bool FindSongById(DataArray **ppSong, int nId);
820
822 const std::vector<std::unique_ptr<PlayerInfo>> &GetPlayers() const {
823 return mPlayers;
824 }
825
827 const String &GetSong() const {
828 return mSong;
829 }
830
832 int GetLoadRemix() const {
833 return mLoadRemix;
834 }
835
837 int GetRemixReadOnly() const {
838 return mRemixReadOnly;
839 }
840
842 const String &GetRemixName() const {
843 return mRemixName;
844 }
845
851 void SetRemixName(const String &name) {
852 mRemixName = name;
853 }
854
856 int GetPracticeMode() const {
857 return mPracticeMode;
858 }
859
861 int GetTutorial() const {
862 return mTutorial;
863 }
864
866 int GetSkillLevel() const {
867 return mSkillLevel;
868 }
869
871 int GetPowerupLevel() const {
872 return mPowerupLevel;
873 }
874
876 int GetRuleSet() const {
877 return mRuleSet;
878 }
879
881 int GetCommunity() const {
882 return mCommunity;
883 }
884
886 int GetMaxPlayers() const {
887 return mMaxPlayers;
888 }
889
891 const String &GetArena() const {
892 return mArena;
893 }
894
900 void SetArena(const String &arena) {
901 mArena = arena;
902 }
903
905 int GetUnlockAll() const {
906 return mUnlockAll;
907 }
908
910 int GetWon() const {
911 return mWon;
912 }
913
915 int GetReservedA4() const {
916 return mReservedA4;
917 }
918
924 void SetReservedA4(int nValue) {
925 mReservedA4 = nValue;
926 }
927
930 return mSongs;
931 }
932
938 void SetSongs(DataArray *pSongs) {
939 mSongs = pSongs;
940 }
941
943 float GetSongTick() const {
944 return mSongTick;
945 }
946
952 void SetSongTick(float fTick) {
953 mSongTick = fTick;
954 }
955
957 float GetSongTime() const {
958 return mSongTime;
959 }
960
966 void SetSongTime(float fTime) {
967 mSongTime = fTime;
968 }
969
972 return mSfxScheduler;
973 }
974
976 const Scheduler &GetSfxScheduler() const {
977 return mSfxScheduler;
978 }
979
980private:
981 std::vector<std::unique_ptr<PlayerInfo>> mPlayers;
982 String mSong;
983 int mLoadRemix;
984 int mRemixReadOnly;
985 String mRemixName;
986 int mPracticeMode;
987 int mTutorial;
988 int mSkillLevel;
989 int mPowerupLevel;
990 int mRuleSet;
991 int mCommunity;
992 int mMaxPlayers;
993 String mArena;
994 int mNumPads;
995 String mDemo;
996 int mWinSequence;
997 int mUnlockAll;
998 int mWon;
999 float mEnergized;
1000 int mFullMixBars;
1001 int mBestStreak;
1002 float mProgress;
1003 int mReservedA4; // +0xa4, cleared with the results and not yet identified.
1004 DataArray *mSongs;
1005 char *mRemixBuffer;
1006 RemixInfo mRemixInfo;
1007 int mRemixActive;
1008 int mNetRemixEnded;
1009 float mSongTick;
1010 float mSongTime;
1011 Scheduler mSfxScheduler;
1012 GameOptions mOptions;
1013
1024 static int FindInt(const char *pszName, DataArray *pData, bool bFail);
1025
1036 static const char *FindSymbol(const char *pszName, DataArray *pData, bool bFail);
1037
1046 static const char *GetSlotColor(int nSlot);
1047
1058 static void GetSkillRange(int nSkillLevel, bool bExact, int *pnFirst, int *pnEnd);
1059
1066 void RankPlayers();
1067};
1068
1074extern GameDb *TheGameDb;
Parts and colours of a player's avatar, the Freq the Freq maker edits.
Definition avatarpartset.h:23
Saved settings and progress of one player, among them the controller bindings.
Definition campaign.h:20
Reference-counted array of script data nodes.
Definition dataarray.h:20
Settings of the game being set up or played, among them the rule set and the timing the world publish...
Definition gamedb.h:27
int GetNumPlayers() const
Report the number of players.
int GetFullMixBars() const
Report the value of SetFullMixBars().
const char * GetModeName() const
Report the localised name of the mode of the game, from mRuleSet.
void InitSfx()
Build TheFxMidi from the fx_midi_file entry of the "db" section, and start mSfxScheduler at the tempo...
void SetWon(bool bWon)
Record whether the song was won.
void SetProgress(float fProgress)
Record the fraction of the song played.
GameOptions * GetOptions()
Report the settings of the game options screen.
int GetSongIndex()
Report the index of the arena of the game, from the digit that ends mArena, less one.
void SetRemixReadOnly(int nReadOnly)
Set mRemixReadOnly.
int GetMaxPlayers() const
Definition gamedb.h:886
void SetFullMixBars(int nBars)
Record the bars a solo song played with every track captured.
bool HasSong(const char *pszSong)
Report whether an arena lists a song.
void Init()
Read the "db" section of the configuration.
void UnlockAllSongs()
Unlock every song.
const std::vector< std::unique_ptr< PlayerInfo > > & GetPlayers() const
Definition gamedb.h:822
void Terminate()
Release what Init() created.
int IsWinSequence() const
Report whether the campaign win sequence runs.
int GetRemixReadOnly() const
Definition gamedb.h:837
const char * GetPlayerColor(int nPlayer) const
Report the colour symbol of a player's difficulty.
int GetReservedA4() const
Definition gamedb.h:915
const char * GetDifficultyName() const
Report the localised name of the difficulty of the game.
int GetNumPads() const
Report the number of controllers the players on this console use.
int GetPracticeMode() const
Definition gamedb.h:856
void AddPlayer(const Campaign *pProfile)
Add a player with a copy of a profile.
const char * GetPowerupName(int nPowerupLevel) const
Report the localised name of a power-up level.
void SetEnergized(float fEnergized)
Record the fraction of the possible capture bars a solo song captured.
void GetHostSongs(std::vector< SongEntry > *pSongs, int nSkillLevel, bool bDuelOnly)
List the songs of every arena but the tutorial that are available at a skill level,...
void SetWinSequence(bool bWinSequence)
Start or end the campaign win sequence.
const char * GetPlayerName(int nPlayer) const
Report the name of a player.
Community
Values of mCommunity.
Definition gamedb.h:37
@ kCommunityLocal
Definition gamedb.h:40
@ kCommunitySolo
Definition gamedb.h:39
@ kCommunityNone
Definition gamedb.h:38
@ kCommunityOnline
Definition gamedb.h:41
DataArray * FindSong(const char *pszSong)
Find the entry of a song in the "songs" section.
void SetSongTick(float fTick)
Set the running world's position in ticks.
Definition gamedb.h:952
void SetAvatarCameraParams(float fNear, float fFar)
Set the depth range of the camera the avatars share, with Avatar::SetDepthRange().
void SetPlayerScore(int nPlayer, int nScore)
Record the score of a player and rank the players by their scores.
void TerminateSfx()
Stop mSfxScheduler and release TheFxMidi.
RemixInfo * GetRemixInfo()
Report the description of the remix being played.
void SetPracticeMode(bool bPracticeMode)
Set the practice mode.
void SetArena(const String &arena)
Set the arena of the game from a string.
Definition gamedb.h:900
Scheduler & GetSfxScheduler()
Definition gamedb.h:971
float GetEnergized() const
Report the value of SetEnergized().
void SetNetRemixEnded(int nEnded)
Record whether the remix of an online game has ended.
RuleSet
Values of mRuleSet, one for each World subclass WorldMgr::Load() can build.
Definition gamedb.h:30
@ kRuleSetRemix
Definition gamedb.h:32
@ kRuleSetDuel
Definition gamedb.h:33
@ kRuleSetGame
Definition gamedb.h:31
const char * GetDifficultyName(int nSkillLevel, int nRuleSet) const
Report the localised name of a difficulty.
void SetSong(const char *pszSong)
Set mSong.
void SetRemixActive(int nActive)
Set the flag that the screens which choose an existing or a tutorial remix set.
Campaign * GetProfile(int nPlayer)
Report the profile of a player.
float GetProgress() const
Report the value of SetProgress().
const char * GetDemo() const
Report the file of the demo being played.
const char * GetModeName(int nRuleSet) const
Report the localised name of a mode.
char * GetRemixBuffer()
Report the buffer of the remix data.
Definition gamedb.h:159
void SetDemo(const char *pszDemo)
Choose the demo to play, or none.
int GetPlayerPad(int nPlayer) const
Report the controller of a player.
InputMap * GetInputMap(int nPlayer)
Report the controller bindings in the profile of a player.
int GetLoadRemix() const
Definition gamedb.h:832
void SetSongTime(float fTime)
Set the running world's position on its song clock.
Definition gamedb.h:966
void SetSkillLevel(int nSkillLevel)
Set mSkillLevel.
void SetMaxPlayers(int nMaxPlayers)
Set mMaxPlayers.
int GetNetRemixEnded() const
Report whether the remix of an online game has ended.
void SetRemix(const RemixInfo *pInfo)
Copy the description of the remix the game plays.
void GetArenaSongs(std::vector< SongEntry > *pSongs, const char *pszArena, int nSkillLevel, int nFilter)
Append the songs of an arena that are available at a skill level.
const Scheduler & GetSfxScheduler() const
Definition gamedb.h:976
void Poll()
Service the database once per frame.
int GetUnlockAll() const
Definition gamedb.h:905
void GetUnlockedSongs(std::vector< SongEntry > *pSongs, const char *pszArena, int nSkillLevel, bool bFirstPlayerOnly)
List the songs the players have unlocked in an arena, or in every unlocked arena.
AvatarPartSet * GetAvatar(int nPlayer)
Report the avatar parts of a player, which its profile stores.
int IsLocalPlayer(int nPlayer) const
Report whether a player plays on this console.
void GetArenaNames(std::vector< const char * > *pArenas, bool bIncludeTutorial)
Append the names of the arenas of the "arenas" section, in their order there.
void SetRemixBuffer(int nSize)
Replace the buffer of the remix data with a new one, billed to RemixBuf.
static GameDb * shared()
Report the single instance, constructing it on first use.
void SetRuleSet(int nRuleSet)
Set mRuleSet.
void SetArena(const char *pszArena)
Set the arena of the game.
const String & GetRemixName() const
Definition gamedb.h:842
void SetReservedA4(int nValue)
Set the value at +0xa4, not yet identified.
Definition gamedb.h:924
const char * FindSongGroup()
Report the arena whose songs include mSong, the tutorial included.
float GetSongTick() const
Definition gamedb.h:943
int GetPlayerNetOrder(int nPlayer) const
Report the position of a player in the order of the online session.
const String & GetArena() const
Definition gamedb.h:891
int GetRemixActive() const
Report the flag SetRemixActive() set.
void AddPlayer(int bLocal, const Campaign *pProfile, int nSlot, int nNetOrder)
Add a player of an online game with a copy of a profile.
int GetSkillLevel() const
Definition gamedb.h:866
void SetSongs(DataArray *pSongs)
Set the songs array of the "db" section.
Definition gamedb.h:938
static constexpr int kPowerupLevelNone
The value of mPowerupLevel that places no power-up.
Definition gamedb.h:54
void GetUnlockedArenas(std::vector< const char * > *pArenas, int nSkillLevel, bool bFirstPlayerOnly, bool bIncludeTutorial)
List the arenas the players have unlocked at a skill level.
int GetTutorial() const
Definition gamedb.h:861
void SetTutorial(int nTutorial)
Set whether the tutorial is played.
bool FindSongById(DataArray **ppSong, int nId)
Find the song whose id matches.
void SetPowerupLevel(int nPowerupLevel)
Set mPowerupLevel.
int GetPowerupLevel() const
Definition gamedb.h:871
float GetSongTime() const
Definition gamedb.h:957
int GetWon() const
Definition gamedb.h:910
void SetCommunity(int nCommunity)
Set mCommunity.
void SetRemixName(const char *pszName)
Set mRemixName.
void SetBestStreak(int nStreak)
Record the longest streak of a solo song.
const String & GetSong() const
Definition gamedb.h:827
int GetPlayerScore(int nPlayer) const
Report the score SetPlayerScore() recorded for a player.
void GetAllSongs(std::vector< SongEntry > *pSongs, bool bDuelOnly, int nSkillLevel)
List the songs of every arena but the tutorial that are available at a skill level.
void SetGameParams(const NetGameParams *pParams)
Take the settings of an online game the host published.
DataArray * GetSongs() const
Definition gamedb.h:929
int GetRuleSet() const
Definition gamedb.h:876
int GetPlayerRank(int nPlayer) const
Report the rank SetPlayerScore() gave a player, 0 for the best score.
SkillLevel
Values of mSkillLevel.
Definition gamedb.h:45
@ kSkillInsane
Definition gamedb.h:49
@ kSkillIntermediate
Definition gamedb.h:47
@ kSkillNovice
Definition gamedb.h:46
@ kSkillAny
Definition gamedb.h:50
@ kSkillAdvanced
Definition gamedb.h:48
void ClearPlayers()
Remove every player.
GameDb()
Construct the database with its defaults.
int GetCommunity() const
Definition gamedb.h:881
void SetLoadRemix(bool bLoadRemix)
Set mLoadRemix.
void SetRemixName(const String &name)
Set the name of the saved remix played.
Definition gamedb.h:851
void SetOptions(const GameOptions *pOptions)
Replace the settings of the game options screen and apply the speaker output mode.
int GetPlayerSlot(int nPlayer) const
Report the slot of a player, which selects the player's sounds and colours.
int GetBestStreak() const
Report the value of SetBestStreak().
The settings of the game options screen, which are saved apart from the players to the settings file ...
Definition gameoptions.h:13
The actions a player's controller buttons and analogue sticks are bound to.
Definition inputmap.h:15
The settings of an online game that the host publishes with its session.
Definition netgameparams.h:13
Description of a saved remix.
Definition remixinfo.h:26
Queue of commands that run when the song clock reaches their tick.
Definition scheduler.h:20
Growable text buffer that is also a PrnStream.
Definition string.h:19
GameDb * TheGameDb
The game database, GameDb::shared() as the unit's static initialiser stored it.