X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGameTick.cpp;h=05bb4ce08dd6c9f5430d30e2b019d5c6fcb7700d;hb=bbf8873b80baf3cb468ac12b3f62b0938320fef1;hp=1fba112a8fbf9ff782b06aa07f5fd8f293a83a17;hpb=6bd4d8e827e8e47b78db4a1f236cba2eed7032b4;p=lugaru.git diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 1fba112..05bb4ce 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" @@ -80,7 +81,6 @@ extern bool debugmode; static int music1; 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(); @@ -1402,7 +1402,7 @@ void Game::Setenvironment(int which) } -void Game::Loadlevel(int which){ +void Game::Loadlevel(int which){ stealthloading=0; whichlevel=which; @@ -1417,7 +1417,7 @@ void Game::Loadlevel(int which){ 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;iendGame(); @@ -2448,8 +2380,7 @@ void Game::MenuTick(){ break; } } - } - else if(mainmenu==9){ + }else if(mainmenu==9){ if(Input::MouseClicked()&&selected=0&&selected<=accountactive->getProgress()){ fireSound(); flash(); @@ -2475,17 +2406,14 @@ void Game::MenuTick(){ flash(); mainmenu=5; } - } - if(mainmenu==10){ + }else if(mainmenu==10){ endgame=2; if(Input::MouseClicked()&&selected==3){ fireSound(); flash(); mainmenu=5; } - } - - if(mainmenu==6){ + }else if(mainmenu==6){ if(Input::MouseClicked()) { if(selected>-1){ fireSound(); @@ -2499,8 +2427,7 @@ void Game::MenuTick(){ } } } - } - if(mainmenu==7){ + }else if(mainmenu==7){ if(Input::MouseClicked()) { if(selected!=-1){ fireSound(); @@ -2516,7 +2443,7 @@ void Game::MenuTick(){ mainmenu=1; for(int j=0;j<255;j++){ - displaytext[0][j]=' '; + displaytext[0][j]=0; } displaychars[0]=0; displayselected=0; @@ -2524,8 +2451,7 @@ void Game::MenuTick(){ } } } - } - if(mainmenu==8){ + }else if(mainmenu==8){ if(Input::MouseClicked()&&selected>-1){ fireSound(); flash(); @@ -2533,8 +2459,7 @@ void Game::MenuTick(){ accountactive->setDifficulty(selected); mainmenu=5; } - } - if (mainmenu==18) { + }else if(mainmenu==18){ if(Input::MouseClicked()&&selected==0) { newstereomode = (StereoMode)(newstereomode + 1); while(!CanInitStereo(newstereomode)) { @@ -2601,7 +2526,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 +2943,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 +3089,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 +3386,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 +3569,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 +3639,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--; @@ -6159,11 +6037,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 +6051,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 +6068,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 +6133,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?