]> git.jsancho.org Git - lugaru.git/commitdiff
no more 5000 int array, a nice vector instead.
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Tue, 10 May 2011 20:08:00 +0000 (22:08 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Tue, 10 May 2011 20:08:00 +0000 (22:08 +0200)
Source/Account.cpp
Source/Account.h

index 56aaf9c33a723f516daaf403e7d73c036031a894..145dea1bdf9cc7ee1dfef1c0f037780637f52dd6 100644 (file)
@@ -44,8 +44,6 @@ Account::Account(string n) {
        campaignfasttime = 0;
        campaignscore = 0;
        campaigntime = 0;
-       campaignchoicesmade = 0;
-       memset(campaignchoices, 0, sizeof(campaignchoices));
 }
 
 Account* Account::add(string name) {
@@ -80,13 +78,13 @@ int Account::getDifficulty() {
 }
 
 void Account::endGame() {
-       campaignchoicesmade=0;
+       campaignchoices.clear();
        campaignscore=0;
        campaigntime=0;
 }
 
 void Account::winCampaignLevel(int choice, float score, float time) {
-       campaignchoices[campaignchoicesmade++] = choice;
+       campaignchoices.push_back(choice);
        setCampaignScore(campaignscore+score);
        campaigntime = time;
 }
@@ -125,14 +123,16 @@ Account* Account::loadFile(string filename) {
                        funpackf(tfile, "Bf", &(acc->campaignhighscore));
                        funpackf(tfile, "Bi", &(acc->difficulty));
                        funpackf(tfile, "Bi", &(acc->progress));
-                       funpackf(tfile, "Bi", &(acc->campaignchoicesmade));
-                       for(j=0;j<acc->campaignchoicesmade;j++)
+                       int campaignchoicesmade,campaignchoice;
+                       funpackf(tfile, "Bi", &campaignchoicesmade);
+                       for(j=0;j<campaignchoicesmade;j++)
                        {
-                               funpackf(tfile, "Bi", &(acc->campaignchoices[j]));
-                               if (acc->campaignchoices[j] >= 10)
+                               funpackf(tfile, "Bi", &campaignchoice);
+                               if (campaignchoice >= 10) // what is that for?
                                {
-                                       acc->campaignchoices[j] = 0;
+                                       campaignchoice = 0;
                                }
+                               acc->campaignchoices.push_back(campaignchoice);
                        }
                        funpackf(tfile, "Bf", &(acc->points));
                        for(j=0;j<50;j++)
@@ -186,8 +186,8 @@ void Account::saveFile(string filename, Account* accountactive) {
                        fpackf(tfile, "Bf", a->campaignhighscore);
                        fpackf(tfile, "Bi", a->difficulty);
                        fpackf(tfile, "Bi", a->progress);
-                       fpackf(tfile, "Bi", a->campaignchoicesmade);
-                       for(j=0;j<a->campaignchoicesmade;j++)
+                       fpackf(tfile, "Bi", a->getCampaignChoicesMade());
+                       for(j=0;j<a->getCampaignChoicesMade();j++)
                        {
                                fpackf(tfile, "Bi", a->campaignchoices[j]);
                        }
index 5acbe6a74b517e5dbffa002dd2504e366bf3a002..24b856fbfb2c513b13df1a11964bd1f882ae43f4 100644 (file)
@@ -47,7 +47,7 @@ class Account {
                void setDifficulty(int i) { difficulty = i; };
                const char* getName() { return name.c_str(); };
                float getCampaignScore() { return campaignscore; };
-               int getCampaignChoicesMade() { return campaignchoicesmade; };
+               int getCampaignChoicesMade() { return campaignchoices.size(); };
                int getCampaignChoice(int i) { return campaignchoices[i]; };
                void setCampaignScore(int s) {
                        campaignscore=s;
@@ -80,8 +80,7 @@ class Account {
                float campaignfasttime;
                float campaignscore;
                float campaigntime;
-               int campaignchoicesmade;
-               int campaignchoices[5000]; // should really disappear. I'd use a vector or something like that.
+               std::vector<int> campaignchoices;
        
        //statics
                static std::vector<Account*> accounts;