]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
No more black background for the map, some little cleanup
[lugaru.git] / Source / GameTick.cpp
index 7f723474709779567fb9cdc4411f8a87ec361b55..c9e3a9691ff0aca2851ebe9c47d0bd5df776d0f3 100644 (file)
@@ -1413,10 +1413,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;
 
@@ -1448,8 +1446,6 @@ void Game::Loadlevel(const char *name){
                tutorialmaxtime=1;
        }
        loadingstuff=1;
-       if(!firstload)
-               oldlevel=50;
        pause_sound(whooshsound);
        pause_sound(stream_firesound);
 
@@ -1528,7 +1524,7 @@ void Game::Loadlevel(const char *name){
                if(console){
                        emit_sound_np(consolesuccesssound);
                        freeze=0;
-                       console=0;
+                       console=false;
                }
 
                if(!stealthloading){
@@ -1638,8 +1634,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;
@@ -1719,11 +1713,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;
                                }
                        }
@@ -1875,9 +1869,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++){
@@ -1941,8 +1932,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);
 
@@ -2243,17 +2234,17 @@ void Game::MenuTick(){
                                                if(difficulty>2) difficulty=0;
                                                break;
                                        case 4:
-                                               ismotionblur = 1-ismotionblur;
+                                               ismotionblur = !ismotionblur;
                                                break;
                                        case 5:
-                                               decals = 1-decals;
+                                               decals = !decals;
                                                break;
                                        case 6:
-                                               musictoggle = 1-musictoggle;
+                                               musictoggle = !musictoggle;
 
-                                               if(musictoggle)
+                                               if(musictoggle) {
                                                  emit_stream_np(stream_menutheme);
-                                               else {
+                                               else {
                                                        pause_sound(leveltheme);
                                                        pause_sound(stream_fighttheme);
                                                        pause_sound(stream_menutheme);
@@ -2278,7 +2269,7 @@ void Game::MenuTick(){
                                                mainmenu=gameon?2:1;
                                                break;
                                        case 9:
-                                               invertmouse = 1-invertmouse;
+                                               invertmouse = !invertmouse;
                                                break;
                                        case 10:
                                                usermousesensitivity+=.2;
@@ -2471,16 +2462,6 @@ void Game::MenuTick(){
         }
     }
 
-    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_menutheme], 22050);
 
     if(entername) {
@@ -3327,9 +3308,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;
@@ -5888,13 +5866,11 @@ 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)){
@@ -5948,25 +5924,36 @@ void Game::Tick(){
     18 stereo configuration
     */
         
-       if(!console){
+       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)))){
+                (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
                        selected=-1;
             if(mainmenu==0&&!winfreeze)
                 mainmenu=2; //pause
-            else if(mainmenu==0&&winfreeze&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1){
-                mainmenu=100;
-                gameon=0;
-                winfreeze=0;
-            }else if(mainmenu==1||mainmenu==2)
+            else if(mainmenu==1||mainmenu==2){
                 mainmenu=0; //unpause
+            }
             //play menu theme
-            if(musictoggle&&(mainmenu==1||mainmenu==2||mainmenu==100)){
+            if(musictoggle&&(mainmenu==1||mainmenu==2)){
                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
                 emit_stream_np(stream_menutheme);
                 pause_sound(leveltheme);
@@ -5991,17 +5978,17 @@ void Game::Tick(){
                     mainmenu=gameon?2:1; break;
                 case 4: case 18:
                     mainmenu=3; break;
-                case 6: case 7: case 9: case 10: case 100:
+                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;
@@ -6036,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 {
@@ -6100,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;
                        }
@@ -6460,8 +6447,6 @@ void Game::Tick(){
                 }
             }
 
-            static float keyrefreshdelay=0,bigrefreshdelay=0;
-
             if(!player[0].jumpkeydown){
                 player[0].jumptogglekeydown=0;
             }
@@ -6484,8 +6469,6 @@ void Game::Tick(){
 
                 hawkcalldelay=16+abs(Random()%8);
             }
-            static float temptexdetail;
-
 
             doDebugKeys();
 
@@ -6599,8 +6582,6 @@ void Game::Tick(){
                         player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
                     }
 
-                    bool pause;
-
                     if(leveltime<.5)
                         numenvsounds=0;
 
@@ -7558,7 +7539,6 @@ void Game::TickOnceAfter(){
        static XYZ coltarget;
        static XYZ target;
        static XYZ col;
-       static float brotate;
        static XYZ facing;
        static float changedelay;
        static bool alldead;
@@ -7729,12 +7709,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;
@@ -7751,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)
@@ -7790,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)
@@ -7808,19 +7787,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();
@@ -7828,67 +7806,7 @@ 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;
@@ -7906,6 +7824,7 @@ void Game::TickOnceAfter(){
 
                                        stealthloading=0;
                                }
+            }
 
             if(loading==3)
                 loading=0;
@@ -7922,7 +7841,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;