]> git.jsancho.org Git - lugaru.git/blob - Source/User/Account.hpp
clang-format: Apply to all headers
[lugaru.git] / Source / User / Account.hpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _ACCOUNT_HPP_
22 #define _ACCOUNT_HPP_
23
24 #include <fstream>
25 #include <map>
26 #include <string>
27 #include <vector>
28
29 struct CampaignProgress
30 {
31     int highscore;
32     float fasttime;
33     int score;
34     float time;
35     std::vector<int> choices;
36     CampaignProgress()
37     {
38         highscore = 0;
39         fasttime = 0;
40         score = 0;
41         time = 0;
42     }
43 };
44
45 class Account
46 {
47 public:
48     static void destroyActive();
49     static void setActive(int i);
50     static void add(const std::string& name);
51     static Account& get(int i);
52     static void loadFile(std::string filename);
53     static void saveFile(std::string filename);
54     static int getNbAccounts();
55
56     static bool hasActive();
57     static Account& active();
58
59     Account(const std::string& name = "");
60     Account(FILE* tfile);
61
62     void endGame();
63     void winCampaignLevel(int choice, int score, float time);
64     void winLevel(int level, int score, float time);
65
66     // getter and setters
67     int getDifficulty();
68     void setDifficulty(int i)
69     {
70         difficulty = i;
71     };
72     const std::string& getName()
73     {
74         return name;
75     };
76     int getCampaignScore()
77     {
78         return campaignProgress[currentCampaign].score;
79     };
80     int getCampaignChoicesMade()
81     {
82         return campaignProgress[currentCampaign].choices.size();
83     };
84     int getCampaignChoice(int i)
85     {
86         return campaignProgress[currentCampaign].choices[i];
87     };
88     void setCampaignScore(int s)
89     {
90         campaignProgress[currentCampaign].score = s;
91         if (s > campaignProgress[currentCampaign].highscore) {
92             campaignProgress[currentCampaign].highscore = s;
93         }
94     };
95     void setCampaignFinalTime(float t)
96     {
97         campaignProgress[currentCampaign].time = t;
98         if ((t < campaignProgress[currentCampaign].fasttime) || ((campaignProgress[currentCampaign].fasttime == 0) && (t != 0))) {
99             campaignProgress[currentCampaign].fasttime = t;
100         }
101     };
102     float getCampaignFasttime()
103     {
104         return campaignProgress[currentCampaign].fasttime;
105     };
106     void resetFasttime()
107     {
108         campaignProgress[currentCampaign].fasttime = 0;
109     };
110     int getCampaignHighScore()
111     {
112         return campaignProgress[currentCampaign].highscore;
113     };
114     int getHighScore(int i)
115     {
116         return highscore[i];
117     };
118     float getFastTime(int i)
119     {
120         return fasttime[i];
121     };
122     int getProgress()
123     {
124         return progress;
125     };
126     std::string getCurrentCampaign()
127     {
128         return currentCampaign;
129     };
130     void setCurrentCampaign(const std::string& name);
131
132 private:
133     //statics
134     static std::vector<Account> accounts;
135     static int i_active;
136
137     void save(FILE* tfile);
138
139     int difficulty;
140     int progress; // progress in challenge levels
141     float points;
142     int highscore[50];
143     float fasttime[50];
144     bool unlocked[60];
145     std::string name;
146
147     std::string currentCampaign;
148     std::map<std::string, CampaignProgress> campaignProgress;
149 };
150
151 #endif