From 2edee4153ff2829f28ca0136520eb9cc37d49dbe Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20BERNIGAUD?= Date: Tue, 10 May 2011 20:51:07 +0200 Subject: [PATCH] Some cleans, some duplicated code corrected. --- Source/Game.cpp | 2 - Source/Game.h | 3 +- Source/GameDraw.cpp | 118 +++++++++++++++++++++++--------------------- Source/GameTick.cpp | 80 ++++-------------------------- Source/Globals.cpp | 74 +++++++++++++-------------- 5 files changed, 110 insertions(+), 167 deletions(-) diff --git a/Source/Game.cpp b/Source/Game.cpp index 9cdf9eb..07b3dd8 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -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)); diff --git a/Source/Game.h b/Source/Game.h index 74e3a5d..5243716 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -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); diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 64e9288..74abd02 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -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> 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> 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;igetCampaignChoicesMade();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.5||oldmainmenu!=mainmenu){ if(mainmenu==5){ - ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt")); - ipstream.ignore(256,':'); - ipstream >> campaignnumlevels; - for(i=0;i> 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> campaignnextlevel[i][j]; - campaignnextlevel[i][j]-=1; - } - ipstream.ignore(256,':'); - ipstream >> campaignlocationx[i]; - ipstream.ignore(256,':'); - ipstream >> campaignlocationy[i]; - } - ipstream.close(); - - for(i=0;igetCampaignChoicesMade():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;i2) 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> 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> 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;igetCampaignChoicesMade();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