]> git.jsancho.org Git - lugaru.git/commitdiff
The game now supports multiple campaigns!
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Wed, 11 May 2011 19:25:08 +0000 (21:25 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Wed, 11 May 2011 19:25:08 +0000 (21:25 +0200)
Source/Game.h
Source/GameDraw.cpp
Source/GameTick.cpp

index 337b0bfe71f82fa6986559ef995872705a2ccde2..70fdb9271fce172e39bfef49951f5ba65a8b8458 100644 (file)
@@ -59,6 +59,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Account.h"
 #include "Sounds.h"
 
+#define NB_CAMPAIGN_MENU_ITEM 7
+
 extern GLuint rabbittexture;
 
 struct TextureInfo;
@@ -221,6 +223,7 @@ class Game
                void LoadStuff();
                void LoadingScreen();
                void LoadCampaign();
+               static std::vector<std::string> ListCampaigns();
                void FadeLoadingScreen(float howmuch);
                void Dispose();
                int DrawGLScene(StereoSide side);
index 7fe9f199164961f1cc22b12419979caa67ffed23..6031cf5f21a8387db64c7a7079562adefa1f807d 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;
@@ -1996,6 +1998,26 @@ 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() {
        if(!accountactive)
                return;
@@ -2335,7 +2357,7 @@ void Game::DrawMenu()
                }
                
                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;
@@ -2372,33 +2394,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]=100;
+                       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){                        
@@ -2655,7 +2685,7 @@ void Game::DrawMenu()
        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!=6) ) selected=i;
+                       else if( (i>0) && (i!=NB_CAMPAIGN_MENU_ITEM) ) selected=i;
                }
        }
 
@@ -2816,7 +2846,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) )
@@ -2861,7 +2891,7 @@ void Game::DrawMenu()
                        }
                        else
                        {
-                if(j==6) {
+                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
                                }
@@ -2873,8 +2903,8 @@ 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);
-                               else glColor4f(1,0,0,1);ss
+                               if(j==NB_CAMPAIGN_MENU_ITEM) glColor4f(1,1,1,1);
+                               else glColor4f(1,0,0,1);
 
                                glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
                                glPushMatrix();                                                                         // Store The Projection Matrix
@@ -2888,7 +2918,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;
@@ -2900,7 +2930,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;
                                                                }
@@ -2913,7 +2943,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 {
@@ -2925,7 +2955,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);
@@ -2944,21 +2974,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();
@@ -2975,7 +3008,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)
@@ -3003,7 +3036,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);
                                }
@@ -3015,8 +3048,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);
@@ -3044,6 +3077,7 @@ void Game::DrawMenu()
                                        glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
                                glPopMatrix();
                        //}
+               }
 
                glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
                glPushMatrix();                                                                         // Store The Projection Matrix
index c9e3a9691ff0aca2851ebe9c47d0bd5df776d0f3..df85211eacfffc298c29c599170ed9201a5a6ff0 100644 (file)
@@ -36,6 +36,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Animation.h"
 #include "Awards.h"
 
+#include <algorithm>
+
 using namespace std;
 
 // Added more evilness needed for MSVC
@@ -2113,438 +2115,57 @@ void Game::Loadlevel(const char *name){
        visibleloading=0;
 }
 
-/*
-Values of mainmenu :
-1 Main menu
-2 Menu pause (resume/end game)
-3 Option menu
-4 Controls configuration menu
-5 Main game menu (choose level or challenge)
-6 Deleting user menu
-7 User managment menu (select/add)
-8 Choose difficulty menu
-9 Challenge level selection menu
-10 End of the campaign congratulation (is that really a menu?)
-11 Same that 9 ??? => unused
-18 stereo configuration
-*/
-    
-void Game::MenuTick(){
-    //menu buttons
-    
-    // some specific case where we do something even if the left mouse button is not pressed.
-       if((mainmenu==5) && (endgame==2)) {
-               accountactive->endGame();
-               endgame=0;
-       }
-       if(mainmenu==10)
-               endgame=2;
-       if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
-               stereoseparation-=0.001;
-               
-    if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
-               switch(mainmenu) {
-                       case 1:
-                       case 2:
-                               switch(selected) {
-                                       case 1:
-                                               if(gameon) { //resume
-                                                       mainmenu=0;
-                                                       pause_sound(stream_menutheme);
-                                                       resume_stream(leveltheme);
-                                               } else { //new game
-                                                       fireSound(firestartsound);
-                                                       flash();
-                                                       mainmenu=(accountactive?5:7);
-                                                       selected=-1;
-                                               }
-                                               break;
-                                       case 2: //options
-                                               fireSound();
-                                               flash();
-                                               mainmenu=3;
-                                               if(newdetail>2) newdetail=detail;
-                                               if(newdetail<0) newdetail=detail;
-                                               if(newscreenwidth>3000) newscreenwidth=screenwidth;
-                                               if(newscreenwidth<0) newscreenwidth=screenwidth;
-                                               if(newscreenheight>3000) newscreenheight=screenheight;
-                                               if(newscreenheight<0) newscreenheight=screenheight;
-                                               break;
-                                       case 3:
-                                               fireSound();
-                                               flash();
-                                               if(gameon){ //end game
-                                                       gameon=0;
-                                                       mainmenu=1;
-                                               } else { //quit
-                                                       tryquit=1;
-                                                       pause_sound(stream_menutheme);
-                                               }
-                                               break;
-                               }
-                               break;
-                       case 3:
-                               fireSound();
-                               bool isCustomResolution,found;
-                               switch(selected){
-                                       case 0:
-                                               extern SDL_Rect **resolutions;
-                                               isCustomResolution = true;
-                                               found = false;
-                                               for(int i = 0; (!found) && (resolutions[i]); i++) {
-                                                       if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
-                                                               isCustomResolution = false;
-
-                                                       if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
-                                                               i++;
-                                                               if(resolutions[i] != NULL) {
-                                                                       newscreenwidth = (int) resolutions[i]->w;
-                                                                       newscreenheight = (int) resolutions[i]->h;
-                                                               } else if(isCustomResolution){
-                                                                       if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
-                                                                               newscreenwidth = (int) resolutions[0]->w;
-                                                                               newscreenheight = (int) resolutions[0]->h;
-                                                                       } else {
-                                                                               newscreenwidth = screenwidth;
-                                                                               newscreenheight = screenheight;
-                                                                       }
-                                                               } else {
-                                                                       newscreenwidth = (int) resolutions[0]->w;
-                                                                       newscreenheight = (int) resolutions[0]->h;
-                                                               }
-                                                               found = true;
-                                                       }
-                                               }
-
-                                               if(!found) {
-                                                       newscreenwidth = (int) resolutions[0]->w;
-                                                       newscreenheight = (int) resolutions[0]->h;
-                                               }
-                                               break;
-                                       case 1:
-                                               newdetail++;
-                                               if(newdetail>2) newdetail=0;
-                                               break;
-                                       case 2:
-                                               bloodtoggle++;
-                                               if(bloodtoggle>2) bloodtoggle=0;
-                                               break;
-                                       case 3:
-                                               difficulty++;
-                                               if(difficulty>2) difficulty=0;
-                                               break;
-                                       case 4:
-                                               ismotionblur = !ismotionblur;
-                                               break;
-                                       case 5:
-                                               decals = !decals;
-                                               break;
-                                       case 6:
-                                               musictoggle = !musictoggle;
+void Game::doTutorial(){
+    if(tutorialstagetime>tutorialmaxtime){
+        tutorialstage++;
+        tutorialsuccess=0;
+        if(tutorialstage<=1){
+            canattack=0;
+            cananger=0;
+            reversaltrain=0;
+        }
+        switch(tutorialstage){
+            case 1:
+                tutorialmaxtime=5;
+            break; case 2:
+                tutorialmaxtime=2;
+            break; case 3:
+                tutorialmaxtime=600;
+            break; case 4:
+                tutorialmaxtime=1000;
+            break; case 5:
+                tutorialmaxtime=600;
+            break; case 6:
+                tutorialmaxtime=600;
+            break; case 7:
+                tutorialmaxtime=600;
+            break; case 8:
+                tutorialmaxtime=600;
+            break; case 9:
+                tutorialmaxtime=600;
+            break; case 10:
+                tutorialmaxtime=2;
+            break; case 11:
+                tutorialmaxtime=1000;
+            break; case 12:
+                tutorialmaxtime=1000;
+            break; case 13:
+                tutorialmaxtime=2;
+            break; case 14: {
+                tutorialmaxtime=3;
 
-                                               if(musictoggle) {
-                                                 emit_stream_np(stream_menutheme);
-                                               } else {
-                                                       pause_sound(leveltheme);
-                                                       pause_sound(stream_fighttheme);
-                                                       pause_sound(stream_menutheme);
+                XYZ temp,temp2;
 
-                                                       for(int i=0;i<4;i++){
-                                                               oldmusicvolume[i]=0;
-                                                               musicvolume[i]=0;
-                                                       }
-                                               }
+                temp.x=1011;
+                temp.y=84;
+                temp.z=491;
+                temp2.x=1025;
+                temp2.y=75;
+                temp2.z=447;
 
-                                               break;
-                                       case 7: // controls
-                                               flash();
-                                               mainmenu=4;
-                                               selected=-1;
-                                               keyselect=-1;
-                                               break;
-                                       case 8:
-                                               flash();
-                                               
-                                               SaveSettings(*this);
-                                               mainmenu=gameon?2:1;
-                                               break;
-                                       case 9:
-                                               invertmouse = !invertmouse;
-                                               break;
-                                       case 10:
-                                               usermousesensitivity+=.2;
-                                               if(usermousesensitivity>2) usermousesensitivity=.2;
-                                               break;
-                                       case 11:
-                                               volume+=.1f;
-                                               if(volume>1.0001f) volume=0;
-                                               OPENAL_SetSFXMasterVolume((int)(volume*255));
-                                               break;
-                                       case 12:
-                                               flash();
-                                               
-                                               newstereomode = stereomode;
-                                               mainmenu=18;
-                                               keyselect=-1;
-                                               break;
-                                       case 13:
-                                               showdamagebar = !showdamagebar;
-                                               break;
-                               }
-                               break;
-                       case 4:
-                               if(!waiting) {
-                                       fireSound();
-                                       if(selected<9 && keyselect==-1)
-                                               keyselect=selected;
-                                       if(keyselect!=-1)
-                                               setKeySelected();
-                                       if(selected==9){
-                                               flash();
+                player[1].coords=(temp+temp2)/2;
 
-                                               mainmenu=3;
-                                       }
-                               }
-                               break;
-                       case 5:
-                               fireSound();
-                               flash();
-                               if((selected-7 >= accountactive->getCampaignChoicesMade())) {
-                                       startbonustotal=0;
-
-                                       loading=2;
-                                       loadtime=0;
-                                       targetlevel=7;
-                                       if(firstload)
-                                               TickOnceAfter();
-                                       else
-                                               LoadStuff();
-                                       whichchoice=selected-7-accountactive->getCampaignChoicesMade();
-                                       visibleloading=1;
-                                       stillloading=1;
-                                       Loadlevel(campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]);
-                                       campaign=1;
-                                       mainmenu=0;
-                                       gameon=1;
-                                       pause_sound(stream_menutheme);
-                               }
-                               switch(selected){
-                                       case 1:
-                                               startbonustotal=0;
-
-                                               loading=2;
-                                               loadtime=0;
-                                               targetlevel=-1;
-                                               if(firstload) {
-                                                       TickOnceAfter();
-                                                       Loadlevel(-1);
-                                               } else
-                                                       LoadStuff();
-
-                                               mainmenu=0;
-                                               gameon=1;
-                                               pause_sound(stream_menutheme);
-                                               break;
-                                       case 2:
-                                               mainmenu=9;
-                                               break;
-                                       case 3:
-                                               mainmenu=6;
-                                               break;
-                                       case 4:
-                                               mainmenu=(gameon?2:1);
-                                               break;
-                                       case 5:
-                                               mainmenu=7;
-                                               break;
-                               }
-                               break;
-                       case 6:
-                               fireSound();
-                               if(selected==1) {
-                                       flash();
-                                       accountactive = Account::destroy(accountactive);
-                                       mainmenu=7;
-                               } else if(selected==2) {
-                                       flash();
-                                       mainmenu=5;
-                               }
-                               break;
-                       case 7:
-                               fireSound();
-                               if(selected==0 && Account::getNbAccounts()<8){
-                                       entername=1;
-                               } else if (selected < Account::getNbAccounts()+1) {
-                                       flash();
-                                       mainmenu=5;
-                                       accountactive=Account::get(selected-1);
-                               } else if (selected == Account::getNbAccounts()+1) {
-                                       flash();
-                                       mainmenu=5;
-                                       for(int j=0;j<255;j++){
-                                               displaytext[0][j]=0;
-                                       }
-                                       displaychars[0]=0;
-                                       displayselected=0;
-                                       entername=0;
-                               }
-                               break;
-                       case 8:
-                               fireSound();
-                               flash();
-                               if(selected<=2)
-                                       accountactive->setDifficulty(selected);
-                               mainmenu=5;
-                               break;
-                       case 9:
-                               if(selected<numchallengelevels && selected<=accountactive->getProgress()){
-                                       fireSound();
-                                       flash();
-
-                                       startbonustotal=0;
-
-                                       loading=2;
-                                       loadtime=0;
-                                       targetlevel=selected;
-                                       if(firstload)TickOnceAfter();
-                                       if(!firstload)LoadStuff();
-                                       else Loadlevel(selected);
-                                       campaign=0;
-
-                                       mainmenu=0;
-                                       gameon=1;
-                                       pause_sound(stream_menutheme);
-                               }
-                               if(selected==numchallengelevels){
-                                       fireSound();
-                                       flash();
-                                       mainmenu=5;
-                               }
-                               break;
-                       case 10:
-                               if(selected==3){
-                                       fireSound();
-                                       flash();
-                                       mainmenu=5;
-                               }
-                               break;
-                       case 18:
-                               if(selected==1)
-                                       stereoseparation+=0.001;
-                               else {
-                                       fireSound();
-                                       if(selected==0){
-                                               newstereomode = (StereoMode)(newstereomode + 1);
-                                               while(!CanInitStereo(newstereomode)){
-                                                       printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
-                                                       newstereomode = (StereoMode)(newstereomode + 1);
-                                                       if(newstereomode >= stereoCount)
-                                                               newstereomode = stereoNone;
-                                               }
-                                       } else if(selected==2) {
-                                               stereoreverse = !stereoreverse;
-                                       } else if(selected==3) {
-                                               flash();
-                                               mainmenu=3;
-
-                                               stereomode = newstereomode;
-                                               InitStereo(stereomode);
-                                       }
-                               }
-                               break;
-               }
-       }
-
-    if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
-        tryquit=1;
-        if(mainmenu==3) {
-            SaveSettings(*this);
-        }
-    }
-
-    OPENAL_SetFrequency(channels[stream_menutheme], 22050);
-
-    if(entername) {
-        inputText(displaytext[0],&displayselected,&displaychars[0]);
-        if(!waiting) { // the input as finished
-            if(displaychars[0]){ // with enter
-                accountactive = Account::add(string(displaytext[0]));
-
-                mainmenu=8;
-
-                flash();
-
-                fireSound(firestartsound);
-
-                for(int i=0;i<255;i++){
-                    displaytext[0][i]=0;
-                }
-                displaychars[0]=0;
-
-                displayselected=0;
-            }
-            entername=0;
-        }
-        
-        displayblinkdelay-=multiplier;
-        if(displayblinkdelay<=0){
-            displayblinkdelay=.3;
-            displayblink=1-displayblink;
-        }
-    }
-}
-
-void Game::doTutorial(){
-    if(tutorialstagetime>tutorialmaxtime){
-        tutorialstage++;
-        tutorialsuccess=0;
-        if(tutorialstage<=1){
-            canattack=0;
-            cananger=0;
-            reversaltrain=0;
-        }
-        switch(tutorialstage){
-            case 1:
-                tutorialmaxtime=5;
-            break; case 2:
-                tutorialmaxtime=2;
-            break; case 3:
-                tutorialmaxtime=600;
-            break; case 4:
-                tutorialmaxtime=1000;
-            break; case 5:
-                tutorialmaxtime=600;
-            break; case 6:
-                tutorialmaxtime=600;
-            break; case 7:
-                tutorialmaxtime=600;
-            break; case 8:
-                tutorialmaxtime=600;
-            break; case 9:
-                tutorialmaxtime=600;
-            break; case 10:
-                tutorialmaxtime=2;
-            break; case 11:
-                tutorialmaxtime=1000;
-            break; case 12:
-                tutorialmaxtime=1000;
-            break; case 13:
-                tutorialmaxtime=2;
-            break; case 14: {
-                tutorialmaxtime=3;
-
-                XYZ temp,temp2;
-
-                temp.x=1011;
-                temp.y=84;
-                temp.z=491;
-                temp2.x=1025;
-                temp2.y=75;
-                temp2.z=447;
-
-                player[1].coords=(temp+temp2)/2;
-
-                emit_sound_at(fireendsound, player[1].coords);
+                emit_sound_at(fireendsound, player[1].coords);
 
                 for(int i=0;i<player[1].skeleton.num_joints;i++){
                     if(Random()%2==0){
@@ -5862,6 +5483,401 @@ void Game::doAI(int i){
     }
 }
 
+/*
+Values of mainmenu :
+1 Main menu
+2 Menu pause (resume/end game)
+3 Option menu
+4 Controls configuration menu
+5 Main game menu (choose level or challenge)
+6 Deleting user menu
+7 User managment menu (select/add)
+8 Choose difficulty menu
+9 Challenge level selection menu
+10 End of the campaign congratulation (is that really a menu?)
+11 Same that 9 ??? => unused
+18 stereo configuration
+*/
+    
+void Game::MenuTick(){
+    //menu buttons
+    
+    // some specific case where we do something even if the left mouse button is not pressed.
+       if((mainmenu==5) && (endgame==2)) {
+               accountactive->endGame();
+               endgame=0;
+       }
+       if(mainmenu==10)
+               endgame=2;
+       if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
+               stereoseparation-=0.001;
+               
+    if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
+               switch(mainmenu) {
+                       case 1:
+                       case 2:
+                               switch(selected) {
+                                       case 1:
+                                               if(gameon) { //resume
+                                                       mainmenu=0;
+                                                       pause_sound(stream_menutheme);
+                                                       resume_stream(leveltheme);
+                                               } else { //new game
+                                                       fireSound(firestartsound);
+                                                       flash();
+                                                       mainmenu=(accountactive?5:7);
+                                                       selected=-1;
+                                               }
+                                               break;
+                                       case 2: //options
+                                               fireSound();
+                                               flash();
+                                               mainmenu=3;
+                                               if(newdetail>2) newdetail=detail;
+                                               if(newdetail<0) newdetail=detail;
+                                               if(newscreenwidth>3000) newscreenwidth=screenwidth;
+                                               if(newscreenwidth<0) newscreenwidth=screenwidth;
+                                               if(newscreenheight>3000) newscreenheight=screenheight;
+                                               if(newscreenheight<0) newscreenheight=screenheight;
+                                               break;
+                                       case 3:
+                                               fireSound();
+                                               flash();
+                                               if(gameon){ //end game
+                                                       gameon=0;
+                                                       mainmenu=1;
+                                               } else { //quit
+                                                       tryquit=1;
+                                                       pause_sound(stream_menutheme);
+                                               }
+                                               break;
+                               }
+                               break;
+                       case 3:
+                               fireSound();
+                               bool isCustomResolution,found;
+                               switch(selected){
+                                       case 0:
+                                               extern SDL_Rect **resolutions;
+                                               isCustomResolution = true;
+                                               found = false;
+                                               for(int i = 0; (!found) && (resolutions[i]); i++) {
+                                                       if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
+                                                               isCustomResolution = false;
+
+                                                       if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
+                                                               i++;
+                                                               if(resolutions[i] != NULL) {
+                                                                       newscreenwidth = (int) resolutions[i]->w;
+                                                                       newscreenheight = (int) resolutions[i]->h;
+                                                               } else if(isCustomResolution){
+                                                                       if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
+                                                                               newscreenwidth = (int) resolutions[0]->w;
+                                                                               newscreenheight = (int) resolutions[0]->h;
+                                                                       } else {
+                                                                               newscreenwidth = screenwidth;
+                                                                               newscreenheight = screenheight;
+                                                                       }
+                                                               } else {
+                                                                       newscreenwidth = (int) resolutions[0]->w;
+                                                                       newscreenheight = (int) resolutions[0]->h;
+                                                               }
+                                                               found = true;
+                                                       }
+                                               }
+
+                                               if(!found) {
+                                                       newscreenwidth = (int) resolutions[0]->w;
+                                                       newscreenheight = (int) resolutions[0]->h;
+                                               }
+                                               break;
+                                       case 1:
+                                               newdetail++;
+                                               if(newdetail>2) newdetail=0;
+                                               break;
+                                       case 2:
+                                               bloodtoggle++;
+                                               if(bloodtoggle>2) bloodtoggle=0;
+                                               break;
+                                       case 3:
+                                               difficulty++;
+                                               if(difficulty>2) difficulty=0;
+                                               break;
+                                       case 4:
+                                               ismotionblur = !ismotionblur;
+                                               break;
+                                       case 5:
+                                               decals = !decals;
+                                               break;
+                                       case 6:
+                                               musictoggle = !musictoggle;
+
+                                               if(musictoggle) {
+                                                 emit_stream_np(stream_menutheme);
+                                               } else {
+                                                       pause_sound(leveltheme);
+                                                       pause_sound(stream_fighttheme);
+                                                       pause_sound(stream_menutheme);
+
+                                                       for(int i=0;i<4;i++){
+                                                               oldmusicvolume[i]=0;
+                                                               musicvolume[i]=0;
+                                                       }
+                                               }
+
+                                               break;
+                                       case 7: // controls
+                                               flash();
+                                               mainmenu=4;
+                                               selected=-1;
+                                               keyselect=-1;
+                                               break;
+                                       case 8:
+                                               flash();
+                                               
+                                               SaveSettings(*this);
+                                               mainmenu=gameon?2:1;
+                                               break;
+                                       case 9:
+                                               invertmouse = !invertmouse;
+                                               break;
+                                       case 10:
+                                               usermousesensitivity+=.2;
+                                               if(usermousesensitivity>2) usermousesensitivity=.2;
+                                               break;
+                                       case 11:
+                                               volume+=.1f;
+                                               if(volume>1.0001f) volume=0;
+                                               OPENAL_SetSFXMasterVolume((int)(volume*255));
+                                               break;
+                                       case 12:
+                                               flash();
+                                               
+                                               newstereomode = stereomode;
+                                               mainmenu=18;
+                                               keyselect=-1;
+                                               break;
+                                       case 13:
+                                               showdamagebar = !showdamagebar;
+                                               break;
+                               }
+                               break;
+                       case 4:
+                               if(!waiting) {
+                                       fireSound();
+                                       if(selected<9 && keyselect==-1)
+                                               keyselect=selected;
+                                       if(keyselect!=-1)
+                                               setKeySelected();
+                                       if(selected==9){
+                                               flash();
+
+                                               mainmenu=3;
+                                       }
+                               }
+                               break;
+                       case 5:
+                               fireSound();
+                               flash();
+                               if((selected-NB_CAMPAIGN_MENU_ITEM-1 >= accountactive->getCampaignChoicesMade())) {
+                                       startbonustotal=0;
+
+                                       loading=2;
+                                       loadtime=0;
+                                       targetlevel=7;
+                                       if(firstload)
+                                               TickOnceAfter();
+                                       else
+                                               LoadStuff();
+                                       whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-1-accountactive->getCampaignChoicesMade();
+                                       visibleloading=1;
+                                       stillloading=1;
+                                       Loadlevel(campaignmapname[campaignchoicewhich[whichchoice]]);
+                                       campaign=1;
+                                       mainmenu=0;
+                                       gameon=1;
+                                       pause_sound(stream_menutheme);
+                               }
+                               switch(selected){
+                                       case 1:
+                                               startbonustotal=0;
+
+                                               loading=2;
+                                               loadtime=0;
+                                               targetlevel=-1;
+                                               if(firstload) {
+                                                       TickOnceAfter();
+                                                       Loadlevel(-1);
+                                               } else
+                                                       LoadStuff();
+
+                                               mainmenu=0;
+                                               gameon=1;
+                                               pause_sound(stream_menutheme);
+                                               break;
+                                       case 2:
+                                               mainmenu=9;
+                                               break;
+                                       case 3:
+                                               mainmenu=6;
+                                               break;
+                                       case 4:
+                                               mainmenu=(gameon?2:1);
+                                               break;
+                                       case 5:
+                                               mainmenu=7;
+                                               break;
+                                       case 6:
+                                               vector<string> campaigns = ListCampaigns();
+                                               vector<string>::iterator c;
+                                               if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
+                                                       if(!campaigns.empty())
+                                                               accountactive->setCurrentCampaign(campaigns.front());
+                                               } else {
+                                                       c++;
+                                                       if(c==campaigns.end())
+                                                               c=campaigns.begin();
+                                                       accountactive->setCurrentCampaign(*c);
+                                               }
+                                               LoadCampaign();
+                                               break;
+                               }
+                               break;
+                       case 6:
+                               fireSound();
+                               if(selected==1) {
+                                       flash();
+                                       accountactive = Account::destroy(accountactive);
+                                       mainmenu=7;
+                               } else if(selected==2) {
+                                       flash();
+                                       mainmenu=5;
+                               }
+                               break;
+                       case 7:
+                               fireSound();
+                               if(selected==0 && Account::getNbAccounts()<8){
+                                       entername=1;
+                               } else if (selected < Account::getNbAccounts()+1) {
+                                       flash();
+                                       mainmenu=5;
+                                       accountactive=Account::get(selected-1);
+                               } else if (selected == Account::getNbAccounts()+1) {
+                                       flash();
+                                       mainmenu=5;
+                                       for(int j=0;j<255;j++){
+                                               displaytext[0][j]=0;
+                                       }
+                                       displaychars[0]=0;
+                                       displayselected=0;
+                                       entername=0;
+                               }
+                               break;
+                       case 8:
+                               fireSound();
+                               flash();
+                               if(selected<=2)
+                                       accountactive->setDifficulty(selected);
+                               mainmenu=5;
+                               break;
+                       case 9:
+                               if(selected<numchallengelevels && selected<=accountactive->getProgress()){
+                                       fireSound();
+                                       flash();
+
+                                       startbonustotal=0;
+
+                                       loading=2;
+                                       loadtime=0;
+                                       targetlevel=selected;
+                                       if(firstload)TickOnceAfter();
+                                       if(!firstload)LoadStuff();
+                                       else Loadlevel(selected);
+                                       campaign=0;
+
+                                       mainmenu=0;
+                                       gameon=1;
+                                       pause_sound(stream_menutheme);
+                               }
+                               if(selected==numchallengelevels){
+                                       fireSound();
+                                       flash();
+                                       mainmenu=5;
+                               }
+                               break;
+                       case 10:
+                               if(selected==3){
+                                       fireSound();
+                                       flash();
+                                       mainmenu=5;
+                               }
+                               break;
+                       case 18:
+                               if(selected==1)
+                                       stereoseparation+=0.001;
+                               else {
+                                       fireSound();
+                                       if(selected==0){
+                                               newstereomode = (StereoMode)(newstereomode + 1);
+                                               while(!CanInitStereo(newstereomode)){
+                                                       printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
+                                                       newstereomode = (StereoMode)(newstereomode + 1);
+                                                       if(newstereomode >= stereoCount)
+                                                               newstereomode = stereoNone;
+                                               }
+                                       } else if(selected==2) {
+                                               stereoreverse = !stereoreverse;
+                                       } else if(selected==3) {
+                                               flash();
+                                               mainmenu=3;
+
+                                               stereomode = newstereomode;
+                                               InitStereo(stereomode);
+                                       }
+                               }
+                               break;
+               }
+       }
+
+    if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
+        tryquit=1;
+        if(mainmenu==3) {
+            SaveSettings(*this);
+        }
+    }
+
+    OPENAL_SetFrequency(channels[stream_menutheme], 22050);
+
+    if(entername) {
+        inputText(displaytext[0],&displayselected,&displaychars[0]);
+        if(!waiting) { // the input as finished
+            if(displaychars[0]){ // with enter
+                accountactive = Account::add(string(displaytext[0]));
+
+                mainmenu=8;
+
+                flash();
+
+                fireSound(firestartsound);
+
+                for(int i=0;i<255;i++){
+                    displaytext[0][i]=0;
+                }
+                displaychars[0]=0;
+
+                displayselected=0;
+            }
+            entername=0;
+        }
+        
+        displayblinkdelay-=multiplier;
+        if(displayblinkdelay<=0){
+            displayblinkdelay=.3;
+            displayblink=1-displayblink;
+        }
+    }
+}
+
 void Game::Tick(){
        static XYZ facing,flatfacing;
        static int target;