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