]> git.jsancho.org Git - lugaru.git/commitdiff
Problem fixed (LoadCampaign added when going back to campaign menu)
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Wed, 11 May 2011 16:49:18 +0000 (18:49 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Wed, 11 May 2011 16:49:18 +0000 (18:49 +0200)
Source/Account.cpp
Source/Account.h
Source/Frustum.cpp
Source/Game.cpp
Source/GameDraw.cpp
Source/GameTick.cpp
Source/Input.cpp
Source/PhysicsMath.h

index 45e1300e68c827c6dccf45fbe5f5900cb5827b1c..beb5f46a041787aae4e675b1588de9449ab21584 100644 (file)
@@ -32,7 +32,7 @@ extern bool debugmode;
 
 vector<Account*> Account::accounts = vector<Account*>();
 
-Account::Account(string n) {
+Account::Account(string n) : campaignProgress() {
        name = string(n);
        difficulty = 0;
        progress = 0;
@@ -41,7 +41,15 @@ Account::Account(string n) {
        memset(fasttime, 0, sizeof(fasttime));
        memset(unlocked, 0, sizeof(unlocked));
        
-       currentCampaign = "main";
+       setCurrentCampaign("main");
+}
+
+void Account::setCurrentCampaign(string name) {
+       currentCampaign = name;
+       campaignProgress[name].highscore = 0;
+       campaignProgress[name].fasttime = 0;
+       campaignProgress[name].score = 0;
+       campaignProgress[name].time = 0;
 }
 
 Account* Account::add(string name) {
@@ -102,7 +110,6 @@ Account* Account::loadFile(string filename) {
        FILE *tfile;
        int numaccounts;
        int accountactive;
-       int j;
        
        tfile=fopen(ConvertFileName(filename.c_str()), "rb" );
        
@@ -126,7 +133,7 @@ Account* Account::loadFile(string filename) {
                                int t;
                                char c;
                                funpackf(tfile, "Bi",  &t);
-                               for(j=0;j<t;j++)
+                               for(int j=0;j<t;j++)
                                {
                                        funpackf(tfile, "Bb",  &c);
                                        campaignName.append(1,c);
@@ -138,7 +145,7 @@ Account* Account::loadFile(string filename) {
                                funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].highscore));
                                int campaignchoicesmade,campaignchoice;
                                funpackf(tfile, "Bi", &campaignchoicesmade);
-                               for(j=0;j<campaignchoicesmade;j++)
+                               for(int j=0;j<campaignchoicesmade;j++)
                                {
                                        funpackf(tfile, "Bi", &campaignchoice);
                                        if (campaignchoice >= 10) // what is that for?
@@ -150,19 +157,19 @@ Account* Account::loadFile(string filename) {
                        }
                        
                        funpackf(tfile, "Bf", &(acc->points));
-                       for(j=0;j<50;j++)
+                       for(int i=0;i<50;i++)
                        {
-                               funpackf(tfile, "Bf", &(acc->highscore[j]));
-                               funpackf(tfile, "Bf", &(acc->fasttime[j]));
+                               funpackf(tfile, "Bf", &(acc->highscore[i]));
+                               funpackf(tfile, "Bf", &(acc->fasttime[i]));
                        }
-                       for(j=0;j<60;j++)
+                       for(int i=0;i<60;i++)
                        {
-                               funpackf(tfile, "Bb",  &(acc->unlocked[j]));
+                               funpackf(tfile, "Bb",  &(acc->unlocked[i]));
                        }
                        int temp;
                        char ctemp;
                        funpackf(tfile, "Bi",  &temp);
-                       for(j=0;j<temp;j++)
+                       for(int i=0;i<temp;i++)
                        {
                                funpackf(tfile, "Bb",  &ctemp);
                                acc->name.append(1,ctemp);
index acd285061266b722d939bd3146425f65a36b21d8..388c064fcc6c2b6063614aeb95b927737beee55f 100644 (file)
@@ -73,6 +73,7 @@ class Account {
                float getHighScore(int i) { return highscore[i]; };
                float getFastTime(int i) { return fasttime[i]; };
                int getProgress() { return progress; };
+               void setCurrentCampaign(std::string name);
                
                static int getNbAccounts() { return accounts.size(); };
        private:
index 9425ddeeea7ac9cbccf34c8837fab3afacf735b5..f8fb2f51758380d9e169cd464a27715d9c087c80 100644 (file)
@@ -30,7 +30,6 @@ void FRUSTUM::
        static float projmatrix[16];
        static float mvmatrix[16];
        static float clip[16];
-       static float t;
        
        glGetFloatv(GL_PROJECTION_MATRIX, projmatrix);
        glGetFloatv(GL_MODELVIEW_MATRIX, mvmatrix);
index 5eb661fb99dc12e9fd4205a98ccf988677e18991..723396bd197b1370da05131663fdf5214020cb2a 100644 (file)
@@ -166,7 +166,7 @@ Game::Game()
        scoreadded = 0;
        numchallengelevels = 0;
 
-       console = 0;
+       console = false;
        archiveselected = 0;
 
        memset(consoletext, 0, sizeof(consoletext));
index 70b6716c177561b4c5e70ec1db3fd21acacf674f..ad542f11c819def708c2f29c9c22ad5fd59e7e33 100644 (file)
@@ -2674,17 +2674,16 @@ void Game::DrawMenu()
 
        if(mainmenu==1||mainmenu==2)
                for(i=1;i<4;i++){
-                       if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
+                       if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]) {
                                selected=i;
                        }
                }
 
        if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==18)
-               for(i=0;i<nummenuitems;i++){
-                       if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
-                               if(mainmenu!=5)selected=i;
-                               if(mainmenu==5&&(i!=0&&i!=6))selected=i;
-                               if(mainmenu==9&&(i!=numchallengelevels+1))selected=i; // seem useless, if mainmenu==9 then mainmenu!=5, so selected==i.
+               for(i=0;i<nummenuitems;i++) {
+                       if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]) {
+                               if(mainmenu!=5) selected=i;
+                               else if( (i!=0) && (i!=6) ) selected=i;
                        }
                }
 
index 11b72f65bbaa9322848f51834025af4fa1361008..2a9cbd519dba303c29fc98491b3a6c2e35b64978 100644 (file)
@@ -1524,7 +1524,7 @@ void Game::Loadlevel(const char *name){
                if(console){
                        emit_sound_np(consolesuccesssound);
                        freeze=0;
-                       console=0;
+                       console=false;
                }
 
                if(!stealthloading){
@@ -5870,7 +5870,7 @@ void Game::Tick(){
                displaytime[i]+=multiplier;
        }
 
-       keyboardfrozen=0;
+       keyboardfrozen=false;
     Input::Tick();
 
        if(Input::isKeyPressed(SDLK_F6)){
@@ -5929,7 +5929,7 @@ void Game::Tick(){
                if(mainmenu&&endgame==1)
             mainmenu=10;
         //go to level select after completing a campaign level
-        if(campaign&&winfreeze&&mainmenu==0&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1){
+        if(campaign&&winfreeze&&mainmenu==0&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1) {
             mainmenu=5;
             gameon=0;
             winfreeze=0;
@@ -5940,11 +5940,12 @@ void Game::Tick(){
                 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)))){
+                (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
                        selected=-1;
             if(mainmenu==0&&!winfreeze)
                 mainmenu=2; //pause
@@ -6022,10 +6023,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 {
@@ -6086,9 +6087,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;
                        }
@@ -7730,7 +7731,7 @@ void Game::TickOnceAfter(){
                                killhotspot=0;
                        }
 
-                       if(!editorenabled&&gameon&&!mainmenu){
+                       if(!editorenabled&&gameon&&!mainmenu) {
                                if(changedelay!=-999)
                     changedelay-=multiplier/7;
                                if(player[0].dead)
@@ -7769,17 +7770,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)
@@ -7787,7 +7787,7 @@ void Game::TickOnceAfter(){
                                }
                        }
 
-                       if(campaign){
+                       if(campaign) {
                 // campaignchoosenext determines what to do when the level is complete:
                 // 0 = load next level
                 // 1 = go back to level select screen
@@ -7795,11 +7795,8 @@ void Game::TickOnceAfter(){
                                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){
                                                fireSound(firestartsound);
index 03a579fe33f1cd19708a125b8ae193436b132d0e..f7ab1ffa3dc6a5328c99a061575f0ba3df1410ca 100644 (file)
@@ -43,7 +43,7 @@ void Input::Tick(){
 }
 
 bool Input::isKeyDown(int k) {
-       if(keyboardfrozen||k>=SDLK_LAST+6) // vraiment utile? à vérifier
+       if(keyboardfrozen||k>=SDLK_LAST+6) // really useful? check that.
         return false;
     return keyDown[k];
 }
index a26c88c60e275eadadbcebe2ee26511bce5cab04..75aa7a861e0893decb57f8d6bd5d484479519e55 100644 (file)
@@ -714,7 +714,7 @@ inline      Quaternion      MakeQFromEulerAngles(float x, float y, float z)
 
 inline Vector  MakeEulerAnglesFromQ(Quaternion q)
 {
-       double  r11, r21, r31, r32, r33, r12, r13;
+       double  r11, r21, r31, r32, r33;
        double  q00, q11, q22, q33;
        double  tmp;
        Vector  u;
@@ -733,8 +733,8 @@ inline      Vector  MakeEulerAnglesFromQ(Quaternion q)
        tmp = fabs(r31);
        if(tmp > 0.999999)
        {
-               r12 = 2 * (q.v.x*q.v.y - q.n*q.v.z);
-               r13 = 2 * (q.v.x*q.v.z + q.n*q.v.y);
+               double r12 = 2 * (q.v.x*q.v.y - q.n*q.v.z);
+               double r13 = 2 * (q.v.x*q.v.z + q.n*q.v.y);
 
                u.x = RadiansToDegrees(0.0f); //roll
                u.y = RadiansToDegrees((float) (-(pi/2) * r31/tmp)); // pitch