From ac1f817a1133a0b81029430c40aab3c047cb7d7c Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20BERNIGAUD?= Date: Tue, 10 May 2011 22:08:00 +0200 Subject: [PATCH] no more 5000 int array, a nice vector instead. --- Source/Account.cpp | 22 +++++++++++----------- Source/Account.h | 5 ++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Source/Account.cpp b/Source/Account.cpp index 56aaf9c..145dea1 100644 --- a/Source/Account.cpp +++ b/Source/Account.cpp @@ -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;jcampaignchoicesmade;j++) + int campaignchoicesmade,campaignchoice; + funpackf(tfile, "Bi", &campaignchoicesmade); + for(j=0;jcampaignchoices[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;jcampaignchoicesmade;j++) + fpackf(tfile, "Bi", a->getCampaignChoicesMade()); + for(j=0;jgetCampaignChoicesMade();j++) { fpackf(tfile, "Bi", a->campaignchoices[j]); } diff --git a/Source/Account.h b/Source/Account.h index 5acbe6a..24b856f 100644 --- a/Source/Account.h +++ b/Source/Account.h @@ -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 campaignchoices; //statics static std::vector accounts; -- 2.39.5