Emergency 20 Dokumentation  4.2.0
PlayerProgress.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
13 #include "em5/Export.h"
15 
18 
19 #include <boost/noncopyable.hpp>
20 #include <boost/container/flat_map.hpp>
21 #include <boost/container/flat_set.hpp>
22 #include <boost/dynamic_bitset.hpp>
23 
24 #include <memory> // For std::unique_ptr
25 
26 
27 //[-------------------------------------------------------]
28 //[ Forward declarations ]
29 //[-------------------------------------------------------]
30 namespace qsf
31 {
32  class BinarySerializer;
33 }
34 namespace em5
35 {
36  class AccountManager;
37  class HighscoreManager;
38  class MapIdentifier;
39  class MainEventIdentifier;
40 }
41 
42 
43 //[-------------------------------------------------------]
44 //[ Namespace ]
45 //[-------------------------------------------------------]
46 namespace em5
47 {
48 
49 
50  //[-------------------------------------------------------]
51  //[ Classes ]
52  //[-------------------------------------------------------]
57  class PlayerProgress : public boost::noncopyable
58  {
59 
60 
61  //[-------------------------------------------------------]
62  //[ Friend classes ]
63  //[-------------------------------------------------------]
64  friend AccountManager;
65 
66 
67  //[-------------------------------------------------------]
68  //[ Public definitions ]
69  //[-------------------------------------------------------]
70  public:
71  static const char LOCAL_PLAYER[];
72 
74  {
77 
78  inline WorldEventProgress() :
79  mWorldEventsActive(false),
80  mWaitTime(qsf::Time::ZERO)
81  {}
82  };
83 
84  enum MedalType
85  {
90  };
91 
92  typedef boost::container::flat_set<qsf::NamedIdentifier> NameSet;
93  typedef std::map<qsf::NamedIdentifier, WorldEventProgress> WorldEventProgressMap;
94  typedef std::pair<const qsf::NamedIdentifier, MedalType> Medal;
95  typedef std::map<qsf::NamedIdentifier, MedalType> MedalMap;
96 
97 
98  //[-------------------------------------------------------]
99  //[ Public methods ]
100  //[-------------------------------------------------------]
101  public:
106  PlayerProgress();
107 
112  virtual ~PlayerProgress();
113 
118  void resetProgress(bool clearAchievementsAndMedals);
119 
120  //[-------------------------------------------------------]
121  //[ Total score ]
122  //[-------------------------------------------------------]
127  uint32 getTotalScore() const;
128 
133  void setTotalScore(uint32 totalScore);
134 
139  void addPointsToTotalScore(uint32 points);
140 
141  //[-------------------------------------------------------]
142  //[ Unlock progress ]
143  //[-------------------------------------------------------]
148  bool isTutorialPlayed() const;
149 
154  void setTutorialPlayed(bool unlock);
155 
160  bool isMapUnlocked(const MapIdentifier& mapIdentifier) const;
161 
166  bool isMainEventUnlocked(const MainEventIdentifier& mainEventIdentifier) const;
167 
172  bool isMainEventWonInCampaign(const MainEventIdentifier& mainEventIdentifier) const;
173 
178  void setMapUnlocked(const MapIdentifier& mapIdentifier);
179 
184  void setMainEventUnlocked(const MainEventIdentifier& mainEventIdentifier);
185 
190  void setMainEventWonInCampaign(const MainEventIdentifier& mainEventIdentifier);
191 
196  bool isWorldEventWonMunich(const qsf::NamedIdentifier& eventIdentifier) const;
197  bool isWorldEventWonHamburg(const qsf::NamedIdentifier& eventIdentifier) const;
198  bool isWorldEventWonBerlin(const qsf::NamedIdentifier& eventIdentifier) const;
199 
204  void setWorldEventWonMunich(const qsf::NamedIdentifier& eventIdentifier);
205  void setWorldEventWonHamburg(const qsf::NamedIdentifier& eventIdentifier);
206  void setWorldEventWonBerlin(const qsf::NamedIdentifier& eventIdentifier);
207 
215 
221 
226  bool wasCampaignStarted(uint32 campaignIndex) const;
227 
232  bool wereAllCampaignsStarted() const;
233 
238  void setCampaignStarted(uint32 campaignIndex, bool started = true);
239 
245 
246  //[-------------------------------------------------------]
247  //[ Medals ]
248  //[-------------------------------------------------------]
257  void unlockMedal(const qsf::NamedIdentifier& medalIdentifier, MedalType medalType);
258 
268 
269  const Medal* getMedal(const qsf::StringHash& medalIdentifier) const;
270 
271  const MedalMap& getMedalMap() const;
272 
273  bool isCampaignComplete(uint32 campaignIndex = 0) const;
274 
275  //[-------------------------------------------------------]
276  //[ Fixed event completion ]
277  //[-------------------------------------------------------]
278  bool isFixedEventPoolCompleted(const MapIdentifier& mapIdentifier) const;
279  void setFixedEventPoolCompleted(const MapIdentifier& mapIdentifier, bool completed = true);
280 
281  //[-------------------------------------------------------]
282  //[ Serialization ]
283  //[-------------------------------------------------------]
291  void serialize(qsf::BinarySerializer& serializer);
292 
293 
294  //[-------------------------------------------------------]
295  //[ Protected methods ]
296  //[-------------------------------------------------------]
297  protected:
302  bool loadProgress(const std::string& screenName);
303 
308  bool saveProgress(const std::string& screenName);
309 
310 
311  //[-------------------------------------------------------]
312  //[ Private methods ]
313  //[-------------------------------------------------------]
314  private:
315  std::string getAbsoluteProgressFilename(const std::string& screenName) const;
316 
317 
318  //[-------------------------------------------------------]
319  //[ Private data ]
320  //[-------------------------------------------------------]
321  private:
322  // Achievements are not part of this class, but managed in the "qsf::game::AchievementSystem"
323 
324  // Player progress
325  uint32 mTotalScore;
326  bool mTutorialPlayed;
327  NameSet mMapsUnlocked;
328  NameSet mWonMainEventInCampaign;
329  NameSet mMainEventsUnlocked;
330  NameSet mWonWorldEventsMunich;
331  NameSet mWonWorldEventsHamburg;
332  NameSet mWonWorldEventsBerlin;
333  WorldEventProgressMap mWorldEventProgressList;
334  MedalMap mMedalMap;
335  std::unique_ptr<HighscoreManager> mHighscoreManager;
336  boost::container::flat_set<uint32> mCampaignsStarted;
337  bool mCompletedFixedEventPools[4];
338 
339 
340  };
341 
342 
343 //[-------------------------------------------------------]
344 //[ Namespace ]
345 //[-------------------------------------------------------]
346 } // em5
347 
348 
349 namespace qsf
350 {
351  // serialization specialization
352  namespace serialization
353  {
354  template <>
355  struct serializer<em5::PlayerProgress::WorldEventProgress>
356  {
358  {
359  serializer & data.mWorldEventsActive;
360  serializer & data.mWaitTime;
361  }
362  };
363 
364  template<>
365  struct serializer<em5::PlayerProgress::MedalType>
366  {
368  {
369  if (serializer.isReading())
370  {
371  // We only read/write a single byte, but the datatype is four bytes long. So ensure it's initialized correctly.
373  serializer.serializeRawBlock(&value, 1);
374  }
375  else
376  {
377  serializer.serializeRawBlock(&value, 1);
378  }
379  }
380  };
381  }
382 }
WorldEventProgress()
Definition: PlayerProgress.h:78
Definition: ActionPriority.h:13
bool isMainEventWonInCampaign(const MainEventIdentifier &mainEventIdentifier) const
Check if a main event is won in campaign.
void setMainEventUnlocked(const MainEventIdentifier &mainEventIdentifier)
Unlock the given main event.
void unlockMedal(const qsf::NamedIdentifier &medalIdentifier, MedalType medalType)
Unlock the specified medal.
boost::container::flat_set< qsf::NamedIdentifier > NameSet
Definition: PlayerProgress.h:92
bool wereAllCampaignsStarted() const
Check if all campaigns were started at least once.
void setMapUnlocked(const MapIdentifier &mapIdentifier)
Unlock the given map.
std::map< qsf::NamedIdentifier, WorldEventProgress > WorldEventProgressMap
Definition: PlayerProgress.h:93
std::map< qsf::NamedIdentifier, MedalType > MedalMap
Definition: PlayerProgress.h:95
void addPointsToTotalScore(uint32 points)
Adds points to the total score.
bool isFixedEventPoolCompleted(const MapIdentifier &mapIdentifier) const
unsigned int uint32
Definition: PlatformTypes.h:181
uint16 getWorldEventsWonHamburg() const
uint32 getTotalScore() const
Return the current total score.
void unlockAchievementsOnMedal()
Triggers an achievement if all needed medals are unlocked.
void setCampaignStarted(uint32 campaignIndex, bool started=true)
Set campaign started flag.
bool isCampaignComplete(uint32 campaignIndex=0) const
HighscoreManager & getHighscoreManager()
Get the highscore manager.
static void serialize(BinarySerializer &serializer, em5::PlayerProgress::WorldEventProgress &data)
Definition: PlayerProgress.h:357
const Medal * getMedal(const qsf::StringHash &medalIdentifier) const
EMERGENCY 5 player progress class.
Definition: PlayerProgress.h:57
Definition: PlayerProgress.h:89
bool isWorldEventWonMunich(const qsf::NamedIdentifier &eventIdentifier) const
Check if world event is won.
PlayerProgress()
Default constructor.
bool isWorldEventWonBerlin(const qsf::NamedIdentifier &eventIdentifier) const
bool isWorldEventWonHamburg(const qsf::NamedIdentifier &eventIdentifier) const
EMERGENCY 5 main event identifier class.
Definition: MainEventIdentifier.h:30
void setFixedEventPoolCompleted(const MapIdentifier &mapIdentifier, bool completed=true)
uint16 getWorldEventsWonBerlin() const
Definition: PlayerProgress.h:86
void setWorldEventWonBerlin(const qsf::NamedIdentifier &eventIdentifier)
Definition: PickupPersonByParamedicAction.h:21
void resetProgress(bool clearAchievementsAndMedals)
Reset the current player progress to initial state.
Definition: BinarySerializer.h:332
void setTotalScore(uint32 totalScore)
Sets total score.
std::pair< const qsf::NamedIdentifier, MedalType > Medal
Definition: PlayerProgress.h:94
void serializeRawBlock(void *address, uint32 bytes)
Serialize or deserialize a raw block of memory.
bool isTutorialPlayed() const
Return whether or not the tutorial is considered to have been played.
void setTutorialPlayed(bool unlock)
Set whether or not the tutorial is considered to have been played (freeplay and multiplay is unlocked...
virtual ~PlayerProgress()
Destructor.
void setWorldEventWonHamburg(const qsf::NamedIdentifier &eventIdentifier)
EMERGENCY 5 map identifier class.
Definition: MapIdentifier.h:34
void setWorldEventWonMunich(const qsf::NamedIdentifier &eventIdentifier)
Set world event won.
Definition: PlayerProgress.h:73
static void serialize(qsf::BinarySerializer &serializer, em5::PlayerProgress::MedalType &value)
Definition: PlayerProgress.h:367
bool loadProgress(const std::string &screenName)
Load player progress from disk ("" = local player)
unsigned short uint16
Definition: PlatformTypes.h:178
WorldEventProgress & getWorldEventProgress(const MapIdentifier &mapIdentifier)
Get the world event progress for a given map.
uint16 getWorldEventsWonMunich() const
Get number of world events won.
void serialize(qsf::BinarySerializer &serializer)
Serialization of the player progress.
Class combining strings with their hashes.
Definition: NamedIdentifier.h:34
EMERGENCY 5 network manager class.
Definition: AccountManager.h:78
void setMainEventWonInCampaign(const MainEventIdentifier &mainEventIdentifier)
Unlock the given main event.
bool saveProgress(const std::string &screenName)
Save player progress to disk ("" = local player)
bool isReading() const
Return whether the serializer is currently reading/deserializing.
Definition: BinarySerializer-inl.h:41
Compile time string hash class.
Definition: StringHash.h:59
qsf::Time mWaitTime
Remaining wait time until the world event state changes.
Definition: PlayerProgress.h:76
Definition: PlayerProgress.h:88
Binary serializer class.
Definition: BinarySerializer.h:35
bool isMapUnlocked(const MapIdentifier &mapIdentifier) const
Check if a map is unlocked.
bool wasCampaignStarted(uint32 campaignIndex) const
Check if a certain campaign was started at least once.
Definition: PlayerProgress.h:87
EMERGENCY 5 highscore manager class.
Definition: HighscoreManager.h:90
static const char LOCAL_PLAYER[]
Definition: PlayerProgress.h:71
bool mWorldEventsActive
Indicates if the world events are currently active.
Definition: PlayerProgress.h:75
const MedalMap & getMedalMap() const
bool isMainEventUnlocked(const MainEventIdentifier &mainEventIdentifier) const
Check if a main event is unlocked.
MedalType
Definition: PlayerProgress.h:84
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32