X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FAccount.cpp;h=7eba58815332e28c4edda56ca0be8fd99c7a7c87;hb=8afdcba610cded0e54b85069ba051268b29669a6;hp=145dea1bdf9cc7ee1dfef1c0f037780637f52dd6;hpb=ac1f817a1133a0b81029430c40aab3c047cb7d7c;p=lugaru.git diff --git a/Source/Account.cpp b/Source/Account.cpp index 145dea1..7eba588 100644 --- a/Source/Account.cpp +++ b/Source/Account.cpp @@ -32,7 +32,7 @@ extern bool debugmode; vector Account::accounts = vector(); -Account::Account(string n) { +Account::Account(string n) : campaignProgress() { name = string(n); difficulty = 0; progress = 0; @@ -40,10 +40,12 @@ Account::Account(string n) { memset(highscore, 0, sizeof(highscore)); memset(fasttime, 0, sizeof(fasttime)); memset(unlocked, 0, sizeof(unlocked)); - campaignhighscore = 0; - campaignfasttime = 0; - campaignscore = 0; - campaigntime = 0; + + setCurrentCampaign("main"); +} + +void Account::setCurrentCampaign(string name) { + currentCampaign = name; } Account* Account::add(string name) { @@ -69,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(); } @@ -78,15 +80,15 @@ int Account::getDifficulty() { } void Account::endGame() { - campaignchoices.clear(); - campaignscore=0; - campaigntime=0; + campaignProgress[currentCampaign].choices.clear(); + campaignProgress[currentCampaign].score=0; + campaignProgress[currentCampaign].time=0; } void Account::winCampaignLevel(int choice, float score, float time) { - campaignchoices.push_back(choice); - setCampaignScore(campaignscore+score); - campaigntime = 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) { @@ -104,7 +106,6 @@ Account* Account::loadFile(string filename) { FILE *tfile; int numaccounts; int accountactive; - int j; tfile=fopen(ConvertFileName(filename.c_str()), "rb" ); @@ -117,37 +118,64 @@ Account* Account::loadFile(string filename) { { printf("loading account %d/%d\n",i,numaccounts); Account* acc = new Account(); - funpackf(tfile, "Bf", &(acc->campaigntime)); - funpackf(tfile, "Bf", &(acc->campaignscore)); - funpackf(tfile, "Bf", &(acc->campaignfasttime)); - funpackf(tfile, "Bf", &(acc->campaignhighscore)); funpackf(tfile, "Bi", &(acc->difficulty)); funpackf(tfile, "Bi", &(acc->progress)); - int campaignchoicesmade,campaignchoice; - funpackf(tfile, "Bi", &campaignchoicesmade); - for(j=0;j= 10) // what is that for? + int nbCampaigns; + funpackf(tfile, "Bi", &nbCampaigns); + printf("loading %d campaign progress info\n",nbCampaigns); + + for(int k=0;kcampaignProgress[campaignName].time)); + funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].score)); + funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].fasttime)); + funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].highscore)); + int campaignchoicesmade,campaignchoice; + funpackf(tfile, "Bi", &campaignchoicesmade); + for(int j=0;j= 10) // what is that for? + { + campaignchoice = 0; + } + acc->campaignProgress[campaignName].choices.push_back(campaignchoice); } - acc->campaignchoices.push_back(campaignchoice); } + + acc->currentCampaign = ""; + int t; + char c; + funpackf(tfile, "Bi", &t); + for(int i=0;icurrentCampaign.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;jname.append(1,ctemp); @@ -180,17 +208,34 @@ void Account::saveFile(string filename, Account* accountactive) { { Account* a = Account::get(i); printf("writing account %d/%d (%s)\n",i+1,getNbAccounts(),a->getName()); - fpackf(tfile, "Bf", a->campaigntime); - fpackf(tfile, "Bf", a->campaignscore); - fpackf(tfile, "Bf", a->campaignfasttime); - fpackf(tfile, "Bf", a->campaignhighscore); fpackf(tfile, "Bi", a->difficulty); fpackf(tfile, "Bi", a->progress); - fpackf(tfile, "Bi", a->getCampaignChoicesMade()); - for(j=0;jgetCampaignChoicesMade();j++) + fpackf(tfile, "Bi", a->campaignProgress.size()); + + map::const_iterator it; + for( it=a->campaignProgress.begin(); it!= a->campaignProgress.end(); ++it) { + fpackf(tfile, "Bi", it->first.size()); + for(j=0;jfirst.size();j++) + { + fpackf(tfile, "Bb", it->first[j]); + } + fpackf(tfile, "Bf", it->second.time); + fpackf(tfile, "Bf", it->second.score); + fpackf(tfile, "Bf", it->second.fasttime); + fpackf(tfile, "Bf", it->second.highscore); + fpackf(tfile, "Bi", it->second.choices.size()); + for(j=0;jsecond.choices.size();j++) + { + fpackf(tfile, "Bi", it->second.choices[j]); + } + } + + fpackf(tfile, "Bi", a->getCurrentCampaign().size()); + for(j=0;jgetCurrentCampaign().size();j++) { - fpackf(tfile, "Bi", a->campaignchoices[j]); + fpackf(tfile, "Bb", a->getCurrentCampaign()[j]); } + fpackf(tfile, "Bf", a->points); for(j=0;j<50;j++) {