]> git.jsancho.org Git - lugaru.git/commitdiff
Some cleans, some duplicated code corrected.
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Tue, 10 May 2011 18:51:07 +0000 (20:51 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Tue, 10 May 2011 18:51:07 +0000 (20:51 +0200)
Source/Game.cpp
Source/Game.h
Source/GameDraw.cpp
Source/GameTick.cpp
Source/Globals.cpp

index 9cdf9eb1ca3a5164dd904b29c2a4b7cc6c6c3c20..07b3dd840f7b12577b6eb86551e26aca5c95df1a 100644 (file)
@@ -116,8 +116,6 @@ Game::Game()
        memset(campaignchoosenext, 0, sizeof(campaignchoosenext));
        memset(campaignnumnext, 0, sizeof(campaignnumnext));
        memset(campaignnextlevel, 0, sizeof(campaignnextlevel));
-       int campaignchoicesmade;
-       memset(campaignchoices, 0, sizeof(campaignchoices));
        memset(campaignlocationx, 0, sizeof(campaignlocationx));
        memset(campaignlocationy, 0, sizeof(campaignlocationy));
        memset(campaignlocationy, 0, sizeof(campaignlocationy));
index 74e3a5d29e0eb6861569a644932ac24e4b1aa4d8..5243716ac2e890dcac5062c184d86cafff13d586 100644 (file)
@@ -144,8 +144,6 @@ class Game
                int campaignchoosenext[50];
                int campaignnumnext[50];
                int campaignnextlevel[50][10];
-               int campaignchoicesmade;
-               int campaignchoices[5000];
                int campaignlocationx[50];
                int campaignlocationy[50];
                int campaignchoicenum;
@@ -227,6 +225,7 @@ class Game
                void LoadScreenTexture();
                void LoadStuff();
                void LoadingScreen();
+               void LoadCampaign();
                void FadeLoadingScreen(float howmuch);
                void Dispose();
                int DrawGLScene(StereoSide side);
index 64e9288597014ce51fc43e756181fbadc7d41801..74abd0210cfdc633aaff1945300b1d11f5baa843 100644 (file)
@@ -1998,6 +1998,67 @@ int Game::DrawGLScene(StereoSide side)
        return 0;
 }
 
+void Game::LoadCampaign() {
+       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;
+       }
+
+       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 = (accountactive?accountactive->getCampaignChoicesMade():0)-1;
+       if(whichlevelstart<0){
+               if(accountactive) {
+                       accountactive->setCampaignScore(0);
+                       accountactive->resetFasttime();
+               }
+               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;
+               }
+       }
+}
+
 void Game::DrawMenu()
 {
        int i,j;
@@ -2028,62 +2089,7 @@ void Game::DrawMenu()
        }
        if(lastcheck>.5||oldmainmenu!=mainmenu){
                if(mainmenu==5){
-                       ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
-                       ipstream.ignore(256,':');
-                       ipstream >> campaignnumlevels;
-                       for(i=0;i<campaignnumlevels;i++){
-                               ipstream.ignore(256,':');
-                               ipstream.ignore(256,':');
-                               ipstream.ignore(256,' ');
-                               ipstream >> campaignmapname[i];
-                               ipstream.ignore(256,':');
-                               ipstream >> campaigndescription[i];
-                               for(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(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(i=0;i<campaignnumlevels;i++){
-                               levelvisible[i]=0;
-                               levelhighlight[i]=0;
-                       }
-
-                       levelorder[0]=0;
-                       levelvisible[0]=1;
-                       for(i=0;i<(accountactive?accountactive->getCampaignChoicesMade():0);i++){
-                               levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
-                               levelvisible[levelorder[i+1]]=1;
-                       }
-                       int whichlevelstart = (accountactive?accountactive->getCampaignChoicesMade():0)-1;
-                       if(whichlevelstart<0){
-                               accountactive->setCampaignScore(0);
-                               accountactive->resetFasttime();
-                               campaignchoicenum=1;
-                               campaignchoicewhich[0]=0;
-                       }
-                       else
-                       {
-                               campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
-                               for(i=0;i<campaignchoicenum;i++){
-                                       campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
-                                       levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                                       levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                               }
-                       }
+                       LoadCampaign();
                }
        }
        if(mainmenu==5){
index 7f723474709779567fb9cdc4411f8a87ec361b55..1d40027c53ebcb55723309c48e69a19bbbd3ea6d 100644 (file)
@@ -2243,17 +2243,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 +2278,7 @@ void Game::MenuTick(){
                                                mainmenu=gameon?2:1;
                                                break;
                                        case 9:
-                                               invertmouse = 1-invertmouse;
+                                               invertmouse = !invertmouse;
                                                break;
                                        case 10:
                                                usermousesensitivity+=.2;
@@ -7729,12 +7729,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;
@@ -7828,67 +7828,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;
index d97de52b2c4738fc28e0bdfbee0ee7634996b3cb..fedc0e5a580d44bddcef6f81ba8694588679f3de 100644 (file)
@@ -40,14 +40,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 bool visibleloading = 0;
 
 float volume = 0;
-bool ismotionblur = 0;
+bool ismotionblur = false;
 float usermousesensitivity = 0;
-bool floatjump = 0;
-bool cellophane = 0;
-bool autoslomo = 0;
-bool decals = 0;
-bool invertmouse = 0;
-bool texttoggle = 0;
+bool floatjump = false;
+bool cellophane = false;
+bool autoslomo = false;
+bool decals = false;
+bool invertmouse = false;
+bool texttoggle = false;
 float blurness = 0;
 float targetblurness = 0;
 float windvar = 0;
@@ -89,32 +89,32 @@ GLubyte bloodText[512*512*3] = {0};
 GLubyte wolfbloodText[512*512*3] = {0};
 float colors[3] = {0};
 int bloodtoggle = 0;
-bool osx = 0;
+bool osx = false;
 float camerashake = 0;
 float woozy = 0;
 float blackout = 0;
-bool foliage = 0;
-bool musictoggle = 0;
+bool foliage = false;
+bool musictoggle = false;
 bool trilinear;
 Weapons weapons;
-bool damageeffects = 0;
+bool damageeffects = false;
 int numplayers = 0;
-bool ambientsound = 0;
-bool mousejump = 0;
-bool freeze = 0;
-bool winfreeze = 0;
+bool ambientsound = false;
+bool mousejump = false;
+bool freeze = false;
+bool winfreeze = false;
 float flashamount = 0,flashr = 0,flashg = 0,flashb = 0;
 int flashdelay = 0;
-bool vblsync = 0;
+bool vblsync = false;
 float motionbluramount = 0;
-bool keyboardfrozen = 0;
-bool loadingstuff = 0;
-bool stillloading = 0;
-bool showpoints = 0;
-bool showdamagebar = 0;
-bool alwaysblur = 0;
-bool immediate = 0;
-bool velocityblur = 0;
+bool keyboardfrozen = false;
+bool loadingstuff = false;
+bool stillloading = false;
+bool showpoints = false;
+bool showdamagebar = false;
+bool alwaysblur = false;
+bool immediate = false;
+bool velocityblur = false;
 int test = 0;
 XYZ windvector;
 short vRefNum = 0;
@@ -148,7 +148,7 @@ float tutorialstagetime = 0;
 float tutorialmaxtime = 0;
 float tutorialsuccess = 0;
 
-bool againbonus = 0;
+bool againbonus = false;
 
 float damagedealt = 0;
 
@@ -157,11 +157,11 @@ int maptype = 0;
 int editoractive = 0;
 int editorpathtype = 0;
 
-bool reversaltrain = 0;
-bool cananger = 0;
-bool canattack = 0;
+bool reversaltrain = false;
+bool cananger = false;
+bool canattack = false;
 
-bool skyboxtexture = 0;
+bool skyboxtexture = false;
 float skyboxr = 0;
 float skyboxg = 0;
 float skyboxb = 0;
@@ -178,20 +178,20 @@ float envsoundlife[30] = {0};
 int numenvsounds;
 
 
-bool tilt2weird = 0;
-bool tiltweird = 0;
-bool midweird = 0;
-bool proportionweird = 0;
+bool tilt2weird = false;
+bool tiltweird = false;
+bool midweird = false;
+bool proportionweird = false;
 bool vertexweird[6] = {0};
 TGAImageRec texture;
-bool debugmode = 0;
+bool debugmode = false;
 
-bool won = 0;
+bool won = false;
 
 
-bool campaign = 0;
+bool campaign = false;
 
-bool gamestarted = 0;
+bool gamestarted = false;
 
 //TextureList textures;