From: Côme BERNIGAUD Date: Tue, 10 May 2011 22:31:04 +0000 (+0200) Subject: first modifications in order to support multiple campaign. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=2cd28eb24fc1b4011511b6c3ed8c025bfc74de4d;p=lugaru.git first modifications in order to support multiple campaign. --- diff --git a/Source/Account.cpp b/Source/Account.cpp index 145dea1..45e1300 100644 --- a/Source/Account.cpp +++ b/Source/Account.cpp @@ -40,10 +40,8 @@ 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; + + currentCampaign = "main"; } Account* Account::add(string name) { @@ -78,15 +76,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) { @@ -117,23 +115,40 @@ 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(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++) { @@ -180,17 +195,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++) { diff --git a/Source/Account.h b/Source/Account.h index 24b856f..acd2850 100644 --- a/Source/Account.h +++ b/Source/Account.h @@ -25,8 +25,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#include #include +typedef struct { + float highscore; + float fasttime; + float score; + float time; + std::vector choices; +} campaign_progress_t; class Account { public: @@ -46,22 +54,22 @@ class Account { int getDifficulty(); void setDifficulty(int i) { difficulty = i; }; const char* getName() { return name.c_str(); }; - float getCampaignScore() { return campaignscore; }; - int getCampaignChoicesMade() { return campaignchoices.size(); }; - int getCampaignChoice(int i) { return campaignchoices[i]; }; + float getCampaignScore() { return campaignProgress[currentCampaign].score; }; + int getCampaignChoicesMade() { return campaignProgress[currentCampaign].choices.size(); }; + int getCampaignChoice(int i) { return campaignProgress[currentCampaign].choices[i]; }; void setCampaignScore(int s) { - campaignscore=s; - if(s>campaignhighscore) - campaignhighscore=s; + campaignProgress[currentCampaign].score=s; + if(s>campaignProgress[currentCampaign].highscore) + campaignProgress[currentCampaign].highscore=s; }; void setCampaignFinalTime(float t) { - campaigntime = t; - if((t campaignchoices; + + std::string currentCampaign; + std::map campaignProgress; //statics static std::vector accounts; diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 855c87e..70b6716 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -2098,7 +2098,7 @@ void Game::DrawMenu() oldmainmenu=mainmenu; - if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==119||mainmenu==18){ + if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==18){ glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.001f); diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 273c7f6..e595805 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -5936,10 +5936,10 @@ void Game::Tick(){ if(mainmenu==0&&!winfreeze) mainmenu=2; //pause else if(mainmenu==0&&winfreeze&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1){ - mainmenu=100; + mainmenu=100; // play menu sound and go to menu 5. gameon=0; winfreeze=0; - }else if(mainmenu==1||mainmenu==2) + } else if(mainmenu==1||mainmenu==2) mainmenu=0; //unpause //play menu theme if(musictoggle&&(mainmenu==1||mainmenu==2||mainmenu==100)){ diff --git a/Source/Settings.cpp b/Source/Settings.cpp index 52ecbeb..284baf4 100644 --- a/Source/Settings.cpp +++ b/Source/Settings.cpp @@ -151,7 +151,7 @@ bool LoadSettings(Game &game) { // skip blank lines // assume lines starting with spaces are all blank if ( strlen(setting) == 0 || setting[0] == ' ' || setting[0] == '\t') continue; - printf("setting : %s\n",setting); + //~ printf("setting : %s\n",setting); if ( ipstream.eof() || ipstream.fail() ) { fprintf(stderr, "Error reading config file: Got setting name '%s', but value can't be read\n", setting);