Colobot
player_profile.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 #include "graphics/core/color.h"
23 
24 #include "level/level_category.h"
25 
26 #include <string>
27 #include <map>
28 #include <vector>
29 
30 struct LevelInfo
31 {
32  int numTry = 0;
33  bool bPassed = false;
34 };
35 
37 {
38  int face = 0; // face
39  int glasses = 0; // glasses
40  Gfx::Color colorHair; // hair color
41  Gfx::Color colorCombi; // spacesuit volor
42  Gfx::Color colorBand; // strips color
43 
44  void DefPerso();
45 };
46 
47 struct SavedScene
48 {
49  std::string path;
50  std::string name;
51 
52  SavedScene(std::string path = "", std::string name = "")
53  : path(path), name(name)
54  {}
55 };
56 
58 {
59 public:
60  // Creates CPlayerProfile instance and loads player save data
61  CPlayerProfile(std::string playerName);
62  ~CPlayerProfile();
63  // Returns last used player name, or "Player" if none found
64  static std::string GetLastName();
65  // Returnslist of possible player names
66  static std::vector<std::string> GetPlayerList();
67 
68  // Creates player save directory (if needed)
69  bool Create();
70  // Removes player save directory
71  bool Delete();
72 
74  std::string GetName();
75 
77  std::string GetSaveDir();
79  std::string GetSaveFile(std::string filename);
80 
82  void IncrementLevelTryCount(LevelCategory cat, int chap, int rank);
84  int GetLevelTryCount(LevelCategory cat, int chap, int rank);
86  void SetLevelPassed(LevelCategory cat, int chap, int rank, bool bPassed);
88  bool GetLevelPassed(LevelCategory cat, int chap, int rank);
90  int GetChapPassed(LevelCategory cat);
91 
93  void SetSelectedChap(LevelCategory category, int chap);
95  int GetSelectedChap(LevelCategory category);
97  void SetSelectedRank(LevelCategory category, int rank);
99  int GetSelectedRank(LevelCategory category);
100 
104  void SetFreeGameBuildUnlock(int freeBuild);
108  void SetFreeGameResearchUnlock(int freeResearch);
109 
113  void LoadApperance();
115  void SaveApperance();
116 
118  bool HasAnySavedScene();
120  std::vector<SavedScene> GetSavedSceneList();
122  void SaveScene(std::string dir, std::string info);
124  void LoadScene(std::string dir);
126  bool DeleteScene(std::string dir);
127 
128 protected:
130  void LoadFinishedLevels(LevelCategory category);
132  void SaveFinishedLevels(LevelCategory category);
133 
135  void LoadFreeGameUnlock();
137  void SaveFreeGameUnlock();
138 
139 protected:
141  std::string m_playerName;
142 
144  std::map<LevelCategory, bool> m_levelInfoLoaded;
146  std::map<LevelCategory, std::map<int, std::map<int, LevelInfo>>> m_levelInfo;
148  std::map<LevelCategory, int> m_selectChap;
150  std::map<LevelCategory, int> m_selectRank;
151 
158 
161 };
void SaveApperance()
Saves PlayerApperance structure.
Definition: player_profile.cpp:401
void SaveScene(std::string dir, std::string info)
Saves current scene status.
Definition: player_profile.cpp:467
std::map< LevelCategory, bool > m_levelInfoLoaded
Is finished levels file loaded already?
Definition: player_profile.h:144
std::map< LevelCategory, int > m_selectRank
Selected level rank.
Definition: player_profile.h:150
PlayerApperance & GetApperance()
Returns a reference to PlayerApperance structure.
Definition: player_profile.cpp:366
Definition: player_profile.h:36
std::string GetName()
Returns player name.
Definition: player_profile.cpp:130
int GetSelectedRank(LevelCategory category)
Returns selected level from save file.
Definition: player_profile.cpp:213
std::string m_playerName
Player name.
Definition: player_profile.h:141
std::string GetSaveDir()
Returns player's save directory path.
Definition: player_profile.cpp:135
int GetFreeGameResearchUnlock()
Returns unlocked DoneResearch for free game.
Definition: player_profile.cpp:308
bool GetLevelPassed(LevelCategory cat, int chap, int rank)
Chenks if the level (or chapter, if rank=0) is passed.
Definition: player_profile.cpp:172
bool DeleteScene(std::string dir)
Delete saved scene.
Definition: player_profile.cpp:525
std::map< LevelCategory, std::map< int, std::map< int, LevelInfo > > > m_levelInfo
Level completion info.
Definition: player_profile.h:146
void LoadScene(std::string dir)
Loads scene.
Definition: player_profile.cpp:477
void SetFreeGameBuildUnlock(int freeBuild)
Saves unlocked EnableBuild for free game.
Definition: player_profile.cpp:302
void SetFreeGameResearchUnlock(int freeResearch)
Saves unlocked DoneResearch for free game.
Definition: player_profile.cpp:315
void IncrementLevelTryCount(LevelCategory cat, int chap, int rank)
Increments level try count.
Definition: player_profile.cpp:147
Color structs and related functions.
void SetSelectedRank(LevelCategory category, int rank)
Sets selected level for save file.
Definition: player_profile.cpp:207
bool HasAnySavedScene()
Returns true if player has at least one saved scene.
Definition: player_profile.cpp:429
int m_freegameBuild
Buildings unlocked for free game.
Definition: player_profile.h:155
Definition: player_profile.h:30
std::string GetSaveFile(std::string filename)
Returns path to file inside player's save directory.
Definition: player_profile.cpp:140
PlayerApperance m_apperance
Player apperance.
Definition: player_profile.h:160
int GetSelectedChap(LevelCategory category)
Returns selected chapter from save file.
Definition: player_profile.cpp:199
int m_freegameResearch
Researches unlocked for free game.
Definition: player_profile.h:157
Definition: player_profile.h:47
void SetSelectedChap(LevelCategory category, int chap)
Sets selected chapter for save file.
Definition: player_profile.cpp:193
Definition: player_profile.h:57
bool m_freegameLoaded
Is freegame save file loaded already?
Definition: player_profile.h:153
void SaveFreeGameUnlock()
Saves free game unlock state.
Definition: player_profile.cpp:348
void SaveFinishedLevels(LevelCategory category)
Saves LevelInfo data for given category.
Definition: player_profile.cpp:264
void SetLevelPassed(LevelCategory cat, int chap, int rank, bool bPassed)
Changes level passed status (also updates chapter passed status)
Definition: player_profile.cpp:160
int GetLevelTryCount(LevelCategory cat, int chap, int rank)
Returns try count for given level.
Definition: player_profile.cpp:153
void LoadApperance()
Loads PlayerApperance structure.
Definition: player_profile.cpp:371
std::vector< SavedScene > GetSavedSceneList()
Returns list of all saved scenes.
Definition: player_profile.cpp:442
int GetChapPassed(LevelCategory cat)
Returns the highest chapter accessible in the given category.
Definition: player_profile.cpp:179
std::map< LevelCategory, int > m_selectChap
Selected level chapter.
Definition: player_profile.h:148
RGBA color.
Definition: color.h:39
void LoadFreeGameUnlock()
Loads free game unlock state.
Definition: player_profile.cpp:321
void LoadFinishedLevels(LevelCategory category)
Loads LevelInfo data for given category.
Definition: player_profile.cpp:221
int GetFreeGameBuildUnlock()
Returns unlocked EnableBuild for free game.
Definition: player_profile.cpp:294