]> git.jsancho.org Git - lugaru.git/commitdiff
first modifications in order to support multiple campaign.
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Tue, 10 May 2011 22:31:04 +0000 (00:31 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Tue, 10 May 2011 22:31:04 +0000 (00:31 +0200)
Source/Account.cpp
Source/Account.h
Source/GameDraw.cpp
Source/GameTick.cpp
Source/Settings.cpp

index 145dea1bdf9cc7ee1dfef1c0f037780637f52dd6..45e1300e68c827c6dccf45fbe5f5900cb5827b1c 100644 (file)
@@ -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<campaignchoicesmade;j++)
-                       {
-                               funpackf(tfile, "Bi", &campaignchoice);
-                               if (campaignchoice >= 10) // what is that for?
+                       int nbCampaigns;
+                       funpackf(tfile, "Bi", &nbCampaigns);
+                       printf("loading %d campaign progress info\n",nbCampaigns);
+                       
+                       for(int k=0;k<nbCampaigns;++k) {
+                               string campaignName = "";
+                               int t;
+                               char c;
+                               funpackf(tfile, "Bi",  &t);
+                               for(j=0;j<t;j++)
                                {
-                                       campaignchoice = 0;
+                                       funpackf(tfile, "Bb",  &c);
+                                       campaignName.append(1,c);
+                               }
+                               printf("loading %s campaign progress info\n",campaignName.c_str());
+                               funpackf(tfile, "Bf", &(acc->campaignProgress[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<campaignchoicesmade;j++)
+                               {
+                                       funpackf(tfile, "Bi", &campaignchoice);
+                                       if (campaignchoice >= 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;j<a->getCampaignChoicesMade();j++)
-                       {
-                               fpackf(tfile, "Bi", a->campaignchoices[j]);
+                       fpackf(tfile, "Bi", a->campaignProgress.size());
+                       
+                       map<string,campaign_progress_t>::const_iterator it;
+                       for( it=a->campaignProgress.begin(); it!= a->campaignProgress.end(); ++it) {
+                               fpackf(tfile, "Bi",  it->first.size());
+                               for(j=0;j<it->first.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;j<it->second.choices.size();j++)
+                               {
+                                       fpackf(tfile, "Bi", it->second.choices[j]);
+                               }
                        }
+                       
                        fpackf(tfile, "Bf", a->points);
                        for(j=0;j<50;j++)
                        {
index 24b856fbfb2c513b13df1a11964bd1f882ae43f4..acd285061266b722d939bd3146425f65a36b21d8 100644 (file)
@@ -25,8 +25,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <vector>
 #include <string>
+#include <map>
 #include <fstream>
 
+typedef struct {
+       float highscore;
+       float fasttime;
+       float score;
+       float time;
+       std::vector<int> 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<campaignfasttime) || (campaignfasttime==0) && (t!=0))
-                                       campaignfasttime = t;
+                               campaignProgress[currentCampaign].time = t;
+                               if((t<campaignProgress[currentCampaign].fasttime) || (campaignProgress[currentCampaign].fasttime==0) && (t!=0))
+                                       campaignProgress[currentCampaign].fasttime = t;
                };
-               float getCampaignFasttime() { return campaignfasttime; };
-               void resetFasttime() { campaignfasttime = 0; };
-               float getCampaignHighScore() { return campaignhighscore; };
+               float getCampaignFasttime() { return campaignProgress[currentCampaign].fasttime; };
+               void resetFasttime() { campaignProgress[currentCampaign].fasttime = 0; };
+               float getCampaignHighScore() { return campaignProgress[currentCampaign].highscore; };
                float getHighScore(int i) { return highscore[i]; };
                float getFastTime(int i) { return fasttime[i]; };
                int getProgress() { return progress; };
@@ -70,17 +78,15 @@ class Account {
        private:
                Account(std::string n="");
                int difficulty;
-               int progress;
+               int progress; // progress in challenge levels
                float points;
                float highscore[50];
                float fasttime[50];
                bool unlocked[60];
                std::string name;
-               float campaignhighscore;
-               float campaignfasttime;
-               float campaignscore;
-               float campaigntime;
-               std::vector<int> campaignchoices;
+               
+               std::string currentCampaign;
+               std::map<std::string,campaign_progress_t> campaignProgress;
        
        //statics
                static std::vector<Account*> accounts;
index 855c87eb794e408e556bc6ad454952947318eed9..70b6716c177561b4c5e70ec1db3fd21acacf674f 100644 (file)
@@ -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);
index 273c7f6d64c5411d49125def785bfccf8cb2897a..e59580515b3008bc990985954ad11bb43b84fa9c 100644 (file)
@@ -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)){
index 52ecbebb4eac4266bcb05ce942156d400d651f07..284baf47fee87a90e732d7ed37a4ef72ef07e737 100644 (file)
@@ -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);