X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FAccount.cpp;h=1388b7e0e281e4d1fa4e57ef3b0295f2a311c72e;hb=5f49519e5b1863ad4fe169e42fd6889a6d17d2aa;hp=145dea1bdf9cc7ee1dfef1c0f037780637f52dd6;hpb=54cbb28b51da68b2280068a41e7964f78dec6858;p=lugaru.git diff --git a/Source/Account.cpp b/Source/Account.cpp index 145dea1..1388b7e 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,18 @@ 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; + if(campaignProgress.find(name)==campaignProgress.end()) { + campaignProgress[name].highscore = 0; + campaignProgress[name].fasttime = 0; + campaignProgress[name].score = 0; + campaignProgress[name].time = 0; + } } Account* Account::add(string name) { @@ -78,15 +86,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 +112,6 @@ Account* Account::loadFile(string filename) { FILE *tfile; int numaccounts; int accountactive; - int j; tfile=fopen(ConvertFileName(filename.c_str()), "rb" ); @@ -117,37 +124,54 @@ 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); } + 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 +204,28 @@ 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->campaignchoices[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, "Bf", a->points); for(j=0;j<50;j++) {