X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;ds=sidebyside;f=Source%2FUser%2FAccount.cpp;h=bfc621e080c6692160ae1727566a0eac58a541a7;hb=0aab437dc560d2afa982e61cc2547756ad7b0761;hp=ed0a654efa389a201a204311c105585e799665d4;hpb=ed3662c0852c4312a612b4fc35bd03aba8d13db7;p=lugaru.git
diff --git a/Source/User/Account.cpp b/Source/User/Account.cpp
index ed0a654..bfc621e 100644
--- a/Source/User/Account.cpp
+++ b/Source/User/Account.cpp
@@ -1,6 +1,6 @@
/*
Copyright (C) 2003, 2010 - Wolfire Games
-Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
This file is part of Lugaru.
@@ -20,7 +20,7 @@ along with Lugaru. If not, see .
#include "User/Account.hpp"
-#include "MacCompatibility.hpp"
+#include "Platform/Platform.hpp"
#include "Utils/binio.h"
#include
@@ -34,7 +34,9 @@ extern bool devtools;
vector Account::accounts;
int Account::i_active = -1;
-Account::Account(const string& name) : name(name), campaignProgress()
+Account::Account(const string& name)
+ : name(name)
+ , campaignProgress()
{
difficulty = 0;
progress = 0;
@@ -46,7 +48,8 @@ Account::Account(const string& name) : name(name), campaignProgress()
setCurrentCampaign("main");
}
-Account::Account(FILE* tfile) : Account("")
+Account::Account(FILE* tfile)
+ : Account("")
{
funpackf(tfile, "Bi", &difficulty);
funpackf(tfile, "Bi", &progress);
@@ -57,15 +60,18 @@ Account::Account(FILE* tfile) : Account("")
string campaignName = "";
int t;
char c;
- funpackf(tfile, "Bi", &t);
+ funpackf(tfile, "Bi", &t);
for (int j = 0; j < t; j++) {
- funpackf(tfile, "Bb", &c);
+ funpackf(tfile, "Bb", &c);
campaignName.append(1, c);
}
+ float fscore, fhighscore;
funpackf(tfile, "Bf", &(campaignProgress[campaignName].time));
- funpackf(tfile, "Bf", &(campaignProgress[campaignName].score));
+ funpackf(tfile, "Bf", &(fscore));
funpackf(tfile, "Bf", &(campaignProgress[campaignName].fasttime));
- funpackf(tfile, "Bf", &(campaignProgress[campaignName].highscore));
+ funpackf(tfile, "Bf", &(fhighscore));
+ campaignProgress[campaignName].score = fscore;
+ campaignProgress[campaignName].highscore = fhighscore;
int campaignchoicesmade, campaignchoice;
funpackf(tfile, "Bi", &campaignchoicesmade);
for (int j = 0; j < campaignchoicesmade; j++) {
@@ -80,25 +86,27 @@ Account::Account(FILE* tfile) : Account("")
currentCampaign = "";
int t;
char c;
- funpackf(tfile, "Bi", &t);
+ funpackf(tfile, "Bi", &t);
for (int i = 0; i < t; i++) {
- funpackf(tfile, "Bb", &c);
+ funpackf(tfile, "Bb", &c);
currentCampaign.append(1, c);
}
funpackf(tfile, "Bf", &points);
for (int i = 0; i < 50; i++) {
- funpackf(tfile, "Bf", &(highscore[i]));
+ float fscore;
+ funpackf(tfile, "Bf", &(fscore));
funpackf(tfile, "Bf", &(fasttime[i]));
+ highscore[i] = fscore;
}
for (int i = 0; i < 60; i++) {
- funpackf(tfile, "Bb", &(unlocked[i]));
+ funpackf(tfile, "Bb", &(unlocked[i]));
}
int temp;
char ctemp;
- funpackf(tfile, "Bi", &temp);
+ funpackf(tfile, "Bi", &temp);
for (int i = 0; i < temp; i++) {
- funpackf(tfile, "Bb", &ctemp);
+ funpackf(tfile, "Bb", &ctemp);
name.append(1, ctemp);
}
if (name.empty()) {
@@ -114,14 +122,14 @@ void Account::save(FILE* tfile)
map::const_iterator it;
for (it = campaignProgress.begin(); it != campaignProgress.end(); ++it) {
- fpackf(tfile, "Bi", it->first.size());
+ fpackf(tfile, "Bi", it->first.size());
for (unsigned j = 0; j < it->first.size(); j++) {
- fpackf(tfile, "Bb", it->first[j]);
+ fpackf(tfile, "Bb", it->first[j]);
}
fpackf(tfile, "Bf", it->second.time);
- fpackf(tfile, "Bf", it->second.score);
+ fpackf(tfile, "Bf", float(it->second.score));
fpackf(tfile, "Bf", it->second.fasttime);
- fpackf(tfile, "Bf", it->second.highscore);
+ fpackf(tfile, "Bf", float(it->second.highscore));
fpackf(tfile, "Bi", it->second.choices.size());
for (unsigned j = 0; j < it->second.choices.size(); j++) {
fpackf(tfile, "Bi", it->second.choices[j]);
@@ -135,15 +143,15 @@ void Account::save(FILE* tfile)
fpackf(tfile, "Bf", points);
for (unsigned j = 0; j < 50; j++) {
- fpackf(tfile, "Bf", highscore[j]);
+ fpackf(tfile, "Bf", float(highscore[j]));
fpackf(tfile, "Bf", fasttime[j]);
}
for (unsigned j = 0; j < 60; j++) {
- fpackf(tfile, "Bb", unlocked[j]);
+ fpackf(tfile, "Bb", unlocked[j]);
}
- fpackf(tfile, "Bi", name.size());
+ fpackf(tfile, "Bi", name.size());
for (unsigned j = 0; j < name.size(); j++) {
- fpackf(tfile, "Bb", name[j]);
+ fpackf(tfile, "Bb", name[j]);
}
}
@@ -211,33 +219,36 @@ void Account::endGame()
campaignProgress[currentCampaign].time = 0;
}
-void Account::winCampaignLevel(int choice, float score, float time)
+void Account::winCampaignLevel(int choice, int score, float time)
{
campaignProgress[currentCampaign].choices.push_back(choice);
setCampaignScore(campaignProgress[currentCampaign].score + score);
campaignProgress[currentCampaign].time = time;
}
-void Account::winLevel(int level, float score, float time)
+void Account::winLevel(int level, int score, float time)
{
if (!devtools) {
- if (score > highscore[level])
+ if (score > highscore[level]) {
highscore[level] = score;
- if (time < fasttime[level] || fasttime[level] == 0)
+ }
+ if (time < fasttime[level] || fasttime[level] == 0) {
fasttime[level] = time;
+ }
}
- if (progress < level + 1)
+ if (progress < level + 1) {
progress = level + 1;
+ }
}
void Account::loadFile(string filename)
{
- FILE *tfile;
+ FILE* tfile;
int numaccounts;
int iactive;
errno = 0;
- tfile = fopen(filename.c_str(), "rb" );
+ tfile = fopen(filename.c_str(), "rb");
if (tfile) {
funpackf(tfile, "Bi", &numaccounts);
@@ -258,10 +269,10 @@ void Account::loadFile(string filename)
void Account::saveFile(string filename)
{
- FILE *tfile;
+ FILE* tfile;
errno = 0;
- tfile = fopen(filename.c_str(), "wb" );
+ tfile = fopen(filename.c_str(), "wb");
if (tfile) {
fpackf(tfile, "Bi", getNbAccounts());
fpackf(tfile, "Bi", i_active);