]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
The game now supports multiple campaigns!
[lugaru.git] / Source / GameTick.cpp
index 4aead8d5b959ea169e0828e75fc82e2e23af1d1f..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
@@ -78,7 +80,7 @@ extern bool keyboardfrozen;
 extern bool loadingstuff;
 extern XYZ windvector;
 extern bool debugmode;
-static int music1;
+static int leveltheme;
 extern int mainmenu;
 extern bool visibleloading;
 extern XYZ envsound[30];
@@ -1130,8 +1132,6 @@ void Screenshot   (void)
        save_image(temp);
 }
 
-
-
 void Game::SetUpLighting(){
        if(environment==snowyenvironment)
         light.setColors(.65,.65,.7,.4,.4,.44);
@@ -1263,7 +1263,7 @@ int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
        return -1;
 }
 
-void   Game::Setenvironment(int which)
+void Game::Setenvironment(int which)
 {
        LOGFUNC;
 
@@ -1272,9 +1272,9 @@ void      Game::Setenvironment(int which)
        float temptexdetail;
        environment=which;
 
-       pause_sound(stream_music1snow);
-       pause_sound(stream_music1grass);
-       pause_sound(stream_music1desert);
+       pause_sound(stream_snowtheme);
+       pause_sound(stream_grasstheme);
+       pause_sound(stream_deserttheme);
        pause_sound(stream_wind);
        pause_sound(stream_desertambient);
 
@@ -1317,8 +1317,7 @@ void      Game::Setenvironment(int which)
 
 
                texdetail=temptexdetail;
-       }
-       if(environment==desertenvironment){
+       } else if(environment==desertenvironment){
                windvector=0;
                windvector.z=2;
                LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
@@ -1356,8 +1355,7 @@ void      Game::Setenvironment(int which)
 
 
                texdetail=temptexdetail;
-       }
-       if(environment==grassyenvironment){
+       } else if(environment==grassyenvironment){
                windvector=0;
                windvector.z=2;
                LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
@@ -1401,7 +1399,6 @@ void      Game::Setenvironment(int which)
        texdetail=temptexdetail;
 }
 
-
 void Game::Loadlevel(int which){
        stealthloading=0;
        whichlevel=which;
@@ -1418,10 +1415,8 @@ void Game::Loadlevel(int which){
 }
 
 void Game::Loadlevel(const char *name){
-       static int oldlevel;
        int templength;
        float lamefloat;
-       int lameint;
        static const char *pfx = ":Data:Maps:";
        char *buf;
 
@@ -1453,8 +1448,6 @@ void Game::Loadlevel(const char *name){
                tutorialmaxtime=1;
        }
        loadingstuff=1;
-       if(!firstload)
-               oldlevel=50;
        pause_sound(whooshsound);
        pause_sound(stream_firesound);
 
@@ -1533,7 +1526,7 @@ void Game::Loadlevel(const char *name){
                if(console){
                        emit_sound_np(consolesuccesssound);
                        freeze=0;
-                       console=0;
+                       console=false;
                }
 
                if(!stealthloading){
@@ -1643,8 +1636,6 @@ void Game::Loadlevel(const char *name){
                     funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
                     funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
 
-                    bool doneread;
-
                     funpackf(tfile, "Bi",&templength);
                     if(templength>128||templength<=0)
                         templength=128;
@@ -1724,11 +1715,11 @@ void Game::Loadlevel(const char *name){
 
                        float maxdistance=0;
                        float tempdist;
-                       int whichclosest;
+                       //~ int whichclosest;
                        for(int i=0;i<objects.numobjects;i++){
                                tempdist=findDistancefast(&objects.center,&objects.position[i]);
                                if(tempdist>maxdistance){
-                                       whichclosest=i;
+                                       //~ whichclosest=i;
                                        maxdistance=tempdist;
                                }
                        }
@@ -1880,9 +1871,6 @@ void Game::Loadlevel(const char *name){
 
                fclose(tfile);
 
-               oldlevel=whichlevel;
-
-
                if(numplayers>maxplayers-1)
             numplayers=maxplayers-1;
                for(int i=0;i<numplayers;i++){
@@ -1946,8 +1934,8 @@ void Game::Loadlevel(const char *name){
                        }
 
 
-                       int texsize;
-                       texsize=512*512*3/texdetail/texdetail;
+                       //~ int texsize;
+                       //~ texsize=512*512*3/texdetail/texdetail;
 
                        LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
 
@@ -2127,422 +2115,6 @@ void Game::Loadlevel(const char *name){
        visibleloading=0;
 }
 
-
-
-void Game::MenuTick(){
-    //menu buttons
-    if(mainmenu==1||mainmenu==2){
-        if(Input::MouseClicked()&&selected==1){
-            if(!gameon){
-                fireSound(firestartsound);
-                flash();
-                //new game
-                if(accountactive) {
-                    mainmenu=5;
-                } else {
-                    mainmenu=7;
-                }
-                selected=-1;
-            }else{
-                //resume
-                mainmenu=0;
-                pause_sound(stream_music3);
-                resume_stream(music1);
-            }
-        }
-
-        if(Input::MouseClicked()&&selected==2){
-            fireSound();
-            flash();
-            //options
-            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;
-        }
-
-        if(Input::MouseClicked()&&selected==3){
-            fireSound();
-            flash();
-            if(!gameon){
-                //quit
-                tryquit=1;
-                pause_sound(stream_music3);
-            }else{
-                //end game
-                gameon=0;
-                mainmenu=1;
-            }
-        }
-    }else if(mainmenu==3){
-        if(Input::MouseClicked()){
-
-            if(selected!=-1)
-                fireSound();
-
-            switch(selected){
-                case 0: {
-                    extern SDL_Rect **resolutions;
-                    bool isCustomResolution = true;
-                    bool 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=1-ismotionblur;
-                    break;
-                case 5:
-                    decals=1-decals;
-                    break;
-                case 6:
-                    musictoggle=1-musictoggle;
-
-                    if(!musictoggle){
-                        pause_sound(music1);
-                        pause_sound(stream_music2);
-                        pause_sound(stream_music3);
-
-                        for(int i=0;i<4;i++){
-                            oldmusicvolume[i]=0;
-                            musicvolume[i]=0;
-                        }
-                    }
-
-                    if(musictoggle)
-                      emit_stream_np(stream_music3);
-                    break;
-                case 7:
-                    flash();
-                    //options
-                    mainmenu=4;
-                    selected=-1;
-                    keyselect=-1;
-                    break;
-                case 8:
-                    flash();
-
-                    if(newdetail>2)newdetail=detail;
-                    if(newdetail<0)newdetail=detail;
-                    if(newscreenwidth<0)newscreenwidth=screenwidth;
-                    if(newscreenheight<0)newscreenheight=screenheight;
-
-                    SaveSettings(*this);
-                    if(mainmenu==3&&gameon)mainmenu=2;
-                    if(mainmenu==3&&!gameon)mainmenu=1;
-                    break;
-                case 9:
-                    invertmouse=1-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;
-            }
-        }
-    }else if(mainmenu==4){
-        if(Input::MouseClicked()&&selected!=-1&&!waiting){
-            fireSound();
-            if(selected<9&&keyselect==-1)
-                keyselect=selected;
-            if(keyselect!=-1)
-                setKeySelected();
-            if(selected==9){
-                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;
-            }
-        }
-    }else if(mainmenu==5){
-
-        if(endgame==2){
-            accountactive->endGame();
-            endgame=0;
-        }
-
-        if(Input::MouseClicked()){
-            if((selected-7>=accountactive->getCampaignChoicesMade())){
-                fireSound();
-                flash();
-                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()]]);
-                //Loadlevel(campaignmapname[levelorder[selected-7]]);
-                campaign=1;
-                mainmenu=0;
-                gameon=1;
-                pause_sound(stream_music3);
-            }
-            if(selected>=1 && selected<=5){
-                fireSound();
-                flash();
-            }
-            switch(selected){
-                case 1:
-                    startbonustotal=0;
-
-                    loading=2;
-                    loadtime=0;
-                    targetlevel=-1;
-                    if(firstload)TickOnceAfter();
-                    if(!firstload)LoadStuff();
-                    else {
-                        Loadlevel(-1);
-                    }
-
-                    mainmenu=0;
-                    gameon=1;
-                    pause_sound(stream_music3);
-                    break;
-                case 2:
-                    mainmenu=9;
-                    break;
-                case 3:
-                    mainmenu=6;
-                    break;
-                case 4:
-                    if(mainmenu==5&&gameon)mainmenu=2;
-                    if(mainmenu==5&&!gameon)mainmenu=1;
-                    break;
-                case 5:
-                    mainmenu=7;
-                    break;
-            }
-        }
-    }else if(mainmenu==9){
-        if(Input::MouseClicked()&&selected<numchallengelevels&&selected>=0&&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_music3);
-        }
-        if(Input::MouseClicked()&&selected==numchallengelevels){
-            fireSound();
-            flash();
-            mainmenu=5;
-        }
-    }else if(mainmenu==10){
-        endgame=2;
-        if(Input::MouseClicked()&&selected==3){
-            fireSound();
-            flash();
-            mainmenu=5;
-        }
-    }else if(mainmenu==6){
-        if(Input::MouseClicked()) {
-            if(selected>-1){
-                fireSound();
-                if(selected==1) {
-                    flash();
-                    accountactive = Account::destroy(accountactive);
-                    mainmenu=7;
-                } else if(selected==2) {
-                    flash();
-                    mainmenu=5;
-                }
-            }
-        }
-    }else if(mainmenu==7){
-        if(Input::MouseClicked()) {
-            if(selected!=-1){
-                fireSound();
-                if(selected==0&&Account::getNbAccounts()<8){
-                    entername=1;
-                } else if (selected<Account::getNbAccounts()+1) {
-                    accountactive=Account::get(selected-1);
-                    mainmenu=5;
-                    flash();
-                } else if (selected==Account::getNbAccounts()+1) {
-                    flash();
-
-                    mainmenu=1;
-
-                    for(int j=0;j<255;j++){
-                        displaytext[0][j]=0;
-                    }
-                    displaychars[0]=0;
-                    displayselected=0;
-                    entername=0;
-                }
-            }
-        }
-    }else if(mainmenu==8){
-        if(Input::MouseClicked()&&selected>-1){
-            fireSound();
-            flash();
-            if(selected<=2)
-                accountactive->setDifficulty(selected);
-            mainmenu=5;
-        }
-    }else if(mainmenu==18){                    
-        if(Input::MouseClicked()&&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;
-                }
-            }
-        }
-        
-        if(Input::isKeyPressed(MOUSEBUTTON1)&&selected==1)
-            stereoseparation+=0.001;
-        if(Input::isKeyPressed(MOUSEBUTTON2)&&selected==1)
-            stereoseparation-=0.001;
-
-        if(Input::MouseClicked()&&selected==2) {
-            stereoreverse =! stereoreverse;
-        }
-        
-        if(Input::MouseClicked()&&selected==3) {
-            flash();
-
-            stereomode = newstereomode;
-            InitStereo(stereomode);
-            
-            mainmenu=3;
-        }
-    }
-
-    if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
-        tryquit=1;
-        if(mainmenu==3){
-            if(newdetail>2)newdetail=detail;
-            if(newdetail<0)newdetail=detail;
-            if(newscreenwidth<0)newscreenwidth=screenwidth;
-            if(newscreenheight<0)newscreenheight=screenheight;
-
-            SaveSettings(*this);
-        }
-    }
-
-    if(mainmenu==1||mainmenu==2){
-        if(loaddistrib>4)transition+=multiplier/8;
-        if(transition>1){
-            transition=0;
-            anim++;
-            if(anim>4)anim=0;
-            loaddistrib=0;
-        }
-    }
-    OPENAL_SetFrequency(channels[stream_music3], 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++;
@@ -2938,8 +2510,6 @@ void Game::doTutorial(){
     }
 }
 
-
-
 void Game::doDebugKeys(){
        float headprop,bodyprop,armprop,legprop;
     if(debugmode){
@@ -3359,9 +2929,6 @@ void Game::doDebugKeys(){
         }
 
         if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
-            int closest=-1;
-            float closestdist=-1;
-            float distance;
             for(int i=0;i<objects.numobjects;i++){
                 if(objects.type[i]==treeleavestype){
                     objects.scale[i]*=.9;
@@ -3733,8 +3300,6 @@ void Game::doDebugKeys(){
     }
 }
 
-
-
 void Game::doJumpReversals(){
     for(int k=0;k<numplayers;k++)
         for(int i=k;i<numplayers;i++){
@@ -4631,7 +4196,7 @@ void Game::doAttacks(){
                                                          player[i].skeleton.longdead<300&&
                                                          player[k].lastattack!=spinkickanim&&
                                                          player[i].skeleton.free)&&
-                                                        (!player[i].dead||musictype!=stream_music2)){
+                                                        (!player[i].dead||musictype!=stream_fighttheme)){
                                                     player[k].targetanimation=dropkickanim;
                                                     for(int j=0;j<terrain.numdecals;j++){
                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
@@ -4943,8 +4508,6 @@ void Game::doPlayerCollisions(){
             }
 }
 
-
-
 void Game::doAI(int i){
     static bool connected;
     if(player[i].aitype!=playercontrolled&&indialogue==-1){
@@ -5920,19 +5483,410 @@ 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;
 
-       int templength;
-
        for(int i=0;i<15;i++){
                displaytime[i]+=multiplier;
        }
 
-       keyboardfrozen=0;
+       keyboardfrozen=false;
     Input::Tick();
 
        if(Input::isKeyPressed(SDLK_F6)){
@@ -5970,68 +5924,87 @@ void Game::Tick(){
                emit_sound_np(consolefailsound, 128.);
        }
 
-       if(!console){
-               if(mainmenu&&endgame==1)mainmenu=10;
-        // menu back
-               if( (Input::isKeyPressed(SDLK_ESCAPE)
-                    ||(mainmenu==0
-                        &&((Input::isKeyPressed(jumpkey)
-                                ||Input::isKeyPressed(SDLK_SPACE)
-                                ||(campaign)))
-                        &&campaign
-                        &&winfreeze))
-                && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==10)){
+    /*
+    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
+    */
+        
+       if(!console) {
+        //campaign over?
+               if(mainmenu&&endgame==1)
+            mainmenu=10;
+        //go to level select after completing a campaign level
+        if(campaign&&winfreeze&&mainmenu==0&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1) {
+            mainmenu=5;
+            gameon=0;
+            winfreeze=0;
+            fireSound();
+            flash();
+            if(musictoggle){
+                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+                emit_stream_np(stream_menutheme);
+                pause_sound(leveltheme);
+            }
+                       LoadCampaign();
+        }
+        //escape key pressed
+        //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
+               if(Input::isKeyPressed(SDLK_ESCAPE)&&
+                (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
                        selected=-1;
-                       if(mainmenu==1||mainmenu==2||mainmenu==0){
-                               if(mainmenu==0&&!winfreeze)mainmenu=2;
-                               else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
-                               else if(mainmenu==0&&winfreeze){ }
-                               else if(mainmenu==1||mainmenu==2)mainmenu=0;
-                               if(mainmenu&&musictoggle){
-                                       if(mainmenu==1||mainmenu==2||mainmenu==100){
-                                               OPENAL_SetFrequency(OPENAL_ALL, 0.001);
-                                               emit_stream_np(stream_music3);
-                                               pause_sound(music1);
-                                       }
-                               }
-                               if(!mainmenu){
-                                       pause_sound(stream_music3);
-                                       resume_stream(music1);
-                               }
-                       }
+            if(mainmenu==0&&!winfreeze)
+                mainmenu=2; //pause
+            else if(mainmenu==1||mainmenu==2){
+                mainmenu=0; //unpause
+            }
+            //play menu theme
+            if(musictoggle&&(mainmenu==1||mainmenu==2)){
+                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+                emit_stream_np(stream_menutheme);
+                pause_sound(leveltheme);
+            }
+            //on resume, play level music
+            if(!mainmenu){
+                pause_sound(stream_menutheme);
+                resume_stream(leveltheme);
+            }
+            //finished with settings menu
                        if(mainmenu==3){
-                               if(newdetail>2)newdetail=detail;
-                               if(newdetail<0)newdetail=detail;
-                               if(newscreenwidth<0)newscreenwidth=screenwidth;
-                               if(newscreenheight<0)newscreenheight=screenheight;
                                SaveSettings(*this);
                        }
-                       if((mainmenu>=3 && mainmenu<=7)||mainmenu==9||mainmenu==10||mainmenu==100){
+            //effects
+                       if(mainmenu>=3&&mainmenu!=8){
                                fireSound();
                                flash();
                        }
-                       if(mainmenu==3&&gameon)mainmenu=2;
-                       if(mainmenu==3&&!gameon)mainmenu=1;
-                       if(mainmenu==5&&gameon)mainmenu=2;
-                       if(mainmenu==5&&!gameon)mainmenu=1;
-                       if(mainmenu==4)mainmenu=3;
-                       if(mainmenu==6)mainmenu=5;
-                       if(mainmenu==7)mainmenu=1;
-                       if(mainmenu==9)mainmenu=5;
-                       if(mainmenu==10)mainmenu=5;
-                       if(mainmenu==100){
-                               mainmenu=5;
-                               gameon=0;
-                               winfreeze=0;
-                       }
+            //go back
+            switch(mainmenu){
+                case 3: case 5:
+                    mainmenu=gameon?2:1; break;
+                case 4: case 18:
+                    mainmenu=3; break;
+                case 6: case 7: case 9: case 10:
+                    mainmenu=5; break;
+            }
                }
        }
 
-       if(mainmenu){
+       if(mainmenu) {
         MenuTick();
        }
 
-       if(!mainmenu){
+       if(!mainmenu) {
                if(hostile==1)hostiletime+=multiplier;
                else hostiletime=0;
                if(!winfreeze)leveltime+=multiplier;
@@ -6066,10 +6039,10 @@ void Game::Tick(){
                        }
                }
                if(chatting)
-            keyboardfrozen=1;
+            keyboardfrozen=true;
 
                if(Input::isKeyPressed(SDLK_BACKQUOTE)&&debugmode){
-                       console=1-console;
+                       console=!console;
                        if(console){
                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
                        } else {
@@ -6110,12 +6083,7 @@ void Game::Tick(){
 
                if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
                        tryquit=1;
-                       if(mainmenu==3){
-                               if(newdetail>2)newdetail=detail;
-                               if(newdetail<0)newdetail=detail;
-                               if(newscreenwidth<0)newscreenwidth=screenwidth;
-                               if(newscreenheight<0)newscreenheight=screenheight;
-
+                       if(mainmenu==3) {
                                SaveSettings(*this);
                        }
                }
@@ -6135,9 +6103,9 @@ void Game::Tick(){
                 winfreeze=0;
                if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
             if(console){
-                console=0;
+                console=false;
                 freeze=0;
-            }else if(winfreeze){
+            } else if(winfreeze) {
                                mainmenu=9;
                                gameon=0;
                        }
@@ -6495,8 +6463,6 @@ void Game::Tick(){
                 }
             }
 
-            static float keyrefreshdelay=0,bigrefreshdelay=0;
-
             if(!player[0].jumpkeydown){
                 player[0].jumptogglekeydown=0;
             }
@@ -6519,8 +6485,6 @@ void Game::Tick(){
 
                 hawkcalldelay=16+abs(Random()%8);
             }
-            static float temptexdetail;
-
 
             doDebugKeys();
 
@@ -6634,8 +6598,6 @@ void Game::Tick(){
                         player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
                     }
 
-                    bool pause;
-
                     if(leveltime<.5)
                         numenvsounds=0;
 
@@ -7040,7 +7002,7 @@ void Game::Tick(){
                             player[i].attackkeydown){
                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
                                 player[i].onterrain&&
-                                bloodtoggle&&musictype!=stream_music2){
+                                bloodtoggle&&musictype!=stream_fighttheme){
                             if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)
                                 setAnimation(i,crouchstabanim);
                             if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)
@@ -7481,7 +7443,7 @@ void Game::Tick(){
                         OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
 
-                        emit_stream_np(stream_music3);
+                        emit_stream_np(stream_menutheme);
 
                         gameon=0;
                         mainmenu=5;
@@ -7571,9 +7533,7 @@ void Game::Tick(){
                Screenshot();
 }
 
-
-
-void   Game::TickOnce(){
+void Game::TickOnce(){
        if(mainmenu)
                rotation+=multiplier*5;
        else
@@ -7590,12 +7550,11 @@ void    Game::TickOnce(){
                }
 }
 
-void   Game::TickOnceAfter(){
+void Game::TickOnceAfter(){
        static XYZ colviewer;
        static XYZ coltarget;
        static XYZ target;
        static XYZ col;
-       static float brotate;
        static XYZ facing;
        static float changedelay;
        static bool alldead;
@@ -7605,15 +7564,15 @@ void    Game::TickOnceAfter(){
        if(!mainmenu){
 
                if(environment==snowyenvironment)
-            music1=stream_music1snow;
+            leveltheme=stream_snowtheme;
                if(environment==grassyenvironment)
-            music1=stream_music1grass;
+            leveltheme=stream_grasstheme;
                if(environment==desertenvironment)
-            music1=stream_music1desert;
+            leveltheme=stream_deserttheme;
 
                realthreat=0;
 
-               musictype=music1;
+               musictype=leveltheme;
                for(int i=0;i<numplayers;i++){
                        if((player[i].aitype==attacktypecutoff||
                         player[i].aitype==getweapontype||
@@ -7623,26 +7582,26 @@ void    Game::TickOnceAfter(){
                     (player[i].targetanimation!=sneakattackedanim&&
                      player[i].targetanimation!=knifesneakattackedanim&&
                      player[i].targetanimation!=swordsneakattackedanim)){
-                               musictype=stream_music2;
+                               musictype=stream_fighttheme;
                                realthreat=1;
                        }
                }
                if(player[0].dead)
-            musictype=stream_music3;
+            musictype=stream_menutheme;
 
 
-               if(musictype==stream_music2)
+               if(musictype==stream_fighttheme)
                        unseendelay=1;
 
-               if(oldmusictype==stream_music2&&musictype!=stream_music2){
+               if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
                        unseendelay-=multiplier;
                        if(unseendelay>0)
-                               musictype=stream_music2;
+                               musictype=stream_fighttheme;
                }
 
 
                if(loading==2){
-                       musictype=stream_music3;
+                       musictype=stream_menutheme;
                        musicvolume[2]=512;
                        musicvolume[0]=0;
                        musicvolume[1]=0;
@@ -7650,19 +7609,19 @@ void    Game::TickOnceAfter(){
                }
 
                if(musictoggle)
-                       if(musictype!=oldmusictype&&musictype==stream_music2)
+                       if(musictype!=oldmusictype&&musictype==stream_fighttheme)
                                emit_sound_np(alarmsound);
                musicselected=musictype;
 
-               if(musicselected==music1)
+               if(musicselected==leveltheme)
             musicvolume[0]+=multiplier*450;
                else
             musicvolume[0]-=multiplier*450;
-               if(musicselected==stream_music2)
+               if(musicselected==stream_fighttheme)
             musicvolume[1]+=multiplier*450;
                else
             musicvolume[1]-=multiplier*450;
-               if(musicselected==stream_music3)
+               if(musicselected==stream_menutheme)
             musicvolume[2]+=multiplier*450;
                else
             musicvolume[2]-=multiplier*450;
@@ -7679,31 +7638,31 @@ void    Game::TickOnceAfter(){
 
                if(musictoggle){
                        if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
-                         emit_stream_np(music1, musicvolume[0]);
+                         emit_stream_np(leveltheme, musicvolume[0]);
                        if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
-                         emit_stream_np(stream_music2, musicvolume[1]);
+                         emit_stream_np(stream_fighttheme, musicvolume[1]);
                        if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
-                         emit_stream_np(stream_music3, musicvolume[2]);
+                         emit_stream_np(stream_menutheme, musicvolume[2]);
                        if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
-                               pause_sound(music1);
+                               pause_sound(leveltheme);
                        if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
-                               pause_sound(stream_music2);
+                               pause_sound(stream_fighttheme);
                        if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
-                               pause_sound(stream_music3);
+                               pause_sound(stream_menutheme);
 
                        if(musicvolume[0]!=oldmusicvolume[0])
-                               OPENAL_SetVolume(channels[music1], musicvolume[0]);
+                               OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
                        if(musicvolume[1]!=oldmusicvolume[1])
-                               OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
+                               OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
                        if(musicvolume[2]!=oldmusicvolume[2])
-                               OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
+                               OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
 
                        for(int i=0;i<3;i++)
                                oldmusicvolume[i]=musicvolume[i];
                } else {
-                       pause_sound(music1);
-                       pause_sound(stream_music2);
-                       pause_sound(stream_music3);
+                       pause_sound(leveltheme);
+                       pause_sound(stream_fighttheme);
+                       pause_sound(stream_menutheme);
 
                        for(int i=0;i<4;i++){
                                oldmusicvolume[i]=0;
@@ -7766,12 +7725,12 @@ void    Game::TickOnceAfter(){
                                if(targetlevel>numchallengelevels-1)targetlevel=0;
                        }
 
-                       if(changedelay>0&&!player[0].dead&&!won){
+                       if(changedelay>0&&!player[0].dead&&!won) {
                                //high scores, awards, win
-                               if(campaign){
+                               if(campaign) {
                                        accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
                                        scoreadded=1;
-                               }else{
+                               } else {
                                        accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
                                }
                                won=1;
@@ -7788,7 +7747,7 @@ void      Game::TickOnceAfter(){
                                killhotspot=0;
                        }
 
-                       if(!editorenabled&&gameon&&!mainmenu){
+                       if(!editorenabled&&gameon&&!mainmenu) {
                                if(changedelay!=-999)
                     changedelay-=multiplier/7;
                                if(player[0].dead)
@@ -7827,17 +7786,16 @@ void    Game::TickOnceAfter(){
                         (player[0].dead||
                          (alldead&&maptype==mapkilleveryone)||
                          (winhotspot)||
-                         (killhotspot))&&
-                        !winfreeze)
+                         (killhotspot)))
                     loading=1;
                                if((player[0].dead||
                             (alldead&&maptype==mapkilleveryone)||
                             (winhotspot)||
                             (windialogue)||
                             (killhotspot))&&
-                        changedelay<=0){
-                    if(whichlevel!=-2&&!loading&&!player[0].dead){
-                        winfreeze=1;
+                        changedelay<=0) {
+                    if(whichlevel!=-2&&!loading&&!player[0].dead) {
+                        winfreeze=true;
                         changedelay=-999;
                     }
                     if(player[0].dead)
@@ -7845,19 +7803,18 @@ void    Game::TickOnceAfter(){
                                }
                        }
 
-                       if(campaign)
-                               if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)
+                       if(campaign) {
+                // campaignchoosenext determines what to do when the level is complete:
+                // 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)
                                                endgame=1;
-                               else if(mainmenu==0&&winfreeze){
-                                       if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
-                                               stealthloading=1;
-                                       else
-                        stealthloading=0;
+                               } else if(mainmenu==0&&winfreeze) {
+                                       stealthloading = (campaignchoosenext[campaignchoicewhich[whichchoice]]==2);
 
                                        if(!stealthloading){
-                                               float gLoc[3]={0,0,0};
-                                               float vel[3]={0,0,0};
                                                fireSound(firestartsound);
 
                                                flash();
@@ -7865,72 +7822,13 @@ void    Game::TickOnceAfter(){
 
                                        startbonustotal=0;
 
-                                       ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
-                                       ipstream.ignore(256,':');
-                                       ipstream >> campaignnumlevels;
-                                       for(int i=0;i<campaignnumlevels;i++){
-                                               ipstream.ignore(256,':');
-                                               ipstream.ignore(256,':');
-                                               ipstream.ignore(256,' ');
-                                               ipstream >> campaignmapname[i];
-                                               ipstream.ignore(256,':');
-                                               ipstream >> campaigndescription[i];
-                                               for(int j=0;j<256;j++){
-                                                       if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
-                                               }
-                                               ipstream.ignore(256,':');
-                                               ipstream >> campaignchoosenext[i];
-                                               ipstream.ignore(256,':');
-                                               ipstream >> campaignnumnext[i];
-                                               for(int j=0;j<campaignnumnext[i];j++){
-                                                       ipstream.ignore(256,':');
-                                                       ipstream >> campaignnextlevel[i][j];
-                                                       campaignnextlevel[i][j]-=1;
-                                               }
-                                               ipstream.ignore(256,':');
-                                               ipstream >> campaignlocationx[i];
-                                               ipstream.ignore(256,':');
-                                               ipstream >> campaignlocationy[i];
-                                       }
-                                       ipstream.close();
-
-                                       for(int i=0;i<campaignnumlevels;i++){
-                                               levelvisible[i]=0;
-                                               levelhighlight[i]=0;
-                                       }
-
-
-                                       for(int i=0;i<campaignnumlevels;i++){
-                                               levelvisible[i]=0;
-                                               levelhighlight[i]=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;
-                                       whichlevelstart=accountactive->getCampaignChoicesMade()-1;
-                                       if(whichlevelstart<0){
-                                               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;
-                                               }
-                                       }
+                                       LoadCampaign();
 
                                        loading=2;
                                        loadtime=0;
                                        targetlevel=7;
-                                       if(!firstload)LoadStuff();
+                                       if(!firstload)
+                                               LoadStuff();
                                        whichchoice=0;
                                        visibleloading=1;
                                        stillloading=1;
@@ -7938,10 +7836,11 @@ void    Game::TickOnceAfter(){
                                        campaign=1;
                                        mainmenu=0;
                                        gameon=1;
-                                       pause_sound(stream_music3);
+                                       pause_sound(stream_menutheme);
 
                                        stealthloading=0;
                                }
+            }
 
             if(loading==3)
                 loading=0;
@@ -7958,7 +7857,6 @@ void      Game::TickOnceAfter(){
        facing=DoRotation(facing,0,0-rotation,0);
        viewerfacing=facing;
 
-       brotate=0;
        if(!cameramode){
                if((animation[player[0].targetanimation].attack!=3&&animation[player[0].currentanimation].attack!=3)||player[0].skeleton.free)target=player[0].coords+player[0].currentoffset*(1-player[0].target)*player[0].scale+player[0].targetoffset*player[0].target*player[0].scale-player[0].facing*.05;
                else target=player[0].oldcoords+player[0].currentoffset*(1-player[0].target)*player[0].scale+player[0].targetoffset*player[0].target*player[0].scale-player[0].facing*.05;