]> git.jsancho.org Git - lugaru.git/blob - Source/Account.h
f9bc5e1654940c614acfa9cda7b40309dee66534
[lugaru.git] / Source / Account.h
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_H_
22 #define _Account_H_
23
24 #include <vector>
25 #include <string>
26 #include <map>
27 #include <fstream>
28
29 struct CampaignProgress {
30     float highscore;
31     float fasttime;
32     float 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 indice(Account* a);
53
54     static bool hasActive() { return (_active != nullptr); }
55     static Account& active() { return *_active; }
56     static Account* _active;
57
58     void endGame();
59     void winCampaignLevel(int choice, float score, float time);
60     void winLevel(int level, float score, float time);
61
62     // getter and setters
63     int getDifficulty();
64     void setDifficulty(int i) {
65         difficulty = i;
66     };
67     const std::string& getName() {
68         return name;
69     };
70     float getCampaignScore() {
71         return campaignProgress[currentCampaign].score;
72     };
73     int getCampaignChoicesMade() {
74         return campaignProgress[currentCampaign].choices.size();
75     };
76     int getCampaignChoice(int i) {
77         return campaignProgress[currentCampaign].choices[i];
78     };
79     void setCampaignScore(int s) {
80         campaignProgress[currentCampaign].score = s;
81         if (s > campaignProgress[currentCampaign].highscore)
82             campaignProgress[currentCampaign].highscore = s;
83     };
84     void setCampaignFinalTime(float t) {
85         campaignProgress[currentCampaign].time = t;
86         if ((t < campaignProgress[currentCampaign].fasttime) || ((campaignProgress[currentCampaign].fasttime == 0) && (t != 0)))
87             campaignProgress[currentCampaign].fasttime = t;
88     };
89     float getCampaignFasttime() {
90         return campaignProgress[currentCampaign].fasttime;
91     };
92     void resetFasttime() {
93         campaignProgress[currentCampaign].fasttime = 0;
94     };
95     float getCampaignHighScore() {
96         return campaignProgress[currentCampaign].highscore;
97     };
98     float getHighScore(int i) {
99         return highscore[i];
100     };
101     float getFastTime(int i) {
102         return fasttime[i];
103     };
104     int getProgress() {
105         return progress;
106     };
107     std::string getCurrentCampaign() {
108         return currentCampaign;
109     };
110     void setCurrentCampaign(const std::string& name);
111
112     static int getNbAccounts() {
113         return accounts.size();
114     };
115 private:
116     Account(const std::string& name = "");
117     int difficulty;
118     int progress; // progress in challenge levels
119     float points;
120     float highscore[50];
121     float fasttime[50];
122     bool unlocked[60];
123     std::string name;
124
125     std::string currentCampaign;
126     std::map<std::string, CampaignProgress> campaignProgress;
127
128     //statics
129     static std::vector<Account*> accounts;
130 };
131
132 #endif