]> git.jsancho.org Git - lugaru.git/commitdiff
little cleanup about campaign level handling
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Sat, 14 May 2011 04:08:23 +0000 (06:08 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Sat, 14 May 2011 04:08:23 +0000 (06:08 +0200)
Source/Game.cpp
Source/Game.h
Source/GameDraw.cpp
Source/GameTick.cpp

index 723396bd197b1370da05131663fdf5214020cb2a..a441e0cd9f8fc78a212d57fd4816be7c84e44fcd 100644 (file)
@@ -114,17 +114,8 @@ Game::Game()
        memset(campaignlocationy, 0, sizeof(campaignlocationy));
        memset(campaignlocationy, 0, sizeof(campaignlocationy));
 
-       campaignchoicenum = 0;
-
-       memset(campaignchoicewhich, 0, sizeof(campaignchoicewhich));
-
        whichchoice = 0;
-
-       numlevelspassed = 0;
-
-       memset(levelorder, 0, sizeof(levelorder));
-       memset(levelvisible, 0, sizeof(levelvisible));
-       memset(levelhighlight, 0, sizeof(levelhighlight));
+       actuallevel = 0;
 
        minimap = 0;
 
index 32d14890b9f1b2f79fe3a0bbfca12f18291904e4..97e3487d61dcabda13282b8e0fa7bc9616230bf1 100644 (file)
@@ -139,18 +139,12 @@ class Game
                char campaignmapname[50][256];
                char campaigndescription[50][256];
                int campaignchoosenext[50];
-               int campaignnumnext[50]; // Set this to 0 on final level. As David said: he meant to add story branching, but he eventually hadn't. 
+               int campaignnumnext[50]; // 0 on final level. As David said: he meant to add story branching, but he eventually hadn't. 
                int campaignnextlevel[50][10];
                int campaignlocationx[50];
                int campaignlocationy[50];
-               int campaignchoicenum;
-               int campaignchoicewhich[10];
                int whichchoice;
-
-               int numlevelspassed;
-               int levelorder[5000];
-               int levelvisible[50];
-               int levelhighlight[50];
+               int actuallevel;
 
                bool minimap;
 
index b4f6ee715f3a97f963228ad47c6fdb86fd6690c4..2795bd75b159eb39152747bdf3224d3dadbd34b0 100644 (file)
@@ -2021,14 +2021,6 @@ vector<string> Game::ListCampaigns() {
 void Game::LoadCampaign() {
        if(!accountactive)
                return;
-       if(!Mainmenuitems[7]) {
-               ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
-               if(test.good()) {
-                       LoadTextureData((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
-               } else {
-                       LoadTextureData(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
-               }
-       }
        ifstream ipstream(ConvertFileName((":Data:Campaigns:"+accountactive->getCurrentCampaign()+".txt").c_str()));
        ipstream.ignore(256,':');
        ipstream >> campaignnumlevels;
@@ -2058,32 +2050,18 @@ void Game::LoadCampaign() {
        }
        ipstream.close();
 
-       for(int i=0;i<campaignnumlevels;i++){
-               levelvisible[i]=0;
-               levelhighlight[i]=0;
+       if(!Mainmenuitems[7]) {
+               ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
+               if(test.good()) {
+                       LoadTextureData((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
+               } else {
+                       LoadTextureData(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
+               }
        }
 
-       levelorder[0]=0;
-       levelvisible[0]=1;
-       for(int i=0;i<accountactive->getCampaignChoicesMade();i++){
-               levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
-               levelvisible[levelorder[i+1]]=1;
-       }
-       int whichlevelstart = accountactive->getCampaignChoicesMade()-1;
-       if(whichlevelstart<0){
+       if(accountactive->getCampaignChoicesMade()==0) {
                accountactive->setCampaignScore(0);
                accountactive->resetFasttime();
-               campaignchoicenum=1;
-               campaignchoicewhich[0]=0;
-       }
-       else
-       {
-               campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
-               for(int i=0;i<campaignchoicenum;i++){
-                       campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
-                       levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                       levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-               }
        }
 }
 
@@ -2364,7 +2342,7 @@ void Game::DrawMenu() {
                }
                
                if(mainmenu==5){                        
-                       nummenuitems=NB_CAMPAIGN_MENU_ITEM+1+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;
+                       nummenuitems=NB_CAMPAIGN_MENU_ITEM+1+accountactive->getCampaignChoicesMade()+(accountactive->getCampaignChoicesMade()>0?campaignnumnext[accountactive->getCampaignChoicesMade()-1]:1);
 
                        sprintf (menustring[0], "%s",accountactive->getName());
                        startx[0]=5;
@@ -2416,24 +2394,28 @@ void Game::DrawMenu() {
                        endx[NB_CAMPAIGN_MENU_ITEM]=startx[NB_CAMPAIGN_MENU_ITEM]+400;
                        endy[NB_CAMPAIGN_MENU_ITEM]=30+480-50;
 
-                       if((accountactive?accountactive->getCampaignChoicesMade():0)) {
-                               for(i=0;i<(accountactive?accountactive->getCampaignChoicesMade():0);i++) {
-                                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+i], "%s", campaigndescription[levelorder[i]]);
-                                       startx[NB_CAMPAIGN_MENU_ITEM+1+i]=30+120+campaignlocationx[levelorder[i]]*400/512;
-                                       starty[NB_CAMPAIGN_MENU_ITEM+1+i]=30+30+(512-campaignlocationy[levelorder[i]])*400/512;
+                       if(accountactive->getCampaignChoicesMade()) {
+                               for(i=0;i<accountactive->getCampaignChoicesMade();i++) {
+                                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+i], "%s", campaigndescription[i]);
+                                       startx[NB_CAMPAIGN_MENU_ITEM+1+i]=30+120+campaignlocationx[i]*400/512;
+                                       starty[NB_CAMPAIGN_MENU_ITEM+1+i]=30+30+(512-campaignlocationy[i])*400/512;
                                        endx[NB_CAMPAIGN_MENU_ITEM+1+i]=startx[NB_CAMPAIGN_MENU_ITEM+1+i]+10;
                                        endy[NB_CAMPAIGN_MENU_ITEM+1+i]=starty[NB_CAMPAIGN_MENU_ITEM+1+i]+10;
                                }
-                       }
-
-                       if(campaignchoicenum>0) {
-                               for(i=(accountactive?accountactive->getCampaignChoicesMade():0);i<(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;i++){
-                                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+i], "%s", campaigndescription[levelorder[i]]);
-                                       startx[NB_CAMPAIGN_MENU_ITEM+1+i]=30+120+campaignlocationx[campaignchoicewhich[i-((accountactive?accountactive->getCampaignChoicesMade():0))]]*400/512;
-                                       starty[NB_CAMPAIGN_MENU_ITEM+1+i]=30+30+(512-campaignlocationy[campaignchoicewhich[i-((accountactive?accountactive->getCampaignChoicesMade():0))]])*400/512;
-                                       endx[NB_CAMPAIGN_MENU_ITEM+1+i]=startx[NB_CAMPAIGN_MENU_ITEM+1+i]+10;
-                                       endy[NB_CAMPAIGN_MENU_ITEM+1+i]=starty[NB_CAMPAIGN_MENU_ITEM+1+i]+10;
+                               for(i=0;i<campaignnumnext[accountactive->getCampaignChoicesMade()-1];i++) {
+                                       int j = campaignnextlevel[accountactive->getCampaignChoicesMade()-1][i];
+                                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+j], "%s", campaigndescription[j]);
+                                       startx[NB_CAMPAIGN_MENU_ITEM+1+j]=30+120+campaignlocationx[j]*400/512;
+                                       starty[NB_CAMPAIGN_MENU_ITEM+1+j]=30+30+(512-campaignlocationy[j])*400/512;
+                                       endx[NB_CAMPAIGN_MENU_ITEM+1+j]=startx[NB_CAMPAIGN_MENU_ITEM+1+j]+10;
+                                       endy[NB_CAMPAIGN_MENU_ITEM+1+j]=starty[NB_CAMPAIGN_MENU_ITEM+1+j]+10;
                                }
+                       } else {
+                               sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1], "%s", campaigndescription[0]);
+                               startx[NB_CAMPAIGN_MENU_ITEM+1]=30+120+campaignlocationx[0]*400/512;
+                               starty[NB_CAMPAIGN_MENU_ITEM+1]=30+30+(512-campaignlocationy[0])*400/512;
+                               endx[NB_CAMPAIGN_MENU_ITEM+1]=startx[NB_CAMPAIGN_MENU_ITEM+1]+10;
+                               endy[NB_CAMPAIGN_MENU_ITEM+1]=starty[NB_CAMPAIGN_MENU_ITEM+1]+10;
                        }
                        
                }
@@ -2950,7 +2932,7 @@ void Game::DrawMenu() {
                                                                Normalise(&offset);
                                                                glDisable(GL_TEXTURE_2D);                                                       
 
-                                                               if(j<NB_CAMPAIGN_MENU_ITEM+(accountactive?accountactive->getCampaignChoicesMade():0)){
+                                                               if(j<NB_CAMPAIGN_MENU_ITEM+accountactive->getCampaignChoicesMade()){
                                                                        glColor4f(0.5,0,0,1);
                                                                        endsize=.5;
                                                                } else {
@@ -2962,7 +2944,7 @@ void Game::DrawMenu() {
                                                                linestart+=fac*4*startsize;
                                                                lineend-=fac*4*endsize;
 
-                                                               if(!(j>NB_CAMPAIGN_MENU_ITEM+1+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum)){
+                                                               //~ if(!(j>NB_CAMPAIGN_MENU_ITEM+1+accountactive->getCampaignChoicesMade()+campaignchoicenum)){
                                                                        glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
                                                                        glPushMatrix();
                                                                                glBegin(GL_QUADS);
@@ -2976,7 +2958,7 @@ void Game::DrawMenu() {
                                                                                glVertex3f(lineend.x-offset.x*endsize,          lineend.y-offset.y*endsize, 0.0f);
                                                                                glEnd();
                                                                        glPopMatrix();
-                                                               }
+                                                               //~ }
                                                                glEnable(GL_TEXTURE_2D);
                                                        }
 
@@ -2995,11 +2977,11 @@ void Game::DrawMenu() {
                                                        midpoint.x=(startx[j]+endx[j])/2;
                                                        midpoint.y=(starty[j]+endy[j])/2;
                                                        if      (j>NB_CAMPAIGN_MENU_ITEM &&
-                                                               (j-NB_CAMPAIGN_MENU_ITEM-1 < (accountactive?accountactive->getCampaignChoicesMade():0))) {
+                                                               (j-NB_CAMPAIGN_MENU_ITEM-1 < accountactive->getCampaignChoicesMade())) {
                                                                        itemsize*=.5;
                                                        }
-                                                       if(!(j-NB_CAMPAIGN_MENU_ITEM-1 > (accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum))
-                                                       {
+                                                       //~ if(!(j-NB_CAMPAIGN_MENU_ITEM-1 > accountactive->getCampaignChoicesMade()+campaignnumnext[accountactive->getCampaignChoicesMade()]))
+                                                       //~ {
                                                                glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
                                                                glPushMatrix();
                                                                        glBegin(GL_QUADS);
@@ -3036,7 +3018,7 @@ void Game::DrawMenu() {
                                                                                glPopMatrix();
                                                                        }
                                                                }
-                                                       }
+                                                       //~ }
                                                glPopMatrix();
                                        glPopMatrix();
                                        glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
index 5b635c75db4e9abd4ae531a1d1ef4363ab60a784..4cae8b1415cc0eacc038c8ca4d45c26aa45d11f7 100644 (file)
@@ -5612,9 +5612,10 @@ void Game::MenuTick(){
                                        else
                                                LoadStuff();
                                        whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-1-accountactive->getCampaignChoicesMade();
+                                       actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignnextlevel[accountactive->getCampaignChoicesMade()-1][whichchoice]:0);
                                        visibleloading=1;
                                        stillloading=1;
-                                       Loadlevel(campaignmapname[campaignchoicewhich[whichchoice]]);
+                                       Loadlevel(campaignmapname[actuallevel]);
                                        campaign=1;
                                        mainmenu=0;
                                        gameon=1;
@@ -5870,13 +5871,13 @@ void Game::Tick(){
                if(mainmenu&&endgame==1)
             mainmenu=10;
         //go to level select after completing a campaign level
-        if(campaign&&winfreeze&&mainmenu==0&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1) {
+        if(campaign&&winfreeze&&mainmenu==0&&campaignchoosenext[actuallevel]==1) {
             mainmenu=5;
             gameon=0;
             winfreeze=0;
             fireSound();
             flash();
-            if(musictoggle){
+            if(musictoggle) {
                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
                 emit_stream_np(stream_menutheme);
                 pause_sound(leveltheme);
@@ -7698,7 +7699,7 @@ void Game::TickOnceAfter(){
 
                                        fireSound(firestartsound);
 
-                                       Loadlevel(campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);
+                                       Loadlevel(campaignmapname[accountactive->getCampaignChoicesMade()]);
 
                                        fireSound();
 
@@ -7732,11 +7733,11 @@ void Game::TickOnceAfter(){
                 // 0 = load next level
                 // 1 = go back to level select screen
                 // 2 = stealthload next level
-                               if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
-                                       if(campaignnumnext[campaignchoicewhich[whichchoice]]==0)
+                               if(mainmenu==0&&winfreeze&&(campaignchoosenext[actuallevel])==1){
+                                       if(campaignnumnext[actuallevel]==0)
                                                endgame=1;
                                } else if(mainmenu==0&&winfreeze) {
-                                       stealthloading = (campaignchoosenext[campaignchoicewhich[whichchoice]]==2);
+                                       stealthloading = (campaignchoosenext[actuallevel]==2);
 
                                        if(!stealthloading){
                                                fireSound(firestartsound);
@@ -7754,9 +7755,10 @@ void Game::TickOnceAfter(){
                                        if(!firstload)
                                                LoadStuff();
                                        whichchoice=0;
+                                       actuallevel=campaignnextlevel[actuallevel][0];
                                        visibleloading=1;
                                        stillloading=1;
-                                       Loadlevel(campaignmapname[campaignchoicewhich[0]]);
+                                       Loadlevel(campaignmapname[actuallevel]);
                                        campaign=1;
                                        mainmenu=0;
                                        gameon=1;