resonance 1.0.1
Loading...
Searching...
No Matches
campaignstats.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <vector>
5
6#include "game/levelstats.h"
7#include "met/metsonglists.h"
8#include "os/hxstr.h"
9#include "stream/ibstream.h"
10#include "stream/obstream.h"
11
12class GameParams;
13
36public:
38 static constexpr int kDifficultyCount = 3;
39
41 static constexpr int kStageCount = 6;
42
44 static constexpr int kIndexedStageCount = 5;
45
47 static constexpr int kDifficultyExpert = 2;
48
50 static constexpr int kSecretStage = 6;
51
62
67 virtual ~CampaignStats();
68
79
89 virtual void Save(OBStream &stream);
90
102 virtual void Load(IBStream &stream);
103
115 int FindLevelIndex(const HxStr &name) {
116 unsigned nIndex = 0;
117 while (nIndex < mLevels.size()) {
118 if (mLevels[nIndex].mName == name) {
119 break;
120 }
121 ++nIndex;
122 }
123 return static_cast<int>(nIndex);
124 }
125
137 int GetLevelBeaten(int nDifficulty, const HxStr &name);
138
150 int GetLevelHighScore(int nDifficulty, const HxStr &name);
151
164 void RecordLevelBeaten(int nDifficulty, const HxStr &name);
165
177 void RecordHighScore(int nDifficulty, const HxStr &name, int nScore);
178
188 int GetStageScoreBeaten(int nDifficulty, int nStage);
189
199 int GetStageScore(int nDifficulty, int nStage);
200
215 int IsStageComplete(int nDifficulty, int nStage);
216
225 int IsDifficultyComplete(int nDifficulty);
226
239 HxStr GetBonusLevelName(int nDifficulty, int nStage);
240
254 int bUnlocked = 0;
256 bUnlocked = GetStageList(kSecretStage)->size() != 0;
257 }
258 return bUnlocked;
259 }
260
272
287
302
315 void Assign(const CampaignStats &other);
316
328 void PrintLevels(std::ostream &stream);
329
330private:
340 void RebuildStageLevels();
341
350 int IsLevelListed(const HxStr &name);
351
359 void RecountAll();
360
369 void RecountStageCompleted(int nDifficulty, int nStage);
370
379 void RecountStageScore(int nDifficulty, int nStage);
380
387 int UpdateUnlockLevel();
388
396 void ResetCounters();
397
398public:
413
414private:
415 std::vector<LevelStats> mLevels;
416
417public:
425
426private:
427 int mStageLevelCounts[kStageCount];
428 int mStageCompleted[kDifficultyCount][kStageCount];
429 int mStageScoreBeaten[kDifficultyCount][kStageCount];
430 int mStageScores[kDifficultyCount][kStageCount];
431 // The indices into mLevels of each stage's levels, for stages 1 through 5.
432 std::vector<int> mStageLevels[kIndexedStageCount];
433};
int FindLevelIndex(const HxStr &name)
Find the record for a level by name.
Definition campaignstats.h:115
CampaignStats()
Construct empty progress.
void RecordLevelBeaten(int nDifficulty, const HxStr &name)
Record a level as beaten at a difficulty and recount what depends on it.
int GetStageScore(int nDifficulty, int nStage)
Report a stage's total score at a difficulty.
int IsSecretUnlocked()
Report whether the secret stage is unlocked.
Definition campaignstats.h:253
int GetStageScoreBeaten(int nDifficulty, int nStage)
Report whether a stage's total score has reached its target at a difficulty.
void RecordHighScore(int nDifficulty, const HxStr &name, int nScore)
Record a score for a level at a difficulty when it beats the high score.
virtual void Save(OBStream &stream)
Write the whole campaign record.
int GetLevelBeaten(int nDifficulty, const HxStr &name)
Report whether a level has been beaten at a difficulty.
int IsSuperSecretUnlocked()
Report whether the super secret is unlocked.
virtual void Load(IBStream &stream)
Read the whole campaign record.
int IsDifficultyComplete(int nDifficulty)
Report whether every stage of a difficulty is complete and every bonus level beaten.
int GetLevelHighScore(int nDifficulty, const HxStr &name)
Report a level's high score at a difficulty.
int IsStageComplete(int nDifficulty, int nStage)
Report whether every required level of a stage is beaten at a difficulty.
static constexpr int kSecretStage
The secret stage, which follows the last regular stage.
Definition campaignstats.h:50
static constexpr int kDifficultyCount
The number of difficulties, easy, normal, and expert.
Definition campaignstats.h:38
static constexpr int kDifficultyExpert
The expert difficulty, the last of the three.
Definition campaignstats.h:47
HxStr GetBonusLevelName(int nDifficulty, int nStage)
Report the name of a stage's bonus level.
void RebuildLevelList()
Clear the level vector and rebuild it from the global level list.
void Assign(const CampaignStats &other)
Copy another record's levels into this one and recount everything.
int IsLastLevelRemaining(const GameParams &params)
Report whether a session's level is the one level left unbeaten at its difficulty.
int mUnlockLevel
The number of arenas unlocked, 1 through 8, as UpdateUnlockLevel() last computed it.
Definition campaignstats.h:424
static constexpr int kIndexedStageCount
The number of stages whose level indices the record stores, stages 1 through 5.
Definition campaignstats.h:44
virtual ~CampaignStats()
int IsStageCompleteAtAnyDifficulty(int nStage)
Report whether a stage is complete at any difficulty that plays it as a main stage.
static constexpr int kStageCount
The number of stages, the secret stage 6 included.
Definition campaignstats.h:41
void PrintLevels(std::ostream &stream)
Write every level to a text stream, one line each as levels[<i>] and the level's own text.
void MergeLevelList()
Rebuild the level vector from the global level list after a load.
Settings a game session is started with.
Definition gameparams.h:42
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Input half of the byte stream interface.
Definition ibstream.h:36
Output half of the byte stream interface.
Definition obstream.h:25
std::vector< StageListEntry > * GetStageList(int nStage)
Report one stage's level list.