wavelength 1.0.0
Loading...
Searching...
No Matches
campaign.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
6#include "game/inputmap.h"
7#include "game/songstats.h"
9#include "os/binstream.h"
10#include "os/datetime.h"
11#include "os/string.h"
12#include "script/dataarray.h"
13
20class Campaign {
21public:
31
43
55 bool CompletesTier(const char *pszSong, int nSkillLevel);
56
65
73 void SetInputMap(const InputMap *pMap);
74
83
91
102 const char *FindFirstUnfinishedSong(int nSkillLevel);
103
115 void GetClearedSongs(int nSkillLevel, const char *pszGroup, std::vector<bool> *pCleared);
116
128 bool IsUnlocked(const char *pszItem, int nSkillLevel);
129
140 void GetUnlockedParts(int nPart, std::vector<const char *> *pTypes);
141
151 void GetUnlockedEmblems(std::vector<const char *> *pTypes);
152
162 void RemoveLockedItems(std::vector<const char *> *pItems);
163
171 int GetSoloOption() const;
172
180 int GetOnlineOption() const;
181
189 void SetSoloOption(int nOption);
190
198 void SetOnlineOption(int nOption);
199
206 static void UnlockAllParts();
207
216 static void UnlockAllSongs();
217
225
233 Campaign(const Campaign &other);
234
242
252
266 bool IsSongFinished(const char *pszSong, int nSkillLevel);
267
278 bool HasBeatenGame(int nSkillLevel);
279
289
301 void GetSongStats(const char *pszSong, int nSkillLevel, SongStats *pRecord);
302
313 void RecordResult(const SongStats *pRecord, std::vector<UnlockableItem> *pUnlocks);
314
324 int GetArenaScore(const char *pszArena, int nSkillLevel);
325
337 int GetArenaScoreToBeat(const char *pszArena, int nSkillLevel);
338
348 int GetMedal(const char *pszSong, int nSkillLevel);
349
361 int GetMedalForScore(const char *pszSong, int nSkillLevel, int nScore, int nPercent);
362
373 const char *TakePendingPowerup(int nSkillLevel);
374
382 int IsModified() const;
383
391 void SetModified(int nModified);
392
400 void Save(BinStream &stream) const;
401
412 void Load(BinStream &stream);
413
415 const String &GetPassword() const {
416 return mPassword;
417 }
418
420 void SetPassword(const char *pszPassword) {
421 mPassword = pszPassword;
422 }
423
425 int GetNameLocked() const {
426 return mNameLocked;
427 }
428
430 void SetNameLocked(int nNameLocked) {
431 mNameLocked = nNameLocked;
432 }
433
435 const String &GetName() const {
436 return mName;
437 }
438
440 void SetName(const char *pszName) {
441 mName = pszName;
442 }
443
445 int GetCustom() const {
446 return mCustom;
447 }
448
450 void SetCustom(int nCustom) {
451 mCustom = nCustom;
452 }
453
455 const DateTime &GetBorn() const {
456 return mBorn;
457 }
458
461 return mBorn;
462 }
463
465 const AvatarPartSet &GetAvatar() const {
466 return mAvatar;
467 }
468
471 return mAvatar;
472 }
473
475 void SetAvatar(const AvatarPartSet &avatar) {
476 mAvatar = avatar;
477 }
478
479private:
480 // Add a result to the records, keeping the best of each statistic.
481 // NTSC-U/C: 0x00277590, PAL: 0x00281020
482 void AddRecord(const SongStats *pRecord);
483
484 // Collect the unlocks of every `campaign` entry the records now pass at a skill level.
485 // NTSC-U/C: 0x002777f8, PAL: 0x00281288
486 void UpdateUnlocks(std::vector<UnlockableItem> *pUnlocks, int nSkillLevel);
487
488 // Apply one `campaign` entry once its condition passes.
489 // NTSC-U/C: 0x00277980, PAL: 0x00281410
490 void ProcessEntry(DataArray *pEntry,
491 int nSkillLevel,
492 int nEntry,
493 std::vector<UnlockableItem> *pUnlocks);
494
495 // Evaluate a `beat_num`, `beat_songs`, `beat_score`, or `always` condition.
496 // NTSC-U/C: 0x00277ae8, PAL: 0x00281578
497 bool CheckCondition(DataArray *pCondition, int nSkillLevel);
498
499 // Report whether a number of songs other than the tutorial were finished.
500 // NTSC-U/C: 0x00277ca8, PAL: 0x00281738
501 bool CheckBeatNum(int nCount, int nSkillLevel);
502
503 // List the songs a `filter`, `all_except`, or `songs` clause selects.
504 // NTSC-U/C: 0x00277d78, PAL: 0x00281808
505 void ParseFilter(DataArray *pFilter, int nSkillLevel, std::vector<const char *> *pSongs);
506
507 // List the available songs of an arena, or of `all`, of one type, or of every type for 5.
508 // NTSC-U/C: 0x00277f40, PAL: 0x002819d0
509 void BuildFiltered(int nType,
510 const char *pszArena,
511 int nSkillLevel,
512 std::vector<const char *> *pSongs);
513
514 // List the available songs of an arena, or of `all`, not of one type.
515 // NTSC-U/C: 0x00278218, PAL: 0x00281ca8
516 void
517 ExceptType(int nType, const char *pszArena, int nSkillLevel, std::vector<const char *> *pSongs);
518
519 // List the available songs of an arena, or of `all`, of neither of two types.
520 // NTSC-U/C: 0x002784f8, PAL: 0x00281f88
521 void ExceptTwoTypes(int nType,
522 int nOtherType,
523 const char *pszArena,
524 int nSkillLevel,
525 std::vector<const char *> *pSongs);
526
527 // List the available songs a `songs` clause specifies.
528 // NTSC-U/C: 0x002787f0, PAL: 0x00282280
529 void FromList(DataArray *pList, int nSkillLevel, std::vector<const char *> *pSongs);
530
531 // Report whether every song was finished.
532 // NTSC-U/C: 0x00278a58, PAL: 0x002824e8
533 bool CheckAllBeaten(const std::vector<const char *> *pSongs, int nSkillLevel);
534
535 // Report whether the best scores of the songs add up to a total.
536 // NTSC-U/C: 0x00278b10, PAL: 0x002825a0
537 bool CheckScoreTotal(const std::vector<const char *> *pSongs, int nSkillLevel, int nTotal);
538
539 // Unlock an item once at a skill level, or at every level for GameDb::kSkillAny.
540 // NTSC-U/C: 0x00278bb8, PAL: 0x00282648
541 void RecordUnlock(int nKind,
542 const char *pszItem,
543 int nSkillLevel,
544 std::vector<UnlockableItem> *pUnlocks);
545
546 // Apply an `unlock` or `skill_unlock` clause.
547 // NTSC-U/C: 0x00278f50, PAL: 0x002829e0
548 void ApplyUnlockNode(DataArray *pNode, int nSkillLevel, std::vector<UnlockableItem> *pUnlocks);
549
550 // Apply a `prefab_unlock` clause.
551 // NTSC-U/C: 0x00279090, PAL: 0x00282b20
552 void PrefabUnlock(DataArray *pNode, std::vector<UnlockableItem> *pUnlocks);
553
554 // Unlock the parts of a prefabricated Freq of the "metagame" section.
555 // NTSC-U/C: 0x002791a0, PAL: 0x00282c30
556 void ExpandPrefab(const char *pszPrefab, std::vector<UnlockableItem> *pUnlocks);
557
558 // Unlock one part of a prefabricated Freq, and the emblem of a torso.
559 // NTSC-U/C: 0x00279330, PAL: 0x00282dc0
560 void RecordPrefabPart(DataArray *pPart, std::vector<UnlockableItem> *pUnlocks);
561
562 // NTSC-U/C: 0x0027ad70, PAL: 0x00284800
563 int GetFlagBit(int nFlag);
564
565 // NTSC-U/C: 0x0027ad80, PAL: 0x00284810
566 void SetFlagBit(int nFlag);
567
568 // Report the Flag of a power-up.
569 // NTSC-U/C: 0x0027ad98, PAL: 0x00284828
570 int GetPowerupBit(const char *pszPowerup);
571
572 std::vector<const char *> mUnlocks;
574 std::vector<std::vector<const char *>> mSkillUnlocks;
576 std::vector<unsigned char> mPassedEntries;
577 String mName;
578 DateTime mBorn;
579 String mPassword;
580 int mNameLocked;
581 std::vector<SongStats> mRecords;
582 AvatarPartSet mAvatar;
583 int mModified;
584 int mCustom;
585 const char *mPendingPowerup;
587 std::vector<const char *> mLastUnlocks;
588 unsigned char mFlags;
589 int mSoloOption;
590 int mOnlineOption;
591 InputMap mInputMap;
592};
593
603BinStream &operator<<(BinStream &stream, const Campaign &profile);
604
615
622extern unsigned int g_dwUnlockAllSongs;
623
630extern unsigned int g_dwUnlockAllParts;
BinStream & operator>>(BinStream &stream, Campaign &profile)
Read a profile from a stream.
unsigned int g_dwUnlockAllSongs
Non-zero when every song counts as unlocked and finished.
unsigned int g_dwUnlockAllParts
Non-zero when every avatar part and emblem counts as unlocked.
BinStream & operator<<(BinStream &stream, const Campaign &profile)
Write a profile to a stream.
Parts and colours of a player's avatar, the Freq the Freq maker edits.
Definition avatarpartset.h:23
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Saved settings and progress of one player, among them the controller bindings.
Definition campaign.h:20
int GetArenaScoreToBeat(const char *pszArena, int nSkillLevel)
Report the arena score to beat, from the arena_scores of the "db" section.
Flag
Bits of mFlags.
Definition campaign.h:23
@ kFlagFreestyle
Definition campaign.h:27
@ kFlagNone
Definition campaign.h:29
@ kFlagMultiplier
Definition campaign.h:25
@ kFlagFreestyleTip
Definition campaign.h:28
@ kFlagSlowdown
Definition campaign.h:26
@ kFlagAutocatcher
Definition campaign.h:24
int GetCustom() const
Definition campaign.h:445
void SetNameLocked(int nNameLocked)
Definition campaign.h:430
void GetClearedSongs(int nSkillLevel, const char *pszGroup, std::vector< bool > *pCleared)
Report which songs of a group the player has cleared at a skill level.
static void UnlockAllParts()
Count every avatar part and emblem as unlocked for every profile.
Campaign & operator=(const Campaign &other)
Copy another profile into this one.
int HasSeenFreestyleTip()
Report whether the tip about the freestyle lap has shown.
void SetInputMap(const InputMap *pMap)
Replace the controller bindings and mark the profile modified.
const AvatarPartSet & GetAvatar() const
Definition campaign.h:465
const DateTime & GetBorn() const
Definition campaign.h:455
int GetNameLocked() const
Definition campaign.h:425
const String & GetPassword() const
Definition campaign.h:415
void SetAvatar(const AvatarPartSet &avatar)
Definition campaign.h:475
~Campaign()
Destroy the profile.
bool IsSongFinished(const char *pszSong, int nSkillLevel)
Report whether a song was finished at a skill level.
const char * TakePendingPowerup(int nSkillLevel)
Grant the power-up of mPendingPowerup once it is unlocked at a skill level, and clear it.
static void UnlockAllSongs()
Count every song as unlocked for every profile, by setting g_dwUnlockAllSongs.
void SetSoloOption(int nOption)
Record the display option for the solo game and mark the profile changed.
int IsModified() const
Report mModified.
AvatarPartSet & GetAvatar()
Definition campaign.h:470
bool CompletesTier(const char *pszSong, int nSkillLevel)
Report whether a song is the one song of its campaign tier the player has not yet won.
InputMap * GetInputMap()
Report the controller bindings.
void GetSongStats(const char *pszSong, int nSkillLevel, SongStats *pRecord)
Copy the record of a song at a skill level.
void SetOnlineOption(int nOption)
Record the display option for the online game.
int GetSoloOption() const
Report the display option the player chose for the solo game.
const String & GetName() const
Definition campaign.h:435
void Save(BinStream &stream) const
Write the profile, at version 6.
const char * FindFirstUnfinishedSong(int nSkillLevel)
Report the first song of the unlocked arenas the player has not finished at a skill level.
void GetUnlockedParts(int nPart, std::vector< const char * > *pTypes)
List the choices of an avatar part the player may use.
void GetUnlockedEmblems(std::vector< const char * > *pTypes)
List the emblems the player may use.
int GetHighestBeatenSkillLevel()
Report the highest skill level at which the player has beaten the game.
void SetModified(int nModified)
Set mModified.
bool HasBeatenGame(int nSkillLevel)
Report whether the player has beaten the game at a skill level, the symbol beat_game among the unlock...
bool IsUnlocked(const char *pszItem, int nSkillLevel)
Report whether the player has unlocked an item at a skill level.
Medal
Values of GetMedal() and GetMedalForScore(), one more than the goals of the score_goal of the song a ...
Definition campaign.h:36
@ kMedalFinished
Definition campaign.h:38
@ kMedalNone
Definition campaign.h:37
@ kMedalSecond
Definition campaign.h:40
@ kMedalFirst
Definition campaign.h:39
@ kMedalThird
Definition campaign.h:41
void SetPassword(const char *pszPassword)
Definition campaign.h:420
Campaign(const Campaign &other)
Copy a profile.
int GetMedalForScore(const char *pszSong, int nSkillLevel, int nScore, int nPercent)
Report the medal a score earns on a song at a skill level.
void SetCustom(int nCustom)
Definition campaign.h:450
void SetName(const char *pszName)
Definition campaign.h:440
void Load(BinStream &stream)
Read a profile Save() wrote, and rebuild the unlocks from the records.
int GetMedal(const char *pszSong, int nSkillLevel)
Report the medal of a song at a skill level.
void RemoveLockedItems(std::vector< const char * > *pItems)
Remove the items the player has not unlocked at any skill level from a list.
int GetOnlineOption() const
Report the display option the player chose for the online game.
Campaign()
Construct a profile with the default settings and the unlocks of the always entries.
void SetSeenFreestyleTip()
Record that the tip about the freestyle lap has shown.
void RecordResult(const SongStats *pRecord, std::vector< UnlockableItem > *pUnlocks)
Record the result of a song and collect the items it unlocks.
DateTime & GetBorn()
Definition campaign.h:460
int GetArenaScore(const char *pszArena, int nSkillLevel)
Report the sum of the best scores of the songs of an arena.
Reference-counted array of script data nodes.
Definition dataarray.h:20
Local date and time of the console clock.
Definition datetime.h:14
The actions a player's controller buttons and analogue sticks are bound to.
Definition inputmap.h:15
Best result of one player on one song at one skill level, as Campaign stores it.
Definition songstats.h:11
Growable text buffer that is also a PrnStream.
Definition string.h:19