X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGameTick.cpp;h=2a22f2599b82ab15119032fb7495ce4e0c98fab6;hb=7a084f44a89054024b83299709c19a2f67fcaea9;hp=1fba112a8fbf9ff782b06aa07f5fd8f293a83a17;hpb=6bd4d8e827e8e47b78db4a1f236cba2eed7032b4;p=lugaru.git diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 1fba112..2a22f25 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #endif +#include #include #include "Game.h" #include "openal_wrapper.h" @@ -77,10 +78,9 @@ extern bool keyboardfrozen; extern bool loadingstuff; extern XYZ windvector; extern bool debugmode; -static int music1; +static int leveltheme; extern int mainmenu; extern bool visibleloading; -extern int loadscreencolor; extern XYZ envsound[30]; extern float envsoundvol[30]; extern int numenvsounds; @@ -283,40 +283,37 @@ static void ch_map(Game *game, const char *args) campaign = 0; } -static void ch_save(Game *game, const char *args) -{ - char buf[64]; - int i, j, k, l, m, templength; - float headprop, bodyprop, armprop, legprop; - snprintf(buf, 63, ":Data:Maps:%s", args); - - - int mapvers = 12;; - - FILE *tfile; - tfile=fopen( ConvertFileName(buf), "wb" ); - fpackf(tfile, "Bi", mapvers); - fpackf(tfile, "Bi", maptype); - fpackf(tfile, "Bi", hostile); - fpackf(tfile, "Bf Bf", viewdistance, fadestart); - fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb); - fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb); - fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z, player[0].rotation, player[0].targetrotation, player[0].num_weapons); - if(player[0].num_weapons>0&&player[0].num_weapons<5) - for(int j=0;j0&&player[0].num_weapons<5) + for(int j=0;jnumpathpoints); + fpackf(tfile, "Bi", game->numpathpoints); for(int j=0;jnumpathpoints;j++){ fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]); - for(int k=0;knumpathpointconnect[j];k++){ + for(int k=0;knumpathpointconnect[j];k++) fpackf(tfile, "Bi", game->pathpointconnect[j][k]); - } } - fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius); + fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius); - fclose(tfile); + fclose(tfile); } static void ch_cellar(Game *game, const char *args) @@ -496,7 +496,7 @@ static void ch_size(Game *game, const char *args) static int find_closest() { int closest = 0; - float closestdist = 1.0/0.0; + float closestdist = std::numeric_limits::max(); for (int i = 1; i < numplayers; i++) { float distance; @@ -640,7 +640,7 @@ static void set_clothes(int pnum, Game *game, const char *args) char buf[64]; snprintf(buf, 63, ":Data:Textures:%s.png", args); - if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize)) + if (!game->AddClothes(buf,&player[pnum].skeleton.skinText[pnum])) return; player[pnum].DoMipmaps(); @@ -1272,9 +1272,9 @@ void Game::Setenvironment(int which) float temptexdetail; environment=which; - pause_sound(stream_music1snow); - pause_sound(stream_music1grass); - pause_sound(stream_music1desert); + pause_sound(stream_snowtheme); + pause_sound(stream_grasstheme); + pause_sound(stream_deserttheme); pause_sound(stream_wind); pause_sound(stream_desertambient); @@ -1402,22 +1402,22 @@ void Game::Setenvironment(int which) } -void Game::Loadlevel(int which){ +void Game::Loadlevel(int which){ stealthloading=0; whichlevel=which; - if (which == -1) { + if(which == -1){ tutoriallevel = -1; Loadlevel("tutorial"); - } else if (which >= 0 && which <= 15) { + }else if(which >= 0 && which <= 15){ char buf[32]; snprintf(buf, 32, "map%d", which + 1); Loadlevel(buf); - } else + }else Loadlevel("mapsave"); } -void Game::Loadlevel(const char *name){ +void Game::Loadlevel(const char *name){ static int oldlevel; int templength; float lamefloat; @@ -1431,27 +1431,30 @@ void Game::Loadlevel(const char *name){ LOG(std::string("Loading level...") + name); - if(!gameon)visibleloading=1; - - if(stealthloading)visibleloading=0; - - if(!stillloading)loadtime=0; + if(!gameon) + visibleloading=1; + if(stealthloading) + visibleloading=0; + if(!stillloading) + loadtime=0; gamestarted=1; numenvsounds=0; //visibleloading=1; - if(tutoriallevel!=-1)tutoriallevel=0; - else tutoriallevel=1; + if(tutoriallevel!=-1) + tutoriallevel=0; + else + tutoriallevel=1; - if(tutoriallevel==1)tutorialstage=0; + if(tutoriallevel==1) + tutorialstage=0; if(tutorialstage==0){ tutorialstagetime=0; tutorialmaxtime=1; } loadingstuff=1; - if(!firstload){ + if(!firstload) oldlevel=50; - } pause_sound(whooshsound); pause_sound(stream_firesound); @@ -1461,29 +1464,21 @@ void Game::Loadlevel(const char *name){ const char *FixedFN = ConvertFileName(buf); int mapvers; - FILE *tfile; + FILE *tfile; tfile=fopen( FixedFN, "rb" ); - if(tfile) - { + if(tfile){ pause_sound(stream_firesound); - - scoreadded=0; windialogue=0; - hostiletime=0; - won=0; - //campaign=0; animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral); numdialogues=0; for(int i=0;i<20;i++) - { dialoguegonethrough[i]=0; - } indialogue=-1; cameramode=0; @@ -1491,10 +1486,13 @@ void Game::Loadlevel(const char *name){ damagedealt=0; damagetaken=0; - if(accountactive)difficulty=accountactive->getDifficulty(); + if(accountactive) + difficulty=accountactive->getDifficulty(); - if(difficulty!=2)minimap=1; - else minimap=0; + if(difficulty!=2) + minimap=1; + else + minimap=0; numhotspots=0; currenthotspot=-1; @@ -1509,9 +1507,7 @@ void Game::Loadlevel(const char *name){ winfreeze=0; for(int i=0;i<100;i++) - { bonusnum[i]=0; - } numfalls=0; numflipfail=0; @@ -1534,84 +1530,83 @@ void Game::Loadlevel(const char *name){ bonus=0; gameon=1; changedelay=0; - if(console) - { + if(console){ emit_sound_np(consolesuccesssound); freeze=0; console=0; } - if(!stealthloading) - { + if(!stealthloading){ terrain.numdecals=0; Sprite::deleteSprites(); for(int i=0;i=15)funpackf(tfile, "Bi", &indemo); - else indemo=0; - if(mapvers>=5)funpackf(tfile, "Bi", &maptype); - else maptype=mapkilleveryone; - if(mapvers>=6)funpackf(tfile, "Bi", &hostile); - else hostile=1; - if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart); + if(mapvers>=15) + funpackf(tfile, "Bi", &indemo); + else + indemo=0; + if(mapvers>=5) + funpackf(tfile, "Bi", &maptype); + else + maptype=mapkilleveryone; + if(mapvers>=6) + funpackf(tfile, "Bi", &hostile); else - { + hostile=1; + if(mapvers>=4) + funpackf(tfile, "Bf Bf", &viewdistance, &fadestart); + else{ viewdistance=100; fadestart=.6; } - if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb); - else - { + if(mapvers>=2) + funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb); + else{ skyboxtexture=1; skyboxr=1; skyboxg=1; skyboxb=1; } - if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb); - else - { + if(mapvers>=10) + funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb); + else{ skyboxlightr=skyboxr; skyboxlightg=skyboxg; skyboxlightb=skyboxb; } - if(!stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons); - if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons); + if(!stealthloading) + funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons); + if(stealthloading) + funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons); player[0].originalcoords=player[0].coords; if(player[0].num_weapons>0&&player[0].num_weapons<5) - { - for(int j=0;j=9) - { funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature); - } - else - { + else{ player[0].whichskin=0; player[0].creature=rabbittype; } @@ -1634,130 +1626,108 @@ void Game::Loadlevel(const char *name){ player[0].lastattack2=-1; player[0].lastattack3=-1; - if(mapvers>=8) - { + //dialogues + if(mapvers>=8){ funpackf(tfile, "Bi", &numdialogues); - if(numdialogues) - { - for(int k=0;k128||templength<=0)templength=128; - int m; - for(m=0;m64||templength<=0)templength=64; - for(m=0;m128||templength<=0) + templength=128; + int m; + for(m=0;m64||templength<=0)templength=64; + for(m=0;m=7) - { + if(mapvers>=7){ funpackf(tfile, "Bi", &numhotspots); - if(numhotspots) - { - for(int i=0;imaxdistance) - { + if(tempdist>maxdistance){ whichclosest=i; maxdistance=tempdist; } @@ -1765,40 +1735,45 @@ void Game::Loadlevel(const char *name){ objects.radius=fast_sqrt(maxdistance); } - if(visibleloading){loadscreencolor=4; LoadingScreen();} + if(visibleloading) + LoadingScreen(); //mapcenter=objects.center; //mapradius=objects.radius; funpackf(tfile, "Bi", &numplayers); int howmanyremoved=0; bool removeanother=0; - if(numplayers>1&&numplayers1&&numplayers=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive); - else player[i-howmanyremoved].howactive=typeactive; - if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale); - else player[i-howmanyremoved].scale=-1; - if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile); - else player[i-howmanyremoved].immobile=0; - if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation); - else player[i-howmanyremoved].rotation=0; + if(mapvers>=5) + funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive); + else + player[i-howmanyremoved].howactive=typeactive; + if(mapvers>=3) + funpackf(tfile, "Bf",&player[i-howmanyremoved].scale); + else + player[i-howmanyremoved].scale=-1; + if(mapvers>=11) + funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile); + else + player[i-howmanyremoved].immobile=0; + if(mapvers>=12) + funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation); + else + player[i-howmanyremoved].rotation=0; player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation; if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){ removeanother=1; howmanyremoved++; } - if(!removeanother) - { - if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5) - { - for(int j=0;j0&&player[i-howmanyremoved].num_weapons<5){ + for(int j=0;j=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]); - else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking; + if(mapvers>=5) + funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]); + else + player[i-howmanyremoved].waypointtype[j] = wpkeepwalking; } funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint); - if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0; + if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1) + player[i-howmanyremoved].waypoint=0; funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow); funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow); funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow); funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult); - if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop); - else - { + if(mapvers>=4) + funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop); + else{ headprop=1; bodyprop=1; armprop=1; legprop=1; } - if(player[i-howmanyremoved].creature==wolftype) - { + if(player[i-howmanyremoved].creature==wolftype){ player[i-howmanyremoved].proportionhead=1.1*headprop; player[i-howmanyremoved].proportionbody=1.1*bodyprop; player[i-howmanyremoved].proportionarms=1.1*armprop; player[i-howmanyremoved].proportionlegs=1.1*legprop; } - if(player[i-howmanyremoved].creature==rabbittype) - { + if(player[i-howmanyremoved].creature==rabbittype){ player[i-howmanyremoved].proportionhead=1.2*headprop; player[i-howmanyremoved].proportionbody=1.05*bodyprop; player[i-howmanyremoved].proportionarms=1.00*armprop; @@ -1850,10 +1825,8 @@ void Game::Loadlevel(const char *name){ } funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes); - if(player[i-howmanyremoved].numclothes) - { - for(int k=0;k30||numpathpoints<0) numpathpoints=0; - if(numpathpoints) - { - for(int j=0;jmaxplayers-1)numplayers=maxplayers-1; - for(int i=0;imaxplayers-1) + numplayers=maxplayers-1; + for(int i=0;i unused +18 stereo configuration +*/ + void Game::MenuTick(){ //menu buttons - if(mainmenu==1||mainmenu==2){ - if(Input::MouseClicked()&&selected==1){ - if(!gameon){ - fireSound(firestartsound); - flash(); - //new game - if(accountactive) { - mainmenu=5; - } else { - mainmenu=7; - } - selected=-1; - }else{ - //resume - mainmenu=0; - pause_sound(stream_music3); - resume_stream(music1); - } - } - - if(Input::MouseClicked()&&selected==2){ - fireSound(); - flash(); - //options - mainmenu=3; - if(newdetail>2)newdetail=detail; - if(newdetail<0)newdetail=detail; - if(newscreenwidth>3000)newscreenwidth=screenwidth; - if(newscreenwidth<0)newscreenwidth=screenwidth; - if(newscreenheight>3000)newscreenheight=screenheight; - if(newscreenheight<0)newscreenheight=screenheight; - } - - if(Input::MouseClicked()&&selected==3){ - fireSound(); - flash(); - if(!gameon){ - //quit - tryquit=1; - pause_sound(stream_music3); - }else{ - //end game - gameon=0; - mainmenu=1; - } - } - } - if(mainmenu==3){ - if(Input::MouseClicked()){ - - if(selected!=-1) - fireSound(); - - switch(selected){ - case 0: { - extern SDL_Rect **resolutions; - bool isCustomResolution = true; - bool found = false; - for(int i = 0; (!found) && (resolutions[i]); i++){ - if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth)) - isCustomResolution = false; - - if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)){ - i++; - if(resolutions[i] != NULL){ - newscreenwidth = (int) resolutions[i]->w; - newscreenheight = (int) resolutions[i]->h; - }else if(isCustomResolution){ - if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)){ - newscreenwidth = (int) resolutions[0]->w; - newscreenheight = (int) resolutions[0]->h; - }else{ - newscreenwidth = screenwidth; - newscreenheight = screenheight; - } - }else{ - newscreenwidth = (int) resolutions[0]->w; - newscreenheight = (int) resolutions[0]->h; - } - found = true; - } - } - - if(!found){ - newscreenwidth = (int) resolutions[0]->w; - newscreenheight = (int) resolutions[0]->h; - } - } break; - case 1: - newdetail++; - if(newdetail>2)newdetail=0; - break; - case 2: - bloodtoggle++; - if(bloodtoggle>2)bloodtoggle=0; - break; - case 3: - difficulty++; - if(difficulty>2)difficulty=0; - break; - case 4: - ismotionblur=1-ismotionblur; - break; - case 5: - decals=1-decals; - break; - case 6: - musictoggle=1-musictoggle; - - if(!musictoggle){ - pause_sound(music1); - pause_sound(stream_music2); - pause_sound(stream_music3); - - for(int i=0;i<4;i++){ - oldmusicvolume[i]=0; - musicvolume[i]=0; - } - } - - if(musictoggle) - emit_stream_np(stream_music3); - break; - case 7: - flash(); - //options - mainmenu=4; - selected=-1; - keyselect=-1; - break; - case 8: - flash(); - - if(newdetail>2)newdetail=detail; - if(newdetail<0)newdetail=detail; - if(newscreenwidth<0)newscreenwidth=screenwidth; - if(newscreenheight<0)newscreenheight=screenheight; - - SaveSettings(*this); - if(mainmenu==3&&gameon)mainmenu=2; - if(mainmenu==3&&!gameon)mainmenu=1; - break; - case 9: - invertmouse=1-invertmouse; - break; - case 10: - usermousesensitivity+=.2; - if(usermousesensitivity>2)usermousesensitivity=.2; - break; - case 11: - volume+=.1f; - if(volume>1.0001f)volume=0; - OPENAL_SetSFXMasterVolume((int)(volume*255)); - break; - case 12: - flash(); - - newstereomode = stereomode; - mainmenu=18; - keyselect=-1; - break; - case 13: - showdamagebar=!showdamagebar; - break; - } - } - } - if(mainmenu==4){ - if(Input::MouseClicked()&&selected!=-1&&!waiting){ - fireSound(); - if(selected<9&&keyselect==-1) - keyselect=selected; - if(keyselect!=-1) - setKeySelected(); - if(selected==9){ - flash(); + + // some specific case where we do something even if the left mouse button is not pressed. + if((mainmenu==5) && (endgame==2)) { + accountactive->endGame(); + endgame=0; + } + if(mainmenu==10) + endgame=2; + if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) ) + stereoseparation-=0.001; + + if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus + switch(mainmenu) { + case 1: + case 2: + switch(selected) { + case 1: + if(gameon) { //resume + mainmenu=0; + pause_sound(stream_menutheme); + resume_stream(leveltheme); + } else { //new game + fireSound(firestartsound); + flash(); + mainmenu=(accountactive?5:7); + selected=-1; + } + break; + case 2: //options + fireSound(); + flash(); + mainmenu=3; + if(newdetail>2) newdetail=detail; + if(newdetail<0) newdetail=detail; + if(newscreenwidth>3000) newscreenwidth=screenwidth; + if(newscreenwidth<0) newscreenwidth=screenwidth; + if(newscreenheight>3000) newscreenheight=screenheight; + if(newscreenheight<0) newscreenheight=screenheight; + break; + case 3: + fireSound(); + flash(); + if(gameon){ //end game + gameon=0; + mainmenu=1; + } else { //quit + tryquit=1; + pause_sound(stream_menutheme); + } + break; + } + break; + case 3: + fireSound(); + bool isCustomResolution,found; + switch(selected){ + case 0: + extern SDL_Rect **resolutions; + isCustomResolution = true; + found = false; + for(int i = 0; (!found) && (resolutions[i]); i++) { + if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth)) + isCustomResolution = false; + + if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) { + i++; + if(resolutions[i] != NULL) { + newscreenwidth = (int) resolutions[i]->w; + newscreenheight = (int) resolutions[i]->h; + } else if(isCustomResolution){ + if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) { + newscreenwidth = (int) resolutions[0]->w; + newscreenheight = (int) resolutions[0]->h; + } else { + newscreenwidth = screenwidth; + newscreenheight = screenheight; + } + } else { + newscreenwidth = (int) resolutions[0]->w; + newscreenheight = (int) resolutions[0]->h; + } + found = true; + } + } - mainmenu=3; + if(!found) { + newscreenwidth = (int) resolutions[0]->w; + newscreenheight = (int) resolutions[0]->h; + } + break; + case 1: + newdetail++; + if(newdetail>2) newdetail=0; + break; + case 2: + bloodtoggle++; + if(bloodtoggle>2) bloodtoggle=0; + break; + case 3: + difficulty++; + if(difficulty>2) difficulty=0; + break; + case 4: + ismotionblur = 1-ismotionblur; + break; + case 5: + decals = 1-decals; + break; + case 6: + musictoggle = 1-musictoggle; + + if(musictoggle) + emit_stream_np(stream_menutheme); + else { + pause_sound(leveltheme); + pause_sound(stream_fighttheme); + pause_sound(stream_menutheme); + + for(int i=0;i<4;i++){ + oldmusicvolume[i]=0; + musicvolume[i]=0; + } + } - if(newdetail>2)newdetail=detail; - if(newdetail<0)newdetail=detail; - if(newscreenwidth>3000)newscreenwidth=screenwidth; - if(newscreenwidth<0)newscreenwidth=screenwidth; - if(newscreenheight>3000)newscreenheight=screenheight; - if(newscreenheight<0)newscreenheight=screenheight; - } - } - } + break; + case 7: // controls + flash(); + mainmenu=4; + selected=-1; + keyselect=-1; + break; + case 8: + flash(); - if(mainmenu==5){ + if(newdetail>2) newdetail=detail; + if(newdetail<0) newdetail=detail; + if(newscreenwidth<0) newscreenwidth=screenwidth; + if(newscreenheight<0) newscreenheight=screenheight; + + SaveSettings(*this); + mainmenu=gameon?2:1; + break; + case 9: + invertmouse = 1-invertmouse; + break; + case 10: + usermousesensitivity+=.2; + if(usermousesensitivity>2) usermousesensitivity=.2; + break; + case 11: + volume+=.1f; + if(volume>1.0001f) volume=0; + OPENAL_SetSFXMasterVolume((int)(volume*255)); + break; + case 12: + flash(); + + newstereomode = stereomode; + mainmenu=18; + keyselect=-1; + break; + case 13: + showdamagebar = !showdamagebar; + break; + } + break; + case 4: + if(!waiting) { + fireSound(); + if(selected<9 && keyselect==-1) + keyselect=selected; + if(keyselect!=-1) + setKeySelected(); + if(selected==9){ + flash(); - if(endgame==2){ - accountactive->endGame(); - endgame=0; - } + mainmenu=3; - if(Input::MouseClicked()){ - if((selected-7>=accountactive->getCampaignChoicesMade())){ - fireSound(); - flash(); - startbonustotal=0; - - loading=2; - loadtime=0; - targetlevel=7; - if(firstload) TickOnceAfter(); - else LoadStuff(); - whichchoice=selected-7-accountactive->getCampaignChoicesMade(); - visibleloading=1; - stillloading=1; - Loadlevel(campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]); - //Loadlevel(campaignmapname[levelorder[selected-7]]); - campaign=1; - mainmenu=0; - gameon=1; - pause_sound(stream_music3); - } - if(selected>=1 && selected<=5){ - fireSound(); - flash(); - } - switch(selected){ - case 1: - startbonustotal=0; - - loading=2; - loadtime=0; - targetlevel=-1; - if(firstload)TickOnceAfter(); - if(!firstload)LoadStuff(); - else { - Loadlevel(-1); - } + if(newdetail>2) newdetail=detail; + if(newdetail<0) newdetail=detail; + if(newscreenwidth>3000) newscreenwidth=screenwidth; + if(newscreenwidth<0) newscreenwidth=screenwidth; + if(newscreenheight>3000) newscreenheight=screenheight; + if(newscreenheight<0) newscreenheight=screenheight; + } + } + break; + case 5: + fireSound(); + flash(); + if((selected-7 >= accountactive->getCampaignChoicesMade())) { + startbonustotal=0; - mainmenu=0; - gameon=1; - pause_sound(stream_music3); - break; - case 2: - mainmenu=9; - break; - case 3: - mainmenu=6; - break; - case 4: - if(mainmenu==5&&gameon)mainmenu=2; - if(mainmenu==5&&!gameon)mainmenu=1; - break; - case 5: - mainmenu=7; - break; - } - } - } - else if(mainmenu==9){ - if(Input::MouseClicked()&&selected=0&&selected<=accountactive->getProgress()){ - fireSound(); - flash(); - - startbonustotal=0; - - loading=2; - loadtime=0; - targetlevel=selected; - if(firstload)TickOnceAfter(); - if(!firstload)LoadStuff(); - else { - Loadlevel(selected); - } - campaign=0; + loading=2; + loadtime=0; + targetlevel=7; + if(firstload) + TickOnceAfter(); + else + LoadStuff(); + whichchoice=selected-7-accountactive->getCampaignChoicesMade(); + visibleloading=1; + stillloading=1; + Loadlevel(campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]); + campaign=1; + mainmenu=0; + gameon=1; + pause_sound(stream_menutheme); + } + switch(selected){ + case 1: + startbonustotal=0; + + loading=2; + loadtime=0; + targetlevel=-1; + if(firstload) { + TickOnceAfter(); + Loadlevel(-1); + } else + LoadStuff(); + + mainmenu=0; + gameon=1; + pause_sound(stream_menutheme); + break; + case 2: + mainmenu=9; + break; + case 3: + mainmenu=6; + break; + case 4: + mainmenu=(gameon?2:1); + break; + case 5: + mainmenu=7; + break; + } + break; + case 6: + fireSound(); + if(selected==1) { + flash(); + accountactive = Account::destroy(accountactive); + mainmenu=7; + } else if(selected==2) { + flash(); + mainmenu=5; + } + break; + case 7: + fireSound(); + if(selected==0 && Account::getNbAccounts()<8){ + entername=1; + } else if (selected < Account::getNbAccounts()+1) { + flash(); + mainmenu=5; + accountactive=Account::get(selected-1); + } else if (selected == Account::getNbAccounts()+1) { + flash(); + mainmenu=5; + for(int j=0;j<255;j++){ + displaytext[0][j]=0; + } + displaychars[0]=0; + displayselected=0; + entername=0; + } + break; + case 8: + fireSound(); + flash(); + if(selected<=2) + accountactive->setDifficulty(selected); + mainmenu=5; + break; + case 9: + if(selectedgetProgress()){ + fireSound(); + flash(); - mainmenu=0; - gameon=1; - pause_sound(stream_music3); - } - if(Input::MouseClicked()&&selected==numchallengelevels){ - fireSound(); - flash(); - mainmenu=5; - } - } - if(mainmenu==10){ - endgame=2; - if(Input::MouseClicked()&&selected==3){ - fireSound(); - flash(); - mainmenu=5; - } - } + startbonustotal=0; - if(mainmenu==6){ - if(Input::MouseClicked()) { - if(selected>-1){ - fireSound(); - if(selected==1) { - flash(); - accountactive = Account::destroy(accountactive); - mainmenu=7; - } else if(selected==2) { - flash(); - mainmenu=5; - } - } - } - } - if(mainmenu==7){ - if(Input::MouseClicked()) { - if(selected!=-1){ - fireSound(); - if(selected==0&&Account::getNbAccounts()<8){ - entername=1; - } else if (selected-1){ - fireSound(); - flash(); - if(selected<=2) - accountactive->setDifficulty(selected); - mainmenu=5; - } - } - if (mainmenu==18) { - if(Input::MouseClicked()&&selected==0) { - newstereomode = (StereoMode)(newstereomode + 1); - while(!CanInitStereo(newstereomode)) { - printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode); - newstereomode = (StereoMode)(newstereomode + 1); - if ( newstereomode >= stereoCount ) { - newstereomode = stereoNone; - } - } - } - - if(Input::isKeyPressed(MOUSEBUTTON1)&&selected==1) - stereoseparation+=0.001; - if(Input::isKeyPressed(MOUSEBUTTON2)&&selected==1) - stereoseparation-=0.001; + loading=2; + loadtime=0; + targetlevel=selected; + if(firstload)TickOnceAfter(); + if(!firstload)LoadStuff(); + else Loadlevel(selected); + campaign=0; - if(Input::MouseClicked()&&selected==2) { - stereoreverse =! stereoreverse; - } - - if(Input::MouseClicked()&&selected==3) { - flash(); + mainmenu=0; + gameon=1; + pause_sound(stream_menutheme); + } + if(selected==numchallengelevels){ + fireSound(); + flash(); + mainmenu=5; + } + break; + case 10: + if(selected==3){ + fireSound(); + flash(); + mainmenu=5; + } + break; + case 18: + if(selected==1) + stereoseparation+=0.001; + else { + fireSound(); + if(selected==0){ + newstereomode = (StereoMode)(newstereomode + 1); + while(!CanInitStereo(newstereomode)){ + printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode); + newstereomode = (StereoMode)(newstereomode + 1); + if(newstereomode >= stereoCount) + newstereomode = stereoNone; + } + } else if(selected==2) { + stereoreverse = !stereoreverse; + } else if(selected==3) { + flash(); + mainmenu=3; - stereomode = newstereomode; - InitStereo(stereomode); - - mainmenu=3; - } - } + stereomode = newstereomode; + InitStereo(stereomode); + } + } + break; + } + } - if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){ + if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){ tryquit=1; if(mainmenu==3){ - if(newdetail>2)newdetail=detail; - if(newdetail<0)newdetail=detail; - if(newscreenwidth<0)newscreenwidth=screenwidth; - if(newscreenheight<0)newscreenheight=screenheight; + if(newdetail>2) newdetail=detail; + if(newdetail<0) newdetail=detail; + if(newscreenwidth<0) newscreenwidth=screenwidth; + if(newscreenheight<0) newscreenheight=screenheight; SaveSettings(*this); } } if(mainmenu==1||mainmenu==2){ - if(loaddistrib>4)transition+=multiplier/8; + if(loaddistrib>4) + transition+=multiplier/8; if(transition>1){ transition=0; anim++; - if(anim>4)anim=0; + if(anim>4) anim=0; loaddistrib=0; } } - OPENAL_SetFrequency(channels[stream_music3], 22050); + OPENAL_SetFrequency(channels[stream_menutheme], 22050); if(entername) { inputText(displaytext[0],&displayselected,&displaychars[0]); @@ -2601,7 +2520,7 @@ void Game::MenuTick(){ fireSound(firestartsound); for(int i=0;i<255;i++){ - displaytext[0][i]=' '; + displaytext[0][i]=0; } displaychars[0]=0; @@ -3018,55 +2937,6 @@ void Game::doTutorial(){ void Game::doDebugKeys(){ float headprop,bodyprop,armprop,legprop; if(debugmode){ - if(Input::isKeyPressed(SDLK_v)){ - freeze=1-freeze; - if(freeze){ - OPENAL_SetFrequency(OPENAL_ALL, 0.001); - } - } - - if(Input::isKeyPressed(SDLK_BACKQUOTE)){ - console=1-console; - if(console){ - OPENAL_SetFrequency(OPENAL_ALL, 0.001); - } else { - freeze=0; - waiting=false; - } - } - - if(console) - freeze=1; - if(console&&!Input::isKeyDown(SDLK_LMETA)){ - inputText(consoletext[0],&consoleselected,&consolechars[0]); - if(!waiting) { - archiveselected=0; - cmd_dispatch(this, consoletext[0]); - if(consolechars[0]>0){ - - for(int k=14;k>=1;k--){ - for(int j=0;j<255;j++){ - consoletext[k][j]=consoletext[k-1][j]; - } - consolechars[k]=consolechars[k-1]; - } - for(int j=0;j<255;j++){ - consoletext[0][j]=' '; - } - consolechars[0]=0; - consoleselected=0; - } - } - - consoleblinkdelay-=multiplier; - if(consoleblinkdelay<=0){ - consoleblinkdelay=.3; - consoleblink=1-consoleblink; - } - } - - - if(Input::isKeyPressed(SDLK_h)){ player[0].damagetolerance=200000; player[0].damage=0; @@ -3213,7 +3083,7 @@ void Game::doDebugKeys(){ tintr=player[closest].clothestintr[i]; tintg=player[closest].clothestintg[i]; tintb=player[closest].clothestintb[i]; - AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize); + AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]); } player[closest].DoMipmaps(); } @@ -3510,7 +3380,8 @@ void Game::doDebugKeys(){ //skip level if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){ targetlevel++; - if(targetlevel>numchallengelevels-1)targetlevel=0; + if(targetlevel>numchallengelevels-1) + targetlevel=0; loading=1; leveltime=5; } @@ -3692,7 +3563,7 @@ void Game::doDebugKeys(){ tintr=player[numplayers].clothestintr[i]; tintg=player[numplayers].clothestintg[i]; tintb=player[numplayers].clothestintb[i]; - AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize); + AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]); } if(player[numplayers].numclothes){ player[numplayers].DoMipmaps(); @@ -3762,7 +3633,8 @@ void Game::doDebugKeys(){ if(Input::isKeyPressed(SDLK_PERIOD)){ pathpointselected++; - if(pathpointselected>=numpathpoints)pathpointselected=-1; + if(pathpointselected>=numpathpoints) + pathpointselected=-1; } if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){ pathpointselected--; @@ -4753,7 +4625,7 @@ void Game::doAttacks(){ player[i].skeleton.longdead<300&& player[k].lastattack!=spinkickanim&& player[i].skeleton.free)&& - (!player[i].dead||musictype!=stream_music2)){ + (!player[i].dead||musictype!=stream_fighttheme)){ player[k].targetanimation=dropkickanim; for(int j=0;j unused + 18 stereo configuration + */ + if(!console){ - if(mainmenu&&endgame==1)mainmenu=10; - // menu back - if( (Input::isKeyPressed(SDLK_ESCAPE) - ||(mainmenu==0 - &&((Input::isKeyPressed(jumpkey) - ||Input::isKeyPressed(SDLK_SPACE) - ||(campaign))) - &&campaign - &&winfreeze)) - && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==10)){ + //campaign over? + if(mainmenu&&endgame==1) + mainmenu=10; + //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)))){ selected=-1; - if(mainmenu==1||mainmenu==2||mainmenu==0){ - if(mainmenu==0&&!winfreeze)mainmenu=2; - else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100; - else if(mainmenu==0&&winfreeze){ } - else if(mainmenu==1||mainmenu==2)mainmenu=0; - if(mainmenu&&musictoggle){ - if(mainmenu==1||mainmenu==2||mainmenu==100){ - OPENAL_SetFrequency(OPENAL_ALL, 0.001); - emit_stream_np(stream_music3); - pause_sound(music1); - } - } - if(!mainmenu){ - pause_sound(stream_music3); - resume_stream(music1); - } - } + 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) + mainmenu=0; //unpause + //play menu theme + if(musictoggle&&(mainmenu==1||mainmenu==2||mainmenu==100)){ + OPENAL_SetFrequency(OPENAL_ALL, 0.001); + emit_stream_np(stream_menutheme); + pause_sound(leveltheme); + } + //on resume, play level music + if(!mainmenu){ + pause_sound(stream_menutheme); + resume_stream(leveltheme); + } + //finished with settings menu if(mainmenu==3){ - if(newdetail>2)newdetail=detail; - if(newdetail<0)newdetail=detail; - if(newscreenwidth<0)newscreenwidth=screenwidth; - if(newscreenheight<0)newscreenheight=screenheight; + if(newdetail>2) + newdetail=detail; + if(newdetail<0) + newdetail=detail; + if(newscreenwidth<0) + newscreenwidth=screenwidth; + if(newscreenheight<0) + newscreenheight=screenheight; SaveSettings(*this); } - if((mainmenu>=3 && mainmenu<=7)||mainmenu==9||mainmenu==10||mainmenu==100){ + //effects + if(mainmenu>=3&&mainmenu!=8){ fireSound(); flash(); } - if(mainmenu==3&&gameon)mainmenu=2; - if(mainmenu==3&&!gameon)mainmenu=1; - if(mainmenu==5&&gameon)mainmenu=2; - if(mainmenu==5&&!gameon)mainmenu=1; - if(mainmenu==4)mainmenu=3; - if(mainmenu==6)mainmenu=5; - if(mainmenu==7)mainmenu=1; - if(mainmenu==9)mainmenu=5; - if(mainmenu==10)mainmenu=5; - if(mainmenu==100){ - mainmenu=5; - gameon=0; - winfreeze=0; - } + //go back + switch(mainmenu){ + case 3: case 5: + mainmenu=gameon?2:1; break; + case 4: case 18: + mainmenu=3; break; + case 6: case 7: case 9: case 10: case 100: + mainmenu=5; break; + } } } @@ -6159,11 +6047,11 @@ void Game::Tick(){ if(!winfreeze)leveltime+=multiplier; //keys - if(Input::isKeyDown(SDLK_ESCAPE)){ - chatting=0; - console=0; - freeze=0; - displaychars[0]=0; + if(Input::isKeyPressed(SDLK_v)&&debugmode){ + freeze=1-freeze; + if(freeze){ + OPENAL_SetFrequency(OPENAL_ALL, 0.001); + } } if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode) @@ -6173,9 +6061,8 @@ void Game::Tick(){ inputText(displaytext[0],&displayselected,&displaychars[0]); if(!waiting) { if(displaychars[0]){ - for(int j=0;j<255;j++){ - displaytext[0][j]=' '; - } + for(int j=0;j<255;j++) + displaytext[0][j]=0; displaychars[0]=0; displayselected=0; } @@ -6191,6 +6078,46 @@ void Game::Tick(){ if(chatting) keyboardfrozen=1; + if(Input::isKeyPressed(SDLK_BACKQUOTE)&&debugmode){ + console=1-console; + if(console){ + OPENAL_SetFrequency(OPENAL_ALL, 0.001); + } else { + freeze=0; + waiting=false; + } + } + + if(console) + freeze=1; + if(console&&!Input::isKeyDown(SDLK_LMETA)){ + inputText(consoletext[0],&consoleselected,&consolechars[0]); + if(!waiting) { + archiveselected=0; + if(consolechars[0]>0){ + consoletext[0][consolechars[0]]=' '; + cmd_dispatch(this, consoletext[0]); + for(int k=14;k>=1;k--){ + for(int j=0;j<255;j++) + consoletext[k][j]=consoletext[k-1][j]; + consolechars[k]=consolechars[k-1]; + } + for(int j=0;j<255;j++) + consoletext[0][j]=0; + consolechars[0]=0; + consoleselected=0; + } + } + + consoleblinkdelay-=multiplier; + if(consoleblinkdelay<=0){ + consoleblinkdelay=.3; + consoleblink=1-consoleblink; + } + } + + + if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){ tryquit=1; if(mainmenu==3){ @@ -6216,11 +6143,16 @@ void Game::Tick(){ if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign) if(winfreeze) winfreeze=0; - if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon) - if(winfreeze){ + if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){ + if(console){ + console=0; + freeze=0; + }else if(winfreeze){ mainmenu=9; gameon=0; } + } + //TODO: what is this test? @@ -7118,7 +7050,7 @@ void Game::Tick(){ player[i].attackkeydown){ if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&& player[i].onterrain&& - bloodtoggle&&musictype!=stream_music2){ + bloodtoggle&&musictype!=stream_fighttheme){ if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife) setAnimation(i,crouchstabanim); if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword) @@ -7559,7 +7491,7 @@ void Game::Tick(){ OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu... OPENAL_SetFrequency(OPENAL_ALL, 0.001); - emit_stream_np(stream_music3); + emit_stream_np(stream_menutheme); gameon=0; mainmenu=5; @@ -7683,15 +7615,15 @@ void Game::TickOnceAfter(){ if(!mainmenu){ if(environment==snowyenvironment) - music1=stream_music1snow; + leveltheme=stream_snowtheme; if(environment==grassyenvironment) - music1=stream_music1grass; + leveltheme=stream_grasstheme; if(environment==desertenvironment) - music1=stream_music1desert; + leveltheme=stream_deserttheme; realthreat=0; - musictype=music1; + musictype=leveltheme; for(int i=0;i0) - musictype=stream_music2; + musictype=stream_fighttheme; } if(loading==2){ - musictype=stream_music3; + musictype=stream_menutheme; musicvolume[2]=512; musicvolume[0]=0; musicvolume[1]=0; @@ -7728,19 +7660,19 @@ void Game::TickOnceAfter(){ } if(musictoggle) - if(musictype!=oldmusictype&&musictype==stream_music2) + if(musictype!=oldmusictype&&musictype==stream_fighttheme) emit_sound_np(alarmsound); musicselected=musictype; - if(musicselected==music1) + if(musicselected==leveltheme) musicvolume[0]+=multiplier*450; else musicvolume[0]-=multiplier*450; - if(musicselected==stream_music2) + if(musicselected==stream_fighttheme) musicvolume[1]+=multiplier*450; else musicvolume[1]-=multiplier*450; - if(musicselected==stream_music3) + if(musicselected==stream_menutheme) musicvolume[2]+=multiplier*450; else musicvolume[2]-=multiplier*450; @@ -7757,31 +7689,31 @@ void Game::TickOnceAfter(){ if(musictoggle){ if(musicvolume[0]>0&&oldmusicvolume[0]<=0) - emit_stream_np(music1, musicvolume[0]); + emit_stream_np(leveltheme, musicvolume[0]); if(musicvolume[1]>0&&oldmusicvolume[1]<=0) - emit_stream_np(stream_music2, musicvolume[1]); + emit_stream_np(stream_fighttheme, musicvolume[1]); if(musicvolume[2]>0&&oldmusicvolume[2]<=0) - emit_stream_np(stream_music3, musicvolume[2]); + emit_stream_np(stream_menutheme, musicvolume[2]); if(musicvolume[0]<=0&&oldmusicvolume[0]>0) - pause_sound(music1); + pause_sound(leveltheme); if(musicvolume[1]<=0&&oldmusicvolume[1]>0) - pause_sound(stream_music2); + pause_sound(stream_fighttheme); if(musicvolume[2]<=0&&oldmusicvolume[2]>0) - pause_sound(stream_music3); + pause_sound(stream_menutheme); if(musicvolume[0]!=oldmusicvolume[0]) - OPENAL_SetVolume(channels[music1], musicvolume[0]); + OPENAL_SetVolume(channels[leveltheme], musicvolume[0]); if(musicvolume[1]!=oldmusicvolume[1]) - OPENAL_SetVolume(channels[stream_music2], musicvolume[1]); + OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]); if(musicvolume[2]!=oldmusicvolume[2]) - OPENAL_SetVolume(channels[stream_music3], musicvolume[2]); + OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]); for(int i=0;i<3;i++) oldmusicvolume[i]=musicvolume[i]; } else { - pause_sound(music1); - pause_sound(stream_music2); - pause_sound(stream_music3); + pause_sound(leveltheme); + pause_sound(stream_fighttheme); + pause_sound(stream_menutheme); for(int i=0;i<4;i++){ oldmusicvolume[i]=0; @@ -8008,7 +7940,8 @@ void Game::TickOnceAfter(){ loading=2; loadtime=0; targetlevel=7; - if(!firstload)LoadStuff(); + if(!firstload) + LoadStuff(); whichchoice=0; visibleloading=1; stillloading=1; @@ -8016,7 +7949,7 @@ void Game::TickOnceAfter(){ campaign=1; mainmenu=0; gameon=1; - pause_sound(stream_music3); + pause_sound(stream_menutheme); stealthloading=0; }