]> git.jsancho.org Git - lugaru.git/blob - Source/User/Account.hpp
f75a1838ddfcbb419d224601640a23f6579dd82a
[lugaru.git] / Source / User / Account.hpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - 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     int highscore;
31     float fasttime;
32     int score;
33     float time;
34     std::vector<int> choices;
35     CampaignProgress() {
36         highscore = 0;
37         fasttime = 0;
38         score = 0;
39         time = 0;
40     }
41 };
42
43 class Account
44 {
45 public:
46     static void destroyActive();
47     static void setActive(int i);
48     static void add(const std::string& name);
49     static Account& get(int i);
50     static void loadFile(std::string filename);
51     static void saveFile(std::string filename);
52     static int getNbAccounts();
53
54     static bool hasActive();
55     static Account& active();
56
57     Account(const std::string& name = "");
58     Account(FILE* tfile);
59
60     void endGame();
61     void winCampaignLevel(int choice, int score, float time);
62     void winLevel(int level, int score, float time);
63
64     // getter and setters
65     int getDifficulty();
66     void setDifficulty(int i) {
67         difficulty = i;
68     };
69     const std::string& getName() {
70         return name;
71     };
72     int getCampaignScore() {
73         return campaignProgress[currentCampaign].score;
74     };
75     int getCampaignChoicesMade() {
76         return campaignProgress[currentCampaign].choices.size();
77     };
78     int getCampaignChoice(int i) {
79         return campaignProgress[currentCampaign].choices[i];
80     };
81     void setCampaignScore(int s) {
82         campaignProgress[currentCampaign].score = s;
83         if (s > campaignProgress[currentCampaign].highscore) {
84             campaignProgress[currentCampaign].highscore = s;
85         }
86     };
87     void setCampaignFinalTime(float t) {
88         campaignProgress[currentCampaign].time = t;
89         if ((t < campaignProgress[currentCampaign].fasttime) || ((campaignProgress[currentCampaign].fasttime == 0) && (t != 0))) {
90             campaignProgress[currentCampaign].fasttime = t;
91         }
92     };
93     float getCampaignFasttime() {
94         return campaignProgress[currentCampaign].fasttime;
95     };
96     void resetFasttime() {
97         campaignProgress[currentCampaign].fasttime = 0;
98     };
99     int getCampaignHighScore() {
100         return campaignProgress[currentCampaign].highscore;
101     };
102     int getHighScore(int i) {
103         return highscore[i];
104     };
105     float getFastTime(int i) {
106         return fasttime[i];
107     };
108     int getProgress() {
109         return progress;
110     };
111     std::string getCurrentCampaign() {
112         return currentCampaign;
113     };
114     void setCurrentCampaign(const std::string& name);
115
116 private:
117     //statics
118     static std::vector<Account> accounts;
119     static int i_active;
120
121     void save(FILE* tfile);
122
123     int difficulty;
124     int progress; // progress in challenge levels
125     float points;
126     int highscore[50];
127     float fasttime[50];
128     bool unlocked[60];
129     std::string name;
130
131     std::string currentCampaign;
132     std::map<std::string, CampaignProgress> campaignProgress;
133 };
134
135 #endif