]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameDraw.cpp
merge
[lugaru.git] / Source / GameDraw.cpp
index 23692b30bac3096fb0d9ce5b3f34f0be5e82a2c7..dd74893d7a9e80aa6b0b1f43e3247113f7eb3f02 100644 (file)
@@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Input.h"
 #include "Awards.h"
 
+#include <dirent.h>
+
 using namespace std;
 
 extern XYZ viewer;
@@ -1433,11 +1435,11 @@ int Game::DrawGLScene(StereoSide side)
 
                        float maxdistance=0;
                        float tempdist;
-                       int whichclosest;
+                       //~ int whichclosest;
                        for(i=0;i<objects.numobjects;i++){
                                tempdist=findDistancefast(&center,&objects.position[i]);
                                if(tempdist>maxdistance){
-                                       whichclosest=i;
+                                       //~ whichclosest=i;
                                        maxdistance=tempdist;
                                }
                        }
@@ -1445,7 +1447,7 @@ int Game::DrawGLScene(StereoSide side)
                                if(!player[i].dead){
                                        tempdist=findDistancefast(&center,&player[i].coords);
                                        if(tempdist>maxdistance){
-                                               whichclosest=i;
+                                               //~ whichclosest=i;
                                                maxdistance=tempdist;
                                        }
                                }
@@ -1996,11 +1998,41 @@ int Game::DrawGLScene(StereoSide side)
        return 0;
 }
 
+vector<string> Game::ListCampaigns() {
+       DIR *campaigns = opendir(ConvertFileName(":Data:Campaigns"));
+       struct dirent *campaign = NULL;
+       if(!campaigns) {
+               perror("Problem while loading campaigns");
+               cerr << "campaign folder was : " << ConvertFileName(":Data:Campaigns") << endl;
+               exit(EXIT_FAILURE);
+       }
+       vector<string> campaignNames;
+       while ((campaign = readdir(campaigns)) != NULL) {
+               string name(campaign->d_name);
+               if(name.length()<5)
+                       continue;
+               if(!name.compare(name.length()-4,4,".txt")) {
+                       campaignNames.push_back(name.substr(0,name.length()-4));
+               }
+       }
+       return campaignNames;
+}
+
 void Game::LoadCampaign() {
-       ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
+       if(!accountactive)
+               return;
+       if(!Mainmenuitems[7]) {
+               ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
+               if(test.good()) {
+                       LoadTexture((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
+               } else {
+                       LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
+               }
+       }
+       ifstream ipstream(ConvertFileName((":Data:Campaigns:"+accountactive->getCurrentCampaign()+".txt").c_str()));
        ipstream.ignore(256,':');
        ipstream >> campaignnumlevels;
-       for(int i=0;i<campaignnumlevels;i++){
+       for(int i=0;i<campaignnumlevels;i++) {
                ipstream.ignore(256,':');
                ipstream.ignore(256,':');
                ipstream.ignore(256,' ');
@@ -2037,12 +2069,10 @@ void Game::LoadCampaign() {
                levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
                levelvisible[levelorder[i+1]]=1;
        }
-       int whichlevelstart = (accountactive?accountactive->getCampaignChoicesMade():0)-1;
+       int whichlevelstart = accountactive->getCampaignChoicesMade()-1;
        if(whichlevelstart<0){
-               if(accountactive) {
-                       accountactive->setCampaignScore(0);
-                       accountactive->resetFasttime();
-               }
+               accountactive->setCampaignScore(0);
+               accountactive->resetFasttime();
                campaignchoicenum=1;
                campaignchoicewhich[0]=0;
        }
@@ -2098,7 +2128,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);
@@ -2333,8 +2363,9 @@ void Game::DrawMenu()
                        starty[9]=10;
                        endy[9]=starty[9]+20;
                }
+               
                if(mainmenu==5){                        
-                       nummenuitems=7+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;
+                       nummenuitems=NB_CAMPAIGN_MENU_ITEM+1+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;
 
                        sprintf (menustring[0], "%s",accountactive->getName());
                        startx[0]=5;
@@ -2371,33 +2402,41 @@ void Game::DrawMenu()
                        endx[5]=startx[5]+strlen(menustring[5])*10;
                        starty[5]=180;
                        endy[5]=starty[5]+20;
+                       
+                       sprintf (menustring[6], "Campaign : %s", accountactive->getCurrentCampaign().c_str());
+                       startx[6]=200;
+                       endx[6]=startx[6]+strlen(menustring[6])*10;
+                       starty[6]=420;
+                       endy[6]=starty[6]+20;
 
                        //World
 
-                       sprintf (menustring[6], "World");
-                       startx[6]=30+120;
-                       starty[6]=30+480-400-50;
-                       endx[6]=startx[6]+400;
-                       endy[6]=30+480-50;
+                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM], "World");
+                       startx[NB_CAMPAIGN_MENU_ITEM]=30+120;
+                       starty[NB_CAMPAIGN_MENU_ITEM]=30+480-400-50;
+                       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[7+i], "%s", campaigndescription[levelorder[i]]);
-                                       startx[7+i]=30+120+campaignlocationx[levelorder[i]]*400/512;
-                                       starty[7+i]=30+30+(512-campaignlocationy[levelorder[i]])*400/512;
-                                       endx[7+i]=startx[7+i]+10;
-                                       endy[7+i]=starty[7+i]+10;
+                                       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;
+                                       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)
+                       if(campaignchoicenum>0) {
                                for(i=(accountactive?accountactive->getCampaignChoicesMade():0);i<(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;i++){
-                                       sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
-                                       startx[7+i]=30+120+campaignlocationx[campaignchoicewhich[i-((accountactive?accountactive->getCampaignChoicesMade():0))]]*400/512;
-                                       starty[7+i]=30+30+(512-campaignlocationy[campaignchoicewhich[i-((accountactive?accountactive->getCampaignChoicesMade():0))]])*400/512;
-                                       endx[7+i]=startx[7+i]+10;
-                                       endy[7+i]=starty[7+i]+10;
+                                       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;
                                }
+                       }
+                       
                }
 
                if(mainmenu==6){                        
@@ -2617,7 +2656,7 @@ void Game::DrawMenu()
        }
 
        if(mainmenu==1||mainmenu==2){
-               nummenuitems=7;
+               nummenuitems=4;
                startx[0]=150;
                starty[0]=480-128;
                endx[0]=150+256;
@@ -2647,46 +2686,16 @@ void Game::DrawMenu()
                        endy[3]=480-306;
                }
 
-               /*startx[4]=150;
-               starty[4]=480-256;
-               endx[4]=150+256;
-               endy[4]=480;
-               */
-               /*if(anim==0){
-                       startx[4]=380;
-                       starty[4]=480-140-256;
-                       endx[4]=380+256;
-                       endy[4]=480-140;
-
-                       startx[5]=145;
-                       starty[5]=480-138-256;
-                       endx[5]=145+256;
-                       endy[5]=480-138;
-
-                       startx[6]=254;
-                       starty[6]=480-144-256;
-                       endx[6]=254+256;
-                       endy[6]=480-144;
-               }*/
        }
 
        selected=-1;
 
-       if(mainmenu==1||mainmenu==2)
-               for(i=1;i<4;i++){
-                       if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
-                               selected=i;
-                       }
-               }
-
-       if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==18)
-               for(i=0;i<nummenuitems;i++){
-                       if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
-                               if(mainmenu!=5)selected=i;
-                               if(mainmenu==5&&(i!=0&&i!=6))selected=i;
-                               if(mainmenu==9&&(i!=numchallengelevels+1))selected=i; // seem useless, if mainmenu==9 then mainmenu!=5, so selected==i.
-                       }
+       for(i=0;i<nummenuitems;i++) {
+               if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]) {
+                       if(mainmenu!=5) selected=i;
+                       else if( (i>0) && (i!=NB_CAMPAIGN_MENU_ITEM) ) selected=i;
                }
+       }
 
        for(i=0;i<nummenuitems;i++){
                if(selected==i) {
@@ -2702,13 +2711,6 @@ void Game::DrawMenu()
                offsety[i]*=.06f;
                offsetx[i]=0;
                offsety[i]=0;
-               if(i>=4&&(mainmenu==1||mainmenu==2)){
-                       selectedlong[i]=0;
-                       offsetx[i]=(startx[i]+endx[i])/2-(640+190)/2;
-                       offsety[i]=(starty[i]+endy[i])/2-(336+150)/2;
-                       offsetx[i]*=.06f;
-                       offsety[i]*=.06f;
-               }
        }
 
        if(mainmenu==1||mainmenu==2){
@@ -2801,8 +2803,6 @@ void Game::DrawMenu()
        glEnable(GL_TEXTURE_2D);
        for(j=0;j<nummenuitems;j++)
        {
-               if(j>3 && (mainmenu==1||mainmenu==2))
-                       continue;
                //glDisable(GL_BLEND);
                glEnable(GL_ALPHA_TEST);
                glEnable(GL_BLEND);
@@ -2830,7 +2830,7 @@ void Game::DrawMenu()
                        glPopMatrix();
                        glEnable(GL_BLEND);
                        //glDisable(GL_ALPHA_TEST);
-                       if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+                       glBlendFunc(GL_SRC_ALPHA,GL_ONE);
                        for(i=0;i<10;i++)
                        {
                                if(1-((float)i)/10-(1-selectedlong[j])>0)
@@ -2854,7 +2854,7 @@ void Game::DrawMenu()
                }
                if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==18)
                {
-                       if(mainmenu!=5||j<6)
+                       if(mainmenu!=5||j<NB_CAMPAIGN_MENU_ITEM)
                        {
                                glColor4f(1,0,0,1);
                                if( (mainmenu==9) && j>accountactive->getProgress() && (j<numchallengelevels) )
@@ -2899,6 +2899,11 @@ void Game::DrawMenu()
                        }
                        else
                        {
+                if(j==NB_CAMPAIGN_MENU_ITEM) {
+                                       //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // black background for the map
+                                       glBlendFunc(GL_SRC_ALPHA,GL_ONE); // no background
+                               }
+
                                glClear(GL_DEPTH_BUFFER_BIT);
                                glEnable(GL_ALPHA_TEST);
                                glAlphaFunc(GL_GREATER, 0.001f);
@@ -2906,7 +2911,7 @@ void Game::DrawMenu()
                                glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
                                glDisable(GL_CULL_FACE);
                                glDisable(GL_LIGHTING);
-                               if(j==6)glColor4f(1,1,1,1);
+                               if(j==NB_CAMPAIGN_MENU_ITEM) glColor4f(1,1,1,1);
                                else glColor4f(1,0,0,1);
 
                                glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
@@ -2921,7 +2926,7 @@ void Game::DrawMenu()
                                                        //Draw world, draw map
                                                        glTranslatef(2,-5,0);
 
-                                                       if(j>6&&j<nummenuitems-1)
+                                                       if(j>NB_CAMPAIGN_MENU_ITEM&&j<nummenuitems-1)
                                                        {
                                                                XYZ linestart,lineend,offset;
                                                                XYZ fac;
@@ -2933,7 +2938,7 @@ void Game::DrawMenu()
                                                                //float linestartx,lineendx,linestarty,lineendy,offsetx,offsety;
                                                                linestart.x=(startx[j]+endx[j])/2;
                                                                linestart.y=(starty[j]+endy[j])/2;
-                                                               if(j>=6+(accountactive?accountactive->getCampaignChoicesMade():0)){
+                                                               if(j>=NB_CAMPAIGN_MENU_ITEM+(accountactive?accountactive->getCampaignChoicesMade():0)){
                                                                        linestart.x=(startx[6+(accountactive?accountactive->getCampaignChoicesMade():0)]+endx[6+(accountactive?accountactive->getCampaignChoicesMade():0)])/2;
                                                                        linestart.y=(starty[6+(accountactive?accountactive->getCampaignChoicesMade():0)]+endy[6+(accountactive?accountactive->getCampaignChoicesMade():0)])/2;
                                                                }
@@ -2946,7 +2951,7 @@ void Game::DrawMenu()
                                                                Normalise(&offset);
                                                                glDisable(GL_TEXTURE_2D);                                                       
 
-                                                               if(j<6+(accountactive?accountactive->getCampaignChoicesMade():0)){
+                                                               if(j<NB_CAMPAIGN_MENU_ITEM+(accountactive?accountactive->getCampaignChoicesMade():0)){
                                                                        glColor4f(0.5,0,0,1);
                                                                        endsize=.5;
                                                                } else {
@@ -2958,7 +2963,7 @@ void Game::DrawMenu()
                                                                linestart+=fac*4*startsize;
                                                                lineend-=fac*4*endsize;
 
-                                                               if(!(j>7+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum)){
+                                                               if(!(j>NB_CAMPAIGN_MENU_ITEM+1+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum)){
                                                                        glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
                                                                        glPushMatrix();
                                                                                glBegin(GL_QUADS);
@@ -2977,21 +2982,24 @@ void Game::DrawMenu()
                                                        }
 
 
-                                                       if(j==6)glBindTexture( GL_TEXTURE_2D, Mainmenuitems[7]);
+                                                       if(j==NB_CAMPAIGN_MENU_ITEM) glBindTexture( GL_TEXTURE_2D, Mainmenuitems[7]);
                                                        else glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
                                                        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
                                                        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
-                                                       if(j-7<(accountactive?accountactive->getCampaignChoicesMade():0))glColor4f(0.5,0,0,1);
-                                                       if(j-7>=(accountactive?accountactive->getCampaignChoicesMade():0))glColor4f(1,0,0,1);
-                                                       if(j==6)glColor4f(1,1,1,1);
+                                                       if(j-NB_CAMPAIGN_MENU_ITEM-1 < (accountactive?accountactive->getCampaignChoicesMade():0)) glColor4f(0.5,0,0,1);
+                                                       if(j-NB_CAMPAIGN_MENU_ITEM-1 >= (accountactive?accountactive->getCampaignChoicesMade():0)) glColor4f(1,0,0,1);
+                                                       if(j==NB_CAMPAIGN_MENU_ITEM) glColor4f(1,1,1,1);
                                                        XYZ midpoint;
                                                        float itemsize;
                                                        itemsize=abs(startx[j]-endx[j])/2;
                                                        midpoint=0;
                                                        midpoint.x=(startx[j]+endx[j])/2;
                                                        midpoint.y=(starty[j]+endy[j])/2;
-                                                       if(j>6&&(j-7<(accountactive?accountactive->getCampaignChoicesMade():0)))itemsize*=.5;
-                                                       if(!(j-7>(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum))
+                                                       if      (j>NB_CAMPAIGN_MENU_ITEM &&
+                                                               (j-NB_CAMPAIGN_MENU_ITEM-1 < (accountactive?accountactive->getCampaignChoicesMade():0))) {
+                                                                       itemsize*=.5;
+                                                       }
+                                                       if(!(j-NB_CAMPAIGN_MENU_ITEM-1 > (accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum))
                                                        {
                                                                glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
                                                                glPushMatrix();
@@ -3008,7 +3016,7 @@ void Game::DrawMenu()
                                                                glPopMatrix();
                                                                glEnable(GL_BLEND);
                                                                //glDisable(GL_ALPHA_TEST);
-                                                               if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
+                                                               if(j<4) glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Black is transparent
                                                                for(i=0;i<10;i++)
                                                                {
                                                                        if(1-((float)i)/10-(1-selectedlong[j])>0)
@@ -3036,7 +3044,7 @@ void Game::DrawMenu()
                                glPopMatrix();
                                glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
 
-                               if(j-7>=(accountactive?accountactive->getCampaignChoicesMade():0)){
+                               if(j-NB_CAMPAIGN_MENU_ITEM-1>=(accountactive?accountactive->getCampaignChoicesMade():0)){
                                        text.glPrintOutlined(0.9,0,0,startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
                                        glDisable(GL_DEPTH_TEST);
                                }
@@ -3048,8 +3056,8 @@ void Game::DrawMenu()
        glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
        glPopMatrix();
 
-               if(mainmenu==1||mainmenu==2)
-                       //if(transition<.1||transition>.9){
+               if(mainmenu==1||mainmenu==2) {
+                       //if(transition<.1||transition>.9) {
                                glClear(GL_DEPTH_BUFFER_BIT);
                                glEnable(GL_ALPHA_TEST);
                                glAlphaFunc(GL_GREATER, 0.001f);
@@ -3077,6 +3085,7 @@ void Game::DrawMenu()
                                        glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
                                glPopMatrix();
                        //}
+               }
 
                glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
                glPushMatrix();                                                                         // Store The Projection Matrix