]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Account.cpp
console commands works again.
[lugaru.git] / Source / Account.cpp
index 45e1300e68c827c6dccf45fbe5f5900cb5827b1c..7eba58815332e28c4edda56ca0be8fd99c7a7c87 100644 (file)
@@ -32,7 +32,7 @@ extern bool debugmode;
 
 vector<Account*> Account::accounts = vector<Account*>();
 
-Account::Account(string n) {
+Account::Account(string n) : campaignProgress() {
        name = string(n);
        difficulty = 0;
        progress = 0;
@@ -41,7 +41,11 @@ Account::Account(string n) {
        memset(fasttime, 0, sizeof(fasttime));
        memset(unlocked, 0, sizeof(unlocked));
        
-       currentCampaign = "main";
+       setCurrentCampaign("main");
+}
+
+void Account::setCurrentCampaign(string name) {
+       currentCampaign = name;
 }
 
 Account* Account::add(string name) {
@@ -67,7 +71,7 @@ Account* Account::destroy(Account* a) {
                        return NULL;
                }
        }
-       printf("Unexpected error : User %s not found %d\n",a->getName(),a);
+       printf("Unexpected error : User %s not found\n",a->getName());
        return accounts.front();
 }
 
@@ -102,7 +106,6 @@ Account* Account::loadFile(string filename) {
        FILE *tfile;
        int numaccounts;
        int accountactive;
-       int j;
        
        tfile=fopen(ConvertFileName(filename.c_str()), "rb" );
        
@@ -126,7 +129,7 @@ Account* Account::loadFile(string filename) {
                                int t;
                                char c;
                                funpackf(tfile, "Bi",  &t);
-                               for(j=0;j<t;j++)
+                               for(int j=0;j<t;j++)
                                {
                                        funpackf(tfile, "Bb",  &c);
                                        campaignName.append(1,c);
@@ -138,7 +141,7 @@ Account* Account::loadFile(string filename) {
                                funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].highscore));
                                int campaignchoicesmade,campaignchoice;
                                funpackf(tfile, "Bi", &campaignchoicesmade);
-                               for(j=0;j<campaignchoicesmade;j++)
+                               for(int j=0;j<campaignchoicesmade;j++)
                                {
                                        funpackf(tfile, "Bi", &campaignchoice);
                                        if (campaignchoice >= 10) // what is that for?
@@ -149,20 +152,30 @@ Account* Account::loadFile(string filename) {
                                }
                        }
                        
+                       acc->currentCampaign = "";
+                       int t;
+                       char c;
+                       funpackf(tfile, "Bi",  &t);
+                       for(int i=0;i<t;i++)
+                       {
+                               funpackf(tfile, "Bb",  &c);
+                               acc->currentCampaign.append(1,c);
+                       }
+                       
                        funpackf(tfile, "Bf", &(acc->points));
-                       for(j=0;j<50;j++)
+                       for(int i=0;i<50;i++)
                        {
-                               funpackf(tfile, "Bf", &(acc->highscore[j]));
-                               funpackf(tfile, "Bf", &(acc->fasttime[j]));
+                               funpackf(tfile, "Bf", &(acc->highscore[i]));
+                               funpackf(tfile, "Bf", &(acc->fasttime[i]));
                        }
-                       for(j=0;j<60;j++)
+                       for(int i=0;i<60;i++)
                        {
-                               funpackf(tfile, "Bb",  &(acc->unlocked[j]));
+                               funpackf(tfile, "Bb",  &(acc->unlocked[i]));
                        }
                        int temp;
                        char ctemp;
                        funpackf(tfile, "Bi",  &temp);
-                       for(j=0;j<temp;j++)
+                       for(int i=0;i<temp;i++)
                        {
                                funpackf(tfile, "Bb",  &ctemp);
                                acc->name.append(1,ctemp);
@@ -199,7 +212,7 @@ void Account::saveFile(string filename, Account* accountactive) {
                        fpackf(tfile, "Bi", a->progress);
                        fpackf(tfile, "Bi", a->campaignProgress.size());
                        
-                       map<string,campaign_progress_t>::const_iterator it;
+                       map<string,CampaignProgress>::const_iterator it;
                        for( it=a->campaignProgress.begin(); it!= a->campaignProgress.end(); ++it) {
                                fpackf(tfile, "Bi",  it->first.size());
                                for(j=0;j<it->first.size();j++)
@@ -217,6 +230,12 @@ void Account::saveFile(string filename, Account* accountactive) {
                                }
                        }
                        
+                       fpackf(tfile, "Bi", a->getCurrentCampaign().size());
+                       for(j=0;j<a->getCurrentCampaign().size();j++)
+                       {
+                               fpackf(tfile, "Bb", a->getCurrentCampaign()[j]);
+                       }
+                       
                        fpackf(tfile, "Bf", a->points);
                        for(j=0;j<50;j++)
                        {