From a5418eb653c419fc82aca6b63b027172f8a97d97 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20BERNIGAUD?= Date: Sat, 14 May 2011 16:01:18 +0200 Subject: [PATCH] cleanup of campaign levels handling. --- Source/Game.cpp | 11 --- Source/Game.h | 68 ++++++++++++++-- Source/GameDraw.cpp | 156 +++++++++++++++++-------------------- Source/GameInitDispose.cpp | 4 +- Source/GameTick.cpp | 18 ++--- 5 files changed, 143 insertions(+), 114 deletions(-) diff --git a/Source/Game.cpp b/Source/Game.cpp index a441e0c..1f48171 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -103,17 +103,6 @@ Game::Game() */ stealthloading = 0; - campaignnumlevels = 0; - - memset(campaignmapname, 0, sizeof(campaignmapname)); - memset(campaigndescription, 0, sizeof(campaigndescription)); - memset(campaignchoosenext, 0, sizeof(campaignchoosenext)); - memset(campaignnumnext, 0, sizeof(campaignnumnext)); - memset(campaignnextlevel, 0, sizeof(campaignnextlevel)); - memset(campaignlocationx, 0, sizeof(campaignlocationx)); - memset(campaignlocationy, 0, sizeof(campaignlocationy)); - memset(campaignlocationy, 0, sizeof(campaignlocationy)); - whichchoice = 0; actuallevel = 0; diff --git a/Source/Game.h b/Source/Game.h index 97e3487..19604e1 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -65,6 +65,65 @@ extern GLuint rabbittexture; struct TextureInfo; +class CampaignLevel +{ +private: + struct Position + { + int x; + int y; + }; +public: + std::string mapname; + std::string description; + int choosenext; + /* + 0 = Immediately load next level at the end of this one. + 1 = Go back to the world map. + 2 = Don't bring up the Fiery loading screen. Maybe other things, I've not investigated. + */ + //int numnext; // 0 on final level. As David said: he meant to add story branching, but he eventually hadn't. + std::vector nextlevel; + Position location; + + CampaignLevel() { + choosenext = 1; + location.x = 0; + location.y = 0; + } + + istream& operator<< (istream& is) { + is.ignore(256,':'); + is.ignore(256,':'); + is.ignore(256,' '); + is >> mapname; + is.ignore(256,':'); + is >> description; + for(int pos = description.find('_');pos!=string::npos;pos = description.find('_',pos)) { + description.replace(pos,1,1,' '); + } + is.ignore(256,':'); + is >> choosenext; + is.ignore(256,':'); + int numnext,next; + is >> numnext; + for(int j=0;j> next; + nextlevel.push_back(next-1); + } + is.ignore(256,':'); + is >> location.x; + is.ignore(256,':'); + is >> location.y; + return is; + } + + friend istream& operator>> (istream& is, CampaignLevel& cl) { + return cl << is; + } +}; + class Game { public: @@ -135,14 +194,7 @@ class Game bool stealthloading; - int campaignnumlevels; - char campaignmapname[50][256]; - char campaigndescription[50][256]; - int campaignchoosenext[50]; - int campaignnumnext[50]; // 0 on final level. As David said: he meant to add story branching, but he eventually hadn't. - int campaignnextlevel[50][10]; - int campaignlocationx[50]; - int campaignlocationy[50]; + std::vector campaignlevels; int whichchoice; int actuallevel; diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 2795bd7..173b2f8 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -2023,30 +2023,13 @@ void Game::LoadCampaign() { return; ifstream ipstream(ConvertFileName((":Data:Campaigns:"+accountactive->getCurrentCampaign()+".txt").c_str())); 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]; + int numlevels; + ipstream >> numlevels; + campaignlevels.clear(); + for(int i=0;i> cl; + campaignlevels.push_back(cl); } ipstream.close(); @@ -2066,7 +2049,6 @@ void Game::LoadCampaign() { } void Game::DrawMenu() { - int i,j; static float lastcheck; lastcheck+=multiplier; @@ -2342,49 +2324,40 @@ void Game::DrawMenu() { } if(mainmenu==5){ - nummenuitems=NB_CAMPAIGN_MENU_ITEM+1+accountactive->getCampaignChoicesMade()+(accountactive->getCampaignChoicesMade()>0?campaignnumnext[accountactive->getCampaignChoicesMade()-1]:1); + nummenuitems=NB_CAMPAIGN_MENU_ITEM+1+accountactive->getCampaignChoicesMade()+(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel.size():1); sprintf (menustring[0], "%s",accountactive->getName()); startx[0]=5; starty[0]=400; - endx[0]=startx[0]+strlen(menustring[0])*10; - endy[0]=starty[0]+20; sprintf (menustring[1], "Tutorial"); startx[1]=5; starty[1]=300; - endx[1]=startx[1]+strlen(menustring[1])*10; - endy[1]=starty[1]+20; sprintf (menustring[2], "Challenge"); startx[2]=5; starty[2]=240; - endx[2]=startx[2]+strlen(menustring[2])*10; - endy[2]=starty[2]+20; sprintf (menustring[3], "Delete User"); startx[3]=400; starty[3]=10; - endx[3]=startx[3]+strlen(menustring[3])*10; - endy[3]=starty[3]+20; sprintf (menustring[4], "Main Menu"); startx[4]=5; starty[4]=10; - endx[4]=startx[4]+strlen(menustring[4])*10; - endy[4]=starty[4]+20; sprintf (menustring[5], "Change User"); startx[5]=5; - endx[5]=startx[5]+strlen(menustring[5])*10; starty[5]=180; - endy[5]=starty[5]+20; sprintf (menustring[6], "Campaign : %s", accountactive->getCurrentCampaign().c_str()); startx[6]=200; - endx[6]=startx[6]+strlen(menustring[6])*10; starty[6]=420; - endy[6]=starty[6]+20; + + for(int i=0;igetCampaignChoicesMade()) { - for(i=0;igetCampaignChoicesMade();i++) { - sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+i], "%s", campaigndescription[i]); - startx[NB_CAMPAIGN_MENU_ITEM+1+i]=30+120+campaignlocationx[i]*400/512; - starty[NB_CAMPAIGN_MENU_ITEM+1+i]=30+30+(512-campaignlocationy[i])*400/512; + cout << "niveaux passés" << endl; + for(int i=0;igetCampaignChoicesMade();i++) { + cout << campaignlevels[i].location.x << "x" << campaignlevels[i].location.y << endl; + sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+i], "%s", campaignlevels[i].description.c_str()); + startx[NB_CAMPAIGN_MENU_ITEM+1+i]=30+120+campaignlevels[i].location.x*400/512; + starty[NB_CAMPAIGN_MENU_ITEM+1+i]=30+30+(512-campaignlevels[i].location.y)*400/512; endx[NB_CAMPAIGN_MENU_ITEM+1+i]=startx[NB_CAMPAIGN_MENU_ITEM+1+i]+10; endy[NB_CAMPAIGN_MENU_ITEM+1+i]=starty[NB_CAMPAIGN_MENU_ITEM+1+i]+10; + cout << "-->" << startx[NB_CAMPAIGN_MENU_ITEM+1+i] << "x" << starty[NB_CAMPAIGN_MENU_ITEM+1+i] << endl; } - for(i=0;igetCampaignChoicesMade()-1];i++) { - int j = campaignnextlevel[accountactive->getCampaignChoicesMade()-1][i]; - sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+j], "%s", campaigndescription[j]); - startx[NB_CAMPAIGN_MENU_ITEM+1+j]=30+120+campaignlocationx[j]*400/512; - starty[NB_CAMPAIGN_MENU_ITEM+1+j]=30+30+(512-campaignlocationy[j])*400/512; + cout << "niveaux à choisir" << endl; + for(int i=0;igetCampaignChoicesMade()-1].nextlevel.size();i++) { + int j = campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[i]; + cout << campaignlevels[j].location.x << "x" << campaignlevels[j].location.y << endl; + sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+j], "%s", campaignlevels[j].description.c_str()); + startx[NB_CAMPAIGN_MENU_ITEM+1+j]=30+120+campaignlevels[j].location.x*400/512; + starty[NB_CAMPAIGN_MENU_ITEM+1+j]=30+30+(512-campaignlevels[j].location.y)*400/512; endx[NB_CAMPAIGN_MENU_ITEM+1+j]=startx[NB_CAMPAIGN_MENU_ITEM+1+j]+10; endy[NB_CAMPAIGN_MENU_ITEM+1+j]=starty[NB_CAMPAIGN_MENU_ITEM+1+j]+10; + cout << "-->" << startx[NB_CAMPAIGN_MENU_ITEM+1+j] << "x" << starty[NB_CAMPAIGN_MENU_ITEM+1+j] << endl; } } else { - sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1], "%s", campaigndescription[0]); - startx[NB_CAMPAIGN_MENU_ITEM+1]=30+120+campaignlocationx[0]*400/512; - starty[NB_CAMPAIGN_MENU_ITEM+1]=30+30+(512-campaignlocationy[0])*400/512; + cout << "premier niveau" << endl; + sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1], "%s", campaignlevels[0].description.c_str()); + startx[NB_CAMPAIGN_MENU_ITEM+1]=30+120+campaignlevels[0].location.x*400/512; + starty[NB_CAMPAIGN_MENU_ITEM+1]=30+30+(512-campaignlevels[0].location.y)*400/512; endx[NB_CAMPAIGN_MENU_ITEM+1]=startx[NB_CAMPAIGN_MENU_ITEM+1]+10; endy[NB_CAMPAIGN_MENU_ITEM+1]=starty[NB_CAMPAIGN_MENU_ITEM+1]+10; } + cout << nummenuitems << " items" << endl; } @@ -2479,7 +2460,7 @@ void Game::DrawMenu() { num=1; - for(i=0;igetName()); startx[num]=10; starty[num]=360-20-20*num; @@ -2491,8 +2472,8 @@ void Game::DrawMenu() { sprintf (menustring[num], "Back"); startx[num]=10; - endx[num]=startx[num]+strlen(menustring[num])*10; starty[num]=10; + endx[num]=startx[num]+strlen(menustring[num])*10; endy[num]=starty[num]+20; } if(mainmenu==8){ @@ -2520,26 +2501,28 @@ void Game::DrawMenu() { nummenuitems=2+numchallengelevels; char temp[255]; - for(j=0;jgetHighScore(j)); - strcat(menustring[j],temp); - for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' '; - menustring[j][32]='\0'; - sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(j)-(int)(accountactive->getFastTime(j))%60)/60)); - strcat(menustring[j],temp); - if((int)(accountactive->getFastTime(j))%60<10)strcat(menustring[j],"0"); - sprintf (temp, "%d",(int)(accountactive->getFastTime(j))%60); - strcat(menustring[j],temp); - - startx[j]=10; - starty[j]=400-j*25; - endx[j]=startx[j]+strlen(menustring[j])*10; - endy[j]=starty[j]+20; + for(int i=0;igetHighScore(i)); + for(int j=strlen(temp);j<(32-17);j++) + strcat(temp," "); + name+=temp; + sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(i)-(int)(accountactive->getFastTime(i))%60)/60)); + if((int)(accountactive->getFastTime(i))%60<10)strcat(temp,"0"); + name+=temp; + sprintf (temp, "%d",(int)(accountactive->getFastTime(i))%60); + name+=temp; + + sprintf(menustring[i],"%s",name.c_str()); + + startx[i]=10; + starty[i]=400-i*25; + endx[i]=startx[i]+strlen(menustring[i])*10; + endy[i]=starty[i]+20; } sprintf (menustring[numchallengelevels], "Back"); @@ -2585,10 +2568,13 @@ void Game::DrawMenu() { starty[3]=10; endy[3]=starty[3]+20; - for(i=0;i<255;i++)menustring[4][i]='\0'; + for(int i=0;i<255;i++) + menustring[4][i]='\0'; sprintf (temp, "Your score:"); strcpy(menustring[4],temp); - for(i=0;i<20;i++)if(menustring[4][i]=='\0')menustring[4][i]=' '; + for(int i=0;i<20;i++) + if(menustring[4][i]=='\0') + menustring[4][i]=' '; menustring[4][20]='\0'; sprintf (temp, "%d",(int)accountactive->getCampaignScore()); strcat(menustring[4],temp); @@ -2596,10 +2582,12 @@ void Game::DrawMenu() { endx[4]=startx[4]+strlen(menustring[4])*10; starty[4]=200; endy[4]=starty[4]+20; - for(i=0;i<255;i++)menustring[5][i]='\0'; + for(int i=0;i<255;i++) + menustring[5][i]='\0'; sprintf (temp, "Highest score:"); strcpy(menustring[5],temp); - for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' '; + for(int i=0;i<20;i++) + if(menustring[5][i]=='\0')menustring[5][i]=' '; menustring[5][20]='\0'; sprintf (temp, "%d",(int)accountactive->getCampaignHighScore()); strcat(menustring[5],temp); @@ -2671,14 +2659,14 @@ void Game::DrawMenu() { selected=-1; - for(i=0;istartx[i]&&(mousecoordh/screenwidth*640)starty[i]&&480-(mousecoordv/screenheight*480)0) && (i!=NB_CAMPAIGN_MENU_ITEM) ) selected=i; } } - for(i=0;i1) selectedlong[i]=1; @@ -2782,7 +2770,7 @@ void Game::DrawMenu() { glPushMatrix(); // Store The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix glEnable(GL_TEXTURE_2D); - for(j=0;j0) { @@ -2859,7 +2847,7 @@ void Game::DrawMenu() { glPopMatrix(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); - for(i=0;i<15;i++) + for(int i=0;i<15;i++) { if(1-((float)i)/15-(1-selectedlong[j])>0) { @@ -2998,7 +2986,7 @@ void Game::DrawMenu() { glEnable(GL_BLEND); //glDisable(GL_ALPHA_TEST); if(j<4) glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Black is transparent - for(i=0;i<10;i++) + for(int i=0;i<10;i++) { if(1-((float)i)/10-(1-selectedlong[j])>0) { diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 7edf75d..65780a0 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -776,9 +776,9 @@ void Game::InitGame() LOG("Initializing sound system..."); - int output = -1; - #if PLATFORM_LINUX + int output = -1; + extern bool cmdline(const char *cmd); unsigned char rc = 0; output = OPENAL_OUTPUT_ALSA; // Try alsa first... diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 4cae8b1..4048f87 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -5612,10 +5612,10 @@ void Game::MenuTick(){ else LoadStuff(); whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-1-accountactive->getCampaignChoicesMade(); - actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignnextlevel[accountactive->getCampaignChoicesMade()-1][whichchoice]:0); + actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[whichchoice]:0); visibleloading=1; stillloading=1; - Loadlevel(campaignmapname[actuallevel]); + Loadlevel(campaignlevels[actuallevel].mapname.c_str()); campaign=1; mainmenu=0; gameon=1; @@ -5871,7 +5871,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[actuallevel]==1) { + if(campaign&&winfreeze&&mainmenu==0&&campaignlevels[actuallevel].choosenext==1) { mainmenu=5; gameon=0; winfreeze=0; @@ -7699,7 +7699,7 @@ void Game::TickOnceAfter(){ fireSound(firestartsound); - Loadlevel(campaignmapname[accountactive->getCampaignChoicesMade()]); + Loadlevel(campaignlevels[accountactive->getCampaignChoicesMade()].mapname.c_str()); fireSound(); @@ -7733,11 +7733,11 @@ void Game::TickOnceAfter(){ // 0 = load next level // 1 = go back to level select screen // 2 = stealthload next level - if(mainmenu==0&&winfreeze&&(campaignchoosenext[actuallevel])==1){ - if(campaignnumnext[actuallevel]==0) + if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1){ + if(campaignlevels[actuallevel].nextlevel.empty()) endgame=1; } else if(mainmenu==0&&winfreeze) { - stealthloading = (campaignchoosenext[actuallevel]==2); + stealthloading = (campaignlevels[actuallevel].choosenext==2); if(!stealthloading){ fireSound(firestartsound); @@ -7755,10 +7755,10 @@ void Game::TickOnceAfter(){ if(!firstload) LoadStuff(); whichchoice=0; - actuallevel=campaignnextlevel[actuallevel][0]; + actuallevel=campaignlevels[actuallevel].nextlevel.front(); visibleloading=1; stillloading=1; - Loadlevel(campaignmapname[actuallevel]); + Loadlevel(campaignlevels[actuallevel].mapname.c_str()); campaign=1; mainmenu=0; gameon=1; -- 2.39.5