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